aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--Documentation/networking/mac80211-injection.txt28
-rw-r--r--Documentation/rfkill.txt16
-rw-r--r--MAINTAINERS10
-rw-r--r--arch/arm/mach-pxa/tosa-bt.c4
-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
-rw-r--r--drivers/platform/x86/acer-wmi.c1
-rw-r--r--drivers/platform/x86/hp-wmi.c3
-rw-r--r--drivers/platform/x86/sony-laptop.c4
-rw-r--r--drivers/platform/x86/toshiba_acpi.c1
-rw-r--r--include/linux/ieee80211.h41
-rw-r--r--include/linux/mmc/sdio_ids.h2
-rw-r--r--include/linux/nl80211.h127
-rw-r--r--include/linux/pci_ids.h2
-rw-r--r--include/linux/rfkill.h14
-rw-r--r--include/net/cfg80211.h897
-rw-r--r--include/net/mac80211.h117
-rw-r--r--include/net/regulatory.h101
-rw-r--r--include/net/wireless.h472
-rw-r--r--net/mac80211/Kconfig16
-rw-r--r--net/mac80211/cfg.c59
-rw-r--r--net/mac80211/debugfs.c8
-rw-r--r--net/mac80211/event.c17
-rw-r--r--net/mac80211/ht.c84
-rw-r--r--net/mac80211/ibss.c347
-rw-r--r--net/mac80211/ieee80211_i.h85
-rw-r--r--net/mac80211/iface.c16
-rw-r--r--net/mac80211/main.c122
-rw-r--r--net/mac80211/mlme.c445
-rw-r--r--net/mac80211/pm.c121
-rw-r--r--net/mac80211/rx.c2
-rw-r--r--net/mac80211/scan.c28
-rw-r--r--net/mac80211/spectmgmt.c2
-rw-r--r--net/mac80211/sta_info.c71
-rw-r--r--net/mac80211/sta_info.h3
-rw-r--r--net/mac80211/tx.c35
-rw-r--r--net/mac80211/util.c240
-rw-r--r--net/mac80211/wext.c270
-rw-r--r--net/mac80211/wpa.c2
-rw-r--r--net/rfkill/rfkill-input.c69
-rw-r--r--net/rfkill/rfkill.c54
-rw-r--r--net/wimax/op-rfkill.c9
-rw-r--r--net/wireless/Makefile2
-rw-r--r--net/wireless/core.c27
-rw-r--r--net/wireless/core.h15
-rw-r--r--net/wireless/ibss.c369
-rw-r--r--net/wireless/mlme.c50
-rw-r--r--net/wireless/nl80211.c639
-rw-r--r--net/wireless/nl80211.h32
-rw-r--r--net/wireless/reg.c35
-rw-r--r--net/wireless/scan.c53
-rw-r--r--net/wireless/util.c6
-rw-r--r--net/wireless/wext-compat.c236
187 files changed, 7859 insertions, 5549 deletions
diff --git a/Documentation/networking/mac80211-injection.txt b/Documentation/networking/mac80211-injection.txt
index 84906ef3ed6e..b30e81ad5307 100644
--- a/Documentation/networking/mac80211-injection.txt
+++ b/Documentation/networking/mac80211-injection.txt
@@ -12,38 +12,22 @@ following format:
12The radiotap format is discussed in 12The radiotap format is discussed in
13./Documentation/networking/radiotap-headers.txt. 13./Documentation/networking/radiotap-headers.txt.
14 14
15Despite 13 radiotap argument types are currently defined, most only make sense 15Despite many radiotap parameters being currently defined, most only make sense
16to appear on received packets. The following information is parsed from the 16to appear on received packets. The following information is parsed from the
17radiotap headers and used to control injection: 17radiotap headers and used to control injection:
18 18
19 * IEEE80211_RADIOTAP_RATE
20
21 rate in 500kbps units, automatic if invalid or not present
22
23
24 * IEEE80211_RADIOTAP_ANTENNA
25
26 antenna to use, automatic if not present
27
28
29 * IEEE80211_RADIOTAP_DBM_TX_POWER
30
31 transmit power in dBm, automatic if not present
32
33
34 * IEEE80211_RADIOTAP_FLAGS 19 * IEEE80211_RADIOTAP_FLAGS
35 20
36 IEEE80211_RADIOTAP_F_FCS: FCS will be removed and recalculated 21 IEEE80211_RADIOTAP_F_FCS: FCS will be removed and recalculated
37 IEEE80211_RADIOTAP_F_WEP: frame will be encrypted if key available 22 IEEE80211_RADIOTAP_F_WEP: frame will be encrypted if key available
38 IEEE80211_RADIOTAP_F_FRAG: frame will be fragmented if longer than the 23 IEEE80211_RADIOTAP_F_FRAG: frame will be fragmented if longer than the
39 current fragmentation threshold. Note that 24 current fragmentation threshold.
40 this flag is only reliable when software 25
41 fragmentation is enabled)
42 26
43The injection code can also skip all other currently defined radiotap fields 27The injection code can also skip all other currently defined radiotap fields
44facilitating replay of captured radiotap headers directly. 28facilitating replay of captured radiotap headers directly.
45 29
46Here is an example valid radiotap header defining these three parameters 30Here is an example valid radiotap header defining some parameters
47 31
48 0x00, 0x00, // <-- radiotap version 32 0x00, 0x00, // <-- radiotap version
49 0x0b, 0x00, // <- radiotap header length 33 0x0b, 0x00, // <- radiotap header length
@@ -72,8 +56,8 @@ interface), along the following lines:
72... 56...
73 r = pcap_inject(ppcap, u8aSendBuffer, nLength); 57 r = pcap_inject(ppcap, u8aSendBuffer, nLength);
74 58
75You can also find sources for a complete inject test applet here: 59You can also find a link to a complete inject application here:
76 60
77http://penumbra.warmcat.com/_twk/tiki-index.php?page=packetspammer 61http://wireless.kernel.org/en/users/Documentation/packetspammer
78 62
79Andy Green <andy@warmcat.com> 63Andy Green <andy@warmcat.com>
diff --git a/Documentation/rfkill.txt b/Documentation/rfkill.txt
index 4d3ee317a4a3..40c3a3f10816 100644
--- a/Documentation/rfkill.txt
+++ b/Documentation/rfkill.txt
@@ -521,16 +521,12 @@ status of the system.
521Input devices may issue events that are related to rfkill. These are the 521Input devices may issue events that are related to rfkill. These are the
522various KEY_* events and SW_* events supported by rfkill-input.c. 522various KEY_* events and SW_* events supported by rfkill-input.c.
523 523
524******IMPORTANT****** 524Userspace may not change the state of an rfkill switch in response to an
525When rfkill-input is ACTIVE, userspace is NOT TO CHANGE THE STATE OF AN RFKILL 525input event, it should refrain from changing states entirely.
526SWITCH IN RESPONSE TO AN INPUT EVENT also handled by rfkill-input, unless it 526
527has set to true the user_claim attribute for that particular switch. This rule 527Userspace cannot assume it is the only source of control for rfkill switches.
528is *absolute*; do NOT violate it. 528Their state can change due to firmware actions, direct user actions, and the
529******IMPORTANT****** 529rfkill-input EPO override for *_RFKILL_ALL.
530
531Userspace must not assume it is the only source of control for rfkill switches.
532Their state CAN and WILL change due to firmware actions, direct user actions,
533and the rfkill-input EPO override for *_RFKILL_ALL.
534 530
535When rfkill-input is not active, userspace must initiate a rfkill status 531When rfkill-input is not active, userspace must initiate a rfkill status
536change by writing to the "state" attribute in order for anything to happen. 532change by writing to the "state" attribute in order for anything to happen.
diff --git a/MAINTAINERS b/MAINTAINERS
index 2dc197c362b3..3dfe1a7c9a93 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -888,6 +888,12 @@ P: Luis R. Rodriguez
888M: lrodriguez@atheros.com 888M: lrodriguez@atheros.com
889P: Jouni Malinen 889P: Jouni Malinen
890M: jmalinen@atheros.com 890M: jmalinen@atheros.com
891P: Sujith Manoharan
892M: Sujith.Manoharan@atheros.com
893P: Vasanthakumar Thiagarajan
894M: vasanth@atheros.com
895P: Senthil Balasubramanian
896M: senthilkumar@atheros.com
891L: linux-wireless@vger.kernel.org 897L: linux-wireless@vger.kernel.org
892L: ath9k-devel@lists.ath9k.org 898L: ath9k-devel@lists.ath9k.org
893S: Supported 899S: Supported
@@ -4421,8 +4427,8 @@ S: Maintained
4421F: drivers/ata/sata_promise.* 4427F: drivers/ata/sata_promise.*
4422 4428
4423PS3 NETWORK SUPPORT 4429PS3 NETWORK SUPPORT
4424P: Masakazu Mokuno 4430P: Geoff Levand
4425M: mokuno@sm.sony.co.jp 4431M: geoffrey.levand@am.sony.com
4426L: netdev@vger.kernel.org 4432L: netdev@vger.kernel.org
4427L: cbe-oss-dev@ozlabs.org 4433L: cbe-oss-dev@ozlabs.org
4428S: Supported 4434S: Supported
diff --git a/arch/arm/mach-pxa/tosa-bt.c b/arch/arm/mach-pxa/tosa-bt.c
index fb0294bd4310..bde42aa29374 100644
--- a/arch/arm/mach-pxa/tosa-bt.c
+++ b/arch/arm/mach-pxa/tosa-bt.c
@@ -38,9 +38,9 @@ static void tosa_bt_off(struct tosa_bt_data *data)
38static int tosa_bt_toggle_radio(void *data, enum rfkill_state state) 38static int tosa_bt_toggle_radio(void *data, enum rfkill_state state)
39{ 39{
40 pr_info("BT_RADIO going: %s\n", 40 pr_info("BT_RADIO going: %s\n",
41 state == RFKILL_STATE_ON ? "on" : "off"); 41 state == RFKILL_STATE_UNBLOCKED ? "on" : "off");
42 42
43 if (state == RFKILL_STATE_ON) { 43 if (state == RFKILL_STATE_UNBLOCKED) {
44 pr_info("TOSA_BT: going ON\n"); 44 pr_info("TOSA_BT: going ON\n");
45 tosa_bt_on(data); 45 tosa_bt_on(data);
46 } else { 46 } else {
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index f84b78d94c40..d696e5fbc176 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 8a0823588c51..2d8434f409b6 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 50e7fba7f0ea..0625e91b5995 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 69248ded5102..55f947ac56d1 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 000000000000..d26e7b485315
--- /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 000000000000..4bb0132ada37
--- /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 de4281fda129..b99e3263ee6d 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 8d91c7ee3215..8d91c7ee3215 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 f4fb2e94aea0..17bd3eaf3e03 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 f57a6200167b..f57a6200167b 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 a4f0e50e52b4..a4f0e50e52b4 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 d2c8cc83f1dd..d2c8cc83f1dd 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 53e250a4278f..95bf812d6fcc 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 341cead7f606..341cead7f606 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 c8fa3073169f..c8fa3073169f 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 5996ff9f7f47..1b60906b80c9 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 6ce20754b8e7..6ce20754b8e7 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 fddda477095c..fddda477095c 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 f5852924cd64..ac42586495d8 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 75383a5df992..509b6f94f73b 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 84a74c5248e5..84a74c5248e5 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 0b616e72fe05..60c6d2edc4b9 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 70d376c63aac..70d376c63aac 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 a08bc8a4fb69..c8c658bfcf9d 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 822956114cd7..852b2c189fd8 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 367a6c7d3cc7..367a6c7d3cc7 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 9770bb3d40f9..9770bb3d40f9 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 66f69f04e55e..66f69f04e55e 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 dc30a2b70a6b..dc30a2b70a6b 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 56158c804e3e..56158c804e3e 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 b65b4feb2d28..941b51130a6f 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 c0fb3b09ba45..c0fb3b09ba45 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 b0c0606dea0b..b0c0606dea0b 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 64a27e73d02e..64a27e73d02e 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 61fb621ed20d..18eb5190ce4b 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 19555fb79c9b..cbdc0b308429 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 55122f1e1986..55122f1e1986 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 9e2faae5ae94..b48b29dca3d2 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 5094c394a4b2..5094c394a4b2 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 7070d1543cdc..7070d1543cdc 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 cb5e15f97095..775fdf78554b 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 e50baff66175..e50baff66175 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 1354d8c392c8..1354d8c392c8 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 90a8dd873786..0ed1ac312aa6 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 1a4d4eab6fe8..783bc39eb2ff 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 0e65c51ba176..0e65c51ba176 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 6c5e887d50d7..1aeafb511ddd 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 08b4e7ed5ff0..08b4e7ed5ff0 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 7b1b40aaf09d..c92d46fa9d51 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 ec995730632d..eb4759fc6a0d 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 e2d62e97131c..a197041d76b5 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 1c74bd50700d..fe5367f14148 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 fdf9528fa49b..97df20cbf528 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 7b0e5419d2bc..23298b90b52b 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 ffc36b0361c7..44fee5ae8925 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 25b68c881ff1..7c59dc47f912 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 b15eaf8417ff..ec2a7a40b00d 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 0b594e0ee260..ab3412672e36 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 e2f0a34b79a1..e2f0a34b79a1 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 e0a6dee45839..8ae4ec21667b 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 1176bce8b76c..1176bce8b76c 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 13d4e6756c99..2398d4f45f28 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 6dbc58580abb..6dbc58580abb 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 8bcba906929a..5ec9ce91d979 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 0f7f8e0c9c95..296d0e985f25 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 824ccbb8b7b8..8f3cf10f65c4 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 199a3ce57d64..e3abd76103fd 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 dd1f30156740..b46badd21f73 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 52605246679f..52605246679f 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 1ff429b027d7..1ff429b027d7 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 689bdbf78808..faf2cab49ea3 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 000000000000..9949b11cb151
--- /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 4ca625102291..fdf07c822081 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 9f5fbd4eea7a..07291ccb23f2 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 4d0e298cd1c7..4d0e298cd1c7 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 aab71a70ba78..21572e40b79d 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 beaf18d6e8a7..4e8ad841c3c5 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 79b685e300c7..a97c6ff0f12e 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 afad42358693..9e1d00bc24d3 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 aef2298d37ac..d4f628a74bbd 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 97b0e06dfe21..da59ef02b6ef 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 879edc786713..ee202b4f77b5 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 b32bf6a94f19..4b0c7d27a51f 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 12fca99f7578..b8e39dd06e99 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 62e09d02788f..91633087a20b 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 cbf15d703201..0e5d51086a44 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 af6b9d444778..f63a9c5ba262 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 527525cc0919..41f1d66cfeba 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 55188844657b..da87528f355f 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 847a6220c5e6..a98ff4ead720 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 e5ca2511a81a..d731a836e6c8 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 edfa5e149f71..ee271d7f6120 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 cab7842a73aa..3504279c7586 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 ab59acc405d9..f875136bc5dc 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 1ef4192207a5..277dfc57fde9 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 29d40746da6a..7b84d5246b36 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 c54fb93e9d72..3dec2d25fa3d 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 a8eac8c3c1fa..d4c60afa2891 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 65d1a7f2db9e..db069801bc41 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 64eb585f1578..ffc4be3842b2 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 cf7f0db58fcf..5aa76a706320 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 2ad9faf1508a..65605ad44e4b 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 8f65908f66f1..fae84262efb6 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 23644cf884f1..799f5eb61ece 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 5798fe49c771..17a4dd2be1f2 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 71d5b8a1a73e..a82cca0a30c7 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 617c4235d971..84feeb70fea4 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 8c3605cdc64c..c455b9abbfc0 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 e8dfde39abfc..48da157d6cda 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 27e81fd97c94..cbaafa653b6a 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 d4457ef808a6..8ff8ac9d817e 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 a899aeb676bb..391c54ab2b09 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 cedeac6322fe..2a5b083bf9bd 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 76f4c653d641..55864c10f9f1 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 533bdfbf5d2a..37ada2c29aa9 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 07311e71af92..dccd01fd1f10 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 8ae935ac32f1..89575e448015 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 8e669775cb5d..65f02cc6752f 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 f10aa39a6b68..160cfd8311c0 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 fb7a2d1a2525..de03b9c9c204 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 ecf8b6ed5a47..7fda1a9e263b 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 c8f0232ee5e0..71394968d450 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 d1fe577de3d4..59a5e778bb08 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 db91db776508..52fc647e6cb6 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 0f08773328c6..411eb9cbb4e5 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 276a8232aaa0..e1be67ca23d8 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 84bd6f19acb0..e03d69975ea4 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 7eb5cd7e5f32..eb9b981b9139 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 9730b4f8fd26..cdd5154bd4c0 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 2ca8b7a9722c..4346cd1494bc 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 41e8959919f6..6c71f77c8165 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 c113b3e69046..37e3d4db0c40 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 9718f61809cf..622196dc078e 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 fd81884b9c7d..ac558da92aac 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 000000000000..b44253592243
--- /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 000000000000..a0332027aead
--- /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 */
diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
index 0f6e43bf4fc2..62d02b3c998e 100644
--- a/drivers/platform/x86/acer-wmi.c
+++ b/drivers/platform/x86/acer-wmi.c
@@ -1005,7 +1005,6 @@ enum rfkill_type type, char *name, u32 cap)
1005 *data = cap; 1005 *data = cap;
1006 rfkill_dev->data = data; 1006 rfkill_dev->data = data;
1007 rfkill_dev->toggle_radio = acer_rfkill_set; 1007 rfkill_dev->toggle_radio = acer_rfkill_set;
1008 rfkill_dev->user_claim_unsupported = 1;
1009 1008
1010 err = rfkill_register(rfkill_dev); 1009 err = rfkill_register(rfkill_dev);
1011 if (err) { 1010 if (err) {
diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c
index 50d9019de2be..fe171fad12cf 100644
--- a/drivers/platform/x86/hp-wmi.c
+++ b/drivers/platform/x86/hp-wmi.c
@@ -434,7 +434,6 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
434 wifi_rfkill->name = "hp-wifi"; 434 wifi_rfkill->name = "hp-wifi";
435 wifi_rfkill->state = hp_wmi_wifi_state(); 435 wifi_rfkill->state = hp_wmi_wifi_state();
436 wifi_rfkill->toggle_radio = hp_wmi_wifi_set; 436 wifi_rfkill->toggle_radio = hp_wmi_wifi_set;
437 wifi_rfkill->user_claim_unsupported = 1;
438 err = rfkill_register(wifi_rfkill); 437 err = rfkill_register(wifi_rfkill);
439 if (err) 438 if (err)
440 goto add_sysfs_error; 439 goto add_sysfs_error;
@@ -446,7 +445,6 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
446 bluetooth_rfkill->name = "hp-bluetooth"; 445 bluetooth_rfkill->name = "hp-bluetooth";
447 bluetooth_rfkill->state = hp_wmi_bluetooth_state(); 446 bluetooth_rfkill->state = hp_wmi_bluetooth_state();
448 bluetooth_rfkill->toggle_radio = hp_wmi_bluetooth_set; 447 bluetooth_rfkill->toggle_radio = hp_wmi_bluetooth_set;
449 bluetooth_rfkill->user_claim_unsupported = 1;
450 err = rfkill_register(bluetooth_rfkill); 448 err = rfkill_register(bluetooth_rfkill);
451 if (err) 449 if (err)
452 goto register_bluetooth_error; 450 goto register_bluetooth_error;
@@ -457,7 +455,6 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
457 wwan_rfkill->name = "hp-wwan"; 455 wwan_rfkill->name = "hp-wwan";
458 wwan_rfkill->state = hp_wmi_wwan_state(); 456 wwan_rfkill->state = hp_wmi_wwan_state();
459 wwan_rfkill->toggle_radio = hp_wmi_wwan_set; 457 wwan_rfkill->toggle_radio = hp_wmi_wwan_set;
460 wwan_rfkill->user_claim_unsupported = 1;
461 err = rfkill_register(wwan_rfkill); 458 err = rfkill_register(wwan_rfkill);
462 if (err) 459 if (err)
463 goto register_wwan_err; 460 goto register_wwan_err;
diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index d3c92d777bde..184e99e72684 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -1097,7 +1097,6 @@ static int sony_nc_setup_wifi_rfkill(struct acpi_device *device)
1097 sony_wifi_rfkill->name = "sony-wifi"; 1097 sony_wifi_rfkill->name = "sony-wifi";
1098 sony_wifi_rfkill->toggle_radio = sony_nc_rfkill_set; 1098 sony_wifi_rfkill->toggle_radio = sony_nc_rfkill_set;
1099 sony_wifi_rfkill->get_state = sony_nc_rfkill_get; 1099 sony_wifi_rfkill->get_state = sony_nc_rfkill_get;
1100 sony_wifi_rfkill->user_claim_unsupported = 1;
1101 sony_wifi_rfkill->data = (void *)SONY_WIFI; 1100 sony_wifi_rfkill->data = (void *)SONY_WIFI;
1102 err = rfkill_register(sony_wifi_rfkill); 1101 err = rfkill_register(sony_wifi_rfkill);
1103 if (err) 1102 if (err)
@@ -1119,7 +1118,6 @@ static int sony_nc_setup_bluetooth_rfkill(struct acpi_device *device)
1119 sony_bluetooth_rfkill->name = "sony-bluetooth"; 1118 sony_bluetooth_rfkill->name = "sony-bluetooth";
1120 sony_bluetooth_rfkill->toggle_radio = sony_nc_rfkill_set; 1119 sony_bluetooth_rfkill->toggle_radio = sony_nc_rfkill_set;
1121 sony_bluetooth_rfkill->get_state = sony_nc_rfkill_get; 1120 sony_bluetooth_rfkill->get_state = sony_nc_rfkill_get;
1122 sony_bluetooth_rfkill->user_claim_unsupported = 1;
1123 sony_bluetooth_rfkill->data = (void *)SONY_BLUETOOTH; 1121 sony_bluetooth_rfkill->data = (void *)SONY_BLUETOOTH;
1124 err = rfkill_register(sony_bluetooth_rfkill); 1122 err = rfkill_register(sony_bluetooth_rfkill);
1125 if (err) 1123 if (err)
@@ -1140,7 +1138,6 @@ static int sony_nc_setup_wwan_rfkill(struct acpi_device *device)
1140 sony_wwan_rfkill->name = "sony-wwan"; 1138 sony_wwan_rfkill->name = "sony-wwan";
1141 sony_wwan_rfkill->toggle_radio = sony_nc_rfkill_set; 1139 sony_wwan_rfkill->toggle_radio = sony_nc_rfkill_set;
1142 sony_wwan_rfkill->get_state = sony_nc_rfkill_get; 1140 sony_wwan_rfkill->get_state = sony_nc_rfkill_get;
1143 sony_wwan_rfkill->user_claim_unsupported = 1;
1144 sony_wwan_rfkill->data = (void *)SONY_WWAN; 1141 sony_wwan_rfkill->data = (void *)SONY_WWAN;
1145 err = rfkill_register(sony_wwan_rfkill); 1142 err = rfkill_register(sony_wwan_rfkill);
1146 if (err) 1143 if (err)
@@ -1161,7 +1158,6 @@ static int sony_nc_setup_wimax_rfkill(struct acpi_device *device)
1161 sony_wimax_rfkill->name = "sony-wimax"; 1158 sony_wimax_rfkill->name = "sony-wimax";
1162 sony_wimax_rfkill->toggle_radio = sony_nc_rfkill_set; 1159 sony_wimax_rfkill->toggle_radio = sony_nc_rfkill_set;
1163 sony_wimax_rfkill->get_state = sony_nc_rfkill_get; 1160 sony_wimax_rfkill->get_state = sony_nc_rfkill_get;
1164 sony_wimax_rfkill->user_claim_unsupported = 1;
1165 sony_wimax_rfkill->data = (void *)SONY_WIMAX; 1161 sony_wimax_rfkill->data = (void *)SONY_WIMAX;
1166 err = rfkill_register(sony_wimax_rfkill); 1162 err = rfkill_register(sony_wimax_rfkill);
1167 if (err) 1163 if (err)
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index 9f187265db8e..4345089f5171 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -803,7 +803,6 @@ static int __init toshiba_acpi_init(void)
803 803
804 toshiba_acpi.rfk_dev->name = toshiba_acpi.bt_name; 804 toshiba_acpi.rfk_dev->name = toshiba_acpi.bt_name;
805 toshiba_acpi.rfk_dev->toggle_radio = bt_rfkill_toggle_radio; 805 toshiba_acpi.rfk_dev->toggle_radio = bt_rfkill_toggle_radio;
806 toshiba_acpi.rfk_dev->user_claim_unsupported = 1;
807 toshiba_acpi.rfk_dev->data = &toshiba_acpi; 806 toshiba_acpi.rfk_dev->data = &toshiba_acpi;
808 807
809 if (hci_get_bt_on(&bt_on) == HCI_SUCCESS && bt_on) { 808 if (hci_get_bt_on(&bt_on) == HCI_SUCCESS && bt_on) {
diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index 4b501b48ce86..c52e7fba4e40 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -540,7 +540,7 @@ struct ieee80211_tim_ie {
540 u8 dtim_period; 540 u8 dtim_period;
541 u8 bitmap_ctrl; 541 u8 bitmap_ctrl;
542 /* variable size: 1 - 251 bytes */ 542 /* variable size: 1 - 251 bytes */
543 u8 virtual_map[0]; 543 u8 virtual_map[1];
544} __attribute__ ((packed)); 544} __attribute__ ((packed));
545 545
546#define WLAN_SA_QUERY_TR_ID_LEN 16 546#define WLAN_SA_QUERY_TR_ID_LEN 16
@@ -1383,4 +1383,43 @@ static inline int ieee80211_freq_to_ofdm_chan(int s_freq, int freq)
1383 return -1; 1383 return -1;
1384} 1384}
1385 1385
1386/**
1387 * ieee80211_tu_to_usec - convert time units (TU) to microseconds
1388 * @tu: the TUs
1389 */
1390static inline unsigned long ieee80211_tu_to_usec(unsigned long tu)
1391{
1392 return 1024 * tu;
1393}
1394
1395/**
1396 * ieee80211_check_tim - check if AID bit is set in TIM
1397 * @tim: the TIM IE
1398 * @tim_len: length of the TIM IE
1399 * @aid: the AID to look for
1400 */
1401static inline bool ieee80211_check_tim(struct ieee80211_tim_ie *tim,
1402 u8 tim_len, u16 aid)
1403{
1404 u8 mask;
1405 u8 index, indexn1, indexn2;
1406
1407 if (unlikely(!tim || tim_len < sizeof(*tim)))
1408 return false;
1409
1410 aid &= 0x3fff;
1411 index = aid / 8;
1412 mask = 1 << (aid & 7);
1413
1414 indexn1 = tim->bitmap_ctrl & 0xfe;
1415 indexn2 = tim_len + indexn1 - 4;
1416
1417 if (index < indexn1 || index > indexn2)
1418 return false;
1419
1420 index -= indexn1;
1421
1422 return !!(tim->virtual_map[index] & mask);
1423}
1424
1386#endif /* LINUX_IEEE80211_H */ 1425#endif /* LINUX_IEEE80211_H */
diff --git a/include/linux/mmc/sdio_ids.h b/include/linux/mmc/sdio_ids.h
index ea1bf5ba092f..c7211ab6dd4b 100644
--- a/include/linux/mmc/sdio_ids.h
+++ b/include/linux/mmc/sdio_ids.h
@@ -25,5 +25,7 @@
25 25
26#define SDIO_VENDOR_ID_MARVELL 0x02df 26#define SDIO_VENDOR_ID_MARVELL 0x02df
27#define SDIO_DEVICE_ID_MARVELL_LIBERTAS 0x9103 27#define SDIO_DEVICE_ID_MARVELL_LIBERTAS 0x9103
28#define SDIO_DEVICE_ID_MARVELL_8688WLAN 0x9104
29#define SDIO_DEVICE_ID_MARVELL_8688BT 0x9105
28 30
29#endif 31#endif
diff --git a/include/linux/nl80211.h b/include/linux/nl80211.h
index cbe8ce3bf486..e9fd13aa79f0 100644
--- a/include/linux/nl80211.h
+++ b/include/linux/nl80211.h
@@ -7,7 +7,7 @@
7 * Copyright 2008 Michael Wu <flamingice@sourmilk.net> 7 * Copyright 2008 Michael Wu <flamingice@sourmilk.net>
8 * Copyright 2008 Luis Carlos Cobo <luisca@cozybit.com> 8 * Copyright 2008 Luis Carlos Cobo <luisca@cozybit.com>
9 * Copyright 2008 Michael Buesch <mb@bu3sch.de> 9 * Copyright 2008 Michael Buesch <mb@bu3sch.de>
10 * Copyright 2008 Luis R. Rodriguez <lrodriguez@atheros.com> 10 * Copyright 2008, 2009 Luis R. Rodriguez <lrodriguez@atheros.com>
11 * Copyright 2008 Jouni Malinen <jouni.malinen@atheros.com> 11 * Copyright 2008 Jouni Malinen <jouni.malinen@atheros.com>
12 * Copyright 2008 Colin McCabe <colin@cozybit.com> 12 * Copyright 2008 Colin McCabe <colin@cozybit.com>
13 * 13 *
@@ -46,8 +46,10 @@
46 * to get a list of all present wiphys. 46 * to get a list of all present wiphys.
47 * @NL80211_CMD_SET_WIPHY: set wiphy parameters, needs %NL80211_ATTR_WIPHY or 47 * @NL80211_CMD_SET_WIPHY: set wiphy parameters, needs %NL80211_ATTR_WIPHY or
48 * %NL80211_ATTR_IFINDEX; can be used to set %NL80211_ATTR_WIPHY_NAME, 48 * %NL80211_ATTR_IFINDEX; can be used to set %NL80211_ATTR_WIPHY_NAME,
49 * %NL80211_ATTR_WIPHY_TXQ_PARAMS, %NL80211_ATTR_WIPHY_FREQ, and/or 49 * %NL80211_ATTR_WIPHY_TXQ_PARAMS, %NL80211_ATTR_WIPHY_FREQ,
50 * %NL80211_ATTR_WIPHY_CHANNEL_TYPE. 50 * %NL80211_ATTR_WIPHY_CHANNEL_TYPE, %NL80211_ATTR_WIPHY_RETRY_SHORT,
51 * %NL80211_ATTR_WIPHY_RETRY_LONG, %NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
52 * and/or %NL80211_ATTR_WIPHY_RTS_THRESHOLD.
51 * @NL80211_CMD_NEW_WIPHY: Newly created wiphy, response to get request 53 * @NL80211_CMD_NEW_WIPHY: Newly created wiphy, response to get request
52 * or rename notification. Has attributes %NL80211_ATTR_WIPHY and 54 * or rename notification. Has attributes %NL80211_ATTR_WIPHY and
53 * %NL80211_ATTR_WIPHY_NAME. 55 * %NL80211_ATTR_WIPHY_NAME.
@@ -166,6 +168,22 @@
166 * set (%NL80211_ATTR_REG_TYPE), if the type of regulatory domain is 168 * set (%NL80211_ATTR_REG_TYPE), if the type of regulatory domain is
167 * %NL80211_REG_TYPE_COUNTRY the alpha2 to which we have moved on 169 * %NL80211_REG_TYPE_COUNTRY the alpha2 to which we have moved on
168 * to (%NL80211_ATTR_REG_ALPHA2). 170 * to (%NL80211_ATTR_REG_ALPHA2).
171 * @NL80211_CMD_REG_BEACON_HINT: indicates to userspace that an AP beacon
172 * has been found while world roaming thus enabling active scan or
173 * any mode of operation that initiates TX (beacons) on a channel
174 * where we would not have been able to do either before. As an example
175 * if you are world roaming (regulatory domain set to world or if your
176 * driver is using a custom world roaming regulatory domain) and while
177 * doing a passive scan on the 5 GHz band you find an AP there (if not
178 * on a DFS channel) you will now be able to actively scan for that AP
179 * or use AP mode on your card on that same channel. Note that this will
180 * never be used for channels 1-11 on the 2 GHz band as they are always
181 * enabled world wide. This beacon hint is only sent if your device had
182 * either disabled active scanning or beaconing on a channel. We send to
183 * userspace the wiphy on which we removed a restriction from
184 * (%NL80211_ATTR_WIPHY) and the channel on which this occurred
185 * before (%NL80211_ATTR_FREQ_BEFORE) and after (%NL80211_ATTR_FREQ_AFTER)
186 * the beacon hint was processed.
169 * 187 *
170 * @NL80211_CMD_AUTHENTICATE: authentication request and notification. 188 * @NL80211_CMD_AUTHENTICATE: authentication request and notification.
171 * This command is used both as a command (request to authenticate) and 189 * This command is used both as a command (request to authenticate) and
@@ -185,8 +203,12 @@
185 * frame, i.e., it was for the local STA and was received in correct 203 * frame, i.e., it was for the local STA and was received in correct
186 * state. This is similar to MLME-AUTHENTICATE.confirm primitive in the 204 * state. This is similar to MLME-AUTHENTICATE.confirm primitive in the
187 * MLME SAP interface (kernel providing MLME, userspace SME). The 205 * MLME SAP interface (kernel providing MLME, userspace SME). The
188 * included NL80211_ATTR_FRAME attribute contains the management frame 206 * included %NL80211_ATTR_FRAME attribute contains the management frame
189 * (including both the header and frame body, but not FCS). 207 * (including both the header and frame body, but not FCS). This event is
208 * also used to indicate if the authentication attempt timed out. In that
209 * case the %NL80211_ATTR_FRAME attribute is replaced with a
210 * %NL80211_ATTR_TIMED_OUT flag (and %NL80211_ATTR_MAC to indicate which
211 * pending authentication timed out).
190 * @NL80211_CMD_ASSOCIATE: association request and notification; like 212 * @NL80211_CMD_ASSOCIATE: association request and notification; like
191 * NL80211_CMD_AUTHENTICATE but for Association and Reassociation 213 * NL80211_CMD_AUTHENTICATE but for Association and Reassociation
192 * (similar to MLME-ASSOCIATE.request, MLME-REASSOCIATE.request, 214 * (similar to MLME-ASSOCIATE.request, MLME-REASSOCIATE.request,
@@ -199,6 +221,25 @@
199 * NL80211_CMD_AUTHENTICATE but for Disassociation frames (similar to 221 * NL80211_CMD_AUTHENTICATE but for Disassociation frames (similar to
200 * MLME-DISASSOCIATE.request and MLME-DISASSOCIATE.indication primitives). 222 * MLME-DISASSOCIATE.request and MLME-DISASSOCIATE.indication primitives).
201 * 223 *
224 * @NL80211_CMD_MICHAEL_MIC_FAILURE: notification of a locally detected Michael
225 * MIC (part of TKIP) failure; sent on the "mlme" multicast group; the
226 * event includes %NL80211_ATTR_MAC to describe the source MAC address of
227 * the frame with invalid MIC, %NL80211_ATTR_KEY_TYPE to show the key
228 * type, %NL80211_ATTR_KEY_IDX to indicate the key identifier, and
229 * %NL80211_ATTR_KEY_SEQ to indicate the TSC value of the frame; this
230 * event matches with MLME-MICHAELMICFAILURE.indication() primitive
231 *
232 * @NL80211_CMD_JOIN_IBSS: Join a new IBSS -- given at least an SSID and a
233 * FREQ attribute (for the initial frequency if no peer can be found)
234 * and optionally a MAC (as BSSID) and FREQ_FIXED attribute if those
235 * should be fixed rather than automatically determined. Can only be
236 * executed on a network interface that is UP, and fixed BSSID/FREQ
237 * may be rejected. Another optional parameter is the beacon interval,
238 * given in the %NL80211_ATTR_BEACON_INTERVAL attribute, which if not
239 * given defaults to 100 TU (102.4ms).
240 * @NL80211_CMD_LEAVE_IBSS: Leave the IBSS -- no special arguments, the IBSS is
241 * determined by the network interface.
242 *
202 * @NL80211_CMD_MAX: highest used command number 243 * @NL80211_CMD_MAX: highest used command number
203 * @__NL80211_CMD_AFTER_LAST: internal use 244 * @__NL80211_CMD_AFTER_LAST: internal use
204 */ 245 */
@@ -260,6 +301,13 @@ enum nl80211_commands {
260 NL80211_CMD_DEAUTHENTICATE, 301 NL80211_CMD_DEAUTHENTICATE,
261 NL80211_CMD_DISASSOCIATE, 302 NL80211_CMD_DISASSOCIATE,
262 303
304 NL80211_CMD_MICHAEL_MIC_FAILURE,
305
306 NL80211_CMD_REG_BEACON_HINT,
307
308 NL80211_CMD_JOIN_IBSS,
309 NL80211_CMD_LEAVE_IBSS,
310
263 /* add new commands above here */ 311 /* add new commands above here */
264 312
265 /* used to define NL80211_CMD_MAX below */ 313 /* used to define NL80211_CMD_MAX below */
@@ -278,6 +326,7 @@ enum nl80211_commands {
278#define NL80211_CMD_ASSOCIATE NL80211_CMD_ASSOCIATE 326#define NL80211_CMD_ASSOCIATE NL80211_CMD_ASSOCIATE
279#define NL80211_CMD_DEAUTHENTICATE NL80211_CMD_DEAUTHENTICATE 327#define NL80211_CMD_DEAUTHENTICATE NL80211_CMD_DEAUTHENTICATE
280#define NL80211_CMD_DISASSOCIATE NL80211_CMD_DISASSOCIATE 328#define NL80211_CMD_DISASSOCIATE NL80211_CMD_DISASSOCIATE
329#define NL80211_CMD_REG_BEACON_HINT NL80211_CMD_REG_BEACON_HINT
281 330
282/** 331/**
283 * enum nl80211_attrs - nl80211 netlink attributes 332 * enum nl80211_attrs - nl80211 netlink attributes
@@ -296,6 +345,18 @@ enum nl80211_commands {
296 * NL80211_CHAN_HT20 = HT20 only 345 * NL80211_CHAN_HT20 = HT20 only
297 * NL80211_CHAN_HT40MINUS = secondary channel is below the primary channel 346 * NL80211_CHAN_HT40MINUS = secondary channel is below the primary channel
298 * NL80211_CHAN_HT40PLUS = secondary channel is above the primary channel 347 * NL80211_CHAN_HT40PLUS = secondary channel is above the primary channel
348 * @NL80211_ATTR_WIPHY_RETRY_SHORT: TX retry limit for frames whose length is
349 * less than or equal to the RTS threshold; allowed range: 1..255;
350 * dot11ShortRetryLimit; u8
351 * @NL80211_ATTR_WIPHY_RETRY_LONG: TX retry limit for frames whose length is
352 * greater than the RTS threshold; allowed range: 1..255;
353 * dot11ShortLongLimit; u8
354 * @NL80211_ATTR_WIPHY_FRAG_THRESHOLD: fragmentation threshold, i.e., maximum
355 * length in octets for frames; allowed range: 256..8000, disable
356 * fragmentation with (u32)-1; dot11FragmentationThreshold; u32
357 * @NL80211_ATTR_WIPHY_RTS_THRESHOLD: RTS threshold (TX frames with length
358 * larger than or equal to this use RTS/CTS handshake); allowed range:
359 * 0..65536, disable with (u32)-1; dot11RTSThreshold; u32
299 * 360 *
300 * @NL80211_ATTR_IFINDEX: network interface index of the device to operate on 361 * @NL80211_ATTR_IFINDEX: network interface index of the device to operate on
301 * @NL80211_ATTR_IFNAME: network interface name 362 * @NL80211_ATTR_IFNAME: network interface name
@@ -380,6 +441,8 @@ enum nl80211_commands {
380 * 441 *
381 * @NL80211_ATTR_MAX_NUM_SCAN_SSIDS: number of SSIDs you can scan with 442 * @NL80211_ATTR_MAX_NUM_SCAN_SSIDS: number of SSIDs you can scan with
382 * a single scan request, a wiphy attribute. 443 * a single scan request, a wiphy attribute.
444 * @NL80211_ATTR_MAX_SCAN_IE_LEN: maximum length of information elements
445 * that can be added to a scan request
383 * 446 *
384 * @NL80211_ATTR_SCAN_FREQUENCIES: nested attribute with frequencies (in MHz) 447 * @NL80211_ATTR_SCAN_FREQUENCIES: nested attribute with frequencies (in MHz)
385 * @NL80211_ATTR_SCAN_SSIDS: nested attribute with SSIDs, leave out for passive 448 * @NL80211_ATTR_SCAN_SSIDS: nested attribute with SSIDs, leave out for passive
@@ -408,6 +471,29 @@ enum nl80211_commands {
408 * @NL80211_ATTR_REASON_CODE: ReasonCode for %NL80211_CMD_DEAUTHENTICATE and 471 * @NL80211_ATTR_REASON_CODE: ReasonCode for %NL80211_CMD_DEAUTHENTICATE and
409 * %NL80211_CMD_DISASSOCIATE, u16 472 * %NL80211_CMD_DISASSOCIATE, u16
410 * 473 *
474 * @NL80211_ATTR_KEY_TYPE: Key Type, see &enum nl80211_key_type, represented as
475 * a u32
476 *
477 * @NL80211_ATTR_FREQ_BEFORE: A channel which has suffered a regulatory change
478 * due to considerations from a beacon hint. This attribute reflects
479 * the state of the channel _before_ the beacon hint processing. This
480 * attributes consists of a nested attribute containing
481 * NL80211_FREQUENCY_ATTR_*
482 * @NL80211_ATTR_FREQ_AFTER: A channel which has suffered a regulatory change
483 * due to considerations from a beacon hint. This attribute reflects
484 * the state of the channel _after_ the beacon hint processing. This
485 * attributes consists of a nested attribute containing
486 * NL80211_FREQUENCY_ATTR_*
487 *
488 * @NL80211_ATTR_CIPHER_SUITES: a set of u32 values indicating the supported
489 * cipher suites
490 *
491 * @NL80211_ATTR_FREQ_FIXED: a flag indicating the IBSS should not try to look
492 * for other networks on different channels
493 *
494 * @NL80211_ATTR_TIMED_OUT: a flag indicating than an operation timed out; this
495 * is used, e.g., with %NL80211_CMD_AUTHENTICATE event
496 *
411 * @NL80211_ATTR_MAX: highest attribute number currently defined 497 * @NL80211_ATTR_MAX: highest attribute number currently defined
412 * @__NL80211_ATTR_AFTER_LAST: internal use 498 * @__NL80211_ATTR_AFTER_LAST: internal use
413 */ 499 */
@@ -492,6 +578,24 @@ enum nl80211_attrs {
492 NL80211_ATTR_AUTH_TYPE, 578 NL80211_ATTR_AUTH_TYPE,
493 NL80211_ATTR_REASON_CODE, 579 NL80211_ATTR_REASON_CODE,
494 580
581 NL80211_ATTR_KEY_TYPE,
582
583 NL80211_ATTR_MAX_SCAN_IE_LEN,
584 NL80211_ATTR_CIPHER_SUITES,
585
586 NL80211_ATTR_FREQ_BEFORE,
587 NL80211_ATTR_FREQ_AFTER,
588
589 NL80211_ATTR_FREQ_FIXED,
590
591
592 NL80211_ATTR_WIPHY_RETRY_SHORT,
593 NL80211_ATTR_WIPHY_RETRY_LONG,
594 NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
595 NL80211_ATTR_WIPHY_RTS_THRESHOLD,
596
597 NL80211_ATTR_TIMED_OUT,
598
495 /* add attributes here, update the policy in nl80211.c */ 599 /* add attributes here, update the policy in nl80211.c */
496 600
497 __NL80211_ATTR_AFTER_LAST, 601 __NL80211_ATTR_AFTER_LAST,
@@ -1062,4 +1166,17 @@ enum nl80211_auth_type {
1062 NL80211_AUTHTYPE_FT, 1166 NL80211_AUTHTYPE_FT,
1063 NL80211_AUTHTYPE_NETWORK_EAP, 1167 NL80211_AUTHTYPE_NETWORK_EAP,
1064}; 1168};
1169
1170/**
1171 * enum nl80211_key_type - Key Type
1172 * @NL80211_KEYTYPE_GROUP: Group (broadcast/multicast) key
1173 * @NL80211_KEYTYPE_PAIRWISE: Pairwise (unicast/individual) key
1174 * @NL80211_KEYTYPE_PEERKEY: PeerKey (DLS)
1175 */
1176enum nl80211_key_type {
1177 NL80211_KEYTYPE_GROUP,
1178 NL80211_KEYTYPE_PAIRWISE,
1179 NL80211_KEYTYPE_PEERKEY,
1180};
1181
1065#endif /* __LINUX_NL80211_H */ 1182#endif /* __LINUX_NL80211_H */
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index ee98cd570885..ea061e290d02 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -2313,6 +2313,8 @@
2313 2313
2314#define PCI_VENDOR_ID_QMI 0x1a32 2314#define PCI_VENDOR_ID_QMI 0x1a32
2315 2315
2316#define PCI_VENDOR_ID_AZWAVE 0x1a3b
2317
2316#define PCI_VENDOR_ID_TEKRAM 0x1de1 2318#define PCI_VENDOR_ID_TEKRAM 0x1de1
2317#define PCI_DEVICE_ID_TEKRAM_DC290 0xdc29 2319#define PCI_DEVICE_ID_TEKRAM_DC290 0xdc29
2318 2320
diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
index 164332cbb77c..de18ef227e00 100644
--- a/include/linux/rfkill.h
+++ b/include/linux/rfkill.h
@@ -52,23 +52,12 @@ enum rfkill_state {
52 RFKILL_STATE_MAX, /* marker for last valid state */ 52 RFKILL_STATE_MAX, /* marker for last valid state */
53}; 53};
54 54
55/*
56 * These are DEPRECATED, drivers using them should be verified to
57 * comply with the rfkill usage guidelines in Documentation/rfkill.txt
58 * and then converted to use the new names for rfkill_state
59 */
60#define RFKILL_STATE_OFF RFKILL_STATE_SOFT_BLOCKED
61#define RFKILL_STATE_ON RFKILL_STATE_UNBLOCKED
62
63/** 55/**
64 * struct rfkill - rfkill control structure. 56 * struct rfkill - rfkill control structure.
65 * @name: Name of the switch. 57 * @name: Name of the switch.
66 * @type: Radio type which the button controls, the value stored 58 * @type: Radio type which the button controls, the value stored
67 * here should be a value from enum rfkill_type. 59 * here should be a value from enum rfkill_type.
68 * @state: State of the switch, "UNBLOCKED" means radio can operate. 60 * @state: State of the switch, "UNBLOCKED" means radio can operate.
69 * @user_claim_unsupported: Whether the hardware supports exclusive
70 * RF-kill control by userspace. Set this before registering.
71 * @user_claim: Set when the switch is controlled exlusively by userspace.
72 * @mutex: Guards switch state transitions. It serializes callbacks 61 * @mutex: Guards switch state transitions. It serializes callbacks
73 * and also protects the state. 62 * and also protects the state.
74 * @data: Pointer to the RF button drivers private data which will be 63 * @data: Pointer to the RF button drivers private data which will be
@@ -91,9 +80,6 @@ struct rfkill {
91 const char *name; 80 const char *name;
92 enum rfkill_type type; 81 enum rfkill_type type;
93 82
94 bool user_claim_unsupported;
95 bool user_claim;
96
97 /* the mutex serializes callbacks and also protects 83 /* the mutex serializes callbacks and also protects
98 * the state */ 84 * the state */
99 struct mutex mutex; 85 struct mutex mutex;
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 5389afdc1297..b8a76764e1c5 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -1,71 +1,217 @@
1#ifndef __NET_CFG80211_H 1#ifndef __NET_CFG80211_H
2#define __NET_CFG80211_H 2#define __NET_CFG80211_H
3/*
4 * 802.11 device and configuration interface
5 *
6 * Copyright 2006-2009 Johannes Berg <johannes@sipsolutions.net>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
3 12
13#include <linux/netdevice.h>
14#include <linux/debugfs.h>
15#include <linux/list.h>
4#include <linux/netlink.h> 16#include <linux/netlink.h>
5#include <linux/skbuff.h> 17#include <linux/skbuff.h>
6#include <linux/nl80211.h> 18#include <linux/nl80211.h>
7#include <linux/if_ether.h> 19#include <linux/if_ether.h>
8#include <linux/ieee80211.h> 20#include <linux/ieee80211.h>
9#include <linux/wireless.h> 21#include <net/regulatory.h>
10#include <net/iw_handler.h> 22
11#include <net/genetlink.h>
12/* remove once we remove the wext stuff */ 23/* remove once we remove the wext stuff */
13#include <net/iw_handler.h> 24#include <net/iw_handler.h>
25#include <linux/wireless.h>
26
14 27
15/* 28/*
16 * 802.11 configuration in-kernel interface 29 * wireless hardware capability structures
30 */
31
32/**
33 * enum ieee80211_band - supported frequency bands
34 *
35 * The bands are assigned this way because the supported
36 * bitrates differ in these bands.
17 * 37 *
18 * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net> 38 * @IEEE80211_BAND_2GHZ: 2.4GHz ISM band
39 * @IEEE80211_BAND_5GHZ: around 5GHz band (4.9-5.7)
19 */ 40 */
41enum ieee80211_band {
42 IEEE80211_BAND_2GHZ,
43 IEEE80211_BAND_5GHZ,
44
45 /* keep last */
46 IEEE80211_NUM_BANDS
47};
20 48
21/** 49/**
22 * struct vif_params - describes virtual interface parameters 50 * enum ieee80211_channel_flags - channel flags
23 * @mesh_id: mesh ID to use 51 *
24 * @mesh_id_len: length of the mesh ID 52 * Channel flags set by the regulatory control code.
53 *
54 * @IEEE80211_CHAN_DISABLED: This channel is disabled.
55 * @IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
56 * on this channel.
57 * @IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
58 * @IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
59 * @IEEE80211_CHAN_NO_FAT_ABOVE: extension channel above this channel
60 * is not permitted.
61 * @IEEE80211_CHAN_NO_FAT_BELOW: extension channel below this channel
62 * is not permitted.
25 */ 63 */
26struct vif_params { 64enum ieee80211_channel_flags {
27 u8 *mesh_id; 65 IEEE80211_CHAN_DISABLED = 1<<0,
28 int mesh_id_len; 66 IEEE80211_CHAN_PASSIVE_SCAN = 1<<1,
67 IEEE80211_CHAN_NO_IBSS = 1<<2,
68 IEEE80211_CHAN_RADAR = 1<<3,
69 IEEE80211_CHAN_NO_FAT_ABOVE = 1<<4,
70 IEEE80211_CHAN_NO_FAT_BELOW = 1<<5,
29}; 71};
30 72
31/* Radiotap header iteration 73/**
32 * implemented in net/wireless/radiotap.c 74 * struct ieee80211_channel - channel definition
33 * docs in Documentation/networking/radiotap-headers.txt 75 *
76 * This structure describes a single channel for use
77 * with cfg80211.
78 *
79 * @center_freq: center frequency in MHz
80 * @max_bandwidth: maximum allowed bandwidth for this channel, in MHz
81 * @hw_value: hardware-specific value for the channel
82 * @flags: channel flags from &enum ieee80211_channel_flags.
83 * @orig_flags: channel flags at registration time, used by regulatory
84 * code to support devices with additional restrictions
85 * @band: band this channel belongs to.
86 * @max_antenna_gain: maximum antenna gain in dBi
87 * @max_power: maximum transmission power (in dBm)
88 * @beacon_found: helper to regulatory code to indicate when a beacon
89 * has been found on this channel. Use regulatory_hint_found_beacon()
90 * to enable this, this is is useful only on 5 GHz band.
91 * @orig_mag: internal use
92 * @orig_mpwr: internal use
34 */ 93 */
94struct ieee80211_channel {
95 enum ieee80211_band band;
96 u16 center_freq;
97 u8 max_bandwidth;
98 u16 hw_value;
99 u32 flags;
100 int max_antenna_gain;
101 int max_power;
102 bool beacon_found;
103 u32 orig_flags;
104 int orig_mag, orig_mpwr;
105};
106
35/** 107/**
36 * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args 108 * enum ieee80211_rate_flags - rate flags
37 * @rtheader: pointer to the radiotap header we are walking through 109 *
38 * @max_length: length of radiotap header in cpu byte ordering 110 * Hardware/specification flags for rates. These are structured
39 * @this_arg_index: IEEE80211_RADIOTAP_... index of current arg 111 * in a way that allows using the same bitrate structure for
40 * @this_arg: pointer to current radiotap arg 112 * different bands/PHY modes.
41 * @arg_index: internal next argument index 113 *
42 * @arg: internal next argument pointer 114 * @IEEE80211_RATE_SHORT_PREAMBLE: Hardware can send with short
43 * @next_bitmap: internal pointer to next present u32 115 * preamble on this bitrate; only relevant in 2.4GHz band and
44 * @bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present 116 * with CCK rates.
117 * @IEEE80211_RATE_MANDATORY_A: This bitrate is a mandatory rate
118 * when used with 802.11a (on the 5 GHz band); filled by the
119 * core code when registering the wiphy.
120 * @IEEE80211_RATE_MANDATORY_B: This bitrate is a mandatory rate
121 * when used with 802.11b (on the 2.4 GHz band); filled by the
122 * core code when registering the wiphy.
123 * @IEEE80211_RATE_MANDATORY_G: This bitrate is a mandatory rate
124 * when used with 802.11g (on the 2.4 GHz band); filled by the
125 * core code when registering the wiphy.
126 * @IEEE80211_RATE_ERP_G: This is an ERP rate in 802.11g mode.
45 */ 127 */
128enum ieee80211_rate_flags {
129 IEEE80211_RATE_SHORT_PREAMBLE = 1<<0,
130 IEEE80211_RATE_MANDATORY_A = 1<<1,
131 IEEE80211_RATE_MANDATORY_B = 1<<2,
132 IEEE80211_RATE_MANDATORY_G = 1<<3,
133 IEEE80211_RATE_ERP_G = 1<<4,
134};
46 135
47struct ieee80211_radiotap_iterator { 136/**
48 struct ieee80211_radiotap_header *rtheader; 137 * struct ieee80211_rate - bitrate definition
49 int max_length; 138 *
50 int this_arg_index; 139 * This structure describes a bitrate that an 802.11 PHY can
51 u8 *this_arg; 140 * operate with. The two values @hw_value and @hw_value_short
141 * are only for driver use when pointers to this structure are
142 * passed around.
143 *
144 * @flags: rate-specific flags
145 * @bitrate: bitrate in units of 100 Kbps
146 * @hw_value: driver/hardware value for this rate
147 * @hw_value_short: driver/hardware value for this rate when
148 * short preamble is used
149 */
150struct ieee80211_rate {
151 u32 flags;
152 u16 bitrate;
153 u16 hw_value, hw_value_short;
154};
52 155
53 int arg_index; 156/**
54 u8 *arg; 157 * struct ieee80211_sta_ht_cap - STA's HT capabilities
55 __le32 *next_bitmap; 158 *
56 u32 bitmap_shifter; 159 * This structure describes most essential parameters needed
160 * to describe 802.11n HT capabilities for an STA.
161 *
162 * @ht_supported: is HT supported by the STA
163 * @cap: HT capabilities map as described in 802.11n spec
164 * @ampdu_factor: Maximum A-MPDU length factor
165 * @ampdu_density: Minimum A-MPDU spacing
166 * @mcs: Supported MCS rates
167 */
168struct ieee80211_sta_ht_cap {
169 u16 cap; /* use IEEE80211_HT_CAP_ */
170 bool ht_supported;
171 u8 ampdu_factor;
172 u8 ampdu_density;
173 struct ieee80211_mcs_info mcs;
57}; 174};
58 175
59extern int ieee80211_radiotap_iterator_init( 176/**
60 struct ieee80211_radiotap_iterator *iterator, 177 * struct ieee80211_supported_band - frequency band definition
61 struct ieee80211_radiotap_header *radiotap_header, 178 *
62 int max_length); 179 * This structure describes a frequency band a wiphy
180 * is able to operate in.
181 *
182 * @channels: Array of channels the hardware can operate in
183 * in this band.
184 * @band: the band this structure represents
185 * @n_channels: Number of channels in @channels
186 * @bitrates: Array of bitrates the hardware can operate with
187 * in this band. Must be sorted to give a valid "supported
188 * rates" IE, i.e. CCK rates first, then OFDM.
189 * @n_bitrates: Number of bitrates in @bitrates
190 */
191struct ieee80211_supported_band {
192 struct ieee80211_channel *channels;
193 struct ieee80211_rate *bitrates;
194 enum ieee80211_band band;
195 int n_channels;
196 int n_bitrates;
197 struct ieee80211_sta_ht_cap ht_cap;
198};
63 199
64extern int ieee80211_radiotap_iterator_next( 200/*
65 struct ieee80211_radiotap_iterator *iterator); 201 * Wireless hardware/device configuration structures and methods
202 */
66 203
204/**
205 * struct vif_params - describes virtual interface parameters
206 * @mesh_id: mesh ID to use
207 * @mesh_id_len: length of the mesh ID
208 */
209struct vif_params {
210 u8 *mesh_id;
211 int mesh_id_len;
212};
67 213
68 /** 214/**
69 * struct key_params - key information 215 * struct key_params - key information
70 * 216 *
71 * Information about a key 217 * Information about a key
@@ -348,92 +494,6 @@ struct bss_parameters {
348 u8 basic_rates_len; 494 u8 basic_rates_len;
349}; 495};
350 496
351/**
352 * enum environment_cap - Environment parsed from country IE
353 * @ENVIRON_ANY: indicates country IE applies to both indoor and
354 * outdoor operation.
355 * @ENVIRON_INDOOR: indicates country IE applies only to indoor operation
356 * @ENVIRON_OUTDOOR: indicates country IE applies only to outdoor operation
357 */
358enum environment_cap {
359 ENVIRON_ANY,
360 ENVIRON_INDOOR,
361 ENVIRON_OUTDOOR,
362};
363
364/**
365 * struct regulatory_request - used to keep track of regulatory requests
366 *
367 * @wiphy_idx: this is set if this request's initiator is
368 * %REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
369 * can be used by the wireless core to deal with conflicts
370 * and potentially inform users of which devices specifically
371 * cased the conflicts.
372 * @initiator: indicates who sent this request, could be any of
373 * of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*)
374 * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
375 * regulatory domain. We have a few special codes:
376 * 00 - World regulatory domain
377 * 99 - built by driver but a specific alpha2 cannot be determined
378 * 98 - result of an intersection between two regulatory domains
379 * @intersect: indicates whether the wireless core should intersect
380 * the requested regulatory domain with the presently set regulatory
381 * domain.
382 * @country_ie_checksum: checksum of the last processed and accepted
383 * country IE
384 * @country_ie_env: lets us know if the AP is telling us we are outdoor,
385 * indoor, or if it doesn't matter
386 * @list: used to insert into the reg_requests_list linked list
387 */
388struct regulatory_request {
389 int wiphy_idx;
390 enum nl80211_reg_initiator initiator;
391 char alpha2[2];
392 bool intersect;
393 u32 country_ie_checksum;
394 enum environment_cap country_ie_env;
395 struct list_head list;
396};
397
398struct ieee80211_freq_range {
399 u32 start_freq_khz;
400 u32 end_freq_khz;
401 u32 max_bandwidth_khz;
402};
403
404struct ieee80211_power_rule {
405 u32 max_antenna_gain;
406 u32 max_eirp;
407};
408
409struct ieee80211_reg_rule {
410 struct ieee80211_freq_range freq_range;
411 struct ieee80211_power_rule power_rule;
412 u32 flags;
413};
414
415struct ieee80211_regdomain {
416 u32 n_reg_rules;
417 char alpha2[2];
418 struct ieee80211_reg_rule reg_rules[];
419};
420
421#define MHZ_TO_KHZ(freq) ((freq) * 1000)
422#define KHZ_TO_MHZ(freq) ((freq) / 1000)
423#define DBI_TO_MBI(gain) ((gain) * 100)
424#define MBI_TO_DBI(gain) ((gain) / 100)
425#define DBM_TO_MBM(gain) ((gain) * 100)
426#define MBM_TO_DBM(gain) ((gain) / 100)
427
428#define REG_RULE(start, end, bw, gain, eirp, reg_flags) { \
429 .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
430 .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
431 .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
432 .power_rule.max_antenna_gain = DBI_TO_MBI(gain), \
433 .power_rule.max_eirp = DBM_TO_MBM(eirp), \
434 .flags = reg_flags, \
435 }
436
437struct mesh_config { 497struct mesh_config {
438 /* Timeouts in ms */ 498 /* Timeouts in ms */
439 /* Mesh plink management parameters */ 499 /* Mesh plink management parameters */
@@ -504,7 +564,7 @@ struct cfg80211_scan_request {
504 int n_ssids; 564 int n_ssids;
505 struct ieee80211_channel **channels; 565 struct ieee80211_channel **channels;
506 u32 n_channels; 566 u32 n_channels;
507 u8 *ie; 567 const u8 *ie;
508 size_t ie_len; 568 size_t ie_len;
509 569
510 /* internal */ 570 /* internal */
@@ -659,6 +719,47 @@ struct cfg80211_disassoc_request {
659}; 719};
660 720
661/** 721/**
722 * struct cfg80211_ibss_params - IBSS parameters
723 *
724 * This structure defines the IBSS parameters for the join_ibss()
725 * method.
726 *
727 * @ssid: The SSID, will always be non-null.
728 * @ssid_len: The length of the SSID, will always be non-zero.
729 * @bssid: Fixed BSSID requested, maybe be %NULL, if set do not
730 * search for IBSSs with a different BSSID.
731 * @channel: The channel to use if no IBSS can be found to join.
732 * @channel_fixed: The channel should be fixed -- do not search for
733 * IBSSs to join on other channels.
734 * @ie: information element(s) to include in the beacon
735 * @ie_len: length of that
736 * @beacon_interval: beacon interval to use
737 */
738struct cfg80211_ibss_params {
739 u8 *ssid;
740 u8 *bssid;
741 struct ieee80211_channel *channel;
742 u8 *ie;
743 u8 ssid_len, ie_len;
744 u16 beacon_interval;
745 bool channel_fixed;
746};
747
748/**
749 * enum wiphy_params_flags - set_wiphy_params bitfield values
750 * WIPHY_PARAM_RETRY_SHORT: wiphy->retry_short has changed
751 * WIPHY_PARAM_RETRY_LONG: wiphy->retry_long has changed
752 * WIPHY_PARAM_FRAG_THRESHOLD: wiphy->frag_threshold has changed
753 * WIPHY_PARAM_RTS_THRESHOLD: wiphy->rts_threshold has changed
754 */
755enum wiphy_params_flags {
756 WIPHY_PARAM_RETRY_SHORT = 1 << 0,
757 WIPHY_PARAM_RETRY_LONG = 1 << 1,
758 WIPHY_PARAM_FRAG_THRESHOLD = 1 << 2,
759 WIPHY_PARAM_RTS_THRESHOLD = 1 << 3,
760};
761
762/**
662 * struct cfg80211_ops - backend description for wireless configuration 763 * struct cfg80211_ops - backend description for wireless configuration
663 * 764 *
664 * This struct is registered by fullmac card drivers and/or wireless stacks 765 * This struct is registered by fullmac card drivers and/or wireless stacks
@@ -733,6 +834,16 @@ struct cfg80211_disassoc_request {
733 * @assoc: Request to (re)associate with the specified peer 834 * @assoc: Request to (re)associate with the specified peer
734 * @deauth: Request to deauthenticate from the specified peer 835 * @deauth: Request to deauthenticate from the specified peer
735 * @disassoc: Request to disassociate from the specified peer 836 * @disassoc: Request to disassociate from the specified peer
837 *
838 * @join_ibss: Join the specified IBSS (or create if necessary). Once done, call
839 * cfg80211_ibss_joined(), also call that function when changing BSSID due
840 * to a merge.
841 * @leave_ibss: Leave the IBSS.
842 *
843 * @set_wiphy_params: Notify that wiphy parameters have changed;
844 * @changed bitfield (see &enum wiphy_params_flags) describes which values
845 * have changed. The actual parameter values are available in
846 * struct wiphy. If returning an error, no value should be changed.
736 */ 847 */
737struct cfg80211_ops { 848struct cfg80211_ops {
738 int (*suspend)(struct wiphy *wiphy); 849 int (*suspend)(struct wiphy *wiphy);
@@ -818,9 +929,414 @@ struct cfg80211_ops {
818 struct cfg80211_deauth_request *req); 929 struct cfg80211_deauth_request *req);
819 int (*disassoc)(struct wiphy *wiphy, struct net_device *dev, 930 int (*disassoc)(struct wiphy *wiphy, struct net_device *dev,
820 struct cfg80211_disassoc_request *req); 931 struct cfg80211_disassoc_request *req);
932
933 int (*join_ibss)(struct wiphy *wiphy, struct net_device *dev,
934 struct cfg80211_ibss_params *params);
935 int (*leave_ibss)(struct wiphy *wiphy, struct net_device *dev);
936
937 int (*set_wiphy_params)(struct wiphy *wiphy, u32 changed);
938};
939
940/*
941 * wireless hardware and networking interfaces structures
942 * and registration/helper functions
943 */
944
945/**
946 * struct wiphy - wireless hardware description
947 * @idx: the wiphy index assigned to this item
948 * @class_dev: the class device representing /sys/class/ieee80211/<wiphy-name>
949 * @custom_regulatory: tells us the driver for this device
950 * has its own custom regulatory domain and cannot identify the
951 * ISO / IEC 3166 alpha2 it belongs to. When this is enabled
952 * we will disregard the first regulatory hint (when the
953 * initiator is %REGDOM_SET_BY_CORE).
954 * @strict_regulatory: tells us the driver for this device will ignore
955 * regulatory domain settings until it gets its own regulatory domain
956 * via its regulatory_hint(). After its gets its own regulatory domain
957 * it will only allow further regulatory domain settings to further
958 * enhance compliance. For example if channel 13 and 14 are disabled
959 * by this regulatory domain no user regulatory domain can enable these
960 * channels at a later time. This can be used for devices which do not
961 * have calibration information gauranteed for frequencies or settings
962 * outside of its regulatory domain.
963 * @reg_notifier: the driver's regulatory notification callback
964 * @regd: the driver's regulatory domain, if one was requested via
965 * the regulatory_hint() API. This can be used by the driver
966 * on the reg_notifier() if it chooses to ignore future
967 * regulatory domain changes caused by other drivers.
968 * @signal_type: signal type reported in &struct cfg80211_bss.
969 * @cipher_suites: supported cipher suites
970 * @n_cipher_suites: number of supported cipher suites
971 * @retry_short: Retry limit for short frames (dot11ShortRetryLimit)
972 * @retry_long: Retry limit for long frames (dot11LongRetryLimit)
973 * @frag_threshold: Fragmentation threshold (dot11FragmentationThreshold);
974 * -1 = fragmentation disabled, only odd values >= 256 used
975 * @rts_threshold: RTS threshold (dot11RTSThreshold); -1 = RTS/CTS disabled
976 */
977struct wiphy {
978 /* assign these fields before you register the wiphy */
979
980 /* permanent MAC address */
981 u8 perm_addr[ETH_ALEN];
982
983 /* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */
984 u16 interface_modes;
985
986 bool custom_regulatory;
987 bool strict_regulatory;
988
989 enum cfg80211_signal_type signal_type;
990
991 int bss_priv_size;
992 u8 max_scan_ssids;
993 u16 max_scan_ie_len;
994
995 int n_cipher_suites;
996 const u32 *cipher_suites;
997
998 u8 retry_short;
999 u8 retry_long;
1000 u32 frag_threshold;
1001 u32 rts_threshold;
1002
1003 /* If multiple wiphys are registered and you're handed e.g.
1004 * a regular netdev with assigned ieee80211_ptr, you won't
1005 * know whether it points to a wiphy your driver has registered
1006 * or not. Assign this to something global to your driver to
1007 * help determine whether you own this wiphy or not. */
1008 void *privid;
1009
1010 struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
1011
1012 /* Lets us get back the wiphy on the callback */
1013 int (*reg_notifier)(struct wiphy *wiphy,
1014 struct regulatory_request *request);
1015
1016 /* fields below are read-only, assigned by cfg80211 */
1017
1018 const struct ieee80211_regdomain *regd;
1019
1020 /* the item in /sys/class/ieee80211/ points to this,
1021 * you need use set_wiphy_dev() (see below) */
1022 struct device dev;
1023
1024 /* dir in debugfs: ieee80211/<wiphyname> */
1025 struct dentry *debugfsdir;
1026
1027 char priv[0] __attribute__((__aligned__(NETDEV_ALIGN)));
1028};
1029
1030/**
1031 * wiphy_priv - return priv from wiphy
1032 *
1033 * @wiphy: the wiphy whose priv pointer to return
1034 */
1035static inline void *wiphy_priv(struct wiphy *wiphy)
1036{
1037 BUG_ON(!wiphy);
1038 return &wiphy->priv;
1039}
1040
1041/**
1042 * set_wiphy_dev - set device pointer for wiphy
1043 *
1044 * @wiphy: The wiphy whose device to bind
1045 * @dev: The device to parent it to
1046 */
1047static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
1048{
1049 wiphy->dev.parent = dev;
1050}
1051
1052/**
1053 * wiphy_dev - get wiphy dev pointer
1054 *
1055 * @wiphy: The wiphy whose device struct to look up
1056 */
1057static inline struct device *wiphy_dev(struct wiphy *wiphy)
1058{
1059 return wiphy->dev.parent;
1060}
1061
1062/**
1063 * wiphy_name - get wiphy name
1064 *
1065 * @wiphy: The wiphy whose name to return
1066 */
1067static inline const char *wiphy_name(struct wiphy *wiphy)
1068{
1069 return dev_name(&wiphy->dev);
1070}
1071
1072/**
1073 * wiphy_new - create a new wiphy for use with cfg80211
1074 *
1075 * @ops: The configuration operations for this device
1076 * @sizeof_priv: The size of the private area to allocate
1077 *
1078 * Create a new wiphy and associate the given operations with it.
1079 * @sizeof_priv bytes are allocated for private use.
1080 *
1081 * The returned pointer must be assigned to each netdev's
1082 * ieee80211_ptr for proper operation.
1083 */
1084struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
1085
1086/**
1087 * wiphy_register - register a wiphy with cfg80211
1088 *
1089 * @wiphy: The wiphy to register.
1090 *
1091 * Returns a non-negative wiphy index or a negative error code.
1092 */
1093extern int wiphy_register(struct wiphy *wiphy);
1094
1095/**
1096 * wiphy_unregister - deregister a wiphy from cfg80211
1097 *
1098 * @wiphy: The wiphy to unregister.
1099 *
1100 * After this call, no more requests can be made with this priv
1101 * pointer, but the call may sleep to wait for an outstanding
1102 * request that is being handled.
1103 */
1104extern void wiphy_unregister(struct wiphy *wiphy);
1105
1106/**
1107 * wiphy_free - free wiphy
1108 *
1109 * @wiphy: The wiphy to free
1110 */
1111extern void wiphy_free(struct wiphy *wiphy);
1112
1113/**
1114 * struct wireless_dev - wireless per-netdev state
1115 *
1116 * This structure must be allocated by the driver/stack
1117 * that uses the ieee80211_ptr field in struct net_device
1118 * (this is intentional so it can be allocated along with
1119 * the netdev.)
1120 *
1121 * @wiphy: pointer to hardware description
1122 * @iftype: interface type
1123 * @list: (private) Used to collect the interfaces
1124 * @netdev: (private) Used to reference back to the netdev
1125 * @current_bss: (private) Used by the internal configuration code
1126 * @bssid: (private) Used by the internal configuration code
1127 * @ssid: (private) Used by the internal configuration code
1128 * @ssid_len: (private) Used by the internal configuration code
1129 * @wext: (private) Used by the internal wireless extensions compat code
1130 * @wext_bssid: (private) Used by the internal wireless extensions compat code
1131 */
1132struct wireless_dev {
1133 struct wiphy *wiphy;
1134 enum nl80211_iftype iftype;
1135
1136 /* private to the generic wireless code */
1137 struct list_head list;
1138 struct net_device *netdev;
1139
1140 /* currently used for IBSS - might be rearranged in the future */
1141 struct cfg80211_bss *current_bss;
1142 u8 bssid[ETH_ALEN];
1143 u8 ssid[IEEE80211_MAX_SSID_LEN];
1144 u8 ssid_len;
1145
1146#ifdef CONFIG_WIRELESS_EXT
1147 /* wext data */
1148 struct cfg80211_ibss_params wext;
1149 u8 wext_bssid[ETH_ALEN];
1150#endif
1151};
1152
1153/**
1154 * wdev_priv - return wiphy priv from wireless_dev
1155 *
1156 * @wdev: The wireless device whose wiphy's priv pointer to return
1157 */
1158static inline void *wdev_priv(struct wireless_dev *wdev)
1159{
1160 BUG_ON(!wdev);
1161 return wiphy_priv(wdev->wiphy);
1162}
1163
1164/*
1165 * Utility functions
1166 */
1167
1168/**
1169 * ieee80211_channel_to_frequency - convert channel number to frequency
1170 */
1171extern int ieee80211_channel_to_frequency(int chan);
1172
1173/**
1174 * ieee80211_frequency_to_channel - convert frequency to channel number
1175 */
1176extern int ieee80211_frequency_to_channel(int freq);
1177
1178/*
1179 * Name indirection necessary because the ieee80211 code also has
1180 * a function named "ieee80211_get_channel", so if you include
1181 * cfg80211's header file you get cfg80211's version, if you try
1182 * to include both header files you'll (rightfully!) get a symbol
1183 * clash.
1184 */
1185extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
1186 int freq);
1187/**
1188 * ieee80211_get_channel - get channel struct from wiphy for specified frequency
1189 */
1190static inline struct ieee80211_channel *
1191ieee80211_get_channel(struct wiphy *wiphy, int freq)
1192{
1193 return __ieee80211_get_channel(wiphy, freq);
1194}
1195
1196/**
1197 * ieee80211_get_response_rate - get basic rate for a given rate
1198 *
1199 * @sband: the band to look for rates in
1200 * @basic_rates: bitmap of basic rates
1201 * @bitrate: the bitrate for which to find the basic rate
1202 *
1203 * This function returns the basic rate corresponding to a given
1204 * bitrate, that is the next lower bitrate contained in the basic
1205 * rate map, which is, for this function, given as a bitmap of
1206 * indices of rates in the band's bitrate table.
1207 */
1208struct ieee80211_rate *
1209ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
1210 u32 basic_rates, int bitrate);
1211
1212/*
1213 * Radiotap parsing functions -- for controlled injection support
1214 *
1215 * Implemented in net/wireless/radiotap.c
1216 * Documentation in Documentation/networking/radiotap-headers.txt
1217 */
1218
1219/**
1220 * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args
1221 * @rtheader: pointer to the radiotap header we are walking through
1222 * @max_length: length of radiotap header in cpu byte ordering
1223 * @this_arg_index: IEEE80211_RADIOTAP_... index of current arg
1224 * @this_arg: pointer to current radiotap arg
1225 * @arg_index: internal next argument index
1226 * @arg: internal next argument pointer
1227 * @next_bitmap: internal pointer to next present u32
1228 * @bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present
1229 */
1230
1231struct ieee80211_radiotap_iterator {
1232 struct ieee80211_radiotap_header *rtheader;
1233 int max_length;
1234 int this_arg_index;
1235 u8 *this_arg;
1236
1237 int arg_index;
1238 u8 *arg;
1239 __le32 *next_bitmap;
1240 u32 bitmap_shifter;
821}; 1241};
822 1242
823/* temporary wext handlers */ 1243extern int ieee80211_radiotap_iterator_init(
1244 struct ieee80211_radiotap_iterator *iterator,
1245 struct ieee80211_radiotap_header *radiotap_header,
1246 int max_length);
1247
1248extern int ieee80211_radiotap_iterator_next(
1249 struct ieee80211_radiotap_iterator *iterator);
1250
1251/*
1252 * Regulatory helper functions for wiphys
1253 */
1254
1255/**
1256 * regulatory_hint - driver hint to the wireless core a regulatory domain
1257 * @wiphy: the wireless device giving the hint (used only for reporting
1258 * conflicts)
1259 * @alpha2: the ISO/IEC 3166 alpha2 the driver claims its regulatory domain
1260 * should be in. If @rd is set this should be NULL. Note that if you
1261 * set this to NULL you should still set rd->alpha2 to some accepted
1262 * alpha2.
1263 *
1264 * Wireless drivers can use this function to hint to the wireless core
1265 * what it believes should be the current regulatory domain by
1266 * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
1267 * domain should be in or by providing a completely build regulatory domain.
1268 * If the driver provides an ISO/IEC 3166 alpha2 userspace will be queried
1269 * for a regulatory domain structure for the respective country.
1270 *
1271 * The wiphy must have been registered to cfg80211 prior to this call.
1272 * For cfg80211 drivers this means you must first use wiphy_register(),
1273 * for mac80211 drivers you must first use ieee80211_register_hw().
1274 *
1275 * Drivers should check the return value, its possible you can get
1276 * an -ENOMEM.
1277 */
1278extern int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
1279
1280/**
1281 * regulatory_hint_11d - hints a country IE as a regulatory domain
1282 * @wiphy: the wireless device giving the hint (used only for reporting
1283 * conflicts)
1284 * @country_ie: pointer to the country IE
1285 * @country_ie_len: length of the country IE
1286 *
1287 * We will intersect the rd with the what CRDA tells us should apply
1288 * for the alpha2 this country IE belongs to, this prevents APs from
1289 * sending us incorrect or outdated information against a country.
1290 */
1291extern void regulatory_hint_11d(struct wiphy *wiphy,
1292 u8 *country_ie,
1293 u8 country_ie_len);
1294/**
1295 * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
1296 * @wiphy: the wireless device we want to process the regulatory domain on
1297 * @regd: the custom regulatory domain to use for this wiphy
1298 *
1299 * Drivers can sometimes have custom regulatory domains which do not apply
1300 * to a specific country. Drivers can use this to apply such custom regulatory
1301 * domains. This routine must be called prior to wiphy registration. The
1302 * custom regulatory domain will be trusted completely and as such previous
1303 * default channel settings will be disregarded. If no rule is found for a
1304 * channel on the regulatory domain the channel will be disabled.
1305 */
1306extern void wiphy_apply_custom_regulatory(
1307 struct wiphy *wiphy,
1308 const struct ieee80211_regdomain *regd);
1309
1310/**
1311 * freq_reg_info - get regulatory information for the given frequency
1312 * @wiphy: the wiphy for which we want to process this rule for
1313 * @center_freq: Frequency in KHz for which we want regulatory information for
1314 * @bandwidth: the bandwidth requirement you have in KHz, if you do not have one
1315 * you can set this to 0. If this frequency is allowed we then set
1316 * this value to the maximum allowed bandwidth.
1317 * @reg_rule: the regulatory rule which we have for this frequency
1318 *
1319 * Use this function to get the regulatory rule for a specific frequency on
1320 * a given wireless device. If the device has a specific regulatory domain
1321 * it wants to follow we respect that unless a country IE has been received
1322 * and processed already.
1323 *
1324 * Returns 0 if it was able to find a valid regulatory rule which does
1325 * apply to the given center_freq otherwise it returns non-zero. It will
1326 * also return -ERANGE if we determine the given center_freq does not even have
1327 * a regulatory rule for a frequency range in the center_freq's band. See
1328 * freq_in_rule_band() for our current definition of a band -- this is purely
1329 * subjective and right now its 802.11 specific.
1330 */
1331extern int freq_reg_info(struct wiphy *wiphy, u32 center_freq, u32 *bandwidth,
1332 const struct ieee80211_reg_rule **reg_rule);
1333
1334/*
1335 * Temporary wext handlers & helper functions
1336 *
1337 * In the future cfg80211 will simply assign the entire wext handler
1338 * structure to netdevs it manages, but we're not there yet.
1339 */
824int cfg80211_wext_giwname(struct net_device *dev, 1340int cfg80211_wext_giwname(struct net_device *dev,
825 struct iw_request_info *info, 1341 struct iw_request_info *info,
826 char *name, char *extra); 1342 char *name, char *extra);
@@ -834,9 +1350,57 @@ int cfg80211_wext_siwscan(struct net_device *dev,
834int cfg80211_wext_giwscan(struct net_device *dev, 1350int cfg80211_wext_giwscan(struct net_device *dev,
835 struct iw_request_info *info, 1351 struct iw_request_info *info,
836 struct iw_point *data, char *extra); 1352 struct iw_point *data, char *extra);
1353int cfg80211_wext_siwmlme(struct net_device *dev,
1354 struct iw_request_info *info,
1355 struct iw_point *data, char *extra);
837int cfg80211_wext_giwrange(struct net_device *dev, 1356int cfg80211_wext_giwrange(struct net_device *dev,
838 struct iw_request_info *info, 1357 struct iw_request_info *info,
839 struct iw_point *data, char *extra); 1358 struct iw_point *data, char *extra);
1359int cfg80211_ibss_wext_siwfreq(struct net_device *dev,
1360 struct iw_request_info *info,
1361 struct iw_freq *freq, char *extra);
1362int cfg80211_ibss_wext_giwfreq(struct net_device *dev,
1363 struct iw_request_info *info,
1364 struct iw_freq *freq, char *extra);
1365int cfg80211_ibss_wext_siwessid(struct net_device *dev,
1366 struct iw_request_info *info,
1367 struct iw_point *data, char *ssid);
1368int cfg80211_ibss_wext_giwessid(struct net_device *dev,
1369 struct iw_request_info *info,
1370 struct iw_point *data, char *ssid);
1371int cfg80211_ibss_wext_siwap(struct net_device *dev,
1372 struct iw_request_info *info,
1373 struct sockaddr *ap_addr, char *extra);
1374int cfg80211_ibss_wext_giwap(struct net_device *dev,
1375 struct iw_request_info *info,
1376 struct sockaddr *ap_addr, char *extra);
1377
1378struct ieee80211_channel *cfg80211_wext_freq(struct wiphy *wiphy,
1379 struct iw_freq *freq);
1380
1381int cfg80211_wext_siwrts(struct net_device *dev,
1382 struct iw_request_info *info,
1383 struct iw_param *rts, char *extra);
1384int cfg80211_wext_giwrts(struct net_device *dev,
1385 struct iw_request_info *info,
1386 struct iw_param *rts, char *extra);
1387int cfg80211_wext_siwfrag(struct net_device *dev,
1388 struct iw_request_info *info,
1389 struct iw_param *frag, char *extra);
1390int cfg80211_wext_giwfrag(struct net_device *dev,
1391 struct iw_request_info *info,
1392 struct iw_param *frag, char *extra);
1393int cfg80211_wext_siwretry(struct net_device *dev,
1394 struct iw_request_info *info,
1395 struct iw_param *retry, char *extra);
1396int cfg80211_wext_giwretry(struct net_device *dev,
1397 struct iw_request_info *info,
1398 struct iw_param *retry, char *extra);
1399
1400/*
1401 * callbacks for asynchronous cfg80211 methods, notification
1402 * functions and BSS handling helpers
1403 */
840 1404
841/** 1405/**
842 * cfg80211_scan_done - notify that scan finished 1406 * cfg80211_scan_done - notify that scan finished
@@ -864,6 +1428,14 @@ cfg80211_inform_bss_frame(struct wiphy *wiphy,
864 struct ieee80211_mgmt *mgmt, size_t len, 1428 struct ieee80211_mgmt *mgmt, size_t len,
865 s32 signal, gfp_t gfp); 1429 s32 signal, gfp_t gfp);
866 1430
1431struct cfg80211_bss*
1432cfg80211_inform_bss(struct wiphy *wiphy,
1433 struct ieee80211_channel *channel,
1434 const u8 *bssid,
1435 u64 timestamp, u16 capability, u16 beacon_interval,
1436 const u8 *ie, size_t ielen,
1437 s32 signal, gfp_t gfp);
1438
867struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy, 1439struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy,
868 struct ieee80211_channel *channel, 1440 struct ieee80211_channel *channel,
869 const u8 *bssid, 1441 const u8 *bssid,
@@ -883,6 +1455,7 @@ struct cfg80211_bss *cfg80211_get_mesh(struct wiphy *wiphy,
883 const u8 *meshid, size_t meshidlen, 1455 const u8 *meshid, size_t meshidlen,
884 const u8 *meshcfg); 1456 const u8 *meshcfg);
885void cfg80211_put_bss(struct cfg80211_bss *bss); 1457void cfg80211_put_bss(struct cfg80211_bss *bss);
1458
886/** 1459/**
887 * cfg80211_unlink_bss - unlink BSS from internal data structures 1460 * cfg80211_unlink_bss - unlink BSS from internal data structures
888 * @wiphy: the wiphy 1461 * @wiphy: the wiphy
@@ -902,44 +1475,62 @@ void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *bss);
902 * @len: length of the frame data 1475 * @len: length of the frame data
903 * 1476 *
904 * This function is called whenever an authentication has been processed in 1477 * This function is called whenever an authentication has been processed in
905 * station mode. 1478 * station mode. The driver is required to call either this function or
1479 * cfg80211_send_auth_timeout() to indicate the result of cfg80211_ops::auth()
1480 * call.
906 */ 1481 */
907void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len); 1482void cfg80211_send_rx_auth(struct net_device *dev, const u8 *buf, size_t len);
908 1483
909/** 1484/**
1485 * cfg80211_send_auth_timeout - notification of timed out authentication
1486 * @dev: network device
1487 * @addr: The MAC address of the device with which the authentication timed out
1488 */
1489void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr);
1490
1491/**
910 * cfg80211_send_rx_assoc - notification of processed association 1492 * cfg80211_send_rx_assoc - notification of processed association
911 * @dev: network device 1493 * @dev: network device
912 * @buf: (re)association response frame (header + body) 1494 * @buf: (re)association response frame (header + body)
913 * @len: length of the frame data 1495 * @len: length of the frame data
914 * 1496 *
915 * This function is called whenever a (re)association response has been 1497 * This function is called whenever a (re)association response has been
916 * processed in station mode. 1498 * processed in station mode. The driver is required to call either this
1499 * function or cfg80211_send_assoc_timeout() to indicate the result of
1500 * cfg80211_ops::assoc() call.
917 */ 1501 */
918void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len); 1502void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len);
919 1503
920/** 1504/**
921 * cfg80211_send_rx_deauth - notification of processed deauthentication 1505 * cfg80211_send_assoc_timeout - notification of timed out association
1506 * @dev: network device
1507 * @addr: The MAC address of the device with which the association timed out
1508 */
1509void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr);
1510
1511/**
1512 * cfg80211_send_deauth - notification of processed deauthentication
922 * @dev: network device 1513 * @dev: network device
923 * @buf: deauthentication frame (header + body) 1514 * @buf: deauthentication frame (header + body)
924 * @len: length of the frame data 1515 * @len: length of the frame data
925 * 1516 *
926 * This function is called whenever deauthentication has been processed in 1517 * This function is called whenever deauthentication has been processed in
927 * station mode. 1518 * station mode. This includes both received deauthentication frames and
1519 * locally generated ones.
928 */ 1520 */
929void cfg80211_send_rx_deauth(struct net_device *dev, const u8 *buf, 1521void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len);
930 size_t len);
931 1522
932/** 1523/**
933 * cfg80211_send_rx_disassoc - notification of processed disassociation 1524 * cfg80211_send_disassoc - notification of processed disassociation
934 * @dev: network device 1525 * @dev: network device
935 * @buf: disassociation response frame (header + body) 1526 * @buf: disassociation response frame (header + body)
936 * @len: length of the frame data 1527 * @len: length of the frame data
937 * 1528 *
938 * This function is called whenever disassociation has been processed in 1529 * This function is called whenever disassociation has been processed in
939 * station mode. 1530 * station mode. This includes both received disassociation frames and locally
1531 * generated ones.
940 */ 1532 */
941void cfg80211_send_rx_disassoc(struct net_device *dev, const u8 *buf, 1533void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len);
942 size_t len);
943 1534
944/** 1535/**
945 * cfg80211_hold_bss - exclude bss from expiration 1536 * cfg80211_hold_bss - exclude bss from expiration
@@ -958,4 +1549,36 @@ void cfg80211_hold_bss(struct cfg80211_bss *bss);
958 */ 1549 */
959void cfg80211_unhold_bss(struct cfg80211_bss *bss); 1550void cfg80211_unhold_bss(struct cfg80211_bss *bss);
960 1551
1552/**
1553 * cfg80211_michael_mic_failure - notification of Michael MIC failure (TKIP)
1554 * @dev: network device
1555 * @addr: The source MAC address of the frame
1556 * @key_type: The key type that the received frame used
1557 * @key_id: Key identifier (0..3)
1558 * @tsc: The TSC value of the frame that generated the MIC failure (6 octets)
1559 *
1560 * This function is called whenever the local MAC detects a MIC failure in a
1561 * received frame. This matches with MLME-MICHAELMICFAILURE.indication()
1562 * primitive.
1563 */
1564void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
1565 enum nl80211_key_type key_type, int key_id,
1566 const u8 *tsc);
1567
1568/**
1569 * cfg80211_ibss_joined - notify cfg80211 that device joined an IBSS
1570 *
1571 * @dev: network device
1572 * @bssid: the BSSID of the IBSS joined
1573 * @gfp: allocation flags
1574 *
1575 * This function notifies cfg80211 that the device joined an IBSS or
1576 * switched to a different BSSID. Before this function can be called,
1577 * either a beacon has to have been received from the IBSS, or one of
1578 * the cfg80211_inform_bss{,_frame} functions must have been called
1579 * with the locally generated beacon -- this guarantees that there is
1580 * always a scan result for this IBSS. cfg80211 will handle the rest.
1581 */
1582void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp);
1583
961#endif /* __NET_CFG80211_H */ 1584#endif /* __NET_CFG80211_H */
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 3b83a80e3fe0..446dbf75a1c5 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -19,7 +19,6 @@
19#include <linux/wireless.h> 19#include <linux/wireless.h>
20#include <linux/device.h> 20#include <linux/device.h>
21#include <linux/ieee80211.h> 21#include <linux/ieee80211.h>
22#include <net/wireless.h>
23#include <net/cfg80211.h> 22#include <net/cfg80211.h>
24 23
25/** 24/**
@@ -518,7 +517,7 @@ struct ieee80211_rx_status {
518 * Flags to define PHY configuration options 517 * Flags to define PHY configuration options
519 * 518 *
520 * @IEEE80211_CONF_RADIOTAP: add radiotap header at receive time (if supported) 519 * @IEEE80211_CONF_RADIOTAP: add radiotap header at receive time (if supported)
521 * @IEEE80211_CONF_PS: Enable 802.11 power save mode 520 * @IEEE80211_CONF_PS: Enable 802.11 power save mode (managed mode only)
522 */ 521 */
523enum ieee80211_conf_flags { 522enum ieee80211_conf_flags {
524 IEEE80211_CONF_RADIOTAP = (1<<0), 523 IEEE80211_CONF_RADIOTAP = (1<<0),
@@ -533,8 +532,7 @@ enum ieee80211_conf_flags {
533 * @IEEE80211_CONF_CHANGE_BEACON_INTERVAL: the beacon interval changed 532 * @IEEE80211_CONF_CHANGE_BEACON_INTERVAL: the beacon interval changed
534 * @IEEE80211_CONF_CHANGE_LISTEN_INTERVAL: the listen interval changed 533 * @IEEE80211_CONF_CHANGE_LISTEN_INTERVAL: the listen interval changed
535 * @IEEE80211_CONF_CHANGE_RADIOTAP: the radiotap flag changed 534 * @IEEE80211_CONF_CHANGE_RADIOTAP: the radiotap flag changed
536 * @IEEE80211_CONF_CHANGE_PS: the PS flag changed 535 * @IEEE80211_CONF_CHANGE_PS: the PS flag or dynamic PS timeout changed
537 * @IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT: the dynamic PS timeout changed
538 * @IEEE80211_CONF_CHANGE_POWER: the TX power changed 536 * @IEEE80211_CONF_CHANGE_POWER: the TX power changed
539 * @IEEE80211_CONF_CHANGE_CHANNEL: the channel/channel_type changed 537 * @IEEE80211_CONF_CHANGE_CHANNEL: the channel/channel_type changed
540 * @IEEE80211_CONF_CHANGE_RETRY_LIMITS: retry limits changed 538 * @IEEE80211_CONF_CHANGE_RETRY_LIMITS: retry limits changed
@@ -545,10 +543,9 @@ enum ieee80211_conf_changed {
545 IEEE80211_CONF_CHANGE_LISTEN_INTERVAL = BIT(2), 543 IEEE80211_CONF_CHANGE_LISTEN_INTERVAL = BIT(2),
546 IEEE80211_CONF_CHANGE_RADIOTAP = BIT(3), 544 IEEE80211_CONF_CHANGE_RADIOTAP = BIT(3),
547 IEEE80211_CONF_CHANGE_PS = BIT(4), 545 IEEE80211_CONF_CHANGE_PS = BIT(4),
548 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT = BIT(5), 546 IEEE80211_CONF_CHANGE_POWER = BIT(5),
549 IEEE80211_CONF_CHANGE_POWER = BIT(6), 547 IEEE80211_CONF_CHANGE_CHANNEL = BIT(6),
550 IEEE80211_CONF_CHANGE_CHANNEL = BIT(7), 548 IEEE80211_CONF_CHANGE_RETRY_LIMITS = BIT(7),
551 IEEE80211_CONF_CHANGE_RETRY_LIMITS = BIT(8),
552}; 549};
553 550
554/** 551/**
@@ -556,14 +553,26 @@ enum ieee80211_conf_changed {
556 * 553 *
557 * This struct indicates how the driver shall configure the hardware. 554 * This struct indicates how the driver shall configure the hardware.
558 * 555 *
556 * @flags: configuration flags defined above
557 *
559 * @radio_enabled: when zero, driver is required to switch off the radio. 558 * @radio_enabled: when zero, driver is required to switch off the radio.
560 * @beacon_int: beacon interval (TODO make interface config) 559 * @beacon_int: beacon interval (TODO make interface config)
560 *
561 * @listen_interval: listen interval in units of beacon interval 561 * @listen_interval: listen interval in units of beacon interval
562 * @flags: configuration flags defined above 562 * @max_sleep_interval: the maximum number of beacon intervals to sleep for
563 * before checking the beacon for a TIM bit (managed mode only); this
564 * value will be only achievable between DTIM frames, the hardware
565 * needs to check for the multicast traffic bit in DTIM beacons.
566 * This variable is valid only when the CONF_PS flag is set.
567 * @dynamic_ps_timeout: The dynamic powersave timeout (in ms), see the
568 * powersave documentation below. This variable is valid only when
569 * the CONF_PS flag is set.
570 *
563 * @power_level: requested transmit power (in dBm) 571 * @power_level: requested transmit power (in dBm)
564 * @dynamic_ps_timeout: dynamic powersave timeout (in ms) 572 *
565 * @channel: the channel to tune to 573 * @channel: the channel to tune to
566 * @channel_type: the channel (HT) type 574 * @channel_type: the channel (HT) type
575 *
567 * @long_frame_max_tx_count: Maximum number of transmissions for a "long" frame 576 * @long_frame_max_tx_count: Maximum number of transmissions for a "long" frame
568 * (a frame not RTS protected), called "dot11LongRetryLimit" in 802.11, 577 * (a frame not RTS protected), called "dot11LongRetryLimit" in 802.11,
569 * but actually means the number of transmissions not the number of retries 578 * but actually means the number of transmissions not the number of retries
@@ -575,6 +584,7 @@ struct ieee80211_conf {
575 int beacon_int; 584 int beacon_int;
576 u32 flags; 585 u32 flags;
577 int power_level, dynamic_ps_timeout; 586 int power_level, dynamic_ps_timeout;
587 int max_sleep_interval;
578 588
579 u16 listen_interval; 589 u16 listen_interval;
580 bool radio_enabled; 590 bool radio_enabled;
@@ -1109,11 +1119,9 @@ ieee80211_get_alt_retry_rate(const struct ieee80211_hw *hw,
1109 * need software support for parsing the TIM bitmap. This is also supported 1119 * need software support for parsing the TIM bitmap. This is also supported
1110 * by mac80211 by combining the %IEEE80211_HW_SUPPORTS_PS and 1120 * by mac80211 by combining the %IEEE80211_HW_SUPPORTS_PS and
1111 * %IEEE80211_HW_PS_NULLFUNC_STACK flags. The hardware is of course still 1121 * %IEEE80211_HW_PS_NULLFUNC_STACK flags. The hardware is of course still
1112 * required to pass up beacons. Additionally, in this case, mac80211 will 1122 * required to pass up beacons. The hardware is still required to handle
1113 * wake up the hardware when multicast traffic is announced in the beacon. 1123 * waking up for multicast traffic; if it cannot the driver must handle that
1114 * 1124 * as best as it can, mac80211 is too slow.
1115 * FIXME: I don't think we can be fast enough in software when we want to
1116 * receive multicast traffic?
1117 * 1125 *
1118 * Dynamic powersave mode is an extension to normal powersave mode in which 1126 * Dynamic powersave mode is an extension to normal powersave mode in which
1119 * the hardware stays awake for a user-specified period of time after sending 1127 * the hardware stays awake for a user-specified period of time after sending
@@ -1134,11 +1142,53 @@ ieee80211_get_alt_retry_rate(const struct ieee80211_hw *hw,
1134 * way the host will only receive beacons where some relevant information 1142 * way the host will only receive beacons where some relevant information
1135 * (for example ERP protection or WMM settings) have changed. 1143 * (for example ERP protection or WMM settings) have changed.
1136 * 1144 *
1137 * Beacon filter support is informed with %IEEE80211_HW_BEACON_FILTER flag. 1145 * Beacon filter support is advertised with the %IEEE80211_HW_BEACON_FILTER
1138 * The driver needs to enable beacon filter support whenever power save is 1146 * hardware capability. The driver needs to enable beacon filter support
1139 * enabled, that is %IEEE80211_CONF_PS is set. When power save is enabled, 1147 * whenever power save is enabled, that is %IEEE80211_CONF_PS is set. When
1140 * the stack will not check for beacon miss at all and the driver needs to 1148 * power save is enabled, the stack will not check for beacon loss and the
1141 * notify about complete loss of beacons with ieee80211_beacon_loss(). 1149 * driver needs to notify about loss of beacons with ieee80211_beacon_loss().
1150 *
1151 * The time (or number of beacons missed) until the firmware notifies the
1152 * driver of a beacon loss event (which in turn causes the driver to call
1153 * ieee80211_beacon_loss()) should be configurable and will be controlled
1154 * by mac80211 and the roaming algorithm in the future.
1155 *
1156 * Since there may be constantly changing information elements that nothing
1157 * in the software stack cares about, we will, in the future, have mac80211
1158 * tell the driver which information elements are interesting in the sense
1159 * that we want to see changes in them. This will include
1160 * - a list of information element IDs
1161 * - a list of OUIs for the vendor information element
1162 *
1163 * Ideally, the hardware would filter out any beacons without changes in the
1164 * requested elements, but if it cannot support that it may, at the expense
1165 * of some efficiency, filter out only a subset. For example, if the device
1166 * doesn't support checking for OUIs it should pass up all changes in all
1167 * vendor information elements.
1168 *
1169 * Note that change, for the sake of simplification, also includes information
1170 * elements appearing or disappearing from the beacon.
1171 *
1172 * Some hardware supports an "ignore list" instead, just make sure nothing
1173 * that was requested is on the ignore list, and include commonly changing
1174 * information element IDs in the ignore list, for example 11 (BSS load) and
1175 * the various vendor-assigned IEs with unknown contents (128, 129, 133-136,
1176 * 149, 150, 155, 156, 173, 176, 178, 179, 219); for forward compatibility
1177 * it could also include some currently unused IDs.
1178 *
1179 *
1180 * In addition to these capabilities, hardware should support notifying the
1181 * host of changes in the beacon RSSI. This is relevant to implement roaming
1182 * when no traffic is flowing (when traffic is flowing we see the RSSI of
1183 * the received data packets). This can consist in notifying the host when
1184 * the RSSI changes significantly or when it drops below or rises above
1185 * configurable thresholds. In the future these thresholds will also be
1186 * configured by mac80211 (which gets them from userspace) to implement
1187 * them as the roaming algorithm requires.
1188 *
1189 * If the hardware cannot implement this, the driver should ask it to
1190 * periodically pass beacon frames to the host so that software can do the
1191 * signal strength threshold checking.
1142 */ 1192 */
1143 1193
1144/** 1194/**
@@ -1330,11 +1380,14 @@ enum ieee80211_ampdu_mlme_action {
1330 * the scan state machine in stack. The scan must honour the channel 1380 * the scan state machine in stack. The scan must honour the channel
1331 * configuration done by the regulatory agent in the wiphy's 1381 * configuration done by the regulatory agent in the wiphy's
1332 * registered bands. The hardware (or the driver) needs to make sure 1382 * registered bands. The hardware (or the driver) needs to make sure
1333 * that power save is disabled. When the scan finishes, 1383 * that power save is disabled.
1334 * ieee80211_scan_completed() must be called; note that it also must 1384 * The @req ie/ie_len members are rewritten by mac80211 to contain the
1335 * be called when the scan cannot finish because the hardware is 1385 * entire IEs after the SSID, so that drivers need not look at these
1336 * turned off! Anything else is a bug! Returns a negative error code 1386 * at all but just send them after the SSID -- mac80211 includes the
1337 * which will be seen in userspace. 1387 * (extended) supported rates and HT information (where applicable).
1388 * When the scan finishes, ieee80211_scan_completed() must be called;
1389 * note that it also must be called when the scan cannot finish due to
1390 * any error unless this callback returned a negative error code.
1338 * 1391 *
1339 * @sw_scan_start: Notifier function that is called just before a software scan 1392 * @sw_scan_start: Notifier function that is called just before a software scan
1340 * is started. Can be NULL, if the driver doesn't need this notification. 1393 * is started. Can be NULL, if the driver doesn't need this notification.
@@ -1572,6 +1625,20 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw);
1572 */ 1625 */
1573void ieee80211_free_hw(struct ieee80211_hw *hw); 1626void ieee80211_free_hw(struct ieee80211_hw *hw);
1574 1627
1628/**
1629 * ieee80211_restart_hw - restart hardware completely
1630 *
1631 * Call this function when the hardware was restarted for some reason
1632 * (hardware error, ...) and the driver is unable to restore its state
1633 * by itself. mac80211 assumes that at this point the driver/hardware
1634 * is completely uninitialised and stopped, it starts the process by
1635 * calling the ->start() operation. The driver will need to reset all
1636 * internal state that it has prior to calling this function.
1637 *
1638 * @hw: the hardware to restart
1639 */
1640void ieee80211_restart_hw(struct ieee80211_hw *hw);
1641
1575/* trick to avoid symbol clashes with the ieee80211 subsystem */ 1642/* trick to avoid symbol clashes with the ieee80211 subsystem */
1576void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb, 1643void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
1577 struct ieee80211_rx_status *status); 1644 struct ieee80211_rx_status *status);
diff --git a/include/net/regulatory.h b/include/net/regulatory.h
new file mode 100644
index 000000000000..47995b81c5d7
--- /dev/null
+++ b/include/net/regulatory.h
@@ -0,0 +1,101 @@
1#ifndef __NET_REGULATORY_H
2#define __NET_REGULATORY_H
3/*
4 * regulatory support structures
5 *
6 * Copyright 2008-2009 Luis R. Rodriguez <lrodriguez@atheros.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13
14/**
15 * enum environment_cap - Environment parsed from country IE
16 * @ENVIRON_ANY: indicates country IE applies to both indoor and
17 * outdoor operation.
18 * @ENVIRON_INDOOR: indicates country IE applies only to indoor operation
19 * @ENVIRON_OUTDOOR: indicates country IE applies only to outdoor operation
20 */
21enum environment_cap {
22 ENVIRON_ANY,
23 ENVIRON_INDOOR,
24 ENVIRON_OUTDOOR,
25};
26
27/**
28 * struct regulatory_request - used to keep track of regulatory requests
29 *
30 * @wiphy_idx: this is set if this request's initiator is
31 * %REGDOM_SET_BY_COUNTRY_IE or %REGDOM_SET_BY_DRIVER. This
32 * can be used by the wireless core to deal with conflicts
33 * and potentially inform users of which devices specifically
34 * cased the conflicts.
35 * @initiator: indicates who sent this request, could be any of
36 * of those set in nl80211_reg_initiator (%NL80211_REGDOM_SET_BY_*)
37 * @alpha2: the ISO / IEC 3166 alpha2 country code of the requested
38 * regulatory domain. We have a few special codes:
39 * 00 - World regulatory domain
40 * 99 - built by driver but a specific alpha2 cannot be determined
41 * 98 - result of an intersection between two regulatory domains
42 * @intersect: indicates whether the wireless core should intersect
43 * the requested regulatory domain with the presently set regulatory
44 * domain.
45 * @country_ie_checksum: checksum of the last processed and accepted
46 * country IE
47 * @country_ie_env: lets us know if the AP is telling us we are outdoor,
48 * indoor, or if it doesn't matter
49 * @list: used to insert into the reg_requests_list linked list
50 */
51struct regulatory_request {
52 int wiphy_idx;
53 enum nl80211_reg_initiator initiator;
54 char alpha2[2];
55 bool intersect;
56 u32 country_ie_checksum;
57 enum environment_cap country_ie_env;
58 struct list_head list;
59};
60
61struct ieee80211_freq_range {
62 u32 start_freq_khz;
63 u32 end_freq_khz;
64 u32 max_bandwidth_khz;
65};
66
67struct ieee80211_power_rule {
68 u32 max_antenna_gain;
69 u32 max_eirp;
70};
71
72struct ieee80211_reg_rule {
73 struct ieee80211_freq_range freq_range;
74 struct ieee80211_power_rule power_rule;
75 u32 flags;
76};
77
78struct ieee80211_regdomain {
79 u32 n_reg_rules;
80 char alpha2[2];
81 struct ieee80211_reg_rule reg_rules[];
82};
83
84#define MHZ_TO_KHZ(freq) ((freq) * 1000)
85#define KHZ_TO_MHZ(freq) ((freq) / 1000)
86#define DBI_TO_MBI(gain) ((gain) * 100)
87#define MBI_TO_DBI(gain) ((gain) / 100)
88#define DBM_TO_MBM(gain) ((gain) * 100)
89#define MBM_TO_DBM(gain) ((gain) / 100)
90
91#define REG_RULE(start, end, bw, gain, eirp, reg_flags) \
92{ \
93 .freq_range.start_freq_khz = MHZ_TO_KHZ(start), \
94 .freq_range.end_freq_khz = MHZ_TO_KHZ(end), \
95 .freq_range.max_bandwidth_khz = MHZ_TO_KHZ(bw), \
96 .power_rule.max_antenna_gain = DBI_TO_MBI(gain),\
97 .power_rule.max_eirp = DBM_TO_MBM(eirp), \
98 .flags = reg_flags, \
99}
100
101#endif
diff --git a/include/net/wireless.h b/include/net/wireless.h
deleted file mode 100644
index 64a76208580c..000000000000
--- a/include/net/wireless.h
+++ /dev/null
@@ -1,472 +0,0 @@
1#ifndef __NET_WIRELESS_H
2#define __NET_WIRELESS_H
3
4/*
5 * 802.11 device management
6 *
7 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
8 */
9
10#include <linux/netdevice.h>
11#include <linux/debugfs.h>
12#include <linux/list.h>
13#include <linux/ieee80211.h>
14#include <net/cfg80211.h>
15
16/**
17 * enum ieee80211_band - supported frequency bands
18 *
19 * The bands are assigned this way because the supported
20 * bitrates differ in these bands.
21 *
22 * @IEEE80211_BAND_2GHZ: 2.4GHz ISM band
23 * @IEEE80211_BAND_5GHZ: around 5GHz band (4.9-5.7)
24 */
25enum ieee80211_band {
26 IEEE80211_BAND_2GHZ,
27 IEEE80211_BAND_5GHZ,
28
29 /* keep last */
30 IEEE80211_NUM_BANDS
31};
32
33/**
34 * enum ieee80211_channel_flags - channel flags
35 *
36 * Channel flags set by the regulatory control code.
37 *
38 * @IEEE80211_CHAN_DISABLED: This channel is disabled.
39 * @IEEE80211_CHAN_PASSIVE_SCAN: Only passive scanning is permitted
40 * on this channel.
41 * @IEEE80211_CHAN_NO_IBSS: IBSS is not allowed on this channel.
42 * @IEEE80211_CHAN_RADAR: Radar detection is required on this channel.
43 * @IEEE80211_CHAN_NO_FAT_ABOVE: extension channel above this channel
44 * is not permitted.
45 * @IEEE80211_CHAN_NO_FAT_BELOW: extension channel below this channel
46 * is not permitted.
47 */
48enum ieee80211_channel_flags {
49 IEEE80211_CHAN_DISABLED = 1<<0,
50 IEEE80211_CHAN_PASSIVE_SCAN = 1<<1,
51 IEEE80211_CHAN_NO_IBSS = 1<<2,
52 IEEE80211_CHAN_RADAR = 1<<3,
53 IEEE80211_CHAN_NO_FAT_ABOVE = 1<<4,
54 IEEE80211_CHAN_NO_FAT_BELOW = 1<<5,
55};
56
57/**
58 * struct ieee80211_channel - channel definition
59 *
60 * This structure describes a single channel for use
61 * with cfg80211.
62 *
63 * @center_freq: center frequency in MHz
64 * @max_bandwidth: maximum allowed bandwidth for this channel, in MHz
65 * @hw_value: hardware-specific value for the channel
66 * @flags: channel flags from &enum ieee80211_channel_flags.
67 * @orig_flags: channel flags at registration time, used by regulatory
68 * code to support devices with additional restrictions
69 * @band: band this channel belongs to.
70 * @max_antenna_gain: maximum antenna gain in dBi
71 * @max_power: maximum transmission power (in dBm)
72 * @beacon_found: helper to regulatory code to indicate when a beacon
73 * has been found on this channel. Use regulatory_hint_found_beacon()
74 * to enable this, this is is useful only on 5 GHz band.
75 * @orig_mag: internal use
76 * @orig_mpwr: internal use
77 */
78struct ieee80211_channel {
79 enum ieee80211_band band;
80 u16 center_freq;
81 u8 max_bandwidth;
82 u16 hw_value;
83 u32 flags;
84 int max_antenna_gain;
85 int max_power;
86 bool beacon_found;
87 u32 orig_flags;
88 int orig_mag, orig_mpwr;
89};
90
91/**
92 * enum ieee80211_rate_flags - rate flags
93 *
94 * Hardware/specification flags for rates. These are structured
95 * in a way that allows using the same bitrate structure for
96 * different bands/PHY modes.
97 *
98 * @IEEE80211_RATE_SHORT_PREAMBLE: Hardware can send with short
99 * preamble on this bitrate; only relevant in 2.4GHz band and
100 * with CCK rates.
101 * @IEEE80211_RATE_MANDATORY_A: This bitrate is a mandatory rate
102 * when used with 802.11a (on the 5 GHz band); filled by the
103 * core code when registering the wiphy.
104 * @IEEE80211_RATE_MANDATORY_B: This bitrate is a mandatory rate
105 * when used with 802.11b (on the 2.4 GHz band); filled by the
106 * core code when registering the wiphy.
107 * @IEEE80211_RATE_MANDATORY_G: This bitrate is a mandatory rate
108 * when used with 802.11g (on the 2.4 GHz band); filled by the
109 * core code when registering the wiphy.
110 * @IEEE80211_RATE_ERP_G: This is an ERP rate in 802.11g mode.
111 */
112enum ieee80211_rate_flags {
113 IEEE80211_RATE_SHORT_PREAMBLE = 1<<0,
114 IEEE80211_RATE_MANDATORY_A = 1<<1,
115 IEEE80211_RATE_MANDATORY_B = 1<<2,
116 IEEE80211_RATE_MANDATORY_G = 1<<3,
117 IEEE80211_RATE_ERP_G = 1<<4,
118};
119
120/**
121 * struct ieee80211_rate - bitrate definition
122 *
123 * This structure describes a bitrate that an 802.11 PHY can
124 * operate with. The two values @hw_value and @hw_value_short
125 * are only for driver use when pointers to this structure are
126 * passed around.
127 *
128 * @flags: rate-specific flags
129 * @bitrate: bitrate in units of 100 Kbps
130 * @hw_value: driver/hardware value for this rate
131 * @hw_value_short: driver/hardware value for this rate when
132 * short preamble is used
133 */
134struct ieee80211_rate {
135 u32 flags;
136 u16 bitrate;
137 u16 hw_value, hw_value_short;
138};
139
140/**
141 * struct ieee80211_sta_ht_cap - STA's HT capabilities
142 *
143 * This structure describes most essential parameters needed
144 * to describe 802.11n HT capabilities for an STA.
145 *
146 * @ht_supported: is HT supported by the STA
147 * @cap: HT capabilities map as described in 802.11n spec
148 * @ampdu_factor: Maximum A-MPDU length factor
149 * @ampdu_density: Minimum A-MPDU spacing
150 * @mcs: Supported MCS rates
151 */
152struct ieee80211_sta_ht_cap {
153 u16 cap; /* use IEEE80211_HT_CAP_ */
154 bool ht_supported;
155 u8 ampdu_factor;
156 u8 ampdu_density;
157 struct ieee80211_mcs_info mcs;
158};
159
160/**
161 * struct ieee80211_supported_band - frequency band definition
162 *
163 * This structure describes a frequency band a wiphy
164 * is able to operate in.
165 *
166 * @channels: Array of channels the hardware can operate in
167 * in this band.
168 * @band: the band this structure represents
169 * @n_channels: Number of channels in @channels
170 * @bitrates: Array of bitrates the hardware can operate with
171 * in this band. Must be sorted to give a valid "supported
172 * rates" IE, i.e. CCK rates first, then OFDM.
173 * @n_bitrates: Number of bitrates in @bitrates
174 */
175struct ieee80211_supported_band {
176 struct ieee80211_channel *channels;
177 struct ieee80211_rate *bitrates;
178 enum ieee80211_band band;
179 int n_channels;
180 int n_bitrates;
181 struct ieee80211_sta_ht_cap ht_cap;
182};
183
184/**
185 * struct wiphy - wireless hardware description
186 * @idx: the wiphy index assigned to this item
187 * @class_dev: the class device representing /sys/class/ieee80211/<wiphy-name>
188 * @custom_regulatory: tells us the driver for this device
189 * has its own custom regulatory domain and cannot identify the
190 * ISO / IEC 3166 alpha2 it belongs to. When this is enabled
191 * we will disregard the first regulatory hint (when the
192 * initiator is %REGDOM_SET_BY_CORE).
193 * @strict_regulatory: tells us the driver for this device will ignore
194 * regulatory domain settings until it gets its own regulatory domain
195 * via its regulatory_hint(). After its gets its own regulatory domain
196 * it will only allow further regulatory domain settings to further
197 * enhance compliance. For example if channel 13 and 14 are disabled
198 * by this regulatory domain no user regulatory domain can enable these
199 * channels at a later time. This can be used for devices which do not
200 * have calibration information gauranteed for frequencies or settings
201 * outside of its regulatory domain.
202 * @reg_notifier: the driver's regulatory notification callback
203 * @regd: the driver's regulatory domain, if one was requested via
204 * the regulatory_hint() API. This can be used by the driver
205 * on the reg_notifier() if it chooses to ignore future
206 * regulatory domain changes caused by other drivers.
207 * @signal_type: signal type reported in &struct cfg80211_bss.
208 */
209struct wiphy {
210 /* assign these fields before you register the wiphy */
211
212 /* permanent MAC address */
213 u8 perm_addr[ETH_ALEN];
214
215 /* Supported interface modes, OR together BIT(NL80211_IFTYPE_...) */
216 u16 interface_modes;
217
218 bool custom_regulatory;
219 bool strict_regulatory;
220
221 enum cfg80211_signal_type signal_type;
222
223 int bss_priv_size;
224 u8 max_scan_ssids;
225
226 /* If multiple wiphys are registered and you're handed e.g.
227 * a regular netdev with assigned ieee80211_ptr, you won't
228 * know whether it points to a wiphy your driver has registered
229 * or not. Assign this to something global to your driver to
230 * help determine whether you own this wiphy or not. */
231 void *privid;
232
233 struct ieee80211_supported_band *bands[IEEE80211_NUM_BANDS];
234
235 /* Lets us get back the wiphy on the callback */
236 int (*reg_notifier)(struct wiphy *wiphy,
237 struct regulatory_request *request);
238
239 /* fields below are read-only, assigned by cfg80211 */
240
241 const struct ieee80211_regdomain *regd;
242
243 /* the item in /sys/class/ieee80211/ points to this,
244 * you need use set_wiphy_dev() (see below) */
245 struct device dev;
246
247 /* dir in debugfs: ieee80211/<wiphyname> */
248 struct dentry *debugfsdir;
249
250 char priv[0] __attribute__((__aligned__(NETDEV_ALIGN)));
251};
252
253/** struct wireless_dev - wireless per-netdev state
254 *
255 * This structure must be allocated by the driver/stack
256 * that uses the ieee80211_ptr field in struct net_device
257 * (this is intentional so it can be allocated along with
258 * the netdev.)
259 *
260 * @wiphy: pointer to hardware description
261 * @iftype: interface type
262 */
263struct wireless_dev {
264 struct wiphy *wiphy;
265 enum nl80211_iftype iftype;
266
267 /* private to the generic wireless code */
268 struct list_head list;
269 struct net_device *netdev;
270};
271
272/**
273 * wiphy_priv - return priv from wiphy
274 */
275static inline void *wiphy_priv(struct wiphy *wiphy)
276{
277 BUG_ON(!wiphy);
278 return &wiphy->priv;
279}
280
281/**
282 * set_wiphy_dev - set device pointer for wiphy
283 */
284static inline void set_wiphy_dev(struct wiphy *wiphy, struct device *dev)
285{
286 wiphy->dev.parent = dev;
287}
288
289/**
290 * wiphy_dev - get wiphy dev pointer
291 */
292static inline struct device *wiphy_dev(struct wiphy *wiphy)
293{
294 return wiphy->dev.parent;
295}
296
297/**
298 * wiphy_name - get wiphy name
299 */
300static inline const char *wiphy_name(struct wiphy *wiphy)
301{
302 return dev_name(&wiphy->dev);
303}
304
305/**
306 * wdev_priv - return wiphy priv from wireless_dev
307 */
308static inline void *wdev_priv(struct wireless_dev *wdev)
309{
310 BUG_ON(!wdev);
311 return wiphy_priv(wdev->wiphy);
312}
313
314/**
315 * wiphy_new - create a new wiphy for use with cfg80211
316 *
317 * create a new wiphy and associate the given operations with it.
318 * @sizeof_priv bytes are allocated for private use.
319 *
320 * the returned pointer must be assigned to each netdev's
321 * ieee80211_ptr for proper operation.
322 */
323struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv);
324
325/**
326 * wiphy_register - register a wiphy with cfg80211
327 *
328 * register the given wiphy
329 *
330 * Returns a non-negative wiphy index or a negative error code.
331 */
332extern int wiphy_register(struct wiphy *wiphy);
333
334/**
335 * wiphy_unregister - deregister a wiphy from cfg80211
336 *
337 * unregister a device with the given priv pointer.
338 * After this call, no more requests can be made with this priv
339 * pointer, but the call may sleep to wait for an outstanding
340 * request that is being handled.
341 */
342extern void wiphy_unregister(struct wiphy *wiphy);
343
344/**
345 * wiphy_free - free wiphy
346 */
347extern void wiphy_free(struct wiphy *wiphy);
348
349/**
350 * ieee80211_channel_to_frequency - convert channel number to frequency
351 */
352extern int ieee80211_channel_to_frequency(int chan);
353
354/**
355 * ieee80211_frequency_to_channel - convert frequency to channel number
356 */
357extern int ieee80211_frequency_to_channel(int freq);
358
359/*
360 * Name indirection necessary because the ieee80211 code also has
361 * a function named "ieee80211_get_channel", so if you include
362 * cfg80211's header file you get cfg80211's version, if you try
363 * to include both header files you'll (rightfully!) get a symbol
364 * clash.
365 */
366extern struct ieee80211_channel *__ieee80211_get_channel(struct wiphy *wiphy,
367 int freq);
368/**
369 * ieee80211_get_channel - get channel struct from wiphy for specified frequency
370 */
371static inline struct ieee80211_channel *
372ieee80211_get_channel(struct wiphy *wiphy, int freq)
373{
374 return __ieee80211_get_channel(wiphy, freq);
375}
376
377/**
378 * ieee80211_get_response_rate - get basic rate for a given rate
379 *
380 * @sband: the band to look for rates in
381 * @basic_rates: bitmap of basic rates
382 * @bitrate: the bitrate for which to find the basic rate
383 *
384 * This function returns the basic rate corresponding to a given
385 * bitrate, that is the next lower bitrate contained in the basic
386 * rate map, which is, for this function, given as a bitmap of
387 * indices of rates in the band's bitrate table.
388 */
389struct ieee80211_rate *
390ieee80211_get_response_rate(struct ieee80211_supported_band *sband,
391 u32 basic_rates, int bitrate);
392
393/**
394 * regulatory_hint - driver hint to the wireless core a regulatory domain
395 * @wiphy: the wireless device giving the hint (used only for reporting
396 * conflicts)
397 * @alpha2: the ISO/IEC 3166 alpha2 the driver claims its regulatory domain
398 * should be in. If @rd is set this should be NULL. Note that if you
399 * set this to NULL you should still set rd->alpha2 to some accepted
400 * alpha2.
401 *
402 * Wireless drivers can use this function to hint to the wireless core
403 * what it believes should be the current regulatory domain by
404 * giving it an ISO/IEC 3166 alpha2 country code it knows its regulatory
405 * domain should be in or by providing a completely build regulatory domain.
406 * If the driver provides an ISO/IEC 3166 alpha2 userspace will be queried
407 * for a regulatory domain structure for the respective country.
408 *
409 * The wiphy must have been registered to cfg80211 prior to this call.
410 * For cfg80211 drivers this means you must first use wiphy_register(),
411 * for mac80211 drivers you must first use ieee80211_register_hw().
412 *
413 * Drivers should check the return value, its possible you can get
414 * an -ENOMEM.
415 */
416extern int regulatory_hint(struct wiphy *wiphy, const char *alpha2);
417
418/**
419 * regulatory_hint_11d - hints a country IE as a regulatory domain
420 * @wiphy: the wireless device giving the hint (used only for reporting
421 * conflicts)
422 * @country_ie: pointer to the country IE
423 * @country_ie_len: length of the country IE
424 *
425 * We will intersect the rd with the what CRDA tells us should apply
426 * for the alpha2 this country IE belongs to, this prevents APs from
427 * sending us incorrect or outdated information against a country.
428 */
429extern void regulatory_hint_11d(struct wiphy *wiphy,
430 u8 *country_ie,
431 u8 country_ie_len);
432/**
433 * wiphy_apply_custom_regulatory - apply a custom driver regulatory domain
434 * @wiphy: the wireless device we want to process the regulatory domain on
435 * @regd: the custom regulatory domain to use for this wiphy
436 *
437 * Drivers can sometimes have custom regulatory domains which do not apply
438 * to a specific country. Drivers can use this to apply such custom regulatory
439 * domains. This routine must be called prior to wiphy registration. The
440 * custom regulatory domain will be trusted completely and as such previous
441 * default channel settings will be disregarded. If no rule is found for a
442 * channel on the regulatory domain the channel will be disabled.
443 */
444extern void wiphy_apply_custom_regulatory(
445 struct wiphy *wiphy,
446 const struct ieee80211_regdomain *regd);
447
448/**
449 * freq_reg_info - get regulatory information for the given frequency
450 * @wiphy: the wiphy for which we want to process this rule for
451 * @center_freq: Frequency in KHz for which we want regulatory information for
452 * @bandwidth: the bandwidth requirement you have in KHz, if you do not have one
453 * you can set this to 0. If this frequency is allowed we then set
454 * this value to the maximum allowed bandwidth.
455 * @reg_rule: the regulatory rule which we have for this frequency
456 *
457 * Use this function to get the regulatory rule for a specific frequency on
458 * a given wireless device. If the device has a specific regulatory domain
459 * it wants to follow we respect that unless a country IE has been received
460 * and processed already.
461 *
462 * Returns 0 if it was able to find a valid regulatory rule which does
463 * apply to the given center_freq otherwise it returns non-zero. It will
464 * also return -ERANGE if we determine the given center_freq does not even have
465 * a regulatory rule for a frequency range in the center_freq's band. See
466 * freq_in_rule_band() for our current definition of a band -- this is purely
467 * subjective and right now its 802.11 specific.
468 */
469extern int freq_reg_info(struct wiphy *wiphy, u32 center_freq, u32 *bandwidth,
470 const struct ieee80211_reg_rule **reg_rule);
471
472#endif /* __NET_WIRELESS_H */
diff --git a/net/mac80211/Kconfig b/net/mac80211/Kconfig
index ecc3faf9f11a..9cbf545e95a2 100644
--- a/net/mac80211/Kconfig
+++ b/net/mac80211/Kconfig
@@ -11,6 +11,22 @@ config MAC80211
11 This option enables the hardware independent IEEE 802.11 11 This option enables the hardware independent IEEE 802.11
12 networking stack. 12 networking stack.
13 13
14config MAC80211_DEFAULT_PS
15 bool "enable powersave by default"
16 depends on MAC80211
17 default y
18 help
19 This option enables powersave mode by default.
20
21 If this causes your applications to misbehave you should fix your
22 applications instead -- they need to register their network
23 latency requirement, see Documentation/power/pm_qos_interface.txt.
24
25config MAC80211_DEFAULT_PS_VALUE
26 int
27 default 1 if MAC80211_DEFAULT_PS
28 default 0
29
14menu "Rate control algorithm selection" 30menu "Rate control algorithm selection"
15 depends on MAC80211 != n 31 depends on MAC80211 != n
16 32
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index e677b751d468..5e1c230744b5 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -1167,7 +1167,8 @@ static int ieee80211_scan(struct wiphy *wiphy,
1167 1167
1168 if (sdata->vif.type != NL80211_IFTYPE_STATION && 1168 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1169 sdata->vif.type != NL80211_IFTYPE_ADHOC && 1169 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
1170 sdata->vif.type != NL80211_IFTYPE_MESH_POINT) 1170 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1171 (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
1171 return -EOPNOTSUPP; 1172 return -EOPNOTSUPP;
1172 1173
1173 return ieee80211_request_scan(sdata, req); 1174 return ieee80211_request_scan(sdata, req);
@@ -1267,25 +1268,62 @@ static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1267static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, 1268static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
1268 struct cfg80211_deauth_request *req) 1269 struct cfg80211_deauth_request *req)
1269{ 1270{
1270 struct ieee80211_sub_if_data *sdata; 1271 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1271
1272 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1273 1272
1274 /* TODO: req->ie */ 1273 /* TODO: req->ie, req->peer_addr */
1275 return ieee80211_sta_deauthenticate(sdata, req->reason_code); 1274 return ieee80211_sta_deauthenticate(sdata, req->reason_code);
1276} 1275}
1277 1276
1278static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, 1277static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
1279 struct cfg80211_disassoc_request *req) 1278 struct cfg80211_disassoc_request *req)
1280{ 1279{
1281 struct ieee80211_sub_if_data *sdata; 1280 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1282
1283 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1284 1281
1285 /* TODO: req->ie */ 1282 /* TODO: req->ie, req->peer_addr */
1286 return ieee80211_sta_disassociate(sdata, req->reason_code); 1283 return ieee80211_sta_disassociate(sdata, req->reason_code);
1287} 1284}
1288 1285
1286static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1287 struct cfg80211_ibss_params *params)
1288{
1289 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1290
1291 return ieee80211_ibss_join(sdata, params);
1292}
1293
1294static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1295{
1296 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1297
1298 return ieee80211_ibss_leave(sdata);
1299}
1300
1301static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1302{
1303 struct ieee80211_local *local = wiphy_priv(wiphy);
1304
1305 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
1306 int err;
1307
1308 if (local->ops->set_rts_threshold) {
1309 err = local->ops->set_rts_threshold(
1310 local_to_hw(local), wiphy->rts_threshold);
1311 if (err)
1312 return err;
1313 }
1314 }
1315
1316 if (changed & WIPHY_PARAM_RETRY_SHORT)
1317 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1318 if (changed & WIPHY_PARAM_RETRY_LONG)
1319 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1320 if (changed &
1321 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1322 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1323
1324 return 0;
1325}
1326
1289struct cfg80211_ops mac80211_config_ops = { 1327struct cfg80211_ops mac80211_config_ops = {
1290 .add_virtual_intf = ieee80211_add_iface, 1328 .add_virtual_intf = ieee80211_add_iface,
1291 .del_virtual_intf = ieee80211_del_iface, 1329 .del_virtual_intf = ieee80211_del_iface,
@@ -1322,4 +1360,7 @@ struct cfg80211_ops mac80211_config_ops = {
1322 .assoc = ieee80211_assoc, 1360 .assoc = ieee80211_assoc,
1323 .deauth = ieee80211_deauth, 1361 .deauth = ieee80211_deauth,
1324 .disassoc = ieee80211_disassoc, 1362 .disassoc = ieee80211_disassoc,
1363 .join_ibss = ieee80211_join_ibss,
1364 .leave_ibss = ieee80211_leave_ibss,
1365 .set_wiphy_params = ieee80211_set_wiphy_params,
1325}; 1366};
diff --git a/net/mac80211/debugfs.c b/net/mac80211/debugfs.c
index 210b9b6fecd2..5001328be46b 100644
--- a/net/mac80211/debugfs.c
+++ b/net/mac80211/debugfs.c
@@ -52,13 +52,13 @@ static const struct file_operations name## _ops = { \
52DEBUGFS_READONLY_FILE(frequency, 20, "%d", 52DEBUGFS_READONLY_FILE(frequency, 20, "%d",
53 local->hw.conf.channel->center_freq); 53 local->hw.conf.channel->center_freq);
54DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d", 54DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
55 local->rts_threshold); 55 local->hw.wiphy->rts_threshold);
56DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d", 56DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
57 local->fragmentation_threshold); 57 local->hw.wiphy->frag_threshold);
58DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d", 58DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
59 local->hw.conf.short_frame_max_tx_count); 59 local->hw.wiphy->retry_short);
60DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d", 60DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
61 local->hw.conf.long_frame_max_tx_count); 61 local->hw.wiphy->retry_long);
62DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d", 62DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
63 local->total_ps_buffered); 63 local->total_ps_buffered);
64DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x", 64DEBUGFS_READONLY_FILE(wep_iv, 20, "%#08x",
diff --git a/net/mac80211/event.c b/net/mac80211/event.c
index 0d95561c0ee0..f288d01a6344 100644
--- a/net/mac80211/event.c
+++ b/net/mac80211/event.c
@@ -12,12 +12,12 @@
12#include "ieee80211_i.h" 12#include "ieee80211_i.h"
13 13
14/* 14/*
15 * indicate a failed Michael MIC to userspace; the passed packet 15 * Indicate a failed Michael MIC to userspace. If the caller knows the TSC of
16 * (in the variable hdr) must be long enough to extract the TKIP 16 * the frame that generated the MIC failure (i.e., if it was provided by the
17 * fields like TSC 17 * driver or is still in the frame), it should provide that information.
18 */ 18 */
19void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx, 19void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx,
20 struct ieee80211_hdr *hdr) 20 struct ieee80211_hdr *hdr, const u8 *tsc)
21{ 21{
22 union iwreq_data wrqu; 22 union iwreq_data wrqu;
23 char *buf = kmalloc(128, GFP_ATOMIC); 23 char *buf = kmalloc(128, GFP_ATOMIC);
@@ -34,8 +34,9 @@ void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int ke
34 kfree(buf); 34 kfree(buf);
35 } 35 }
36 36
37 /* 37 cfg80211_michael_mic_failure(sdata->dev, hdr->addr2,
38 * TODO: re-add support for sending MIC failure indication 38 (hdr->addr1[0] & 0x01) ?
39 * with all info via nl80211 39 NL80211_KEYTYPE_GROUP :
40 */ 40 NL80211_KEYTYPE_PAIRWISE,
41 keyidx, tsc);
41} 42}
diff --git a/net/mac80211/ht.c b/net/mac80211/ht.c
index 4e3c72f20de7..0891bfb06996 100644
--- a/net/mac80211/ht.c
+++ b/net/mac80211/ht.c
@@ -14,7 +14,6 @@
14 */ 14 */
15 15
16#include <linux/ieee80211.h> 16#include <linux/ieee80211.h>
17#include <net/wireless.h>
18#include <net/mac80211.h> 17#include <net/mac80211.h>
19#include "ieee80211_i.h" 18#include "ieee80211_i.h"
20#include "rate.h" 19#include "rate.h"
@@ -83,89 +82,6 @@ void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband,
83 ht_cap->mcs.rx_mask[32/8] |= 1; 82 ht_cap->mcs.rx_mask[32/8] |= 1;
84} 83}
85 84
86/*
87 * ieee80211_enable_ht should be called only after the operating band
88 * has been determined as ht configuration depends on the hw's
89 * HT abilities for a specific band.
90 */
91u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
92 struct ieee80211_ht_info *hti,
93 u16 ap_ht_cap_flags)
94{
95 struct ieee80211_local *local = sdata->local;
96 struct ieee80211_supported_band *sband;
97 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
98 struct ieee80211_bss_ht_conf ht;
99 struct sta_info *sta;
100 u32 changed = 0;
101 bool enable_ht = true, ht_changed;
102 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
103
104 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
105
106 memset(&ht, 0, sizeof(ht));
107
108 /* HT is not supported */
109 if (!sband->ht_cap.ht_supported)
110 enable_ht = false;
111
112 /* check that channel matches the right operating channel */
113 if (local->hw.conf.channel->center_freq !=
114 ieee80211_channel_to_frequency(hti->control_chan))
115 enable_ht = false;
116
117 if (enable_ht) {
118 channel_type = NL80211_CHAN_HT20;
119
120 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
121 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
122 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
123 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
124 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
125 channel_type = NL80211_CHAN_HT40PLUS;
126 break;
127 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
128 channel_type = NL80211_CHAN_HT40MINUS;
129 break;
130 }
131 }
132 }
133
134 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
135 channel_type != local->hw.conf.channel_type;
136
137 local->oper_channel_type = channel_type;
138
139 if (ht_changed) {
140 /* channel_type change automatically detected */
141 ieee80211_hw_config(local, 0);
142
143 rcu_read_lock();
144
145 sta = sta_info_get(local, ifmgd->bssid);
146 if (sta)
147 rate_control_rate_update(local, sband, sta,
148 IEEE80211_RC_HT_CHANGED);
149
150 rcu_read_unlock();
151
152 }
153
154 /* disable HT */
155 if (!enable_ht)
156 return 0;
157
158 ht.operation_mode = le16_to_cpu(hti->operation_mode);
159
160 /* if bss configuration changed store the new one */
161 if (memcmp(&sdata->vif.bss_conf.ht, &ht, sizeof(ht))) {
162 changed |= BSS_CHANGED_HT;
163 sdata->vif.bss_conf.ht = ht;
164 }
165
166 return changed;
167}
168
169void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta) 85void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta)
170{ 86{
171 int i; 87 int i;
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 3201e1f96365..6030e003180c 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -59,74 +59,59 @@ static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata,
59 sdata->u.ibss.bssid, 0); 59 sdata->u.ibss.bssid, 0);
60} 60}
61 61
62static int __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, 62static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
63 const u8 *bssid, const int beacon_int, 63 const u8 *bssid, const int beacon_int,
64 const int freq, 64 struct ieee80211_channel *chan,
65 const size_t supp_rates_len, 65 const size_t supp_rates_len,
66 const u8 *supp_rates, 66 const u8 *supp_rates,
67 const u16 capability, u64 tsf) 67 const u16 capability, u64 tsf)
68{ 68{
69 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 69 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
70 struct ieee80211_local *local = sdata->local; 70 struct ieee80211_local *local = sdata->local;
71 int res = 0, rates, i, j; 71 int rates, i, j;
72 struct sk_buff *skb; 72 struct sk_buff *skb;
73 struct ieee80211_mgmt *mgmt; 73 struct ieee80211_mgmt *mgmt;
74 u8 *pos; 74 u8 *pos;
75 struct ieee80211_supported_band *sband; 75 struct ieee80211_supported_band *sband;
76 union iwreq_data wrqu;
77 76
78 if (local->ops->reset_tsf) { 77 if (local->ops->reset_tsf) {
79 /* Reset own TSF to allow time synchronization work. */ 78 /* Reset own TSF to allow time synchronization work. */
80 local->ops->reset_tsf(local_to_hw(local)); 79 local->ops->reset_tsf(local_to_hw(local));
81 } 80 }
82 81
83 if ((ifibss->flags & IEEE80211_IBSS_PREV_BSSID_SET) && 82 skb = ifibss->skb;
84 memcmp(ifibss->bssid, bssid, ETH_ALEN) == 0) 83 rcu_assign_pointer(ifibss->presp, NULL);
85 return res; 84 synchronize_rcu();
85 skb->data = skb->head;
86 skb->len = 0;
87 skb_reset_tail_pointer(skb);
88 skb_reserve(skb, sdata->local->hw.extra_tx_headroom);
86 89
87 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 400); 90 if (memcmp(ifibss->bssid, bssid, ETH_ALEN))
88 if (!skb) { 91 sta_info_flush(sdata->local, sdata);
89 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
90 "response\n", sdata->dev->name);
91 return -ENOMEM;
92 }
93
94 if (!(ifibss->flags & IEEE80211_IBSS_PREV_BSSID_SET)) {
95 /* Remove possible STA entries from other IBSS networks. */
96 sta_info_flush_delayed(sdata);
97 }
98 92
99 memcpy(ifibss->bssid, bssid, ETH_ALEN); 93 memcpy(ifibss->bssid, bssid, ETH_ALEN);
100 res = ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
101 if (res)
102 return res;
103 94
104 local->hw.conf.beacon_int = beacon_int >= 10 ? beacon_int : 10; 95 local->hw.conf.beacon_int = beacon_int >= 10 ? beacon_int : 10;
105 96
106 sdata->drop_unencrypted = capability & 97 sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0;
107 WLAN_CAPABILITY_PRIVACY ? 1 : 0;
108
109 res = ieee80211_set_freq(sdata, freq);
110 98
111 if (res) 99 ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID);
112 return res;
113 100
114 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 101 local->oper_channel = chan;
102 local->oper_channel_type = NL80211_CHAN_NO_HT;
103 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
104 sband = local->hw.wiphy->bands[chan->band];
115 105
116 /* Build IBSS probe response */ 106 /* Build IBSS probe response */
117 107 mgmt = (void *) skb_put(skb, 24 + sizeof(mgmt->u.beacon));
118 skb_reserve(skb, local->hw.extra_tx_headroom);
119
120 mgmt = (struct ieee80211_mgmt *)
121 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
122 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); 108 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
123 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 109 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
124 IEEE80211_STYPE_PROBE_RESP); 110 IEEE80211_STYPE_PROBE_RESP);
125 memset(mgmt->da, 0xff, ETH_ALEN); 111 memset(mgmt->da, 0xff, ETH_ALEN);
126 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); 112 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
127 memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN); 113 memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN);
128 mgmt->u.beacon.beacon_int = 114 mgmt->u.beacon.beacon_int = cpu_to_le16(local->hw.conf.beacon_int);
129 cpu_to_le16(local->hw.conf.beacon_int);
130 mgmt->u.beacon.timestamp = cpu_to_le64(tsf); 115 mgmt->u.beacon.timestamp = cpu_to_le64(tsf);
131 mgmt->u.beacon.capab_info = cpu_to_le16(capability); 116 mgmt->u.beacon.capab_info = cpu_to_le16(capability);
132 117
@@ -147,7 +132,7 @@ static int __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
147 pos = skb_put(skb, 2 + 1); 132 pos = skb_put(skb, 2 + 1);
148 *pos++ = WLAN_EID_DS_PARAMS; 133 *pos++ = WLAN_EID_DS_PARAMS;
149 *pos++ = 1; 134 *pos++ = 1;
150 *pos++ = ieee80211_frequency_to_channel(freq); 135 *pos++ = ieee80211_frequency_to_channel(chan->center_freq);
151 } 136 }
152 137
153 pos = skb_put(skb, 2 + 2); 138 pos = skb_put(skb, 2 + 2);
@@ -165,12 +150,15 @@ static int __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
165 memcpy(pos, &supp_rates[8], rates); 150 memcpy(pos, &supp_rates[8], rates);
166 } 151 }
167 152
168 ifibss->probe_resp = skb; 153 if (ifibss->ie_len)
154 memcpy(skb_put(skb, ifibss->ie_len),
155 ifibss->ie, ifibss->ie_len);
156
157 rcu_assign_pointer(ifibss->presp, skb);
169 158
170 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON | 159 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON |
171 IEEE80211_IFCC_BEACON_ENABLED); 160 IEEE80211_IFCC_BEACON_ENABLED);
172 161
173
174 rates = 0; 162 rates = 0;
175 for (i = 0; i < supp_rates_len; i++) { 163 for (i = 0; i < supp_rates_len; i++) {
176 int bitrate = (supp_rates[i] & 0x7f) * 5; 164 int bitrate = (supp_rates[i] & 0x7f) * 5;
@@ -181,27 +169,24 @@ static int __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
181 169
182 ieee80211_sta_def_wmm_params(sdata, supp_rates_len, supp_rates); 170 ieee80211_sta_def_wmm_params(sdata, supp_rates_len, supp_rates);
183 171
184 ifibss->flags |= IEEE80211_IBSS_PREV_BSSID_SET;
185 ifibss->state = IEEE80211_IBSS_MLME_JOINED; 172 ifibss->state = IEEE80211_IBSS_MLME_JOINED;
186 mod_timer(&ifibss->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); 173 mod_timer(&ifibss->timer,
174 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
187 175
188 memset(&wrqu, 0, sizeof(wrqu)); 176 cfg80211_inform_bss_frame(local->hw.wiphy, local->hw.conf.channel,
189 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN); 177 mgmt, skb->len, 0, GFP_KERNEL);
190 wireless_send_event(sdata->dev, SIOCGIWAP, &wrqu, NULL); 178 cfg80211_ibss_joined(sdata->dev, ifibss->bssid, GFP_KERNEL);
191
192 return res;
193} 179}
194 180
195static int ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata, 181static void ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
196 struct ieee80211_bss *bss) 182 struct ieee80211_bss *bss)
197{ 183{
198 return __ieee80211_sta_join_ibss(sdata, 184 __ieee80211_sta_join_ibss(sdata, bss->cbss.bssid,
199 bss->cbss.bssid, 185 bss->cbss.beacon_interval,
200 bss->cbss.beacon_interval, 186 bss->cbss.channel,
201 bss->cbss.channel->center_freq, 187 bss->supp_rates_len, bss->supp_rates,
202 bss->supp_rates_len, bss->supp_rates, 188 bss->cbss.capability,
203 bss->cbss.capability, 189 bss->cbss.tsf);
204 bss->cbss.tsf);
205} 190}
206 191
207static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, 192static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
@@ -277,7 +262,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
277 goto put_bss; 262 goto put_bss;
278 263
279 /* we use a fixed BSSID */ 264 /* we use a fixed BSSID */
280 if (sdata->u.ibss.flags & IEEE80211_IBSS_BSSID_SET) 265 if (sdata->u.ibss.bssid)
281 goto put_bss; 266 goto put_bss;
282 267
283 /* not an IBSS */ 268 /* not an IBSS */
@@ -369,13 +354,14 @@ struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
369 struct sta_info *sta; 354 struct sta_info *sta;
370 int band = local->hw.conf.channel->band; 355 int band = local->hw.conf.channel->band;
371 356
372 /* TODO: Could consider removing the least recently used entry and 357 /*
373 * allow new one to be added. */ 358 * XXX: Consider removing the least recently used entry and
359 * allow new one to be added.
360 */
374 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) { 361 if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
375 if (net_ratelimit()) { 362 if (net_ratelimit())
376 printk(KERN_DEBUG "%s: No room for a new IBSS STA " 363 printk(KERN_DEBUG "%s: No room for a new IBSS STA entry %pM\n",
377 "entry %pM\n", sdata->dev->name, addr); 364 sdata->dev->name, addr);
378 }
379 return NULL; 365 return NULL;
380 } 366 }
381 367
@@ -432,14 +418,15 @@ static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
432{ 418{
433 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 419 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
434 420
435 mod_timer(&ifibss->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL); 421 mod_timer(&ifibss->timer,
422 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
436 423
437 ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT); 424 ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT);
425
438 if (ieee80211_sta_active_ibss(sdata)) 426 if (ieee80211_sta_active_ibss(sdata))
439 return; 427 return;
440 428
441 if ((ifibss->flags & IEEE80211_IBSS_BSSID_SET) && 429 if (ifibss->fixed_channel)
442 (!(ifibss->flags & IEEE80211_IBSS_AUTO_CHANNEL_SEL)))
443 return; 430 return;
444 431
445 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " 432 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
@@ -455,7 +442,7 @@ static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
455 ieee80211_request_scan(sdata, &sdata->local->int_scan_req); 442 ieee80211_request_scan(sdata, &sdata->local->int_scan_req);
456} 443}
457 444
458static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata) 445static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
459{ 446{
460 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 447 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
461 struct ieee80211_local *local = sdata->local; 448 struct ieee80211_local *local = sdata->local;
@@ -466,7 +453,7 @@ static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
466 u16 capability; 453 u16 capability;
467 int i; 454 int i;
468 455
469 if (ifibss->flags & IEEE80211_IBSS_BSSID_SET) { 456 if (ifibss->fixed_bssid) {
470 memcpy(bssid, ifibss->bssid, ETH_ALEN); 457 memcpy(bssid, ifibss->bssid, ETH_ALEN);
471 } else { 458 } else {
472 /* Generate random, not broadcast, locally administered BSSID. Mix in 459 /* Generate random, not broadcast, locally administered BSSID. Mix in
@@ -482,7 +469,7 @@ static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
482 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n", 469 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n",
483 sdata->dev->name, bssid); 470 sdata->dev->name, bssid);
484 471
485 sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 472 sband = local->hw.wiphy->bands[ifibss->channel->band];
486 473
487 if (local->hw.conf.beacon_int == 0) 474 if (local->hw.conf.beacon_int == 0)
488 local->hw.conf.beacon_int = 100; 475 local->hw.conf.beacon_int = 100;
@@ -500,24 +487,20 @@ static int ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
500 *pos++ = (u8) (rate / 5); 487 *pos++ = (u8) (rate / 5);
501 } 488 }
502 489
503 return __ieee80211_sta_join_ibss(sdata, 490 __ieee80211_sta_join_ibss(sdata, bssid, local->hw.conf.beacon_int,
504 bssid, local->hw.conf.beacon_int, 491 ifibss->channel, sband->n_bitrates,
505 local->hw.conf.channel->center_freq, 492 supp_rates, capability, 0);
506 sband->n_bitrates, supp_rates,
507 capability, 0);
508} 493}
509 494
510static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata) 495static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
511{ 496{
512 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 497 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
513 struct ieee80211_local *local = sdata->local; 498 struct ieee80211_local *local = sdata->local;
514 struct ieee80211_bss *bss; 499 struct ieee80211_bss *bss;
500 struct ieee80211_channel *chan = NULL;
515 const u8 *bssid = NULL; 501 const u8 *bssid = NULL;
516 int active_ibss; 502 int active_ibss;
517 503
518 if (ifibss->ssid_len == 0)
519 return -EINVAL;
520
521 active_ibss = ieee80211_sta_active_ibss(sdata); 504 active_ibss = ieee80211_sta_active_ibss(sdata);
522#ifdef CONFIG_MAC80211_IBSS_DEBUG 505#ifdef CONFIG_MAC80211_IBSS_DEBUG
523 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", 506 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
@@ -525,11 +508,15 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
525#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 508#endif /* CONFIG_MAC80211_IBSS_DEBUG */
526 509
527 if (active_ibss) 510 if (active_ibss)
528 return 0; 511 return;
529 512
530 if (ifibss->flags & IEEE80211_IBSS_BSSID_SET) 513 if (ifibss->fixed_bssid)
514 bssid = ifibss->bssid;
515 if (ifibss->fixed_channel)
516 chan = ifibss->channel;
517 if (!is_zero_ether_addr(ifibss->bssid))
531 bssid = ifibss->bssid; 518 bssid = ifibss->bssid;
532 bss = (void *)cfg80211_get_bss(local->hw.wiphy, NULL, bssid, 519 bss = (void *)cfg80211_get_bss(local->hw.wiphy, chan, bssid,
533 ifibss->ssid, ifibss->ssid_len, 520 ifibss->ssid, ifibss->ssid_len,
534 WLAN_CAPABILITY_IBSS, 521 WLAN_CAPABILITY_IBSS,
535 WLAN_CAPABILITY_IBSS); 522 WLAN_CAPABILITY_IBSS);
@@ -540,18 +527,14 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
540 "%pM\n", bss->cbss.bssid, ifibss->bssid); 527 "%pM\n", bss->cbss.bssid, ifibss->bssid);
541#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 528#endif /* CONFIG_MAC80211_IBSS_DEBUG */
542 529
543 if (bss && 530 if (bss && memcmp(ifibss->bssid, bss->cbss.bssid, ETH_ALEN)) {
544 (!(ifibss->flags & IEEE80211_IBSS_PREV_BSSID_SET) ||
545 memcmp(ifibss->bssid, bss->cbss.bssid, ETH_ALEN))) {
546 int ret;
547
548 printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM" 531 printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM"
549 " based on configured SSID\n", 532 " based on configured SSID\n",
550 sdata->dev->name, bss->cbss.bssid); 533 sdata->dev->name, bss->cbss.bssid);
551 534
552 ret = ieee80211_sta_join_ibss(sdata, bss); 535 ieee80211_sta_join_ibss(sdata, bss);
553 ieee80211_rx_bss_put(local, bss); 536 ieee80211_rx_bss_put(local, bss);
554 return ret; 537 return;
555 } else if (bss) 538 } else if (bss)
556 ieee80211_rx_bss_put(local, bss); 539 ieee80211_rx_bss_put(local, bss);
557 540
@@ -562,29 +545,31 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
562 /* Selected IBSS not found in current scan results - try to scan */ 545 /* Selected IBSS not found in current scan results - try to scan */
563 if (ifibss->state == IEEE80211_IBSS_MLME_JOINED && 546 if (ifibss->state == IEEE80211_IBSS_MLME_JOINED &&
564 !ieee80211_sta_active_ibss(sdata)) { 547 !ieee80211_sta_active_ibss(sdata)) {
565 mod_timer(&ifibss->timer, jiffies + 548 mod_timer(&ifibss->timer,
566 IEEE80211_IBSS_MERGE_INTERVAL); 549 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
567 } else if (time_after(jiffies, local->last_scan_completed + 550 } else if (time_after(jiffies, ifibss->last_scan_completed +
568 IEEE80211_SCAN_INTERVAL)) { 551 IEEE80211_SCAN_INTERVAL)) {
569 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " 552 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
570 "join\n", sdata->dev->name); 553 "join\n", sdata->dev->name);
571 554
572 /* XXX maybe racy? */ 555 /* XXX maybe racy? */
573 if (local->scan_req) 556 if (local->scan_req)
574 return -EBUSY; 557 return;
575 558
576 memcpy(local->int_scan_req.ssids[0].ssid, 559 memcpy(local->int_scan_req.ssids[0].ssid,
577 ifibss->ssid, IEEE80211_MAX_SSID_LEN); 560 ifibss->ssid, IEEE80211_MAX_SSID_LEN);
578 local->int_scan_req.ssids[0].ssid_len = ifibss->ssid_len; 561 local->int_scan_req.ssids[0].ssid_len =
579 return ieee80211_request_scan(sdata, &local->int_scan_req); 562 ifibss->ssid_len;
563 ieee80211_request_scan(sdata, &local->int_scan_req);
580 } else if (ifibss->state != IEEE80211_IBSS_MLME_JOINED) { 564 } else if (ifibss->state != IEEE80211_IBSS_MLME_JOINED) {
581 int interval = IEEE80211_SCAN_INTERVAL; 565 int interval = IEEE80211_SCAN_INTERVAL;
582 566
583 if (time_after(jiffies, ifibss->ibss_join_req + 567 if (time_after(jiffies, ifibss->ibss_join_req +
584 IEEE80211_IBSS_JOIN_TIMEOUT)) { 568 IEEE80211_IBSS_JOIN_TIMEOUT)) {
585 if (!(local->oper_channel->flags & 569 if (!(local->oper_channel->flags & IEEE80211_CHAN_NO_IBSS)) {
586 IEEE80211_CHAN_NO_IBSS)) 570 ieee80211_sta_create_ibss(sdata);
587 return ieee80211_sta_create_ibss(sdata); 571 return;
572 }
588 printk(KERN_DEBUG "%s: IBSS not allowed on" 573 printk(KERN_DEBUG "%s: IBSS not allowed on"
589 " %d MHz\n", sdata->dev->name, 574 " %d MHz\n", sdata->dev->name,
590 local->hw.conf.channel->center_freq); 575 local->hw.conf.channel->center_freq);
@@ -595,11 +580,9 @@ static int ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
595 } 580 }
596 581
597 ifibss->state = IEEE80211_IBSS_MLME_SEARCH; 582 ifibss->state = IEEE80211_IBSS_MLME_SEARCH;
598 mod_timer(&ifibss->timer, jiffies + interval); 583 mod_timer(&ifibss->timer,
599 return 0; 584 round_jiffies(jiffies + interval));
600 } 585 }
601
602 return 0;
603} 586}
604 587
605static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata, 588static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
@@ -614,7 +597,7 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
614 u8 *pos, *end; 597 u8 *pos, *end;
615 598
616 if (ifibss->state != IEEE80211_IBSS_MLME_JOINED || 599 if (ifibss->state != IEEE80211_IBSS_MLME_JOINED ||
617 len < 24 + 2 || !ifibss->probe_resp) 600 len < 24 + 2 || !ifibss->presp)
618 return; 601 return;
619 602
620 if (local->ops->tx_last_beacon) 603 if (local->ops->tx_last_beacon)
@@ -649,13 +632,13 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
649 } 632 }
650 if (pos[1] != 0 && 633 if (pos[1] != 0 &&
651 (pos[1] != ifibss->ssid_len || 634 (pos[1] != ifibss->ssid_len ||
652 memcmp(pos + 2, ifibss->ssid, ifibss->ssid_len) != 0)) { 635 !memcmp(pos + 2, ifibss->ssid, ifibss->ssid_len))) {
653 /* Ignore ProbeReq for foreign SSID */ 636 /* Ignore ProbeReq for foreign SSID */
654 return; 637 return;
655 } 638 }
656 639
657 /* Reply with ProbeResp */ 640 /* Reply with ProbeResp */
658 skb = skb_copy(ifibss->probe_resp, GFP_KERNEL); 641 skb = skb_copy(ifibss->presp, GFP_KERNEL);
659 if (!skb) 642 if (!skb)
660 return; 643 return;
661 644
@@ -794,89 +777,21 @@ void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata)
794 setup_timer(&ifibss->timer, ieee80211_ibss_timer, 777 setup_timer(&ifibss->timer, ieee80211_ibss_timer,
795 (unsigned long) sdata); 778 (unsigned long) sdata);
796 skb_queue_head_init(&ifibss->skb_queue); 779 skb_queue_head_init(&ifibss->skb_queue);
797
798 ifibss->flags |= IEEE80211_IBSS_AUTO_BSSID_SEL |
799 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
800}
801
802int ieee80211_ibss_commit(struct ieee80211_sub_if_data *sdata)
803{
804 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
805
806 ifibss->flags &= ~IEEE80211_IBSS_PREV_BSSID_SET;
807
808 if (ifibss->ssid_len)
809 ifibss->flags |= IEEE80211_IBSS_SSID_SET;
810 else
811 ifibss->flags &= ~IEEE80211_IBSS_SSID_SET;
812
813 ifibss->ibss_join_req = jiffies;
814 ifibss->state = IEEE80211_IBSS_MLME_SEARCH;
815 set_bit(IEEE80211_IBSS_REQ_RUN, &ifibss->request);
816
817 return 0;
818}
819
820int ieee80211_ibss_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len)
821{
822 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
823
824 if (len > IEEE80211_MAX_SSID_LEN)
825 return -EINVAL;
826
827 if (ifibss->ssid_len != len || memcmp(ifibss->ssid, ssid, len) != 0) {
828 memset(ifibss->ssid, 0, sizeof(ifibss->ssid));
829 memcpy(ifibss->ssid, ssid, len);
830 ifibss->ssid_len = len;
831 }
832
833 return ieee80211_ibss_commit(sdata);
834}
835
836int ieee80211_ibss_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len)
837{
838 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
839
840 memcpy(ssid, ifibss->ssid, ifibss->ssid_len);
841 *len = ifibss->ssid_len;
842
843 return 0;
844}
845
846int ieee80211_ibss_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid)
847{
848 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
849
850 if (is_valid_ether_addr(bssid)) {
851 memcpy(ifibss->bssid, bssid, ETH_ALEN);
852 ifibss->flags |= IEEE80211_IBSS_BSSID_SET;
853 } else {
854 memset(ifibss->bssid, 0, ETH_ALEN);
855 ifibss->flags &= ~IEEE80211_IBSS_BSSID_SET;
856 }
857
858 if (netif_running(sdata->dev)) {
859 if (ieee80211_if_config(sdata, IEEE80211_IFCC_BSSID)) {
860 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
861 "the low-level driver\n", sdata->dev->name);
862 }
863 }
864
865 return ieee80211_ibss_commit(sdata);
866} 780}
867 781
868/* scan finished notification */ 782/* scan finished notification */
869void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local) 783void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local)
870{ 784{
871 struct ieee80211_sub_if_data *sdata = local->scan_sdata; 785 struct ieee80211_sub_if_data *sdata;
872 struct ieee80211_if_ibss *ifibss;
873 786
874 if (sdata && sdata->vif.type == NL80211_IFTYPE_ADHOC) { 787 mutex_lock(&local->iflist_mtx);
875 ifibss = &sdata->u.ibss; 788 list_for_each_entry(sdata, &local->interfaces, list) {
876 if ((!(ifibss->flags & IEEE80211_IBSS_PREV_BSSID_SET)) || 789 if (sdata->vif.type != NL80211_IFTYPE_ADHOC)
877 !ieee80211_sta_active_ibss(sdata)) 790 continue;
878 ieee80211_sta_find_ibss(sdata); 791 sdata->u.ibss.last_scan_completed = jiffies;
792 ieee80211_sta_find_ibss(sdata);
879 } 793 }
794 mutex_unlock(&local->iflist_mtx);
880} 795}
881 796
882ieee80211_rx_result 797ieee80211_rx_result
@@ -906,3 +821,71 @@ ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
906 821
907 return RX_DROP_MONITOR; 822 return RX_DROP_MONITOR;
908} 823}
824
825int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
826 struct cfg80211_ibss_params *params)
827{
828 struct sk_buff *skb;
829
830 memcpy(sdata->u.ibss.ssid, params->ssid, IEEE80211_MAX_SSID_LEN);
831 sdata->u.ibss.ssid_len = params->ssid_len;
832
833 if (params->bssid) {
834 memcpy(sdata->u.ibss.bssid, params->bssid, ETH_ALEN);
835 sdata->u.ibss.fixed_bssid = true;
836 } else
837 sdata->u.ibss.fixed_bssid = false;
838
839 sdata->u.ibss.channel = params->channel;
840 sdata->u.ibss.fixed_channel = params->channel_fixed;
841
842 if (params->ie) {
843 sdata->u.ibss.ie = kmemdup(params->ie, params->ie_len,
844 GFP_KERNEL);
845 if (sdata->u.ibss.ie)
846 sdata->u.ibss.ie_len = params->ie_len;
847 }
848
849 skb = dev_alloc_skb(sdata->local->hw.extra_tx_headroom +
850 36 /* bitrates */ +
851 34 /* SSID */ +
852 3 /* DS params */ +
853 4 /* IBSS params */ +
854 params->ie_len);
855 if (!skb)
856 return -ENOMEM;
857
858 sdata->u.ibss.skb = skb;
859 sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH;
860 sdata->u.ibss.ibss_join_req = jiffies;
861
862 set_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request);
863 queue_work(sdata->local->hw.workqueue, &sdata->u.ibss.work);
864
865 return 0;
866}
867
868int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata)
869{
870 struct sk_buff *skb;
871
872 del_timer_sync(&sdata->u.ibss.timer);
873 clear_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request);
874 cancel_work_sync(&sdata->u.ibss.work);
875 clear_bit(IEEE80211_IBSS_REQ_RUN, &sdata->u.ibss.request);
876
877 sta_info_flush(sdata->local, sdata);
878
879 /* remove beacon */
880 kfree(sdata->u.ibss.ie);
881 skb = sdata->u.ibss.presp;
882 rcu_assign_pointer(sdata->u.ibss.presp, NULL);
883 ieee80211_if_config(sdata, IEEE80211_IFCC_BEACON_ENABLED);
884 synchronize_rcu();
885 kfree_skb(skb);
886
887 skb_queue_purge(&sdata->u.ibss.skb_queue);
888 memset(sdata->u.ibss.bssid, 0, ETH_ALEN);
889
890 return 0;
891}
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index e6ed78cb16b3..1579bc92c88d 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -24,7 +24,6 @@
24#include <linux/spinlock.h> 24#include <linux/spinlock.h>
25#include <linux/etherdevice.h> 25#include <linux/etherdevice.h>
26#include <net/cfg80211.h> 26#include <net/cfg80211.h>
27#include <net/wireless.h>
28#include <net/iw_handler.h> 27#include <net/iw_handler.h>
29#include <net/mac80211.h> 28#include <net/mac80211.h>
30#include "key.h" 29#include "key.h"
@@ -295,6 +294,8 @@ struct ieee80211_if_managed {
295 int auth_tries; /* retries for auth req */ 294 int auth_tries; /* retries for auth req */
296 int assoc_tries; /* retries for assoc req */ 295 int assoc_tries; /* retries for assoc req */
297 296
297 bool powersave; /* powersave requested for this iface */
298
298 unsigned long request; 299 unsigned long request;
299 300
300 unsigned long last_probe; 301 unsigned long last_probe;
@@ -306,6 +307,8 @@ struct ieee80211_if_managed {
306 int auth_alg; /* currently used IEEE 802.11 authentication algorithm */ 307 int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
307 int auth_transaction; 308 int auth_transaction;
308 309
310 u32 beacon_crc;
311
309 enum { 312 enum {
310 IEEE80211_MFP_DISABLED, 313 IEEE80211_MFP_DISABLED,
311 IEEE80211_MFP_OPTIONAL, 314 IEEE80211_MFP_OPTIONAL,
@@ -319,14 +322,6 @@ struct ieee80211_if_managed {
319 size_t sme_auth_ie_len; 322 size_t sme_auth_ie_len;
320}; 323};
321 324
322enum ieee80211_ibss_flags {
323 IEEE80211_IBSS_AUTO_CHANNEL_SEL = BIT(0),
324 IEEE80211_IBSS_AUTO_BSSID_SEL = BIT(1),
325 IEEE80211_IBSS_BSSID_SET = BIT(2),
326 IEEE80211_IBSS_PREV_BSSID_SET = BIT(3),
327 IEEE80211_IBSS_SSID_SET = BIT(4),
328};
329
330enum ieee80211_ibss_request { 325enum ieee80211_ibss_request {
331 IEEE80211_IBSS_REQ_RUN = 0, 326 IEEE80211_IBSS_REQ_RUN = 0,
332}; 327};
@@ -337,17 +332,20 @@ struct ieee80211_if_ibss {
337 332
338 struct sk_buff_head skb_queue; 333 struct sk_buff_head skb_queue;
339 334
340 u8 ssid[IEEE80211_MAX_SSID_LEN]; 335 unsigned long request;
341 u8 ssid_len; 336 unsigned long last_scan_completed;
342 337 bool fixed_bssid;
343 u32 flags; 338 bool fixed_channel;
344 339
345 u8 bssid[ETH_ALEN]; 340 u8 bssid[ETH_ALEN];
346 341 u8 ssid[IEEE80211_MAX_SSID_LEN];
347 unsigned long request; 342 u8 ssid_len, ie_len;
343 u8 *ie;
344 struct ieee80211_channel *channel;
348 345
349 unsigned long ibss_join_req; 346 unsigned long ibss_join_req;
350 struct sk_buff *probe_resp; /* ProbeResp template for IBSS */ 347 /* probe response/beacon for IBSS */
348 struct sk_buff *presp, *skb;
351 349
352 enum { 350 enum {
353 IEEE80211_IBSS_MLME_SEARCH, 351 IEEE80211_IBSS_MLME_SEARCH,
@@ -626,8 +624,6 @@ struct ieee80211_local {
626 spinlock_t sta_lock; 624 spinlock_t sta_lock;
627 unsigned long num_sta; 625 unsigned long num_sta;
628 struct list_head sta_list; 626 struct list_head sta_list;
629 struct list_head sta_flush_list;
630 struct work_struct sta_flush_work;
631 struct sta_info *sta_hash[STA_HASH_SIZE]; 627 struct sta_info *sta_hash[STA_HASH_SIZE];
632 struct timer_list sta_cleanup; 628 struct timer_list sta_cleanup;
633 629
@@ -647,9 +643,6 @@ struct ieee80211_local {
647 643
648 struct rate_control_ref *rate_ctrl; 644 struct rate_control_ref *rate_ctrl;
649 645
650 int rts_threshold;
651 int fragmentation_threshold;
652
653 struct crypto_blkcipher *wep_tx_tfm; 646 struct crypto_blkcipher *wep_tx_tfm;
654 struct crypto_blkcipher *wep_rx_tfm; 647 struct crypto_blkcipher *wep_rx_tfm;
655 u32 wep_iv; 648 u32 wep_iv;
@@ -671,10 +664,12 @@ struct ieee80211_local {
671 struct cfg80211_scan_request int_scan_req; 664 struct cfg80211_scan_request int_scan_req;
672 struct cfg80211_scan_request *scan_req; 665 struct cfg80211_scan_request *scan_req;
673 struct ieee80211_channel *scan_channel; 666 struct ieee80211_channel *scan_channel;
667 const u8 *orig_ies;
668 int orig_ies_len;
674 int scan_channel_idx; 669 int scan_channel_idx;
670 int scan_ies_len;
675 671
676 enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state; 672 enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
677 unsigned long last_scan_completed;
678 struct delayed_work scan_work; 673 struct delayed_work scan_work;
679 struct ieee80211_sub_if_data *scan_sdata; 674 struct ieee80211_sub_if_data *scan_sdata;
680 enum nl80211_channel_type oper_channel_type; 675 enum nl80211_channel_type oper_channel_type;
@@ -736,15 +731,22 @@ struct ieee80211_local {
736 int wifi_wme_noack_test; 731 int wifi_wme_noack_test;
737 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */ 732 unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
738 733
739 bool powersave;
740 bool pspolling; 734 bool pspolling;
735 /*
736 * PS can only be enabled when we have exactly one managed
737 * interface (and monitors) in PS, this then points there.
738 */
739 struct ieee80211_sub_if_data *ps_sdata;
741 struct work_struct dynamic_ps_enable_work; 740 struct work_struct dynamic_ps_enable_work;
742 struct work_struct dynamic_ps_disable_work; 741 struct work_struct dynamic_ps_disable_work;
743 struct timer_list dynamic_ps_timer; 742 struct timer_list dynamic_ps_timer;
743 struct notifier_block network_latency_notifier;
744 744
745 int user_power_level; /* in dBm */ 745 int user_power_level; /* in dBm */
746 int power_constr_level; /* in dBm */ 746 int power_constr_level; /* in dBm */
747 747
748 struct work_struct restart_work;
749
748#ifdef CONFIG_MAC80211_DEBUGFS 750#ifdef CONFIG_MAC80211_DEBUGFS
749 struct local_debugfsdentries { 751 struct local_debugfsdentries {
750 struct dentry *rcdir; 752 struct dentry *rcdir;
@@ -830,7 +832,7 @@ struct ieee802_11_elems {
830 u8 *fh_params; 832 u8 *fh_params;
831 u8 *ds_params; 833 u8 *ds_params;
832 u8 *cf_params; 834 u8 *cf_params;
833 u8 *tim; 835 struct ieee80211_tim_ie *tim;
834 u8 *ibss_params; 836 u8 *ibss_params;
835 u8 *challenge; 837 u8 *challenge;
836 u8 *wpa; 838 u8 *wpa;
@@ -927,12 +929,11 @@ int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason
927int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason); 929int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason);
928void ieee80211_send_pspoll(struct ieee80211_local *local, 930void ieee80211_send_pspoll(struct ieee80211_local *local,
929 struct ieee80211_sub_if_data *sdata); 931 struct ieee80211_sub_if_data *sdata);
932void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency);
933int ieee80211_max_network_latency(struct notifier_block *nb,
934 unsigned long data, void *dummy);
930 935
931/* IBSS code */ 936/* IBSS code */
932int ieee80211_ibss_commit(struct ieee80211_sub_if_data *sdata);
933int ieee80211_ibss_set_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t len);
934int ieee80211_ibss_get_ssid(struct ieee80211_sub_if_data *sdata, char *ssid, size_t *len);
935int ieee80211_ibss_set_bssid(struct ieee80211_sub_if_data *sdata, u8 *bssid);
936void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local); 937void ieee80211_ibss_notify_scan_completed(struct ieee80211_local *local);
937void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata); 938void ieee80211_ibss_setup_sdata(struct ieee80211_sub_if_data *sdata);
938ieee80211_rx_result 939ieee80211_rx_result
@@ -940,6 +941,9 @@ ieee80211_ibss_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
940 struct ieee80211_rx_status *rx_status); 941 struct ieee80211_rx_status *rx_status);
941struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata, 942struct sta_info *ieee80211_ibss_add_sta(struct ieee80211_sub_if_data *sdata,
942 u8 *bssid, u8 *addr, u32 supp_rates); 943 u8 *bssid, u8 *addr, u32 supp_rates);
944int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
945 struct cfg80211_ibss_params *params);
946int ieee80211_ibss_leave(struct ieee80211_sub_if_data *sdata);
943 947
944/* scan/BSS handling */ 948/* scan/BSS handling */
945void ieee80211_scan_work(struct work_struct *work); 949void ieee80211_scan_work(struct work_struct *work);
@@ -995,9 +999,6 @@ int ieee80211_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
995void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband, 999void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband,
996 struct ieee80211_ht_cap *ht_cap_ie, 1000 struct ieee80211_ht_cap *ht_cap_ie,
997 struct ieee80211_sta_ht_cap *ht_cap); 1001 struct ieee80211_sta_ht_cap *ht_cap);
998u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
999 struct ieee80211_ht_info *hti,
1000 u16 ap_ht_cap_flags);
1001void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn); 1002void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn);
1002void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata, 1003void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
1003 const u8 *da, u16 tid, 1004 const u8 *da, u16 tid,
@@ -1036,15 +1037,22 @@ void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
1036 u16 capab_info, u8 *pwr_constr_elem, 1037 u16 capab_info, u8 *pwr_constr_elem,
1037 u8 pwr_constr_elem_len); 1038 u8 pwr_constr_elem_len);
1038 1039
1039/* Suspend/resume */ 1040/* Suspend/resume and hw reconfiguration */
1041int ieee80211_reconfig(struct ieee80211_local *local);
1042
1040#ifdef CONFIG_PM 1043#ifdef CONFIG_PM
1041int __ieee80211_suspend(struct ieee80211_hw *hw); 1044int __ieee80211_suspend(struct ieee80211_hw *hw);
1042int __ieee80211_resume(struct ieee80211_hw *hw); 1045
1046static inline int __ieee80211_resume(struct ieee80211_hw *hw)
1047{
1048 return ieee80211_reconfig(hw_to_local(hw));
1049}
1043#else 1050#else
1044static inline int __ieee80211_suspend(struct ieee80211_hw *hw) 1051static inline int __ieee80211_suspend(struct ieee80211_hw *hw)
1045{ 1052{
1046 return 0; 1053 return 0;
1047} 1054}
1055
1048static inline int __ieee80211_resume(struct ieee80211_hw *hw) 1056static inline int __ieee80211_resume(struct ieee80211_hw *hw)
1049{ 1057{
1050 return 0; 1058 return 0;
@@ -1060,12 +1068,15 @@ u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
1060int ieee80211_frame_duration(struct ieee80211_local *local, size_t len, 1068int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
1061 int rate, int erp, int short_preamble); 1069 int rate, int erp, int short_preamble);
1062void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx, 1070void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx,
1063 struct ieee80211_hdr *hdr); 1071 struct ieee80211_hdr *hdr, const u8 *tsc);
1064void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata); 1072void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata);
1065void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, 1073void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
1066 int encrypt); 1074 int encrypt);
1067void ieee802_11_parse_elems(u8 *start, size_t len, 1075void ieee802_11_parse_elems(u8 *start, size_t len,
1068 struct ieee802_11_elems *elems); 1076 struct ieee802_11_elems *elems);
1077u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
1078 struct ieee802_11_elems *elems,
1079 u64 filter, u32 crc);
1069int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freq); 1080int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freq);
1070u32 ieee80211_mandatory_rates(struct ieee80211_local *local, 1081u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
1071 enum ieee80211_band band); 1082 enum ieee80211_band band);
@@ -1093,9 +1104,11 @@ void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
1093 u16 transaction, u16 auth_alg, 1104 u16 transaction, u16 auth_alg,
1094 u8 *extra, size_t extra_len, 1105 u8 *extra, size_t extra_len,
1095 const u8 *bssid, int encrypt); 1106 const u8 *bssid, int encrypt);
1107int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
1108 const u8 *ie, size_t ie_len);
1096void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, 1109void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
1097 u8 *ssid, size_t ssid_len, 1110 const u8 *ssid, size_t ssid_len,
1098 u8 *ie, size_t ie_len); 1111 const u8 *ie, size_t ie_len);
1099 1112
1100void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, 1113void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
1101 const size_t supp_rates_len, 1114 const size_t supp_rates_len,
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 91e8e1bacaaa..52425975bbbe 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -235,11 +235,7 @@ static int ieee80211_open(struct net_device *dev)
235 netif_addr_unlock_bh(local->mdev); 235 netif_addr_unlock_bh(local->mdev);
236 break; 236 break;
237 case NL80211_IFTYPE_STATION: 237 case NL80211_IFTYPE_STATION:
238 case NL80211_IFTYPE_ADHOC: 238 sdata->u.mgd.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
239 if (sdata->vif.type == NL80211_IFTYPE_STATION)
240 sdata->u.mgd.flags &= ~IEEE80211_STA_PREV_BSSID_SET;
241 else
242 sdata->u.ibss.flags &= ~IEEE80211_IBSS_PREV_BSSID_SET;
243 /* fall through */ 239 /* fall through */
244 default: 240 default:
245 conf.vif = &sdata->vif; 241 conf.vif = &sdata->vif;
@@ -317,6 +313,8 @@ static int ieee80211_open(struct net_device *dev)
317 ieee80211_set_wmm_default(sdata); 313 ieee80211_set_wmm_default(sdata);
318 } 314 }
319 315
316 ieee80211_recalc_ps(local, -1);
317
320 /* 318 /*
321 * ieee80211_sta_work is disabled while network interface 319 * ieee80211_sta_work is disabled while network interface
322 * is down. Therefore, some configuration changes may not 320 * is down. Therefore, some configuration changes may not
@@ -325,8 +323,6 @@ static int ieee80211_open(struct net_device *dev)
325 */ 323 */
326 if (sdata->vif.type == NL80211_IFTYPE_STATION) 324 if (sdata->vif.type == NL80211_IFTYPE_STATION)
327 queue_work(local->hw.workqueue, &sdata->u.mgd.work); 325 queue_work(local->hw.workqueue, &sdata->u.mgd.work);
328 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
329 queue_work(local->hw.workqueue, &sdata->u.ibss.work);
330 326
331 netif_tx_start_all_queues(dev); 327 netif_tx_start_all_queues(dev);
332 328
@@ -497,7 +493,6 @@ static int ieee80211_stop(struct net_device *dev)
497 /* fall through */ 493 /* fall through */
498 case NL80211_IFTYPE_ADHOC: 494 case NL80211_IFTYPE_ADHOC:
499 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { 495 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
500 memset(sdata->u.ibss.bssid, 0, ETH_ALEN);
501 del_timer_sync(&sdata->u.ibss.timer); 496 del_timer_sync(&sdata->u.ibss.timer);
502 cancel_work_sync(&sdata->u.ibss.work); 497 cancel_work_sync(&sdata->u.ibss.work);
503 synchronize_rcu(); 498 synchronize_rcu();
@@ -572,6 +567,8 @@ static int ieee80211_stop(struct net_device *dev)
572 hw_reconf_flags = 0; 567 hw_reconf_flags = 0;
573 } 568 }
574 569
570 ieee80211_recalc_ps(local, -1);
571
575 /* do after stop to avoid reconfiguring when we stop anyway */ 572 /* do after stop to avoid reconfiguring when we stop anyway */
576 if (hw_reconf_flags) 573 if (hw_reconf_flags)
577 ieee80211_hw_config(local, hw_reconf_flags); 574 ieee80211_hw_config(local, hw_reconf_flags);
@@ -649,7 +646,8 @@ static void ieee80211_teardown_sdata(struct net_device *dev)
649 mesh_rmc_free(sdata); 646 mesh_rmc_free(sdata);
650 break; 647 break;
651 case NL80211_IFTYPE_ADHOC: 648 case NL80211_IFTYPE_ADHOC:
652 kfree_skb(sdata->u.ibss.probe_resp); 649 if (WARN_ON(sdata->u.ibss.presp))
650 kfree_skb(sdata->u.ibss.presp);
653 break; 651 break;
654 case NL80211_IFTYPE_STATION: 652 case NL80211_IFTYPE_STATION:
655 kfree(sdata->u.mgd.extra_ie); 653 kfree(sdata->u.mgd.extra_ie);
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index fbcbed6cad01..5320e08434ac 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -21,6 +21,7 @@
21#include <linux/wireless.h> 21#include <linux/wireless.h>
22#include <linux/rtnetlink.h> 22#include <linux/rtnetlink.h>
23#include <linux/bitmap.h> 23#include <linux/bitmap.h>
24#include <linux/pm_qos_params.h>
24#include <net/net_namespace.h> 25#include <net/net_namespace.h>
25#include <net/cfg80211.h> 26#include <net/cfg80211.h>
26 27
@@ -208,7 +209,7 @@ int ieee80211_if_config(struct ieee80211_sub_if_data *sdata, u32 changed)
208 !!rcu_dereference(sdata->u.ap.beacon); 209 !!rcu_dereference(sdata->u.ap.beacon);
209 break; 210 break;
210 case NL80211_IFTYPE_ADHOC: 211 case NL80211_IFTYPE_ADHOC:
211 conf.enable_beacon = !!sdata->u.ibss.probe_resp; 212 conf.enable_beacon = !!sdata->u.ibss.presp;
212 break; 213 break;
213 case NL80211_IFTYPE_MESH_POINT: 214 case NL80211_IFTYPE_MESH_POINT:
214 conf.enable_beacon = true; 215 conf.enable_beacon = true;
@@ -696,6 +697,28 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
696} 697}
697EXPORT_SYMBOL(ieee80211_tx_status); 698EXPORT_SYMBOL(ieee80211_tx_status);
698 699
700static void ieee80211_restart_work(struct work_struct *work)
701{
702 struct ieee80211_local *local =
703 container_of(work, struct ieee80211_local, restart_work);
704
705 rtnl_lock();
706 ieee80211_reconfig(local);
707 rtnl_unlock();
708}
709
710void ieee80211_restart_hw(struct ieee80211_hw *hw)
711{
712 struct ieee80211_local *local = hw_to_local(hw);
713
714 /* use this reason, __ieee80211_resume will unblock it */
715 ieee80211_stop_queues_by_reason(hw,
716 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
717
718 schedule_work(&local->restart_work);
719}
720EXPORT_SYMBOL(ieee80211_restart_hw);
721
699struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, 722struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
700 const struct ieee80211_ops *ops) 723 const struct ieee80211_ops *ops)
701{ 724{
@@ -728,12 +751,13 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
728 return NULL; 751 return NULL;
729 752
730 wiphy->privid = mac80211_wiphy_privid; 753 wiphy->privid = mac80211_wiphy_privid;
731 wiphy->max_scan_ssids = 4; 754
732 /* Yes, putting cfg80211_bss into ieee80211_bss is a hack */ 755 /* Yes, putting cfg80211_bss into ieee80211_bss is a hack */
733 wiphy->bss_priv_size = sizeof(struct ieee80211_bss) - 756 wiphy->bss_priv_size = sizeof(struct ieee80211_bss) -
734 sizeof(struct cfg80211_bss); 757 sizeof(struct cfg80211_bss);
735 758
736 local = wiphy_priv(wiphy); 759 local = wiphy_priv(wiphy);
760
737 local->hw.wiphy = wiphy; 761 local->hw.wiphy = wiphy;
738 762
739 local->hw.priv = (char *)local + 763 local->hw.priv = (char *)local +
@@ -752,10 +776,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
752 /* set up some defaults */ 776 /* set up some defaults */
753 local->hw.queues = 1; 777 local->hw.queues = 1;
754 local->hw.max_rates = 1; 778 local->hw.max_rates = 1;
755 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD; 779 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
756 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD; 780 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
757 local->hw.conf.long_frame_max_tx_count = 4;
758 local->hw.conf.short_frame_max_tx_count = 7;
759 local->hw.conf.radio_enabled = true; 781 local->hw.conf.radio_enabled = true;
760 782
761 INIT_LIST_HEAD(&local->interfaces); 783 INIT_LIST_HEAD(&local->interfaces);
@@ -767,6 +789,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
767 789
768 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work); 790 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
769 791
792 INIT_WORK(&local->restart_work, ieee80211_restart_work);
793
770 INIT_WORK(&local->dynamic_ps_enable_work, 794 INIT_WORK(&local->dynamic_ps_enable_work,
771 ieee80211_dynamic_ps_enable_work); 795 ieee80211_dynamic_ps_enable_work);
772 INIT_WORK(&local->dynamic_ps_disable_work, 796 INIT_WORK(&local->dynamic_ps_disable_work,
@@ -820,7 +844,17 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
820 enum ieee80211_band band; 844 enum ieee80211_band band;
821 struct net_device *mdev; 845 struct net_device *mdev;
822 struct ieee80211_master_priv *mpriv; 846 struct ieee80211_master_priv *mpriv;
823 int channels, i, j; 847 int channels, i, j, max_bitrates;
848 bool supp_ht;
849 static const u32 cipher_suites[] = {
850 WLAN_CIPHER_SUITE_WEP40,
851 WLAN_CIPHER_SUITE_WEP104,
852 WLAN_CIPHER_SUITE_TKIP,
853 WLAN_CIPHER_SUITE_CCMP,
854
855 /* keep last -- depends on hw flags! */
856 WLAN_CIPHER_SUITE_AES_CMAC
857 };
824 858
825 /* 859 /*
826 * generic code guarantees at least one band, 860 * generic code guarantees at least one band,
@@ -828,18 +862,25 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
828 * that hw.conf.channel is assigned 862 * that hw.conf.channel is assigned
829 */ 863 */
830 channels = 0; 864 channels = 0;
865 max_bitrates = 0;
866 supp_ht = false;
831 for (band = 0; band < IEEE80211_NUM_BANDS; band++) { 867 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
832 struct ieee80211_supported_band *sband; 868 struct ieee80211_supported_band *sband;
833 869
834 sband = local->hw.wiphy->bands[band]; 870 sband = local->hw.wiphy->bands[band];
835 if (sband && !local->oper_channel) { 871 if (!sband)
872 continue;
873 if (!local->oper_channel) {
836 /* init channel we're on */ 874 /* init channel we're on */
837 local->hw.conf.channel = 875 local->hw.conf.channel =
838 local->oper_channel = 876 local->oper_channel =
839 local->scan_channel = &sband->channels[0]; 877 local->scan_channel = &sband->channels[0];
840 } 878 }
841 if (sband) 879 channels += sband->n_channels;
842 channels += sband->n_channels; 880
881 if (max_bitrates < sband->n_bitrates)
882 max_bitrates = sband->n_bitrates;
883 supp_ht = supp_ht || sband->ht_cap.ht_supported;
843 } 884 }
844 885
845 local->int_scan_req.n_channels = channels; 886 local->int_scan_req.n_channels = channels;
@@ -859,6 +900,37 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
859 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) 900 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
860 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC; 901 local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
861 902
903 /*
904 * Calculate scan IE length -- we need this to alloc
905 * memory and to subtract from the driver limit. It
906 * includes the (extended) supported rates and HT
907 * information -- SSID is the driver's responsibility.
908 */
909 local->scan_ies_len = 4 + max_bitrates; /* (ext) supp rates */
910 if (supp_ht)
911 local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
912
913 if (!local->ops->hw_scan) {
914 /* For hw_scan, driver needs to set these up. */
915 local->hw.wiphy->max_scan_ssids = 4;
916 local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
917 }
918
919 /*
920 * If the driver supports any scan IEs, then assume the
921 * limit includes the IEs mac80211 will add, otherwise
922 * leave it at zero and let the driver sort it out; we
923 * still pass our IEs to the driver but userspace will
924 * not be allowed to in that case.
925 */
926 if (local->hw.wiphy->max_scan_ie_len)
927 local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
928
929 local->hw.wiphy->cipher_suites = cipher_suites;
930 local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
931 if (!(local->hw.flags & IEEE80211_HW_MFP_CAPABLE))
932 local->hw.wiphy->n_cipher_suites--;
933
862 result = wiphy_register(local->hw.wiphy); 934 result = wiphy_register(local->hw.wiphy);
863 if (result < 0) 935 if (result < 0)
864 goto fail_wiphy_register; 936 goto fail_wiphy_register;
@@ -965,25 +1037,38 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
965 } 1037 }
966 } 1038 }
967 1039
1040 local->network_latency_notifier.notifier_call =
1041 ieee80211_max_network_latency;
1042 result = pm_qos_add_notifier(PM_QOS_NETWORK_LATENCY,
1043 &local->network_latency_notifier);
1044
1045 if (result) {
1046 rtnl_lock();
1047 goto fail_pm_qos;
1048 }
1049
968 return 0; 1050 return 0;
969 1051
970fail_wep: 1052 fail_pm_qos:
1053 ieee80211_led_exit(local);
1054 ieee80211_remove_interfaces(local);
1055 fail_wep:
971 rate_control_deinitialize(local); 1056 rate_control_deinitialize(local);
972fail_rate: 1057 fail_rate:
973 unregister_netdevice(local->mdev); 1058 unregister_netdevice(local->mdev);
974 local->mdev = NULL; 1059 local->mdev = NULL;
975fail_dev: 1060 fail_dev:
976 rtnl_unlock(); 1061 rtnl_unlock();
977 sta_info_stop(local); 1062 sta_info_stop(local);
978fail_sta_info: 1063 fail_sta_info:
979 debugfs_hw_del(local); 1064 debugfs_hw_del(local);
980 destroy_workqueue(local->hw.workqueue); 1065 destroy_workqueue(local->hw.workqueue);
981fail_workqueue: 1066 fail_workqueue:
982 if (local->mdev) 1067 if (local->mdev)
983 free_netdev(local->mdev); 1068 free_netdev(local->mdev);
984fail_mdev_alloc: 1069 fail_mdev_alloc:
985 wiphy_unregister(local->hw.wiphy); 1070 wiphy_unregister(local->hw.wiphy);
986fail_wiphy_register: 1071 fail_wiphy_register:
987 kfree(local->int_scan_req.channels); 1072 kfree(local->int_scan_req.channels);
988 return result; 1073 return result;
989} 1074}
@@ -996,6 +1081,9 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
996 tasklet_kill(&local->tx_pending_tasklet); 1081 tasklet_kill(&local->tx_pending_tasklet);
997 tasklet_kill(&local->tasklet); 1082 tasklet_kill(&local->tasklet);
998 1083
1084 pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
1085 &local->network_latency_notifier);
1086
999 rtnl_lock(); 1087 rtnl_lock();
1000 1088
1001 /* 1089 /*
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 132938b073dc..3610c11286bc 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -17,6 +17,8 @@
17#include <linux/if_arp.h> 17#include <linux/if_arp.h>
18#include <linux/etherdevice.h> 18#include <linux/etherdevice.h>
19#include <linux/rtnetlink.h> 19#include <linux/rtnetlink.h>
20#include <linux/pm_qos_params.h>
21#include <linux/crc32.h>
20#include <net/mac80211.h> 22#include <net/mac80211.h>
21#include <asm/unaligned.h> 23#include <asm/unaligned.h>
22 24
@@ -80,6 +82,89 @@ static int ieee80211_compatible_rates(struct ieee80211_bss *bss,
80 return count; 82 return count;
81} 83}
82 84
85/*
86 * ieee80211_enable_ht should be called only after the operating band
87 * has been determined as ht configuration depends on the hw's
88 * HT abilities for a specific band.
89 */
90static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
91 struct ieee80211_ht_info *hti,
92 u16 ap_ht_cap_flags)
93{
94 struct ieee80211_local *local = sdata->local;
95 struct ieee80211_supported_band *sband;
96 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
97 struct ieee80211_bss_ht_conf ht;
98 struct sta_info *sta;
99 u32 changed = 0;
100 bool enable_ht = true, ht_changed;
101 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
102
103 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
104
105 memset(&ht, 0, sizeof(ht));
106
107 /* HT is not supported */
108 if (!sband->ht_cap.ht_supported)
109 enable_ht = false;
110
111 /* check that channel matches the right operating channel */
112 if (local->hw.conf.channel->center_freq !=
113 ieee80211_channel_to_frequency(hti->control_chan))
114 enable_ht = false;
115
116 if (enable_ht) {
117 channel_type = NL80211_CHAN_HT20;
118
119 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
120 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
121 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
122 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
123 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
124 channel_type = NL80211_CHAN_HT40PLUS;
125 break;
126 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
127 channel_type = NL80211_CHAN_HT40MINUS;
128 break;
129 }
130 }
131 }
132
133 ht_changed = conf_is_ht(&local->hw.conf) != enable_ht ||
134 channel_type != local->hw.conf.channel_type;
135
136 local->oper_channel_type = channel_type;
137
138 if (ht_changed) {
139 /* channel_type change automatically detected */
140 ieee80211_hw_config(local, 0);
141
142 rcu_read_lock();
143
144 sta = sta_info_get(local, ifmgd->bssid);
145 if (sta)
146 rate_control_rate_update(local, sband, sta,
147 IEEE80211_RC_HT_CHANGED);
148
149 rcu_read_unlock();
150
151 }
152
153 /* disable HT */
154 if (!enable_ht)
155 return 0;
156
157 ht.operation_mode = le16_to_cpu(hti->operation_mode);
158
159 /* if bss configuration changed store the new one */
160 if (memcmp(&sdata->vif.bss_conf.ht, &ht, sizeof(ht))) {
161 changed |= BSS_CHANGED_HT;
162 sdata->vif.bss_conf.ht = ht;
163 }
164
165 return changed;
166}
167
83/* frame sending functions */ 168/* frame sending functions */
84 169
85static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) 170static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
@@ -325,6 +410,10 @@ static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
325 /* u.deauth.reason_code == u.disassoc.reason_code */ 410 /* u.deauth.reason_code == u.disassoc.reason_code */
326 mgmt->u.deauth.reason_code = cpu_to_le16(reason); 411 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
327 412
413 if (stype == IEEE80211_STYPE_DEAUTH)
414 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, skb->len);
415 else
416 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, skb->len);
328 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED); 417 ieee80211_tx_skb(sdata, skb, ifmgd->flags & IEEE80211_STA_MFP_ENABLED);
329} 418}
330 419
@@ -359,6 +448,166 @@ void ieee80211_send_pspoll(struct ieee80211_local *local,
359 ieee80211_tx_skb(sdata, skb, 0); 448 ieee80211_tx_skb(sdata, skb, 0);
360} 449}
361 450
451void ieee80211_send_nullfunc(struct ieee80211_local *local,
452 struct ieee80211_sub_if_data *sdata,
453 int powersave)
454{
455 struct sk_buff *skb;
456 struct ieee80211_hdr *nullfunc;
457 __le16 fc;
458
459 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
460 return;
461
462 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
463 if (!skb) {
464 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
465 "frame\n", sdata->dev->name);
466 return;
467 }
468 skb_reserve(skb, local->hw.extra_tx_headroom);
469
470 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
471 memset(nullfunc, 0, 24);
472 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
473 IEEE80211_FCTL_TODS);
474 if (powersave)
475 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
476 nullfunc->frame_control = fc;
477 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
478 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
479 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
480
481 ieee80211_tx_skb(sdata, skb, 0);
482}
483
484/* powersave */
485static void ieee80211_enable_ps(struct ieee80211_local *local,
486 struct ieee80211_sub_if_data *sdata)
487{
488 struct ieee80211_conf *conf = &local->hw.conf;
489
490 if (conf->dynamic_ps_timeout > 0 &&
491 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
492 mod_timer(&local->dynamic_ps_timer, jiffies +
493 msecs_to_jiffies(conf->dynamic_ps_timeout));
494 } else {
495 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
496 ieee80211_send_nullfunc(local, sdata, 1);
497 conf->flags |= IEEE80211_CONF_PS;
498 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
499 }
500}
501
502static void ieee80211_change_ps(struct ieee80211_local *local)
503{
504 struct ieee80211_conf *conf = &local->hw.conf;
505
506 if (local->ps_sdata) {
507 if (!(local->ps_sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED))
508 return;
509
510 ieee80211_enable_ps(local, local->ps_sdata);
511 } else if (conf->flags & IEEE80211_CONF_PS) {
512 conf->flags &= ~IEEE80211_CONF_PS;
513 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
514 del_timer_sync(&local->dynamic_ps_timer);
515 cancel_work_sync(&local->dynamic_ps_enable_work);
516 }
517}
518
519/* need to hold RTNL or interface lock */
520void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
521{
522 struct ieee80211_sub_if_data *sdata, *found = NULL;
523 int count = 0;
524
525 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
526 local->ps_sdata = NULL;
527 return;
528 }
529
530 list_for_each_entry(sdata, &local->interfaces, list) {
531 if (!netif_running(sdata->dev))
532 continue;
533 if (sdata->vif.type != NL80211_IFTYPE_STATION)
534 continue;
535 found = sdata;
536 count++;
537 }
538
539 if (count == 1 && found->u.mgd.powersave) {
540 s32 beaconint_us;
541
542 if (latency < 0)
543 latency = pm_qos_requirement(PM_QOS_NETWORK_LATENCY);
544
545 beaconint_us = ieee80211_tu_to_usec(
546 found->vif.bss_conf.beacon_int);
547
548 if (beaconint_us > latency) {
549 local->ps_sdata = NULL;
550 } else {
551 u8 dtimper = found->vif.bss_conf.dtim_period;
552 int maxslp = 1;
553
554 if (dtimper > 1)
555 maxslp = min_t(int, dtimper,
556 latency / beaconint_us);
557
558 local->hw.conf.max_sleep_interval = maxslp;
559 local->ps_sdata = found;
560 }
561 } else {
562 local->ps_sdata = NULL;
563 }
564
565 ieee80211_change_ps(local);
566}
567
568void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
569{
570 struct ieee80211_local *local =
571 container_of(work, struct ieee80211_local,
572 dynamic_ps_disable_work);
573
574 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
575 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
576 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
577 }
578
579 ieee80211_wake_queues_by_reason(&local->hw,
580 IEEE80211_QUEUE_STOP_REASON_PS);
581}
582
583void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
584{
585 struct ieee80211_local *local =
586 container_of(work, struct ieee80211_local,
587 dynamic_ps_enable_work);
588 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
589
590 /* can only happen when PS was just disabled anyway */
591 if (!sdata)
592 return;
593
594 if (local->hw.conf.flags & IEEE80211_CONF_PS)
595 return;
596
597 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
598 ieee80211_send_nullfunc(local, sdata, 1);
599
600 local->hw.conf.flags |= IEEE80211_CONF_PS;
601 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
602}
603
604void ieee80211_dynamic_ps_timer(unsigned long data)
605{
606 struct ieee80211_local *local = (void *) data;
607
608 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
609}
610
362/* MLME */ 611/* MLME */
363static void ieee80211_sta_wmm_params(struct ieee80211_local *local, 612static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
364 struct ieee80211_if_managed *ifmgd, 613 struct ieee80211_if_managed *ifmgd,
@@ -435,30 +684,6 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
435 } 684 }
436} 685}
437 686
438static bool ieee80211_check_tim(struct ieee802_11_elems *elems, u16 aid)
439{
440 u8 mask;
441 u8 index, indexn1, indexn2;
442 struct ieee80211_tim_ie *tim = (struct ieee80211_tim_ie *) elems->tim;
443
444 if (unlikely(!tim || elems->tim_len < 4))
445 return false;
446
447 aid &= 0x3fff;
448 index = aid / 8;
449 mask = 1 << (aid & 7);
450
451 indexn1 = tim->bitmap_ctrl & 0xfe;
452 indexn2 = elems->tim_len + indexn1 - 4;
453
454 if (index < indexn1 || index > indexn2)
455 return false;
456
457 index -= indexn1;
458
459 return !!(tim->virtual_map[index] & mask);
460}
461
462static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, 687static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
463 u16 capab, bool erp_valid, u8 erp) 688 u16 capab, bool erp_valid, u8 erp)
464{ 689{
@@ -634,18 +859,11 @@ static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
634 bss_info_changed |= BSS_CHANGED_BASIC_RATES; 859 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
635 ieee80211_bss_info_change_notify(sdata, bss_info_changed); 860 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
636 861
637 if (local->powersave) { 862 /* will be same as sdata */
638 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) && 863 if (local->ps_sdata) {
639 local->hw.conf.dynamic_ps_timeout > 0) { 864 mutex_lock(&local->iflist_mtx);
640 mod_timer(&local->dynamic_ps_timer, jiffies + 865 ieee80211_recalc_ps(local, -1);
641 msecs_to_jiffies( 866 mutex_unlock(&local->iflist_mtx);
642 local->hw.conf.dynamic_ps_timeout));
643 } else {
644 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
645 ieee80211_send_nullfunc(local, sdata, 1);
646 conf->flags |= IEEE80211_CONF_PS;
647 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
648 }
649 } 867 }
650 868
651 netif_tx_start_all_queues(sdata->dev); 869 netif_tx_start_all_queues(sdata->dev);
@@ -714,7 +932,7 @@ static void ieee80211_authenticate(struct ieee80211_sub_if_data *sdata)
714 " timed out\n", 932 " timed out\n",
715 sdata->dev->name, ifmgd->bssid); 933 sdata->dev->name, ifmgd->bssid);
716 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 934 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
717 ieee80211_sta_send_apinfo(sdata); 935 cfg80211_send_auth_timeout(sdata->dev, ifmgd->bssid);
718 ieee80211_rx_bss_remove(sdata, ifmgd->bssid, 936 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
719 sdata->local->hw.conf.channel->center_freq, 937 sdata->local->hw.conf.channel->center_freq,
720 ifmgd->ssid, ifmgd->ssid_len); 938 ifmgd->ssid, ifmgd->ssid_len);
@@ -897,7 +1115,7 @@ static void ieee80211_associate(struct ieee80211_sub_if_data *sdata)
897 " timed out\n", 1115 " timed out\n",
898 sdata->dev->name, ifmgd->bssid); 1116 sdata->dev->name, ifmgd->bssid);
899 ifmgd->state = IEEE80211_STA_MLME_DISABLED; 1117 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
900 ieee80211_sta_send_apinfo(sdata); 1118 cfg80211_send_assoc_timeout(sdata->dev, ifmgd->bssid);
901 ieee80211_rx_bss_remove(sdata, ifmgd->bssid, 1119 ieee80211_rx_bss_remove(sdata, ifmgd->bssid,
902 sdata->local->hw.conf.channel->center_freq, 1120 sdata->local->hw.conf.channel->center_freq,
903 ifmgd->ssid, ifmgd->ssid_len); 1121 ifmgd->ssid, ifmgd->ssid_len);
@@ -1187,7 +1405,7 @@ static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1187 1405
1188 ieee80211_set_disassoc(sdata, true, false, 0); 1406 ieee80211_set_disassoc(sdata, true, false, 0);
1189 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED; 1407 ifmgd->flags &= ~IEEE80211_STA_AUTHENTICATED;
1190 cfg80211_send_rx_deauth(sdata->dev, (u8 *) mgmt, len); 1408 cfg80211_send_deauth(sdata->dev, (u8 *) mgmt, len);
1191} 1409}
1192 1410
1193 1411
@@ -1218,7 +1436,7 @@ static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1218 } 1436 }
1219 1437
1220 ieee80211_set_disassoc(sdata, false, false, reason_code); 1438 ieee80211_set_disassoc(sdata, false, false, reason_code);
1221 cfg80211_send_rx_disassoc(sdata->dev, (u8 *) mgmt, len); 1439 cfg80211_send_disassoc(sdata->dev, (u8 *) mgmt, len);
1222} 1440}
1223 1441
1224 1442
@@ -1287,6 +1505,11 @@ static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
1287 * association next time. This works around some broken APs 1505 * association next time. This works around some broken APs
1288 * which do not correctly reject reassociation requests. */ 1506 * which do not correctly reject reassociation requests. */
1289 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET; 1507 ifmgd->flags &= ~IEEE80211_STA_PREV_BSSID_SET;
1508 cfg80211_send_rx_assoc(sdata->dev, (u8 *) mgmt, len);
1509 if (ifmgd->flags & IEEE80211_STA_EXT_SME) {
1510 /* Wait for SME to decide what to do next */
1511 ifmgd->state = IEEE80211_STA_MLME_DISABLED;
1512 }
1290 return; 1513 return;
1291 } 1514 }
1292 1515
@@ -1518,46 +1741,74 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
1518 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL; 1741 ifmgd->flags &= ~IEEE80211_STA_PROBEREQ_POLL;
1519} 1742}
1520 1743
1744/*
1745 * This is the canonical list of information elements we care about,
1746 * the filter code also gives us all changes to the Microsoft OUI
1747 * (00:50:F2) vendor IE which is used for WMM which we need to track.
1748 *
1749 * We implement beacon filtering in software since that means we can
1750 * avoid processing the frame here and in cfg80211, and userspace
1751 * will not be able to tell whether the hardware supports it or not.
1752 *
1753 * XXX: This list needs to be dynamic -- userspace needs to be able to
1754 * add items it requires. It also needs to be able to tell us to
1755 * look out for other vendor IEs.
1756 */
1757static const u64 care_about_ies =
1758 (1ULL << WLAN_EID_COUNTRY) |
1759 (1ULL << WLAN_EID_ERP_INFO) |
1760 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
1761 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
1762 (1ULL << WLAN_EID_HT_CAPABILITY) |
1763 (1ULL << WLAN_EID_HT_INFORMATION);
1764
1521static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, 1765static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
1522 struct ieee80211_mgmt *mgmt, 1766 struct ieee80211_mgmt *mgmt,
1523 size_t len, 1767 size_t len,
1524 struct ieee80211_rx_status *rx_status) 1768 struct ieee80211_rx_status *rx_status)
1525{ 1769{
1526 struct ieee80211_if_managed *ifmgd; 1770 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
1527 size_t baselen; 1771 size_t baselen;
1528 struct ieee802_11_elems elems; 1772 struct ieee802_11_elems elems;
1529 struct ieee80211_local *local = sdata->local; 1773 struct ieee80211_local *local = sdata->local;
1530 u32 changed = 0; 1774 u32 changed = 0;
1531 bool erp_valid, directed_tim; 1775 bool erp_valid, directed_tim = false;
1532 u8 erp_value = 0; 1776 u8 erp_value = 0;
1777 u32 ncrc;
1533 1778
1534 /* Process beacon from the current BSS */ 1779 /* Process beacon from the current BSS */
1535 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; 1780 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
1536 if (baselen > len) 1781 if (baselen > len)
1537 return; 1782 return;
1538 1783
1539 ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen, &elems); 1784 if (rx_status->freq != local->hw.conf.channel->center_freq)
1540
1541 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
1542
1543 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1544 return; 1785 return;
1545 1786
1546 ifmgd = &sdata->u.mgd;
1547
1548 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) || 1787 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED) ||
1549 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0) 1788 memcmp(ifmgd->bssid, mgmt->bssid, ETH_ALEN) != 0)
1550 return; 1789 return;
1551 1790
1552 if (rx_status->freq != local->hw.conf.channel->center_freq) 1791 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
1792 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
1793 len - baselen, &elems,
1794 care_about_ies, ncrc);
1795
1796 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
1797 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
1798 ifmgd->aid);
1799
1800 ncrc = crc32_be(ncrc, (void *)&directed_tim, sizeof(directed_tim));
1801
1802 if (ncrc == ifmgd->beacon_crc)
1553 return; 1803 return;
1804 ifmgd->beacon_crc = ncrc;
1805
1806 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, true);
1554 1807
1555 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param, 1808 ieee80211_sta_wmm_params(local, ifmgd, elems.wmm_param,
1556 elems.wmm_param_len); 1809 elems.wmm_param_len);
1557 1810
1558 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) { 1811 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
1559 directed_tim = ieee80211_check_tim(&elems, ifmgd->aid);
1560
1561 if (directed_tim) { 1812 if (directed_tim) {
1562 if (local->hw.conf.dynamic_ps_timeout > 0) { 1813 if (local->hw.conf.dynamic_ps_timeout > 0) {
1563 local->hw.conf.flags &= ~IEEE80211_CONF_PS; 1814 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
@@ -1930,6 +2181,7 @@ static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
1930void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) 2181void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
1931{ 2182{
1932 struct ieee80211_if_managed *ifmgd; 2183 struct ieee80211_if_managed *ifmgd;
2184 u32 hw_flags;
1933 2185
1934 ifmgd = &sdata->u.mgd; 2186 ifmgd = &sdata->u.mgd;
1935 INIT_WORK(&ifmgd->work, ieee80211_sta_work); 2187 INIT_WORK(&ifmgd->work, ieee80211_sta_work);
@@ -1949,6 +2201,13 @@ void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
1949 IEEE80211_STA_AUTO_CHANNEL_SEL; 2201 IEEE80211_STA_AUTO_CHANNEL_SEL;
1950 if (sdata->local->hw.queues >= 4) 2202 if (sdata->local->hw.queues >= 4)
1951 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED; 2203 ifmgd->flags |= IEEE80211_STA_WMM_ENABLED;
2204
2205 hw_flags = sdata->local->hw.flags;
2206
2207 if (hw_flags & IEEE80211_HW_SUPPORTS_PS) {
2208 ifmgd->powersave = CONFIG_MAC80211_DEFAULT_PS_VALUE;
2209 sdata->local->hw.conf.dynamic_ps_timeout = 500;
2210 }
1952} 2211}
1953 2212
1954/* configuration hooks */ 2213/* configuration hooks */
@@ -2068,9 +2327,6 @@ int ieee80211_sta_deauthenticate(struct ieee80211_sub_if_data *sdata, u16 reason
2068 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n", 2327 printk(KERN_DEBUG "%s: deauthenticating by local choice (reason=%d)\n",
2069 sdata->dev->name, reason); 2328 sdata->dev->name, reason);
2070 2329
2071 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2072 return -EINVAL;
2073
2074 ieee80211_set_disassoc(sdata, true, true, reason); 2330 ieee80211_set_disassoc(sdata, true, true, reason);
2075 return 0; 2331 return 0;
2076} 2332}
@@ -2082,9 +2338,6 @@ int ieee80211_sta_disassociate(struct ieee80211_sub_if_data *sdata, u16 reason)
2082 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n", 2338 printk(KERN_DEBUG "%s: disassociating by local choice (reason=%d)\n",
2083 sdata->dev->name, reason); 2339 sdata->dev->name, reason);
2084 2340
2085 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2086 return -EINVAL;
2087
2088 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED)) 2341 if (!(ifmgd->flags & IEEE80211_STA_ASSOCIATED))
2089 return -ENOLINK; 2342 return -ENOLINK;
2090 2343
@@ -2104,75 +2357,17 @@ void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
2104 rcu_read_unlock(); 2357 rcu_read_unlock();
2105} 2358}
2106 2359
2107void ieee80211_dynamic_ps_disable_work(struct work_struct *work) 2360int ieee80211_max_network_latency(struct notifier_block *nb,
2361 unsigned long data, void *dummy)
2108{ 2362{
2363 s32 latency_usec = (s32) data;
2109 struct ieee80211_local *local = 2364 struct ieee80211_local *local =
2110 container_of(work, struct ieee80211_local, 2365 container_of(nb, struct ieee80211_local,
2111 dynamic_ps_disable_work); 2366 network_latency_notifier);
2112 2367
2113 if (local->hw.conf.flags & IEEE80211_CONF_PS) { 2368 mutex_lock(&local->iflist_mtx);
2114 local->hw.conf.flags &= ~IEEE80211_CONF_PS; 2369 ieee80211_recalc_ps(local, latency_usec);
2115 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); 2370 mutex_unlock(&local->iflist_mtx);
2116 }
2117
2118 ieee80211_wake_queues_by_reason(&local->hw,
2119 IEEE80211_QUEUE_STOP_REASON_PS);
2120}
2121
2122void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
2123{
2124 struct ieee80211_local *local =
2125 container_of(work, struct ieee80211_local,
2126 dynamic_ps_enable_work);
2127 /* XXX: using scan_sdata is completely broken! */
2128 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
2129
2130 if (local->hw.conf.flags & IEEE80211_CONF_PS)
2131 return;
2132
2133 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK && sdata)
2134 ieee80211_send_nullfunc(local, sdata, 1);
2135
2136 local->hw.conf.flags |= IEEE80211_CONF_PS;
2137 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2138}
2139 2371
2140void ieee80211_dynamic_ps_timer(unsigned long data) 2372 return 0;
2141{
2142 struct ieee80211_local *local = (void *) data;
2143
2144 queue_work(local->hw.workqueue, &local->dynamic_ps_enable_work);
2145}
2146
2147void ieee80211_send_nullfunc(struct ieee80211_local *local,
2148 struct ieee80211_sub_if_data *sdata,
2149 int powersave)
2150{
2151 struct sk_buff *skb;
2152 struct ieee80211_hdr *nullfunc;
2153 __le16 fc;
2154
2155 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
2156 return;
2157
2158 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24);
2159 if (!skb) {
2160 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
2161 "frame\n", sdata->dev->name);
2162 return;
2163 }
2164 skb_reserve(skb, local->hw.extra_tx_headroom);
2165
2166 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24);
2167 memset(nullfunc, 0, 24);
2168 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
2169 IEEE80211_FCTL_TODS);
2170 if (powersave)
2171 fc |= cpu_to_le16(IEEE80211_FCTL_PM);
2172 nullfunc->frame_control = fc;
2173 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
2174 memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN);
2175 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
2176
2177 ieee80211_tx_skb(sdata, skb, 0);
2178} 2373}
diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
index 81985d27cbda..b38986c9deef 100644
--- a/net/mac80211/pm.c
+++ b/net/mac80211/pm.c
@@ -72,119 +72,8 @@ int __ieee80211_suspend(struct ieee80211_hw *hw)
72 return 0; 72 return 0;
73} 73}
74 74
75int __ieee80211_resume(struct ieee80211_hw *hw) 75/*
76{ 76 * __ieee80211_resume() is a static inline which just calls
77 struct ieee80211_local *local = hw_to_local(hw); 77 * ieee80211_reconfig(), which is also needed for hardware
78 struct ieee80211_sub_if_data *sdata; 78 * hang/firmware failure/etc. recovery.
79 struct ieee80211_if_init_conf conf; 79 */
80 struct sta_info *sta;
81 unsigned long flags;
82 int res;
83
84 /* restart hardware */
85 if (local->open_count) {
86 res = local->ops->start(hw);
87
88 ieee80211_led_radio(local, hw->conf.radio_enabled);
89 }
90
91 /* add interfaces */
92 list_for_each_entry(sdata, &local->interfaces, list) {
93 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
94 sdata->vif.type != NL80211_IFTYPE_MONITOR &&
95 netif_running(sdata->dev)) {
96 conf.vif = &sdata->vif;
97 conf.type = sdata->vif.type;
98 conf.mac_addr = sdata->dev->dev_addr;
99 res = local->ops->add_interface(hw, &conf);
100 }
101 }
102
103 /* add STAs back */
104 if (local->ops->sta_notify) {
105 spin_lock_irqsave(&local->sta_lock, flags);
106 list_for_each_entry(sta, &local->sta_list, list) {
107 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
108 sdata = container_of(sdata->bss,
109 struct ieee80211_sub_if_data,
110 u.ap);
111
112 local->ops->sta_notify(hw, &sdata->vif,
113 STA_NOTIFY_ADD, &sta->sta);
114 }
115 spin_unlock_irqrestore(&local->sta_lock, flags);
116 }
117
118 /* Clear Suspend state so that ADDBA requests can be processed */
119
120 rcu_read_lock();
121
122 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
123 list_for_each_entry_rcu(sta, &local->sta_list, list) {
124 clear_sta_flags(sta, WLAN_STA_SUSPEND);
125 }
126 }
127
128 rcu_read_unlock();
129
130 /* add back keys */
131 list_for_each_entry(sdata, &local->interfaces, list)
132 if (netif_running(sdata->dev))
133 ieee80211_enable_keys(sdata);
134
135 /* setup RTS threshold */
136 if (local->ops->set_rts_threshold)
137 local->ops->set_rts_threshold(hw, local->rts_threshold);
138
139 /* reconfigure hardware */
140 ieee80211_hw_config(local, ~0);
141
142 netif_addr_lock_bh(local->mdev);
143 ieee80211_configure_filter(local);
144 netif_addr_unlock_bh(local->mdev);
145
146 /* Finally also reconfigure all the BSS information */
147 list_for_each_entry(sdata, &local->interfaces, list) {
148 u32 changed = ~0;
149 if (!netif_running(sdata->dev))
150 continue;
151 switch (sdata->vif.type) {
152 case NL80211_IFTYPE_STATION:
153 /* disable beacon change bits */
154 changed &= ~IEEE80211_IFCC_BEACON;
155 /* fall through */
156 case NL80211_IFTYPE_ADHOC:
157 case NL80211_IFTYPE_AP:
158 case NL80211_IFTYPE_MESH_POINT:
159 /*
160 * Driver's config_interface can fail if rfkill is
161 * enabled. Accommodate this return code.
162 * FIXME: When mac80211 has knowledge of rfkill
163 * state the code below can change back to:
164 * WARN(ieee80211_if_config(sdata, changed));
165 * ieee80211_bss_info_change_notify(sdata, ~0);
166 */
167 if (ieee80211_if_config(sdata, changed))
168 printk(KERN_DEBUG "%s: failed to configure interface during resume\n",
169 sdata->dev->name);
170 else
171 ieee80211_bss_info_change_notify(sdata, ~0);
172 break;
173 case NL80211_IFTYPE_WDS:
174 break;
175 case NL80211_IFTYPE_AP_VLAN:
176 case NL80211_IFTYPE_MONITOR:
177 /* ignore virtual */
178 break;
179 case NL80211_IFTYPE_UNSPECIFIED:
180 case __NL80211_IFTYPE_AFTER_LAST:
181 WARN_ON(1);
182 break;
183 }
184 }
185
186 ieee80211_wake_queues_by_reason(hw,
187 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
188
189 return 0;
190}
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 9776f73c51ad..a5afb79dab6e 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -1932,7 +1932,7 @@ static void ieee80211_rx_michael_mic_report(struct net_device *dev,
1932 !ieee80211_is_auth(hdr->frame_control)) 1932 !ieee80211_is_auth(hdr->frame_control))
1933 goto ignore; 1933 goto ignore;
1934 1934
1935 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr); 1935 mac80211_ev_michael_mic_failure(rx->sdata, keyidx, hdr, NULL);
1936 ignore: 1936 ignore:
1937 dev_kfree_skb(rx->skb); 1937 dev_kfree_skb(rx->skb);
1938 rx->skb = NULL; 1938 rx->skb = NULL;
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 3bf9839f5916..f25b07feabf9 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -253,7 +253,7 @@ static void ieee80211_scan_ps_disable(struct ieee80211_sub_if_data *sdata)
253{ 253{
254 struct ieee80211_local *local = sdata->local; 254 struct ieee80211_local *local = sdata->local;
255 255
256 if (!local->powersave) 256 if (!local->ps_sdata)
257 ieee80211_send_nullfunc(local, sdata, 0); 257 ieee80211_send_nullfunc(local, sdata, 0);
258 else { 258 else {
259 /* 259 /*
@@ -285,12 +285,16 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
285 if (WARN_ON(!local->scan_req)) 285 if (WARN_ON(!local->scan_req))
286 return; 286 return;
287 287
288 if (local->hw_scanning) {
289 kfree(local->scan_req->ie);
290 local->scan_req->ie = local->orig_ies;
291 local->scan_req->ie_len = local->orig_ies_len;
292 }
293
288 if (local->scan_req != &local->int_scan_req) 294 if (local->scan_req != &local->int_scan_req)
289 cfg80211_scan_done(local->scan_req, aborted); 295 cfg80211_scan_done(local->scan_req, aborted);
290 local->scan_req = NULL; 296 local->scan_req = NULL;
291 297
292 local->last_scan_completed = jiffies;
293
294 if (local->hw_scanning) { 298 if (local->hw_scanning) {
295 local->hw_scanning = false; 299 local->hw_scanning = false;
296 /* 300 /*
@@ -457,12 +461,28 @@ int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata,
457 } 461 }
458 462
459 if (local->ops->hw_scan) { 463 if (local->ops->hw_scan) {
460 int rc; 464 u8 *ies;
465 int rc, ielen;
466
467 ies = kmalloc(2 + IEEE80211_MAX_SSID_LEN +
468 local->scan_ies_len + req->ie_len, GFP_KERNEL);
469 if (!ies)
470 return -ENOMEM;
471
472 ielen = ieee80211_build_preq_ies(local, ies,
473 req->ie, req->ie_len);
474 local->orig_ies = req->ie;
475 local->orig_ies_len = req->ie_len;
476 req->ie = ies;
477 req->ie_len = ielen;
461 478
462 local->hw_scanning = true; 479 local->hw_scanning = true;
463 rc = local->ops->hw_scan(local_to_hw(local), req); 480 rc = local->ops->hw_scan(local_to_hw(local), req);
464 if (rc) { 481 if (rc) {
465 local->hw_scanning = false; 482 local->hw_scanning = false;
483 kfree(ies);
484 req->ie_len = local->orig_ies_len;
485 req->ie = local->orig_ies;
466 return rc; 486 return rc;
467 } 487 }
468 local->scan_sdata = scan_sdata; 488 local->scan_sdata = scan_sdata;
diff --git a/net/mac80211/spectmgmt.c b/net/mac80211/spectmgmt.c
index 5f7a2624ed74..48bf78e7fa7a 100644
--- a/net/mac80211/spectmgmt.c
+++ b/net/mac80211/spectmgmt.c
@@ -15,7 +15,7 @@
15 */ 15 */
16 16
17#include <linux/ieee80211.h> 17#include <linux/ieee80211.h>
18#include <net/wireless.h> 18#include <net/cfg80211.h>
19#include <net/mac80211.h> 19#include <net/mac80211.h>
20#include "ieee80211_i.h" 20#include "ieee80211_i.h"
21#include "sta_info.h" 21#include "sta_info.h"
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index c5f14e6bbde2..654a8e963ccb 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -686,41 +686,10 @@ static void sta_info_debugfs_add_work(struct work_struct *work)
686} 686}
687#endif 687#endif
688 688
689static void __ieee80211_run_pending_flush(struct ieee80211_local *local)
690{
691 struct sta_info *sta;
692 unsigned long flags;
693
694 ASSERT_RTNL();
695
696 spin_lock_irqsave(&local->sta_lock, flags);
697 while (!list_empty(&local->sta_flush_list)) {
698 sta = list_first_entry(&local->sta_flush_list,
699 struct sta_info, list);
700 list_del(&sta->list);
701 spin_unlock_irqrestore(&local->sta_lock, flags);
702 sta_info_destroy(sta);
703 spin_lock_irqsave(&local->sta_lock, flags);
704 }
705 spin_unlock_irqrestore(&local->sta_lock, flags);
706}
707
708static void ieee80211_sta_flush_work(struct work_struct *work)
709{
710 struct ieee80211_local *local =
711 container_of(work, struct ieee80211_local, sta_flush_work);
712
713 rtnl_lock();
714 __ieee80211_run_pending_flush(local);
715 rtnl_unlock();
716}
717
718void sta_info_init(struct ieee80211_local *local) 689void sta_info_init(struct ieee80211_local *local)
719{ 690{
720 spin_lock_init(&local->sta_lock); 691 spin_lock_init(&local->sta_lock);
721 INIT_LIST_HEAD(&local->sta_list); 692 INIT_LIST_HEAD(&local->sta_list);
722 INIT_LIST_HEAD(&local->sta_flush_list);
723 INIT_WORK(&local->sta_flush_work, ieee80211_sta_flush_work);
724 693
725 setup_timer(&local->sta_cleanup, sta_info_cleanup, 694 setup_timer(&local->sta_cleanup, sta_info_cleanup,
726 (unsigned long)local); 695 (unsigned long)local);
@@ -741,7 +710,6 @@ int sta_info_start(struct ieee80211_local *local)
741void sta_info_stop(struct ieee80211_local *local) 710void sta_info_stop(struct ieee80211_local *local)
742{ 711{
743 del_timer(&local->sta_cleanup); 712 del_timer(&local->sta_cleanup);
744 cancel_work_sync(&local->sta_flush_work);
745#ifdef CONFIG_MAC80211_DEBUGFS 713#ifdef CONFIG_MAC80211_DEBUGFS
746 /* 714 /*
747 * Make sure the debugfs adding work isn't pending after this 715 * Make sure the debugfs adding work isn't pending after this
@@ -752,10 +720,7 @@ void sta_info_stop(struct ieee80211_local *local)
752 cancel_work_sync(&local->sta_debugfs_add); 720 cancel_work_sync(&local->sta_debugfs_add);
753#endif 721#endif
754 722
755 rtnl_lock();
756 sta_info_flush(local, NULL); 723 sta_info_flush(local, NULL);
757 __ieee80211_run_pending_flush(local);
758 rtnl_unlock();
759} 724}
760 725
761/** 726/**
@@ -767,7 +732,7 @@ void sta_info_stop(struct ieee80211_local *local)
767 * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs 732 * @sdata: matching rule for the net device (sta->dev) or %NULL to match all STAs
768 */ 733 */
769int sta_info_flush(struct ieee80211_local *local, 734int sta_info_flush(struct ieee80211_local *local,
770 struct ieee80211_sub_if_data *sdata) 735 struct ieee80211_sub_if_data *sdata)
771{ 736{
772 struct sta_info *sta, *tmp; 737 struct sta_info *sta, *tmp;
773 LIST_HEAD(tmp_list); 738 LIST_HEAD(tmp_list);
@@ -775,7 +740,6 @@ int sta_info_flush(struct ieee80211_local *local,
775 unsigned long flags; 740 unsigned long flags;
776 741
777 might_sleep(); 742 might_sleep();
778 ASSERT_RTNL();
779 743
780 spin_lock_irqsave(&local->sta_lock, flags); 744 spin_lock_irqsave(&local->sta_lock, flags);
781 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) { 745 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
@@ -795,39 +759,6 @@ int sta_info_flush(struct ieee80211_local *local,
795 return ret; 759 return ret;
796} 760}
797 761
798/**
799 * sta_info_flush_delayed - flush matching STA entries from the STA table
800 *
801 * This function unlinks all stations for a given interface and queues
802 * them for freeing. Note that the workqueue function scheduled here has
803 * to run before any new keys can be added to the system to avoid set_key()
804 * callback ordering issues.
805 *
806 * @sdata: the interface
807 */
808void sta_info_flush_delayed(struct ieee80211_sub_if_data *sdata)
809{
810 struct ieee80211_local *local = sdata->local;
811 struct sta_info *sta, *tmp;
812 unsigned long flags;
813 bool work = false;
814
815 spin_lock_irqsave(&local->sta_lock, flags);
816 list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
817 if (sdata == sta->sdata) {
818 __sta_info_unlink(&sta);
819 if (sta) {
820 list_add_tail(&sta->list,
821 &local->sta_flush_list);
822 work = true;
823 }
824 }
825 }
826 if (work)
827 schedule_work(&local->sta_flush_work);
828 spin_unlock_irqrestore(&local->sta_lock, flags);
829}
830
831void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, 762void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
832 unsigned long exp_time) 763 unsigned long exp_time)
833{ 764{
diff --git a/net/mac80211/sta_info.h b/net/mac80211/sta_info.h
index 5534d489f506..31a8990ce401 100644
--- a/net/mac80211/sta_info.h
+++ b/net/mac80211/sta_info.h
@@ -442,8 +442,7 @@ void sta_info_init(struct ieee80211_local *local);
442int sta_info_start(struct ieee80211_local *local); 442int sta_info_start(struct ieee80211_local *local);
443void sta_info_stop(struct ieee80211_local *local); 443void sta_info_stop(struct ieee80211_local *local);
444int sta_info_flush(struct ieee80211_local *local, 444int sta_info_flush(struct ieee80211_local *local,
445 struct ieee80211_sub_if_data *sdata); 445 struct ieee80211_sub_if_data *sdata);
446void sta_info_flush_delayed(struct ieee80211_sub_if_data *sdata);
447void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata, 446void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
448 unsigned long exp_time); 447 unsigned long exp_time);
449 448
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index 3fb04a86444d..1865622003c9 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -409,8 +409,24 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
409 sta->sta.addr); 409 sta->sta.addr);
410 } 410 }
411#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 411#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
412 clear_sta_flags(sta, WLAN_STA_PSPOLL); 412 if (test_and_clear_sta_flags(sta, WLAN_STA_PSPOLL)) {
413 /*
414 * The sleeping station with pending data is now snoozing.
415 * It queried us for its buffered frames and will go back
416 * to deep sleep once it got everything.
417 *
418 * inform the driver, in case the hardware does powersave
419 * frame filtering and keeps a station blacklist on its own
420 * (e.g: p54), so that frames can be delivered unimpeded.
421 *
422 * Note: It should be save to disable the filter now.
423 * As, it is really unlikely that we still have any pending
424 * frame for this station in the hw's buffers/fifos left,
425 * that is not rejected with a unsuccessful tx_status yet.
426 */
413 427
428 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
429 }
414 return TX_CONTINUE; 430 return TX_CONTINUE;
415} 431}
416 432
@@ -429,7 +445,7 @@ ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
429static ieee80211_tx_result debug_noinline 445static ieee80211_tx_result debug_noinline
430ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) 446ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
431{ 447{
432 struct ieee80211_key *key; 448 struct ieee80211_key *key = NULL;
433 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); 449 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
434 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; 450 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
435 451
@@ -500,7 +516,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
500 sband = tx->local->hw.wiphy->bands[tx->channel->band]; 516 sband = tx->local->hw.wiphy->bands[tx->channel->band];
501 517
502 len = min_t(int, tx->skb->len + FCS_LEN, 518 len = min_t(int, tx->skb->len + FCS_LEN,
503 tx->local->fragmentation_threshold); 519 tx->local->hw.wiphy->frag_threshold);
504 520
505 /* set up the tx rate control struct we give the RC algo */ 521 /* set up the tx rate control struct we give the RC algo */
506 txrc.hw = local_to_hw(tx->local); 522 txrc.hw = local_to_hw(tx->local);
@@ -511,8 +527,7 @@ ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
511 txrc.max_rate_idx = tx->sdata->max_ratectrl_rateidx; 527 txrc.max_rate_idx = tx->sdata->max_ratectrl_rateidx;
512 528
513 /* set up RTS protection if desired */ 529 /* set up RTS protection if desired */
514 if (tx->local->rts_threshold < IEEE80211_MAX_RTS_THRESHOLD && 530 if (len > tx->local->hw.wiphy->rts_threshold) {
515 len > tx->local->rts_threshold) {
516 txrc.rts = rts = true; 531 txrc.rts = rts = true;
517 } 532 }
518 533
@@ -754,7 +769,7 @@ ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
754 struct sk_buff *skb = tx->skb; 769 struct sk_buff *skb = tx->skb;
755 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 770 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
756 struct ieee80211_hdr *hdr = (void *)skb->data; 771 struct ieee80211_hdr *hdr = (void *)skb->data;
757 int frag_threshold = tx->local->fragmentation_threshold; 772 int frag_threshold = tx->local->hw.wiphy->frag_threshold;
758 int hdrlen; 773 int hdrlen;
759 int fragnum; 774 int fragnum;
760 775
@@ -1072,7 +1087,7 @@ __ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
1072 1087
1073 if (tx->flags & IEEE80211_TX_FRAGMENTED) { 1088 if (tx->flags & IEEE80211_TX_FRAGMENTED) {
1074 if ((tx->flags & IEEE80211_TX_UNICAST) && 1089 if ((tx->flags & IEEE80211_TX_UNICAST) &&
1075 skb->len + FCS_LEN > local->fragmentation_threshold && 1090 skb->len + FCS_LEN > local->hw.wiphy->frag_threshold &&
1076 !(info->flags & IEEE80211_TX_CTL_AMPDU)) 1091 !(info->flags & IEEE80211_TX_CTL_AMPDU))
1077 tx->flags |= IEEE80211_TX_FRAGMENTED; 1092 tx->flags |= IEEE80211_TX_FRAGMENTED;
1078 else 1093 else
@@ -2086,18 +2101,18 @@ struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
2086 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { 2101 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2087 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 2102 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
2088 struct ieee80211_hdr *hdr; 2103 struct ieee80211_hdr *hdr;
2104 struct sk_buff *presp = rcu_dereference(ifibss->presp);
2089 2105
2090 if (!ifibss->probe_resp) 2106 if (!presp)
2091 goto out; 2107 goto out;
2092 2108
2093 skb = skb_copy(ifibss->probe_resp, GFP_ATOMIC); 2109 skb = skb_copy(presp, GFP_ATOMIC);
2094 if (!skb) 2110 if (!skb)
2095 goto out; 2111 goto out;
2096 2112
2097 hdr = (struct ieee80211_hdr *) skb->data; 2113 hdr = (struct ieee80211_hdr *) skb->data;
2098 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 2114 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2099 IEEE80211_STYPE_BEACON); 2115 IEEE80211_STYPE_BEACON);
2100
2101 } else if (ieee80211_vif_is_mesh(&sdata->vif)) { 2116 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
2102 struct ieee80211_mgmt *mgmt; 2117 struct ieee80211_mgmt *mgmt;
2103 u8 *pos; 2118 u8 *pos;
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index fdf432f14554..61876eb50b49 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -20,6 +20,7 @@
20#include <linux/if_arp.h> 20#include <linux/if_arp.h>
21#include <linux/wireless.h> 21#include <linux/wireless.h>
22#include <linux/bitmap.h> 22#include <linux/bitmap.h>
23#include <linux/crc32.h>
23#include <net/net_namespace.h> 24#include <net/net_namespace.h>
24#include <net/cfg80211.h> 25#include <net/cfg80211.h>
25#include <net/rtnetlink.h> 26#include <net/rtnetlink.h>
@@ -28,6 +29,7 @@
28#include "rate.h" 29#include "rate.h"
29#include "mesh.h" 30#include "mesh.h"
30#include "wme.h" 31#include "wme.h"
32#include "led.h"
31 33
32/* privid for wiphys to determine whether they belong to us or not */ 34/* privid for wiphys to determine whether they belong to us or not */
33void *mac80211_wiphy_privid = &mac80211_wiphy_privid; 35void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
@@ -536,8 +538,16 @@ EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
536void ieee802_11_parse_elems(u8 *start, size_t len, 538void ieee802_11_parse_elems(u8 *start, size_t len,
537 struct ieee802_11_elems *elems) 539 struct ieee802_11_elems *elems)
538{ 540{
541 ieee802_11_parse_elems_crc(start, len, elems, 0, 0);
542}
543
544u32 ieee802_11_parse_elems_crc(u8 *start, size_t len,
545 struct ieee802_11_elems *elems,
546 u64 filter, u32 crc)
547{
539 size_t left = len; 548 size_t left = len;
540 u8 *pos = start; 549 u8 *pos = start;
550 bool calc_crc = filter != 0;
541 551
542 memset(elems, 0, sizeof(*elems)); 552 memset(elems, 0, sizeof(*elems));
543 elems->ie_start = start; 553 elems->ie_start = start;
@@ -551,7 +561,10 @@ void ieee802_11_parse_elems(u8 *start, size_t len,
551 left -= 2; 561 left -= 2;
552 562
553 if (elen > left) 563 if (elen > left)
554 return; 564 break;
565
566 if (calc_crc && id < 64 && (filter & BIT(id)))
567 crc = crc32_be(crc, pos - 2, elen + 2);
555 568
556 switch (id) { 569 switch (id) {
557 case WLAN_EID_SSID: 570 case WLAN_EID_SSID:
@@ -575,8 +588,10 @@ void ieee802_11_parse_elems(u8 *start, size_t len,
575 elems->cf_params_len = elen; 588 elems->cf_params_len = elen;
576 break; 589 break;
577 case WLAN_EID_TIM: 590 case WLAN_EID_TIM:
578 elems->tim = pos; 591 if (elen >= sizeof(struct ieee80211_tim_ie)) {
579 elems->tim_len = elen; 592 elems->tim = (void *)pos;
593 elems->tim_len = elen;
594 }
580 break; 595 break;
581 case WLAN_EID_IBSS_PARAMS: 596 case WLAN_EID_IBSS_PARAMS:
582 elems->ibss_params = pos; 597 elems->ibss_params = pos;
@@ -586,15 +601,20 @@ void ieee802_11_parse_elems(u8 *start, size_t len,
586 elems->challenge = pos; 601 elems->challenge = pos;
587 elems->challenge_len = elen; 602 elems->challenge_len = elen;
588 break; 603 break;
589 case WLAN_EID_WPA: 604 case WLAN_EID_VENDOR_SPECIFIC:
590 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 && 605 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
591 pos[2] == 0xf2) { 606 pos[2] == 0xf2) {
592 /* Microsoft OUI (00:50:F2) */ 607 /* Microsoft OUI (00:50:F2) */
608
609 if (calc_crc)
610 crc = crc32_be(crc, pos - 2, elen + 2);
611
593 if (pos[3] == 1) { 612 if (pos[3] == 1) {
594 /* OUI Type 1 - WPA IE */ 613 /* OUI Type 1 - WPA IE */
595 elems->wpa = pos; 614 elems->wpa = pos;
596 elems->wpa_len = elen; 615 elems->wpa_len = elen;
597 } else if (elen >= 5 && pos[3] == 2) { 616 } else if (elen >= 5 && pos[3] == 2) {
617 /* OUI Type 2 - WMM IE */
598 if (pos[4] == 0) { 618 if (pos[4] == 0) {
599 elems->wmm_info = pos; 619 elems->wmm_info = pos;
600 elems->wmm_info_len = elen; 620 elems->wmm_info_len = elen;
@@ -679,6 +699,8 @@ void ieee802_11_parse_elems(u8 *start, size_t len,
679 left -= elen; 699 left -= elen;
680 pos += elen; 700 pos += elen;
681 } 701 }
702
703 return crc;
682} 704}
683 705
684void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata) 706void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata)
@@ -831,16 +853,73 @@ void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
831 ieee80211_tx_skb(sdata, skb, encrypt); 853 ieee80211_tx_skb(sdata, skb, encrypt);
832} 854}
833 855
856int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
857 const u8 *ie, size_t ie_len)
858{
859 struct ieee80211_supported_band *sband;
860 u8 *pos, *supp_rates_len, *esupp_rates_len = NULL;
861 int i;
862
863 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
864
865 pos = buffer;
866
867 *pos++ = WLAN_EID_SUPP_RATES;
868 supp_rates_len = pos;
869 *pos++ = 0;
870
871 for (i = 0; i < sband->n_bitrates; i++) {
872 struct ieee80211_rate *rate = &sband->bitrates[i];
873
874 if (esupp_rates_len) {
875 *esupp_rates_len += 1;
876 } else if (*supp_rates_len == 8) {
877 *pos++ = WLAN_EID_EXT_SUPP_RATES;
878 esupp_rates_len = pos;
879 *pos++ = 1;
880 } else
881 *supp_rates_len += 1;
882
883 *pos++ = rate->bitrate / 5;
884 }
885
886 if (sband->ht_cap.ht_supported) {
887 __le16 tmp = cpu_to_le16(sband->ht_cap.cap);
888
889 *pos++ = WLAN_EID_HT_CAPABILITY;
890 *pos++ = sizeof(struct ieee80211_ht_cap);
891 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
892 memcpy(pos, &tmp, sizeof(u16));
893 pos += sizeof(u16);
894 /* TODO: needs a define here for << 2 */
895 *pos++ = sband->ht_cap.ampdu_factor |
896 (sband->ht_cap.ampdu_density << 2);
897 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
898 pos += sizeof(sband->ht_cap.mcs);
899 pos += 2 + 4 + 1; /* ext info, BF cap, antsel */
900 }
901
902 /*
903 * If adding more here, adjust code in main.c
904 * that calculates local->scan_ies_len.
905 */
906
907 if (ie) {
908 memcpy(pos, ie, ie_len);
909 pos += ie_len;
910 }
911
912 return pos - buffer;
913}
914
834void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, 915void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
835 u8 *ssid, size_t ssid_len, 916 const u8 *ssid, size_t ssid_len,
836 u8 *ie, size_t ie_len) 917 const u8 *ie, size_t ie_len)
837{ 918{
838 struct ieee80211_local *local = sdata->local; 919 struct ieee80211_local *local = sdata->local;
839 struct ieee80211_supported_band *sband;
840 struct sk_buff *skb; 920 struct sk_buff *skb;
841 struct ieee80211_mgmt *mgmt; 921 struct ieee80211_mgmt *mgmt;
842 u8 *pos, *supp_rates, *esupp_rates = NULL; 922 u8 *pos;
843 int i;
844 923
845 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200 + 924 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200 +
846 ie_len); 925 ie_len);
@@ -867,31 +946,9 @@ void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
867 *pos++ = WLAN_EID_SSID; 946 *pos++ = WLAN_EID_SSID;
868 *pos++ = ssid_len; 947 *pos++ = ssid_len;
869 memcpy(pos, ssid, ssid_len); 948 memcpy(pos, ssid, ssid_len);
949 pos += ssid_len;
870 950
871 supp_rates = skb_put(skb, 2); 951 skb_put(skb, ieee80211_build_preq_ies(local, pos, ie, ie_len));
872 supp_rates[0] = WLAN_EID_SUPP_RATES;
873 supp_rates[1] = 0;
874 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
875
876 for (i = 0; i < sband->n_bitrates; i++) {
877 struct ieee80211_rate *rate = &sband->bitrates[i];
878 if (esupp_rates) {
879 pos = skb_put(skb, 1);
880 esupp_rates[1]++;
881 } else if (supp_rates[1] == 8) {
882 esupp_rates = skb_put(skb, 3);
883 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
884 esupp_rates[1] = 1;
885 pos = &esupp_rates[2];
886 } else {
887 pos = skb_put(skb, 1);
888 supp_rates[1]++;
889 }
890 *pos = rate->bitrate / 5;
891 }
892
893 if (ie)
894 memcpy(skb_put(skb, ie_len), ie, ie_len);
895 952
896 ieee80211_tx_skb(sdata, skb, 0); 953 ieee80211_tx_skb(sdata, skb, 0);
897} 954}
@@ -931,3 +988,120 @@ u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
931 } 988 }
932 return supp_rates; 989 return supp_rates;
933} 990}
991
992int ieee80211_reconfig(struct ieee80211_local *local)
993{
994 struct ieee80211_hw *hw = &local->hw;
995 struct ieee80211_sub_if_data *sdata;
996 struct ieee80211_if_init_conf conf;
997 struct sta_info *sta;
998 unsigned long flags;
999 int res;
1000
1001 /* restart hardware */
1002 if (local->open_count) {
1003 res = local->ops->start(hw);
1004
1005 ieee80211_led_radio(local, hw->conf.radio_enabled);
1006 }
1007
1008 /* add interfaces */
1009 list_for_each_entry(sdata, &local->interfaces, list) {
1010 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1011 sdata->vif.type != NL80211_IFTYPE_MONITOR &&
1012 netif_running(sdata->dev)) {
1013 conf.vif = &sdata->vif;
1014 conf.type = sdata->vif.type;
1015 conf.mac_addr = sdata->dev->dev_addr;
1016 res = local->ops->add_interface(hw, &conf);
1017 }
1018 }
1019
1020 /* add STAs back */
1021 if (local->ops->sta_notify) {
1022 spin_lock_irqsave(&local->sta_lock, flags);
1023 list_for_each_entry(sta, &local->sta_list, list) {
1024 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1025 sdata = container_of(sdata->bss,
1026 struct ieee80211_sub_if_data,
1027 u.ap);
1028
1029 local->ops->sta_notify(hw, &sdata->vif,
1030 STA_NOTIFY_ADD, &sta->sta);
1031 }
1032 spin_unlock_irqrestore(&local->sta_lock, flags);
1033 }
1034
1035 /* Clear Suspend state so that ADDBA requests can be processed */
1036
1037 rcu_read_lock();
1038
1039 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
1040 list_for_each_entry_rcu(sta, &local->sta_list, list) {
1041 clear_sta_flags(sta, WLAN_STA_SUSPEND);
1042 }
1043 }
1044
1045 rcu_read_unlock();
1046
1047 /* setup RTS threshold */
1048 if (local->ops->set_rts_threshold)
1049 local->ops->set_rts_threshold(hw, hw->wiphy->rts_threshold);
1050
1051 /* reconfigure hardware */
1052 ieee80211_hw_config(local, ~0);
1053
1054 netif_addr_lock_bh(local->mdev);
1055 ieee80211_configure_filter(local);
1056 netif_addr_unlock_bh(local->mdev);
1057
1058 /* Finally also reconfigure all the BSS information */
1059 list_for_each_entry(sdata, &local->interfaces, list) {
1060 u32 changed = ~0;
1061 if (!netif_running(sdata->dev))
1062 continue;
1063 switch (sdata->vif.type) {
1064 case NL80211_IFTYPE_STATION:
1065 /* disable beacon change bits */
1066 changed &= ~IEEE80211_IFCC_BEACON;
1067 /* fall through */
1068 case NL80211_IFTYPE_ADHOC:
1069 case NL80211_IFTYPE_AP:
1070 case NL80211_IFTYPE_MESH_POINT:
1071 /*
1072 * Driver's config_interface can fail if rfkill is
1073 * enabled. Accommodate this return code.
1074 * FIXME: When mac80211 has knowledge of rfkill
1075 * state the code below can change back to:
1076 * WARN(ieee80211_if_config(sdata, changed));
1077 * ieee80211_bss_info_change_notify(sdata, ~0);
1078 */
1079 if (ieee80211_if_config(sdata, changed))
1080 printk(KERN_DEBUG "%s: failed to configure interface during resume\n",
1081 sdata->dev->name);
1082 else
1083 ieee80211_bss_info_change_notify(sdata, ~0);
1084 break;
1085 case NL80211_IFTYPE_WDS:
1086 break;
1087 case NL80211_IFTYPE_AP_VLAN:
1088 case NL80211_IFTYPE_MONITOR:
1089 /* ignore virtual */
1090 break;
1091 case NL80211_IFTYPE_UNSPECIFIED:
1092 case __NL80211_IFTYPE_AFTER_LAST:
1093 WARN_ON(1);
1094 break;
1095 }
1096 }
1097
1098 /* add back keys */
1099 list_for_each_entry(sdata, &local->interfaces, list)
1100 if (netif_running(sdata->dev))
1101 ieee80211_enable_keys(sdata);
1102
1103 ieee80211_wake_queues_by_reason(hw,
1104 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
1105
1106 return 0;
1107}
diff --git a/net/mac80211/wext.c b/net/mac80211/wext.c
index 959aa8379ccf..1a649da42c41 100644
--- a/net/mac80211/wext.c
+++ b/net/mac80211/wext.c
@@ -149,17 +149,14 @@ static int ieee80211_ioctl_siwfreq(struct net_device *dev,
149 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 149 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
150 150
151 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 151 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
152 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_CHANNEL_SEL; 152 return cfg80211_ibss_wext_siwfreq(dev, info, freq, extra);
153 else if (sdata->vif.type == NL80211_IFTYPE_STATION) 153 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
154 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL; 154 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
155 155
156 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */ 156 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
157 if (freq->e == 0) { 157 if (freq->e == 0) {
158 if (freq->m < 0) { 158 if (freq->m < 0) {
159 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 159 if (sdata->vif.type == NL80211_IFTYPE_STATION)
160 sdata->u.ibss.flags |=
161 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
162 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
163 sdata->u.mgd.flags |= 160 sdata->u.mgd.flags |=
164 IEEE80211_STA_AUTO_CHANNEL_SEL; 161 IEEE80211_STA_AUTO_CHANNEL_SEL;
165 return 0; 162 return 0;
@@ -183,6 +180,10 @@ static int ieee80211_ioctl_giwfreq(struct net_device *dev,
183 struct iw_freq *freq, char *extra) 180 struct iw_freq *freq, char *extra)
184{ 181{
185 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 182 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
183 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
184
185 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
186 return cfg80211_ibss_wext_giwfreq(dev, info, freq, extra);
186 187
187 freq->m = local->hw.conf.channel->center_freq; 188 freq->m = local->hw.conf.channel->center_freq;
188 freq->e = 6; 189 freq->e = 6;
@@ -195,15 +196,17 @@ static int ieee80211_ioctl_siwessid(struct net_device *dev,
195 struct iw_request_info *info, 196 struct iw_request_info *info,
196 struct iw_point *data, char *ssid) 197 struct iw_point *data, char *ssid)
197{ 198{
198 struct ieee80211_sub_if_data *sdata; 199 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
199 size_t len = data->length; 200 size_t len = data->length;
200 int ret; 201 int ret;
201 202
203 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
204 return cfg80211_ibss_wext_siwessid(dev, info, data, ssid);
205
202 /* iwconfig uses nul termination in SSID.. */ 206 /* iwconfig uses nul termination in SSID.. */
203 if (len > 0 && ssid[len - 1] == '\0') 207 if (len > 0 && ssid[len - 1] == '\0')
204 len--; 208 len--;
205 209
206 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
207 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 210 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
208 if (data->flags) 211 if (data->flags)
209 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL; 212 sdata->u.mgd.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
@@ -217,8 +220,7 @@ static int ieee80211_ioctl_siwessid(struct net_device *dev,
217 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME; 220 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
218 ieee80211_sta_req_auth(sdata); 221 ieee80211_sta_req_auth(sdata);
219 return 0; 222 return 0;
220 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) 223 }
221 return ieee80211_ibss_set_ssid(sdata, ssid, len);
222 224
223 return -EOPNOTSUPP; 225 return -EOPNOTSUPP;
224} 226}
@@ -229,9 +231,13 @@ static int ieee80211_ioctl_giwessid(struct net_device *dev,
229 struct iw_point *data, char *ssid) 231 struct iw_point *data, char *ssid)
230{ 232{
231 size_t len; 233 size_t len;
232
233 struct ieee80211_sub_if_data *sdata; 234 struct ieee80211_sub_if_data *sdata;
235
234 sdata = IEEE80211_DEV_TO_SUB_IF(dev); 236 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
237
238 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
239 return cfg80211_ibss_wext_giwessid(dev, info, data, ssid);
240
235 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 241 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
236 int res = ieee80211_sta_get_ssid(sdata, ssid, &len); 242 int res = ieee80211_sta_get_ssid(sdata, ssid, &len);
237 if (res == 0) { 243 if (res == 0) {
@@ -240,14 +246,6 @@ static int ieee80211_ioctl_giwessid(struct net_device *dev,
240 } else 246 } else
241 data->flags = 0; 247 data->flags = 0;
242 return res; 248 return res;
243 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
244 int res = ieee80211_ibss_get_ssid(sdata, ssid, &len);
245 if (res == 0) {
246 data->length = len;
247 data->flags = 1;
248 } else
249 data->flags = 0;
250 return res;
251 } 249 }
252 250
253 return -EOPNOTSUPP; 251 return -EOPNOTSUPP;
@@ -258,9 +256,11 @@ static int ieee80211_ioctl_siwap(struct net_device *dev,
258 struct iw_request_info *info, 256 struct iw_request_info *info,
259 struct sockaddr *ap_addr, char *extra) 257 struct sockaddr *ap_addr, char *extra)
260{ 258{
261 struct ieee80211_sub_if_data *sdata; 259 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
260
261 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
262 return cfg80211_ibss_wext_siwap(dev, info, ap_addr, extra);
262 263
263 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
264 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 264 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
265 int ret; 265 int ret;
266 266
@@ -277,16 +277,6 @@ static int ieee80211_ioctl_siwap(struct net_device *dev,
277 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME; 277 sdata->u.mgd.flags &= ~IEEE80211_STA_EXT_SME;
278 ieee80211_sta_req_auth(sdata); 278 ieee80211_sta_req_auth(sdata);
279 return 0; 279 return 0;
280 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
281 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
282 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL |
283 IEEE80211_IBSS_AUTO_CHANNEL_SEL;
284 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
285 sdata->u.ibss.flags |= IEEE80211_IBSS_AUTO_BSSID_SEL;
286 else
287 sdata->u.ibss.flags &= ~IEEE80211_IBSS_AUTO_BSSID_SEL;
288
289 return ieee80211_ibss_set_bssid(sdata, (u8 *) &ap_addr->sa_data);
290 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) { 280 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
291 /* 281 /*
292 * If it is necessary to update the WDS peer address 282 * If it is necessary to update the WDS peer address
@@ -312,9 +302,11 @@ static int ieee80211_ioctl_giwap(struct net_device *dev,
312 struct iw_request_info *info, 302 struct iw_request_info *info,
313 struct sockaddr *ap_addr, char *extra) 303 struct sockaddr *ap_addr, char *extra)
314{ 304{
315 struct ieee80211_sub_if_data *sdata; 305 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
306
307 if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
308 return cfg80211_ibss_wext_giwap(dev, info, ap_addr, extra);
316 309
317 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
318 if (sdata->vif.type == NL80211_IFTYPE_STATION) { 310 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
319 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) { 311 if (sdata->u.mgd.state == IEEE80211_STA_MLME_ASSOCIATED) {
320 ap_addr->sa_family = ARPHRD_ETHER; 312 ap_addr->sa_family = ARPHRD_ETHER;
@@ -322,13 +314,6 @@ static int ieee80211_ioctl_giwap(struct net_device *dev,
322 } else 314 } else
323 memset(&ap_addr->sa_data, 0, ETH_ALEN); 315 memset(&ap_addr->sa_data, 0, ETH_ALEN);
324 return 0; 316 return 0;
325 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
326 if (sdata->u.ibss.state == IEEE80211_IBSS_MLME_JOINED) {
327 ap_addr->sa_family = ARPHRD_ETHER;
328 memcpy(&ap_addr->sa_data, sdata->u.ibss.bssid, ETH_ALEN);
329 } else
330 memset(&ap_addr->sa_data, 0, ETH_ALEN);
331 return 0;
332 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) { 317 } else if (sdata->vif.type == NL80211_IFTYPE_WDS) {
333 ap_addr->sa_family = ARPHRD_ETHER; 318 ap_addr->sa_family = ARPHRD_ETHER;
334 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN); 319 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
@@ -487,155 +472,6 @@ static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
487 return 0; 472 return 0;
488} 473}
489 474
490static int ieee80211_ioctl_siwrts(struct net_device *dev,
491 struct iw_request_info *info,
492 struct iw_param *rts, char *extra)
493{
494 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
495
496 if (rts->disabled)
497 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
498 else if (!rts->fixed)
499 /* if the rts value is not fixed, then take default */
500 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
501 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
502 return -EINVAL;
503 else
504 local->rts_threshold = rts->value;
505
506 /* If the wlan card performs RTS/CTS in hardware/firmware,
507 * configure it here */
508
509 if (local->ops->set_rts_threshold)
510 local->ops->set_rts_threshold(local_to_hw(local),
511 local->rts_threshold);
512
513 return 0;
514}
515
516static int ieee80211_ioctl_giwrts(struct net_device *dev,
517 struct iw_request_info *info,
518 struct iw_param *rts, char *extra)
519{
520 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
521
522 rts->value = local->rts_threshold;
523 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
524 rts->fixed = 1;
525
526 return 0;
527}
528
529
530static int ieee80211_ioctl_siwfrag(struct net_device *dev,
531 struct iw_request_info *info,
532 struct iw_param *frag, char *extra)
533{
534 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
535
536 if (frag->disabled)
537 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
538 else if (!frag->fixed)
539 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
540 else if (frag->value < 256 ||
541 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
542 return -EINVAL;
543 else {
544 /* Fragment length must be even, so strip LSB. */
545 local->fragmentation_threshold = frag->value & ~0x1;
546 }
547
548 return 0;
549}
550
551static int ieee80211_ioctl_giwfrag(struct net_device *dev,
552 struct iw_request_info *info,
553 struct iw_param *frag, char *extra)
554{
555 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
556
557 frag->value = local->fragmentation_threshold;
558 frag->disabled = (frag->value >= IEEE80211_MAX_FRAG_THRESHOLD);
559 frag->fixed = 1;
560
561 return 0;
562}
563
564
565static int ieee80211_ioctl_siwretry(struct net_device *dev,
566 struct iw_request_info *info,
567 struct iw_param *retry, char *extra)
568{
569 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
570
571 if (retry->disabled ||
572 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
573 return -EINVAL;
574
575 if (retry->flags & IW_RETRY_MAX) {
576 local->hw.conf.long_frame_max_tx_count = retry->value;
577 } else if (retry->flags & IW_RETRY_MIN) {
578 local->hw.conf.short_frame_max_tx_count = retry->value;
579 } else {
580 local->hw.conf.long_frame_max_tx_count = retry->value;
581 local->hw.conf.short_frame_max_tx_count = retry->value;
582 }
583
584 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
585
586 return 0;
587}
588
589
590static int ieee80211_ioctl_giwretry(struct net_device *dev,
591 struct iw_request_info *info,
592 struct iw_param *retry, char *extra)
593{
594 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
595
596 retry->disabled = 0;
597 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
598 /* first return min value, iwconfig will ask max value
599 * later if needed */
600 retry->flags |= IW_RETRY_LIMIT;
601 retry->value = local->hw.conf.short_frame_max_tx_count;
602 if (local->hw.conf.long_frame_max_tx_count !=
603 local->hw.conf.short_frame_max_tx_count)
604 retry->flags |= IW_RETRY_MIN;
605 return 0;
606 }
607 if (retry->flags & IW_RETRY_MAX) {
608 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
609 retry->value = local->hw.conf.long_frame_max_tx_count;
610 }
611
612 return 0;
613}
614
615static int ieee80211_ioctl_siwmlme(struct net_device *dev,
616 struct iw_request_info *info,
617 struct iw_point *data, char *extra)
618{
619 struct ieee80211_sub_if_data *sdata;
620 struct iw_mlme *mlme = (struct iw_mlme *) extra;
621
622 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
623 if (!(sdata->vif.type == NL80211_IFTYPE_STATION))
624 return -EINVAL;
625
626 switch (mlme->cmd) {
627 case IW_MLME_DEAUTH:
628 /* TODO: mlme->addr.sa_data */
629 return ieee80211_sta_deauthenticate(sdata, mlme->reason_code);
630 case IW_MLME_DISASSOC:
631 /* TODO: mlme->addr.sa_data */
632 return ieee80211_sta_disassociate(sdata, mlme->reason_code);
633 default:
634 return -EOPNOTSUPP;
635 }
636}
637
638
639static int ieee80211_ioctl_siwencode(struct net_device *dev, 475static int ieee80211_ioctl_siwencode(struct net_device *dev,
640 struct iw_request_info *info, 476 struct iw_request_info *info,
641 struct iw_point *erq, char *keybuf) 477 struct iw_point *erq, char *keybuf)
@@ -675,7 +511,7 @@ static int ieee80211_ioctl_siwencode(struct net_device *dev,
675 !sdata->default_key, 511 !sdata->default_key,
676 keybuf, erq->length); 512 keybuf, erq->length);
677 513
678 if (!ret) { 514 if (!ret && sdata->vif.type == NL80211_IFTYPE_STATION) {
679 if (remove) 515 if (remove)
680 sdata->u.mgd.flags &= ~IEEE80211_STA_TKIP_WEP_USED; 516 sdata->u.mgd.flags &= ~IEEE80211_STA_TKIP_WEP_USED;
681 else 517 else
@@ -747,7 +583,7 @@ static int ieee80211_ioctl_siwpower(struct net_device *dev,
747 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 583 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
748 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 584 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
749 struct ieee80211_conf *conf = &local->hw.conf; 585 struct ieee80211_conf *conf = &local->hw.conf;
750 int ret = 0, timeout = 0; 586 int timeout = 0;
751 bool ps; 587 bool ps;
752 588
753 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) 589 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
@@ -779,42 +615,18 @@ static int ieee80211_ioctl_siwpower(struct net_device *dev,
779 timeout = wrq->value / 1000; 615 timeout = wrq->value / 1000;
780 616
781 set: 617 set:
782 if (ps == local->powersave && timeout == conf->dynamic_ps_timeout) 618 if (ps == sdata->u.mgd.powersave && timeout == conf->dynamic_ps_timeout)
783 return ret; 619 return 0;
784 620
785 local->powersave = ps; 621 sdata->u.mgd.powersave = ps;
786 conf->dynamic_ps_timeout = timeout; 622 conf->dynamic_ps_timeout = timeout;
787 623
788 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS) 624 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
789 ret = ieee80211_hw_config(local, 625 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
790 IEEE80211_CONF_CHANGE_DYNPS_TIMEOUT);
791 626
792 if (!(sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED)) 627 ieee80211_recalc_ps(local, -1);
793 return ret;
794 628
795 if (conf->dynamic_ps_timeout > 0 && 629 return 0;
796 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
797 mod_timer(&local->dynamic_ps_timer, jiffies +
798 msecs_to_jiffies(conf->dynamic_ps_timeout));
799 } else {
800 if (local->powersave) {
801 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
802 ieee80211_send_nullfunc(local, sdata, 1);
803 conf->flags |= IEEE80211_CONF_PS;
804 ret = ieee80211_hw_config(local,
805 IEEE80211_CONF_CHANGE_PS);
806 } else {
807 conf->flags &= ~IEEE80211_CONF_PS;
808 ret = ieee80211_hw_config(local,
809 IEEE80211_CONF_CHANGE_PS);
810 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
811 ieee80211_send_nullfunc(local, sdata, 0);
812 del_timer_sync(&local->dynamic_ps_timer);
813 cancel_work_sync(&local->dynamic_ps_enable_work);
814 }
815 }
816
817 return ret;
818} 630}
819 631
820static int ieee80211_ioctl_giwpower(struct net_device *dev, 632static int ieee80211_ioctl_giwpower(struct net_device *dev,
@@ -822,9 +634,9 @@ static int ieee80211_ioctl_giwpower(struct net_device *dev,
822 union iwreq_data *wrqu, 634 union iwreq_data *wrqu,
823 char *extra) 635 char *extra)
824{ 636{
825 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 637 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
826 638
827 wrqu->power.disabled = !local->powersave; 639 wrqu->power.disabled = !sdata->u.mgd.powersave;
828 640
829 return 0; 641 return 0;
830} 642}
@@ -1099,7 +911,7 @@ static const iw_handler ieee80211_handler[] =
1099 (iw_handler) NULL, /* SIOCGIWTHRSPY */ 911 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1100 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */ 912 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1101 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */ 913 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1102 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */ 914 (iw_handler) cfg80211_wext_siwmlme, /* SIOCSIWMLME */
1103 (iw_handler) NULL, /* SIOCGIWAPLIST */ 915 (iw_handler) NULL, /* SIOCGIWAPLIST */
1104 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */ 916 (iw_handler) cfg80211_wext_siwscan, /* SIOCSIWSCAN */
1105 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */ 917 (iw_handler) cfg80211_wext_giwscan, /* SIOCGIWSCAN */
@@ -1111,14 +923,14 @@ static const iw_handler ieee80211_handler[] =
1111 (iw_handler) NULL, /* -- hole -- */ 923 (iw_handler) NULL, /* -- hole -- */
1112 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */ 924 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1113 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */ 925 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1114 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */ 926 (iw_handler) cfg80211_wext_siwrts, /* SIOCSIWRTS */
1115 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */ 927 (iw_handler) cfg80211_wext_giwrts, /* SIOCGIWRTS */
1116 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */ 928 (iw_handler) cfg80211_wext_siwfrag, /* SIOCSIWFRAG */
1117 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */ 929 (iw_handler) cfg80211_wext_giwfrag, /* SIOCGIWFRAG */
1118 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */ 930 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1119 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */ 931 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1120 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */ 932 (iw_handler) cfg80211_wext_siwretry, /* SIOCSIWRETRY */
1121 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */ 933 (iw_handler) cfg80211_wext_giwretry, /* SIOCGIWRETRY */
1122 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */ 934 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1123 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */ 935 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1124 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */ 936 (iw_handler) ieee80211_ioctl_siwpower, /* SIOCSIWPOWER */
diff --git a/net/mac80211/wpa.c b/net/mac80211/wpa.c
index 4f8bfea278f2..dcfae8884b86 100644
--- a/net/mac80211/wpa.c
+++ b/net/mac80211/wpa.c
@@ -122,7 +122,7 @@ ieee80211_rx_h_michael_mic_verify(struct ieee80211_rx_data *rx)
122 return RX_DROP_UNUSABLE; 122 return RX_DROP_UNUSABLE;
123 123
124 mac80211_ev_michael_mic_failure(rx->sdata, rx->key->conf.keyidx, 124 mac80211_ev_michael_mic_failure(rx->sdata, rx->key->conf.keyidx,
125 (void *) skb->data); 125 (void *) skb->data, NULL);
126 return RX_DROP_UNUSABLE; 126 return RX_DROP_UNUSABLE;
127 } 127 }
128 128
diff --git a/net/rfkill/rfkill-input.c b/net/rfkill/rfkill-input.c
index 84efde97c5a7..60a34f3b5f65 100644
--- a/net/rfkill/rfkill-input.c
+++ b/net/rfkill/rfkill-input.c
@@ -47,12 +47,6 @@ enum rfkill_global_sched_op {
47 RFKILL_GLOBAL_OP_UNBLOCK, 47 RFKILL_GLOBAL_OP_UNBLOCK,
48}; 48};
49 49
50/*
51 * Currently, the code marked with RFKILL_NEED_SWSET is inactive.
52 * If handling of EV_SW SW_WLAN/WWAN/BLUETOOTH/etc is needed in the
53 * future, when such events are added, that code will be necessary.
54 */
55
56struct rfkill_task { 50struct rfkill_task {
57 struct delayed_work dwork; 51 struct delayed_work dwork;
58 52
@@ -65,14 +59,6 @@ struct rfkill_task {
65 /* pending regular switch operations (1=pending) */ 59 /* pending regular switch operations (1=pending) */
66 unsigned long sw_pending[BITS_TO_LONGS(RFKILL_TYPE_MAX)]; 60 unsigned long sw_pending[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
67 61
68#ifdef RFKILL_NEED_SWSET
69 /* set operation pending (1=pending) */
70 unsigned long sw_setpending[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
71
72 /* desired state for pending set operation (1=unblock) */
73 unsigned long sw_newstate[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
74#endif
75
76 /* should the state be complemented (1=yes) */ 62 /* should the state be complemented (1=yes) */
77 unsigned long sw_togglestate[BITS_TO_LONGS(RFKILL_TYPE_MAX)]; 63 unsigned long sw_togglestate[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
78 64
@@ -111,24 +97,6 @@ static void __rfkill_handle_global_op(enum rfkill_global_sched_op op)
111 } 97 }
112} 98}
113 99
114#ifdef RFKILL_NEED_SWSET
115static void __rfkill_handle_normal_op(const enum rfkill_type type,
116 const bool sp, const bool s, const bool c)
117{
118 enum rfkill_state state;
119
120 if (sp)
121 state = (s) ? RFKILL_STATE_UNBLOCKED :
122 RFKILL_STATE_SOFT_BLOCKED;
123 else
124 state = rfkill_get_global_state(type);
125
126 if (c)
127 state = rfkill_state_complement(state);
128
129 rfkill_switch_all(type, state);
130}
131#else
132static void __rfkill_handle_normal_op(const enum rfkill_type type, 100static void __rfkill_handle_normal_op(const enum rfkill_type type,
133 const bool c) 101 const bool c)
134{ 102{
@@ -140,7 +108,6 @@ static void __rfkill_handle_normal_op(const enum rfkill_type type,
140 108
141 rfkill_switch_all(type, state); 109 rfkill_switch_all(type, state);
142} 110}
143#endif
144 111
145static void rfkill_task_handler(struct work_struct *work) 112static void rfkill_task_handler(struct work_struct *work)
146{ 113{
@@ -171,21 +138,11 @@ static void rfkill_task_handler(struct work_struct *work)
171 i < RFKILL_TYPE_MAX) { 138 i < RFKILL_TYPE_MAX) {
172 if (test_and_clear_bit(i, task->sw_pending)) { 139 if (test_and_clear_bit(i, task->sw_pending)) {
173 bool c; 140 bool c;
174#ifdef RFKILL_NEED_SWSET
175 bool sp, s;
176 sp = test_and_clear_bit(i,
177 task->sw_setpending);
178 s = test_bit(i, task->sw_newstate);
179#endif
180 c = test_and_clear_bit(i, 141 c = test_and_clear_bit(i,
181 task->sw_togglestate); 142 task->sw_togglestate);
182 spin_unlock_irq(&task->lock); 143 spin_unlock_irq(&task->lock);
183 144
184#ifdef RFKILL_NEED_SWSET
185 __rfkill_handle_normal_op(i, sp, s, c);
186#else
187 __rfkill_handle_normal_op(i, c); 145 __rfkill_handle_normal_op(i, c);
188#endif
189 146
190 spin_lock_irq(&task->lock); 147 spin_lock_irq(&task->lock);
191 } 148 }
@@ -238,32 +195,6 @@ static void rfkill_schedule_global_op(enum rfkill_global_sched_op op)
238 spin_unlock_irqrestore(&rfkill_task.lock, flags); 195 spin_unlock_irqrestore(&rfkill_task.lock, flags);
239} 196}
240 197
241#ifdef RFKILL_NEED_SWSET
242/* Use this if you need to add EV_SW SW_WLAN/WWAN/BLUETOOTH/etc handling */
243
244static void rfkill_schedule_set(enum rfkill_type type,
245 enum rfkill_state desired_state)
246{
247 unsigned long flags;
248
249 if (rfkill_is_epo_lock_active())
250 return;
251
252 spin_lock_irqsave(&rfkill_task.lock, flags);
253 if (!rfkill_task.global_op_pending) {
254 set_bit(type, rfkill_task.sw_pending);
255 set_bit(type, rfkill_task.sw_setpending);
256 clear_bit(type, rfkill_task.sw_togglestate);
257 if (desired_state)
258 set_bit(type, rfkill_task.sw_newstate);
259 else
260 clear_bit(type, rfkill_task.sw_newstate);
261 rfkill_schedule_ratelimited();
262 }
263 spin_unlock_irqrestore(&rfkill_task.lock, flags);
264}
265#endif
266
267static void rfkill_schedule_toggle(enum rfkill_type type) 198static void rfkill_schedule_toggle(enum rfkill_type type)
268{ 199{
269 unsigned long flags; 200 unsigned long flags;
diff --git a/net/rfkill/rfkill.c b/net/rfkill/rfkill.c
index 3eaa39403c13..e2d4510623f2 100644
--- a/net/rfkill/rfkill.c
+++ b/net/rfkill/rfkill.c
@@ -96,6 +96,7 @@ static void update_rfkill_state(struct rfkill *rfkill)
96 } 96 }
97 mutex_unlock(&rfkill->mutex); 97 mutex_unlock(&rfkill->mutex);
98 } 98 }
99 rfkill_led_trigger(rfkill, rfkill->state);
99} 100}
100 101
101/** 102/**
@@ -136,8 +137,9 @@ static int rfkill_toggle_radio(struct rfkill *rfkill,
136 oldstate = rfkill->state; 137 oldstate = rfkill->state;
137 138
138 if (rfkill->get_state && !force && 139 if (rfkill->get_state && !force &&
139 !rfkill->get_state(rfkill->data, &newstate)) 140 !rfkill->get_state(rfkill->data, &newstate)) {
140 rfkill->state = newstate; 141 rfkill->state = newstate;
142 }
141 143
142 switch (state) { 144 switch (state) {
143 case RFKILL_STATE_HARD_BLOCKED: 145 case RFKILL_STATE_HARD_BLOCKED:
@@ -172,6 +174,7 @@ static int rfkill_toggle_radio(struct rfkill *rfkill,
172 if (force || rfkill->state != oldstate) 174 if (force || rfkill->state != oldstate)
173 rfkill_uevent(rfkill); 175 rfkill_uevent(rfkill);
174 176
177 rfkill_led_trigger(rfkill, rfkill->state);
175 return retval; 178 return retval;
176} 179}
177 180
@@ -200,10 +203,11 @@ static void __rfkill_switch_all(const enum rfkill_type type,
200 203
201 rfkill_global_states[type].current_state = state; 204 rfkill_global_states[type].current_state = state;
202 list_for_each_entry(rfkill, &rfkill_list, node) { 205 list_for_each_entry(rfkill, &rfkill_list, node) {
203 if ((!rfkill->user_claim) && (rfkill->type == type)) { 206 if (rfkill->type == type) {
204 mutex_lock(&rfkill->mutex); 207 mutex_lock(&rfkill->mutex);
205 rfkill_toggle_radio(rfkill, state, 0); 208 rfkill_toggle_radio(rfkill, state, 0);
206 mutex_unlock(&rfkill->mutex); 209 mutex_unlock(&rfkill->mutex);
210 rfkill_led_trigger(rfkill, rfkill->state);
207 } 211 }
208 } 212 }
209} 213}
@@ -256,6 +260,7 @@ void rfkill_epo(void)
256 RFKILL_STATE_SOFT_BLOCKED; 260 RFKILL_STATE_SOFT_BLOCKED;
257 } 261 }
258 mutex_unlock(&rfkill_global_mutex); 262 mutex_unlock(&rfkill_global_mutex);
263 rfkill_led_trigger(rfkill, rfkill->state);
259} 264}
260EXPORT_SYMBOL_GPL(rfkill_epo); 265EXPORT_SYMBOL_GPL(rfkill_epo);
261 266
@@ -358,6 +363,7 @@ int rfkill_force_state(struct rfkill *rfkill, enum rfkill_state state)
358 rfkill_uevent(rfkill); 363 rfkill_uevent(rfkill);
359 364
360 mutex_unlock(&rfkill->mutex); 365 mutex_unlock(&rfkill->mutex);
366 rfkill_led_trigger(rfkill, rfkill->state);
361 367
362 return 0; 368 return 0;
363} 369}
@@ -447,53 +453,14 @@ static ssize_t rfkill_claim_show(struct device *dev,
447 struct device_attribute *attr, 453 struct device_attribute *attr,
448 char *buf) 454 char *buf)
449{ 455{
450 struct rfkill *rfkill = to_rfkill(dev); 456 return sprintf(buf, "%d\n", 0);
451
452 return sprintf(buf, "%d\n", rfkill->user_claim);
453} 457}
454 458
455static ssize_t rfkill_claim_store(struct device *dev, 459static ssize_t rfkill_claim_store(struct device *dev,
456 struct device_attribute *attr, 460 struct device_attribute *attr,
457 const char *buf, size_t count) 461 const char *buf, size_t count)
458{ 462{
459 struct rfkill *rfkill = to_rfkill(dev); 463 return -EOPNOTSUPP;
460 unsigned long claim_tmp;
461 bool claim;
462 int error;
463
464 if (!capable(CAP_NET_ADMIN))
465 return -EPERM;
466
467 if (rfkill->user_claim_unsupported)
468 return -EOPNOTSUPP;
469
470 error = strict_strtoul(buf, 0, &claim_tmp);
471 if (error)
472 return error;
473 claim = !!claim_tmp;
474
475 /*
476 * Take the global lock to make sure the kernel is not in
477 * the middle of rfkill_switch_all
478 */
479 error = mutex_lock_killable(&rfkill_global_mutex);
480 if (error)
481 return error;
482
483 if (rfkill->user_claim != claim) {
484 if (!claim && !rfkill_epo_lock_active) {
485 mutex_lock(&rfkill->mutex);
486 rfkill_toggle_radio(rfkill,
487 rfkill_global_states[rfkill->type].current_state,
488 0);
489 mutex_unlock(&rfkill->mutex);
490 }
491 rfkill->user_claim = claim;
492 }
493
494 mutex_unlock(&rfkill_global_mutex);
495
496 return error ? error : count;
497} 464}
498 465
499static struct device_attribute rfkill_dev_attrs[] = { 466static struct device_attribute rfkill_dev_attrs[] = {
@@ -559,6 +526,7 @@ static int rfkill_resume(struct device *dev)
559 1); 526 1);
560 527
561 mutex_unlock(&rfkill->mutex); 528 mutex_unlock(&rfkill->mutex);
529 rfkill_led_trigger(rfkill, rfkill->state);
562 } 530 }
563 531
564 return 0; 532 return 0;
diff --git a/net/wimax/op-rfkill.c b/net/wimax/op-rfkill.c
index 2b75aee04217..a3616e2ccb8a 100644
--- a/net/wimax/op-rfkill.c
+++ b/net/wimax/op-rfkill.c
@@ -113,7 +113,7 @@ void wimax_report_rfkill_hw(struct wimax_dev *wimax_dev,
113 if (state != wimax_dev->rf_hw) { 113 if (state != wimax_dev->rf_hw) {
114 wimax_dev->rf_hw = state; 114 wimax_dev->rf_hw = state;
115 rfkill_state = state == WIMAX_RF_ON ? 115 rfkill_state = state == WIMAX_RF_ON ?
116 RFKILL_STATE_OFF : RFKILL_STATE_ON; 116 RFKILL_STATE_UNBLOCKED : RFKILL_STATE_SOFT_BLOCKED;
117 if (wimax_dev->rf_hw == WIMAX_RF_ON 117 if (wimax_dev->rf_hw == WIMAX_RF_ON
118 && wimax_dev->rf_sw == WIMAX_RF_ON) 118 && wimax_dev->rf_sw == WIMAX_RF_ON)
119 wimax_state = WIMAX_ST_READY; 119 wimax_state = WIMAX_ST_READY;
@@ -259,10 +259,10 @@ int wimax_rfkill_toggle_radio(void *data, enum rfkill_state state)
259 259
260 d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state); 260 d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state);
261 switch (state) { 261 switch (state) {
262 case RFKILL_STATE_ON: 262 case RFKILL_STATE_SOFT_BLOCKED:
263 rf_state = WIMAX_RF_OFF; 263 rf_state = WIMAX_RF_OFF;
264 break; 264 break;
265 case RFKILL_STATE_OFF: 265 case RFKILL_STATE_UNBLOCKED:
266 rf_state = WIMAX_RF_ON; 266 rf_state = WIMAX_RF_ON;
267 break; 267 break;
268 default: 268 default:
@@ -361,10 +361,9 @@ int wimax_rfkill_add(struct wimax_dev *wimax_dev)
361 wimax_dev->rfkill = rfkill; 361 wimax_dev->rfkill = rfkill;
362 362
363 rfkill->name = wimax_dev->name; 363 rfkill->name = wimax_dev->name;
364 rfkill->state = RFKILL_STATE_OFF; 364 rfkill->state = RFKILL_STATE_UNBLOCKED;
365 rfkill->data = wimax_dev; 365 rfkill->data = wimax_dev;
366 rfkill->toggle_radio = wimax_rfkill_toggle_radio; 366 rfkill->toggle_radio = wimax_rfkill_toggle_radio;
367 rfkill->user_claim_unsupported = 1;
368 367
369 /* Initialize the input device for the hw key */ 368 /* Initialize the input device for the hw key */
370 input_dev = input_allocate_device(); 369 input_dev = input_allocate_device();
diff --git a/net/wireless/Makefile b/net/wireless/Makefile
index 6d1e7b27b752..14ea01c4a103 100644
--- a/net/wireless/Makefile
+++ b/net/wireless/Makefile
@@ -5,7 +5,7 @@ obj-$(CONFIG_LIB80211_CRYPT_WEP) += lib80211_crypt_wep.o
5obj-$(CONFIG_LIB80211_CRYPT_CCMP) += lib80211_crypt_ccmp.o 5obj-$(CONFIG_LIB80211_CRYPT_CCMP) += lib80211_crypt_ccmp.o
6obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o 6obj-$(CONFIG_LIB80211_CRYPT_TKIP) += lib80211_crypt_tkip.o
7 7
8cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o mlme.o 8cfg80211-y += core.o sysfs.o radiotap.o util.o reg.o scan.o nl80211.o mlme.o ibss.o
9cfg80211-$(CONFIG_WIRELESS_EXT) += wext-compat.o 9cfg80211-$(CONFIG_WIRELESS_EXT) += wext-compat.o
10 10
11ccflags-y += -D__CHECK_ENDIAN__ 11ccflags-y += -D__CHECK_ENDIAN__
diff --git a/net/wireless/core.c b/net/wireless/core.c
index d1f556535f6d..2006a4ee60eb 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -14,7 +14,6 @@
14#include <linux/device.h> 14#include <linux/device.h>
15#include <net/genetlink.h> 15#include <net/genetlink.h>
16#include <net/cfg80211.h> 16#include <net/cfg80211.h>
17#include <net/wireless.h>
18#include "nl80211.h" 17#include "nl80211.h"
19#include "core.h" 18#include "core.h"
20#include "sysfs.h" 19#include "sysfs.h"
@@ -274,6 +273,16 @@ struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
274 drv->wiphy.dev.class = &ieee80211_class; 273 drv->wiphy.dev.class = &ieee80211_class;
275 drv->wiphy.dev.platform_data = drv; 274 drv->wiphy.dev.platform_data = drv;
276 275
276 /*
277 * Initialize wiphy parameters to IEEE 802.11 MIB default values.
278 * Fragmentation and RTS threshold are disabled by default with the
279 * special -1 value.
280 */
281 drv->wiphy.retry_short = 7;
282 drv->wiphy.retry_long = 4;
283 drv->wiphy.frag_threshold = (u32) -1;
284 drv->wiphy.rts_threshold = (u32) -1;
285
277 return &drv->wiphy; 286 return &drv->wiphy;
278} 287}
279EXPORT_SYMBOL(wiphy_new); 288EXPORT_SYMBOL(wiphy_new);
@@ -450,6 +459,22 @@ static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
450 dev->ieee80211_ptr->netdev = dev; 459 dev->ieee80211_ptr->netdev = dev;
451 mutex_unlock(&rdev->devlist_mtx); 460 mutex_unlock(&rdev->devlist_mtx);
452 break; 461 break;
462 case NETDEV_GOING_DOWN:
463 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
464 break;
465 if (!dev->ieee80211_ptr->ssid_len)
466 break;
467 cfg80211_leave_ibss(rdev, dev, true);
468 break;
469 case NETDEV_UP:
470#ifdef CONFIG_WIRELESS_EXT
471 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
472 break;
473 if (!dev->ieee80211_ptr->wext.ssid_len)
474 break;
475 cfg80211_join_ibss(rdev, dev, &dev->ieee80211_ptr->wext);
476 break;
477#endif
453 case NETDEV_UNREGISTER: 478 case NETDEV_UNREGISTER:
454 mutex_lock(&rdev->devlist_mtx); 479 mutex_lock(&rdev->devlist_mtx);
455 if (!list_empty(&dev->ieee80211_ptr->list)) { 480 if (!list_empty(&dev->ieee80211_ptr->list)) {
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 0a592e4295f0..3e49d3399311 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -10,9 +10,7 @@
10#include <linux/netdevice.h> 10#include <linux/netdevice.h>
11#include <linux/kref.h> 11#include <linux/kref.h>
12#include <linux/rbtree.h> 12#include <linux/rbtree.h>
13#include <linux/mutex.h>
14#include <net/genetlink.h> 13#include <net/genetlink.h>
15#include <net/wireless.h>
16#include <net/cfg80211.h> 14#include <net/cfg80211.h>
17#include "reg.h" 15#include "reg.h"
18 16
@@ -74,10 +72,7 @@ bool wiphy_idx_valid(int wiphy_idx)
74extern struct mutex cfg80211_mutex; 72extern struct mutex cfg80211_mutex;
75extern struct list_head cfg80211_drv_list; 73extern struct list_head cfg80211_drv_list;
76 74
77static inline void assert_cfg80211_lock(void) 75#define assert_cfg80211_lock() WARN_ON(!mutex_is_locked(&cfg80211_mutex))
78{
79 WARN_ON(!mutex_is_locked(&cfg80211_mutex));
80}
81 76
82/* 77/*
83 * You can use this to mark a wiphy_idx as not having an associated wiphy. 78 * You can use this to mark a wiphy_idx as not having an associated wiphy.
@@ -148,4 +143,12 @@ void cfg80211_bss_expire(struct cfg80211_registered_device *dev);
148void cfg80211_bss_age(struct cfg80211_registered_device *dev, 143void cfg80211_bss_age(struct cfg80211_registered_device *dev,
149 unsigned long age_secs); 144 unsigned long age_secs);
150 145
146/* IBSS */
147int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
148 struct net_device *dev,
149 struct cfg80211_ibss_params *params);
150void cfg80211_clear_ibss(struct net_device *dev, bool nowext);
151int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
152 struct net_device *dev, bool nowext);
153
151#endif /* __NET_WIRELESS_CORE_H */ 154#endif /* __NET_WIRELESS_CORE_H */
diff --git a/net/wireless/ibss.c b/net/wireless/ibss.c
new file mode 100644
index 000000000000..3c38afaed28a
--- /dev/null
+++ b/net/wireless/ibss.c
@@ -0,0 +1,369 @@
1/*
2 * Some IBSS support code for cfg80211.
3 *
4 * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
5 */
6
7#include <linux/etherdevice.h>
8#include <linux/if_arp.h>
9#include <net/cfg80211.h>
10#include "nl80211.h"
11
12
13void cfg80211_ibss_joined(struct net_device *dev, const u8 *bssid, gfp_t gfp)
14{
15 struct wireless_dev *wdev = dev->ieee80211_ptr;
16 struct cfg80211_bss *bss;
17#ifdef CONFIG_WIRELESS_EXT
18 union iwreq_data wrqu;
19#endif
20
21 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
22 return;
23
24 if (WARN_ON(!wdev->ssid_len))
25 return;
26
27 if (memcmp(bssid, wdev->bssid, ETH_ALEN) == 0)
28 return;
29
30 bss = cfg80211_get_bss(wdev->wiphy, NULL, bssid,
31 wdev->ssid, wdev->ssid_len,
32 WLAN_CAPABILITY_IBSS, WLAN_CAPABILITY_IBSS);
33
34 if (WARN_ON(!bss))
35 return;
36
37 if (wdev->current_bss) {
38 cfg80211_unhold_bss(wdev->current_bss);
39 cfg80211_put_bss(wdev->current_bss);
40 }
41
42 cfg80211_hold_bss(bss);
43 wdev->current_bss = bss;
44 memcpy(wdev->bssid, bssid, ETH_ALEN);
45
46 nl80211_send_ibss_bssid(wiphy_to_dev(wdev->wiphy), dev, bssid, gfp);
47#ifdef CONFIG_WIRELESS_EXT
48 memset(&wrqu, 0, sizeof(wrqu));
49 memcpy(wrqu.ap_addr.sa_data, bssid, ETH_ALEN);
50 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
51#endif
52}
53EXPORT_SYMBOL(cfg80211_ibss_joined);
54
55int cfg80211_join_ibss(struct cfg80211_registered_device *rdev,
56 struct net_device *dev,
57 struct cfg80211_ibss_params *params)
58{
59 struct wireless_dev *wdev = dev->ieee80211_ptr;
60 int err;
61
62 if (wdev->ssid_len)
63 return -EALREADY;
64
65#ifdef CONFIG_WIRELESS_EXT
66 wdev->wext.channel = params->channel;
67#endif
68 err = rdev->ops->join_ibss(&rdev->wiphy, dev, params);
69
70 if (err)
71 return err;
72
73 memcpy(wdev->ssid, params->ssid, params->ssid_len);
74 wdev->ssid_len = params->ssid_len;
75
76 return 0;
77}
78
79void cfg80211_clear_ibss(struct net_device *dev, bool nowext)
80{
81 struct wireless_dev *wdev = dev->ieee80211_ptr;
82
83 if (wdev->current_bss) {
84 cfg80211_unhold_bss(wdev->current_bss);
85 cfg80211_put_bss(wdev->current_bss);
86 }
87
88 wdev->current_bss = NULL;
89 wdev->ssid_len = 0;
90 memset(wdev->bssid, 0, ETH_ALEN);
91#ifdef CONFIG_WIRELESS_EXT
92 if (!nowext)
93 wdev->wext.ssid_len = 0;
94#endif
95}
96
97int cfg80211_leave_ibss(struct cfg80211_registered_device *rdev,
98 struct net_device *dev, bool nowext)
99{
100 int err;
101
102 err = rdev->ops->leave_ibss(&rdev->wiphy, dev);
103
104 if (err)
105 return err;
106
107 cfg80211_clear_ibss(dev, nowext);
108
109 return 0;
110}
111
112#ifdef CONFIG_WIRELESS_EXT
113static int cfg80211_ibss_wext_join(struct cfg80211_registered_device *rdev,
114 struct wireless_dev *wdev)
115{
116 enum ieee80211_band band;
117 int i;
118
119 if (!wdev->wext.beacon_interval)
120 wdev->wext.beacon_interval = 100;
121
122 /* try to find an IBSS channel if none requested ... */
123 if (!wdev->wext.channel) {
124 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
125 struct ieee80211_supported_band *sband;
126 struct ieee80211_channel *chan;
127
128 sband = rdev->wiphy.bands[band];
129 if (!sband)
130 continue;
131
132 for (i = 0; i < sband->n_channels; i++) {
133 chan = &sband->channels[i];
134 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
135 continue;
136 if (chan->flags & IEEE80211_CHAN_DISABLED)
137 continue;
138 wdev->wext.channel = chan;
139 break;
140 }
141
142 if (wdev->wext.channel)
143 break;
144 }
145
146 if (!wdev->wext.channel)
147 return -EINVAL;
148 }
149
150 /* don't join -- SSID is not there */
151 if (!wdev->wext.ssid_len)
152 return 0;
153
154 if (!netif_running(wdev->netdev))
155 return 0;
156
157 return cfg80211_join_ibss(wiphy_to_dev(wdev->wiphy),
158 wdev->netdev, &wdev->wext);
159}
160
161int cfg80211_ibss_wext_siwfreq(struct net_device *dev,
162 struct iw_request_info *info,
163 struct iw_freq *freq, char *extra)
164{
165 struct wireless_dev *wdev = dev->ieee80211_ptr;
166 struct ieee80211_channel *chan;
167 int err;
168
169 /* call only for ibss! */
170 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
171 return -EINVAL;
172
173 if (!wiphy_to_dev(wdev->wiphy)->ops->join_ibss)
174 return -EOPNOTSUPP;
175
176 chan = cfg80211_wext_freq(wdev->wiphy, freq);
177 if (chan && IS_ERR(chan))
178 return PTR_ERR(chan);
179
180 if (chan &&
181 (chan->flags & IEEE80211_CHAN_NO_IBSS ||
182 chan->flags & IEEE80211_CHAN_DISABLED))
183 return -EINVAL;
184
185 if (wdev->wext.channel == chan)
186 return 0;
187
188 if (wdev->ssid_len) {
189 err = cfg80211_leave_ibss(wiphy_to_dev(wdev->wiphy),
190 dev, true);
191 if (err)
192 return err;
193 }
194
195 if (chan) {
196 wdev->wext.channel = chan;
197 wdev->wext.channel_fixed = true;
198 } else {
199 /* cfg80211_ibss_wext_join will pick one if needed */
200 wdev->wext.channel_fixed = false;
201 }
202
203 return cfg80211_ibss_wext_join(wiphy_to_dev(wdev->wiphy), wdev);
204}
205/* temporary symbol - mark GPL - in the future the handler won't be */
206EXPORT_SYMBOL_GPL(cfg80211_ibss_wext_siwfreq);
207
208int cfg80211_ibss_wext_giwfreq(struct net_device *dev,
209 struct iw_request_info *info,
210 struct iw_freq *freq, char *extra)
211{
212 struct wireless_dev *wdev = dev->ieee80211_ptr;
213 struct ieee80211_channel *chan = NULL;
214
215 /* call only for ibss! */
216 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
217 return -EINVAL;
218
219 if (wdev->current_bss)
220 chan = wdev->current_bss->channel;
221 else if (wdev->wext.channel)
222 chan = wdev->wext.channel;
223
224 if (chan) {
225 freq->m = chan->center_freq;
226 freq->e = 6;
227 return 0;
228 }
229
230 /* no channel if not joining */
231 return -EINVAL;
232}
233/* temporary symbol - mark GPL - in the future the handler won't be */
234EXPORT_SYMBOL_GPL(cfg80211_ibss_wext_giwfreq);
235
236int cfg80211_ibss_wext_siwessid(struct net_device *dev,
237 struct iw_request_info *info,
238 struct iw_point *data, char *ssid)
239{
240 struct wireless_dev *wdev = dev->ieee80211_ptr;
241 size_t len = data->length;
242 int err;
243
244 /* call only for ibss! */
245 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
246 return -EINVAL;
247
248 if (!wiphy_to_dev(wdev->wiphy)->ops->join_ibss)
249 return -EOPNOTSUPP;
250
251 if (wdev->ssid_len) {
252 err = cfg80211_leave_ibss(wiphy_to_dev(wdev->wiphy),
253 dev, true);
254 if (err)
255 return err;
256 }
257
258 /* iwconfig uses nul termination in SSID.. */
259 if (len > 0 && ssid[len - 1] == '\0')
260 len--;
261
262 wdev->wext.ssid = wdev->ssid;
263 memcpy(wdev->wext.ssid, ssid, len);
264 wdev->wext.ssid_len = len;
265
266 return cfg80211_ibss_wext_join(wiphy_to_dev(wdev->wiphy), wdev);
267}
268/* temporary symbol - mark GPL - in the future the handler won't be */
269EXPORT_SYMBOL_GPL(cfg80211_ibss_wext_siwessid);
270
271int cfg80211_ibss_wext_giwessid(struct net_device *dev,
272 struct iw_request_info *info,
273 struct iw_point *data, char *ssid)
274{
275 struct wireless_dev *wdev = dev->ieee80211_ptr;
276
277 /* call only for ibss! */
278 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
279 return -EINVAL;
280
281 data->flags = 0;
282
283 if (wdev->ssid_len) {
284 data->flags = 1;
285 data->length = wdev->ssid_len;
286 memcpy(ssid, wdev->ssid, data->length);
287 } else if (wdev->wext.ssid && wdev->wext.ssid_len) {
288 data->flags = 1;
289 data->length = wdev->wext.ssid_len;
290 memcpy(ssid, wdev->wext.ssid, data->length);
291 }
292
293 return 0;
294}
295/* temporary symbol - mark GPL - in the future the handler won't be */
296EXPORT_SYMBOL_GPL(cfg80211_ibss_wext_giwessid);
297
298int cfg80211_ibss_wext_siwap(struct net_device *dev,
299 struct iw_request_info *info,
300 struct sockaddr *ap_addr, char *extra)
301{
302 struct wireless_dev *wdev = dev->ieee80211_ptr;
303 u8 *bssid = ap_addr->sa_data;
304 int err;
305
306 /* call only for ibss! */
307 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
308 return -EINVAL;
309
310 if (!wiphy_to_dev(wdev->wiphy)->ops->join_ibss)
311 return -EOPNOTSUPP;
312
313 if (ap_addr->sa_family != ARPHRD_ETHER)
314 return -EINVAL;
315
316 /* automatic mode */
317 if (is_zero_ether_addr(bssid) || is_broadcast_ether_addr(bssid))
318 bssid = NULL;
319
320 /* both automatic */
321 if (!bssid && !wdev->wext.bssid)
322 return 0;
323
324 /* fixed already - and no change */
325 if (wdev->wext.bssid && bssid &&
326 compare_ether_addr(bssid, wdev->wext.bssid) == 0)
327 return 0;
328
329 if (wdev->ssid_len) {
330 err = cfg80211_leave_ibss(wiphy_to_dev(wdev->wiphy),
331 dev, true);
332 if (err)
333 return err;
334 }
335
336 if (bssid) {
337 memcpy(wdev->wext_bssid, bssid, ETH_ALEN);
338 wdev->wext.bssid = wdev->wext_bssid;
339 } else
340 wdev->wext.bssid = NULL;
341
342 return cfg80211_ibss_wext_join(wiphy_to_dev(wdev->wiphy), wdev);
343}
344/* temporary symbol - mark GPL - in the future the handler won't be */
345EXPORT_SYMBOL_GPL(cfg80211_ibss_wext_siwap);
346
347int cfg80211_ibss_wext_giwap(struct net_device *dev,
348 struct iw_request_info *info,
349 struct sockaddr *ap_addr, char *extra)
350{
351 struct wireless_dev *wdev = dev->ieee80211_ptr;
352
353 /* call only for ibss! */
354 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_ADHOC))
355 return -EINVAL;
356
357 ap_addr->sa_family = ARPHRD_ETHER;
358
359 if (wdev->wext.bssid) {
360 memcpy(ap_addr->sa_data, wdev->wext.bssid, ETH_ALEN);
361 return 0;
362 }
363
364 memcpy(ap_addr->sa_data, wdev->bssid, ETH_ALEN);
365 return 0;
366}
367/* temporary symbol - mark GPL - in the future the handler won't be */
368EXPORT_SYMBOL_GPL(cfg80211_ibss_wext_giwap);
369#endif
diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c
index bec5721b6f99..42184361a109 100644
--- a/net/wireless/mlme.c
+++ b/net/wireless/mlme.c
@@ -28,19 +28,55 @@ void cfg80211_send_rx_assoc(struct net_device *dev, const u8 *buf, size_t len)
28} 28}
29EXPORT_SYMBOL(cfg80211_send_rx_assoc); 29EXPORT_SYMBOL(cfg80211_send_rx_assoc);
30 30
31void cfg80211_send_rx_deauth(struct net_device *dev, const u8 *buf, size_t len) 31void cfg80211_send_deauth(struct net_device *dev, const u8 *buf, size_t len)
32{ 32{
33 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 33 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
34 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 34 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
35 nl80211_send_rx_deauth(rdev, dev, buf, len); 35 nl80211_send_deauth(rdev, dev, buf, len);
36} 36}
37EXPORT_SYMBOL(cfg80211_send_rx_deauth); 37EXPORT_SYMBOL(cfg80211_send_deauth);
38 38
39void cfg80211_send_rx_disassoc(struct net_device *dev, const u8 *buf, 39void cfg80211_send_disassoc(struct net_device *dev, const u8 *buf, size_t len)
40 size_t len)
41{ 40{
42 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; 41 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
43 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); 42 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
44 nl80211_send_rx_disassoc(rdev, dev, buf, len); 43 nl80211_send_disassoc(rdev, dev, buf, len);
45} 44}
46EXPORT_SYMBOL(cfg80211_send_rx_disassoc); 45EXPORT_SYMBOL(cfg80211_send_disassoc);
46
47static void cfg80211_wext_disconnected(struct net_device *dev)
48{
49#ifdef CONFIG_WIRELESS_EXT
50 union iwreq_data wrqu;
51 memset(&wrqu, 0, sizeof(wrqu));
52 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
53#endif
54}
55
56void cfg80211_send_auth_timeout(struct net_device *dev, const u8 *addr)
57{
58 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
59 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
60 nl80211_send_auth_timeout(rdev, dev, addr);
61 cfg80211_wext_disconnected(dev);
62}
63EXPORT_SYMBOL(cfg80211_send_auth_timeout);
64
65void cfg80211_send_assoc_timeout(struct net_device *dev, const u8 *addr)
66{
67 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
68 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
69 nl80211_send_assoc_timeout(rdev, dev, addr);
70 cfg80211_wext_disconnected(dev);
71}
72EXPORT_SYMBOL(cfg80211_send_assoc_timeout);
73
74void cfg80211_michael_mic_failure(struct net_device *dev, const u8 *addr,
75 enum nl80211_key_type key_type, int key_id,
76 const u8 *tsc)
77{
78 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
79 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
80 nl80211_michael_mic_failure(rdev, dev, addr, key_type, key_id, tsc);
81}
82EXPORT_SYMBOL(cfg80211_michael_mic_failure);
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 2456e4ee445e..b1fc98225fd1 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -61,6 +61,10 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
61 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, 61 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
62 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, 62 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
63 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, 63 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
64 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
65 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
66 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
67 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
64 68
65 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, 69 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
66 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, 70 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
@@ -116,8 +120,40 @@ static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
116 .len = IEEE80211_MAX_SSID_LEN }, 120 .len = IEEE80211_MAX_SSID_LEN },
117 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, 121 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
118 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, 122 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
123 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
124 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
119}; 125};
120 126
127/* IE validation */
128static bool is_valid_ie_attr(const struct nlattr *attr)
129{
130 const u8 *pos;
131 int len;
132
133 if (!attr)
134 return true;
135
136 pos = nla_data(attr);
137 len = nla_len(attr);
138
139 while (len) {
140 u8 elemlen;
141
142 if (len < 2)
143 return false;
144 len -= 2;
145
146 elemlen = pos[1];
147 if (elemlen > len)
148 return false;
149
150 len -= elemlen;
151 pos += 2 + elemlen;
152 }
153
154 return true;
155}
156
121/* message building helper */ 157/* message building helper */
122static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, 158static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
123 int flags, u8 cmd) 159 int flags, u8 cmd)
@@ -126,6 +162,30 @@ static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
126 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); 162 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
127} 163}
128 164
165static int nl80211_msg_put_channel(struct sk_buff *msg,
166 struct ieee80211_channel *chan)
167{
168 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
169 chan->center_freq);
170
171 if (chan->flags & IEEE80211_CHAN_DISABLED)
172 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
173 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
174 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
175 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
176 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
177 if (chan->flags & IEEE80211_CHAN_RADAR)
178 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
179
180 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
181 DBM_TO_MBM(chan->max_power));
182
183 return 0;
184
185 nla_put_failure:
186 return -ENOBUFS;
187}
188
129/* netlink command implementations */ 189/* netlink command implementations */
130 190
131static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, 191static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
@@ -149,8 +209,24 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
149 209
150 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); 210 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
151 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); 211 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
212
213 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
214 dev->wiphy.retry_short);
215 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
216 dev->wiphy.retry_long);
217 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
218 dev->wiphy.frag_threshold);
219 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
220 dev->wiphy.rts_threshold);
221
152 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, 222 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
153 dev->wiphy.max_scan_ssids); 223 dev->wiphy.max_scan_ssids);
224 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
225 dev->wiphy.max_scan_ie_len);
226
227 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
228 sizeof(u32) * dev->wiphy.n_cipher_suites,
229 dev->wiphy.cipher_suites);
154 230
155 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); 231 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES);
156 if (!nl_modes) 232 if (!nl_modes)
@@ -202,20 +278,9 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
202 goto nla_put_failure; 278 goto nla_put_failure;
203 279
204 chan = &dev->wiphy.bands[band]->channels[i]; 280 chan = &dev->wiphy.bands[band]->channels[i];
205 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
206 chan->center_freq);
207
208 if (chan->flags & IEEE80211_CHAN_DISABLED)
209 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
210 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
211 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
212 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
213 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
214 if (chan->flags & IEEE80211_CHAN_RADAR)
215 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
216 281
217 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, 282 if (nl80211_msg_put_channel(msg, chan))
218 DBM_TO_MBM(chan->max_power)); 283 goto nla_put_failure;
219 284
220 nla_nest_end(msg, nl_freq); 285 nla_nest_end(msg, nl_freq);
221 } 286 }
@@ -273,6 +338,7 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
273 CMD(assoc, ASSOCIATE); 338 CMD(assoc, ASSOCIATE);
274 CMD(deauth, DEAUTHENTICATE); 339 CMD(deauth, DEAUTHENTICATE);
275 CMD(disassoc, DISASSOCIATE); 340 CMD(disassoc, DISASSOCIATE);
341 CMD(join_ibss, JOIN_IBSS);
276 342
277#undef CMD 343#undef CMD
278 nla_nest_end(msg, nl_cmds); 344 nla_nest_end(msg, nl_cmds);
@@ -365,6 +431,9 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
365 struct cfg80211_registered_device *rdev; 431 struct cfg80211_registered_device *rdev;
366 int result = 0, rem_txq_params = 0; 432 int result = 0, rem_txq_params = 0;
367 struct nlattr *nl_txq_params; 433 struct nlattr *nl_txq_params;
434 u32 changed;
435 u8 retry_short = 0, retry_long = 0;
436 u32 frag_threshold = 0, rts_threshold = 0;
368 437
369 rtnl_lock(); 438 rtnl_lock();
370 439
@@ -479,6 +548,84 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
479 goto bad_res; 548 goto bad_res;
480 } 549 }
481 550
551 changed = 0;
552
553 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
554 retry_short = nla_get_u8(
555 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
556 if (retry_short == 0) {
557 result = -EINVAL;
558 goto bad_res;
559 }
560 changed |= WIPHY_PARAM_RETRY_SHORT;
561 }
562
563 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
564 retry_long = nla_get_u8(
565 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
566 if (retry_long == 0) {
567 result = -EINVAL;
568 goto bad_res;
569 }
570 changed |= WIPHY_PARAM_RETRY_LONG;
571 }
572
573 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
574 frag_threshold = nla_get_u32(
575 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
576 if (frag_threshold < 256) {
577 result = -EINVAL;
578 goto bad_res;
579 }
580 if (frag_threshold != (u32) -1) {
581 /*
582 * Fragments (apart from the last one) are required to
583 * have even length. Make the fragmentation code
584 * simpler by stripping LSB should someone try to use
585 * odd threshold value.
586 */
587 frag_threshold &= ~0x1;
588 }
589 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
590 }
591
592 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
593 rts_threshold = nla_get_u32(
594 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
595 changed |= WIPHY_PARAM_RTS_THRESHOLD;
596 }
597
598 if (changed) {
599 u8 old_retry_short, old_retry_long;
600 u32 old_frag_threshold, old_rts_threshold;
601
602 if (!rdev->ops->set_wiphy_params) {
603 result = -EOPNOTSUPP;
604 goto bad_res;
605 }
606
607 old_retry_short = rdev->wiphy.retry_short;
608 old_retry_long = rdev->wiphy.retry_long;
609 old_frag_threshold = rdev->wiphy.frag_threshold;
610 old_rts_threshold = rdev->wiphy.rts_threshold;
611
612 if (changed & WIPHY_PARAM_RETRY_SHORT)
613 rdev->wiphy.retry_short = retry_short;
614 if (changed & WIPHY_PARAM_RETRY_LONG)
615 rdev->wiphy.retry_long = retry_long;
616 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
617 rdev->wiphy.frag_threshold = frag_threshold;
618 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
619 rdev->wiphy.rts_threshold = rts_threshold;
620
621 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
622 if (result) {
623 rdev->wiphy.retry_short = old_retry_short;
624 rdev->wiphy.retry_long = old_retry_long;
625 rdev->wiphy.frag_threshold = old_frag_threshold;
626 rdev->wiphy.rts_threshold = old_rts_threshold;
627 }
628 }
482 629
483 bad_res: 630 bad_res:
484 mutex_unlock(&rdev->mtx); 631 mutex_unlock(&rdev->mtx);
@@ -489,6 +636,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
489 636
490 637
491static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, 638static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
639 struct cfg80211_registered_device *rdev,
492 struct net_device *dev) 640 struct net_device *dev)
493{ 641{
494 void *hdr; 642 void *hdr;
@@ -498,6 +646,7 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
498 return -1; 646 return -1;
499 647
500 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); 648 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
649 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
501 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); 650 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
502 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); 651 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
503 return genlmsg_end(msg, hdr); 652 return genlmsg_end(msg, hdr);
@@ -532,7 +681,7 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *
532 } 681 }
533 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, 682 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
534 cb->nlh->nlmsg_seq, NLM_F_MULTI, 683 cb->nlh->nlmsg_seq, NLM_F_MULTI,
535 wdev->netdev) < 0) { 684 dev, wdev->netdev) < 0) {
536 mutex_unlock(&dev->devlist_mtx); 685 mutex_unlock(&dev->devlist_mtx);
537 goto out; 686 goto out;
538 } 687 }
@@ -566,7 +715,8 @@ static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
566 if (!msg) 715 if (!msg)
567 goto out_err; 716 goto out_err;
568 717
569 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, netdev) < 0) 718 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
719 dev, netdev) < 0)
570 goto out_free; 720 goto out_free;
571 721
572 dev_put(netdev); 722 dev_put(netdev);
@@ -616,7 +766,7 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
616 struct cfg80211_registered_device *drv; 766 struct cfg80211_registered_device *drv;
617 struct vif_params params; 767 struct vif_params params;
618 int err, ifindex; 768 int err, ifindex;
619 enum nl80211_iftype type; 769 enum nl80211_iftype otype, ntype;
620 struct net_device *dev; 770 struct net_device *dev;
621 u32 _flags, *flags = NULL; 771 u32 _flags, *flags = NULL;
622 bool change = false; 772 bool change = false;
@@ -630,30 +780,27 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
630 goto unlock_rtnl; 780 goto unlock_rtnl;
631 781
632 ifindex = dev->ifindex; 782 ifindex = dev->ifindex;
633 type = dev->ieee80211_ptr->iftype; 783 otype = ntype = dev->ieee80211_ptr->iftype;
634 dev_put(dev); 784 dev_put(dev);
635 785
636 if (info->attrs[NL80211_ATTR_IFTYPE]) { 786 if (info->attrs[NL80211_ATTR_IFTYPE]) {
637 enum nl80211_iftype ntype;
638
639 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); 787 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
640 if (type != ntype) 788 if (otype != ntype)
641 change = true; 789 change = true;
642 type = ntype; 790 if (ntype > NL80211_IFTYPE_MAX) {
643 if (type > NL80211_IFTYPE_MAX) {
644 err = -EINVAL; 791 err = -EINVAL;
645 goto unlock; 792 goto unlock;
646 } 793 }
647 } 794 }
648 795
649 if (!drv->ops->change_virtual_intf || 796 if (!drv->ops->change_virtual_intf ||
650 !(drv->wiphy.interface_modes & (1 << type))) { 797 !(drv->wiphy.interface_modes & (1 << ntype))) {
651 err = -EOPNOTSUPP; 798 err = -EOPNOTSUPP;
652 goto unlock; 799 goto unlock;
653 } 800 }
654 801
655 if (info->attrs[NL80211_ATTR_MESH_ID]) { 802 if (info->attrs[NL80211_ATTR_MESH_ID]) {
656 if (type != NL80211_IFTYPE_MESH_POINT) { 803 if (ntype != NL80211_IFTYPE_MESH_POINT) {
657 err = -EINVAL; 804 err = -EINVAL;
658 goto unlock; 805 goto unlock;
659 } 806 }
@@ -663,7 +810,7 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
663 } 810 }
664 811
665 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { 812 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
666 if (type != NL80211_IFTYPE_MONITOR) { 813 if (ntype != NL80211_IFTYPE_MONITOR) {
667 err = -EINVAL; 814 err = -EINVAL;
668 goto unlock; 815 goto unlock;
669 } 816 }
@@ -678,12 +825,17 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
678 825
679 if (change) 826 if (change)
680 err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex, 827 err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex,
681 type, flags, &params); 828 ntype, flags, &params);
682 else 829 else
683 err = 0; 830 err = 0;
684 831
685 dev = __dev_get_by_index(&init_net, ifindex); 832 dev = __dev_get_by_index(&init_net, ifindex);
686 WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != type)); 833 WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != ntype));
834
835 if (dev && !err && (ntype != otype)) {
836 if (otype == NL80211_IFTYPE_ADHOC)
837 cfg80211_clear_ibss(dev, false);
838 }
687 839
688 unlock: 840 unlock:
689 cfg80211_put_dev(drv); 841 cfg80211_put_dev(drv);
@@ -934,7 +1086,7 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
934static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) 1086static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
935{ 1087{
936 struct cfg80211_registered_device *drv; 1088 struct cfg80211_registered_device *drv;
937 int err; 1089 int err, i;
938 struct net_device *dev; 1090 struct net_device *dev;
939 struct key_params params; 1091 struct key_params params;
940 u8 key_idx = 0; 1092 u8 key_idx = 0;
@@ -1003,6 +1155,14 @@ static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1003 if (err) 1155 if (err)
1004 goto unlock_rtnl; 1156 goto unlock_rtnl;
1005 1157
1158 for (i = 0; i < drv->wiphy.n_cipher_suites; i++)
1159 if (params.cipher == drv->wiphy.cipher_suites[i])
1160 break;
1161 if (i == drv->wiphy.n_cipher_suites) {
1162 err = -EINVAL;
1163 goto out;
1164 }
1165
1006 if (!drv->ops->add_key) { 1166 if (!drv->ops->add_key) {
1007 err = -EOPNOTSUPP; 1167 err = -EOPNOTSUPP;
1008 goto out; 1168 goto out;
@@ -1069,6 +1229,9 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1069 struct beacon_parameters params; 1229 struct beacon_parameters params;
1070 int haveinfo = 0; 1230 int haveinfo = 0;
1071 1231
1232 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]))
1233 return -EINVAL;
1234
1072 rtnl_lock(); 1235 rtnl_lock();
1073 1236
1074 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 1237 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
@@ -2442,6 +2605,9 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2442 enum ieee80211_band band; 2605 enum ieee80211_band band;
2443 size_t ie_len; 2606 size_t ie_len;
2444 2607
2608 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2609 return -EINVAL;
2610
2445 rtnl_lock(); 2611 rtnl_lock();
2446 2612
2447 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 2613 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
@@ -2492,6 +2658,11 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2492 else 2658 else
2493 ie_len = 0; 2659 ie_len = 0;
2494 2660
2661 if (ie_len > wiphy->max_scan_ie_len) {
2662 err = -EINVAL;
2663 goto out;
2664 }
2665
2495 request = kzalloc(sizeof(*request) 2666 request = kzalloc(sizeof(*request)
2496 + sizeof(*ssid) * n_ssids 2667 + sizeof(*ssid) * n_ssids
2497 + sizeof(channel) * n_channels 2668 + sizeof(channel) * n_channels
@@ -2554,7 +2725,8 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2554 2725
2555 if (info->attrs[NL80211_ATTR_IE]) { 2726 if (info->attrs[NL80211_ATTR_IE]) {
2556 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 2727 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2557 memcpy(request->ie, nla_data(info->attrs[NL80211_ATTR_IE]), 2728 memcpy((void *)request->ie,
2729 nla_data(info->attrs[NL80211_ATTR_IE]),
2558 request->ie_len); 2730 request->ie_len);
2559 } 2731 }
2560 2732
@@ -2710,6 +2882,15 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
2710 struct wiphy *wiphy; 2882 struct wiphy *wiphy;
2711 int err; 2883 int err;
2712 2884
2885 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2886 return -EINVAL;
2887
2888 if (!info->attrs[NL80211_ATTR_MAC])
2889 return -EINVAL;
2890
2891 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
2892 return -EINVAL;
2893
2713 rtnl_lock(); 2894 rtnl_lock();
2714 2895
2715 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 2896 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
@@ -2731,11 +2912,6 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
2731 goto out; 2912 goto out;
2732 } 2913 }
2733 2914
2734 if (!info->attrs[NL80211_ATTR_MAC]) {
2735 err = -EINVAL;
2736 goto out;
2737 }
2738
2739 wiphy = &drv->wiphy; 2915 wiphy = &drv->wiphy;
2740 memset(&req, 0, sizeof(req)); 2916 memset(&req, 0, sizeof(req));
2741 2917
@@ -2761,13 +2937,10 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
2761 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); 2937 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2762 } 2938 }
2763 2939
2764 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { 2940 req.auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
2765 req.auth_type = 2941 if (!nl80211_valid_auth_type(req.auth_type)) {
2766 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); 2942 err = -EINVAL;
2767 if (!nl80211_valid_auth_type(req.auth_type)) { 2943 goto out;
2768 err = -EINVAL;
2769 goto out;
2770 }
2771 } 2944 }
2772 2945
2773 err = drv->ops->auth(&drv->wiphy, dev, &req); 2946 err = drv->ops->auth(&drv->wiphy, dev, &req);
@@ -2788,6 +2961,13 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
2788 struct wiphy *wiphy; 2961 struct wiphy *wiphy;
2789 int err; 2962 int err;
2790 2963
2964 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2965 return -EINVAL;
2966
2967 if (!info->attrs[NL80211_ATTR_MAC] ||
2968 !info->attrs[NL80211_ATTR_SSID])
2969 return -EINVAL;
2970
2791 rtnl_lock(); 2971 rtnl_lock();
2792 2972
2793 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 2973 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
@@ -2809,12 +2989,6 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
2809 goto out; 2989 goto out;
2810 } 2990 }
2811 2991
2812 if (!info->attrs[NL80211_ATTR_MAC] ||
2813 !info->attrs[NL80211_ATTR_SSID]) {
2814 err = -EINVAL;
2815 goto out;
2816 }
2817
2818 wiphy = &drv->wiphy; 2992 wiphy = &drv->wiphy;
2819 memset(&req, 0, sizeof(req)); 2993 memset(&req, 0, sizeof(req));
2820 2994
@@ -2856,6 +3030,15 @@ static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
2856 struct wiphy *wiphy; 3030 struct wiphy *wiphy;
2857 int err; 3031 int err;
2858 3032
3033 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3034 return -EINVAL;
3035
3036 if (!info->attrs[NL80211_ATTR_MAC])
3037 return -EINVAL;
3038
3039 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3040 return -EINVAL;
3041
2859 rtnl_lock(); 3042 rtnl_lock();
2860 3043
2861 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 3044 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
@@ -2877,24 +3060,16 @@ static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
2877 goto out; 3060 goto out;
2878 } 3061 }
2879 3062
2880 if (!info->attrs[NL80211_ATTR_MAC]) {
2881 err = -EINVAL;
2882 goto out;
2883 }
2884
2885 wiphy = &drv->wiphy; 3063 wiphy = &drv->wiphy;
2886 memset(&req, 0, sizeof(req)); 3064 memset(&req, 0, sizeof(req));
2887 3065
2888 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 3066 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2889 3067
2890 if (info->attrs[NL80211_ATTR_REASON_CODE]) { 3068 req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
2891 req.reason_code = 3069 if (req.reason_code == 0) {
2892 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 3070 /* Reason Code 0 is reserved */
2893 if (req.reason_code == 0) { 3071 err = -EINVAL;
2894 /* Reason Code 0 is reserved */ 3072 goto out;
2895 err = -EINVAL;
2896 goto out;
2897 }
2898 } 3073 }
2899 3074
2900 if (info->attrs[NL80211_ATTR_IE]) { 3075 if (info->attrs[NL80211_ATTR_IE]) {
@@ -2920,6 +3095,15 @@ static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
2920 struct wiphy *wiphy; 3095 struct wiphy *wiphy;
2921 int err; 3096 int err;
2922 3097
3098 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3099 return -EINVAL;
3100
3101 if (!info->attrs[NL80211_ATTR_MAC])
3102 return -EINVAL;
3103
3104 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3105 return -EINVAL;
3106
2923 rtnl_lock(); 3107 rtnl_lock();
2924 3108
2925 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); 3109 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
@@ -2941,24 +3125,16 @@ static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
2941 goto out; 3125 goto out;
2942 } 3126 }
2943 3127
2944 if (!info->attrs[NL80211_ATTR_MAC]) {
2945 err = -EINVAL;
2946 goto out;
2947 }
2948
2949 wiphy = &drv->wiphy; 3128 wiphy = &drv->wiphy;
2950 memset(&req, 0, sizeof(req)); 3129 memset(&req, 0, sizeof(req));
2951 3130
2952 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); 3131 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2953 3132
2954 if (info->attrs[NL80211_ATTR_REASON_CODE]) { 3133 req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
2955 req.reason_code = 3134 if (req.reason_code == 0) {
2956 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); 3135 /* Reason Code 0 is reserved */
2957 if (req.reason_code == 0) { 3136 err = -EINVAL;
2958 /* Reason Code 0 is reserved */ 3137 goto out;
2959 err = -EINVAL;
2960 goto out;
2961 }
2962 } 3138 }
2963 3139
2964 if (info->attrs[NL80211_ATTR_IE]) { 3140 if (info->attrs[NL80211_ATTR_IE]) {
@@ -2976,6 +3152,124 @@ unlock_rtnl:
2976 return err; 3152 return err;
2977} 3153}
2978 3154
3155static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
3156{
3157 struct cfg80211_registered_device *drv;
3158 struct net_device *dev;
3159 struct cfg80211_ibss_params ibss;
3160 struct wiphy *wiphy;
3161 int err;
3162
3163 memset(&ibss, 0, sizeof(ibss));
3164
3165 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3166 return -EINVAL;
3167
3168 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
3169 !info->attrs[NL80211_ATTR_SSID] ||
3170 !nla_len(info->attrs[NL80211_ATTR_SSID]))
3171 return -EINVAL;
3172
3173 ibss.beacon_interval = 100;
3174
3175 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
3176 ibss.beacon_interval =
3177 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3178 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
3179 return -EINVAL;
3180 }
3181
3182 rtnl_lock();
3183
3184 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
3185 if (err)
3186 goto unlock_rtnl;
3187
3188 if (!drv->ops->join_ibss) {
3189 err = -EOPNOTSUPP;
3190 goto out;
3191 }
3192
3193 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) {
3194 err = -EOPNOTSUPP;
3195 goto out;
3196 }
3197
3198 if (!netif_running(dev)) {
3199 err = -ENETDOWN;
3200 goto out;
3201 }
3202
3203 wiphy = &drv->wiphy;
3204
3205 if (info->attrs[NL80211_ATTR_MAC])
3206 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3207 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3208 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3209
3210 if (info->attrs[NL80211_ATTR_IE]) {
3211 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3212 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3213 }
3214
3215 ibss.channel = ieee80211_get_channel(wiphy,
3216 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3217 if (!ibss.channel ||
3218 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
3219 ibss.channel->flags & IEEE80211_CHAN_DISABLED) {
3220 err = -EINVAL;
3221 goto out;
3222 }
3223
3224 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
3225
3226 err = cfg80211_join_ibss(drv, dev, &ibss);
3227
3228out:
3229 cfg80211_put_dev(drv);
3230 dev_put(dev);
3231unlock_rtnl:
3232 rtnl_unlock();
3233 return err;
3234}
3235
3236static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
3237{
3238 struct cfg80211_registered_device *drv;
3239 struct net_device *dev;
3240 int err;
3241
3242 rtnl_lock();
3243
3244 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
3245 if (err)
3246 goto unlock_rtnl;
3247
3248 if (!drv->ops->leave_ibss) {
3249 err = -EOPNOTSUPP;
3250 goto out;
3251 }
3252
3253 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) {
3254 err = -EOPNOTSUPP;
3255 goto out;
3256 }
3257
3258 if (!netif_running(dev)) {
3259 err = -ENETDOWN;
3260 goto out;
3261 }
3262
3263 err = cfg80211_leave_ibss(drv, dev, false);
3264
3265out:
3266 cfg80211_put_dev(drv);
3267 dev_put(dev);
3268unlock_rtnl:
3269 rtnl_unlock();
3270 return err;
3271}
3272
2979static struct genl_ops nl80211_ops[] = { 3273static struct genl_ops nl80211_ops[] = {
2980 { 3274 {
2981 .cmd = NL80211_CMD_GET_WIPHY, 3275 .cmd = NL80211_CMD_GET_WIPHY,
@@ -3177,6 +3471,18 @@ static struct genl_ops nl80211_ops[] = {
3177 .policy = nl80211_policy, 3471 .policy = nl80211_policy,
3178 .flags = GENL_ADMIN_PERM, 3472 .flags = GENL_ADMIN_PERM,
3179 }, 3473 },
3474 {
3475 .cmd = NL80211_CMD_JOIN_IBSS,
3476 .doit = nl80211_join_ibss,
3477 .policy = nl80211_policy,
3478 .flags = GENL_ADMIN_PERM,
3479 },
3480 {
3481 .cmd = NL80211_CMD_LEAVE_IBSS,
3482 .doit = nl80211_leave_ibss,
3483 .policy = nl80211_policy,
3484 .flags = GENL_ADMIN_PERM,
3485 },
3180}; 3486};
3181static struct genl_multicast_group nl80211_mlme_mcgrp = { 3487static struct genl_multicast_group nl80211_mlme_mcgrp = {
3182 .name = "mlme", 3488 .name = "mlme",
@@ -3375,22 +3681,197 @@ void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
3375 nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE); 3681 nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE);
3376} 3682}
3377 3683
3378void nl80211_send_rx_deauth(struct cfg80211_registered_device *rdev, 3684void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
3379 struct net_device *netdev, const u8 *buf, 3685 struct net_device *netdev, const u8 *buf, size_t len)
3380 size_t len)
3381{ 3686{
3382 nl80211_send_mlme_event(rdev, netdev, buf, len, 3687 nl80211_send_mlme_event(rdev, netdev, buf, len,
3383 NL80211_CMD_DEAUTHENTICATE); 3688 NL80211_CMD_DEAUTHENTICATE);
3384} 3689}
3385 3690
3386void nl80211_send_rx_disassoc(struct cfg80211_registered_device *rdev, 3691void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
3387 struct net_device *netdev, const u8 *buf, 3692 struct net_device *netdev, const u8 *buf,
3388 size_t len) 3693 size_t len)
3389{ 3694{
3390 nl80211_send_mlme_event(rdev, netdev, buf, len, 3695 nl80211_send_mlme_event(rdev, netdev, buf, len,
3391 NL80211_CMD_DISASSOCIATE); 3696 NL80211_CMD_DISASSOCIATE);
3392} 3697}
3393 3698
3699void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
3700 struct net_device *netdev, int cmd,
3701 const u8 *addr)
3702{
3703 struct sk_buff *msg;
3704 void *hdr;
3705
3706 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
3707 if (!msg)
3708 return;
3709
3710 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
3711 if (!hdr) {
3712 nlmsg_free(msg);
3713 return;
3714 }
3715
3716 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3717 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3718 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
3719 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
3720
3721 if (genlmsg_end(msg, hdr) < 0) {
3722 nlmsg_free(msg);
3723 return;
3724 }
3725
3726 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC);
3727 return;
3728
3729 nla_put_failure:
3730 genlmsg_cancel(msg, hdr);
3731 nlmsg_free(msg);
3732}
3733
3734void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
3735 struct net_device *netdev, const u8 *addr)
3736{
3737 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
3738 addr);
3739}
3740
3741void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
3742 struct net_device *netdev, const u8 *addr)
3743{
3744 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, addr);
3745}
3746
3747void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
3748 struct net_device *netdev, const u8 *bssid,
3749 gfp_t gfp)
3750{
3751 struct sk_buff *msg;
3752 void *hdr;
3753
3754 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
3755 if (!msg)
3756 return;
3757
3758 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
3759 if (!hdr) {
3760 nlmsg_free(msg);
3761 return;
3762 }
3763
3764 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3765 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3766 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
3767
3768 if (genlmsg_end(msg, hdr) < 0) {
3769 nlmsg_free(msg);
3770 return;
3771 }
3772
3773 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
3774 return;
3775
3776 nla_put_failure:
3777 genlmsg_cancel(msg, hdr);
3778 nlmsg_free(msg);
3779}
3780
3781void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
3782 struct net_device *netdev, const u8 *addr,
3783 enum nl80211_key_type key_type, int key_id,
3784 const u8 *tsc)
3785{
3786 struct sk_buff *msg;
3787 void *hdr;
3788
3789 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3790 if (!msg)
3791 return;
3792
3793 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
3794 if (!hdr) {
3795 nlmsg_free(msg);
3796 return;
3797 }
3798
3799 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3800 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3801 if (addr)
3802 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
3803 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
3804 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
3805 if (tsc)
3806 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
3807
3808 if (genlmsg_end(msg, hdr) < 0) {
3809 nlmsg_free(msg);
3810 return;
3811 }
3812
3813 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL);
3814 return;
3815
3816 nla_put_failure:
3817 genlmsg_cancel(msg, hdr);
3818 nlmsg_free(msg);
3819}
3820
3821void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
3822 struct ieee80211_channel *channel_before,
3823 struct ieee80211_channel *channel_after)
3824{
3825 struct sk_buff *msg;
3826 void *hdr;
3827 struct nlattr *nl_freq;
3828
3829 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
3830 if (!msg)
3831 return;
3832
3833 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
3834 if (!hdr) {
3835 nlmsg_free(msg);
3836 return;
3837 }
3838
3839 /*
3840 * Since we are applying the beacon hint to a wiphy we know its
3841 * wiphy_idx is valid
3842 */
3843 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
3844
3845 /* Before */
3846 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
3847 if (!nl_freq)
3848 goto nla_put_failure;
3849 if (nl80211_msg_put_channel(msg, channel_before))
3850 goto nla_put_failure;
3851 nla_nest_end(msg, nl_freq);
3852
3853 /* After */
3854 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
3855 if (!nl_freq)
3856 goto nla_put_failure;
3857 if (nl80211_msg_put_channel(msg, channel_after))
3858 goto nla_put_failure;
3859 nla_nest_end(msg, nl_freq);
3860
3861 if (genlmsg_end(msg, hdr) < 0) {
3862 nlmsg_free(msg);
3863 return;
3864 }
3865
3866 genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_ATOMIC);
3867
3868 return;
3869
3870nla_put_failure:
3871 genlmsg_cancel(msg, hdr);
3872 nlmsg_free(msg);
3873}
3874
3394/* initialisation/exit functions */ 3875/* initialisation/exit functions */
3395 3876
3396int nl80211_init(void) 3877int nl80211_init(void)
diff --git a/net/wireless/nl80211.h b/net/wireless/nl80211.h
index b77af4ab80be..5c12ad13499b 100644
--- a/net/wireless/nl80211.h
+++ b/net/wireless/nl80211.h
@@ -17,11 +17,31 @@ extern void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
17extern void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, 17extern void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
18 struct net_device *netdev, 18 struct net_device *netdev,
19 const u8 *buf, size_t len); 19 const u8 *buf, size_t len);
20extern void nl80211_send_rx_deauth(struct cfg80211_registered_device *rdev, 20extern void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
21 struct net_device *netdev, 21 struct net_device *netdev,
22 const u8 *buf, size_t len); 22 const u8 *buf, size_t len);
23extern void nl80211_send_rx_disassoc(struct cfg80211_registered_device *rdev, 23extern void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
24 struct net_device *netdev, 24 struct net_device *netdev,
25 const u8 *buf, size_t len); 25 const u8 *buf, size_t len);
26extern void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
27 struct net_device *netdev,
28 const u8 *addr);
29extern void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
30 struct net_device *netdev,
31 const u8 *addr);
32extern void
33nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
34 struct net_device *netdev, const u8 *addr,
35 enum nl80211_key_type key_type,
36 int key_id, const u8 *tsc);
37
38extern void
39nl80211_send_beacon_hint_event(struct wiphy *wiphy,
40 struct ieee80211_channel *channel_before,
41 struct ieee80211_channel *channel_after);
42
43void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
44 struct net_device *netdev, const u8 *bssid,
45 gfp_t gfp);
26 46
27#endif /* __NET_WIRELESS_NL80211_H */ 47#endif /* __NET_WIRELESS_NL80211_H */
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 6c1993d99902..f38cc39fa79e 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -37,7 +37,6 @@
37#include <linux/random.h> 37#include <linux/random.h>
38#include <linux/nl80211.h> 38#include <linux/nl80211.h>
39#include <linux/platform_device.h> 39#include <linux/platform_device.h>
40#include <net/wireless.h>
41#include <net/cfg80211.h> 40#include <net/cfg80211.h>
42#include "core.h" 41#include "core.h"
43#include "reg.h" 42#include "reg.h"
@@ -1049,18 +1048,10 @@ static void handle_reg_beacon(struct wiphy *wiphy,
1049 unsigned int chan_idx, 1048 unsigned int chan_idx,
1050 struct reg_beacon *reg_beacon) 1049 struct reg_beacon *reg_beacon)
1051{ 1050{
1052#ifdef CONFIG_CFG80211_REG_DEBUG
1053#define REG_DEBUG_BEACON_FLAG(desc) \
1054 printk(KERN_DEBUG "cfg80211: Enabling " desc " on " \
1055 "frequency: %d MHz (Ch %d) on %s\n", \
1056 reg_beacon->chan.center_freq, \
1057 ieee80211_frequency_to_channel(reg_beacon->chan.center_freq), \
1058 wiphy_name(wiphy));
1059#else
1060#define REG_DEBUG_BEACON_FLAG(desc) do {} while (0)
1061#endif
1062 struct ieee80211_supported_band *sband; 1051 struct ieee80211_supported_band *sband;
1063 struct ieee80211_channel *chan; 1052 struct ieee80211_channel *chan;
1053 bool channel_changed = false;
1054 struct ieee80211_channel chan_before;
1064 1055
1065 assert_cfg80211_lock(); 1056 assert_cfg80211_lock();
1066 1057
@@ -1070,18 +1061,28 @@ static void handle_reg_beacon(struct wiphy *wiphy,
1070 if (likely(chan->center_freq != reg_beacon->chan.center_freq)) 1061 if (likely(chan->center_freq != reg_beacon->chan.center_freq))
1071 return; 1062 return;
1072 1063
1073 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) { 1064 if (chan->beacon_found)
1065 return;
1066
1067 chan->beacon_found = true;
1068
1069 chan_before.center_freq = chan->center_freq;
1070 chan_before.flags = chan->flags;
1071
1072 if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
1073 !(chan->orig_flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
1074 chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN; 1074 chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
1075 REG_DEBUG_BEACON_FLAG("active scanning"); 1075 channel_changed = true;
1076 } 1076 }
1077 1077
1078 if (chan->flags & IEEE80211_CHAN_NO_IBSS) { 1078 if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
1079 !(chan->orig_flags & IEEE80211_CHAN_NO_IBSS)) {
1079 chan->flags &= ~IEEE80211_CHAN_NO_IBSS; 1080 chan->flags &= ~IEEE80211_CHAN_NO_IBSS;
1080 REG_DEBUG_BEACON_FLAG("beaconing"); 1081 channel_changed = true;
1081 } 1082 }
1082 1083
1083 chan->beacon_found = true; 1084 if (channel_changed)
1084#undef REG_DEBUG_BEACON_FLAG 1085 nl80211_send_beacon_hint_event(wiphy, &chan_before, chan);
1085} 1086}
1086 1087
1087/* 1088/*
diff --git a/net/wireless/scan.c b/net/wireless/scan.c
index 2ae65b39b529..723aeb3d9462 100644
--- a/net/wireless/scan.c
+++ b/net/wireless/scan.c
@@ -414,6 +414,55 @@ cfg80211_bss_update(struct cfg80211_registered_device *dev,
414 return found; 414 return found;
415} 415}
416 416
417struct cfg80211_bss*
418cfg80211_inform_bss(struct wiphy *wiphy,
419 struct ieee80211_channel *channel,
420 const u8 *bssid,
421 u64 timestamp, u16 capability, u16 beacon_interval,
422 const u8 *ie, size_t ielen,
423 s32 signal, gfp_t gfp)
424{
425 struct cfg80211_internal_bss *res;
426 size_t privsz;
427
428 if (WARN_ON(!wiphy))
429 return NULL;
430
431 privsz = wiphy->bss_priv_size;
432
433 if (WARN_ON(wiphy->signal_type == NL80211_BSS_SIGNAL_UNSPEC &&
434 (signal < 0 || signal > 100)))
435 return NULL;
436
437 res = kzalloc(sizeof(*res) + privsz + ielen, gfp);
438 if (!res)
439 return NULL;
440
441 memcpy(res->pub.bssid, bssid, ETH_ALEN);
442 res->pub.channel = channel;
443 res->pub.signal = signal;
444 res->pub.tsf = timestamp;
445 res->pub.beacon_interval = beacon_interval;
446 res->pub.capability = capability;
447 /* point to after the private area */
448 res->pub.information_elements = (u8 *)res + sizeof(*res) + privsz;
449 memcpy(res->pub.information_elements, ie, ielen);
450 res->pub.len_information_elements = ielen;
451
452 kref_init(&res->ref);
453
454 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res, 0);
455 if (!res)
456 return NULL;
457
458 if (res->pub.capability & WLAN_CAPABILITY_ESS)
459 regulatory_hint_found_beacon(wiphy, channel, gfp);
460
461 /* cfg80211_bss_update gives us a referenced result */
462 return &res->pub;
463}
464EXPORT_SYMBOL(cfg80211_inform_bss);
465
417struct cfg80211_bss * 466struct cfg80211_bss *
418cfg80211_inform_bss_frame(struct wiphy *wiphy, 467cfg80211_inform_bss_frame(struct wiphy *wiphy,
419 struct ieee80211_channel *channel, 468 struct ieee80211_channel *channel,
@@ -604,7 +653,7 @@ int cfg80211_wext_siwscan(struct net_device *dev,
604 cfg80211_put_dev(rdev); 653 cfg80211_put_dev(rdev);
605 return err; 654 return err;
606} 655}
607EXPORT_SYMBOL(cfg80211_wext_siwscan); 656EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan);
608 657
609static void ieee80211_scan_add_ies(struct iw_request_info *info, 658static void ieee80211_scan_add_ies(struct iw_request_info *info,
610 struct cfg80211_bss *bss, 659 struct cfg80211_bss *bss,
@@ -913,5 +962,5 @@ int cfg80211_wext_giwscan(struct net_device *dev,
913 cfg80211_put_dev(rdev); 962 cfg80211_put_dev(rdev);
914 return res; 963 return res;
915} 964}
916EXPORT_SYMBOL(cfg80211_wext_giwscan); 965EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan);
917#endif 966#endif
diff --git a/net/wireless/util.c b/net/wireless/util.c
index 487cdd9bcffc..5f7e997195c7 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * Wireless utility functions 2 * Wireless utility functions
3 * 3 *
4 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> 4 * Copyright 2007-2009 Johannes Berg <johannes@sipsolutions.net>
5 */ 5 */
6#include <net/wireless.h> 6#include <linux/bitops.h>
7#include <asm/bitops.h> 7#include <net/cfg80211.h>
8#include "core.h" 8#include "core.h"
9 9
10struct ieee80211_rate * 10struct ieee80211_rate *
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
index 0fd1db6e95bb..5ef82f2ca88f 100644
--- a/net/wireless/wext-compat.c
+++ b/net/wireless/wext-compat.c
@@ -10,8 +10,8 @@
10 10
11#include <linux/wireless.h> 11#include <linux/wireless.h>
12#include <linux/nl80211.h> 12#include <linux/nl80211.h>
13#include <linux/if_arp.h>
13#include <net/iw_handler.h> 14#include <net/iw_handler.h>
14#include <net/wireless.h>
15#include <net/cfg80211.h> 15#include <net/cfg80211.h>
16#include "core.h" 16#include "core.h"
17 17
@@ -57,7 +57,7 @@ int cfg80211_wext_giwname(struct net_device *dev,
57 57
58 return 0; 58 return 0;
59} 59}
60EXPORT_SYMBOL(cfg80211_wext_giwname); 60EXPORT_SYMBOL_GPL(cfg80211_wext_giwname);
61 61
62int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info, 62int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
63 u32 *mode, char *extra) 63 u32 *mode, char *extra)
@@ -108,7 +108,7 @@ int cfg80211_wext_siwmode(struct net_device *dev, struct iw_request_info *info,
108 108
109 return ret; 109 return ret;
110} 110}
111EXPORT_SYMBOL(cfg80211_wext_siwmode); 111EXPORT_SYMBOL_GPL(cfg80211_wext_siwmode);
112 112
113int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info, 113int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
114 u32 *mode, char *extra) 114 u32 *mode, char *extra)
@@ -143,7 +143,7 @@ int cfg80211_wext_giwmode(struct net_device *dev, struct iw_request_info *info,
143 } 143 }
144 return 0; 144 return 0;
145} 145}
146EXPORT_SYMBOL(cfg80211_wext_giwmode); 146EXPORT_SYMBOL_GPL(cfg80211_wext_giwmode);
147 147
148 148
149int cfg80211_wext_giwrange(struct net_device *dev, 149int cfg80211_wext_giwrange(struct net_device *dev,
@@ -206,7 +206,6 @@ int cfg80211_wext_giwrange(struct net_device *dev,
206 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | 206 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
207 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; 207 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
208 208
209
210 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) { 209 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
211 int i; 210 int i;
212 struct ieee80211_supported_band *sband; 211 struct ieee80211_supported_band *sband;
@@ -240,4 +239,229 @@ int cfg80211_wext_giwrange(struct net_device *dev,
240 239
241 return 0; 240 return 0;
242} 241}
243EXPORT_SYMBOL(cfg80211_wext_giwrange); 242EXPORT_SYMBOL_GPL(cfg80211_wext_giwrange);
243
244int cfg80211_wext_siwmlme(struct net_device *dev,
245 struct iw_request_info *info,
246 struct iw_point *data, char *extra)
247{
248 struct wireless_dev *wdev = dev->ieee80211_ptr;
249 struct iw_mlme *mlme = (struct iw_mlme *)extra;
250 struct cfg80211_registered_device *rdev;
251 union {
252 struct cfg80211_disassoc_request disassoc;
253 struct cfg80211_deauth_request deauth;
254 } cmd;
255
256 if (!wdev)
257 return -EOPNOTSUPP;
258
259 rdev = wiphy_to_dev(wdev->wiphy);
260
261 if (wdev->iftype != NL80211_IFTYPE_STATION)
262 return -EINVAL;
263
264 if (mlme->addr.sa_family != ARPHRD_ETHER)
265 return -EINVAL;
266
267 memset(&cmd, 0, sizeof(cmd));
268
269 switch (mlme->cmd) {
270 case IW_MLME_DEAUTH:
271 if (!rdev->ops->deauth)
272 return -EOPNOTSUPP;
273 cmd.deauth.peer_addr = mlme->addr.sa_data;
274 cmd.deauth.reason_code = mlme->reason_code;
275 return rdev->ops->deauth(wdev->wiphy, dev, &cmd.deauth);
276 case IW_MLME_DISASSOC:
277 if (!rdev->ops->disassoc)
278 return -EOPNOTSUPP;
279 cmd.disassoc.peer_addr = mlme->addr.sa_data;
280 cmd.disassoc.reason_code = mlme->reason_code;
281 return rdev->ops->disassoc(wdev->wiphy, dev, &cmd.disassoc);
282 default:
283 return -EOPNOTSUPP;
284 }
285}
286EXPORT_SYMBOL_GPL(cfg80211_wext_siwmlme);
287
288
289/**
290 * cfg80211_wext_freq - get wext frequency for non-"auto"
291 * @wiphy: the wiphy
292 * @freq: the wext freq encoding
293 *
294 * Returns a channel, %NULL for auto, or an ERR_PTR for errors!
295 */
296struct ieee80211_channel *cfg80211_wext_freq(struct wiphy *wiphy,
297 struct iw_freq *freq)
298{
299 if (freq->e == 0) {
300 if (freq->m < 0)
301 return NULL;
302 else
303 return ieee80211_get_channel(wiphy,
304 ieee80211_channel_to_frequency(freq->m));
305 } else {
306 int i, div = 1000000;
307 for (i = 0; i < freq->e; i++)
308 div /= 10;
309 if (div > 0)
310 return ieee80211_get_channel(wiphy, freq->m / div);
311 else
312 return ERR_PTR(-EINVAL);
313 }
314
315}
316EXPORT_SYMBOL_GPL(cfg80211_wext_freq);
317
318int cfg80211_wext_siwrts(struct net_device *dev,
319 struct iw_request_info *info,
320 struct iw_param *rts, char *extra)
321{
322 struct wireless_dev *wdev = dev->ieee80211_ptr;
323 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
324 u32 orts = wdev->wiphy->rts_threshold;
325 int err;
326
327 if (rts->disabled || !rts->fixed)
328 wdev->wiphy->rts_threshold = (u32) -1;
329 else if (rts->value < 0)
330 return -EINVAL;
331 else
332 wdev->wiphy->rts_threshold = rts->value;
333
334 err = rdev->ops->set_wiphy_params(wdev->wiphy,
335 WIPHY_PARAM_RTS_THRESHOLD);
336 if (err)
337 wdev->wiphy->rts_threshold = orts;
338
339 return err;
340}
341EXPORT_SYMBOL_GPL(cfg80211_wext_siwrts);
342
343int cfg80211_wext_giwrts(struct net_device *dev,
344 struct iw_request_info *info,
345 struct iw_param *rts, char *extra)
346{
347 struct wireless_dev *wdev = dev->ieee80211_ptr;
348
349 rts->value = wdev->wiphy->rts_threshold;
350 rts->disabled = rts->value == (u32) -1;
351 rts->fixed = 1;
352
353 return 0;
354}
355EXPORT_SYMBOL_GPL(cfg80211_wext_giwrts);
356
357int cfg80211_wext_siwfrag(struct net_device *dev,
358 struct iw_request_info *info,
359 struct iw_param *frag, char *extra)
360{
361 struct wireless_dev *wdev = dev->ieee80211_ptr;
362 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
363 u32 ofrag = wdev->wiphy->frag_threshold;
364 int err;
365
366 if (frag->disabled || !frag->fixed)
367 wdev->wiphy->frag_threshold = (u32) -1;
368 else if (frag->value < 256)
369 return -EINVAL;
370 else {
371 /* Fragment length must be even, so strip LSB. */
372 wdev->wiphy->frag_threshold = frag->value & ~0x1;
373 }
374
375 err = rdev->ops->set_wiphy_params(wdev->wiphy,
376 WIPHY_PARAM_FRAG_THRESHOLD);
377 if (err)
378 wdev->wiphy->frag_threshold = ofrag;
379
380 return err;
381}
382EXPORT_SYMBOL_GPL(cfg80211_wext_siwfrag);
383
384int cfg80211_wext_giwfrag(struct net_device *dev,
385 struct iw_request_info *info,
386 struct iw_param *frag, char *extra)
387{
388 struct wireless_dev *wdev = dev->ieee80211_ptr;
389
390 frag->value = wdev->wiphy->frag_threshold;
391 frag->disabled = frag->value == (u32) -1;
392 frag->fixed = 1;
393
394 return 0;
395}
396EXPORT_SYMBOL_GPL(cfg80211_wext_giwfrag);
397
398int cfg80211_wext_siwretry(struct net_device *dev,
399 struct iw_request_info *info,
400 struct iw_param *retry, char *extra)
401{
402 struct wireless_dev *wdev = dev->ieee80211_ptr;
403 struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
404 u32 changed = 0;
405 u8 olong = wdev->wiphy->retry_long;
406 u8 oshort = wdev->wiphy->retry_short;
407 int err;
408
409 if (retry->disabled ||
410 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
411 return -EINVAL;
412
413 if (retry->flags & IW_RETRY_LONG) {
414 wdev->wiphy->retry_long = retry->value;
415 changed |= WIPHY_PARAM_RETRY_LONG;
416 } else if (retry->flags & IW_RETRY_SHORT) {
417 wdev->wiphy->retry_short = retry->value;
418 changed |= WIPHY_PARAM_RETRY_SHORT;
419 } else {
420 wdev->wiphy->retry_short = retry->value;
421 wdev->wiphy->retry_long = retry->value;
422 changed |= WIPHY_PARAM_RETRY_LONG;
423 changed |= WIPHY_PARAM_RETRY_SHORT;
424 }
425
426 if (!changed)
427 return 0;
428
429 err = rdev->ops->set_wiphy_params(wdev->wiphy, changed);
430 if (err) {
431 wdev->wiphy->retry_short = oshort;
432 wdev->wiphy->retry_long = olong;
433 }
434
435 return err;
436}
437EXPORT_SYMBOL_GPL(cfg80211_wext_siwretry);
438
439int cfg80211_wext_giwretry(struct net_device *dev,
440 struct iw_request_info *info,
441 struct iw_param *retry, char *extra)
442{
443 struct wireless_dev *wdev = dev->ieee80211_ptr;
444
445 retry->disabled = 0;
446
447 if (retry->flags == 0 || (retry->flags & IW_RETRY_SHORT)) {
448 /*
449 * First return short value, iwconfig will ask long value
450 * later if needed
451 */
452 retry->flags |= IW_RETRY_LIMIT;
453 retry->value = wdev->wiphy->retry_short;
454 if (wdev->wiphy->retry_long != wdev->wiphy->retry_short)
455 retry->flags |= IW_RETRY_LONG;
456
457 return 0;
458 }
459
460 if (retry->flags & IW_RETRY_LONG) {
461 retry->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
462 retry->value = wdev->wiphy->retry_long;
463 }
464
465 return 0;
466}
467EXPORT_SYMBOL_GPL(cfg80211_wext_giwretry);