aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/feature-removal-schedule.txt22
-rw-r--r--MAINTAINERS18
-rw-r--r--drivers/bluetooth/bluecard_cs.c10
-rw-r--r--drivers/bluetooth/bpa10x.c2
-rw-r--r--drivers/bluetooth/bt3c_cs.c4
-rw-r--r--drivers/bluetooth/btmrvl_sdio.c3
-rw-r--r--drivers/bluetooth/btuart_cs.c4
-rw-r--r--drivers/bluetooth/btusb.c14
-rw-r--r--drivers/bluetooth/dtl1_cs.c4
-rw-r--r--drivers/bluetooth/hci_bcsp.c2
-rw-r--r--drivers/bluetooth/hci_h4.c2
-rw-r--r--drivers/bluetooth/hci_ldisc.c2
-rw-r--r--drivers/bluetooth/hci_ll.c6
-rw-r--r--drivers/net/wireless/ath/ath6kl/cfg80211.c36
-rw-r--r--drivers/net/wireless/ath/ath6kl/core.h3
-rw-r--r--drivers/net/wireless/ath/ath6kl/main.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/Makefile4
-rw-r--r--drivers/net/wireless/ath/ath9k/ahb.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/antenna.c776
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_calib.c20
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_eeprom.c5
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_mac.c7
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_mci.c721
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_mci.h40
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.c4
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.h32
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h7
-rw-r--r--drivers/net/wireless/ath/ath9k/ath9k.h50
-rw-r--r--drivers/net/wireless/ath/ath9k/beacon.c23
-rw-r--r--drivers/net/wireless/ath/ath9k/btcoex.c10
-rw-r--r--drivers/net/wireless/ath/ath9k/btcoex.h4
-rw-r--r--drivers/net/wireless/ath/ath9k/debug.c9
-rw-r--r--drivers/net/wireless/ath/ath9k/debug.h1
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom_4k.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom_9287.c2
-rw-r--r--drivers/net/wireless/ath/ath9k/eeprom_def.c4
-rw-r--r--drivers/net/wireless/ath/ath9k/gpio.c44
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c223
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.h10
-rw-r--r--drivers/net/wireless/ath/ath9k/init.c18
-rw-r--r--drivers/net/wireless/ath/ath9k/link.c510
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c705
-rw-r--r--drivers/net/wireless/ath/ath9k/mci.c227
-rw-r--r--drivers/net/wireless/ath/ath9k/mci.h11
-rw-r--r--drivers/net/wireless/ath/ath9k/pci.c7
-rw-r--r--drivers/net/wireless/ath/ath9k/rc.c17
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c768
-rw-r--r--drivers/net/wireless/ath/ath9k/reg.h6
-rw-r--r--drivers/net/wireless/ath/ath9k/xmit.c51
-rw-r--r--drivers/net/wireless/b43legacy/main.c2
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/Makefile2
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd.h3
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c126
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.h59
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c7
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c169
-rw-r--r--drivers/net/wireless/brcm80211/brcmsmac/aiutils.c3
-rw-r--r--drivers/net/wireless/brcm80211/brcmsmac/aiutils.h2
-rw-r--r--drivers/net/wireless/brcm80211/brcmsmac/ampdu.c5
-rw-r--r--drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c14
-rw-r--r--drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c2
-rw-r--r--drivers/net/wireless/brcm80211/brcmutil/utils.c2
-rw-r--r--drivers/net/wireless/ipw2x00/ipw2200.c23
-rw-r--r--drivers/net/wireless/iwlegacy/4965-mac.c13
-rw-r--r--drivers/net/wireless/iwlwifi/Kconfig5
-rw-r--r--drivers/net/wireless/iwlwifi/Makefile32
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/Makefile13
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/agn.h (renamed from drivers/net/wireless/iwlwifi/iwl-agn.h)111
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/calib.c (renamed from drivers/net/wireless/iwlwifi/iwl-agn-calib.c)24
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/calib.h (renamed from drivers/net/wireless/iwlwifi/iwl-agn-calib.h)4
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/commands.h (renamed from drivers/net/wireless/iwlwifi/iwl-commands.h)7
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/debugfs.c (renamed from drivers/net/wireless/iwlwifi/iwl-debugfs.c)31
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/dev.h (renamed from drivers/net/wireless/iwlwifi/iwl-dev.h)174
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/devices.c (renamed from drivers/net/wireless/iwlwifi/iwl-agn-devices.c)178
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/led.c (renamed from drivers/net/wireless/iwlwifi/iwl-led.c)5
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/led.h (renamed from drivers/net/wireless/iwlwifi/iwl-led.h)0
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/lib.c (renamed from drivers/net/wireless/iwlwifi/iwl-agn-lib.c)20
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/mac80211.c (renamed from drivers/net/wireless/iwlwifi/iwl-mac80211.c)146
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/main.c (renamed from drivers/net/wireless/iwlwifi/iwl-agn.c)426
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/power.c (renamed from drivers/net/wireless/iwlwifi/iwl-power.c)11
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/power.h (renamed from drivers/net/wireless/iwlwifi/iwl-power.h)2
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/rs.c (renamed from drivers/net/wireless/iwlwifi/iwl-agn-rs.c)50
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/rs.h (renamed from drivers/net/wireless/iwlwifi/iwl-agn-rs.h)3
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/rx.c (renamed from drivers/net/wireless/iwlwifi/iwl-agn-rx.c)34
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/rxon.c (renamed from drivers/net/wireless/iwlwifi/iwl-agn-rxon.c)52
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/scan.c (renamed from drivers/net/wireless/iwlwifi/iwl-scan.c)111
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/sta.c (renamed from drivers/net/wireless/iwlwifi/iwl-agn-sta.c)60
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/testmode.c471
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/tt.c (renamed from drivers/net/wireless/iwlwifi/iwl-agn-tt.c)13
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/tt.h (renamed from drivers/net/wireless/iwlwifi/iwl-agn-tt.h)2
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/tx.c (renamed from drivers/net/wireless/iwlwifi/iwl-agn-tx.c)62
-rw-r--r--drivers/net/wireless/iwlwifi/dvm/ucode.c (renamed from drivers/net/wireless/iwlwifi/iwl-ucode.c)34
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-config.h28
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-csr.h28
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debug.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debug.h17
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-devtrace.c5
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-devtrace.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-drv.c149
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c900
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom-parse.h138
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom-read.c463
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom-read.h70
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.c1148
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-eeprom.h269
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-fh.h2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-io.c53
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-io.h16
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-notif-wait.c8
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-op-mode.h8
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-prph.h2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-test.c856
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-test.h161
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-testmode.c1114
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-trans.h56
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/1000.c (renamed from drivers/net/wireless/iwlwifi/iwl-1000.c)19
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/2000.c (renamed from drivers/net/wireless/iwlwifi/iwl-2000.c)22
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/5000.c (renamed from drivers/net/wireless/iwlwifi/iwl-5000.c)20
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/6000.c (renamed from drivers/net/wireless/iwlwifi/iwl-6000.c)25
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/cfg.h (renamed from drivers/net/wireless/iwlwifi/iwl-cfg.h)0
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/drv.c (renamed from drivers/net/wireless/iwlwifi/iwl-pci.c)5
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/internal.h (renamed from drivers/net/wireless/iwlwifi/iwl-trans-pcie-int.h)22
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/rx.c (renamed from drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c)75
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/trans.c (renamed from drivers/net/wireless/iwlwifi/iwl-trans-pcie.c)347
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/tx.c (renamed from drivers/net/wireless/iwlwifi/iwl-trans-pcie-tx.c)200
-rw-r--r--drivers/net/wireless/libertas/cfg.c39
-rw-r--r--drivers/net/wireless/libertas/dev.h1
-rw-r--r--drivers/net/wireless/libertas/mesh.c7
-rw-r--r--drivers/net/wireless/mwifiex/init.c65
-rw-r--r--drivers/net/wireless/mwifiex/main.c4
-rw-r--r--drivers/net/wireless/mwifiex/main.h11
-rw-r--r--drivers/net/wireless/mwifiex/scan.c59
-rw-r--r--drivers/net/wireless/orinoco/cfg.c9
-rw-r--r--drivers/net/wireless/rt2x00/rt2800.h8
-rw-r--r--drivers/net/wireless/rt2x00/rt2800lib.c27
-rw-r--r--drivers/net/wireless/rt2x00/rt2800pci.c1
-rw-r--r--drivers/net/wireless/rt2x00/rt2800usb.c3
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00mac.c14
-rw-r--r--drivers/net/wireless/ti/Kconfig1
-rw-r--r--drivers/net/wireless/ti/Makefile1
-rw-r--r--drivers/net/wireless/ti/wl12xx/Makefile2
-rw-r--r--drivers/net/wireless/ti/wl12xx/acx.h237
-rw-r--r--drivers/net/wireless/ti/wl12xx/cmd.c8
-rw-r--r--drivers/net/wireless/ti/wl12xx/debugfs.c243
-rw-r--r--drivers/net/wireless/ti/wl12xx/debugfs.h28
-rw-r--r--drivers/net/wireless/ti/wl12xx/main.c242
-rw-r--r--drivers/net/wireless/ti/wl12xx/wl12xx.h8
-rw-r--r--drivers/net/wireless/ti/wl18xx/Kconfig7
-rw-r--r--drivers/net/wireless/ti/wl18xx/Makefile3
-rw-r--r--drivers/net/wireless/ti/wl18xx/acx.c111
-rw-r--r--drivers/net/wireless/ti/wl18xx/acx.h291
-rw-r--r--drivers/net/wireless/ti/wl18xx/conf.h92
-rw-r--r--drivers/net/wireless/ti/wl18xx/debugfs.c403
-rw-r--r--drivers/net/wireless/ti/wl18xx/debugfs.h28
-rw-r--r--drivers/net/wireless/ti/wl18xx/io.c60
-rw-r--r--drivers/net/wireless/ti/wl18xx/io.h28
-rw-r--r--drivers/net/wireless/ti/wl18xx/main.c1463
-rw-r--r--drivers/net/wireless/ti/wl18xx/reg.h191
-rw-r--r--drivers/net/wireless/ti/wl18xx/tx.c127
-rw-r--r--drivers/net/wireless/ti/wl18xx/tx.h46
-rw-r--r--drivers/net/wireless/ti/wl18xx/wl18xx.h88
-rw-r--r--drivers/net/wireless/ti/wlcore/acx.c8
-rw-r--r--drivers/net/wireless/ti/wlcore/acx.h254
-rw-r--r--drivers/net/wireless/ti/wlcore/boot.c57
-rw-r--r--drivers/net/wireless/ti/wlcore/boot.h1
-rw-r--r--drivers/net/wireless/ti/wlcore/cmd.c62
-rw-r--r--drivers/net/wireless/ti/wlcore/cmd.h13
-rw-r--r--drivers/net/wireless/ti/wlcore/conf.h93
-rw-r--r--drivers/net/wireless/ti/wlcore/debugfs.c390
-rw-r--r--drivers/net/wireless/ti/wlcore/debugfs.h87
-rw-r--r--drivers/net/wireless/ti/wlcore/event.c24
-rw-r--r--drivers/net/wireless/ti/wlcore/hw_ops.h78
-rw-r--r--drivers/net/wireless/ti/wlcore/init.c3
-rw-r--r--drivers/net/wireless/ti/wlcore/main.c504
-rw-r--r--drivers/net/wireless/ti/wlcore/ps.c21
-rw-r--r--drivers/net/wireless/ti/wlcore/rx.c11
-rw-r--r--drivers/net/wireless/ti/wlcore/rx.h7
-rw-r--r--drivers/net/wireless/ti/wlcore/scan.c52
-rw-r--r--drivers/net/wireless/ti/wlcore/scan.h19
-rw-r--r--drivers/net/wireless/ti/wlcore/sdio.c35
-rw-r--r--drivers/net/wireless/ti/wlcore/tx.c185
-rw-r--r--drivers/net/wireless/ti/wlcore/tx.h49
-rw-r--r--drivers/net/wireless/ti/wlcore/wlcore.h70
-rw-r--r--drivers/net/wireless/ti/wlcore/wlcore_i.h (renamed from drivers/net/wireless/ti/wlcore/wl12xx.h)44
-rw-r--r--drivers/nfc/pn533.c662
-rw-r--r--drivers/nfc/pn544_hci.c10
-rw-r--r--drivers/ssb/b43_pci_bridge.c1
-rw-r--r--drivers/ssb/scan.c2
-rw-r--r--include/linux/nfc.h12
-rw-r--r--include/linux/nl80211.h8
-rw-r--r--include/linux/ssb/ssb.h1
-rw-r--r--include/net/bluetooth/a2mp.h126
-rw-r--r--include/net/bluetooth/bluetooth.h39
-rw-r--r--include/net/bluetooth/hci.h99
-rw-r--r--include/net/bluetooth/hci_core.h29
-rw-r--r--include/net/bluetooth/l2cap.h205
-rw-r--r--include/net/cfg80211.h45
-rw-r--r--include/net/mac80211.h44
-rw-r--r--include/net/nfc/hci.h3
-rw-r--r--include/net/nfc/nfc.h14
-rw-r--r--include/net/nfc/shdlc.h3
-rw-r--r--net/bluetooth/Makefile3
-rw-r--r--net/bluetooth/a2mp.c568
-rw-r--r--net/bluetooth/af_bluetooth.c14
-rw-r--r--net/bluetooth/bnep/core.c21
-rw-r--r--net/bluetooth/bnep/netdev.c16
-rw-r--r--net/bluetooth/bnep/sock.c18
-rw-r--r--net/bluetooth/hci_conn.c98
-rw-r--r--net/bluetooth/hci_core.c214
-rw-r--r--net/bluetooth/hci_event.c309
-rw-r--r--net/bluetooth/hci_sock.c59
-rw-r--r--net/bluetooth/hci_sysfs.c99
-rw-r--r--net/bluetooth/hidp/core.c26
-rw-r--r--net/bluetooth/hidp/sock.c16
-rw-r--r--net/bluetooth/l2cap_core.c2125
-rw-r--r--net/bluetooth/l2cap_sock.c130
-rw-r--r--net/bluetooth/lib.c7
-rw-r--r--net/bluetooth/mgmt.c71
-rw-r--r--net/bluetooth/rfcomm/core.c32
-rw-r--r--net/bluetooth/rfcomm/sock.c21
-rw-r--r--net/bluetooth/rfcomm/tty.c9
-rw-r--r--net/bluetooth/sco.c43
-rw-r--r--net/bluetooth/smp.c7
-rw-r--r--net/core/net-sysfs.c74
-rw-r--r--net/mac80211/Makefile1
-rw-r--r--net/mac80211/agg-rx.c30
-rw-r--r--net/mac80211/agg-tx.c109
-rw-r--r--net/mac80211/cfg.c579
-rw-r--r--net/mac80211/chan.c4
-rw-r--r--net/mac80211/debugfs_netdev.c3
-rw-r--r--net/mac80211/ibss.c114
-rw-r--r--net/mac80211/ieee80211_i.h92
-rw-r--r--net/mac80211/iface.c42
-rw-r--r--net/mac80211/main.c17
-rw-r--r--net/mac80211/mesh.c3
-rw-r--r--net/mac80211/mesh_hwmp.c2
-rw-r--r--net/mac80211/mesh_pathtbl.c2
-rw-r--r--net/mac80211/mesh_plink.c2
-rw-r--r--net/mac80211/mesh_sync.c2
-rw-r--r--net/mac80211/mlme.c189
-rw-r--r--net/mac80211/offchannel.c280
-rw-r--r--net/mac80211/pm.c1
-rw-r--r--net/mac80211/rx.c22
-rw-r--r--net/mac80211/scan.c4
-rw-r--r--net/mac80211/sta_info.c23
-rw-r--r--net/mac80211/status.c30
-rw-r--r--net/mac80211/tkip.c21
-rw-r--r--net/mac80211/tx.c14
-rw-r--r--net/mac80211/util.c117
-rw-r--r--net/mac80211/work.c370
-rw-r--r--net/nfc/core.c119
-rw-r--r--net/nfc/hci/core.c13
-rw-r--r--net/nfc/hci/shdlc.c6
-rw-r--r--net/nfc/llcp/commands.c54
-rw-r--r--net/nfc/llcp/llcp.c421
-rw-r--r--net/nfc/llcp/llcp.h26
-rw-r--r--net/nfc/llcp/sock.c47
-rw-r--r--net/nfc/nci/core.c15
-rw-r--r--net/nfc/netlink.c81
-rw-r--r--net/nfc/nfc.h12
-rw-r--r--net/rfkill/core.c2
-rw-r--r--net/wireless/Kconfig14
-rw-r--r--net/wireless/chan.c55
-rw-r--r--net/wireless/core.h12
-rw-r--r--net/wireless/mesh.c91
-rw-r--r--net/wireless/mlme.c2
-rw-r--r--net/wireless/nl80211.c129
-rw-r--r--net/wireless/wext-compat.c21
-rw-r--r--net/wireless/wext-sme.c10
270 files changed, 17069 insertions, 10641 deletions
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index 56000b33340b..dec901554ef7 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -249,15 +249,6 @@ Who: Ravikiran Thirumalai <kiran@scalex86.org>
249 249
250--------------------------- 250---------------------------
251 251
252What: Code that is now under CONFIG_WIRELESS_EXT_SYSFS
253 (in net/core/net-sysfs.c)
254When: 3.5
255Why: Over 1K .text/.data size reduction, data is available in other
256 ways (ioctls)
257Who: Johannes Berg <johannes@sipsolutions.net>
258
259---------------------------
260
261What: sysfs ui for changing p4-clockmod parameters 252What: sysfs ui for changing p4-clockmod parameters
262When: September 2009 253When: September 2009
263Why: See commits 129f8ae9b1b5be94517da76009ea956e89104ce8 and 254Why: See commits 129f8ae9b1b5be94517da76009ea956e89104ce8 and
@@ -449,6 +440,19 @@ Who: Hans Verkuil <hans.verkuil@cisco.com>
449 440
450---------------------------- 441----------------------------
451 442
443What: CONFIG_CFG80211_WEXT
444When: as soon as distributions ship new wireless tools, ie. wpa_supplicant 1.0
445 and NetworkManager/connman/etc. that are able to use nl80211
446Why: Wireless extensions are deprecated, and userland tools are moving to
447 using nl80211. New drivers are no longer using wireless extensions,
448 and while there might still be old drivers, both new drivers and new
449 userland no longer needs them and they can't be used for an feature
450 developed in the past couple of years. As such, compatibility with
451 wireless extensions in new drivers will be removed.
452Who: Johannes Berg <johannes@sipsolutions.net>
453
454----------------------------
455
452What: g_file_storage driver 456What: g_file_storage driver
453When: 3.8 457When: 3.8
454Why: This driver has been superseded by g_mass_storage. 458Why: This driver has been superseded by g_mass_storage.
diff --git a/MAINTAINERS b/MAINTAINERS
index 03660de94cf7..3075a2a29511 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -329,7 +329,7 @@ F: drivers/hwmon/adm1029.c
329 329
330ADM8211 WIRELESS DRIVER 330ADM8211 WIRELESS DRIVER
331L: linux-wireless@vger.kernel.org 331L: linux-wireless@vger.kernel.org
332W: http://linuxwireless.org/ 332W: http://wireless.kernel.org/
333S: Orphan 333S: Orphan
334F: drivers/net/wireless/adm8211.* 334F: drivers/net/wireless/adm8211.*
335 335
@@ -1423,7 +1423,7 @@ B43 WIRELESS DRIVER
1423M: Stefano Brivio <stefano.brivio@polimi.it> 1423M: Stefano Brivio <stefano.brivio@polimi.it>
1424L: linux-wireless@vger.kernel.org 1424L: linux-wireless@vger.kernel.org
1425L: b43-dev@lists.infradead.org 1425L: b43-dev@lists.infradead.org
1426W: http://linuxwireless.org/en/users/Drivers/b43 1426W: http://wireless.kernel.org/en/users/Drivers/b43
1427S: Maintained 1427S: Maintained
1428F: drivers/net/wireless/b43/ 1428F: drivers/net/wireless/b43/
1429 1429
@@ -1432,7 +1432,7 @@ M: Larry Finger <Larry.Finger@lwfinger.net>
1432M: Stefano Brivio <stefano.brivio@polimi.it> 1432M: Stefano Brivio <stefano.brivio@polimi.it>
1433L: linux-wireless@vger.kernel.org 1433L: linux-wireless@vger.kernel.org
1434L: b43-dev@lists.infradead.org 1434L: b43-dev@lists.infradead.org
1435W: http://linuxwireless.org/en/users/Drivers/b43 1435W: http://wireless.kernel.org/en/users/Drivers/b43
1436S: Maintained 1436S: Maintained
1437F: drivers/net/wireless/b43legacy/ 1437F: drivers/net/wireless/b43legacy/
1438 1438
@@ -4342,7 +4342,7 @@ F: arch/m68k/hp300/
4342MAC80211 4342MAC80211
4343M: Johannes Berg <johannes@sipsolutions.net> 4343M: Johannes Berg <johannes@sipsolutions.net>
4344L: linux-wireless@vger.kernel.org 4344L: linux-wireless@vger.kernel.org
4345W: http://linuxwireless.org/ 4345W: http://wireless.kernel.org/
4346T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211.git 4346T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211.git
4347T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git 4347T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git
4348S: Maintained 4348S: Maintained
@@ -4354,7 +4354,7 @@ MAC80211 PID RATE CONTROL
4354M: Stefano Brivio <stefano.brivio@polimi.it> 4354M: Stefano Brivio <stefano.brivio@polimi.it>
4355M: Mattias Nissler <mattias.nissler@gmx.de> 4355M: Mattias Nissler <mattias.nissler@gmx.de>
4356L: linux-wireless@vger.kernel.org 4356L: linux-wireless@vger.kernel.org
4357W: http://linuxwireless.org/en/developers/Documentation/mac80211/RateControl/PID 4357W: http://wireless.kernel.org/en/developers/Documentation/mac80211/RateControl/PID
4358T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211.git 4358T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211.git
4359T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git 4359T: git git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git
4360S: Maintained 4360S: Maintained
@@ -5032,7 +5032,7 @@ F: fs/ocfs2/
5032 5032
5033ORINOCO DRIVER 5033ORINOCO DRIVER
5034L: linux-wireless@vger.kernel.org 5034L: linux-wireless@vger.kernel.org
5035W: http://linuxwireless.org/en/users/Drivers/orinoco 5035W: http://wireless.kernel.org/en/users/Drivers/orinoco
5036W: http://www.nongnu.org/orinoco/ 5036W: http://www.nongnu.org/orinoco/
5037S: Orphan 5037S: Orphan
5038F: drivers/net/wireless/orinoco/ 5038F: drivers/net/wireless/orinoco/
@@ -5737,7 +5737,7 @@ F: net/rose/
5737RTL8180 WIRELESS DRIVER 5737RTL8180 WIRELESS DRIVER
5738M: "John W. Linville" <linville@tuxdriver.com> 5738M: "John W. Linville" <linville@tuxdriver.com>
5739L: linux-wireless@vger.kernel.org 5739L: linux-wireless@vger.kernel.org
5740W: http://linuxwireless.org/ 5740W: http://wireless.kernel.org/
5741T: git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git 5741T: git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git
5742S: Maintained 5742S: Maintained
5743F: drivers/net/wireless/rtl818x/rtl8180/ 5743F: drivers/net/wireless/rtl818x/rtl8180/
@@ -5747,7 +5747,7 @@ M: Herton Ronaldo Krzesinski <herton@canonical.com>
5747M: Hin-Tak Leung <htl10@users.sourceforge.net> 5747M: Hin-Tak Leung <htl10@users.sourceforge.net>
5748M: Larry Finger <Larry.Finger@lwfinger.net> 5748M: Larry Finger <Larry.Finger@lwfinger.net>
5749L: linux-wireless@vger.kernel.org 5749L: linux-wireless@vger.kernel.org
5750W: http://linuxwireless.org/ 5750W: http://wireless.kernel.org/
5751T: git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git 5751T: git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git
5752S: Maintained 5752S: Maintained
5753F: drivers/net/wireless/rtl818x/rtl8187/ 5753F: drivers/net/wireless/rtl818x/rtl8187/
@@ -5756,7 +5756,7 @@ RTL8192CE WIRELESS DRIVER
5756M: Larry Finger <Larry.Finger@lwfinger.net> 5756M: Larry Finger <Larry.Finger@lwfinger.net>
5757M: Chaoming Li <chaoming_li@realsil.com.cn> 5757M: Chaoming Li <chaoming_li@realsil.com.cn>
5758L: linux-wireless@vger.kernel.org 5758L: linux-wireless@vger.kernel.org
5759W: http://linuxwireless.org/ 5759W: http://wireless.kernel.org/
5760T: git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git 5760T: git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git
5761S: Maintained 5761S: Maintained
5762F: drivers/net/wireless/rtlwifi/ 5762F: drivers/net/wireless/rtlwifi/
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
index 1fcd92380356..585c88e01893 100644
--- a/drivers/bluetooth/bluecard_cs.c
+++ b/drivers/bluetooth/bluecard_cs.c
@@ -231,12 +231,12 @@ static void bluecard_write_wakeup(bluecard_info_t *info)
231 } 231 }
232 232
233 do { 233 do {
234 register unsigned int iobase = info->p_dev->resource[0]->start; 234 unsigned int iobase = info->p_dev->resource[0]->start;
235 register unsigned int offset; 235 unsigned int offset;
236 register unsigned char command; 236 unsigned char command;
237 register unsigned long ready_bit; 237 unsigned long ready_bit;
238 register struct sk_buff *skb; 238 register struct sk_buff *skb;
239 register int len; 239 int len;
240 240
241 clear_bit(XMIT_WAKEUP, &(info->tx_state)); 241 clear_bit(XMIT_WAKEUP, &(info->tx_state));
242 242
diff --git a/drivers/bluetooth/bpa10x.c b/drivers/bluetooth/bpa10x.c
index 609861a53c28..29caaed2d715 100644
--- a/drivers/bluetooth/bpa10x.c
+++ b/drivers/bluetooth/bpa10x.c
@@ -470,7 +470,7 @@ static int bpa10x_probe(struct usb_interface *intf, const struct usb_device_id *
470 hdev->flush = bpa10x_flush; 470 hdev->flush = bpa10x_flush;
471 hdev->send = bpa10x_send_frame; 471 hdev->send = bpa10x_send_frame;
472 472
473 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks); 473 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
474 474
475 err = hci_register_dev(hdev); 475 err = hci_register_dev(hdev);
476 if (err < 0) { 476 if (err < 0) {
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index 308c8599ab55..b2b0fbbb43b5 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -186,9 +186,9 @@ static void bt3c_write_wakeup(bt3c_info_t *info)
186 return; 186 return;
187 187
188 do { 188 do {
189 register unsigned int iobase = info->p_dev->resource[0]->start; 189 unsigned int iobase = info->p_dev->resource[0]->start;
190 register struct sk_buff *skb; 190 register struct sk_buff *skb;
191 register int len; 191 int len;
192 192
193 if (!pcmcia_dev_present(info->p_dev)) 193 if (!pcmcia_dev_present(info->p_dev))
194 break; 194 break;
diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index a853244e7fd7..2867499f7256 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -110,6 +110,9 @@ static const struct sdio_device_id btmrvl_sdio_ids[] = {
110 /* Marvell SD8787 Bluetooth device */ 110 /* Marvell SD8787 Bluetooth device */
111 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x911A), 111 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x911A),
112 .driver_data = (unsigned long) &btmrvl_sdio_sd8787 }, 112 .driver_data = (unsigned long) &btmrvl_sdio_sd8787 },
113 /* Marvell SD8787 Bluetooth AMP device */
114 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x911B),
115 .driver_data = (unsigned long) &btmrvl_sdio_sd8787 },
113 /* Marvell SD8797 Bluetooth device */ 116 /* Marvell SD8797 Bluetooth device */
114 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x912A), 117 { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, 0x912A),
115 .driver_data = (unsigned long) &btmrvl_sdio_sd8797 }, 118 .driver_data = (unsigned long) &btmrvl_sdio_sd8797 },
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c
index c4fc2f3fc32c..65b8d996840c 100644
--- a/drivers/bluetooth/btuart_cs.c
+++ b/drivers/bluetooth/btuart_cs.c
@@ -140,9 +140,9 @@ static void btuart_write_wakeup(btuart_info_t *info)
140 } 140 }
141 141
142 do { 142 do {
143 register unsigned int iobase = info->p_dev->resource[0]->start; 143 unsigned int iobase = info->p_dev->resource[0]->start;
144 register struct sk_buff *skb; 144 register struct sk_buff *skb;
145 register int len; 145 int len;
146 146
147 clear_bit(XMIT_WAKEUP, &(info->tx_state)); 147 clear_bit(XMIT_WAKEUP, &(info->tx_state));
148 148
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index c9463af8e564..a45e717f5f84 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -21,15 +21,7 @@
21 * 21 *
22 */ 22 */
23 23
24#include <linux/kernel.h>
25#include <linux/module.h> 24#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/slab.h>
28#include <linux/types.h>
29#include <linux/sched.h>
30#include <linux/errno.h>
31#include <linux/skbuff.h>
32
33#include <linux/usb.h> 25#include <linux/usb.h>
34 26
35#include <net/bluetooth/bluetooth.h> 27#include <net/bluetooth/bluetooth.h>
@@ -1026,7 +1018,7 @@ static int btusb_probe(struct usb_interface *intf,
1026 data->isoc = usb_ifnum_to_if(data->udev, 1); 1018 data->isoc = usb_ifnum_to_if(data->udev, 1);
1027 1019
1028 if (!reset) 1020 if (!reset)
1029 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks); 1021 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
1030 1022
1031 if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) { 1023 if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
1032 if (!disable_scofix) 1024 if (!disable_scofix)
@@ -1038,7 +1030,7 @@ static int btusb_probe(struct usb_interface *intf,
1038 1030
1039 if (id->driver_info & BTUSB_DIGIANSWER) { 1031 if (id->driver_info & BTUSB_DIGIANSWER) {
1040 data->cmdreq_type = USB_TYPE_VENDOR; 1032 data->cmdreq_type = USB_TYPE_VENDOR;
1041 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks); 1033 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
1042 } 1034 }
1043 1035
1044 if (id->driver_info & BTUSB_CSR) { 1036 if (id->driver_info & BTUSB_CSR) {
@@ -1046,7 +1038,7 @@ static int btusb_probe(struct usb_interface *intf,
1046 1038
1047 /* Old firmware would otherwise execute USB reset */ 1039 /* Old firmware would otherwise execute USB reset */
1048 if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x117) 1040 if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x117)
1049 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks); 1041 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
1050 } 1042 }
1051 1043
1052 if (id->driver_info & BTUSB_SNIFFER) { 1044 if (id->driver_info & BTUSB_SNIFFER) {
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index 6e8d96189684..b1b37ccd3cd4 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -144,9 +144,9 @@ static void dtl1_write_wakeup(dtl1_info_t *info)
144 } 144 }
145 145
146 do { 146 do {
147 register unsigned int iobase = info->p_dev->resource[0]->start; 147 unsigned int iobase = info->p_dev->resource[0]->start;
148 register struct sk_buff *skb; 148 register struct sk_buff *skb;
149 register int len; 149 int len;
150 150
151 clear_bit(XMIT_WAKEUP, &(info->tx_state)); 151 clear_bit(XMIT_WAKEUP, &(info->tx_state));
152 152
diff --git a/drivers/bluetooth/hci_bcsp.c b/drivers/bluetooth/hci_bcsp.c
index 661a8dc4d2f8..57e502e06080 100644
--- a/drivers/bluetooth/hci_bcsp.c
+++ b/drivers/bluetooth/hci_bcsp.c
@@ -552,7 +552,7 @@ static u16 bscp_get_crc(struct bcsp_struct *bcsp)
552static int bcsp_recv(struct hci_uart *hu, void *data, int count) 552static int bcsp_recv(struct hci_uart *hu, void *data, int count)
553{ 553{
554 struct bcsp_struct *bcsp = hu->priv; 554 struct bcsp_struct *bcsp = hu->priv;
555 register unsigned char *ptr; 555 unsigned char *ptr;
556 556
557 BT_DBG("hu %p count %d rx_state %d rx_count %ld", 557 BT_DBG("hu %p count %d rx_state %d rx_count %ld",
558 hu, count, bcsp->rx_state, bcsp->rx_count); 558 hu, count, bcsp->rx_state, bcsp->rx_count);
diff --git a/drivers/bluetooth/hci_h4.c b/drivers/bluetooth/hci_h4.c
index 748329468d26..c60623f206d4 100644
--- a/drivers/bluetooth/hci_h4.c
+++ b/drivers/bluetooth/hci_h4.c
@@ -126,7 +126,7 @@ static int h4_enqueue(struct hci_uart *hu, struct sk_buff *skb)
126 126
127static inline int h4_check_data_len(struct h4_struct *h4, int len) 127static inline int h4_check_data_len(struct h4_struct *h4, int len)
128{ 128{
129 register int room = skb_tailroom(h4->rx_skb); 129 int room = skb_tailroom(h4->rx_skb);
130 130
131 BT_DBG("len %d room %d", len, room); 131 BT_DBG("len %d room %d", len, room);
132 132
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index e564579a6115..2f9b796e106e 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -394,7 +394,7 @@ static int hci_uart_register_dev(struct hci_uart *hu)
394 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks); 394 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
395 395
396 if (!test_bit(HCI_UART_RESET_ON_INIT, &hu->hdev_flags)) 396 if (!test_bit(HCI_UART_RESET_ON_INIT, &hu->hdev_flags))
397 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks); 397 set_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks);
398 398
399 if (test_bit(HCI_UART_CREATE_AMP, &hu->hdev_flags)) 399 if (test_bit(HCI_UART_CREATE_AMP, &hu->hdev_flags))
400 hdev->dev_type = HCI_AMP; 400 hdev->dev_type = HCI_AMP;
diff --git a/drivers/bluetooth/hci_ll.c b/drivers/bluetooth/hci_ll.c
index b874c0efde24..ff6d589c34a5 100644
--- a/drivers/bluetooth/hci_ll.c
+++ b/drivers/bluetooth/hci_ll.c
@@ -348,7 +348,7 @@ static int ll_enqueue(struct hci_uart *hu, struct sk_buff *skb)
348 348
349static inline int ll_check_data_len(struct ll_struct *ll, int len) 349static inline int ll_check_data_len(struct ll_struct *ll, int len)
350{ 350{
351 register int room = skb_tailroom(ll->rx_skb); 351 int room = skb_tailroom(ll->rx_skb);
352 352
353 BT_DBG("len %d room %d", len, room); 353 BT_DBG("len %d room %d", len, room);
354 354
@@ -374,11 +374,11 @@ static inline int ll_check_data_len(struct ll_struct *ll, int len)
374static int ll_recv(struct hci_uart *hu, void *data, int count) 374static int ll_recv(struct hci_uart *hu, void *data, int count)
375{ 375{
376 struct ll_struct *ll = hu->priv; 376 struct ll_struct *ll = hu->priv;
377 register char *ptr; 377 char *ptr;
378 struct hci_event_hdr *eh; 378 struct hci_event_hdr *eh;
379 struct hci_acl_hdr *ah; 379 struct hci_acl_hdr *ah;
380 struct hci_sco_hdr *sh; 380 struct hci_sco_hdr *sh;
381 register int len, type, dlen; 381 int len, type, dlen;
382 382
383 BT_DBG("hu %p count %d rx_state %ld rx_count %ld", hu, count, ll->rx_state, ll->rx_count); 383 BT_DBG("hu %p count %d rx_state %ld rx_count %ld", hu, count, ll->rx_state, ll->rx_count);
384 384
diff --git a/drivers/net/wireless/ath/ath6kl/cfg80211.c b/drivers/net/wireless/ath/ath6kl/cfg80211.c
index b869a358ce43..f27e9732951d 100644
--- a/drivers/net/wireless/ath/ath6kl/cfg80211.c
+++ b/drivers/net/wireless/ath/ath6kl/cfg80211.c
@@ -2585,35 +2585,6 @@ static int ath6kl_set_ies(struct ath6kl_vif *vif,
2585 return 0; 2585 return 0;
2586} 2586}
2587 2587
2588static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
2589 struct ieee80211_channel *chan,
2590 enum nl80211_channel_type channel_type)
2591{
2592 struct ath6kl_vif *vif;
2593
2594 /*
2595 * 'dev' could be NULL if a channel change is required for the hardware
2596 * device itself, instead of a particular VIF.
2597 *
2598 * FIXME: To be handled properly when monitor mode is supported.
2599 */
2600 if (!dev)
2601 return -EBUSY;
2602
2603 vif = netdev_priv(dev);
2604
2605 if (!ath6kl_cfg80211_ready(vif))
2606 return -EIO;
2607
2608 ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
2609 __func__, chan->center_freq, chan->hw_value);
2610 vif->next_chan = chan->center_freq;
2611 vif->next_ch_type = channel_type;
2612 vif->next_ch_band = chan->band;
2613
2614 return 0;
2615}
2616
2617static int ath6kl_get_rsn_capab(struct cfg80211_beacon_data *beacon, 2588static int ath6kl_get_rsn_capab(struct cfg80211_beacon_data *beacon,
2618 u8 *rsn_capab) 2589 u8 *rsn_capab)
2619{ 2590{
@@ -2791,7 +2762,7 @@ static int ath6kl_start_ap(struct wiphy *wiphy, struct net_device *dev,
2791 p.ssid_len = vif->ssid_len; 2762 p.ssid_len = vif->ssid_len;
2792 memcpy(p.ssid, vif->ssid, vif->ssid_len); 2763 memcpy(p.ssid, vif->ssid, vif->ssid_len);
2793 p.dot11_auth_mode = vif->dot11_auth_mode; 2764 p.dot11_auth_mode = vif->dot11_auth_mode;
2794 p.ch = cpu_to_le16(vif->next_chan); 2765 p.ch = cpu_to_le16(info->channel->center_freq);
2795 2766
2796 /* Enable uAPSD support by default */ 2767 /* Enable uAPSD support by default */
2797 res = ath6kl_wmi_ap_set_apsd(ar->wmi, vif->fw_vif_idx, true); 2768 res = ath6kl_wmi_ap_set_apsd(ar->wmi, vif->fw_vif_idx, true);
@@ -2815,8 +2786,8 @@ static int ath6kl_start_ap(struct wiphy *wiphy, struct net_device *dev,
2815 return res; 2786 return res;
2816 } 2787 }
2817 2788
2818 if (ath6kl_set_htcap(vif, vif->next_ch_band, 2789 if (ath6kl_set_htcap(vif, info->channel->band,
2819 vif->next_ch_type != NL80211_CHAN_NO_HT)) 2790 info->channel_type != NL80211_CHAN_NO_HT))
2820 return -EIO; 2791 return -EIO;
2821 2792
2822 /* 2793 /*
@@ -3271,7 +3242,6 @@ static struct cfg80211_ops ath6kl_cfg80211_ops = {
3271 .suspend = __ath6kl_cfg80211_suspend, 3242 .suspend = __ath6kl_cfg80211_suspend,
3272 .resume = __ath6kl_cfg80211_resume, 3243 .resume = __ath6kl_cfg80211_resume,
3273#endif 3244#endif
3274 .set_channel = ath6kl_set_channel,
3275 .start_ap = ath6kl_start_ap, 3245 .start_ap = ath6kl_start_ap,
3276 .change_beacon = ath6kl_change_beacon, 3246 .change_beacon = ath6kl_change_beacon,
3277 .stop_ap = ath6kl_stop_ap, 3247 .stop_ap = ath6kl_stop_ap,
diff --git a/drivers/net/wireless/ath/ath6kl/core.h b/drivers/net/wireless/ath/ath6kl/core.h
index 4d9c6f142698..8443b2a4133e 100644
--- a/drivers/net/wireless/ath/ath6kl/core.h
+++ b/drivers/net/wireless/ath/ath6kl/core.h
@@ -553,9 +553,6 @@ struct ath6kl_vif {
553 u32 last_cancel_roc_id; 553 u32 last_cancel_roc_id;
554 u32 send_action_id; 554 u32 send_action_id;
555 bool probe_req_report; 555 bool probe_req_report;
556 u16 next_chan;
557 enum nl80211_channel_type next_ch_type;
558 enum ieee80211_band next_ch_band;
559 u16 assoc_bss_beacon_int; 556 u16 assoc_bss_beacon_int;
560 u16 listen_intvl_t; 557 u16 listen_intvl_t;
561 u16 bmiss_time_t; 558 u16 bmiss_time_t;
diff --git a/drivers/net/wireless/ath/ath6kl/main.c b/drivers/net/wireless/ath/ath6kl/main.c
index e5524470529c..b836f2795114 100644
--- a/drivers/net/wireless/ath/ath6kl/main.c
+++ b/drivers/net/wireless/ath/ath6kl/main.c
@@ -598,7 +598,6 @@ static int ath6kl_commit_ch_switch(struct ath6kl_vif *vif, u16 channel)
598 598
599 struct ath6kl *ar = vif->ar; 599 struct ath6kl *ar = vif->ar;
600 600
601 vif->next_chan = channel;
602 vif->profile.ch = cpu_to_le16(channel); 601 vif->profile.ch = cpu_to_le16(channel);
603 602
604 switch (vif->nw_type) { 603 switch (vif->nw_type) {
diff --git a/drivers/net/wireless/ath/ath9k/Makefile b/drivers/net/wireless/ath/ath9k/Makefile
index 3f0b84723789..9c41232b0cd0 100644
--- a/drivers/net/wireless/ath/ath9k/Makefile
+++ b/drivers/net/wireless/ath/ath9k/Makefile
@@ -3,7 +3,9 @@ ath9k-y += beacon.o \
3 init.o \ 3 init.o \
4 main.o \ 4 main.o \
5 recv.o \ 5 recv.o \
6 xmit.o 6 xmit.o \
7 link.o \
8 antenna.o
7 9
8ath9k-$(CONFIG_ATH9K_BTCOEX_SUPPORT) += mci.o 10ath9k-$(CONFIG_ATH9K_BTCOEX_SUPPORT) += mci.o
9ath9k-$(CONFIG_ATH9K_RATE_CONTROL) += rc.o 11ath9k-$(CONFIG_ATH9K_RATE_CONTROL) += rc.o
diff --git a/drivers/net/wireless/ath/ath9k/ahb.c b/drivers/net/wireless/ath/ath9k/ahb.c
index 5e47ca6d16a8..4a4e8a2b9d2c 100644
--- a/drivers/net/wireless/ath/ath9k/ahb.c
+++ b/drivers/net/wireless/ath/ath9k/ahb.c
@@ -126,7 +126,7 @@ static int ath_ahb_probe(struct platform_device *pdev)
126 sc->irq = irq; 126 sc->irq = irq;
127 127
128 /* Will be cleared in ath9k_start() */ 128 /* Will be cleared in ath9k_start() */
129 sc->sc_flags |= SC_OP_INVALID; 129 set_bit(SC_OP_INVALID, &sc->sc_flags);
130 130
131 ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc); 131 ret = request_irq(irq, ath_isr, IRQF_SHARED, "ath9k", sc);
132 if (ret) { 132 if (ret) {
diff --git a/drivers/net/wireless/ath/ath9k/antenna.c b/drivers/net/wireless/ath/ath9k/antenna.c
new file mode 100644
index 000000000000..bbcfeb3b2a60
--- /dev/null
+++ b/drivers/net/wireless/ath/ath9k/antenna.c
@@ -0,0 +1,776 @@
1/*
2 * Copyright (c) 2012 Qualcomm Atheros, 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 "ath9k.h"
18
19static inline bool ath_is_alt_ant_ratio_better(int alt_ratio, int maxdelta,
20 int mindelta, int main_rssi_avg,
21 int alt_rssi_avg, int pkt_count)
22{
23 return (((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
24 (alt_rssi_avg > main_rssi_avg + maxdelta)) ||
25 (alt_rssi_avg > main_rssi_avg + mindelta)) && (pkt_count > 50);
26}
27
28static inline bool ath_ant_div_comb_alt_check(u8 div_group, int alt_ratio,
29 int curr_main_set, int curr_alt_set,
30 int alt_rssi_avg, int main_rssi_avg)
31{
32 bool result = false;
33 switch (div_group) {
34 case 0:
35 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO)
36 result = true;
37 break;
38 case 1:
39 case 2:
40 if ((((curr_main_set == ATH_ANT_DIV_COMB_LNA2) &&
41 (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) &&
42 (alt_rssi_avg >= (main_rssi_avg - 5))) ||
43 ((curr_main_set == ATH_ANT_DIV_COMB_LNA1) &&
44 (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) &&
45 (alt_rssi_avg >= (main_rssi_avg - 2)))) &&
46 (alt_rssi_avg >= 4))
47 result = true;
48 else
49 result = false;
50 break;
51 }
52
53 return result;
54}
55
56static void ath_lnaconf_alt_good_scan(struct ath_ant_comb *antcomb,
57 struct ath_hw_antcomb_conf ant_conf,
58 int main_rssi_avg)
59{
60 antcomb->quick_scan_cnt = 0;
61
62 if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
63 antcomb->rssi_lna2 = main_rssi_avg;
64 else if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA1)
65 antcomb->rssi_lna1 = main_rssi_avg;
66
67 switch ((ant_conf.main_lna_conf << 4) | ant_conf.alt_lna_conf) {
68 case 0x10: /* LNA2 A-B */
69 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
70 antcomb->first_quick_scan_conf =
71 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
72 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
73 break;
74 case 0x20: /* LNA1 A-B */
75 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
76 antcomb->first_quick_scan_conf =
77 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
78 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
79 break;
80 case 0x21: /* LNA1 LNA2 */
81 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA2;
82 antcomb->first_quick_scan_conf =
83 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
84 antcomb->second_quick_scan_conf =
85 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
86 break;
87 case 0x12: /* LNA2 LNA1 */
88 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1;
89 antcomb->first_quick_scan_conf =
90 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
91 antcomb->second_quick_scan_conf =
92 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
93 break;
94 case 0x13: /* LNA2 A+B */
95 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
96 antcomb->first_quick_scan_conf =
97 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
98 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
99 break;
100 case 0x23: /* LNA1 A+B */
101 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
102 antcomb->first_quick_scan_conf =
103 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
104 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
105 break;
106 default:
107 break;
108 }
109}
110
111static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb,
112 struct ath_hw_antcomb_conf *div_ant_conf,
113 int main_rssi_avg, int alt_rssi_avg,
114 int alt_ratio)
115{
116 /* alt_good */
117 switch (antcomb->quick_scan_cnt) {
118 case 0:
119 /* set alt to main, and alt to first conf */
120 div_ant_conf->main_lna_conf = antcomb->main_conf;
121 div_ant_conf->alt_lna_conf = antcomb->first_quick_scan_conf;
122 break;
123 case 1:
124 /* set alt to main, and alt to first conf */
125 div_ant_conf->main_lna_conf = antcomb->main_conf;
126 div_ant_conf->alt_lna_conf = antcomb->second_quick_scan_conf;
127 antcomb->rssi_first = main_rssi_avg;
128 antcomb->rssi_second = alt_rssi_avg;
129
130 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
131 /* main is LNA1 */
132 if (ath_is_alt_ant_ratio_better(alt_ratio,
133 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
134 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
135 main_rssi_avg, alt_rssi_avg,
136 antcomb->total_pkt_count))
137 antcomb->first_ratio = true;
138 else
139 antcomb->first_ratio = false;
140 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
141 if (ath_is_alt_ant_ratio_better(alt_ratio,
142 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
143 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
144 main_rssi_avg, alt_rssi_avg,
145 antcomb->total_pkt_count))
146 antcomb->first_ratio = true;
147 else
148 antcomb->first_ratio = false;
149 } else {
150 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
151 (alt_rssi_avg > main_rssi_avg +
152 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
153 (alt_rssi_avg > main_rssi_avg)) &&
154 (antcomb->total_pkt_count > 50))
155 antcomb->first_ratio = true;
156 else
157 antcomb->first_ratio = false;
158 }
159 break;
160 case 2:
161 antcomb->alt_good = false;
162 antcomb->scan_not_start = false;
163 antcomb->scan = false;
164 antcomb->rssi_first = main_rssi_avg;
165 antcomb->rssi_third = alt_rssi_avg;
166
167 if (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1)
168 antcomb->rssi_lna1 = alt_rssi_avg;
169 else if (antcomb->second_quick_scan_conf ==
170 ATH_ANT_DIV_COMB_LNA2)
171 antcomb->rssi_lna2 = alt_rssi_avg;
172 else if (antcomb->second_quick_scan_conf ==
173 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2) {
174 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2)
175 antcomb->rssi_lna2 = main_rssi_avg;
176 else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1)
177 antcomb->rssi_lna1 = main_rssi_avg;
178 }
179
180 if (antcomb->rssi_lna2 > antcomb->rssi_lna1 +
181 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)
182 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
183 else
184 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
185
186 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
187 if (ath_is_alt_ant_ratio_better(alt_ratio,
188 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
189 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
190 main_rssi_avg, alt_rssi_avg,
191 antcomb->total_pkt_count))
192 antcomb->second_ratio = true;
193 else
194 antcomb->second_ratio = false;
195 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
196 if (ath_is_alt_ant_ratio_better(alt_ratio,
197 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
198 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
199 main_rssi_avg, alt_rssi_avg,
200 antcomb->total_pkt_count))
201 antcomb->second_ratio = true;
202 else
203 antcomb->second_ratio = false;
204 } else {
205 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
206 (alt_rssi_avg > main_rssi_avg +
207 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
208 (alt_rssi_avg > main_rssi_avg)) &&
209 (antcomb->total_pkt_count > 50))
210 antcomb->second_ratio = true;
211 else
212 antcomb->second_ratio = false;
213 }
214
215 /* set alt to the conf with maximun ratio */
216 if (antcomb->first_ratio && antcomb->second_ratio) {
217 if (antcomb->rssi_second > antcomb->rssi_third) {
218 /* first alt*/
219 if ((antcomb->first_quick_scan_conf ==
220 ATH_ANT_DIV_COMB_LNA1) ||
221 (antcomb->first_quick_scan_conf ==
222 ATH_ANT_DIV_COMB_LNA2))
223 /* Set alt LNA1 or LNA2*/
224 if (div_ant_conf->main_lna_conf ==
225 ATH_ANT_DIV_COMB_LNA2)
226 div_ant_conf->alt_lna_conf =
227 ATH_ANT_DIV_COMB_LNA1;
228 else
229 div_ant_conf->alt_lna_conf =
230 ATH_ANT_DIV_COMB_LNA2;
231 else
232 /* Set alt to A+B or A-B */
233 div_ant_conf->alt_lna_conf =
234 antcomb->first_quick_scan_conf;
235 } else if ((antcomb->second_quick_scan_conf ==
236 ATH_ANT_DIV_COMB_LNA1) ||
237 (antcomb->second_quick_scan_conf ==
238 ATH_ANT_DIV_COMB_LNA2)) {
239 /* Set alt LNA1 or LNA2 */
240 if (div_ant_conf->main_lna_conf ==
241 ATH_ANT_DIV_COMB_LNA2)
242 div_ant_conf->alt_lna_conf =
243 ATH_ANT_DIV_COMB_LNA1;
244 else
245 div_ant_conf->alt_lna_conf =
246 ATH_ANT_DIV_COMB_LNA2;
247 } else {
248 /* Set alt to A+B or A-B */
249 div_ant_conf->alt_lna_conf =
250 antcomb->second_quick_scan_conf;
251 }
252 } else if (antcomb->first_ratio) {
253 /* first alt */
254 if ((antcomb->first_quick_scan_conf ==
255 ATH_ANT_DIV_COMB_LNA1) ||
256 (antcomb->first_quick_scan_conf ==
257 ATH_ANT_DIV_COMB_LNA2))
258 /* Set alt LNA1 or LNA2 */
259 if (div_ant_conf->main_lna_conf ==
260 ATH_ANT_DIV_COMB_LNA2)
261 div_ant_conf->alt_lna_conf =
262 ATH_ANT_DIV_COMB_LNA1;
263 else
264 div_ant_conf->alt_lna_conf =
265 ATH_ANT_DIV_COMB_LNA2;
266 else
267 /* Set alt to A+B or A-B */
268 div_ant_conf->alt_lna_conf =
269 antcomb->first_quick_scan_conf;
270 } else if (antcomb->second_ratio) {
271 /* second alt */
272 if ((antcomb->second_quick_scan_conf ==
273 ATH_ANT_DIV_COMB_LNA1) ||
274 (antcomb->second_quick_scan_conf ==
275 ATH_ANT_DIV_COMB_LNA2))
276 /* Set alt LNA1 or LNA2 */
277 if (div_ant_conf->main_lna_conf ==
278 ATH_ANT_DIV_COMB_LNA2)
279 div_ant_conf->alt_lna_conf =
280 ATH_ANT_DIV_COMB_LNA1;
281 else
282 div_ant_conf->alt_lna_conf =
283 ATH_ANT_DIV_COMB_LNA2;
284 else
285 /* Set alt to A+B or A-B */
286 div_ant_conf->alt_lna_conf =
287 antcomb->second_quick_scan_conf;
288 } else {
289 /* main is largest */
290 if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) ||
291 (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2))
292 /* Set alt LNA1 or LNA2 */
293 if (div_ant_conf->main_lna_conf ==
294 ATH_ANT_DIV_COMB_LNA2)
295 div_ant_conf->alt_lna_conf =
296 ATH_ANT_DIV_COMB_LNA1;
297 else
298 div_ant_conf->alt_lna_conf =
299 ATH_ANT_DIV_COMB_LNA2;
300 else
301 /* Set alt to A+B or A-B */
302 div_ant_conf->alt_lna_conf = antcomb->main_conf;
303 }
304 break;
305 default:
306 break;
307 }
308}
309
310static void ath_ant_div_conf_fast_divbias(struct ath_hw_antcomb_conf *ant_conf,
311 struct ath_ant_comb *antcomb,
312 int alt_ratio)
313{
314 if (ant_conf->div_group == 0) {
315 /* Adjust the fast_div_bias based on main and alt lna conf */
316 switch ((ant_conf->main_lna_conf << 4) |
317 ant_conf->alt_lna_conf) {
318 case 0x01: /* A-B LNA2 */
319 ant_conf->fast_div_bias = 0x3b;
320 break;
321 case 0x02: /* A-B LNA1 */
322 ant_conf->fast_div_bias = 0x3d;
323 break;
324 case 0x03: /* A-B A+B */
325 ant_conf->fast_div_bias = 0x1;
326 break;
327 case 0x10: /* LNA2 A-B */
328 ant_conf->fast_div_bias = 0x7;
329 break;
330 case 0x12: /* LNA2 LNA1 */
331 ant_conf->fast_div_bias = 0x2;
332 break;
333 case 0x13: /* LNA2 A+B */
334 ant_conf->fast_div_bias = 0x7;
335 break;
336 case 0x20: /* LNA1 A-B */
337 ant_conf->fast_div_bias = 0x6;
338 break;
339 case 0x21: /* LNA1 LNA2 */
340 ant_conf->fast_div_bias = 0x0;
341 break;
342 case 0x23: /* LNA1 A+B */
343 ant_conf->fast_div_bias = 0x6;
344 break;
345 case 0x30: /* A+B A-B */
346 ant_conf->fast_div_bias = 0x1;
347 break;
348 case 0x31: /* A+B LNA2 */
349 ant_conf->fast_div_bias = 0x3b;
350 break;
351 case 0x32: /* A+B LNA1 */
352 ant_conf->fast_div_bias = 0x3d;
353 break;
354 default:
355 break;
356 }
357 } else if (ant_conf->div_group == 1) {
358 /* Adjust the fast_div_bias based on main and alt_lna_conf */
359 switch ((ant_conf->main_lna_conf << 4) |
360 ant_conf->alt_lna_conf) {
361 case 0x01: /* A-B LNA2 */
362 ant_conf->fast_div_bias = 0x1;
363 ant_conf->main_gaintb = 0;
364 ant_conf->alt_gaintb = 0;
365 break;
366 case 0x02: /* A-B LNA1 */
367 ant_conf->fast_div_bias = 0x1;
368 ant_conf->main_gaintb = 0;
369 ant_conf->alt_gaintb = 0;
370 break;
371 case 0x03: /* A-B A+B */
372 ant_conf->fast_div_bias = 0x1;
373 ant_conf->main_gaintb = 0;
374 ant_conf->alt_gaintb = 0;
375 break;
376 case 0x10: /* LNA2 A-B */
377 if (!(antcomb->scan) &&
378 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
379 ant_conf->fast_div_bias = 0x3f;
380 else
381 ant_conf->fast_div_bias = 0x1;
382 ant_conf->main_gaintb = 0;
383 ant_conf->alt_gaintb = 0;
384 break;
385 case 0x12: /* LNA2 LNA1 */
386 ant_conf->fast_div_bias = 0x1;
387 ant_conf->main_gaintb = 0;
388 ant_conf->alt_gaintb = 0;
389 break;
390 case 0x13: /* LNA2 A+B */
391 if (!(antcomb->scan) &&
392 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
393 ant_conf->fast_div_bias = 0x3f;
394 else
395 ant_conf->fast_div_bias = 0x1;
396 ant_conf->main_gaintb = 0;
397 ant_conf->alt_gaintb = 0;
398 break;
399 case 0x20: /* LNA1 A-B */
400 if (!(antcomb->scan) &&
401 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
402 ant_conf->fast_div_bias = 0x3f;
403 else
404 ant_conf->fast_div_bias = 0x1;
405 ant_conf->main_gaintb = 0;
406 ant_conf->alt_gaintb = 0;
407 break;
408 case 0x21: /* LNA1 LNA2 */
409 ant_conf->fast_div_bias = 0x1;
410 ant_conf->main_gaintb = 0;
411 ant_conf->alt_gaintb = 0;
412 break;
413 case 0x23: /* LNA1 A+B */
414 if (!(antcomb->scan) &&
415 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
416 ant_conf->fast_div_bias = 0x3f;
417 else
418 ant_conf->fast_div_bias = 0x1;
419 ant_conf->main_gaintb = 0;
420 ant_conf->alt_gaintb = 0;
421 break;
422 case 0x30: /* A+B A-B */
423 ant_conf->fast_div_bias = 0x1;
424 ant_conf->main_gaintb = 0;
425 ant_conf->alt_gaintb = 0;
426 break;
427 case 0x31: /* A+B LNA2 */
428 ant_conf->fast_div_bias = 0x1;
429 ant_conf->main_gaintb = 0;
430 ant_conf->alt_gaintb = 0;
431 break;
432 case 0x32: /* A+B LNA1 */
433 ant_conf->fast_div_bias = 0x1;
434 ant_conf->main_gaintb = 0;
435 ant_conf->alt_gaintb = 0;
436 break;
437 default:
438 break;
439 }
440 } else if (ant_conf->div_group == 2) {
441 /* Adjust the fast_div_bias based on main and alt_lna_conf */
442 switch ((ant_conf->main_lna_conf << 4) |
443 ant_conf->alt_lna_conf) {
444 case 0x01: /* A-B LNA2 */
445 ant_conf->fast_div_bias = 0x1;
446 ant_conf->main_gaintb = 0;
447 ant_conf->alt_gaintb = 0;
448 break;
449 case 0x02: /* A-B LNA1 */
450 ant_conf->fast_div_bias = 0x1;
451 ant_conf->main_gaintb = 0;
452 ant_conf->alt_gaintb = 0;
453 break;
454 case 0x03: /* A-B A+B */
455 ant_conf->fast_div_bias = 0x1;
456 ant_conf->main_gaintb = 0;
457 ant_conf->alt_gaintb = 0;
458 break;
459 case 0x10: /* LNA2 A-B */
460 if (!(antcomb->scan) &&
461 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
462 ant_conf->fast_div_bias = 0x1;
463 else
464 ant_conf->fast_div_bias = 0x2;
465 ant_conf->main_gaintb = 0;
466 ant_conf->alt_gaintb = 0;
467 break;
468 case 0x12: /* LNA2 LNA1 */
469 ant_conf->fast_div_bias = 0x1;
470 ant_conf->main_gaintb = 0;
471 ant_conf->alt_gaintb = 0;
472 break;
473 case 0x13: /* LNA2 A+B */
474 if (!(antcomb->scan) &&
475 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
476 ant_conf->fast_div_bias = 0x1;
477 else
478 ant_conf->fast_div_bias = 0x2;
479 ant_conf->main_gaintb = 0;
480 ant_conf->alt_gaintb = 0;
481 break;
482 case 0x20: /* LNA1 A-B */
483 if (!(antcomb->scan) &&
484 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
485 ant_conf->fast_div_bias = 0x1;
486 else
487 ant_conf->fast_div_bias = 0x2;
488 ant_conf->main_gaintb = 0;
489 ant_conf->alt_gaintb = 0;
490 break;
491 case 0x21: /* LNA1 LNA2 */
492 ant_conf->fast_div_bias = 0x1;
493 ant_conf->main_gaintb = 0;
494 ant_conf->alt_gaintb = 0;
495 break;
496 case 0x23: /* LNA1 A+B */
497 if (!(antcomb->scan) &&
498 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
499 ant_conf->fast_div_bias = 0x1;
500 else
501 ant_conf->fast_div_bias = 0x2;
502 ant_conf->main_gaintb = 0;
503 ant_conf->alt_gaintb = 0;
504 break;
505 case 0x30: /* A+B A-B */
506 ant_conf->fast_div_bias = 0x1;
507 ant_conf->main_gaintb = 0;
508 ant_conf->alt_gaintb = 0;
509 break;
510 case 0x31: /* A+B LNA2 */
511 ant_conf->fast_div_bias = 0x1;
512 ant_conf->main_gaintb = 0;
513 ant_conf->alt_gaintb = 0;
514 break;
515 case 0x32: /* A+B LNA1 */
516 ant_conf->fast_div_bias = 0x1;
517 ant_conf->main_gaintb = 0;
518 ant_conf->alt_gaintb = 0;
519 break;
520 default:
521 break;
522 }
523 }
524}
525
526void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs)
527{
528 struct ath_hw_antcomb_conf div_ant_conf;
529 struct ath_ant_comb *antcomb = &sc->ant_comb;
530 int alt_ratio = 0, alt_rssi_avg = 0, main_rssi_avg = 0, curr_alt_set;
531 int curr_main_set;
532 int main_rssi = rs->rs_rssi_ctl0;
533 int alt_rssi = rs->rs_rssi_ctl1;
534 int rx_ant_conf, main_ant_conf;
535 bool short_scan = false;
536
537 rx_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_CURRENT_SHIFT) &
538 ATH_ANT_RX_MASK;
539 main_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_MAIN_SHIFT) &
540 ATH_ANT_RX_MASK;
541
542 /* Record packet only when both main_rssi and alt_rssi is positive */
543 if (main_rssi > 0 && alt_rssi > 0) {
544 antcomb->total_pkt_count++;
545 antcomb->main_total_rssi += main_rssi;
546 antcomb->alt_total_rssi += alt_rssi;
547 if (main_ant_conf == rx_ant_conf)
548 antcomb->main_recv_cnt++;
549 else
550 antcomb->alt_recv_cnt++;
551 }
552
553 /* Short scan check */
554 if (antcomb->scan && antcomb->alt_good) {
555 if (time_after(jiffies, antcomb->scan_start_time +
556 msecs_to_jiffies(ATH_ANT_DIV_COMB_SHORT_SCAN_INTR)))
557 short_scan = true;
558 else
559 if (antcomb->total_pkt_count ==
560 ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT) {
561 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
562 antcomb->total_pkt_count);
563 if (alt_ratio < ATH_ANT_DIV_COMB_ALT_ANT_RATIO)
564 short_scan = true;
565 }
566 }
567
568 if (((antcomb->total_pkt_count < ATH_ANT_DIV_COMB_MAX_PKTCOUNT) ||
569 rs->rs_moreaggr) && !short_scan)
570 return;
571
572 if (antcomb->total_pkt_count) {
573 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
574 antcomb->total_pkt_count);
575 main_rssi_avg = (antcomb->main_total_rssi /
576 antcomb->total_pkt_count);
577 alt_rssi_avg = (antcomb->alt_total_rssi /
578 antcomb->total_pkt_count);
579 }
580
581
582 ath9k_hw_antdiv_comb_conf_get(sc->sc_ah, &div_ant_conf);
583 curr_alt_set = div_ant_conf.alt_lna_conf;
584 curr_main_set = div_ant_conf.main_lna_conf;
585
586 antcomb->count++;
587
588 if (antcomb->count == ATH_ANT_DIV_COMB_MAX_COUNT) {
589 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
590 ath_lnaconf_alt_good_scan(antcomb, div_ant_conf,
591 main_rssi_avg);
592 antcomb->alt_good = true;
593 } else {
594 antcomb->alt_good = false;
595 }
596
597 antcomb->count = 0;
598 antcomb->scan = true;
599 antcomb->scan_not_start = true;
600 }
601
602 if (!antcomb->scan) {
603 if (ath_ant_div_comb_alt_check(div_ant_conf.div_group,
604 alt_ratio, curr_main_set, curr_alt_set,
605 alt_rssi_avg, main_rssi_avg)) {
606 if (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) {
607 /* Switch main and alt LNA */
608 div_ant_conf.main_lna_conf =
609 ATH_ANT_DIV_COMB_LNA2;
610 div_ant_conf.alt_lna_conf =
611 ATH_ANT_DIV_COMB_LNA1;
612 } else if (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) {
613 div_ant_conf.main_lna_conf =
614 ATH_ANT_DIV_COMB_LNA1;
615 div_ant_conf.alt_lna_conf =
616 ATH_ANT_DIV_COMB_LNA2;
617 }
618
619 goto div_comb_done;
620 } else if ((curr_alt_set != ATH_ANT_DIV_COMB_LNA1) &&
621 (curr_alt_set != ATH_ANT_DIV_COMB_LNA2)) {
622 /* Set alt to another LNA */
623 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2)
624 div_ant_conf.alt_lna_conf =
625 ATH_ANT_DIV_COMB_LNA1;
626 else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1)
627 div_ant_conf.alt_lna_conf =
628 ATH_ANT_DIV_COMB_LNA2;
629
630 goto div_comb_done;
631 }
632
633 if ((alt_rssi_avg < (main_rssi_avg +
634 div_ant_conf.lna1_lna2_delta)))
635 goto div_comb_done;
636 }
637
638 if (!antcomb->scan_not_start) {
639 switch (curr_alt_set) {
640 case ATH_ANT_DIV_COMB_LNA2:
641 antcomb->rssi_lna2 = alt_rssi_avg;
642 antcomb->rssi_lna1 = main_rssi_avg;
643 antcomb->scan = true;
644 /* set to A+B */
645 div_ant_conf.main_lna_conf =
646 ATH_ANT_DIV_COMB_LNA1;
647 div_ant_conf.alt_lna_conf =
648 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
649 break;
650 case ATH_ANT_DIV_COMB_LNA1:
651 antcomb->rssi_lna1 = alt_rssi_avg;
652 antcomb->rssi_lna2 = main_rssi_avg;
653 antcomb->scan = true;
654 /* set to A+B */
655 div_ant_conf.main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
656 div_ant_conf.alt_lna_conf =
657 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
658 break;
659 case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
660 antcomb->rssi_add = alt_rssi_avg;
661 antcomb->scan = true;
662 /* set to A-B */
663 div_ant_conf.alt_lna_conf =
664 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
665 break;
666 case ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2:
667 antcomb->rssi_sub = alt_rssi_avg;
668 antcomb->scan = false;
669 if (antcomb->rssi_lna2 >
670 (antcomb->rssi_lna1 +
671 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) {
672 /* use LNA2 as main LNA */
673 if ((antcomb->rssi_add > antcomb->rssi_lna1) &&
674 (antcomb->rssi_add > antcomb->rssi_sub)) {
675 /* set to A+B */
676 div_ant_conf.main_lna_conf =
677 ATH_ANT_DIV_COMB_LNA2;
678 div_ant_conf.alt_lna_conf =
679 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
680 } else if (antcomb->rssi_sub >
681 antcomb->rssi_lna1) {
682 /* set to A-B */
683 div_ant_conf.main_lna_conf =
684 ATH_ANT_DIV_COMB_LNA2;
685 div_ant_conf.alt_lna_conf =
686 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
687 } else {
688 /* set to LNA1 */
689 div_ant_conf.main_lna_conf =
690 ATH_ANT_DIV_COMB_LNA2;
691 div_ant_conf.alt_lna_conf =
692 ATH_ANT_DIV_COMB_LNA1;
693 }
694 } else {
695 /* use LNA1 as main LNA */
696 if ((antcomb->rssi_add > antcomb->rssi_lna2) &&
697 (antcomb->rssi_add > antcomb->rssi_sub)) {
698 /* set to A+B */
699 div_ant_conf.main_lna_conf =
700 ATH_ANT_DIV_COMB_LNA1;
701 div_ant_conf.alt_lna_conf =
702 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
703 } else if (antcomb->rssi_sub >
704 antcomb->rssi_lna1) {
705 /* set to A-B */
706 div_ant_conf.main_lna_conf =
707 ATH_ANT_DIV_COMB_LNA1;
708 div_ant_conf.alt_lna_conf =
709 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
710 } else {
711 /* set to LNA2 */
712 div_ant_conf.main_lna_conf =
713 ATH_ANT_DIV_COMB_LNA1;
714 div_ant_conf.alt_lna_conf =
715 ATH_ANT_DIV_COMB_LNA2;
716 }
717 }
718 break;
719 default:
720 break;
721 }
722 } else {
723 if (!antcomb->alt_good) {
724 antcomb->scan_not_start = false;
725 /* Set alt to another LNA */
726 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2) {
727 div_ant_conf.main_lna_conf =
728 ATH_ANT_DIV_COMB_LNA2;
729 div_ant_conf.alt_lna_conf =
730 ATH_ANT_DIV_COMB_LNA1;
731 } else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1) {
732 div_ant_conf.main_lna_conf =
733 ATH_ANT_DIV_COMB_LNA1;
734 div_ant_conf.alt_lna_conf =
735 ATH_ANT_DIV_COMB_LNA2;
736 }
737 goto div_comb_done;
738 }
739 }
740
741 ath_select_ant_div_from_quick_scan(antcomb, &div_ant_conf,
742 main_rssi_avg, alt_rssi_avg,
743 alt_ratio);
744
745 antcomb->quick_scan_cnt++;
746
747div_comb_done:
748 ath_ant_div_conf_fast_divbias(&div_ant_conf, antcomb, alt_ratio);
749 ath9k_hw_antdiv_comb_conf_set(sc->sc_ah, &div_ant_conf);
750
751 antcomb->scan_start_time = jiffies;
752 antcomb->total_pkt_count = 0;
753 antcomb->main_total_rssi = 0;
754 antcomb->alt_total_rssi = 0;
755 antcomb->main_recv_cnt = 0;
756 antcomb->alt_recv_cnt = 0;
757}
758
759void ath_ant_comb_update(struct ath_softc *sc)
760{
761 struct ath_hw *ah = sc->sc_ah;
762 struct ath_hw_antcomb_conf div_ant_conf;
763 u8 lna_conf;
764
765 ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
766
767 if (sc->ant_rx == 1)
768 lna_conf = ATH_ANT_DIV_COMB_LNA1;
769 else
770 lna_conf = ATH_ANT_DIV_COMB_LNA2;
771
772 div_ant_conf.main_lna_conf = lna_conf;
773 div_ant_conf.alt_lna_conf = lna_conf;
774
775 ath9k_hw_antdiv_comb_conf_set(ah, &div_ant_conf);
776}
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_calib.c b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
index 9fdd70fcaf5b..d7deb8c9f299 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c
@@ -653,7 +653,6 @@ static void ar9003_hw_detect_outlier(int *mp_coeff, int nmeasurement,
653} 653}
654 654
655static void ar9003_hw_tx_iqcal_load_avg_2_passes(struct ath_hw *ah, 655static void ar9003_hw_tx_iqcal_load_avg_2_passes(struct ath_hw *ah,
656 u8 num_chains,
657 struct coeff *coeff, 656 struct coeff *coeff,
658 bool is_reusable) 657 bool is_reusable)
659{ 658{
@@ -677,7 +676,9 @@ static void ar9003_hw_tx_iqcal_load_avg_2_passes(struct ath_hw *ah,
677 } 676 }
678 677
679 /* Load the average of 2 passes */ 678 /* Load the average of 2 passes */
680 for (i = 0; i < num_chains; i++) { 679 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
680 if (!(ah->txchainmask & (1 << i)))
681 continue;
681 nmeasurement = REG_READ_FIELD(ah, 682 nmeasurement = REG_READ_FIELD(ah,
682 AR_PHY_TX_IQCAL_STATUS_B0, 683 AR_PHY_TX_IQCAL_STATUS_B0,
683 AR_PHY_CALIBRATED_GAINS_0); 684 AR_PHY_CALIBRATED_GAINS_0);
@@ -767,16 +768,13 @@ static void ar9003_hw_tx_iq_cal_post_proc(struct ath_hw *ah, bool is_reusable)
767 }; 768 };
768 struct coeff coeff; 769 struct coeff coeff;
769 s32 iq_res[6]; 770 s32 iq_res[6];
770 u8 num_chains = 0;
771 int i, im, j; 771 int i, im, j;
772 int nmeasurement; 772 int nmeasurement;
773 773
774 for (i = 0; i < AR9300_MAX_CHAINS; i++) { 774 for (i = 0; i < AR9300_MAX_CHAINS; i++) {
775 if (ah->txchainmask & (1 << i)) 775 if (!(ah->txchainmask & (1 << i)))
776 num_chains++; 776 continue;
777 }
778 777
779 for (i = 0; i < num_chains; i++) {
780 nmeasurement = REG_READ_FIELD(ah, 778 nmeasurement = REG_READ_FIELD(ah,
781 AR_PHY_TX_IQCAL_STATUS_B0, 779 AR_PHY_TX_IQCAL_STATUS_B0,
782 AR_PHY_CALIBRATED_GAINS_0); 780 AR_PHY_CALIBRATED_GAINS_0);
@@ -839,8 +837,7 @@ static void ar9003_hw_tx_iq_cal_post_proc(struct ath_hw *ah, bool is_reusable)
839 coeff.phs_coeff[i][im] -= 128; 837 coeff.phs_coeff[i][im] -= 128;
840 } 838 }
841 } 839 }
842 ar9003_hw_tx_iqcal_load_avg_2_passes(ah, num_chains, 840 ar9003_hw_tx_iqcal_load_avg_2_passes(ah, &coeff, is_reusable);
843 &coeff, is_reusable);
844 841
845 return; 842 return;
846 843
@@ -901,7 +898,6 @@ static bool ar9003_hw_init_cal(struct ath_hw *ah,
901 bool is_reusable = true, status = true; 898 bool is_reusable = true, status = true;
902 bool run_rtt_cal = false, run_agc_cal; 899 bool run_rtt_cal = false, run_agc_cal;
903 bool rtt = !!(ah->caps.hw_caps & ATH9K_HW_CAP_RTT); 900 bool rtt = !!(ah->caps.hw_caps & ATH9K_HW_CAP_RTT);
904 bool mci = !!(ah->caps.hw_caps & ATH9K_HW_CAP_MCI);
905 u32 agc_ctrl = 0, agc_supp_cals = AR_PHY_AGC_CONTROL_OFFSET_CAL | 901 u32 agc_ctrl = 0, agc_supp_cals = AR_PHY_AGC_CONTROL_OFFSET_CAL |
906 AR_PHY_AGC_CONTROL_FLTR_CAL | 902 AR_PHY_AGC_CONTROL_FLTR_CAL |
907 AR_PHY_AGC_CONTROL_PKDET_CAL; 903 AR_PHY_AGC_CONTROL_PKDET_CAL;
@@ -970,7 +966,7 @@ static bool ar9003_hw_init_cal(struct ath_hw *ah,
970 } else if (caldata && !caldata->done_txiqcal_once) 966 } else if (caldata && !caldata->done_txiqcal_once)
971 run_agc_cal = true; 967 run_agc_cal = true;
972 968
973 if (mci && IS_CHAN_2GHZ(chan) && run_agc_cal) 969 if (ath9k_hw_mci_is_enabled(ah) && IS_CHAN_2GHZ(chan) && run_agc_cal)
974 ar9003_mci_init_cal_req(ah, &is_reusable); 970 ar9003_mci_init_cal_req(ah, &is_reusable);
975 971
976 if (!(IS_CHAN_HALF_RATE(chan) || IS_CHAN_QUARTER_RATE(chan))) { 972 if (!(IS_CHAN_HALF_RATE(chan) || IS_CHAN_QUARTER_RATE(chan))) {
@@ -993,7 +989,7 @@ skip_tx_iqcal:
993 0, AH_WAIT_TIMEOUT); 989 0, AH_WAIT_TIMEOUT);
994 } 990 }
995 991
996 if (mci && IS_CHAN_2GHZ(chan) && run_agc_cal) 992 if (ath9k_hw_mci_is_enabled(ah) && IS_CHAN_2GHZ(chan) && run_agc_cal)
997 ar9003_mci_init_cal_done(ah); 993 ar9003_mci_init_cal_done(ah);
998 994
999 if (rtt && !run_rtt_cal) { 995 if (rtt && !run_rtt_cal) {
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
index dfb0441f406c..2cdf82bdb11d 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
@@ -3412,11 +3412,11 @@ static u32 ath9k_hw_ar9003_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
3412 if (!dump_base_hdr) { 3412 if (!dump_base_hdr) {
3413 len += snprintf(buf + len, size - len, 3413 len += snprintf(buf + len, size - len,
3414 "%20s :\n", "2GHz modal Header"); 3414 "%20s :\n", "2GHz modal Header");
3415 len += ar9003_dump_modal_eeprom(buf, len, size, 3415 len = ar9003_dump_modal_eeprom(buf, len, size,
3416 &eep->modalHeader2G); 3416 &eep->modalHeader2G);
3417 len += snprintf(buf + len, size - len, 3417 len += snprintf(buf + len, size - len,
3418 "%20s :\n", "5GHz modal Header"); 3418 "%20s :\n", "5GHz modal Header");
3419 len += ar9003_dump_modal_eeprom(buf, len, size, 3419 len = ar9003_dump_modal_eeprom(buf, len, size,
3420 &eep->modalHeader5G); 3420 &eep->modalHeader5G);
3421 goto out; 3421 goto out;
3422 } 3422 }
@@ -3613,6 +3613,7 @@ static void ar9003_hw_ant_ctrl_apply(struct ath_hw *ah, bool is2ghz)
3613 value = ar9003_switch_com_spdt_get(ah, is2ghz); 3613 value = ar9003_switch_com_spdt_get(ah, is2ghz);
3614 REG_RMW_FIELD(ah, AR_PHY_GLB_CONTROL, 3614 REG_RMW_FIELD(ah, AR_PHY_GLB_CONTROL,
3615 AR_SWITCH_TABLE_COM_SPDT_ALL, value); 3615 AR_SWITCH_TABLE_COM_SPDT_ALL, value);
3616 REG_SET_BIT(ah, AR_PHY_GLB_CONTROL, AR_BTCOEX_CTRL_SPDT_ENABLE);
3616 } 3617 }
3617 3618
3618 value = ar9003_hw_ant_ctrl_common_2_get(ah, is2ghz); 3619 value = ar9003_hw_ant_ctrl_common_2_get(ah, is2ghz);
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
index d9e0824af093..78816b8b2173 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
@@ -181,11 +181,14 @@ static bool ar9003_hw_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
181 u32 mask2 = 0; 181 u32 mask2 = 0;
182 struct ath9k_hw_capabilities *pCap = &ah->caps; 182 struct ath9k_hw_capabilities *pCap = &ah->caps;
183 struct ath_common *common = ath9k_hw_common(ah); 183 struct ath_common *common = ath9k_hw_common(ah);
184 u32 sync_cause = 0, async_cause; 184 u32 sync_cause = 0, async_cause, async_mask = AR_INTR_MAC_IRQ;
185
186 if (ath9k_hw_mci_is_enabled(ah))
187 async_mask |= AR_INTR_ASYNC_MASK_MCI;
185 188
186 async_cause = REG_READ(ah, AR_INTR_ASYNC_CAUSE); 189 async_cause = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
187 190
188 if (async_cause & (AR_INTR_MAC_IRQ | AR_INTR_ASYNC_MASK_MCI)) { 191 if (async_cause & async_mask) {
189 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M) 192 if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
190 == AR_RTC_STATUS_ON) 193 == AR_RTC_STATUS_ON)
191 isr = REG_READ(ah, AR_ISR); 194 isr = REG_READ(ah, AR_ISR);
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mci.c b/drivers/net/wireless/ath/ath9k/ar9003_mci.c
index ffbb180f91e1..cc2853ade8f8 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_mci.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_mci.c
@@ -35,31 +35,30 @@ static int ar9003_mci_wait_for_interrupt(struct ath_hw *ah, u32 address,
35 struct ath_common *common = ath9k_hw_common(ah); 35 struct ath_common *common = ath9k_hw_common(ah);
36 36
37 while (time_out) { 37 while (time_out) {
38 if (REG_READ(ah, address) & bit_position) { 38 if (!(REG_READ(ah, address) & bit_position)) {
39 REG_WRITE(ah, address, bit_position); 39 udelay(10);
40 40 time_out -= 10;
41 if (address == AR_MCI_INTERRUPT_RX_MSG_RAW) {
42 if (bit_position &
43 AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE)
44 ar9003_mci_reset_req_wakeup(ah);
45
46 if (bit_position &
47 (AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING |
48 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING))
49 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
50 AR_MCI_INTERRUPT_REMOTE_SLEEP_UPDATE);
51
52 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
53 AR_MCI_INTERRUPT_RX_MSG);
54 }
55 break;
56 }
57 41
58 udelay(10); 42 if (time_out < 0)
59 time_out -= 10; 43 break;
44 else
45 continue;
46 }
47 REG_WRITE(ah, address, bit_position);
60 48
61 if (time_out < 0) 49 if (address != AR_MCI_INTERRUPT_RX_MSG_RAW)
62 break; 50 break;
51
52 if (bit_position & AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE)
53 ar9003_mci_reset_req_wakeup(ah);
54
55 if (bit_position & (AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING |
56 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING))
57 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
58 AR_MCI_INTERRUPT_REMOTE_SLEEP_UPDATE);
59
60 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW, AR_MCI_INTERRUPT_RX_MSG);
61 break;
63 } 62 }
64 63
65 if (time_out <= 0) { 64 if (time_out <= 0) {
@@ -127,14 +126,13 @@ static void ar9003_mci_send_coex_version_query(struct ath_hw *ah,
127 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci; 126 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
128 u32 payload[4] = {0, 0, 0, 0}; 127 u32 payload[4] = {0, 0, 0, 0};
129 128
130 if (!mci->bt_version_known && 129 if (mci->bt_version_known ||
131 (mci->bt_state != MCI_BT_SLEEP)) { 130 (mci->bt_state == MCI_BT_SLEEP))
132 MCI_GPM_SET_TYPE_OPCODE(payload, 131 return;
133 MCI_GPM_COEX_AGENT, 132
134 MCI_GPM_COEX_VERSION_QUERY); 133 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
135 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, 134 MCI_GPM_COEX_VERSION_QUERY);
136 wait_done, true); 135 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
137 }
138} 136}
139 137
140static void ar9003_mci_send_coex_version_response(struct ath_hw *ah, 138static void ar9003_mci_send_coex_version_response(struct ath_hw *ah,
@@ -158,15 +156,14 @@ static void ar9003_mci_send_coex_wlan_channels(struct ath_hw *ah,
158 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci; 156 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
159 u32 *payload = &mci->wlan_channels[0]; 157 u32 *payload = &mci->wlan_channels[0];
160 158
161 if ((mci->wlan_channels_update == true) && 159 if (!mci->wlan_channels_update ||
162 (mci->bt_state != MCI_BT_SLEEP)) { 160 (mci->bt_state == MCI_BT_SLEEP))
163 MCI_GPM_SET_TYPE_OPCODE(payload, 161 return;
164 MCI_GPM_COEX_AGENT, 162
165 MCI_GPM_COEX_WLAN_CHANNELS); 163 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
166 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, 164 MCI_GPM_COEX_WLAN_CHANNELS);
167 wait_done, true); 165 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
168 MCI_GPM_SET_TYPE_OPCODE(payload, 0xff, 0xff); 166 MCI_GPM_SET_TYPE_OPCODE(payload, 0xff, 0xff);
169 }
170} 167}
171 168
172static void ar9003_mci_send_coex_bt_status_query(struct ath_hw *ah, 169static void ar9003_mci_send_coex_bt_status_query(struct ath_hw *ah,
@@ -174,29 +171,30 @@ static void ar9003_mci_send_coex_bt_status_query(struct ath_hw *ah,
174{ 171{
175 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci; 172 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
176 u32 payload[4] = {0, 0, 0, 0}; 173 u32 payload[4] = {0, 0, 0, 0};
177 bool query_btinfo = !!(query_type & (MCI_GPM_COEX_QUERY_BT_ALL_INFO | 174 bool query_btinfo;
178 MCI_GPM_COEX_QUERY_BT_TOPOLOGY));
179 175
180 if (mci->bt_state != MCI_BT_SLEEP) { 176 if (mci->bt_state == MCI_BT_SLEEP)
177 return;
181 178
182 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT, 179 query_btinfo = !!(query_type & (MCI_GPM_COEX_QUERY_BT_ALL_INFO |
183 MCI_GPM_COEX_STATUS_QUERY); 180 MCI_GPM_COEX_QUERY_BT_TOPOLOGY));
181 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
182 MCI_GPM_COEX_STATUS_QUERY);
184 183
185 *(((u8 *)payload) + MCI_GPM_COEX_B_BT_BITMAP) = query_type; 184 *(((u8 *)payload) + MCI_GPM_COEX_B_BT_BITMAP) = query_type;
186
187 /*
188 * If bt_status_query message is not sent successfully,
189 * then need_flush_btinfo should be set again.
190 */
191 if (!ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16,
192 wait_done, true)) {
193 if (query_btinfo)
194 mci->need_flush_btinfo = true;
195 }
196 185
186 /*
187 * If bt_status_query message is not sent successfully,
188 * then need_flush_btinfo should be set again.
189 */
190 if (!ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16,
191 wait_done, true)) {
197 if (query_btinfo) 192 if (query_btinfo)
198 mci->query_bt = false; 193 mci->need_flush_btinfo = true;
199 } 194 }
195
196 if (query_btinfo)
197 mci->query_bt = false;
200} 198}
201 199
202static void ar9003_mci_send_coex_halt_bt_gpm(struct ath_hw *ah, bool halt, 200static void ar9003_mci_send_coex_halt_bt_gpm(struct ath_hw *ah, bool halt,
@@ -241,73 +239,73 @@ static void ar9003_mci_prep_interface(struct ath_hw *ah)
241 ar9003_mci_remote_reset(ah, true); 239 ar9003_mci_remote_reset(ah, true);
242 ar9003_mci_send_req_wake(ah, true); 240 ar9003_mci_send_req_wake(ah, true);
243 241
244 if (ar9003_mci_wait_for_interrupt(ah, AR_MCI_INTERRUPT_RX_MSG_RAW, 242 if (!ar9003_mci_wait_for_interrupt(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
245 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING, 500)) { 243 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING, 500))
244 goto clear_redunt;
246 245
247 mci->bt_state = MCI_BT_AWAKE; 246 mci->bt_state = MCI_BT_AWAKE;
248 247
249 /* 248 /*
250 * we don't need to send more remote_reset at this moment. 249 * we don't need to send more remote_reset at this moment.
251 * If BT receive first remote_reset, then BT HW will 250 * If BT receive first remote_reset, then BT HW will
252 * be cleaned up and will be able to receive req_wake 251 * be cleaned up and will be able to receive req_wake
253 * and BT HW will respond sys_waking. 252 * and BT HW will respond sys_waking.
254 * In this case, WLAN will receive BT's HW sys_waking. 253 * In this case, WLAN will receive BT's HW sys_waking.
255 * Otherwise, if BT SW missed initial remote_reset, 254 * Otherwise, if BT SW missed initial remote_reset,
256 * that remote_reset will still clean up BT MCI RX, 255 * that remote_reset will still clean up BT MCI RX,
257 * and the req_wake will wake BT up, 256 * and the req_wake will wake BT up,
258 * and BT SW will respond this req_wake with a remote_reset and 257 * and BT SW will respond this req_wake with a remote_reset and
259 * sys_waking. In this case, WLAN will receive BT's SW 258 * sys_waking. In this case, WLAN will receive BT's SW
260 * sys_waking. In either case, BT's RX is cleaned up. So we 259 * sys_waking. In either case, BT's RX is cleaned up. So we
261 * don't need to reply BT's remote_reset now, if any. 260 * don't need to reply BT's remote_reset now, if any.
262 * Similarly, if in any case, WLAN can receive BT's sys_waking, 261 * Similarly, if in any case, WLAN can receive BT's sys_waking,
263 * that means WLAN's RX is also fine. 262 * that means WLAN's RX is also fine.
264 */ 263 */
265 ar9003_mci_send_sys_waking(ah, true); 264 ar9003_mci_send_sys_waking(ah, true);
266 udelay(10); 265 udelay(10);
267 266
268 /* 267 /*
269 * Set BT priority interrupt value to be 0xff to 268 * Set BT priority interrupt value to be 0xff to
270 * avoid having too many BT PRIORITY interrupts. 269 * avoid having too many BT PRIORITY interrupts.
271 */ 270 */
272 REG_WRITE(ah, AR_MCI_BT_PRI0, 0xFFFFFFFF); 271 REG_WRITE(ah, AR_MCI_BT_PRI0, 0xFFFFFFFF);
273 REG_WRITE(ah, AR_MCI_BT_PRI1, 0xFFFFFFFF); 272 REG_WRITE(ah, AR_MCI_BT_PRI1, 0xFFFFFFFF);
274 REG_WRITE(ah, AR_MCI_BT_PRI2, 0xFFFFFFFF); 273 REG_WRITE(ah, AR_MCI_BT_PRI2, 0xFFFFFFFF);
275 REG_WRITE(ah, AR_MCI_BT_PRI3, 0xFFFFFFFF); 274 REG_WRITE(ah, AR_MCI_BT_PRI3, 0xFFFFFFFF);
276 REG_WRITE(ah, AR_MCI_BT_PRI, 0X000000FF); 275 REG_WRITE(ah, AR_MCI_BT_PRI, 0X000000FF);
277 276
278 /* 277 /*
279 * A contention reset will be received after send out 278 * A contention reset will be received after send out
280 * sys_waking. Also BT priority interrupt bits will be set. 279 * sys_waking. Also BT priority interrupt bits will be set.
281 * Clear those bits before the next step. 280 * Clear those bits before the next step.
282 */ 281 */
283 282
284 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW, 283 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
285 AR_MCI_INTERRUPT_RX_MSG_CONT_RST); 284 AR_MCI_INTERRUPT_RX_MSG_CONT_RST);
286 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW, 285 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW, AR_MCI_INTERRUPT_BT_PRI);
287 AR_MCI_INTERRUPT_BT_PRI);
288 286
289 if (mci->is_2g) { 287 if (mci->is_2g) {
290 ar9003_mci_send_lna_transfer(ah, true); 288 ar9003_mci_send_lna_transfer(ah, true);
291 udelay(5); 289 udelay(5);
292 } 290 }
293 291
294 if ((mci->is_2g && !mci->update_2g5g)) { 292 if ((mci->is_2g && !mci->update_2g5g)) {
295 if (ar9003_mci_wait_for_interrupt(ah, 293 if (ar9003_mci_wait_for_interrupt(ah,
296 AR_MCI_INTERRUPT_RX_MSG_RAW, 294 AR_MCI_INTERRUPT_RX_MSG_RAW,
297 AR_MCI_INTERRUPT_RX_MSG_LNA_INFO, 295 AR_MCI_INTERRUPT_RX_MSG_LNA_INFO,
298 mci_timeout)) 296 mci_timeout))
299 ath_dbg(common, MCI, 297 ath_dbg(common, MCI,
300 "MCI WLAN has control over the LNA & BT obeys it\n"); 298 "MCI WLAN has control over the LNA & BT obeys it\n");
301 else 299 else
302 ath_dbg(common, MCI, 300 ath_dbg(common, MCI,
303 "MCI BT didn't respond to LNA_TRANS\n"); 301 "MCI BT didn't respond to LNA_TRANS\n");
304 }
305 } 302 }
306 303
304clear_redunt:
307 /* Clear the extra redundant SYS_WAKING from BT */ 305 /* Clear the extra redundant SYS_WAKING from BT */
308 if ((mci->bt_state == MCI_BT_AWAKE) && 306 if ((mci->bt_state == MCI_BT_AWAKE) &&
309 (REG_READ_FIELD(ah, AR_MCI_INTERRUPT_RX_MSG_RAW, 307 (REG_READ_FIELD(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
310 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING)) && 308 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING)) &&
311 (REG_READ_FIELD(ah, AR_MCI_INTERRUPT_RX_MSG_RAW, 309 (REG_READ_FIELD(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
312 AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) == 0)) { 310 AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) == 0)) {
313 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW, 311 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
@@ -323,14 +321,13 @@ void ar9003_mci_set_full_sleep(struct ath_hw *ah)
323{ 321{
324 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci; 322 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
325 323
326 if (ar9003_mci_state(ah, MCI_STATE_ENABLE, NULL) && 324 if (ar9003_mci_state(ah, MCI_STATE_ENABLE) &&
327 (mci->bt_state != MCI_BT_SLEEP) && 325 (mci->bt_state != MCI_BT_SLEEP) &&
328 !mci->halted_bt_gpm) { 326 !mci->halted_bt_gpm) {
329 ar9003_mci_send_coex_halt_bt_gpm(ah, true, true); 327 ar9003_mci_send_coex_halt_bt_gpm(ah, true, true);
330 } 328 }
331 329
332 mci->ready = false; 330 mci->ready = false;
333 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
334} 331}
335 332
336static void ar9003_mci_disable_interrupt(struct ath_hw *ah) 333static void ar9003_mci_disable_interrupt(struct ath_hw *ah)
@@ -487,7 +484,7 @@ static void ar9003_mci_sync_bt_state(struct ath_hw *ah)
487 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci; 484 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
488 u32 cur_bt_state; 485 u32 cur_bt_state;
489 486
490 cur_bt_state = ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP, NULL); 487 cur_bt_state = ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP);
491 488
492 if (mci->bt_state != cur_bt_state) 489 if (mci->bt_state != cur_bt_state)
493 mci->bt_state = cur_bt_state; 490 mci->bt_state = cur_bt_state;
@@ -596,8 +593,7 @@ static u32 ar9003_mci_wait_for_gpm(struct ath_hw *ah, u8 gpm_type,
596 if (!time_out) 593 if (!time_out)
597 break; 594 break;
598 595
599 offset = ar9003_mci_state(ah, MCI_STATE_NEXT_GPM_OFFSET, 596 offset = ar9003_mci_get_next_gpm_offset(ah, false, &more_data);
600 &more_data);
601 597
602 if (offset == MCI_GPM_INVALID) 598 if (offset == MCI_GPM_INVALID)
603 continue; 599 continue;
@@ -615,9 +611,9 @@ static u32 ar9003_mci_wait_for_gpm(struct ath_hw *ah, u8 gpm_type,
615 } 611 }
616 break; 612 break;
617 } 613 }
618 } else if ((recv_type == gpm_type) && (recv_opcode == gpm_opcode)) { 614 } else if ((recv_type == gpm_type) &&
615 (recv_opcode == gpm_opcode))
619 break; 616 break;
620 }
621 617
622 /* 618 /*
623 * check if it's cal_grant 619 * check if it's cal_grant
@@ -661,8 +657,7 @@ static u32 ar9003_mci_wait_for_gpm(struct ath_hw *ah, u8 gpm_type,
661 time_out = 0; 657 time_out = 0;
662 658
663 while (more_data == MCI_GPM_MORE) { 659 while (more_data == MCI_GPM_MORE) {
664 offset = ar9003_mci_state(ah, MCI_STATE_NEXT_GPM_OFFSET, 660 offset = ar9003_mci_get_next_gpm_offset(ah, false, &more_data);
665 &more_data);
666 if (offset == MCI_GPM_INVALID) 661 if (offset == MCI_GPM_INVALID)
667 break; 662 break;
668 663
@@ -731,38 +726,38 @@ int ar9003_mci_end_reset(struct ath_hw *ah, struct ath9k_channel *chan,
731 if (!IS_CHAN_2GHZ(chan) || (mci_hw->bt_state != MCI_BT_SLEEP)) 726 if (!IS_CHAN_2GHZ(chan) || (mci_hw->bt_state != MCI_BT_SLEEP))
732 goto exit; 727 goto exit;
733 728
734 if (ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET) || 729 if (!ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET) &&
735 ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE)) { 730 !ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE))
731 goto exit;
736 732
737 /* 733 /*
738 * BT is sleeping. Check if BT wakes up during 734 * BT is sleeping. Check if BT wakes up during
739 * WLAN calibration. If BT wakes up during 735 * WLAN calibration. If BT wakes up during
740 * WLAN calibration, need to go through all 736 * WLAN calibration, need to go through all
741 * message exchanges again and recal. 737 * message exchanges again and recal.
742 */ 738 */
743 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW, 739 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
744 AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET | 740 (AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET |
745 AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE); 741 AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE));
746 742
747 ar9003_mci_remote_reset(ah, true); 743 ar9003_mci_remote_reset(ah, true);
748 ar9003_mci_send_sys_waking(ah, true); 744 ar9003_mci_send_sys_waking(ah, true);
749 udelay(1); 745 udelay(1);
750 746
751 if (IS_CHAN_2GHZ(chan)) 747 if (IS_CHAN_2GHZ(chan))
752 ar9003_mci_send_lna_transfer(ah, true); 748 ar9003_mci_send_lna_transfer(ah, true);
753 749
754 mci_hw->bt_state = MCI_BT_AWAKE; 750 mci_hw->bt_state = MCI_BT_AWAKE;
755 751
756 if (caldata) { 752 if (caldata) {
757 caldata->done_txiqcal_once = false; 753 caldata->done_txiqcal_once = false;
758 caldata->done_txclcal_once = false; 754 caldata->done_txclcal_once = false;
759 caldata->rtt_done = false; 755 caldata->rtt_done = false;
760 } 756 }
761 757
762 if (!ath9k_hw_init_cal(ah, chan)) 758 if (!ath9k_hw_init_cal(ah, chan))
763 return -EIO; 759 return -EIO;
764 760
765 }
766exit: 761exit:
767 ar9003_mci_enable_interrupt(ah); 762 ar9003_mci_enable_interrupt(ah);
768 return 0; 763 return 0;
@@ -798,29 +793,27 @@ static void ar9003_mci_osla_setup(struct ath_hw *ah, bool enable)
798 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci; 793 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
799 u32 thresh; 794 u32 thresh;
800 795
801 if (enable) { 796 if (!enable) {
802 REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2,
803 AR_MCI_SCHD_TABLE_2_HW_BASED, 1);
804 REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2,
805 AR_MCI_SCHD_TABLE_2_MEM_BASED, 1);
806
807 if (!(mci->config & ATH_MCI_CONFIG_DISABLE_AGGR_THRESH)) {
808 thresh = MS(mci->config, ATH_MCI_CONFIG_AGGR_THRESH);
809 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
810 AR_BTCOEX_CTRL_AGGR_THRESH, thresh);
811 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
812 AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 1);
813 } else {
814 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
815 AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 0);
816 }
817
818 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
819 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN, 1);
820 } else {
821 REG_CLR_BIT(ah, AR_BTCOEX_CTRL, 797 REG_CLR_BIT(ah, AR_BTCOEX_CTRL,
822 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN); 798 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
799 return;
823 } 800 }
801 REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2, AR_MCI_SCHD_TABLE_2_HW_BASED, 1);
802 REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2,
803 AR_MCI_SCHD_TABLE_2_MEM_BASED, 1);
804
805 if (!(mci->config & ATH_MCI_CONFIG_DISABLE_AGGR_THRESH)) {
806 thresh = MS(mci->config, ATH_MCI_CONFIG_AGGR_THRESH);
807 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
808 AR_BTCOEX_CTRL_AGGR_THRESH, thresh);
809 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
810 AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 1);
811 } else
812 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
813 AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 0);
814
815 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
816 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN, 1);
824} 817}
825 818
826void ar9003_mci_reset(struct ath_hw *ah, bool en_int, bool is_2g, 819void ar9003_mci_reset(struct ath_hw *ah, bool en_int, bool is_2g,
@@ -898,13 +891,16 @@ void ar9003_mci_reset(struct ath_hw *ah, bool en_int, bool is_2g,
898 udelay(100); 891 udelay(100);
899 } 892 }
900 893
894 /* Check pending GPM msg before MCI Reset Rx */
895 ar9003_mci_check_gpm_offset(ah);
896
901 regval |= SM(1, AR_MCI_COMMAND2_RESET_RX); 897 regval |= SM(1, AR_MCI_COMMAND2_RESET_RX);
902 REG_WRITE(ah, AR_MCI_COMMAND2, regval); 898 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
903 udelay(1); 899 udelay(1);
904 regval &= ~SM(1, AR_MCI_COMMAND2_RESET_RX); 900 regval &= ~SM(1, AR_MCI_COMMAND2_RESET_RX);
905 REG_WRITE(ah, AR_MCI_COMMAND2, regval); 901 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
906 902
907 ar9003_mci_state(ah, MCI_STATE_INIT_GPM_OFFSET, NULL); 903 ar9003_mci_get_next_gpm_offset(ah, true, NULL);
908 904
909 REG_WRITE(ah, AR_MCI_MSG_ATTRIBUTES_TABLE, 905 REG_WRITE(ah, AR_MCI_MSG_ATTRIBUTES_TABLE,
910 (SM(0xe801, AR_MCI_MSG_ATTRIBUTES_TABLE_INVALID_HDR) | 906 (SM(0xe801, AR_MCI_MSG_ATTRIBUTES_TABLE_INVALID_HDR) |
@@ -943,26 +939,27 @@ static void ar9003_mci_send_2g5g_status(struct ath_hw *ah, bool wait_done)
943 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci; 939 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
944 u32 new_flags, to_set, to_clear; 940 u32 new_flags, to_set, to_clear;
945 941
946 if (mci->update_2g5g && (mci->bt_state != MCI_BT_SLEEP)) { 942 if (!mci->update_2g5g || (mci->bt_state == MCI_BT_SLEEP))
947 if (mci->is_2g) { 943 return;
948 new_flags = MCI_2G_FLAGS; 944
949 to_clear = MCI_2G_FLAGS_CLEAR_MASK; 945 if (mci->is_2g) {
950 to_set = MCI_2G_FLAGS_SET_MASK; 946 new_flags = MCI_2G_FLAGS;
951 } else { 947 to_clear = MCI_2G_FLAGS_CLEAR_MASK;
952 new_flags = MCI_5G_FLAGS; 948 to_set = MCI_2G_FLAGS_SET_MASK;
953 to_clear = MCI_5G_FLAGS_CLEAR_MASK; 949 } else {
954 to_set = MCI_5G_FLAGS_SET_MASK; 950 new_flags = MCI_5G_FLAGS;
955 } 951 to_clear = MCI_5G_FLAGS_CLEAR_MASK;
952 to_set = MCI_5G_FLAGS_SET_MASK;
953 }
956 954
957 if (to_clear) 955 if (to_clear)
958 ar9003_mci_send_coex_bt_flags(ah, wait_done, 956 ar9003_mci_send_coex_bt_flags(ah, wait_done,
959 MCI_GPM_COEX_BT_FLAGS_CLEAR, 957 MCI_GPM_COEX_BT_FLAGS_CLEAR,
960 to_clear); 958 to_clear);
961 if (to_set) 959 if (to_set)
962 ar9003_mci_send_coex_bt_flags(ah, wait_done, 960 ar9003_mci_send_coex_bt_flags(ah, wait_done,
963 MCI_GPM_COEX_BT_FLAGS_SET, 961 MCI_GPM_COEX_BT_FLAGS_SET,
964 to_set); 962 to_set);
965 }
966} 963}
967 964
968static void ar9003_mci_queue_unsent_gpm(struct ath_hw *ah, u8 header, 965static void ar9003_mci_queue_unsent_gpm(struct ath_hw *ah, u8 header,
@@ -1014,38 +1011,32 @@ static void ar9003_mci_queue_unsent_gpm(struct ath_hw *ah, u8 header,
1014 } 1011 }
1015} 1012}
1016 1013
1017void ar9003_mci_2g5g_switch(struct ath_hw *ah, bool wait_done) 1014void ar9003_mci_2g5g_switch(struct ath_hw *ah, bool force)
1018{ 1015{
1019 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci; 1016 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1020 1017
1021 if (mci->update_2g5g) { 1018 if (!mci->update_2g5g && !force)
1022 if (mci->is_2g) { 1019 return;
1023 ar9003_mci_send_2g5g_status(ah, true);
1024 ar9003_mci_send_lna_transfer(ah, true);
1025 udelay(5);
1026 1020
1027 REG_CLR_BIT(ah, AR_MCI_TX_CTRL, 1021 if (mci->is_2g) {
1028 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE); 1022 ar9003_mci_send_2g5g_status(ah, true);
1029 REG_CLR_BIT(ah, AR_PHY_GLB_CONTROL,
1030 AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
1031 1023
1032 if (!(mci->config & ATH_MCI_CONFIG_DISABLE_OSLA)) { 1024 REG_SET_BIT(ah, AR_MCI_TX_CTRL,
1033 REG_SET_BIT(ah, AR_BTCOEX_CTRL, 1025 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
1034 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN); 1026 REG_CLR_BIT(ah, AR_PHY_GLB_CONTROL,
1035 } 1027 AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
1036 } else {
1037 ar9003_mci_send_lna_take(ah, true);
1038 udelay(5);
1039 1028
1040 REG_SET_BIT(ah, AR_MCI_TX_CTRL, 1029 if (!(mci->config & ATH_MCI_CONFIG_DISABLE_OSLA))
1041 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE); 1030 ar9003_mci_osla_setup(ah, true);
1042 REG_SET_BIT(ah, AR_PHY_GLB_CONTROL, 1031 } else {
1043 AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL); 1032 REG_SET_BIT(ah, AR_MCI_TX_CTRL,
1044 REG_CLR_BIT(ah, AR_BTCOEX_CTRL, 1033 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
1045 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN); 1034 REG_SET_BIT(ah, AR_PHY_GLB_CONTROL,
1035 AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
1046 1036
1037 ar9003_mci_osla_setup(ah, false);
1038 if (!force)
1047 ar9003_mci_send_2g5g_status(ah, true); 1039 ar9003_mci_send_2g5g_status(ah, true);
1048 }
1049 } 1040 }
1050} 1041}
1051 1042
@@ -1132,7 +1123,7 @@ void ar9003_mci_init_cal_req(struct ath_hw *ah, bool *is_reusable)
1132 if (ar9003_mci_wait_for_gpm(ah, MCI_GPM_BT_CAL_GRANT, 0, 50000)) { 1123 if (ar9003_mci_wait_for_gpm(ah, MCI_GPM_BT_CAL_GRANT, 0, 50000)) {
1133 ath_dbg(common, MCI, "MCI BT_CAL_GRANT received\n"); 1124 ath_dbg(common, MCI, "MCI BT_CAL_GRANT received\n");
1134 } else { 1125 } else {
1135 is_reusable = false; 1126 *is_reusable = false;
1136 ath_dbg(common, MCI, "MCI BT_CAL_GRANT not received\n"); 1127 ath_dbg(common, MCI, "MCI BT_CAL_GRANT not received\n");
1137 } 1128 }
1138} 1129}
@@ -1173,11 +1164,10 @@ void ar9003_mci_cleanup(struct ath_hw *ah)
1173} 1164}
1174EXPORT_SYMBOL(ar9003_mci_cleanup); 1165EXPORT_SYMBOL(ar9003_mci_cleanup);
1175 1166
1176u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type, u32 *p_data) 1167u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type)
1177{ 1168{
1178 struct ath_common *common = ath9k_hw_common(ah);
1179 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci; 1169 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1180 u32 value = 0, more_gpm = 0, gpm_ptr; 1170 u32 value = 0;
1181 u8 query_type; 1171 u8 query_type;
1182 1172
1183 switch (state_type) { 1173 switch (state_type) {
@@ -1190,81 +1180,6 @@ u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type, u32 *p_data)
1190 } 1180 }
1191 value &= AR_BTCOEX_CTRL_MCI_MODE_EN; 1181 value &= AR_BTCOEX_CTRL_MCI_MODE_EN;
1192 break; 1182 break;
1193 case MCI_STATE_INIT_GPM_OFFSET:
1194 value = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
1195 mci->gpm_idx = value;
1196 break;
1197 case MCI_STATE_NEXT_GPM_OFFSET:
1198 case MCI_STATE_LAST_GPM_OFFSET:
1199 /*
1200 * This could be useful to avoid new GPM message interrupt which
1201 * may lead to spurious interrupt after power sleep, or multiple
1202 * entry of ath_mci_intr().
1203 * Adding empty GPM check by returning HAL_MCI_GPM_INVALID can
1204 * alleviate this effect, but clearing GPM RX interrupt bit is
1205 * safe, because whether this is called from hw or driver code
1206 * there must be an interrupt bit set/triggered initially
1207 */
1208 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
1209 AR_MCI_INTERRUPT_RX_MSG_GPM);
1210
1211 gpm_ptr = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
1212 value = gpm_ptr;
1213
1214 if (value == 0)
1215 value = mci->gpm_len - 1;
1216 else if (value >= mci->gpm_len) {
1217 if (value != 0xFFFF)
1218 value = 0;
1219 } else {
1220 value--;
1221 }
1222
1223 if (value == 0xFFFF) {
1224 value = MCI_GPM_INVALID;
1225 more_gpm = MCI_GPM_NOMORE;
1226 } else if (state_type == MCI_STATE_NEXT_GPM_OFFSET) {
1227 if (gpm_ptr == mci->gpm_idx) {
1228 value = MCI_GPM_INVALID;
1229 more_gpm = MCI_GPM_NOMORE;
1230 } else {
1231 for (;;) {
1232 u32 temp_index;
1233
1234 /* skip reserved GPM if any */
1235
1236 if (value != mci->gpm_idx)
1237 more_gpm = MCI_GPM_MORE;
1238 else
1239 more_gpm = MCI_GPM_NOMORE;
1240
1241 temp_index = mci->gpm_idx;
1242 mci->gpm_idx++;
1243
1244 if (mci->gpm_idx >=
1245 mci->gpm_len)
1246 mci->gpm_idx = 0;
1247
1248 if (ar9003_mci_is_gpm_valid(ah,
1249 temp_index)) {
1250 value = temp_index;
1251 break;
1252 }
1253
1254 if (more_gpm == MCI_GPM_NOMORE) {
1255 value = MCI_GPM_INVALID;
1256 break;
1257 }
1258 }
1259 }
1260 if (p_data)
1261 *p_data = more_gpm;
1262 }
1263
1264 if (value != MCI_GPM_INVALID)
1265 value <<= 4;
1266
1267 break;
1268 case MCI_STATE_LAST_SCHD_MSG_OFFSET: 1183 case MCI_STATE_LAST_SCHD_MSG_OFFSET:
1269 value = MS(REG_READ(ah, AR_MCI_RX_STATUS), 1184 value = MS(REG_READ(ah, AR_MCI_RX_STATUS),
1270 AR_MCI_RX_LAST_SCHD_MSG_INDEX); 1185 AR_MCI_RX_LAST_SCHD_MSG_INDEX);
@@ -1276,21 +1191,6 @@ u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type, u32 *p_data)
1276 AR_MCI_RX_REMOTE_SLEEP) ? 1191 AR_MCI_RX_REMOTE_SLEEP) ?
1277 MCI_BT_SLEEP : MCI_BT_AWAKE; 1192 MCI_BT_SLEEP : MCI_BT_AWAKE;
1278 break; 1193 break;
1279 case MCI_STATE_CONT_RSSI_POWER:
1280 value = MS(mci->cont_status, AR_MCI_CONT_RSSI_POWER);
1281 break;
1282 case MCI_STATE_CONT_PRIORITY:
1283 value = MS(mci->cont_status, AR_MCI_CONT_RRIORITY);
1284 break;
1285 case MCI_STATE_CONT_TXRX:
1286 value = MS(mci->cont_status, AR_MCI_CONT_TXRX);
1287 break;
1288 case MCI_STATE_BT:
1289 value = mci->bt_state;
1290 break;
1291 case MCI_STATE_SET_BT_SLEEP:
1292 mci->bt_state = MCI_BT_SLEEP;
1293 break;
1294 case MCI_STATE_SET_BT_AWAKE: 1194 case MCI_STATE_SET_BT_AWAKE:
1295 mci->bt_state = MCI_BT_AWAKE; 1195 mci->bt_state = MCI_BT_AWAKE;
1296 ar9003_mci_send_coex_version_query(ah, true); 1196 ar9003_mci_send_coex_version_query(ah, true);
@@ -1299,7 +1199,7 @@ u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type, u32 *p_data)
1299 if (mci->unhalt_bt_gpm) 1199 if (mci->unhalt_bt_gpm)
1300 ar9003_mci_send_coex_halt_bt_gpm(ah, false, true); 1200 ar9003_mci_send_coex_halt_bt_gpm(ah, false, true);
1301 1201
1302 ar9003_mci_2g5g_switch(ah, true); 1202 ar9003_mci_2g5g_switch(ah, false);
1303 break; 1203 break;
1304 case MCI_STATE_SET_BT_CAL_START: 1204 case MCI_STATE_SET_BT_CAL_START:
1305 mci->bt_state = MCI_BT_CAL_START; 1205 mci->bt_state = MCI_BT_CAL_START;
@@ -1323,34 +1223,6 @@ u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type, u32 *p_data)
1323 case MCI_STATE_SEND_WLAN_COEX_VERSION: 1223 case MCI_STATE_SEND_WLAN_COEX_VERSION:
1324 ar9003_mci_send_coex_version_response(ah, true); 1224 ar9003_mci_send_coex_version_response(ah, true);
1325 break; 1225 break;
1326 case MCI_STATE_SET_BT_COEX_VERSION:
1327 if (!p_data)
1328 ath_dbg(common, MCI,
1329 "MCI Set BT Coex version with NULL data!!\n");
1330 else {
1331 mci->bt_ver_major = (*p_data >> 8) & 0xff;
1332 mci->bt_ver_minor = (*p_data) & 0xff;
1333 mci->bt_version_known = true;
1334 ath_dbg(common, MCI, "MCI BT version set: %d.%d\n",
1335 mci->bt_ver_major, mci->bt_ver_minor);
1336 }
1337 break;
1338 case MCI_STATE_SEND_WLAN_CHANNELS:
1339 if (p_data) {
1340 if (((mci->wlan_channels[1] & 0xffff0000) ==
1341 (*(p_data + 1) & 0xffff0000)) &&
1342 (mci->wlan_channels[2] == *(p_data + 2)) &&
1343 (mci->wlan_channels[3] == *(p_data + 3)))
1344 break;
1345
1346 mci->wlan_channels[0] = *p_data++;
1347 mci->wlan_channels[1] = *p_data++;
1348 mci->wlan_channels[2] = *p_data++;
1349 mci->wlan_channels[3] = *p_data++;
1350 }
1351 mci->wlan_channels_update = true;
1352 ar9003_mci_send_coex_wlan_channels(ah, true);
1353 break;
1354 case MCI_STATE_SEND_VERSION_QUERY: 1226 case MCI_STATE_SEND_VERSION_QUERY:
1355 ar9003_mci_send_coex_version_query(ah, true); 1227 ar9003_mci_send_coex_version_query(ah, true);
1356 break; 1228 break;
@@ -1358,38 +1230,16 @@ u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type, u32 *p_data)
1358 query_type = MCI_GPM_COEX_QUERY_BT_TOPOLOGY; 1230 query_type = MCI_GPM_COEX_QUERY_BT_TOPOLOGY;
1359 ar9003_mci_send_coex_bt_status_query(ah, true, query_type); 1231 ar9003_mci_send_coex_bt_status_query(ah, true, query_type);
1360 break; 1232 break;
1361 case MCI_STATE_NEED_FLUSH_BT_INFO:
1362 /*
1363 * btcoex_hw.mci.unhalt_bt_gpm means whether it's
1364 * needed to send UNHALT message. It's set whenever
1365 * there's a request to send HALT message.
1366 * mci_halted_bt_gpm means whether HALT message is sent
1367 * out successfully.
1368 *
1369 * Checking (mci_unhalt_bt_gpm == false) instead of
1370 * checking (ah->mci_halted_bt_gpm == false) will make
1371 * sure currently is in UNHALT-ed mode and BT can
1372 * respond to status query.
1373 */
1374 value = (!mci->unhalt_bt_gpm &&
1375 mci->need_flush_btinfo) ? 1 : 0;
1376 if (p_data)
1377 mci->need_flush_btinfo =
1378 (*p_data != 0) ? true : false;
1379 break;
1380 case MCI_STATE_RECOVER_RX: 1233 case MCI_STATE_RECOVER_RX:
1381 ar9003_mci_prep_interface(ah); 1234 ar9003_mci_prep_interface(ah);
1382 mci->query_bt = true; 1235 mci->query_bt = true;
1383 mci->need_flush_btinfo = true; 1236 mci->need_flush_btinfo = true;
1384 ar9003_mci_send_coex_wlan_channels(ah, true); 1237 ar9003_mci_send_coex_wlan_channels(ah, true);
1385 ar9003_mci_2g5g_switch(ah, true); 1238 ar9003_mci_2g5g_switch(ah, false);
1386 break; 1239 break;
1387 case MCI_STATE_NEED_FTP_STOMP: 1240 case MCI_STATE_NEED_FTP_STOMP:
1388 value = !(mci->config & ATH_MCI_CONFIG_DISABLE_FTP_STOMP); 1241 value = !(mci->config & ATH_MCI_CONFIG_DISABLE_FTP_STOMP);
1389 break; 1242 break;
1390 case MCI_STATE_NEED_TUNING:
1391 value = !(mci->config & ATH_MCI_CONFIG_DISABLE_TUNING);
1392 break;
1393 default: 1243 default:
1394 break; 1244 break;
1395 } 1245 }
@@ -1397,3 +1247,170 @@ u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type, u32 *p_data)
1397 return value; 1247 return value;
1398} 1248}
1399EXPORT_SYMBOL(ar9003_mci_state); 1249EXPORT_SYMBOL(ar9003_mci_state);
1250
1251void ar9003_mci_bt_gain_ctrl(struct ath_hw *ah)
1252{
1253 struct ath_common *common = ath9k_hw_common(ah);
1254 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1255
1256 ath_dbg(common, MCI, "Give LNA and SPDT control to BT\n");
1257
1258 REG_SET_BIT(ah, AR_PHY_GLB_CONTROL, AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
1259 mci->is_2g = false;
1260 mci->update_2g5g = true;
1261 ar9003_mci_send_2g5g_status(ah, true);
1262
1263 /* Force another 2g5g update at next scanning */
1264 mci->update_2g5g = true;
1265}
1266
1267void ar9003_mci_set_power_awake(struct ath_hw *ah)
1268{
1269 u32 btcoex_ctrl2, diag_sw;
1270 int i;
1271 u8 lna_ctrl, bt_sleep;
1272
1273 for (i = 0; i < AH_WAIT_TIMEOUT; i++) {
1274 btcoex_ctrl2 = REG_READ(ah, AR_BTCOEX_CTRL2);
1275 if (btcoex_ctrl2 != 0xdeadbeef)
1276 break;
1277 udelay(AH_TIME_QUANTUM);
1278 }
1279 REG_WRITE(ah, AR_BTCOEX_CTRL2, (btcoex_ctrl2 | BIT(23)));
1280
1281 for (i = 0; i < AH_WAIT_TIMEOUT; i++) {
1282 diag_sw = REG_READ(ah, AR_DIAG_SW);
1283 if (diag_sw != 0xdeadbeef)
1284 break;
1285 udelay(AH_TIME_QUANTUM);
1286 }
1287 REG_WRITE(ah, AR_DIAG_SW, (diag_sw | BIT(27) | BIT(19) | BIT(18)));
1288 lna_ctrl = REG_READ(ah, AR_OBS_BUS_CTRL) & 0x3;
1289 bt_sleep = REG_READ(ah, AR_MCI_RX_STATUS) & AR_MCI_RX_REMOTE_SLEEP;
1290
1291 REG_WRITE(ah, AR_BTCOEX_CTRL2, btcoex_ctrl2);
1292 REG_WRITE(ah, AR_DIAG_SW, diag_sw);
1293
1294 if (bt_sleep && (lna_ctrl == 2)) {
1295 REG_SET_BIT(ah, AR_BTCOEX_RC, 0x1);
1296 REG_CLR_BIT(ah, AR_BTCOEX_RC, 0x1);
1297 udelay(50);
1298 }
1299}
1300
1301void ar9003_mci_check_gpm_offset(struct ath_hw *ah)
1302{
1303 struct ath_common *common = ath9k_hw_common(ah);
1304 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1305 u32 offset;
1306
1307 /*
1308 * This should only be called before "MAC Warm Reset" or "MCI Reset Rx".
1309 */
1310 offset = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
1311 if (mci->gpm_idx == offset)
1312 return;
1313 ath_dbg(common, MCI, "GPM cached write pointer mismatch %d %d\n",
1314 mci->gpm_idx, offset);
1315 mci->query_bt = true;
1316 mci->need_flush_btinfo = true;
1317 mci->gpm_idx = 0;
1318}
1319
1320u32 ar9003_mci_get_next_gpm_offset(struct ath_hw *ah, bool first, u32 *more)
1321{
1322 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1323 u32 offset, more_gpm = 0, gpm_ptr;
1324
1325 if (first) {
1326 gpm_ptr = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
1327 mci->gpm_idx = gpm_ptr;
1328 return gpm_ptr;
1329 }
1330
1331 /*
1332 * This could be useful to avoid new GPM message interrupt which
1333 * may lead to spurious interrupt after power sleep, or multiple
1334 * entry of ath_mci_intr().
1335 * Adding empty GPM check by returning HAL_MCI_GPM_INVALID can
1336 * alleviate this effect, but clearing GPM RX interrupt bit is
1337 * safe, because whether this is called from hw or driver code
1338 * there must be an interrupt bit set/triggered initially
1339 */
1340 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
1341 AR_MCI_INTERRUPT_RX_MSG_GPM);
1342
1343 gpm_ptr = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
1344 offset = gpm_ptr;
1345
1346 if (!offset)
1347 offset = mci->gpm_len - 1;
1348 else if (offset >= mci->gpm_len) {
1349 if (offset != 0xFFFF)
1350 offset = 0;
1351 } else {
1352 offset--;
1353 }
1354
1355 if ((offset == 0xFFFF) || (gpm_ptr == mci->gpm_idx)) {
1356 offset = MCI_GPM_INVALID;
1357 more_gpm = MCI_GPM_NOMORE;
1358 goto out;
1359 }
1360 for (;;) {
1361 u32 temp_index;
1362
1363 /* skip reserved GPM if any */
1364
1365 if (offset != mci->gpm_idx)
1366 more_gpm = MCI_GPM_MORE;
1367 else
1368 more_gpm = MCI_GPM_NOMORE;
1369
1370 temp_index = mci->gpm_idx;
1371 mci->gpm_idx++;
1372
1373 if (mci->gpm_idx >= mci->gpm_len)
1374 mci->gpm_idx = 0;
1375
1376 if (ar9003_mci_is_gpm_valid(ah, temp_index)) {
1377 offset = temp_index;
1378 break;
1379 }
1380
1381 if (more_gpm == MCI_GPM_NOMORE) {
1382 offset = MCI_GPM_INVALID;
1383 break;
1384 }
1385 }
1386
1387 if (offset != MCI_GPM_INVALID)
1388 offset <<= 4;
1389out:
1390 if (more)
1391 *more = more_gpm;
1392
1393 return offset;
1394}
1395EXPORT_SYMBOL(ar9003_mci_get_next_gpm_offset);
1396
1397void ar9003_mci_set_bt_version(struct ath_hw *ah, u8 major, u8 minor)
1398{
1399 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1400
1401 mci->bt_ver_major = major;
1402 mci->bt_ver_minor = minor;
1403 mci->bt_version_known = true;
1404 ath_dbg(ath9k_hw_common(ah), MCI, "MCI BT version set: %d.%d\n",
1405 mci->bt_ver_major, mci->bt_ver_minor);
1406}
1407EXPORT_SYMBOL(ar9003_mci_set_bt_version);
1408
1409void ar9003_mci_send_wlan_channels(struct ath_hw *ah)
1410{
1411 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1412
1413 mci->wlan_channels_update = true;
1414 ar9003_mci_send_coex_wlan_channels(ah, true);
1415}
1416EXPORT_SYMBOL(ar9003_mci_send_wlan_channels);
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mci.h b/drivers/net/wireless/ath/ath9k/ar9003_mci.h
index 4842f6c06b8c..d33b8e128855 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_mci.h
+++ b/drivers/net/wireless/ath/ath9k/ar9003_mci.h
@@ -189,30 +189,18 @@ enum mci_bt_state {
189/* Type of state query */ 189/* Type of state query */
190enum mci_state_type { 190enum mci_state_type {
191 MCI_STATE_ENABLE, 191 MCI_STATE_ENABLE,
192 MCI_STATE_INIT_GPM_OFFSET,
193 MCI_STATE_NEXT_GPM_OFFSET,
194 MCI_STATE_LAST_GPM_OFFSET,
195 MCI_STATE_BT,
196 MCI_STATE_SET_BT_SLEEP,
197 MCI_STATE_SET_BT_AWAKE, 192 MCI_STATE_SET_BT_AWAKE,
198 MCI_STATE_SET_BT_CAL_START, 193 MCI_STATE_SET_BT_CAL_START,
199 MCI_STATE_SET_BT_CAL, 194 MCI_STATE_SET_BT_CAL,
200 MCI_STATE_LAST_SCHD_MSG_OFFSET, 195 MCI_STATE_LAST_SCHD_MSG_OFFSET,
201 MCI_STATE_REMOTE_SLEEP, 196 MCI_STATE_REMOTE_SLEEP,
202 MCI_STATE_CONT_RSSI_POWER,
203 MCI_STATE_CONT_PRIORITY,
204 MCI_STATE_CONT_TXRX,
205 MCI_STATE_RESET_REQ_WAKE, 197 MCI_STATE_RESET_REQ_WAKE,
206 MCI_STATE_SEND_WLAN_COEX_VERSION, 198 MCI_STATE_SEND_WLAN_COEX_VERSION,
207 MCI_STATE_SET_BT_COEX_VERSION,
208 MCI_STATE_SEND_WLAN_CHANNELS,
209 MCI_STATE_SEND_VERSION_QUERY, 199 MCI_STATE_SEND_VERSION_QUERY,
210 MCI_STATE_SEND_STATUS_QUERY, 200 MCI_STATE_SEND_STATUS_QUERY,
211 MCI_STATE_NEED_FLUSH_BT_INFO,
212 MCI_STATE_SET_CONCUR_TX_PRI, 201 MCI_STATE_SET_CONCUR_TX_PRI,
213 MCI_STATE_RECOVER_RX, 202 MCI_STATE_RECOVER_RX,
214 MCI_STATE_NEED_FTP_STOMP, 203 MCI_STATE_NEED_FTP_STOMP,
215 MCI_STATE_NEED_TUNING,
216 MCI_STATE_DEBUG, 204 MCI_STATE_DEBUG,
217 MCI_STATE_MAX 205 MCI_STATE_MAX
218}; 206};
@@ -260,28 +248,26 @@ enum mci_gpm_coex_opcode {
260bool ar9003_mci_send_message(struct ath_hw *ah, u8 header, u32 flag, 248bool ar9003_mci_send_message(struct ath_hw *ah, u8 header, u32 flag,
261 u32 *payload, u8 len, bool wait_done, 249 u32 *payload, u8 len, bool wait_done,
262 bool check_bt); 250 bool check_bt);
263u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type, u32 *p_data); 251u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type);
264void ar9003_mci_setup(struct ath_hw *ah, u32 gpm_addr, void *gpm_buf, 252void ar9003_mci_setup(struct ath_hw *ah, u32 gpm_addr, void *gpm_buf,
265 u16 len, u32 sched_addr); 253 u16 len, u32 sched_addr);
266void ar9003_mci_cleanup(struct ath_hw *ah); 254void ar9003_mci_cleanup(struct ath_hw *ah);
267void ar9003_mci_get_interrupt(struct ath_hw *ah, u32 *raw_intr, 255void ar9003_mci_get_interrupt(struct ath_hw *ah, u32 *raw_intr,
268 u32 *rx_msg_intr); 256 u32 *rx_msg_intr);
269 257u32 ar9003_mci_get_next_gpm_offset(struct ath_hw *ah, bool first, u32 *more);
258void ar9003_mci_set_bt_version(struct ath_hw *ah, u8 major, u8 minor);
259void ar9003_mci_send_wlan_channels(struct ath_hw *ah);
270/* 260/*
271 * These functions are used by ath9k_hw. 261 * These functions are used by ath9k_hw.
272 */ 262 */
273 263
274#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT 264#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
275 265
276static inline bool ar9003_mci_is_ready(struct ath_hw *ah)
277{
278 return ah->btcoex_hw.mci.ready;
279}
280void ar9003_mci_stop_bt(struct ath_hw *ah, bool save_fullsleep); 266void ar9003_mci_stop_bt(struct ath_hw *ah, bool save_fullsleep);
281void ar9003_mci_init_cal_req(struct ath_hw *ah, bool *is_reusable); 267void ar9003_mci_init_cal_req(struct ath_hw *ah, bool *is_reusable);
282void ar9003_mci_init_cal_done(struct ath_hw *ah); 268void ar9003_mci_init_cal_done(struct ath_hw *ah);
283void ar9003_mci_set_full_sleep(struct ath_hw *ah); 269void ar9003_mci_set_full_sleep(struct ath_hw *ah);
284void ar9003_mci_2g5g_switch(struct ath_hw *ah, bool wait_done); 270void ar9003_mci_2g5g_switch(struct ath_hw *ah, bool force);
285void ar9003_mci_check_bt(struct ath_hw *ah); 271void ar9003_mci_check_bt(struct ath_hw *ah);
286bool ar9003_mci_start_reset(struct ath_hw *ah, struct ath9k_channel *chan); 272bool ar9003_mci_start_reset(struct ath_hw *ah, struct ath9k_channel *chan);
287int ar9003_mci_end_reset(struct ath_hw *ah, struct ath9k_channel *chan, 273int ar9003_mci_end_reset(struct ath_hw *ah, struct ath9k_channel *chan,
@@ -289,13 +275,12 @@ int ar9003_mci_end_reset(struct ath_hw *ah, struct ath9k_channel *chan,
289void ar9003_mci_reset(struct ath_hw *ah, bool en_int, bool is_2g, 275void ar9003_mci_reset(struct ath_hw *ah, bool en_int, bool is_2g,
290 bool is_full_sleep); 276 bool is_full_sleep);
291void ar9003_mci_get_isr(struct ath_hw *ah, enum ath9k_int *masked); 277void ar9003_mci_get_isr(struct ath_hw *ah, enum ath9k_int *masked);
278void ar9003_mci_bt_gain_ctrl(struct ath_hw *ah);
279void ar9003_mci_set_power_awake(struct ath_hw *ah);
280void ar9003_mci_check_gpm_offset(struct ath_hw *ah);
292 281
293#else 282#else
294 283
295static inline bool ar9003_mci_is_ready(struct ath_hw *ah)
296{
297 return false;
298}
299static inline void ar9003_mci_stop_bt(struct ath_hw *ah, bool save_fullsleep) 284static inline void ar9003_mci_stop_bt(struct ath_hw *ah, bool save_fullsleep)
300{ 285{
301} 286}
@@ -330,6 +315,15 @@ static inline void ar9003_mci_reset(struct ath_hw *ah, bool en_int, bool is_2g,
330static inline void ar9003_mci_get_isr(struct ath_hw *ah, enum ath9k_int *masked) 315static inline void ar9003_mci_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
331{ 316{
332} 317}
318static inline void ar9003_mci_bt_gain_ctrl(struct ath_hw *ah)
319{
320}
321static inline void ar9003_mci_set_power_awake(struct ath_hw *ah)
322{
323}
324static inline void ar9003_mci_check_gpm_offset(struct ath_hw *ah)
325{
326}
333#endif /* CONFIG_ATH9K_BTCOEX_SUPPORT */ 327#endif /* CONFIG_ATH9K_BTCOEX_SUPPORT */
334 328
335#endif 329#endif
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.c b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
index 11abb972be1f..d6baf69cdc14 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
@@ -676,6 +676,10 @@ static int ar9003_hw_process_ini(struct ath_hw *ah,
676 if (chan->channel == 2484) 676 if (chan->channel == 2484)
677 ar9003_hw_prog_ini(ah, &ah->ini_japan2484, 1); 677 ar9003_hw_prog_ini(ah, &ah->ini_japan2484, 1);
678 678
679 if (AR_SREV_9462(ah))
680 REG_WRITE(ah, AR_GLB_SWREG_DISCONT_MODE,
681 AR_GLB_SWREG_DISCONT_EN_BT_WLAN);
682
679 ah->modes_index = modesIndex; 683 ah->modes_index = modesIndex;
680 ar9003_hw_override_ini(ah); 684 ar9003_hw_override_ini(ah);
681 ar9003_hw_set_channel_regs(ah, chan); 685 ar9003_hw_set_channel_regs(ah, chan);
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.h b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
index 7268a48a92a1..ed662c3bae5b 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.h
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
@@ -820,18 +820,26 @@
820#define AR_PHY_CHAN_INFO_MEMORY_CAPTURE_MASK 0x0001 820#define AR_PHY_CHAN_INFO_MEMORY_CAPTURE_MASK 0x0001
821#define AR_PHY_RX_DELAY_DELAY 0x00003FFF 821#define AR_PHY_RX_DELAY_DELAY 0x00003FFF
822#define AR_PHY_CCK_TX_CTRL_JAPAN 0x00000010 822#define AR_PHY_CCK_TX_CTRL_JAPAN 0x00000010
823#define AR_PHY_SPECTRAL_SCAN_ENABLE 0x00000001 823
824#define AR_PHY_SPECTRAL_SCAN_ENABLE_S 0 824#define AR_PHY_SPECTRAL_SCAN_ENABLE 0x00000001
825#define AR_PHY_SPECTRAL_SCAN_ACTIVE 0x00000002 825#define AR_PHY_SPECTRAL_SCAN_ENABLE_S 0
826#define AR_PHY_SPECTRAL_SCAN_ACTIVE_S 1 826#define AR_PHY_SPECTRAL_SCAN_ACTIVE 0x00000002
827#define AR_PHY_SPECTRAL_SCAN_FFT_PERIOD 0x000000F0 827#define AR_PHY_SPECTRAL_SCAN_ACTIVE_S 1
828#define AR_PHY_SPECTRAL_SCAN_FFT_PERIOD_S 4 828#define AR_PHY_SPECTRAL_SCAN_FFT_PERIOD 0x000000F0
829#define AR_PHY_SPECTRAL_SCAN_PERIOD 0x0000FF00 829#define AR_PHY_SPECTRAL_SCAN_FFT_PERIOD_S 4
830#define AR_PHY_SPECTRAL_SCAN_PERIOD_S 8 830#define AR_PHY_SPECTRAL_SCAN_PERIOD 0x0000FF00
831#define AR_PHY_SPECTRAL_SCAN_COUNT 0x00FF0000 831#define AR_PHY_SPECTRAL_SCAN_PERIOD_S 8
832#define AR_PHY_SPECTRAL_SCAN_COUNT_S 16 832#define AR_PHY_SPECTRAL_SCAN_COUNT 0x0FFF0000
833#define AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT 0x01000000 833#define AR_PHY_SPECTRAL_SCAN_COUNT_S 16
834#define AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT_S 24 834#define AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT 0x10000000
835#define AR_PHY_SPECTRAL_SCAN_SHORT_REPEAT_S 28
836#define AR_PHY_SPECTRAL_SCAN_PRIORITY 0x20000000
837#define AR_PHY_SPECTRAL_SCAN_PRIORITY_S 29
838#define AR_PHY_SPECTRAL_SCAN_USE_ERR5 0x40000000
839#define AR_PHY_SPECTRAL_SCAN_USE_ERR5_S 30
840#define AR_PHY_SPECTRAL_SCAN_COMPRESSED_RPT 0x80000000
841#define AR_PHY_SPECTRAL_SCAN_COMPRESSED_RPT_S 31
842
835#define AR_PHY_CHANNEL_STATUS_RX_CLEAR 0x00000004 843#define AR_PHY_CHANNEL_STATUS_RX_CLEAR 0x00000004
836#define AR_PHY_RTT_CTRL_ENA_RADIO_RETENTION 0x00000001 844#define AR_PHY_RTT_CTRL_ENA_RADIO_RETENTION 0x00000001
837#define AR_PHY_RTT_CTRL_ENA_RADIO_RETENTION_S 0 845#define AR_PHY_RTT_CTRL_ENA_RADIO_RETENTION_S 0
diff --git a/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h b/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
index 1d6658e139b5..8f406ff2c95e 100644
--- a/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
+++ b/drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
@@ -52,7 +52,7 @@ static const u32 ar9462_2p0_baseband_postamble[][5] = {
52 {0x00009e04, 0x001c2020, 0x001c2020, 0x001c2020, 0x001c2020}, 52 {0x00009e04, 0x001c2020, 0x001c2020, 0x001c2020, 0x001c2020},
53 {0x00009e0c, 0x6c4000e2, 0x6d4000e2, 0x6d4000e2, 0x6c4000d8}, 53 {0x00009e0c, 0x6c4000e2, 0x6d4000e2, 0x6d4000e2, 0x6c4000d8},
54 {0x00009e10, 0x92c88d2e, 0x7ec88d2e, 0x7ec84d2e, 0x7ec86d2e}, 54 {0x00009e10, 0x92c88d2e, 0x7ec88d2e, 0x7ec84d2e, 0x7ec86d2e},
55 {0x00009e14, 0x37b95d5e, 0x37b9605e, 0x3376605e, 0x33795d5e}, 55 {0x00009e14, 0x37b95d5e, 0x37b9605e, 0x3376605e, 0x32395d5e},
56 {0x00009e18, 0x00000000, 0x00000000, 0x00000000, 0x00000000}, 56 {0x00009e18, 0x00000000, 0x00000000, 0x00000000, 0x00000000},
57 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c}, 57 {0x00009e1c, 0x0001cf9c, 0x0001cf9c, 0x00021f9c, 0x00021f9c},
58 {0x00009e20, 0x000003b5, 0x000003b5, 0x000003ce, 0x000003ce}, 58 {0x00009e20, 0x000003b5, 0x000003b5, 0x000003ce, 0x000003ce},
@@ -958,7 +958,7 @@ static const u32 ar9462_2p0_radio_core[][2] = {
958 {0x0001604c, 0x2699e04f}, 958 {0x0001604c, 0x2699e04f},
959 {0x00016050, 0x6db6db6c}, 959 {0x00016050, 0x6db6db6c},
960 {0x00016058, 0x6c200000}, 960 {0x00016058, 0x6c200000},
961 {0x00016080, 0x00040000}, 961 {0x00016080, 0x000c0000},
962 {0x00016084, 0x9a68048c}, 962 {0x00016084, 0x9a68048c},
963 {0x00016088, 0x54214514}, 963 {0x00016088, 0x54214514},
964 {0x0001608c, 0x1203040b}, 964 {0x0001608c, 0x1203040b},
@@ -981,7 +981,7 @@ static const u32 ar9462_2p0_radio_core[][2] = {
981 {0x00016144, 0x02084080}, 981 {0x00016144, 0x02084080},
982 {0x00016148, 0x000080c0}, 982 {0x00016148, 0x000080c0},
983 {0x00016280, 0x050a0001}, 983 {0x00016280, 0x050a0001},
984 {0x00016284, 0x3d841400}, 984 {0x00016284, 0x3d841418},
985 {0x00016288, 0x00000000}, 985 {0x00016288, 0x00000000},
986 {0x0001628c, 0xe3000000}, 986 {0x0001628c, 0xe3000000},
987 {0x00016290, 0xa1005080}, 987 {0x00016290, 0xa1005080},
@@ -1007,6 +1007,7 @@ static const u32 ar9462_2p0_radio_core[][2] = {
1007 1007
1008static const u32 ar9462_2p0_soc_preamble[][2] = { 1008static const u32 ar9462_2p0_soc_preamble[][2] = {
1009 /* Addr allmodes */ 1009 /* Addr allmodes */
1010 {0x000040a4 ,0x00a0c1c9},
1010 {0x00007020, 0x00000000}, 1011 {0x00007020, 0x00000000},
1011 {0x00007034, 0x00000002}, 1012 {0x00007034, 0x00000002},
1012 {0x00007038, 0x000004c2}, 1013 {0x00007038, 0x000004c2},
diff --git a/drivers/net/wireless/ath/ath9k/ath9k.h b/drivers/net/wireless/ath/ath9k/ath9k.h
index a277cf6f339d..a8c050085648 100644
--- a/drivers/net/wireless/ath/ath9k/ath9k.h
+++ b/drivers/net/wireless/ath/ath9k/ath9k.h
@@ -307,6 +307,7 @@ struct ath_rx {
307 u8 defant; 307 u8 defant;
308 u8 rxotherant; 308 u8 rxotherant;
309 u32 *rxlink; 309 u32 *rxlink;
310 u32 num_pkts;
310 unsigned int rxfilter; 311 unsigned int rxfilter;
311 spinlock_t rxbuflock; 312 spinlock_t rxbuflock;
312 struct list_head rxbuf; 313 struct list_head rxbuf;
@@ -325,6 +326,9 @@ int ath_rx_init(struct ath_softc *sc, int nbufs);
325void ath_rx_cleanup(struct ath_softc *sc); 326void ath_rx_cleanup(struct ath_softc *sc);
326int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp); 327int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp);
327struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype); 328struct ath_txq *ath_txq_setup(struct ath_softc *sc, int qtype, int subtype);
329void ath_txq_lock(struct ath_softc *sc, struct ath_txq *txq);
330void ath_txq_unlock(struct ath_softc *sc, struct ath_txq *txq);
331void ath_txq_unlock_complete(struct ath_softc *sc, struct ath_txq *txq);
328void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq); 332void ath_tx_cleanupq(struct ath_softc *sc, struct ath_txq *txq);
329bool ath_drain_all_txq(struct ath_softc *sc, bool retry_tx); 333bool ath_drain_all_txq(struct ath_softc *sc, bool retry_tx);
330void ath_draintxq(struct ath_softc *sc, 334void ath_draintxq(struct ath_softc *sc,
@@ -414,9 +418,9 @@ int ath_beaconq_config(struct ath_softc *sc);
414void ath_set_beacon(struct ath_softc *sc); 418void ath_set_beacon(struct ath_softc *sc);
415void ath9k_set_beaconing_status(struct ath_softc *sc, bool status); 419void ath9k_set_beaconing_status(struct ath_softc *sc, bool status);
416 420
417/*******/ 421/*******************/
418/* ANI */ 422/* Link Monitoring */
419/*******/ 423/*******************/
420 424
421#define ATH_STA_SHORT_CALINTERVAL 1000 /* 1 second */ 425#define ATH_STA_SHORT_CALINTERVAL 1000 /* 1 second */
422#define ATH_AP_SHORT_CALINTERVAL 100 /* 100 ms */ 426#define ATH_AP_SHORT_CALINTERVAL 100 /* 100 ms */
@@ -427,7 +431,9 @@ void ath9k_set_beaconing_status(struct ath_softc *sc, bool status);
427#define ATH_RESTART_CALINTERVAL 1200000 /* 20 minutes */ 431#define ATH_RESTART_CALINTERVAL 1200000 /* 20 minutes */
428 432
429#define ATH_PAPRD_TIMEOUT 100 /* msecs */ 433#define ATH_PAPRD_TIMEOUT 100 /* msecs */
434#define ATH_PLL_WORK_INTERVAL 100
430 435
436void ath_tx_complete_poll_work(struct work_struct *work);
431void ath_reset_work(struct work_struct *work); 437void ath_reset_work(struct work_struct *work);
432void ath_hw_check(struct work_struct *work); 438void ath_hw_check(struct work_struct *work);
433void ath_hw_pll_work(struct work_struct *work); 439void ath_hw_pll_work(struct work_struct *work);
@@ -436,22 +442,31 @@ void ath_start_rx_poll(struct ath_softc *sc, u8 nbeacon);
436void ath_paprd_calibrate(struct work_struct *work); 442void ath_paprd_calibrate(struct work_struct *work);
437void ath_ani_calibrate(unsigned long data); 443void ath_ani_calibrate(unsigned long data);
438void ath_start_ani(struct ath_common *common); 444void ath_start_ani(struct ath_common *common);
445int ath_update_survey_stats(struct ath_softc *sc);
446void ath_update_survey_nf(struct ath_softc *sc, int channel);
439 447
440/**********/ 448/**********/
441/* BTCOEX */ 449/* BTCOEX */
442/**********/ 450/**********/
443 451
452enum bt_op_flags {
453 BT_OP_PRIORITY_DETECTED,
454 BT_OP_SCAN,
455};
456
444struct ath_btcoex { 457struct ath_btcoex {
445 bool hw_timer_enabled; 458 bool hw_timer_enabled;
446 spinlock_t btcoex_lock; 459 spinlock_t btcoex_lock;
447 struct timer_list period_timer; /* Timer for BT period */ 460 struct timer_list period_timer; /* Timer for BT period */
448 u32 bt_priority_cnt; 461 u32 bt_priority_cnt;
449 unsigned long bt_priority_time; 462 unsigned long bt_priority_time;
463 unsigned long op_flags;
450 int bt_stomp_type; /* Types of BT stomping */ 464 int bt_stomp_type; /* Types of BT stomping */
451 u32 btcoex_no_stomp; /* in usec */ 465 u32 btcoex_no_stomp; /* in usec */
452 u32 btcoex_period; /* in usec */ 466 u32 btcoex_period; /* in usec */
453 u32 btscan_no_stomp; /* in usec */ 467 u32 btscan_no_stomp; /* in usec */
454 u32 duty_cycle; 468 u32 duty_cycle;
469 u32 bt_wait_time;
455 struct ath_gen_timer *no_stomp_timer; /* Timer for no BT stomping */ 470 struct ath_gen_timer *no_stomp_timer; /* Timer for no BT stomping */
456 struct ath_mci_profile mci; 471 struct ath_mci_profile mci;
457}; 472};
@@ -513,8 +528,10 @@ static inline void ath_deinit_leds(struct ath_softc *sc)
513} 528}
514#endif 529#endif
515 530
516 531/*******************************/
517/* Antenna diversity/combining */ 532/* Antenna diversity/combining */
533/*******************************/
534
518#define ATH_ANT_RX_CURRENT_SHIFT 4 535#define ATH_ANT_RX_CURRENT_SHIFT 4
519#define ATH_ANT_RX_MAIN_SHIFT 2 536#define ATH_ANT_RX_MAIN_SHIFT 2
520#define ATH_ANT_RX_MASK 0x3 537#define ATH_ANT_RX_MASK 0x3
@@ -567,6 +584,9 @@ struct ath_ant_comb {
567 unsigned long scan_start_time; 584 unsigned long scan_start_time;
568}; 585};
569 586
587void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs);
588void ath_ant_comb_update(struct ath_softc *sc);
589
570/********************/ 590/********************/
571/* Main driver core */ 591/* Main driver core */
572/********************/ 592/********************/
@@ -584,15 +604,15 @@ struct ath_ant_comb {
584#define ATH_TXPOWER_MAX 100 /* .5 dBm units */ 604#define ATH_TXPOWER_MAX 100 /* .5 dBm units */
585#define ATH_RATE_DUMMY_MARKER 0 605#define ATH_RATE_DUMMY_MARKER 0
586 606
587#define SC_OP_INVALID BIT(0) 607enum sc_op_flags {
588#define SC_OP_BEACONS BIT(1) 608 SC_OP_INVALID,
589#define SC_OP_OFFCHANNEL BIT(2) 609 SC_OP_BEACONS,
590#define SC_OP_RXFLUSH BIT(3) 610 SC_OP_RXFLUSH,
591#define SC_OP_TSF_RESET BIT(4) 611 SC_OP_TSF_RESET,
592#define SC_OP_BT_PRIORITY_DETECTED BIT(5) 612 SC_OP_ANI_RUN,
593#define SC_OP_BT_SCAN BIT(6) 613 SC_OP_PRIM_STA_VIF,
594#define SC_OP_ANI_RUN BIT(7) 614 SC_OP_HW_RESET,
595#define SC_OP_PRIM_STA_VIF BIT(8) 615};
596 616
597/* Powersave flags */ 617/* Powersave flags */
598#define PS_WAIT_FOR_BEACON BIT(0) 618#define PS_WAIT_FOR_BEACON BIT(0)
@@ -638,9 +658,9 @@ struct ath_softc {
638 struct completion paprd_complete; 658 struct completion paprd_complete;
639 659
640 unsigned int hw_busy_count; 660 unsigned int hw_busy_count;
661 unsigned long sc_flags;
641 662
642 u32 intrstatus; 663 u32 intrstatus;
643 u32 sc_flags; /* SC_OP_* */
644 u16 ps_flags; /* PS_* */ 664 u16 ps_flags; /* PS_* */
645 u16 curtxpow; 665 u16 curtxpow;
646 bool ps_enabled; 666 bool ps_enabled;
@@ -678,6 +698,7 @@ struct ath_softc {
678#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT 698#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
679 struct ath_btcoex btcoex; 699 struct ath_btcoex btcoex;
680 struct ath_mci_coex mci_coex; 700 struct ath_mci_coex mci_coex;
701 struct work_struct mci_work;
681#endif 702#endif
682 703
683 struct ath_descdma txsdma; 704 struct ath_descdma txsdma;
@@ -736,5 +757,4 @@ void ath9k_calculate_iter_data(struct ieee80211_hw *hw,
736 struct ieee80211_vif *vif, 757 struct ieee80211_vif *vif,
737 struct ath9k_vif_iter_data *iter_data); 758 struct ath9k_vif_iter_data *iter_data);
738 759
739
740#endif /* ATH9K_H */ 760#endif /* ATH9K_H */
diff --git a/drivers/net/wireless/ath/ath9k/beacon.c b/drivers/net/wireless/ath/ath9k/beacon.c
index 11bc55e3d697..40775da8941e 100644
--- a/drivers/net/wireless/ath/ath9k/beacon.c
+++ b/drivers/net/wireless/ath/ath9k/beacon.c
@@ -48,7 +48,10 @@ int ath_beaconq_config(struct ath_softc *sc)
48 txq = sc->tx.txq_map[WME_AC_BE]; 48 txq = sc->tx.txq_map[WME_AC_BE];
49 ath9k_hw_get_txq_props(ah, txq->axq_qnum, &qi_be); 49 ath9k_hw_get_txq_props(ah, txq->axq_qnum, &qi_be);
50 qi.tqi_aifs = qi_be.tqi_aifs; 50 qi.tqi_aifs = qi_be.tqi_aifs;
51 qi.tqi_cwmin = 4*qi_be.tqi_cwmin; 51 if (ah->slottime == ATH9K_SLOT_TIME_20)
52 qi.tqi_cwmin = 2*qi_be.tqi_cwmin;
53 else
54 qi.tqi_cwmin = 4*qi_be.tqi_cwmin;
52 qi.tqi_cwmax = qi_be.tqi_cwmax; 55 qi.tqi_cwmax = qi_be.tqi_cwmax;
53 } 56 }
54 57
@@ -387,7 +390,7 @@ void ath_beacon_tasklet(unsigned long data)
387 } else if (sc->beacon.bmisscnt >= BSTUCK_THRESH) { 390 } else if (sc->beacon.bmisscnt >= BSTUCK_THRESH) {
388 ath_dbg(common, BSTUCK, "beacon is officially stuck\n"); 391 ath_dbg(common, BSTUCK, "beacon is officially stuck\n");
389 sc->beacon.bmisscnt = 0; 392 sc->beacon.bmisscnt = 0;
390 sc->sc_flags |= SC_OP_TSF_RESET; 393 set_bit(SC_OP_TSF_RESET, &sc->sc_flags);
391 ieee80211_queue_work(sc->hw, &sc->hw_reset_work); 394 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
392 } 395 }
393 396
@@ -477,16 +480,16 @@ static void ath9k_beacon_init(struct ath_softc *sc,
477 u32 next_beacon, 480 u32 next_beacon,
478 u32 beacon_period) 481 u32 beacon_period)
479{ 482{
480 if (sc->sc_flags & SC_OP_TSF_RESET) { 483 if (test_bit(SC_OP_TSF_RESET, &sc->sc_flags)) {
481 ath9k_ps_wakeup(sc); 484 ath9k_ps_wakeup(sc);
482 ath9k_hw_reset_tsf(sc->sc_ah); 485 ath9k_hw_reset_tsf(sc->sc_ah);
483 } 486 }
484 487
485 ath9k_hw_beaconinit(sc->sc_ah, next_beacon, beacon_period); 488 ath9k_hw_beaconinit(sc->sc_ah, next_beacon, beacon_period);
486 489
487 if (sc->sc_flags & SC_OP_TSF_RESET) { 490 if (test_bit(SC_OP_TSF_RESET, &sc->sc_flags)) {
488 ath9k_ps_restore(sc); 491 ath9k_ps_restore(sc);
489 sc->sc_flags &= ~SC_OP_TSF_RESET; 492 clear_bit(SC_OP_TSF_RESET, &sc->sc_flags);
490 } 493 }
491} 494}
492 495
@@ -516,7 +519,7 @@ static void ath_beacon_config_ap(struct ath_softc *sc,
516 /* Set the computed AP beacon timers */ 519 /* Set the computed AP beacon timers */
517 520
518 ath9k_hw_disable_interrupts(ah); 521 ath9k_hw_disable_interrupts(ah);
519 sc->sc_flags |= SC_OP_TSF_RESET; 522 set_bit(SC_OP_TSF_RESET, &sc->sc_flags);
520 ath9k_beacon_init(sc, nexttbtt, intval); 523 ath9k_beacon_init(sc, nexttbtt, intval);
521 sc->beacon.bmisscnt = 0; 524 sc->beacon.bmisscnt = 0;
522 ath9k_hw_set_interrupts(ah); 525 ath9k_hw_set_interrupts(ah);
@@ -659,7 +662,7 @@ static void ath_beacon_config_adhoc(struct ath_softc *sc,
659 u32 tsf, intval, nexttbtt; 662 u32 tsf, intval, nexttbtt;
660 663
661 ath9k_reset_beacon_status(sc); 664 ath9k_reset_beacon_status(sc);
662 if (!(sc->sc_flags & SC_OP_BEACONS)) 665 if (!test_bit(SC_OP_BEACONS, &sc->sc_flags))
663 ath9k_hw_settsf64(ah, sc->beacon.bc_tstamp); 666 ath9k_hw_settsf64(ah, sc->beacon.bc_tstamp);
664 667
665 intval = TU_TO_USEC(conf->beacon_interval); 668 intval = TU_TO_USEC(conf->beacon_interval);
@@ -724,7 +727,7 @@ static bool ath9k_allow_beacon_config(struct ath_softc *sc,
724 */ 727 */
725 if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) && 728 if ((sc->sc_ah->opmode == NL80211_IFTYPE_STATION) &&
726 (vif->type == NL80211_IFTYPE_STATION) && 729 (vif->type == NL80211_IFTYPE_STATION) &&
727 (sc->sc_flags & SC_OP_BEACONS) && 730 test_bit(SC_OP_BEACONS, &sc->sc_flags) &&
728 !avp->primary_sta_vif) { 731 !avp->primary_sta_vif) {
729 ath_dbg(common, CONFIG, 732 ath_dbg(common, CONFIG,
730 "Beacon already configured for a station interface\n"); 733 "Beacon already configured for a station interface\n");
@@ -810,7 +813,7 @@ void ath_set_beacon(struct ath_softc *sc)
810 return; 813 return;
811 } 814 }
812 815
813 sc->sc_flags |= SC_OP_BEACONS; 816 set_bit(SC_OP_BEACONS, &sc->sc_flags);
814} 817}
815 818
816void ath9k_set_beaconing_status(struct ath_softc *sc, bool status) 819void ath9k_set_beaconing_status(struct ath_softc *sc, bool status)
@@ -818,7 +821,7 @@ void ath9k_set_beaconing_status(struct ath_softc *sc, bool status)
818 struct ath_hw *ah = sc->sc_ah; 821 struct ath_hw *ah = sc->sc_ah;
819 822
820 if (!ath_has_valid_bslot(sc)) { 823 if (!ath_has_valid_bslot(sc)) {
821 sc->sc_flags &= ~SC_OP_BEACONS; 824 clear_bit(SC_OP_BEACONS, &sc->sc_flags);
822 return; 825 return;
823 } 826 }
824 827
diff --git a/drivers/net/wireless/ath/ath9k/btcoex.c b/drivers/net/wireless/ath/ath9k/btcoex.c
index 1ca6da80d4ad..acd437384fe4 100644
--- a/drivers/net/wireless/ath/ath9k/btcoex.c
+++ b/drivers/net/wireless/ath/ath9k/btcoex.c
@@ -336,10 +336,16 @@ static void ar9003_btcoex_bt_stomp(struct ath_hw *ah,
336 enum ath_stomp_type stomp_type) 336 enum ath_stomp_type stomp_type)
337{ 337{
338 struct ath_btcoex_hw *btcoex = &ah->btcoex_hw; 338 struct ath_btcoex_hw *btcoex = &ah->btcoex_hw;
339 const u32 *weight = AR_SREV_9462(ah) ? ar9003_wlan_weights[stomp_type] : 339 const u32 *weight = ar9003_wlan_weights[stomp_type];
340 ar9462_wlan_weights[stomp_type];
341 int i; 340 int i;
342 341
342 if (AR_SREV_9462(ah)) {
343 if ((stomp_type == ATH_BTCOEX_STOMP_LOW) &&
344 btcoex->mci.stomp_ftp)
345 stomp_type = ATH_BTCOEX_STOMP_LOW_FTP;
346 weight = ar9462_wlan_weights[stomp_type];
347 }
348
343 for (i = 0; i < AR9300_NUM_WLAN_WEIGHTS; i++) { 349 for (i = 0; i < AR9300_NUM_WLAN_WEIGHTS; i++) {
344 btcoex->bt_weight[i] = AR9300_BT_WGHT; 350 btcoex->bt_weight[i] = AR9300_BT_WGHT;
345 btcoex->wlan_weight[i] = weight[i]; 351 btcoex->wlan_weight[i] = weight[i];
diff --git a/drivers/net/wireless/ath/ath9k/btcoex.h b/drivers/net/wireless/ath/ath9k/btcoex.h
index 3a1e1cfabd5e..20092f98658f 100644
--- a/drivers/net/wireless/ath/ath9k/btcoex.h
+++ b/drivers/net/wireless/ath/ath9k/btcoex.h
@@ -36,6 +36,9 @@
36#define ATH_BT_CNT_THRESHOLD 3 36#define ATH_BT_CNT_THRESHOLD 3
37#define ATH_BT_CNT_SCAN_THRESHOLD 15 37#define ATH_BT_CNT_SCAN_THRESHOLD 15
38 38
39#define ATH_BTCOEX_RX_WAIT_TIME 100
40#define ATH_BTCOEX_STOMP_FTP_THRESH 5
41
39#define AR9300_NUM_BT_WEIGHTS 4 42#define AR9300_NUM_BT_WEIGHTS 4
40#define AR9300_NUM_WLAN_WEIGHTS 4 43#define AR9300_NUM_WLAN_WEIGHTS 4
41/* Defines the BT AR_BT_COEX_WGHT used */ 44/* Defines the BT AR_BT_COEX_WGHT used */
@@ -80,6 +83,7 @@ struct ath9k_hw_mci {
80 u8 bt_ver_major; 83 u8 bt_ver_major;
81 u8 bt_ver_minor; 84 u8 bt_ver_minor;
82 u8 bt_state; 85 u8 bt_state;
86 u8 stomp_ftp;
83}; 87};
84 88
85struct ath_btcoex_hw { 89struct ath_btcoex_hw {
diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
index fde700c4e490..2831258d9507 100644
--- a/drivers/net/wireless/ath/ath9k/debug.c
+++ b/drivers/net/wireless/ath/ath9k/debug.c
@@ -205,10 +205,10 @@ static ssize_t write_file_disable_ani(struct file *file,
205 common->disable_ani = !!disable_ani; 205 common->disable_ani = !!disable_ani;
206 206
207 if (disable_ani) { 207 if (disable_ani) {
208 sc->sc_flags &= ~SC_OP_ANI_RUN; 208 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
209 del_timer_sync(&common->ani.timer); 209 del_timer_sync(&common->ani.timer);
210 } else { 210 } else {
211 sc->sc_flags |= SC_OP_ANI_RUN; 211 set_bit(SC_OP_ANI_RUN, &sc->sc_flags);
212 ath_start_ani(common); 212 ath_start_ani(common);
213 } 213 }
214 214
@@ -374,6 +374,8 @@ void ath_debug_stat_interrupt(struct ath_softc *sc, enum ath9k_int status)
374 sc->debug.stats.istats.dtim++; 374 sc->debug.stats.istats.dtim++;
375 if (status & ATH9K_INT_TSFOOR) 375 if (status & ATH9K_INT_TSFOOR)
376 sc->debug.stats.istats.tsfoor++; 376 sc->debug.stats.istats.tsfoor++;
377 if (status & ATH9K_INT_MCI)
378 sc->debug.stats.istats.mci++;
377} 379}
378 380
379static ssize_t read_file_interrupt(struct file *file, char __user *user_buf, 381static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
@@ -418,6 +420,7 @@ static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
418 PR_IS("DTIMSYNC", dtimsync); 420 PR_IS("DTIMSYNC", dtimsync);
419 PR_IS("DTIM", dtim); 421 PR_IS("DTIM", dtim);
420 PR_IS("TSFOOR", tsfoor); 422 PR_IS("TSFOOR", tsfoor);
423 PR_IS("MCI", mci);
421 PR_IS("TOTAL", total); 424 PR_IS("TOTAL", total);
422 425
423 len += snprintf(buf + len, mxlen - len, 426 len += snprintf(buf + len, mxlen - len,
@@ -1318,7 +1321,7 @@ static int open_file_bb_mac_samps(struct inode *inode, struct file *file)
1318 u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask; 1321 u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
1319 u8 nread; 1322 u8 nread;
1320 1323
1321 if (sc->sc_flags & SC_OP_INVALID) 1324 if (test_bit(SC_OP_INVALID, &sc->sc_flags))
1322 return -EAGAIN; 1325 return -EAGAIN;
1323 1326
1324 buf = vmalloc(size); 1327 buf = vmalloc(size);
diff --git a/drivers/net/wireless/ath/ath9k/debug.h b/drivers/net/wireless/ath/ath9k/debug.h
index c34da09d9103..d0f851cea43a 100644
--- a/drivers/net/wireless/ath/ath9k/debug.h
+++ b/drivers/net/wireless/ath/ath9k/debug.h
@@ -86,6 +86,7 @@ struct ath_interrupt_stats {
86 u32 dtim; 86 u32 dtim;
87 u32 bb_watchdog; 87 u32 bb_watchdog;
88 u32 tsfoor; 88 u32 tsfoor;
89 u32 mci;
89 90
90 /* Sync-cause stats */ 91 /* Sync-cause stats */
91 u32 sync_cause_all; 92 u32 sync_cause_all;
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_4k.c b/drivers/net/wireless/ath/ath9k/eeprom_4k.c
index 4322ac80c203..a850f44fa767 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom_4k.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom_4k.c
@@ -135,7 +135,7 @@ static u32 ath9k_hw_4k_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
135 if (!dump_base_hdr) { 135 if (!dump_base_hdr) {
136 len += snprintf(buf + len, size - len, 136 len += snprintf(buf + len, size - len,
137 "%20s :\n", "2GHz modal Header"); 137 "%20s :\n", "2GHz modal Header");
138 len += ath9k_dump_4k_modal_eeprom(buf, len, size, 138 len = ath9k_dump_4k_modal_eeprom(buf, len, size,
139 &eep->modalHeader); 139 &eep->modalHeader);
140 goto out; 140 goto out;
141 } 141 }
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_9287.c b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
index aa614767adff..cd742fb944c2 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom_9287.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom_9287.c
@@ -132,7 +132,7 @@ static u32 ath9k_hw_ar9287_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
132 if (!dump_base_hdr) { 132 if (!dump_base_hdr) {
133 len += snprintf(buf + len, size - len, 133 len += snprintf(buf + len, size - len,
134 "%20s :\n", "2GHz modal Header"); 134 "%20s :\n", "2GHz modal Header");
135 len += ar9287_dump_modal_eeprom(buf, len, size, 135 len = ar9287_dump_modal_eeprom(buf, len, size,
136 &eep->modalHeader); 136 &eep->modalHeader);
137 goto out; 137 goto out;
138 } 138 }
diff --git a/drivers/net/wireless/ath/ath9k/eeprom_def.c b/drivers/net/wireless/ath/ath9k/eeprom_def.c
index b5fba8b18b8b..56290f318520 100644
--- a/drivers/net/wireless/ath/ath9k/eeprom_def.c
+++ b/drivers/net/wireless/ath/ath9k/eeprom_def.c
@@ -211,11 +211,11 @@ static u32 ath9k_hw_def_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
211 if (!dump_base_hdr) { 211 if (!dump_base_hdr) {
212 len += snprintf(buf + len, size - len, 212 len += snprintf(buf + len, size - len,
213 "%20s :\n", "2GHz modal Header"); 213 "%20s :\n", "2GHz modal Header");
214 len += ath9k_def_dump_modal_eeprom(buf, len, size, 214 len = ath9k_def_dump_modal_eeprom(buf, len, size,
215 &eep->modalHeader[0]); 215 &eep->modalHeader[0]);
216 len += snprintf(buf + len, size - len, 216 len += snprintf(buf + len, size - len,
217 "%20s :\n", "5GHz modal Header"); 217 "%20s :\n", "5GHz modal Header");
218 len += ath9k_def_dump_modal_eeprom(buf, len, size, 218 len = ath9k_def_dump_modal_eeprom(buf, len, size,
219 &eep->modalHeader[1]); 219 &eep->modalHeader[1]);
220 goto out; 220 goto out;
221 } 221 }
diff --git a/drivers/net/wireless/ath/ath9k/gpio.c b/drivers/net/wireless/ath/ath9k/gpio.c
index 281a9af0f1b6..26032cb59b8a 100644
--- a/drivers/net/wireless/ath/ath9k/gpio.c
+++ b/drivers/net/wireless/ath/ath9k/gpio.c
@@ -132,17 +132,18 @@ static void ath_detect_bt_priority(struct ath_softc *sc)
132 132
133 if (time_after(jiffies, btcoex->bt_priority_time + 133 if (time_after(jiffies, btcoex->bt_priority_time +
134 msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) { 134 msecs_to_jiffies(ATH_BT_PRIORITY_TIME_THRESHOLD))) {
135 sc->sc_flags &= ~(SC_OP_BT_PRIORITY_DETECTED | SC_OP_BT_SCAN); 135 clear_bit(BT_OP_PRIORITY_DETECTED, &btcoex->op_flags);
136 clear_bit(BT_OP_SCAN, &btcoex->op_flags);
136 /* Detect if colocated bt started scanning */ 137 /* Detect if colocated bt started scanning */
137 if (btcoex->bt_priority_cnt >= ATH_BT_CNT_SCAN_THRESHOLD) { 138 if (btcoex->bt_priority_cnt >= ATH_BT_CNT_SCAN_THRESHOLD) {
138 ath_dbg(ath9k_hw_common(sc->sc_ah), BTCOEX, 139 ath_dbg(ath9k_hw_common(sc->sc_ah), BTCOEX,
139 "BT scan detected\n"); 140 "BT scan detected\n");
140 sc->sc_flags |= (SC_OP_BT_SCAN | 141 set_bit(BT_OP_PRIORITY_DETECTED, &btcoex->op_flags);
141 SC_OP_BT_PRIORITY_DETECTED); 142 set_bit(BT_OP_SCAN, &btcoex->op_flags);
142 } else if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) { 143 } else if (btcoex->bt_priority_cnt >= ATH_BT_CNT_THRESHOLD) {
143 ath_dbg(ath9k_hw_common(sc->sc_ah), BTCOEX, 144 ath_dbg(ath9k_hw_common(sc->sc_ah), BTCOEX,
144 "BT priority traffic detected\n"); 145 "BT priority traffic detected\n");
145 sc->sc_flags |= SC_OP_BT_PRIORITY_DETECTED; 146 set_bit(BT_OP_PRIORITY_DETECTED, &btcoex->op_flags);
146 } 147 }
147 148
148 btcoex->bt_priority_cnt = 0; 149 btcoex->bt_priority_cnt = 0;
@@ -190,13 +191,26 @@ static void ath_btcoex_period_timer(unsigned long data)
190 struct ath_softc *sc = (struct ath_softc *) data; 191 struct ath_softc *sc = (struct ath_softc *) data;
191 struct ath_hw *ah = sc->sc_ah; 192 struct ath_hw *ah = sc->sc_ah;
192 struct ath_btcoex *btcoex = &sc->btcoex; 193 struct ath_btcoex *btcoex = &sc->btcoex;
194 struct ath_mci_profile *mci = &btcoex->mci;
193 u32 timer_period; 195 u32 timer_period;
194 bool is_btscan; 196 bool is_btscan;
195 197
196 ath9k_ps_wakeup(sc); 198 ath9k_ps_wakeup(sc);
197 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_MCI)) 199 if (!(ah->caps.hw_caps & ATH9K_HW_CAP_MCI))
198 ath_detect_bt_priority(sc); 200 ath_detect_bt_priority(sc);
199 is_btscan = sc->sc_flags & SC_OP_BT_SCAN; 201 is_btscan = test_bit(BT_OP_SCAN, &btcoex->op_flags);
202
203 btcoex->bt_wait_time += btcoex->btcoex_period;
204 if (btcoex->bt_wait_time > ATH_BTCOEX_RX_WAIT_TIME) {
205 if (ar9003_mci_state(ah, MCI_STATE_NEED_FTP_STOMP) &&
206 (mci->num_pan || mci->num_other_acl))
207 ah->btcoex_hw.mci.stomp_ftp =
208 (sc->rx.num_pkts < ATH_BTCOEX_STOMP_FTP_THRESH);
209 else
210 ah->btcoex_hw.mci.stomp_ftp = false;
211 btcoex->bt_wait_time = 0;
212 sc->rx.num_pkts = 0;
213 }
200 214
201 spin_lock_bh(&btcoex->btcoex_lock); 215 spin_lock_bh(&btcoex->btcoex_lock);
202 216
@@ -218,9 +232,8 @@ static void ath_btcoex_period_timer(unsigned long data)
218 } 232 }
219 233
220 ath9k_ps_restore(sc); 234 ath9k_ps_restore(sc);
221 timer_period = btcoex->btcoex_period / 1000; 235 timer_period = btcoex->btcoex_period;
222 mod_timer(&btcoex->period_timer, jiffies + 236 mod_timer(&btcoex->period_timer, jiffies + msecs_to_jiffies(timer_period));
223 msecs_to_jiffies(timer_period));
224} 237}
225 238
226/* 239/*
@@ -233,14 +246,14 @@ static void ath_btcoex_no_stomp_timer(void *arg)
233 struct ath_hw *ah = sc->sc_ah; 246 struct ath_hw *ah = sc->sc_ah;
234 struct ath_btcoex *btcoex = &sc->btcoex; 247 struct ath_btcoex *btcoex = &sc->btcoex;
235 struct ath_common *common = ath9k_hw_common(ah); 248 struct ath_common *common = ath9k_hw_common(ah);
236 bool is_btscan = sc->sc_flags & SC_OP_BT_SCAN;
237 249
238 ath_dbg(common, BTCOEX, "no stomp timer running\n"); 250 ath_dbg(common, BTCOEX, "no stomp timer running\n");
239 251
240 ath9k_ps_wakeup(sc); 252 ath9k_ps_wakeup(sc);
241 spin_lock_bh(&btcoex->btcoex_lock); 253 spin_lock_bh(&btcoex->btcoex_lock);
242 254
243 if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW || is_btscan) 255 if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_LOW ||
256 test_bit(BT_OP_SCAN, &btcoex->op_flags))
244 ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_NONE); 257 ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_NONE);
245 else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL) 258 else if (btcoex->bt_stomp_type == ATH_BTCOEX_STOMP_ALL)
246 ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_LOW); 259 ath9k_hw_btcoex_bt_stomp(ah, ATH_BTCOEX_STOMP_LOW);
@@ -254,10 +267,10 @@ static int ath_init_btcoex_timer(struct ath_softc *sc)
254{ 267{
255 struct ath_btcoex *btcoex = &sc->btcoex; 268 struct ath_btcoex *btcoex = &sc->btcoex;
256 269
257 btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD * 1000; 270 btcoex->btcoex_period = ATH_BTCOEX_DEF_BT_PERIOD;
258 btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) * 271 btcoex->btcoex_no_stomp = (100 - ATH_BTCOEX_DEF_DUTY_CYCLE) * 1000 *
259 btcoex->btcoex_period / 100; 272 btcoex->btcoex_period / 100;
260 btcoex->btscan_no_stomp = (100 - ATH_BTCOEX_BTSCAN_DUTY_CYCLE) * 273 btcoex->btscan_no_stomp = (100 - ATH_BTCOEX_BTSCAN_DUTY_CYCLE) * 1000 *
261 btcoex->btcoex_period / 100; 274 btcoex->btcoex_period / 100;
262 275
263 setup_timer(&btcoex->period_timer, ath_btcoex_period_timer, 276 setup_timer(&btcoex->period_timer, ath_btcoex_period_timer,
@@ -292,7 +305,7 @@ void ath9k_btcoex_timer_resume(struct ath_softc *sc)
292 305
293 btcoex->bt_priority_cnt = 0; 306 btcoex->bt_priority_cnt = 0;
294 btcoex->bt_priority_time = jiffies; 307 btcoex->bt_priority_time = jiffies;
295 sc->sc_flags &= ~(SC_OP_BT_PRIORITY_DETECTED | SC_OP_BT_SCAN); 308 btcoex->op_flags &= ~(BT_OP_PRIORITY_DETECTED | BT_OP_SCAN);
296 309
297 mod_timer(&btcoex->period_timer, jiffies); 310 mod_timer(&btcoex->period_timer, jiffies);
298} 311}
@@ -316,12 +329,13 @@ void ath9k_btcoex_timer_pause(struct ath_softc *sc)
316 329
317u16 ath9k_btcoex_aggr_limit(struct ath_softc *sc, u32 max_4ms_framelen) 330u16 ath9k_btcoex_aggr_limit(struct ath_softc *sc, u32 max_4ms_framelen)
318{ 331{
332 struct ath_btcoex *btcoex = &sc->btcoex;
319 struct ath_mci_profile *mci = &sc->btcoex.mci; 333 struct ath_mci_profile *mci = &sc->btcoex.mci;
320 u16 aggr_limit = 0; 334 u16 aggr_limit = 0;
321 335
322 if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_MCI) && mci->aggr_limit) 336 if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_MCI) && mci->aggr_limit)
323 aggr_limit = (max_4ms_framelen * mci->aggr_limit) >> 4; 337 aggr_limit = (max_4ms_framelen * mci->aggr_limit) >> 4;
324 else if (sc->sc_flags & SC_OP_BT_PRIORITY_DETECTED) 338 else if (test_bit(BT_OP_PRIORITY_DETECTED, &btcoex->op_flags))
325 aggr_limit = min((max_4ms_framelen * 3) / 8, 339 aggr_limit = min((max_4ms_framelen * 3) / 8,
326 (u32)ATH_AMPDU_LIMIT_MAX); 340 (u32)ATH_AMPDU_LIMIT_MAX);
327 341
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 7db1890448f2..784baee5db84 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -390,14 +390,6 @@ static void ath9k_hw_disablepcie(struct ath_hw *ah)
390 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000); 390 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
391} 391}
392 392
393static void ath9k_hw_aspm_init(struct ath_hw *ah)
394{
395 struct ath_common *common = ath9k_hw_common(ah);
396
397 if (common->bus_ops->aspm_init)
398 common->bus_ops->aspm_init(common);
399}
400
401/* This should work for all families including legacy */ 393/* This should work for all families including legacy */
402static bool ath9k_hw_chip_test(struct ath_hw *ah) 394static bool ath9k_hw_chip_test(struct ath_hw *ah)
403{ 395{
@@ -693,9 +685,6 @@ static int __ath9k_hw_init(struct ath_hw *ah)
693 if (r) 685 if (r)
694 return r; 686 return r;
695 687
696 if (ah->is_pciexpress)
697 ath9k_hw_aspm_init(ah);
698
699 r = ath9k_hw_init_macaddr(ah); 688 r = ath9k_hw_init_macaddr(ah);
700 if (r) { 689 if (r) {
701 ath_err(common, "Failed to initialize MAC address\n"); 690 ath_err(common, "Failed to initialize MAC address\n");
@@ -1359,6 +1348,9 @@ static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
1359 } 1348 }
1360 } 1349 }
1361 1350
1351 if (ath9k_hw_mci_is_enabled(ah))
1352 ar9003_mci_check_gpm_offset(ah);
1353
1362 REG_WRITE(ah, AR_RTC_RC, rst_flags); 1354 REG_WRITE(ah, AR_RTC_RC, rst_flags);
1363 1355
1364 REGWRITE_BUFFER_FLUSH(ah); 1356 REGWRITE_BUFFER_FLUSH(ah);
@@ -1443,9 +1435,6 @@ static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
1443 break; 1435 break;
1444 } 1436 }
1445 1437
1446 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
1447 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
1448
1449 return ret; 1438 return ret;
1450} 1439}
1451 1440
@@ -1721,8 +1710,8 @@ static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
1721 ath9k_hw_loadnf(ah, ah->curchan); 1710 ath9k_hw_loadnf(ah, ah->curchan);
1722 ath9k_hw_start_nfcal(ah, true); 1711 ath9k_hw_start_nfcal(ah, true);
1723 1712
1724 if ((ah->caps.hw_caps & ATH9K_HW_CAP_MCI) && ar9003_mci_is_ready(ah)) 1713 if (ath9k_hw_mci_is_enabled(ah))
1725 ar9003_mci_2g5g_switch(ah, true); 1714 ar9003_mci_2g5g_switch(ah, false);
1726 1715
1727 if (AR_SREV_9271(ah)) 1716 if (AR_SREV_9271(ah))
1728 ar9002_hw_load_ani_reg(ah, chan); 1717 ar9002_hw_load_ani_reg(ah, chan);
@@ -1742,10 +1731,9 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1742 u64 tsf = 0; 1731 u64 tsf = 0;
1743 int i, r; 1732 int i, r;
1744 bool start_mci_reset = false; 1733 bool start_mci_reset = false;
1745 bool mci = !!(ah->caps.hw_caps & ATH9K_HW_CAP_MCI);
1746 bool save_fullsleep = ah->chip_fullsleep; 1734 bool save_fullsleep = ah->chip_fullsleep;
1747 1735
1748 if (mci) { 1736 if (ath9k_hw_mci_is_enabled(ah)) {
1749 start_mci_reset = ar9003_mci_start_reset(ah, chan); 1737 start_mci_reset = ar9003_mci_start_reset(ah, chan);
1750 if (start_mci_reset) 1738 if (start_mci_reset)
1751 return 0; 1739 return 0;
@@ -1774,7 +1762,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1774 return r; 1762 return r;
1775 } 1763 }
1776 1764
1777 if (mci) 1765 if (ath9k_hw_mci_is_enabled(ah))
1778 ar9003_mci_stop_bt(ah, save_fullsleep); 1766 ar9003_mci_stop_bt(ah, save_fullsleep);
1779 1767
1780 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA); 1768 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
@@ -1832,7 +1820,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1832 if (r) 1820 if (r)
1833 return r; 1821 return r;
1834 1822
1835 if (mci) 1823 if (ath9k_hw_mci_is_enabled(ah))
1836 ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep); 1824 ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep);
1837 1825
1838 /* 1826 /*
@@ -1927,7 +1915,8 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1927 1915
1928 ath9k_hw_set_dma(ah); 1916 ath9k_hw_set_dma(ah);
1929 1917
1930 REG_WRITE(ah, AR_OBS, 8); 1918 if (!ath9k_hw_mci_is_enabled(ah))
1919 REG_WRITE(ah, AR_OBS, 8);
1931 1920
1932 if (ah->config.rx_intr_mitigation) { 1921 if (ah->config.rx_intr_mitigation) {
1933 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500); 1922 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
@@ -1951,7 +1940,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1951 ath9k_hw_loadnf(ah, chan); 1940 ath9k_hw_loadnf(ah, chan);
1952 ath9k_hw_start_nfcal(ah, true); 1941 ath9k_hw_start_nfcal(ah, true);
1953 1942
1954 if (mci && ar9003_mci_end_reset(ah, chan, caldata)) 1943 if (ath9k_hw_mci_is_enabled(ah) && ar9003_mci_end_reset(ah, chan, caldata))
1955 return -EIO; 1944 return -EIO;
1956 1945
1957 ENABLE_REGWRITE_BUFFER(ah); 1946 ENABLE_REGWRITE_BUFFER(ah);
@@ -1996,7 +1985,7 @@ int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1996 if (ath9k_hw_btcoex_is_enabled(ah)) 1985 if (ath9k_hw_btcoex_is_enabled(ah))
1997 ath9k_hw_btcoex_enable(ah); 1986 ath9k_hw_btcoex_enable(ah);
1998 1987
1999 if (mci) 1988 if (ath9k_hw_mci_is_enabled(ah))
2000 ar9003_mci_check_bt(ah); 1989 ar9003_mci_check_bt(ah);
2001 1990
2002 if (AR_SREV_9300_20_OR_LATER(ah)) { 1991 if (AR_SREV_9300_20_OR_LATER(ah)) {
@@ -2019,39 +2008,35 @@ EXPORT_SYMBOL(ath9k_hw_reset);
2019 * Notify Power Mgt is disabled in self-generated frames. 2008 * Notify Power Mgt is disabled in self-generated frames.
2020 * If requested, force chip to sleep. 2009 * If requested, force chip to sleep.
2021 */ 2010 */
2022static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip) 2011static void ath9k_set_power_sleep(struct ath_hw *ah)
2023{ 2012{
2024 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); 2013 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2025 if (setChip) {
2026 if (AR_SREV_9462(ah)) {
2027 REG_WRITE(ah, AR_TIMER_MODE,
2028 REG_READ(ah, AR_TIMER_MODE) & 0xFFFFFF00);
2029 REG_WRITE(ah, AR_NDP2_TIMER_MODE, REG_READ(ah,
2030 AR_NDP2_TIMER_MODE) & 0xFFFFFF00);
2031 REG_WRITE(ah, AR_SLP32_INC,
2032 REG_READ(ah, AR_SLP32_INC) & 0xFFF00000);
2033 /* xxx Required for WLAN only case ? */
2034 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
2035 udelay(100);
2036 }
2037 2014
2038 /* 2015 if (AR_SREV_9462(ah)) {
2039 * Clear the RTC force wake bit to allow the 2016 REG_CLR_BIT(ah, AR_TIMER_MODE, 0xff);
2040 * mac to go to sleep. 2017 REG_CLR_BIT(ah, AR_NDP2_TIMER_MODE, 0xff);
2041 */ 2018 REG_CLR_BIT(ah, AR_SLP32_INC, 0xfffff);
2042 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN); 2019 /* xxx Required for WLAN only case ? */
2020 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
2021 udelay(100);
2022 }
2043 2023
2044 if (AR_SREV_9462(ah)) 2024 /*
2045 udelay(100); 2025 * Clear the RTC force wake bit to allow the
2026 * mac to go to sleep.
2027 */
2028 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
2046 2029
2047 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah)) 2030 if (ath9k_hw_mci_is_enabled(ah))
2048 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF); 2031 udelay(100);
2049 2032
2050 /* Shutdown chip. Active low */ 2033 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
2051 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) { 2034 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2052 REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN); 2035
2053 udelay(2); 2036 /* Shutdown chip. Active low */
2054 } 2037 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) {
2038 REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
2039 udelay(2);
2055 } 2040 }
2056 2041
2057 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */ 2042 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
@@ -2064,44 +2049,38 @@ static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
2064 * frames. If request, set power mode of chip to 2049 * frames. If request, set power mode of chip to
2065 * auto/normal. Duration in units of 128us (1/8 TU). 2050 * auto/normal. Duration in units of 128us (1/8 TU).
2066 */ 2051 */
2067static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip) 2052static void ath9k_set_power_network_sleep(struct ath_hw *ah)
2068{ 2053{
2069 u32 val; 2054 struct ath9k_hw_capabilities *pCap = &ah->caps;
2070 2055
2071 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); 2056 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2072 if (setChip) {
2073 struct ath9k_hw_capabilities *pCap = &ah->caps;
2074 2057
2075 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) { 2058 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2076 /* Set WakeOnInterrupt bit; clear ForceWake bit */ 2059 /* Set WakeOnInterrupt bit; clear ForceWake bit */
2077 REG_WRITE(ah, AR_RTC_FORCE_WAKE, 2060 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2078 AR_RTC_FORCE_WAKE_ON_INT); 2061 AR_RTC_FORCE_WAKE_ON_INT);
2079 } else { 2062 } else {
2080 2063
2081 /* When chip goes into network sleep, it could be waken 2064 /* When chip goes into network sleep, it could be waken
2082 * up by MCI_INT interrupt caused by BT's HW messages 2065 * up by MCI_INT interrupt caused by BT's HW messages
2083 * (LNA_xxx, CONT_xxx) which chould be in a very fast 2066 * (LNA_xxx, CONT_xxx) which chould be in a very fast
2084 * rate (~100us). This will cause chip to leave and 2067 * rate (~100us). This will cause chip to leave and
2085 * re-enter network sleep mode frequently, which in 2068 * re-enter network sleep mode frequently, which in
2086 * consequence will have WLAN MCI HW to generate lots of 2069 * consequence will have WLAN MCI HW to generate lots of
2087 * SYS_WAKING and SYS_SLEEPING messages which will make 2070 * SYS_WAKING and SYS_SLEEPING messages which will make
2088 * BT CPU to busy to process. 2071 * BT CPU to busy to process.
2089 */ 2072 */
2090 if (AR_SREV_9462(ah)) { 2073 if (ath9k_hw_mci_is_enabled(ah))
2091 val = REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_EN) & 2074 REG_CLR_BIT(ah, AR_MCI_INTERRUPT_RX_MSG_EN,
2092 ~AR_MCI_INTERRUPT_RX_HW_MSG_MASK; 2075 AR_MCI_INTERRUPT_RX_HW_MSG_MASK);
2093 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, val); 2076 /*
2094 } 2077 * Clear the RTC force wake bit to allow the
2095 /* 2078 * mac to go to sleep.
2096 * Clear the RTC force wake bit to allow the 2079 */
2097 * mac to go to sleep. 2080 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
2098 */ 2081
2099 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, 2082 if (ath9k_hw_mci_is_enabled(ah))
2100 AR_RTC_FORCE_WAKE_EN); 2083 udelay(30);
2101
2102 if (AR_SREV_9462(ah))
2103 udelay(30);
2104 }
2105 } 2084 }
2106 2085
2107 /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */ 2086 /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
@@ -2109,7 +2088,7 @@ static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
2109 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE); 2088 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
2110} 2089}
2111 2090
2112static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip) 2091static bool ath9k_hw_set_power_awake(struct ath_hw *ah)
2113{ 2092{
2114 u32 val; 2093 u32 val;
2115 int i; 2094 int i;
@@ -2120,37 +2099,38 @@ static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
2120 udelay(10); 2099 udelay(10);
2121 } 2100 }
2122 2101
2123 if (setChip) { 2102 if ((REG_READ(ah, AR_RTC_STATUS) &
2124 if ((REG_READ(ah, AR_RTC_STATUS) & 2103 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2125 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) { 2104 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
2126 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) { 2105 return false;
2127 return false;
2128 }
2129 if (!AR_SREV_9300_20_OR_LATER(ah))
2130 ath9k_hw_init_pll(ah, NULL);
2131 } 2106 }
2132 if (AR_SREV_9100(ah)) 2107 if (!AR_SREV_9300_20_OR_LATER(ah))
2133 REG_SET_BIT(ah, AR_RTC_RESET, 2108 ath9k_hw_init_pll(ah, NULL);
2134 AR_RTC_RESET_EN); 2109 }
2110 if (AR_SREV_9100(ah))
2111 REG_SET_BIT(ah, AR_RTC_RESET,
2112 AR_RTC_RESET_EN);
2135 2113
2114 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2115 AR_RTC_FORCE_WAKE_EN);
2116 udelay(50);
2117
2118 if (ath9k_hw_mci_is_enabled(ah))
2119 ar9003_mci_set_power_awake(ah);
2120
2121 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2122 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2123 if (val == AR_RTC_STATUS_ON)
2124 break;
2125 udelay(50);
2136 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, 2126 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2137 AR_RTC_FORCE_WAKE_EN); 2127 AR_RTC_FORCE_WAKE_EN);
2138 udelay(50); 2128 }
2139 2129 if (i == 0) {
2140 for (i = POWER_UP_TIME / 50; i > 0; i--) { 2130 ath_err(ath9k_hw_common(ah),
2141 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M; 2131 "Failed to wakeup in %uus\n",
2142 if (val == AR_RTC_STATUS_ON) 2132 POWER_UP_TIME / 20);
2143 break; 2133 return false;
2144 udelay(50);
2145 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2146 AR_RTC_FORCE_WAKE_EN);
2147 }
2148 if (i == 0) {
2149 ath_err(ath9k_hw_common(ah),
2150 "Failed to wakeup in %uus\n",
2151 POWER_UP_TIME / 20);
2152 return false;
2153 }
2154 } 2134 }
2155 2135
2156 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); 2136 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
@@ -2161,7 +2141,7 @@ static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
2161bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode) 2141bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
2162{ 2142{
2163 struct ath_common *common = ath9k_hw_common(ah); 2143 struct ath_common *common = ath9k_hw_common(ah);
2164 int status = true, setChip = true; 2144 int status = true;
2165 static const char *modes[] = { 2145 static const char *modes[] = {
2166 "AWAKE", 2146 "AWAKE",
2167 "FULL-SLEEP", 2147 "FULL-SLEEP",
@@ -2177,25 +2157,17 @@ bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
2177 2157
2178 switch (mode) { 2158 switch (mode) {
2179 case ATH9K_PM_AWAKE: 2159 case ATH9K_PM_AWAKE:
2180 status = ath9k_hw_set_power_awake(ah, setChip); 2160 status = ath9k_hw_set_power_awake(ah);
2181
2182 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
2183 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
2184
2185 break; 2161 break;
2186 case ATH9K_PM_FULL_SLEEP: 2162 case ATH9K_PM_FULL_SLEEP:
2187 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI) 2163 if (ath9k_hw_mci_is_enabled(ah))
2188 ar9003_mci_set_full_sleep(ah); 2164 ar9003_mci_set_full_sleep(ah);
2189 2165
2190 ath9k_set_power_sleep(ah, setChip); 2166 ath9k_set_power_sleep(ah);
2191 ah->chip_fullsleep = true; 2167 ah->chip_fullsleep = true;
2192 break; 2168 break;
2193 case ATH9K_PM_NETWORK_SLEEP: 2169 case ATH9K_PM_NETWORK_SLEEP:
2194 2170 ath9k_set_power_network_sleep(ah);
2195 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
2196 REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2);
2197
2198 ath9k_set_power_network_sleep(ah, setChip);
2199 break; 2171 break;
2200 default: 2172 default:
2201 ath_err(common, "Unknown power mode %u\n", mode); 2173 ath_err(common, "Unknown power mode %u\n", mode);
@@ -2765,6 +2737,9 @@ EXPORT_SYMBOL(ath9k_hw_setrxfilter);
2765 2737
2766bool ath9k_hw_phy_disable(struct ath_hw *ah) 2738bool ath9k_hw_phy_disable(struct ath_hw *ah)
2767{ 2739{
2740 if (ath9k_hw_mci_is_enabled(ah))
2741 ar9003_mci_bt_gain_ctrl(ah);
2742
2768 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM)) 2743 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2769 return false; 2744 return false;
2770 2745
diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
index b620c557c2a6..03d590924c64 100644
--- a/drivers/net/wireless/ath/ath9k/hw.h
+++ b/drivers/net/wireless/ath/ath9k/hw.h
@@ -824,7 +824,6 @@ struct ath_hw {
824 struct ar5416IniArray ini_japan2484; 824 struct ar5416IniArray ini_japan2484;
825 struct ar5416IniArray iniModes_9271_ANI_reg; 825 struct ar5416IniArray iniModes_9271_ANI_reg;
826 struct ar5416IniArray ini_radio_post_sys2ant; 826 struct ar5416IniArray ini_radio_post_sys2ant;
827 struct ar5416IniArray ini_BTCOEX_MAX_TXPWR;
828 827
829 struct ar5416IniArray iniMac[ATH_INI_NUM_SPLIT]; 828 struct ar5416IniArray iniMac[ATH_INI_NUM_SPLIT];
830 struct ar5416IniArray iniBB[ATH_INI_NUM_SPLIT]; 829 struct ar5416IniArray iniBB[ATH_INI_NUM_SPLIT];
@@ -1037,6 +1036,11 @@ static inline bool ath9k_hw_btcoex_is_enabled(struct ath_hw *ah)
1037{ 1036{
1038 return ah->btcoex_hw.enabled; 1037 return ah->btcoex_hw.enabled;
1039} 1038}
1039static inline bool ath9k_hw_mci_is_enabled(struct ath_hw *ah)
1040{
1041 return ah->btcoex_hw.enabled && (ah->caps.hw_caps & ATH9K_HW_CAP_MCI);
1042
1043}
1040void ath9k_hw_btcoex_enable(struct ath_hw *ah); 1044void ath9k_hw_btcoex_enable(struct ath_hw *ah);
1041static inline enum ath_btcoex_scheme 1045static inline enum ath_btcoex_scheme
1042ath9k_hw_get_btcoex_scheme(struct ath_hw *ah) 1046ath9k_hw_get_btcoex_scheme(struct ath_hw *ah)
@@ -1048,6 +1052,10 @@ static inline bool ath9k_hw_btcoex_is_enabled(struct ath_hw *ah)
1048{ 1052{
1049 return false; 1053 return false;
1050} 1054}
1055static inline bool ath9k_hw_mci_is_enabled(struct ath_hw *ah)
1056{
1057 return false;
1058}
1051static inline void ath9k_hw_btcoex_enable(struct ath_hw *ah) 1059static inline void ath9k_hw_btcoex_enable(struct ath_hw *ah)
1052{ 1060{
1053} 1061}
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index dee9e092449a..9dfce1a69c73 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -489,6 +489,7 @@ static void ath9k_init_misc(struct ath_softc *sc)
489 489
490 setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc); 490 setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
491 491
492 sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
492 sc->config.txpowlimit = ATH_TXPOWER_MAX; 493 sc->config.txpowlimit = ATH_TXPOWER_MAX;
493 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN); 494 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
494 sc->beacon.slottime = ATH9K_SLOT_TIME_9; 495 sc->beacon.slottime = ATH9K_SLOT_TIME_9;
@@ -560,6 +561,12 @@ static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
560 tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet, 561 tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
561 (unsigned long)sc); 562 (unsigned long)sc);
562 563
564 INIT_WORK(&sc->hw_reset_work, ath_reset_work);
565 INIT_WORK(&sc->hw_check_work, ath_hw_check);
566 INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
567 INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
568 setup_timer(&sc->rx_poll_timer, ath_rx_poll, (unsigned long)sc);
569
563 /* 570 /*
564 * Cache line size is used to size and align various 571 * Cache line size is used to size and align various
565 * structures used to communicate with the hardware. 572 * structures used to communicate with the hardware.
@@ -590,6 +597,9 @@ static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
590 ath9k_cmn_init_crypto(sc->sc_ah); 597 ath9k_cmn_init_crypto(sc->sc_ah);
591 ath9k_init_misc(sc); 598 ath9k_init_misc(sc);
592 599
600 if (common->bus_ops->aspm_init)
601 common->bus_ops->aspm_init(common);
602
593 return 0; 603 return 0;
594 604
595err_btcoex: 605err_btcoex:
@@ -782,11 +792,6 @@ int ath9k_init_device(u16 devid, struct ath_softc *sc,
782 ARRAY_SIZE(ath9k_tpt_blink)); 792 ARRAY_SIZE(ath9k_tpt_blink));
783#endif 793#endif
784 794
785 INIT_WORK(&sc->hw_reset_work, ath_reset_work);
786 INIT_WORK(&sc->hw_check_work, ath_hw_check);
787 INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
788 INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
789
790 /* Register with mac80211 */ 795 /* Register with mac80211 */
791 error = ieee80211_register_hw(hw); 796 error = ieee80211_register_hw(hw);
792 if (error) 797 if (error)
@@ -805,9 +810,6 @@ int ath9k_init_device(u16 devid, struct ath_softc *sc,
805 goto error_world; 810 goto error_world;
806 } 811 }
807 812
808 setup_timer(&sc->rx_poll_timer, ath_rx_poll, (unsigned long)sc);
809 sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
810
811 ath_init_leds(sc); 813 ath_init_leds(sc);
812 ath_start_rfkill_poll(sc); 814 ath_start_rfkill_poll(sc);
813 815
diff --git a/drivers/net/wireless/ath/ath9k/link.c b/drivers/net/wireless/ath/ath9k/link.c
new file mode 100644
index 000000000000..a105c9426251
--- /dev/null
+++ b/drivers/net/wireless/ath/ath9k/link.c
@@ -0,0 +1,510 @@
1/*
2 * Copyright (c) 2012 Qualcomm Atheros, 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 "ath9k.h"
18
19/*
20 * TX polling - checks if the TX engine is stuck somewhere
21 * and issues a chip reset if so.
22 */
23void ath_tx_complete_poll_work(struct work_struct *work)
24{
25 struct ath_softc *sc = container_of(work, struct ath_softc,
26 tx_complete_work.work);
27 struct ath_txq *txq;
28 int i;
29 bool needreset = false;
30#ifdef CONFIG_ATH9K_DEBUGFS
31 sc->tx_complete_poll_work_seen++;
32#endif
33
34 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
35 if (ATH_TXQ_SETUP(sc, i)) {
36 txq = &sc->tx.txq[i];
37 ath_txq_lock(sc, txq);
38 if (txq->axq_depth) {
39 if (txq->axq_tx_inprogress) {
40 needreset = true;
41 ath_txq_unlock(sc, txq);
42 break;
43 } else {
44 txq->axq_tx_inprogress = true;
45 }
46 }
47 ath_txq_unlock_complete(sc, txq);
48 }
49
50 if (needreset) {
51 ath_dbg(ath9k_hw_common(sc->sc_ah), RESET,
52 "tx hung, resetting the chip\n");
53 RESET_STAT_INC(sc, RESET_TYPE_TX_HANG);
54 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
55 return;
56 }
57
58 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work,
59 msecs_to_jiffies(ATH_TX_COMPLETE_POLL_INT));
60}
61
62/*
63 * Checks if the BB/MAC is hung.
64 */
65void ath_hw_check(struct work_struct *work)
66{
67 struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
68 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
69 unsigned long flags;
70 int busy;
71 u8 is_alive, nbeacon = 1;
72
73 ath9k_ps_wakeup(sc);
74 is_alive = ath9k_hw_check_alive(sc->sc_ah);
75
76 if (is_alive && !AR_SREV_9300(sc->sc_ah))
77 goto out;
78 else if (!is_alive && AR_SREV_9300(sc->sc_ah)) {
79 ath_dbg(common, RESET,
80 "DCU stuck is detected. Schedule chip reset\n");
81 RESET_STAT_INC(sc, RESET_TYPE_MAC_HANG);
82 goto sched_reset;
83 }
84
85 spin_lock_irqsave(&common->cc_lock, flags);
86 busy = ath_update_survey_stats(sc);
87 spin_unlock_irqrestore(&common->cc_lock, flags);
88
89 ath_dbg(common, RESET, "Possible baseband hang, busy=%d (try %d)\n",
90 busy, sc->hw_busy_count + 1);
91 if (busy >= 99) {
92 if (++sc->hw_busy_count >= 3) {
93 RESET_STAT_INC(sc, RESET_TYPE_BB_HANG);
94 goto sched_reset;
95 }
96 } else if (busy >= 0) {
97 sc->hw_busy_count = 0;
98 nbeacon = 3;
99 }
100
101 ath_start_rx_poll(sc, nbeacon);
102 goto out;
103
104sched_reset:
105 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
106out:
107 ath9k_ps_restore(sc);
108}
109
110/*
111 * PLL-WAR for AR9485/AR9340
112 */
113static bool ath_hw_pll_rx_hang_check(struct ath_softc *sc, u32 pll_sqsum)
114{
115 static int count;
116 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
117
118 if (pll_sqsum >= 0x40000) {
119 count++;
120 if (count == 3) {
121 ath_dbg(common, RESET, "PLL WAR, resetting the chip\n");
122 RESET_STAT_INC(sc, RESET_TYPE_PLL_HANG);
123 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
124 count = 0;
125 return true;
126 }
127 } else {
128 count = 0;
129 }
130
131 return false;
132}
133
134void ath_hw_pll_work(struct work_struct *work)
135{
136 u32 pll_sqsum;
137 struct ath_softc *sc = container_of(work, struct ath_softc,
138 hw_pll_work.work);
139 /*
140 * ensure that the PLL WAR is executed only
141 * after the STA is associated (or) if the
142 * beaconing had started in interfaces that
143 * uses beacons.
144 */
145 if (!test_bit(SC_OP_BEACONS, &sc->sc_flags))
146 return;
147
148 ath9k_ps_wakeup(sc);
149 pll_sqsum = ar9003_get_pll_sqsum_dvc(sc->sc_ah);
150 ath9k_ps_restore(sc);
151 if (ath_hw_pll_rx_hang_check(sc, pll_sqsum))
152 return;
153
154 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
155 msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
156}
157
158/*
159 * RX Polling - monitors baseband hangs.
160 */
161void ath_start_rx_poll(struct ath_softc *sc, u8 nbeacon)
162{
163 if (!AR_SREV_9300(sc->sc_ah))
164 return;
165
166 if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags))
167 return;
168
169 mod_timer(&sc->rx_poll_timer, jiffies + msecs_to_jiffies
170 (nbeacon * sc->cur_beacon_conf.beacon_interval));
171}
172
173void ath_rx_poll(unsigned long data)
174{
175 struct ath_softc *sc = (struct ath_softc *)data;
176
177 ieee80211_queue_work(sc->hw, &sc->hw_check_work);
178}
179
180/*
181 * PA Pre-distortion.
182 */
183static void ath_paprd_activate(struct ath_softc *sc)
184{
185 struct ath_hw *ah = sc->sc_ah;
186 struct ath9k_hw_cal_data *caldata = ah->caldata;
187 int chain;
188
189 if (!caldata || !caldata->paprd_done)
190 return;
191
192 ath9k_ps_wakeup(sc);
193 ar9003_paprd_enable(ah, false);
194 for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
195 if (!(ah->txchainmask & BIT(chain)))
196 continue;
197
198 ar9003_paprd_populate_single_table(ah, caldata, chain);
199 }
200
201 ar9003_paprd_enable(ah, true);
202 ath9k_ps_restore(sc);
203}
204
205static bool ath_paprd_send_frame(struct ath_softc *sc, struct sk_buff *skb, int chain)
206{
207 struct ieee80211_hw *hw = sc->hw;
208 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
209 struct ath_hw *ah = sc->sc_ah;
210 struct ath_common *common = ath9k_hw_common(ah);
211 struct ath_tx_control txctl;
212 int time_left;
213
214 memset(&txctl, 0, sizeof(txctl));
215 txctl.txq = sc->tx.txq_map[WME_AC_BE];
216
217 memset(tx_info, 0, sizeof(*tx_info));
218 tx_info->band = hw->conf.channel->band;
219 tx_info->flags |= IEEE80211_TX_CTL_NO_ACK;
220 tx_info->control.rates[0].idx = 0;
221 tx_info->control.rates[0].count = 1;
222 tx_info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
223 tx_info->control.rates[1].idx = -1;
224
225 init_completion(&sc->paprd_complete);
226 txctl.paprd = BIT(chain);
227
228 if (ath_tx_start(hw, skb, &txctl) != 0) {
229 ath_dbg(common, CALIBRATE, "PAPRD TX failed\n");
230 dev_kfree_skb_any(skb);
231 return false;
232 }
233
234 time_left = wait_for_completion_timeout(&sc->paprd_complete,
235 msecs_to_jiffies(ATH_PAPRD_TIMEOUT));
236
237 if (!time_left)
238 ath_dbg(common, CALIBRATE,
239 "Timeout waiting for paprd training on TX chain %d\n",
240 chain);
241
242 return !!time_left;
243}
244
245void ath_paprd_calibrate(struct work_struct *work)
246{
247 struct ath_softc *sc = container_of(work, struct ath_softc, paprd_work);
248 struct ieee80211_hw *hw = sc->hw;
249 struct ath_hw *ah = sc->sc_ah;
250 struct ieee80211_hdr *hdr;
251 struct sk_buff *skb = NULL;
252 struct ath9k_hw_cal_data *caldata = ah->caldata;
253 struct ath_common *common = ath9k_hw_common(ah);
254 int ftype;
255 int chain_ok = 0;
256 int chain;
257 int len = 1800;
258
259 if (!caldata)
260 return;
261
262 ath9k_ps_wakeup(sc);
263
264 if (ar9003_paprd_init_table(ah) < 0)
265 goto fail_paprd;
266
267 skb = alloc_skb(len, GFP_KERNEL);
268 if (!skb)
269 goto fail_paprd;
270
271 skb_put(skb, len);
272 memset(skb->data, 0, len);
273 hdr = (struct ieee80211_hdr *)skb->data;
274 ftype = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC;
275 hdr->frame_control = cpu_to_le16(ftype);
276 hdr->duration_id = cpu_to_le16(10);
277 memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
278 memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
279 memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
280
281 for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
282 if (!(ah->txchainmask & BIT(chain)))
283 continue;
284
285 chain_ok = 0;
286
287 ath_dbg(common, CALIBRATE,
288 "Sending PAPRD frame for thermal measurement on chain %d\n",
289 chain);
290 if (!ath_paprd_send_frame(sc, skb, chain))
291 goto fail_paprd;
292
293 ar9003_paprd_setup_gain_table(ah, chain);
294
295 ath_dbg(common, CALIBRATE,
296 "Sending PAPRD training frame on chain %d\n", chain);
297 if (!ath_paprd_send_frame(sc, skb, chain))
298 goto fail_paprd;
299
300 if (!ar9003_paprd_is_done(ah)) {
301 ath_dbg(common, CALIBRATE,
302 "PAPRD not yet done on chain %d\n", chain);
303 break;
304 }
305
306 if (ar9003_paprd_create_curve(ah, caldata, chain)) {
307 ath_dbg(common, CALIBRATE,
308 "PAPRD create curve failed on chain %d\n",
309 chain);
310 break;
311 }
312
313 chain_ok = 1;
314 }
315 kfree_skb(skb);
316
317 if (chain_ok) {
318 caldata->paprd_done = true;
319 ath_paprd_activate(sc);
320 }
321
322fail_paprd:
323 ath9k_ps_restore(sc);
324}
325
326/*
327 * ANI performs periodic noise floor calibration
328 * that is used to adjust and optimize the chip performance. This
329 * takes environmental changes (location, temperature) into account.
330 * When the task is complete, it reschedules itself depending on the
331 * appropriate interval that was calculated.
332 */
333void ath_ani_calibrate(unsigned long data)
334{
335 struct ath_softc *sc = (struct ath_softc *)data;
336 struct ath_hw *ah = sc->sc_ah;
337 struct ath_common *common = ath9k_hw_common(ah);
338 bool longcal = false;
339 bool shortcal = false;
340 bool aniflag = false;
341 unsigned int timestamp = jiffies_to_msecs(jiffies);
342 u32 cal_interval, short_cal_interval, long_cal_interval;
343 unsigned long flags;
344
345 if (ah->caldata && ah->caldata->nfcal_interference)
346 long_cal_interval = ATH_LONG_CALINTERVAL_INT;
347 else
348 long_cal_interval = ATH_LONG_CALINTERVAL;
349
350 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
351 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
352
353 /* Only calibrate if awake */
354 if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
355 goto set_timer;
356
357 ath9k_ps_wakeup(sc);
358
359 /* Long calibration runs independently of short calibration. */
360 if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) {
361 longcal = true;
362 common->ani.longcal_timer = timestamp;
363 }
364
365 /* Short calibration applies only while caldone is false */
366 if (!common->ani.caldone) {
367 if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) {
368 shortcal = true;
369 common->ani.shortcal_timer = timestamp;
370 common->ani.resetcal_timer = timestamp;
371 }
372 } else {
373 if ((timestamp - common->ani.resetcal_timer) >=
374 ATH_RESTART_CALINTERVAL) {
375 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
376 if (common->ani.caldone)
377 common->ani.resetcal_timer = timestamp;
378 }
379 }
380
381 /* Verify whether we must check ANI */
382 if (sc->sc_ah->config.enable_ani
383 && (timestamp - common->ani.checkani_timer) >=
384 ah->config.ani_poll_interval) {
385 aniflag = true;
386 common->ani.checkani_timer = timestamp;
387 }
388
389 /* Call ANI routine if necessary */
390 if (aniflag) {
391 spin_lock_irqsave(&common->cc_lock, flags);
392 ath9k_hw_ani_monitor(ah, ah->curchan);
393 ath_update_survey_stats(sc);
394 spin_unlock_irqrestore(&common->cc_lock, flags);
395 }
396
397 /* Perform calibration if necessary */
398 if (longcal || shortcal) {
399 common->ani.caldone =
400 ath9k_hw_calibrate(ah, ah->curchan,
401 ah->rxchainmask, longcal);
402 }
403
404 ath_dbg(common, ANI,
405 "Calibration @%lu finished: %s %s %s, caldone: %s\n",
406 jiffies,
407 longcal ? "long" : "", shortcal ? "short" : "",
408 aniflag ? "ani" : "", common->ani.caldone ? "true" : "false");
409
410 ath9k_ps_restore(sc);
411
412set_timer:
413 /*
414 * Set timer interval based on previous results.
415 * The interval must be the shortest necessary to satisfy ANI,
416 * short calibration and long calibration.
417 */
418 ath9k_debug_samp_bb_mac(sc);
419 cal_interval = ATH_LONG_CALINTERVAL;
420 if (sc->sc_ah->config.enable_ani)
421 cal_interval = min(cal_interval,
422 (u32)ah->config.ani_poll_interval);
423 if (!common->ani.caldone)
424 cal_interval = min(cal_interval, (u32)short_cal_interval);
425
426 mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
427 if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && ah->caldata) {
428 if (!ah->caldata->paprd_done)
429 ieee80211_queue_work(sc->hw, &sc->paprd_work);
430 else if (!ah->paprd_table_write_done)
431 ath_paprd_activate(sc);
432 }
433}
434
435void ath_start_ani(struct ath_common *common)
436{
437 struct ath_hw *ah = common->ah;
438 unsigned long timestamp = jiffies_to_msecs(jiffies);
439 struct ath_softc *sc = (struct ath_softc *) common->priv;
440
441 if (!test_bit(SC_OP_ANI_RUN, &sc->sc_flags))
442 return;
443
444 if (sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
445 return;
446
447 common->ani.longcal_timer = timestamp;
448 common->ani.shortcal_timer = timestamp;
449 common->ani.checkani_timer = timestamp;
450
451 mod_timer(&common->ani.timer,
452 jiffies + msecs_to_jiffies((u32)ah->config.ani_poll_interval));
453}
454
455void ath_update_survey_nf(struct ath_softc *sc, int channel)
456{
457 struct ath_hw *ah = sc->sc_ah;
458 struct ath9k_channel *chan = &ah->channels[channel];
459 struct survey_info *survey = &sc->survey[channel];
460
461 if (chan->noisefloor) {
462 survey->filled |= SURVEY_INFO_NOISE_DBM;
463 survey->noise = ath9k_hw_getchan_noise(ah, chan);
464 }
465}
466
467/*
468 * Updates the survey statistics and returns the busy time since last
469 * update in %, if the measurement duration was long enough for the
470 * result to be useful, -1 otherwise.
471 */
472int ath_update_survey_stats(struct ath_softc *sc)
473{
474 struct ath_hw *ah = sc->sc_ah;
475 struct ath_common *common = ath9k_hw_common(ah);
476 int pos = ah->curchan - &ah->channels[0];
477 struct survey_info *survey = &sc->survey[pos];
478 struct ath_cycle_counters *cc = &common->cc_survey;
479 unsigned int div = common->clockrate * 1000;
480 int ret = 0;
481
482 if (!ah->curchan)
483 return -1;
484
485 if (ah->power_mode == ATH9K_PM_AWAKE)
486 ath_hw_cycle_counters_update(common);
487
488 if (cc->cycles > 0) {
489 survey->filled |= SURVEY_INFO_CHANNEL_TIME |
490 SURVEY_INFO_CHANNEL_TIME_BUSY |
491 SURVEY_INFO_CHANNEL_TIME_RX |
492 SURVEY_INFO_CHANNEL_TIME_TX;
493 survey->channel_time += cc->cycles / div;
494 survey->channel_time_busy += cc->rx_busy / div;
495 survey->channel_time_rx += cc->rx_frame / div;
496 survey->channel_time_tx += cc->tx_frame / div;
497 }
498
499 if (cc->cycles < div)
500 return -1;
501
502 if (cc->cycles > 0)
503 ret = cc->rx_busy * 100 / cc->cycles;
504
505 memset(cc, 0, sizeof(*cc));
506
507 ath_update_survey_nf(sc, pos);
508
509 return ret;
510}
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index dac1a2709e3c..52561b341d68 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -101,6 +101,7 @@ void ath9k_ps_wakeup(struct ath_softc *sc)
101 spin_lock(&common->cc_lock); 101 spin_lock(&common->cc_lock);
102 ath_hw_cycle_counters_update(common); 102 ath_hw_cycle_counters_update(common);
103 memset(&common->cc_survey, 0, sizeof(common->cc_survey)); 103 memset(&common->cc_survey, 0, sizeof(common->cc_survey));
104 memset(&common->cc_ani, 0, sizeof(common->cc_ani));
104 spin_unlock(&common->cc_lock); 105 spin_unlock(&common->cc_lock);
105 } 106 }
106 107
@@ -143,90 +144,15 @@ void ath9k_ps_restore(struct ath_softc *sc)
143 spin_unlock_irqrestore(&sc->sc_pm_lock, flags); 144 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
144} 145}
145 146
146void ath_start_ani(struct ath_common *common)
147{
148 struct ath_hw *ah = common->ah;
149 unsigned long timestamp = jiffies_to_msecs(jiffies);
150 struct ath_softc *sc = (struct ath_softc *) common->priv;
151
152 if (!(sc->sc_flags & SC_OP_ANI_RUN))
153 return;
154
155 if (sc->sc_flags & SC_OP_OFFCHANNEL)
156 return;
157
158 common->ani.longcal_timer = timestamp;
159 common->ani.shortcal_timer = timestamp;
160 common->ani.checkani_timer = timestamp;
161
162 mod_timer(&common->ani.timer,
163 jiffies +
164 msecs_to_jiffies((u32)ah->config.ani_poll_interval));
165}
166
167static void ath_update_survey_nf(struct ath_softc *sc, int channel)
168{
169 struct ath_hw *ah = sc->sc_ah;
170 struct ath9k_channel *chan = &ah->channels[channel];
171 struct survey_info *survey = &sc->survey[channel];
172
173 if (chan->noisefloor) {
174 survey->filled |= SURVEY_INFO_NOISE_DBM;
175 survey->noise = ath9k_hw_getchan_noise(ah, chan);
176 }
177}
178
179/*
180 * Updates the survey statistics and returns the busy time since last
181 * update in %, if the measurement duration was long enough for the
182 * result to be useful, -1 otherwise.
183 */
184static int ath_update_survey_stats(struct ath_softc *sc)
185{
186 struct ath_hw *ah = sc->sc_ah;
187 struct ath_common *common = ath9k_hw_common(ah);
188 int pos = ah->curchan - &ah->channels[0];
189 struct survey_info *survey = &sc->survey[pos];
190 struct ath_cycle_counters *cc = &common->cc_survey;
191 unsigned int div = common->clockrate * 1000;
192 int ret = 0;
193
194 if (!ah->curchan)
195 return -1;
196
197 if (ah->power_mode == ATH9K_PM_AWAKE)
198 ath_hw_cycle_counters_update(common);
199
200 if (cc->cycles > 0) {
201 survey->filled |= SURVEY_INFO_CHANNEL_TIME |
202 SURVEY_INFO_CHANNEL_TIME_BUSY |
203 SURVEY_INFO_CHANNEL_TIME_RX |
204 SURVEY_INFO_CHANNEL_TIME_TX;
205 survey->channel_time += cc->cycles / div;
206 survey->channel_time_busy += cc->rx_busy / div;
207 survey->channel_time_rx += cc->rx_frame / div;
208 survey->channel_time_tx += cc->tx_frame / div;
209 }
210
211 if (cc->cycles < div)
212 return -1;
213
214 if (cc->cycles > 0)
215 ret = cc->rx_busy * 100 / cc->cycles;
216
217 memset(cc, 0, sizeof(*cc));
218
219 ath_update_survey_nf(sc, pos);
220
221 return ret;
222}
223
224static void __ath_cancel_work(struct ath_softc *sc) 147static void __ath_cancel_work(struct ath_softc *sc)
225{ 148{
226 cancel_work_sync(&sc->paprd_work); 149 cancel_work_sync(&sc->paprd_work);
227 cancel_work_sync(&sc->hw_check_work); 150 cancel_work_sync(&sc->hw_check_work);
228 cancel_delayed_work_sync(&sc->tx_complete_work); 151 cancel_delayed_work_sync(&sc->tx_complete_work);
229 cancel_delayed_work_sync(&sc->hw_pll_work); 152 cancel_delayed_work_sync(&sc->hw_pll_work);
153#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
154 cancel_work_sync(&sc->mci_work);
155#endif
230} 156}
231 157
232static void ath_cancel_work(struct ath_softc *sc) 158static void ath_cancel_work(struct ath_softc *sc)
@@ -235,6 +161,22 @@ static void ath_cancel_work(struct ath_softc *sc)
235 cancel_work_sync(&sc->hw_reset_work); 161 cancel_work_sync(&sc->hw_reset_work);
236} 162}
237 163
164static void ath_restart_work(struct ath_softc *sc)
165{
166 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
167
168 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
169
170 if (AR_SREV_9485(sc->sc_ah) || AR_SREV_9340(sc->sc_ah))
171 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
172 msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
173
174 ath_start_rx_poll(sc, 3);
175
176 if (!common->disable_ani)
177 ath_start_ani(common);
178}
179
238static bool ath_prepare_reset(struct ath_softc *sc, bool retry_tx, bool flush) 180static bool ath_prepare_reset(struct ath_softc *sc, bool retry_tx, bool flush)
239{ 181{
240 struct ath_hw *ah = sc->sc_ah; 182 struct ath_hw *ah = sc->sc_ah;
@@ -271,6 +213,7 @@ static bool ath_complete_reset(struct ath_softc *sc, bool start)
271{ 213{
272 struct ath_hw *ah = sc->sc_ah; 214 struct ath_hw *ah = sc->sc_ah;
273 struct ath_common *common = ath9k_hw_common(ah); 215 struct ath_common *common = ath9k_hw_common(ah);
216 unsigned long flags;
274 217
275 if (ath_startrecv(sc) != 0) { 218 if (ath_startrecv(sc) != 0) {
276 ath_err(common, "Unable to restart recv logic\n"); 219 ath_err(common, "Unable to restart recv logic\n");
@@ -279,36 +222,30 @@ static bool ath_complete_reset(struct ath_softc *sc, bool start)
279 222
280 ath9k_cmn_update_txpow(ah, sc->curtxpow, 223 ath9k_cmn_update_txpow(ah, sc->curtxpow,
281 sc->config.txpowlimit, &sc->curtxpow); 224 sc->config.txpowlimit, &sc->curtxpow);
225
226 clear_bit(SC_OP_HW_RESET, &sc->sc_flags);
282 ath9k_hw_set_interrupts(ah); 227 ath9k_hw_set_interrupts(ah);
283 ath9k_hw_enable_interrupts(ah); 228 ath9k_hw_enable_interrupts(ah);
284 229
285 if (!(sc->sc_flags & (SC_OP_OFFCHANNEL)) && start) { 230 if (!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) && start) {
286 if (sc->sc_flags & SC_OP_BEACONS) 231 if (!test_bit(SC_OP_BEACONS, &sc->sc_flags))
287 ath_set_beacon(sc); 232 goto work;
288
289 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
290 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, HZ/2);
291 ath_start_rx_poll(sc, 3);
292 if (!common->disable_ani)
293 ath_start_ani(common);
294 }
295
296 if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx != 3) {
297 struct ath_hw_antcomb_conf div_ant_conf;
298 u8 lna_conf;
299 233
300 ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf); 234 ath_set_beacon(sc);
301
302 if (sc->ant_rx == 1)
303 lna_conf = ATH_ANT_DIV_COMB_LNA1;
304 else
305 lna_conf = ATH_ANT_DIV_COMB_LNA2;
306 div_ant_conf.main_lna_conf = lna_conf;
307 div_ant_conf.alt_lna_conf = lna_conf;
308 235
309 ath9k_hw_antdiv_comb_conf_set(ah, &div_ant_conf); 236 if (ah->opmode == NL80211_IFTYPE_STATION &&
237 test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
238 spin_lock_irqsave(&sc->sc_pm_lock, flags);
239 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
240 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
241 }
242 work:
243 ath_restart_work(sc);
310 } 244 }
311 245
246 if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx != 3)
247 ath_ant_comb_update(sc);
248
312 ieee80211_wake_queues(sc->hw); 249 ieee80211_wake_queues(sc->hw);
313 250
314 return true; 251 return true;
@@ -328,7 +265,7 @@ static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan,
328 265
329 spin_lock_bh(&sc->sc_pcu_lock); 266 spin_lock_bh(&sc->sc_pcu_lock);
330 267
331 if (!(sc->sc_flags & SC_OP_OFFCHANNEL)) { 268 if (!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)) {
332 fastcc = false; 269 fastcc = false;
333 caldata = &sc->caldata; 270 caldata = &sc->caldata;
334 } 271 }
@@ -371,7 +308,7 @@ static int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
371{ 308{
372 int r; 309 int r;
373 310
374 if (sc->sc_flags & SC_OP_INVALID) 311 if (test_bit(SC_OP_INVALID, &sc->sc_flags))
375 return -EIO; 312 return -EIO;
376 313
377 r = ath_reset_internal(sc, hchan, false); 314 r = ath_reset_internal(sc, hchan, false);
@@ -379,258 +316,6 @@ static int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
379 return r; 316 return r;
380} 317}
381 318
382static void ath_paprd_activate(struct ath_softc *sc)
383{
384 struct ath_hw *ah = sc->sc_ah;
385 struct ath9k_hw_cal_data *caldata = ah->caldata;
386 int chain;
387
388 if (!caldata || !caldata->paprd_done)
389 return;
390
391 ath9k_ps_wakeup(sc);
392 ar9003_paprd_enable(ah, false);
393 for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
394 if (!(ah->txchainmask & BIT(chain)))
395 continue;
396
397 ar9003_paprd_populate_single_table(ah, caldata, chain);
398 }
399
400 ar9003_paprd_enable(ah, true);
401 ath9k_ps_restore(sc);
402}
403
404static bool ath_paprd_send_frame(struct ath_softc *sc, struct sk_buff *skb, int chain)
405{
406 struct ieee80211_hw *hw = sc->hw;
407 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
408 struct ath_hw *ah = sc->sc_ah;
409 struct ath_common *common = ath9k_hw_common(ah);
410 struct ath_tx_control txctl;
411 int time_left;
412
413 memset(&txctl, 0, sizeof(txctl));
414 txctl.txq = sc->tx.txq_map[WME_AC_BE];
415
416 memset(tx_info, 0, sizeof(*tx_info));
417 tx_info->band = hw->conf.channel->band;
418 tx_info->flags |= IEEE80211_TX_CTL_NO_ACK;
419 tx_info->control.rates[0].idx = 0;
420 tx_info->control.rates[0].count = 1;
421 tx_info->control.rates[0].flags = IEEE80211_TX_RC_MCS;
422 tx_info->control.rates[1].idx = -1;
423
424 init_completion(&sc->paprd_complete);
425 txctl.paprd = BIT(chain);
426
427 if (ath_tx_start(hw, skb, &txctl) != 0) {
428 ath_dbg(common, CALIBRATE, "PAPRD TX failed\n");
429 dev_kfree_skb_any(skb);
430 return false;
431 }
432
433 time_left = wait_for_completion_timeout(&sc->paprd_complete,
434 msecs_to_jiffies(ATH_PAPRD_TIMEOUT));
435
436 if (!time_left)
437 ath_dbg(common, CALIBRATE,
438 "Timeout waiting for paprd training on TX chain %d\n",
439 chain);
440
441 return !!time_left;
442}
443
444void ath_paprd_calibrate(struct work_struct *work)
445{
446 struct ath_softc *sc = container_of(work, struct ath_softc, paprd_work);
447 struct ieee80211_hw *hw = sc->hw;
448 struct ath_hw *ah = sc->sc_ah;
449 struct ieee80211_hdr *hdr;
450 struct sk_buff *skb = NULL;
451 struct ath9k_hw_cal_data *caldata = ah->caldata;
452 struct ath_common *common = ath9k_hw_common(ah);
453 int ftype;
454 int chain_ok = 0;
455 int chain;
456 int len = 1800;
457
458 if (!caldata)
459 return;
460
461 ath9k_ps_wakeup(sc);
462
463 if (ar9003_paprd_init_table(ah) < 0)
464 goto fail_paprd;
465
466 skb = alloc_skb(len, GFP_KERNEL);
467 if (!skb)
468 goto fail_paprd;
469
470 skb_put(skb, len);
471 memset(skb->data, 0, len);
472 hdr = (struct ieee80211_hdr *)skb->data;
473 ftype = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC;
474 hdr->frame_control = cpu_to_le16(ftype);
475 hdr->duration_id = cpu_to_le16(10);
476 memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
477 memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
478 memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
479
480 for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) {
481 if (!(ah->txchainmask & BIT(chain)))
482 continue;
483
484 chain_ok = 0;
485
486 ath_dbg(common, CALIBRATE,
487 "Sending PAPRD frame for thermal measurement on chain %d\n",
488 chain);
489 if (!ath_paprd_send_frame(sc, skb, chain))
490 goto fail_paprd;
491
492 ar9003_paprd_setup_gain_table(ah, chain);
493
494 ath_dbg(common, CALIBRATE,
495 "Sending PAPRD training frame on chain %d\n", chain);
496 if (!ath_paprd_send_frame(sc, skb, chain))
497 goto fail_paprd;
498
499 if (!ar9003_paprd_is_done(ah)) {
500 ath_dbg(common, CALIBRATE,
501 "PAPRD not yet done on chain %d\n", chain);
502 break;
503 }
504
505 if (ar9003_paprd_create_curve(ah, caldata, chain)) {
506 ath_dbg(common, CALIBRATE,
507 "PAPRD create curve failed on chain %d\n",
508 chain);
509 break;
510 }
511
512 chain_ok = 1;
513 }
514 kfree_skb(skb);
515
516 if (chain_ok) {
517 caldata->paprd_done = true;
518 ath_paprd_activate(sc);
519 }
520
521fail_paprd:
522 ath9k_ps_restore(sc);
523}
524
525/*
526 * This routine performs the periodic noise floor calibration function
527 * that is used to adjust and optimize the chip performance. This
528 * takes environmental changes (location, temperature) into account.
529 * When the task is complete, it reschedules itself depending on the
530 * appropriate interval that was calculated.
531 */
532void ath_ani_calibrate(unsigned long data)
533{
534 struct ath_softc *sc = (struct ath_softc *)data;
535 struct ath_hw *ah = sc->sc_ah;
536 struct ath_common *common = ath9k_hw_common(ah);
537 bool longcal = false;
538 bool shortcal = false;
539 bool aniflag = false;
540 unsigned int timestamp = jiffies_to_msecs(jiffies);
541 u32 cal_interval, short_cal_interval, long_cal_interval;
542 unsigned long flags;
543
544 if (ah->caldata && ah->caldata->nfcal_interference)
545 long_cal_interval = ATH_LONG_CALINTERVAL_INT;
546 else
547 long_cal_interval = ATH_LONG_CALINTERVAL;
548
549 short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
550 ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
551
552 /* Only calibrate if awake */
553 if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE)
554 goto set_timer;
555
556 ath9k_ps_wakeup(sc);
557
558 /* Long calibration runs independently of short calibration. */
559 if ((timestamp - common->ani.longcal_timer) >= long_cal_interval) {
560 longcal = true;
561 common->ani.longcal_timer = timestamp;
562 }
563
564 /* Short calibration applies only while caldone is false */
565 if (!common->ani.caldone) {
566 if ((timestamp - common->ani.shortcal_timer) >= short_cal_interval) {
567 shortcal = true;
568 common->ani.shortcal_timer = timestamp;
569 common->ani.resetcal_timer = timestamp;
570 }
571 } else {
572 if ((timestamp - common->ani.resetcal_timer) >=
573 ATH_RESTART_CALINTERVAL) {
574 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
575 if (common->ani.caldone)
576 common->ani.resetcal_timer = timestamp;
577 }
578 }
579
580 /* Verify whether we must check ANI */
581 if (sc->sc_ah->config.enable_ani
582 && (timestamp - common->ani.checkani_timer) >=
583 ah->config.ani_poll_interval) {
584 aniflag = true;
585 common->ani.checkani_timer = timestamp;
586 }
587
588 /* Call ANI routine if necessary */
589 if (aniflag) {
590 spin_lock_irqsave(&common->cc_lock, flags);
591 ath9k_hw_ani_monitor(ah, ah->curchan);
592 ath_update_survey_stats(sc);
593 spin_unlock_irqrestore(&common->cc_lock, flags);
594 }
595
596 /* Perform calibration if necessary */
597 if (longcal || shortcal) {
598 common->ani.caldone =
599 ath9k_hw_calibrate(ah, ah->curchan,
600 ah->rxchainmask, longcal);
601 }
602
603 ath_dbg(common, ANI,
604 "Calibration @%lu finished: %s %s %s, caldone: %s\n",
605 jiffies,
606 longcal ? "long" : "", shortcal ? "short" : "",
607 aniflag ? "ani" : "", common->ani.caldone ? "true" : "false");
608
609 ath9k_ps_restore(sc);
610
611set_timer:
612 /*
613 * Set timer interval based on previous results.
614 * The interval must be the shortest necessary to satisfy ANI,
615 * short calibration and long calibration.
616 */
617 ath9k_debug_samp_bb_mac(sc);
618 cal_interval = ATH_LONG_CALINTERVAL;
619 if (sc->sc_ah->config.enable_ani)
620 cal_interval = min(cal_interval,
621 (u32)ah->config.ani_poll_interval);
622 if (!common->ani.caldone)
623 cal_interval = min(cal_interval, (u32)short_cal_interval);
624
625 mod_timer(&common->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
626 if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_PAPRD) && ah->caldata) {
627 if (!ah->caldata->paprd_done)
628 ieee80211_queue_work(sc->hw, &sc->paprd_work);
629 else if (!ah->paprd_table_write_done)
630 ath_paprd_activate(sc);
631 }
632}
633
634static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta, 319static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta,
635 struct ieee80211_vif *vif) 320 struct ieee80211_vif *vif)
636{ 321{
@@ -668,13 +353,12 @@ static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
668 ath_tx_node_cleanup(sc, an); 353 ath_tx_node_cleanup(sc, an);
669} 354}
670 355
671
672void ath9k_tasklet(unsigned long data) 356void ath9k_tasklet(unsigned long data)
673{ 357{
674 struct ath_softc *sc = (struct ath_softc *)data; 358 struct ath_softc *sc = (struct ath_softc *)data;
675 struct ath_hw *ah = sc->sc_ah; 359 struct ath_hw *ah = sc->sc_ah;
676 struct ath_common *common = ath9k_hw_common(ah); 360 struct ath_common *common = ath9k_hw_common(ah);
677 361 unsigned long flags;
678 u32 status = sc->intrstatus; 362 u32 status = sc->intrstatus;
679 u32 rxmask; 363 u32 rxmask;
680 364
@@ -693,10 +377,12 @@ void ath9k_tasklet(unsigned long data)
693 377
694 RESET_STAT_INC(sc, type); 378 RESET_STAT_INC(sc, type);
695#endif 379#endif
380 set_bit(SC_OP_HW_RESET, &sc->sc_flags);
696 ieee80211_queue_work(sc->hw, &sc->hw_reset_work); 381 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
697 goto out; 382 goto out;
698 } 383 }
699 384
385 spin_lock_irqsave(&sc->sc_pm_lock, flags);
700 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) { 386 if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
701 /* 387 /*
702 * TSF sync does not look correct; remain awake to sync with 388 * TSF sync does not look correct; remain awake to sync with
@@ -705,6 +391,7 @@ void ath9k_tasklet(unsigned long data)
705 ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n"); 391 ath_dbg(common, PS, "TSFOOR - Sync with next Beacon\n");
706 sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC; 392 sc->ps_flags |= PS_WAIT_FOR_BEACON | PS_BEACON_SYNC;
707 } 393 }
394 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
708 395
709 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) 396 if (ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
710 rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL | 397 rxmask = (ATH9K_INT_RXHP | ATH9K_INT_RXLP | ATH9K_INT_RXEOL |
@@ -766,15 +453,17 @@ irqreturn_t ath_isr(int irq, void *dev)
766 * touch anything. Note this can happen early 453 * touch anything. Note this can happen early
767 * on if the IRQ is shared. 454 * on if the IRQ is shared.
768 */ 455 */
769 if (sc->sc_flags & SC_OP_INVALID) 456 if (test_bit(SC_OP_INVALID, &sc->sc_flags))
770 return IRQ_NONE; 457 return IRQ_NONE;
771 458
772
773 /* shared irq, not for us */ 459 /* shared irq, not for us */
774 460
775 if (!ath9k_hw_intrpend(ah)) 461 if (!ath9k_hw_intrpend(ah))
776 return IRQ_NONE; 462 return IRQ_NONE;
777 463
464 if(test_bit(SC_OP_HW_RESET, &sc->sc_flags))
465 return IRQ_HANDLED;
466
778 /* 467 /*
779 * Figure out the reason(s) for the interrupt. Note 468 * Figure out the reason(s) for the interrupt. Note
780 * that the hal returns a pseudo-ISR that may include 469 * that the hal returns a pseudo-ISR that may include
@@ -852,8 +541,10 @@ irqreturn_t ath_isr(int irq, void *dev)
852 /* Clear RxAbort bit so that we can 541 /* Clear RxAbort bit so that we can
853 * receive frames */ 542 * receive frames */
854 ath9k_setpower(sc, ATH9K_PM_AWAKE); 543 ath9k_setpower(sc, ATH9K_PM_AWAKE);
544 spin_lock(&sc->sc_pm_lock);
855 ath9k_hw_setrxabort(sc->sc_ah, 0); 545 ath9k_hw_setrxabort(sc->sc_ah, 0);
856 sc->ps_flags |= PS_WAIT_FOR_BEACON; 546 sc->ps_flags |= PS_WAIT_FOR_BEACON;
547 spin_unlock(&sc->sc_pm_lock);
857 } 548 }
858 549
859chip_reset: 550chip_reset:
@@ -902,96 +593,6 @@ void ath_reset_work(struct work_struct *work)
902 ath_reset(sc, true); 593 ath_reset(sc, true);
903} 594}
904 595
905void ath_hw_check(struct work_struct *work)
906{
907 struct ath_softc *sc = container_of(work, struct ath_softc, hw_check_work);
908 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
909 unsigned long flags;
910 int busy;
911 u8 is_alive, nbeacon = 1;
912
913 ath9k_ps_wakeup(sc);
914 is_alive = ath9k_hw_check_alive(sc->sc_ah);
915
916 if (is_alive && !AR_SREV_9300(sc->sc_ah))
917 goto out;
918 else if (!is_alive && AR_SREV_9300(sc->sc_ah)) {
919 ath_dbg(common, RESET,
920 "DCU stuck is detected. Schedule chip reset\n");
921 RESET_STAT_INC(sc, RESET_TYPE_MAC_HANG);
922 goto sched_reset;
923 }
924
925 spin_lock_irqsave(&common->cc_lock, flags);
926 busy = ath_update_survey_stats(sc);
927 spin_unlock_irqrestore(&common->cc_lock, flags);
928
929 ath_dbg(common, RESET, "Possible baseband hang, busy=%d (try %d)\n",
930 busy, sc->hw_busy_count + 1);
931 if (busy >= 99) {
932 if (++sc->hw_busy_count >= 3) {
933 RESET_STAT_INC(sc, RESET_TYPE_BB_HANG);
934 goto sched_reset;
935 }
936 } else if (busy >= 0) {
937 sc->hw_busy_count = 0;
938 nbeacon = 3;
939 }
940
941 ath_start_rx_poll(sc, nbeacon);
942 goto out;
943
944sched_reset:
945 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
946out:
947 ath9k_ps_restore(sc);
948}
949
950static void ath_hw_pll_rx_hang_check(struct ath_softc *sc, u32 pll_sqsum)
951{
952 static int count;
953 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
954
955 if (pll_sqsum >= 0x40000) {
956 count++;
957 if (count == 3) {
958 /* Rx is hung for more than 500ms. Reset it */
959 ath_dbg(common, RESET, "Possible RX hang, resetting\n");
960 RESET_STAT_INC(sc, RESET_TYPE_PLL_HANG);
961 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
962 count = 0;
963 }
964 } else
965 count = 0;
966}
967
968void ath_hw_pll_work(struct work_struct *work)
969{
970 struct ath_softc *sc = container_of(work, struct ath_softc,
971 hw_pll_work.work);
972 u32 pll_sqsum;
973
974 /*
975 * ensure that the PLL WAR is executed only
976 * after the STA is associated (or) if the
977 * beaconing had started in interfaces that
978 * uses beacons.
979 */
980 if (!(sc->sc_flags & SC_OP_BEACONS))
981 return;
982
983 if (AR_SREV_9485(sc->sc_ah)) {
984
985 ath9k_ps_wakeup(sc);
986 pll_sqsum = ar9003_get_pll_sqsum_dvc(sc->sc_ah);
987 ath9k_ps_restore(sc);
988
989 ath_hw_pll_rx_hang_check(sc, pll_sqsum);
990
991 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work, HZ/5);
992 }
993}
994
995/**********************/ 596/**********************/
996/* mac80211 callbacks */ 597/* mac80211 callbacks */
997/**********************/ 598/**********************/
@@ -1054,10 +655,9 @@ static int ath9k_start(struct ieee80211_hw *hw)
1054 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) 655 if (ah->caps.hw_caps & ATH9K_HW_CAP_HT)
1055 ah->imask |= ATH9K_INT_CST; 656 ah->imask |= ATH9K_INT_CST;
1056 657
1057 if (ah->caps.hw_caps & ATH9K_HW_CAP_MCI) 658 ath_mci_enable(sc);
1058 ah->imask |= ATH9K_INT_MCI;
1059 659
1060 sc->sc_flags &= ~SC_OP_INVALID; 660 clear_bit(SC_OP_INVALID, &sc->sc_flags);
1061 sc->sc_ah->is_monitoring = false; 661 sc->sc_ah->is_monitoring = false;
1062 662
1063 if (!ath_complete_reset(sc, false)) { 663 if (!ath_complete_reset(sc, false)) {
@@ -1099,6 +699,7 @@ static void ath9k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1099 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 699 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1100 struct ath_tx_control txctl; 700 struct ath_tx_control txctl;
1101 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 701 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
702 unsigned long flags;
1102 703
1103 if (sc->ps_enabled) { 704 if (sc->ps_enabled) {
1104 /* 705 /*
@@ -1121,6 +722,7 @@ static void ath9k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1121 * completed and if needed, also for RX of buffered frames. 722 * completed and if needed, also for RX of buffered frames.
1122 */ 723 */
1123 ath9k_ps_wakeup(sc); 724 ath9k_ps_wakeup(sc);
725 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1124 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) 726 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
1125 ath9k_hw_setrxabort(sc->sc_ah, 0); 727 ath9k_hw_setrxabort(sc->sc_ah, 0);
1126 if (ieee80211_is_pspoll(hdr->frame_control)) { 728 if (ieee80211_is_pspoll(hdr->frame_control)) {
@@ -1136,6 +738,7 @@ static void ath9k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1136 * the ps_flags bit is cleared. We are just dropping 738 * the ps_flags bit is cleared. We are just dropping
1137 * the ps_usecount here. 739 * the ps_usecount here.
1138 */ 740 */
741 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1139 ath9k_ps_restore(sc); 742 ath9k_ps_restore(sc);
1140 } 743 }
1141 744
@@ -1176,7 +779,7 @@ static void ath9k_stop(struct ieee80211_hw *hw)
1176 ath_cancel_work(sc); 779 ath_cancel_work(sc);
1177 del_timer_sync(&sc->rx_poll_timer); 780 del_timer_sync(&sc->rx_poll_timer);
1178 781
1179 if (sc->sc_flags & SC_OP_INVALID) { 782 if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
1180 ath_dbg(common, ANY, "Device not present\n"); 783 ath_dbg(common, ANY, "Device not present\n");
1181 mutex_unlock(&sc->mutex); 784 mutex_unlock(&sc->mutex);
1182 return; 785 return;
@@ -1233,7 +836,7 @@ static void ath9k_stop(struct ieee80211_hw *hw)
1233 836
1234 ath9k_ps_restore(sc); 837 ath9k_ps_restore(sc);
1235 838
1236 sc->sc_flags |= SC_OP_INVALID; 839 set_bit(SC_OP_INVALID, &sc->sc_flags);
1237 sc->ps_idle = prev_idle; 840 sc->ps_idle = prev_idle;
1238 841
1239 mutex_unlock(&sc->mutex); 842 mutex_unlock(&sc->mutex);
@@ -1337,11 +940,11 @@ static void ath9k_calculate_summary_state(struct ieee80211_hw *hw,
1337 /* Set op-mode & TSF */ 940 /* Set op-mode & TSF */
1338 if (iter_data.naps > 0) { 941 if (iter_data.naps > 0) {
1339 ath9k_hw_set_tsfadjust(ah, 1); 942 ath9k_hw_set_tsfadjust(ah, 1);
1340 sc->sc_flags |= SC_OP_TSF_RESET; 943 set_bit(SC_OP_TSF_RESET, &sc->sc_flags);
1341 ah->opmode = NL80211_IFTYPE_AP; 944 ah->opmode = NL80211_IFTYPE_AP;
1342 } else { 945 } else {
1343 ath9k_hw_set_tsfadjust(ah, 0); 946 ath9k_hw_set_tsfadjust(ah, 0);
1344 sc->sc_flags &= ~SC_OP_TSF_RESET; 947 clear_bit(SC_OP_TSF_RESET, &sc->sc_flags);
1345 948
1346 if (iter_data.nmeshes) 949 if (iter_data.nmeshes)
1347 ah->opmode = NL80211_IFTYPE_MESH_POINT; 950 ah->opmode = NL80211_IFTYPE_MESH_POINT;
@@ -1372,12 +975,12 @@ static void ath9k_calculate_summary_state(struct ieee80211_hw *hw,
1372 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER; 975 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
1373 976
1374 if (!common->disable_ani) { 977 if (!common->disable_ani) {
1375 sc->sc_flags |= SC_OP_ANI_RUN; 978 set_bit(SC_OP_ANI_RUN, &sc->sc_flags);
1376 ath_start_ani(common); 979 ath_start_ani(common);
1377 } 980 }
1378 981
1379 } else { 982 } else {
1380 sc->sc_flags &= ~SC_OP_ANI_RUN; 983 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
1381 del_timer_sync(&common->ani.timer); 984 del_timer_sync(&common->ani.timer);
1382 } 985 }
1383} 986}
@@ -1398,25 +1001,6 @@ static void ath9k_do_vif_add_setup(struct ieee80211_hw *hw,
1398 } 1001 }
1399} 1002}
1400 1003
1401void ath_start_rx_poll(struct ath_softc *sc, u8 nbeacon)
1402{
1403 if (!AR_SREV_9300(sc->sc_ah))
1404 return;
1405
1406 if (!(sc->sc_flags & SC_OP_PRIM_STA_VIF))
1407 return;
1408
1409 mod_timer(&sc->rx_poll_timer, jiffies + msecs_to_jiffies
1410 (nbeacon * sc->cur_beacon_conf.beacon_interval));
1411}
1412
1413void ath_rx_poll(unsigned long data)
1414{
1415 struct ath_softc *sc = (struct ath_softc *)data;
1416
1417 ieee80211_queue_work(sc->hw, &sc->hw_check_work);
1418}
1419
1420static int ath9k_add_interface(struct ieee80211_hw *hw, 1004static int ath9k_add_interface(struct ieee80211_hw *hw,
1421 struct ieee80211_vif *vif) 1005 struct ieee80211_vif *vif)
1422{ 1006{
@@ -1618,11 +1202,6 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1618 if (ah->curchan) 1202 if (ah->curchan)
1619 old_pos = ah->curchan - &ah->channels[0]; 1203 old_pos = ah->curchan - &ah->channels[0];
1620 1204
1621 if (hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
1622 sc->sc_flags |= SC_OP_OFFCHANNEL;
1623 else
1624 sc->sc_flags &= ~SC_OP_OFFCHANNEL;
1625
1626 ath_dbg(common, CONFIG, "Set channel: %d MHz type: %d\n", 1205 ath_dbg(common, CONFIG, "Set channel: %d MHz type: %d\n",
1627 curchan->center_freq, conf->channel_type); 1206 curchan->center_freq, conf->channel_type);
1628 1207
@@ -1664,6 +1243,7 @@ static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
1664 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) { 1243 if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
1665 ath_err(common, "Unable to set channel\n"); 1244 ath_err(common, "Unable to set channel\n");
1666 mutex_unlock(&sc->mutex); 1245 mutex_unlock(&sc->mutex);
1246 ath9k_ps_restore(sc);
1667 return -EINVAL; 1247 return -EINVAL;
1668 } 1248 }
1669 1249
@@ -1902,16 +1482,16 @@ static void ath9k_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1902 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 1482 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1903 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 1483 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1904 struct ath_vif *avp = (void *)vif->drv_priv; 1484 struct ath_vif *avp = (void *)vif->drv_priv;
1905 1485 unsigned long flags;
1906 /* 1486 /*
1907 * Skip iteration if primary station vif's bss info 1487 * Skip iteration if primary station vif's bss info
1908 * was not changed 1488 * was not changed
1909 */ 1489 */
1910 if (sc->sc_flags & SC_OP_PRIM_STA_VIF) 1490 if (test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags))
1911 return; 1491 return;
1912 1492
1913 if (bss_conf->assoc) { 1493 if (bss_conf->assoc) {
1914 sc->sc_flags |= SC_OP_PRIM_STA_VIF; 1494 set_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags);
1915 avp->primary_sta_vif = true; 1495 avp->primary_sta_vif = true;
1916 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN); 1496 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1917 common->curaid = bss_conf->aid; 1497 common->curaid = bss_conf->aid;
@@ -1924,7 +1504,10 @@ static void ath9k_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1924 * on the receipt of the first Beacon frame (i.e., 1504 * on the receipt of the first Beacon frame (i.e.,
1925 * after time sync with the AP). 1505 * after time sync with the AP).
1926 */ 1506 */
1507 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1927 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON; 1508 sc->ps_flags |= PS_BEACON_SYNC | PS_WAIT_FOR_BEACON;
1509 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1510
1928 /* Reset rssi stats */ 1511 /* Reset rssi stats */
1929 sc->last_rssi = ATH_RSSI_DUMMY_MARKER; 1512 sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
1930 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER; 1513 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
@@ -1932,7 +1515,7 @@ static void ath9k_bss_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
1932 ath_start_rx_poll(sc, 3); 1515 ath_start_rx_poll(sc, 3);
1933 1516
1934 if (!common->disable_ani) { 1517 if (!common->disable_ani) {
1935 sc->sc_flags |= SC_OP_ANI_RUN; 1518 set_bit(SC_OP_ANI_RUN, &sc->sc_flags);
1936 ath_start_ani(common); 1519 ath_start_ani(common);
1937 } 1520 }
1938 1521
@@ -1952,7 +1535,8 @@ static void ath9k_config_bss(struct ath_softc *sc, struct ieee80211_vif *vif)
1952 if (avp->primary_sta_vif && !bss_conf->assoc) { 1535 if (avp->primary_sta_vif && !bss_conf->assoc) {
1953 ath_dbg(common, CONFIG, "Bss Info DISASSOC %d, bssid %pM\n", 1536 ath_dbg(common, CONFIG, "Bss Info DISASSOC %d, bssid %pM\n",
1954 common->curaid, common->curbssid); 1537 common->curaid, common->curbssid);
1955 sc->sc_flags &= ~(SC_OP_PRIM_STA_VIF | SC_OP_BEACONS); 1538 clear_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags);
1539 clear_bit(SC_OP_BEACONS, &sc->sc_flags);
1956 avp->primary_sta_vif = false; 1540 avp->primary_sta_vif = false;
1957 memset(common->curbssid, 0, ETH_ALEN); 1541 memset(common->curbssid, 0, ETH_ALEN);
1958 common->curaid = 0; 1542 common->curaid = 0;
@@ -1965,10 +1549,9 @@ static void ath9k_config_bss(struct ath_softc *sc, struct ieee80211_vif *vif)
1965 * None of station vifs are associated. 1549 * None of station vifs are associated.
1966 * Clear bssid & aid 1550 * Clear bssid & aid
1967 */ 1551 */
1968 if (!(sc->sc_flags & SC_OP_PRIM_STA_VIF)) { 1552 if (!test_bit(SC_OP_PRIM_STA_VIF, &sc->sc_flags)) {
1969 ath9k_hw_write_associd(sc->sc_ah); 1553 ath9k_hw_write_associd(sc->sc_ah);
1970 /* Stop ANI */ 1554 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
1971 sc->sc_flags &= ~SC_OP_ANI_RUN;
1972 del_timer_sync(&common->ani.timer); 1555 del_timer_sync(&common->ani.timer);
1973 del_timer_sync(&sc->rx_poll_timer); 1556 del_timer_sync(&sc->rx_poll_timer);
1974 memset(&sc->caldata, 0, sizeof(sc->caldata)); 1557 memset(&sc->caldata, 0, sizeof(sc->caldata));
@@ -2006,12 +1589,12 @@ static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
2006 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER; 1589 sc->sc_ah->stats.avgbrssi = ATH_RSSI_DUMMY_MARKER;
2007 1590
2008 if (!common->disable_ani) { 1591 if (!common->disable_ani) {
2009 sc->sc_flags |= SC_OP_ANI_RUN; 1592 set_bit(SC_OP_ANI_RUN, &sc->sc_flags);
2010 ath_start_ani(common); 1593 ath_start_ani(common);
2011 } 1594 }
2012 1595
2013 } else { 1596 } else {
2014 sc->sc_flags &= ~SC_OP_ANI_RUN; 1597 clear_bit(SC_OP_ANI_RUN, &sc->sc_flags);
2015 del_timer_sync(&common->ani.timer); 1598 del_timer_sync(&common->ani.timer);
2016 del_timer_sync(&sc->rx_poll_timer); 1599 del_timer_sync(&sc->rx_poll_timer);
2017 } 1600 }
@@ -2023,7 +1606,7 @@ static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
2023 */ 1606 */
2024 if ((changed & BSS_CHANGED_BEACON_INT) && 1607 if ((changed & BSS_CHANGED_BEACON_INT) &&
2025 (vif->type == NL80211_IFTYPE_AP)) 1608 (vif->type == NL80211_IFTYPE_AP))
2026 sc->sc_flags |= SC_OP_TSF_RESET; 1609 set_bit(SC_OP_TSF_RESET, &sc->sc_flags);
2027 1610
2028 /* Configure beaconing (AP, IBSS, MESH) */ 1611 /* Configure beaconing (AP, IBSS, MESH) */
2029 if (ath9k_uses_beacons(vif->type) && 1612 if (ath9k_uses_beacons(vif->type) &&
@@ -2215,7 +1798,7 @@ static void ath9k_flush(struct ieee80211_hw *hw, bool drop)
2215 return; 1798 return;
2216 } 1799 }
2217 1800
2218 if (sc->sc_flags & SC_OP_INVALID) { 1801 if (test_bit(SC_OP_INVALID, &sc->sc_flags)) {
2219 ath_dbg(common, ANY, "Device not present\n"); 1802 ath_dbg(common, ANY, "Device not present\n");
2220 mutex_unlock(&sc->mutex); 1803 mutex_unlock(&sc->mutex);
2221 return; 1804 return;
@@ -2380,6 +1963,134 @@ static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
2380 return 0; 1963 return 0;
2381} 1964}
2382 1965
1966#ifdef CONFIG_ATH9K_DEBUGFS
1967
1968/* Ethtool support for get-stats */
1969
1970#define AMKSTR(nm) #nm "_BE", #nm "_BK", #nm "_VI", #nm "_VO"
1971static const char ath9k_gstrings_stats[][ETH_GSTRING_LEN] = {
1972 "tx_pkts_nic",
1973 "tx_bytes_nic",
1974 "rx_pkts_nic",
1975 "rx_bytes_nic",
1976 AMKSTR(d_tx_pkts),
1977 AMKSTR(d_tx_bytes),
1978 AMKSTR(d_tx_mpdus_queued),
1979 AMKSTR(d_tx_mpdus_completed),
1980 AMKSTR(d_tx_mpdu_xretries),
1981 AMKSTR(d_tx_aggregates),
1982 AMKSTR(d_tx_ampdus_queued_hw),
1983 AMKSTR(d_tx_ampdus_queued_sw),
1984 AMKSTR(d_tx_ampdus_completed),
1985 AMKSTR(d_tx_ampdu_retries),
1986 AMKSTR(d_tx_ampdu_xretries),
1987 AMKSTR(d_tx_fifo_underrun),
1988 AMKSTR(d_tx_op_exceeded),
1989 AMKSTR(d_tx_timer_expiry),
1990 AMKSTR(d_tx_desc_cfg_err),
1991 AMKSTR(d_tx_data_underrun),
1992 AMKSTR(d_tx_delim_underrun),
1993
1994 "d_rx_decrypt_crc_err",
1995 "d_rx_phy_err",
1996 "d_rx_mic_err",
1997 "d_rx_pre_delim_crc_err",
1998 "d_rx_post_delim_crc_err",
1999 "d_rx_decrypt_busy_err",
2000
2001 "d_rx_phyerr_radar",
2002 "d_rx_phyerr_ofdm_timing",
2003 "d_rx_phyerr_cck_timing",
2004
2005};
2006#define ATH9K_SSTATS_LEN ARRAY_SIZE(ath9k_gstrings_stats)
2007
2008static void ath9k_get_et_strings(struct ieee80211_hw *hw,
2009 struct ieee80211_vif *vif,
2010 u32 sset, u8 *data)
2011{
2012 if (sset == ETH_SS_STATS)
2013 memcpy(data, *ath9k_gstrings_stats,
2014 sizeof(ath9k_gstrings_stats));
2015}
2016
2017static int ath9k_get_et_sset_count(struct ieee80211_hw *hw,
2018 struct ieee80211_vif *vif, int sset)
2019{
2020 if (sset == ETH_SS_STATS)
2021 return ATH9K_SSTATS_LEN;
2022 return 0;
2023}
2024
2025#define PR_QNUM(_n) (sc->tx.txq_map[_n]->axq_qnum)
2026#define AWDATA(elem) \
2027 do { \
2028 data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].elem; \
2029 data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].elem; \
2030 data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].elem; \
2031 data[i++] = sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].elem; \
2032 } while (0)
2033
2034#define AWDATA_RX(elem) \
2035 do { \
2036 data[i++] = sc->debug.stats.rxstats.elem; \
2037 } while (0)
2038
2039static void ath9k_get_et_stats(struct ieee80211_hw *hw,
2040 struct ieee80211_vif *vif,
2041 struct ethtool_stats *stats, u64 *data)
2042{
2043 struct ath_softc *sc = hw->priv;
2044 int i = 0;
2045
2046 data[i++] = (sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].tx_pkts_all +
2047 sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].tx_pkts_all +
2048 sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].tx_pkts_all +
2049 sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].tx_pkts_all);
2050 data[i++] = (sc->debug.stats.txstats[PR_QNUM(WME_AC_BE)].tx_bytes_all +
2051 sc->debug.stats.txstats[PR_QNUM(WME_AC_BK)].tx_bytes_all +
2052 sc->debug.stats.txstats[PR_QNUM(WME_AC_VI)].tx_bytes_all +
2053 sc->debug.stats.txstats[PR_QNUM(WME_AC_VO)].tx_bytes_all);
2054 AWDATA_RX(rx_pkts_all);
2055 AWDATA_RX(rx_bytes_all);
2056
2057 AWDATA(tx_pkts_all);
2058 AWDATA(tx_bytes_all);
2059 AWDATA(queued);
2060 AWDATA(completed);
2061 AWDATA(xretries);
2062 AWDATA(a_aggr);
2063 AWDATA(a_queued_hw);
2064 AWDATA(a_queued_sw);
2065 AWDATA(a_completed);
2066 AWDATA(a_retries);
2067 AWDATA(a_xretries);
2068 AWDATA(fifo_underrun);
2069 AWDATA(xtxop);
2070 AWDATA(timer_exp);
2071 AWDATA(desc_cfg_err);
2072 AWDATA(data_underrun);
2073 AWDATA(delim_underrun);
2074
2075 AWDATA_RX(decrypt_crc_err);
2076 AWDATA_RX(phy_err);
2077 AWDATA_RX(mic_err);
2078 AWDATA_RX(pre_delim_crc_err);
2079 AWDATA_RX(post_delim_crc_err);
2080 AWDATA_RX(decrypt_busy_err);
2081
2082 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_RADAR]);
2083 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_OFDM_TIMING]);
2084 AWDATA_RX(phy_err_stats[ATH9K_PHYERR_CCK_TIMING]);
2085
2086 WARN_ON(i != ATH9K_SSTATS_LEN);
2087}
2088
2089/* End of ethtool get-stats functions */
2090
2091#endif
2092
2093
2383struct ieee80211_ops ath9k_ops = { 2094struct ieee80211_ops ath9k_ops = {
2384 .tx = ath9k_tx, 2095 .tx = ath9k_tx,
2385 .start = ath9k_start, 2096 .start = ath9k_start,
@@ -2408,4 +2119,10 @@ struct ieee80211_ops ath9k_ops = {
2408 .get_stats = ath9k_get_stats, 2119 .get_stats = ath9k_get_stats,
2409 .set_antenna = ath9k_set_antenna, 2120 .set_antenna = ath9k_set_antenna,
2410 .get_antenna = ath9k_get_antenna, 2121 .get_antenna = ath9k_get_antenna,
2122
2123#ifdef CONFIG_ATH9K_DEBUGFS
2124 .get_et_sset_count = ath9k_get_et_sset_count,
2125 .get_et_stats = ath9k_get_et_stats,
2126 .get_et_strings = ath9k_get_et_strings,
2127#endif
2411}; 2128};
diff --git a/drivers/net/wireless/ath/ath9k/mci.c b/drivers/net/wireless/ath/ath9k/mci.c
index 29fe52d69973..7d34a504d617 100644
--- a/drivers/net/wireless/ath/ath9k/mci.c
+++ b/drivers/net/wireless/ath/ath9k/mci.c
@@ -20,7 +20,7 @@
20#include "ath9k.h" 20#include "ath9k.h"
21#include "mci.h" 21#include "mci.h"
22 22
23static const u8 ath_mci_duty_cycle[] = { 0, 50, 60, 70, 80, 85, 90, 95, 98 }; 23static const u8 ath_mci_duty_cycle[] = { 55, 50, 60, 70, 80, 85, 90, 95, 98 };
24 24
25static struct ath_mci_profile_info* 25static struct ath_mci_profile_info*
26ath_mci_find_profile(struct ath_mci_profile *mci, 26ath_mci_find_profile(struct ath_mci_profile *mci,
@@ -28,11 +28,14 @@ ath_mci_find_profile(struct ath_mci_profile *mci,
28{ 28{
29 struct ath_mci_profile_info *entry; 29 struct ath_mci_profile_info *entry;
30 30
31 if (list_empty(&mci->info))
32 return NULL;
33
31 list_for_each_entry(entry, &mci->info, list) { 34 list_for_each_entry(entry, &mci->info, list) {
32 if (entry->conn_handle == info->conn_handle) 35 if (entry->conn_handle == info->conn_handle)
33 break; 36 return entry;
34 } 37 }
35 return entry; 38 return NULL;
36} 39}
37 40
38static bool ath_mci_add_profile(struct ath_common *common, 41static bool ath_mci_add_profile(struct ath_common *common,
@@ -49,31 +52,21 @@ static bool ath_mci_add_profile(struct ath_common *common,
49 (info->type != MCI_GPM_COEX_PROFILE_VOICE)) 52 (info->type != MCI_GPM_COEX_PROFILE_VOICE))
50 return false; 53 return false;
51 54
52 entry = ath_mci_find_profile(mci, info); 55 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
56 if (!entry)
57 return false;
53 58
54 if (entry) { 59 memcpy(entry, info, 10);
55 memcpy(entry, info, 10); 60 INC_PROF(mci, info);
56 } else { 61 list_add_tail(&entry->list, &mci->info);
57 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
58 if (!entry)
59 return false;
60
61 memcpy(entry, info, 10);
62 INC_PROF(mci, info);
63 list_add_tail(&info->list, &mci->info);
64 }
65 62
66 return true; 63 return true;
67} 64}
68 65
69static void ath_mci_del_profile(struct ath_common *common, 66static void ath_mci_del_profile(struct ath_common *common,
70 struct ath_mci_profile *mci, 67 struct ath_mci_profile *mci,
71 struct ath_mci_profile_info *info) 68 struct ath_mci_profile_info *entry)
72{ 69{
73 struct ath_mci_profile_info *entry;
74
75 entry = ath_mci_find_profile(mci, info);
76
77 if (!entry) 70 if (!entry)
78 return; 71 return;
79 72
@@ -86,12 +79,16 @@ void ath_mci_flush_profile(struct ath_mci_profile *mci)
86{ 79{
87 struct ath_mci_profile_info *info, *tinfo; 80 struct ath_mci_profile_info *info, *tinfo;
88 81
82 mci->aggr_limit = 0;
83
84 if (list_empty(&mci->info))
85 return;
86
89 list_for_each_entry_safe(info, tinfo, &mci->info, list) { 87 list_for_each_entry_safe(info, tinfo, &mci->info, list) {
90 list_del(&info->list); 88 list_del(&info->list);
91 DEC_PROF(mci, info); 89 DEC_PROF(mci, info);
92 kfree(info); 90 kfree(info);
93 } 91 }
94 mci->aggr_limit = 0;
95} 92}
96 93
97static void ath_mci_adjust_aggr_limit(struct ath_btcoex *btcoex) 94static void ath_mci_adjust_aggr_limit(struct ath_btcoex *btcoex)
@@ -116,42 +113,60 @@ static void ath_mci_update_scheme(struct ath_softc *sc)
116 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 113 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
117 struct ath_btcoex *btcoex = &sc->btcoex; 114 struct ath_btcoex *btcoex = &sc->btcoex;
118 struct ath_mci_profile *mci = &btcoex->mci; 115 struct ath_mci_profile *mci = &btcoex->mci;
116 struct ath9k_hw_mci *mci_hw = &sc->sc_ah->btcoex_hw.mci;
119 struct ath_mci_profile_info *info; 117 struct ath_mci_profile_info *info;
120 u32 num_profile = NUM_PROF(mci); 118 u32 num_profile = NUM_PROF(mci);
121 119
120 if (mci_hw->config & ATH_MCI_CONFIG_DISABLE_TUNING)
121 goto skip_tuning;
122
123 btcoex->duty_cycle = ath_mci_duty_cycle[num_profile];
124
122 if (num_profile == 1) { 125 if (num_profile == 1) {
123 info = list_first_entry(&mci->info, 126 info = list_first_entry(&mci->info,
124 struct ath_mci_profile_info, 127 struct ath_mci_profile_info,
125 list); 128 list);
126 if (mci->num_sco && info->T == 12) { 129 if (mci->num_sco) {
127 mci->aggr_limit = 8; 130 if (info->T == 12)
131 mci->aggr_limit = 8;
132 else if (info->T == 6) {
133 mci->aggr_limit = 6;
134 btcoex->duty_cycle = 30;
135 }
128 ath_dbg(common, MCI, 136 ath_dbg(common, MCI,
129 "Single SCO, aggregation limit 2 ms\n"); 137 "Single SCO, aggregation limit %d 1/4 ms\n",
130 } else if ((info->type == MCI_GPM_COEX_PROFILE_BNEP) && 138 mci->aggr_limit);
131 !info->master) { 139 } else if (mci->num_pan || mci->num_other_acl) {
132 btcoex->btcoex_period = 60; 140 /*
141 * For single PAN/FTP profile, allocate 35% for BT
142 * to improve WLAN throughput.
143 */
144 btcoex->duty_cycle = 35;
145 btcoex->btcoex_period = 53;
133 ath_dbg(common, MCI, 146 ath_dbg(common, MCI,
134 "Single slave PAN/FTP, bt period 60 ms\n"); 147 "Single PAN/FTP bt period %d ms dutycycle %d\n",
135 } else if ((info->type == MCI_GPM_COEX_PROFILE_HID) && 148 btcoex->duty_cycle, btcoex->btcoex_period);
136 (info->T > 0 && info->T < 50) && 149 } else if (mci->num_hid) {
137 (info->A > 1 || info->W > 1)) {
138 btcoex->duty_cycle = 30; 150 btcoex->duty_cycle = 30;
139 mci->aggr_limit = 8; 151 mci->aggr_limit = 6;
140 ath_dbg(common, MCI, 152 ath_dbg(common, MCI,
141 "Multiple attempt/timeout single HID " 153 "Multiple attempt/timeout single HID "
142 "aggregation limit 2 ms dutycycle 30%%\n"); 154 "aggregation limit 1.5 ms dutycycle 30%%\n");
143 } 155 }
144 } else if ((num_profile == 2) && (mci->num_hid == 2)) { 156 } else if (num_profile == 2) {
145 btcoex->duty_cycle = 30; 157 if (mci->num_hid == 2)
146 mci->aggr_limit = 8; 158 btcoex->duty_cycle = 30;
147 ath_dbg(common, MCI,
148 "Two HIDs aggregation limit 2 ms dutycycle 30%%\n");
149 } else if (num_profile > 3) {
150 mci->aggr_limit = 6; 159 mci->aggr_limit = 6;
151 ath_dbg(common, MCI, 160 ath_dbg(common, MCI,
152 "Three or more profiles aggregation limit 1.5 ms\n"); 161 "Two BT profiles aggr limit 1.5 ms dutycycle %d%%\n",
162 btcoex->duty_cycle);
163 } else if (num_profile >= 3) {
164 mci->aggr_limit = 4;
165 ath_dbg(common, MCI,
166 "Three or more profiles aggregation limit 1 ms\n");
153 } 167 }
154 168
169skip_tuning:
155 if (IS_CHAN_2GHZ(sc->sc_ah->curchan)) { 170 if (IS_CHAN_2GHZ(sc->sc_ah->curchan)) {
156 if (IS_CHAN_HT(sc->sc_ah->curchan)) 171 if (IS_CHAN_HT(sc->sc_ah->curchan))
157 ath_mci_adjust_aggr_limit(btcoex); 172 ath_mci_adjust_aggr_limit(btcoex);
@@ -165,12 +180,11 @@ static void ath_mci_update_scheme(struct ath_softc *sc)
165 if (IS_CHAN_5GHZ(sc->sc_ah->curchan)) 180 if (IS_CHAN_5GHZ(sc->sc_ah->curchan))
166 return; 181 return;
167 182
168 btcoex->duty_cycle += (mci->num_bdr ? ATH_MCI_MAX_DUTY_CYCLE : 0); 183 btcoex->duty_cycle += (mci->num_bdr ? ATH_MCI_BDR_DUTY_CYCLE : 0);
169 if (btcoex->duty_cycle > ATH_MCI_MAX_DUTY_CYCLE) 184 if (btcoex->duty_cycle > ATH_MCI_MAX_DUTY_CYCLE)
170 btcoex->duty_cycle = ATH_MCI_MAX_DUTY_CYCLE; 185 btcoex->duty_cycle = ATH_MCI_MAX_DUTY_CYCLE;
171 186
172 btcoex->btcoex_period *= 1000; 187 btcoex->btcoex_no_stomp = btcoex->btcoex_period * 1000 *
173 btcoex->btcoex_no_stomp = btcoex->btcoex_period *
174 (100 - btcoex->duty_cycle) / 100; 188 (100 - btcoex->duty_cycle) / 100;
175 189
176 ath9k_hw_btcoex_enable(sc->sc_ah); 190 ath9k_hw_btcoex_enable(sc->sc_ah);
@@ -181,20 +195,16 @@ static void ath_mci_cal_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload)
181{ 195{
182 struct ath_hw *ah = sc->sc_ah; 196 struct ath_hw *ah = sc->sc_ah;
183 struct ath_common *common = ath9k_hw_common(ah); 197 struct ath_common *common = ath9k_hw_common(ah);
198 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
184 u32 payload[4] = {0, 0, 0, 0}; 199 u32 payload[4] = {0, 0, 0, 0};
185 200
186 switch (opcode) { 201 switch (opcode) {
187 case MCI_GPM_BT_CAL_REQ: 202 case MCI_GPM_BT_CAL_REQ:
188 if (ar9003_mci_state(ah, MCI_STATE_BT, NULL) == MCI_BT_AWAKE) { 203 if (mci_hw->bt_state == MCI_BT_AWAKE) {
189 ar9003_mci_state(ah, MCI_STATE_SET_BT_CAL_START, NULL); 204 ar9003_mci_state(ah, MCI_STATE_SET_BT_CAL_START);
190 ieee80211_queue_work(sc->hw, &sc->hw_reset_work); 205 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
191 } else {
192 ath_dbg(common, MCI, "MCI State mismatch: %d\n",
193 ar9003_mci_state(ah, MCI_STATE_BT, NULL));
194 } 206 }
195 break; 207 ath_dbg(common, MCI, "MCI State : %d\n", mci_hw->bt_state);
196 case MCI_GPM_BT_CAL_DONE:
197 ar9003_mci_state(ah, MCI_STATE_BT, NULL);
198 break; 208 break;
199 case MCI_GPM_BT_CAL_GRANT: 209 case MCI_GPM_BT_CAL_GRANT:
200 MCI_GPM_SET_CAL_TYPE(payload, MCI_GPM_WLAN_CAL_DONE); 210 MCI_GPM_SET_CAL_TYPE(payload, MCI_GPM_WLAN_CAL_DONE);
@@ -207,32 +217,42 @@ static void ath_mci_cal_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload)
207 } 217 }
208} 218}
209 219
220static void ath9k_mci_work(struct work_struct *work)
221{
222 struct ath_softc *sc = container_of(work, struct ath_softc, mci_work);
223
224 ath_mci_update_scheme(sc);
225}
226
210static void ath_mci_process_profile(struct ath_softc *sc, 227static void ath_mci_process_profile(struct ath_softc *sc,
211 struct ath_mci_profile_info *info) 228 struct ath_mci_profile_info *info)
212{ 229{
213 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 230 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
214 struct ath_btcoex *btcoex = &sc->btcoex; 231 struct ath_btcoex *btcoex = &sc->btcoex;
215 struct ath_mci_profile *mci = &btcoex->mci; 232 struct ath_mci_profile *mci = &btcoex->mci;
233 struct ath_mci_profile_info *entry = NULL;
234
235 entry = ath_mci_find_profile(mci, info);
236 if (entry)
237 memcpy(entry, info, 10);
216 238
217 if (info->start) { 239 if (info->start) {
218 if (!ath_mci_add_profile(common, mci, info)) 240 if (!entry && !ath_mci_add_profile(common, mci, info))
219 return; 241 return;
220 } else 242 } else
221 ath_mci_del_profile(common, mci, info); 243 ath_mci_del_profile(common, mci, entry);
222 244
223 btcoex->btcoex_period = ATH_MCI_DEF_BT_PERIOD; 245 btcoex->btcoex_period = ATH_MCI_DEF_BT_PERIOD;
224 mci->aggr_limit = mci->num_sco ? 6 : 0; 246 mci->aggr_limit = mci->num_sco ? 6 : 0;
225 247
226 if (NUM_PROF(mci)) { 248 btcoex->duty_cycle = ath_mci_duty_cycle[NUM_PROF(mci)];
249 if (NUM_PROF(mci))
227 btcoex->bt_stomp_type = ATH_BTCOEX_STOMP_LOW; 250 btcoex->bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
228 btcoex->duty_cycle = ath_mci_duty_cycle[NUM_PROF(mci)]; 251 else
229 } else {
230 btcoex->bt_stomp_type = mci->num_mgmt ? ATH_BTCOEX_STOMP_ALL : 252 btcoex->bt_stomp_type = mci->num_mgmt ? ATH_BTCOEX_STOMP_ALL :
231 ATH_BTCOEX_STOMP_LOW; 253 ATH_BTCOEX_STOMP_LOW;
232 btcoex->duty_cycle = ATH_BTCOEX_DEF_DUTY_CYCLE;
233 }
234 254
235 ath_mci_update_scheme(sc); 255 ieee80211_queue_work(sc->hw, &sc->mci_work);
236} 256}
237 257
238static void ath_mci_process_status(struct ath_softc *sc, 258static void ath_mci_process_status(struct ath_softc *sc,
@@ -247,8 +267,6 @@ static void ath_mci_process_status(struct ath_softc *sc,
247 if (status->is_link) 267 if (status->is_link)
248 return; 268 return;
249 269
250 memset(&info, 0, sizeof(struct ath_mci_profile_info));
251
252 info.conn_handle = status->conn_handle; 270 info.conn_handle = status->conn_handle;
253 if (ath_mci_find_profile(mci, &info)) 271 if (ath_mci_find_profile(mci, &info))
254 return; 272 return;
@@ -268,7 +286,7 @@ static void ath_mci_process_status(struct ath_softc *sc,
268 } while (++i < ATH_MCI_MAX_PROFILE); 286 } while (++i < ATH_MCI_MAX_PROFILE);
269 287
270 if (old_num_mgmt != mci->num_mgmt) 288 if (old_num_mgmt != mci->num_mgmt)
271 ath_mci_update_scheme(sc); 289 ieee80211_queue_work(sc->hw, &sc->mci_work);
272} 290}
273 291
274static void ath_mci_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload) 292static void ath_mci_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload)
@@ -277,25 +295,20 @@ static void ath_mci_msg(struct ath_softc *sc, u8 opcode, u8 *rx_payload)
277 struct ath_mci_profile_info profile_info; 295 struct ath_mci_profile_info profile_info;
278 struct ath_mci_profile_status profile_status; 296 struct ath_mci_profile_status profile_status;
279 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 297 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
280 u32 version; 298 u8 major, minor;
281 u8 major;
282 u8 minor;
283 u32 seq_num; 299 u32 seq_num;
284 300
285 switch (opcode) { 301 switch (opcode) {
286 case MCI_GPM_COEX_VERSION_QUERY: 302 case MCI_GPM_COEX_VERSION_QUERY:
287 version = ar9003_mci_state(ah, MCI_STATE_SEND_WLAN_COEX_VERSION, 303 ar9003_mci_state(ah, MCI_STATE_SEND_WLAN_COEX_VERSION);
288 NULL);
289 break; 304 break;
290 case MCI_GPM_COEX_VERSION_RESPONSE: 305 case MCI_GPM_COEX_VERSION_RESPONSE:
291 major = *(rx_payload + MCI_GPM_COEX_B_MAJOR_VERSION); 306 major = *(rx_payload + MCI_GPM_COEX_B_MAJOR_VERSION);
292 minor = *(rx_payload + MCI_GPM_COEX_B_MINOR_VERSION); 307 minor = *(rx_payload + MCI_GPM_COEX_B_MINOR_VERSION);
293 version = (major << 8) + minor; 308 ar9003_mci_set_bt_version(ah, major, minor);
294 version = ar9003_mci_state(ah, MCI_STATE_SET_BT_COEX_VERSION,
295 &version);
296 break; 309 break;
297 case MCI_GPM_COEX_STATUS_QUERY: 310 case MCI_GPM_COEX_STATUS_QUERY:
298 ar9003_mci_state(ah, MCI_STATE_SEND_WLAN_CHANNELS, NULL); 311 ar9003_mci_send_wlan_channels(ah);
299 break; 312 break;
300 case MCI_GPM_COEX_BT_PROFILE_INFO: 313 case MCI_GPM_COEX_BT_PROFILE_INFO:
301 memcpy(&profile_info, 314 memcpy(&profile_info,
@@ -362,6 +375,7 @@ int ath_mci_setup(struct ath_softc *sc)
362 mci->gpm_buf.bf_addr, (mci->gpm_buf.bf_len >> 4), 375 mci->gpm_buf.bf_addr, (mci->gpm_buf.bf_len >> 4),
363 mci->sched_buf.bf_paddr); 376 mci->sched_buf.bf_paddr);
364 377
378 INIT_WORK(&sc->mci_work, ath9k_mci_work);
365 ath_dbg(common, MCI, "MCI Initialized\n"); 379 ath_dbg(common, MCI, "MCI Initialized\n");
366 380
367 return 0; 381 return 0;
@@ -389,6 +403,7 @@ void ath_mci_intr(struct ath_softc *sc)
389 struct ath_mci_coex *mci = &sc->mci_coex; 403 struct ath_mci_coex *mci = &sc->mci_coex;
390 struct ath_hw *ah = sc->sc_ah; 404 struct ath_hw *ah = sc->sc_ah;
391 struct ath_common *common = ath9k_hw_common(ah); 405 struct ath_common *common = ath9k_hw_common(ah);
406 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
392 u32 mci_int, mci_int_rxmsg; 407 u32 mci_int, mci_int_rxmsg;
393 u32 offset, subtype, opcode; 408 u32 offset, subtype, opcode;
394 u32 *pgpm; 409 u32 *pgpm;
@@ -397,8 +412,8 @@ void ath_mci_intr(struct ath_softc *sc)
397 412
398 ar9003_mci_get_interrupt(sc->sc_ah, &mci_int, &mci_int_rxmsg); 413 ar9003_mci_get_interrupt(sc->sc_ah, &mci_int, &mci_int_rxmsg);
399 414
400 if (ar9003_mci_state(ah, MCI_STATE_ENABLE, NULL) == 0) { 415 if (ar9003_mci_state(ah, MCI_STATE_ENABLE) == 0) {
401 ar9003_mci_state(ah, MCI_STATE_INIT_GPM_OFFSET, NULL); 416 ar9003_mci_get_next_gpm_offset(ah, true, NULL);
402 return; 417 return;
403 } 418 }
404 419
@@ -417,46 +432,41 @@ void ath_mci_intr(struct ath_softc *sc)
417 NULL, 0, true, false); 432 NULL, 0, true, false);
418 433
419 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE; 434 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE;
420 ar9003_mci_state(ah, MCI_STATE_RESET_REQ_WAKE, NULL); 435 ar9003_mci_state(ah, MCI_STATE_RESET_REQ_WAKE);
421 436
422 /* 437 /*
423 * always do this for recovery and 2G/5G toggling and LNA_TRANS 438 * always do this for recovery and 2G/5G toggling and LNA_TRANS
424 */ 439 */
425 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE, NULL); 440 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE);
426 } 441 }
427 442
428 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING) { 443 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING) {
429 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING; 444 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING;
430 445
431 if (ar9003_mci_state(ah, MCI_STATE_BT, NULL) == MCI_BT_SLEEP) { 446 if ((mci_hw->bt_state == MCI_BT_SLEEP) &&
432 if (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP, NULL) != 447 (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP) !=
433 MCI_BT_SLEEP) 448 MCI_BT_SLEEP))
434 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE, 449 ar9003_mci_state(ah, MCI_STATE_SET_BT_AWAKE);
435 NULL);
436 }
437 } 450 }
438 451
439 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) { 452 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) {
440 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING; 453 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING;
441 454
442 if (ar9003_mci_state(ah, MCI_STATE_BT, NULL) == MCI_BT_AWAKE) { 455 if ((mci_hw->bt_state == MCI_BT_AWAKE) &&
443 if (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP, NULL) != 456 (ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP) !=
444 MCI_BT_AWAKE) 457 MCI_BT_AWAKE))
445 ar9003_mci_state(ah, MCI_STATE_SET_BT_SLEEP, 458 mci_hw->bt_state = MCI_BT_SLEEP;
446 NULL);
447 }
448 } 459 }
449 460
450 if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) || 461 if ((mci_int & AR_MCI_INTERRUPT_RX_INVALID_HDR) ||
451 (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT)) { 462 (mci_int & AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT)) {
452 ar9003_mci_state(ah, MCI_STATE_RECOVER_RX, NULL); 463 ar9003_mci_state(ah, MCI_STATE_RECOVER_RX);
453 skip_gpm = true; 464 skip_gpm = true;
454 } 465 }
455 466
456 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO) { 467 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO) {
457 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO; 468 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_SCHD_INFO;
458 offset = ar9003_mci_state(ah, MCI_STATE_LAST_SCHD_MSG_OFFSET, 469 offset = ar9003_mci_state(ah, MCI_STATE_LAST_SCHD_MSG_OFFSET);
459 NULL);
460 } 470 }
461 471
462 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_GPM) { 472 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_GPM) {
@@ -465,8 +475,8 @@ void ath_mci_intr(struct ath_softc *sc)
465 while (more_data == MCI_GPM_MORE) { 475 while (more_data == MCI_GPM_MORE) {
466 476
467 pgpm = mci->gpm_buf.bf_addr; 477 pgpm = mci->gpm_buf.bf_addr;
468 offset = ar9003_mci_state(ah, MCI_STATE_NEXT_GPM_OFFSET, 478 offset = ar9003_mci_get_next_gpm_offset(ah, false,
469 &more_data); 479 &more_data);
470 480
471 if (offset == MCI_GPM_INVALID) 481 if (offset == MCI_GPM_INVALID)
472 break; 482 break;
@@ -507,23 +517,17 @@ void ath_mci_intr(struct ath_softc *sc)
507 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_INFO; 517 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_LNA_INFO;
508 518
509 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_INFO) { 519 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_INFO) {
510 int value_dbm = ar9003_mci_state(ah, 520 int value_dbm = MS(mci_hw->cont_status,
511 MCI_STATE_CONT_RSSI_POWER, NULL); 521 AR_MCI_CONT_RSSI_POWER);
512 522
513 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_INFO; 523 mci_int_rxmsg &= ~AR_MCI_INTERRUPT_RX_MSG_CONT_INFO;
514 524
515 if (ar9003_mci_state(ah, MCI_STATE_CONT_TXRX, NULL)) 525 ath_dbg(common, MCI,
516 ath_dbg(common, MCI, 526 "MCI CONT_INFO: (%s) pri = %d pwr = %d dBm\n",
517 "MCI CONT_INFO: (tx) pri = %d, pwr = %d dBm\n", 527 MS(mci_hw->cont_status, AR_MCI_CONT_TXRX) ?
518 ar9003_mci_state(ah, 528 "tx" : "rx",
519 MCI_STATE_CONT_PRIORITY, NULL), 529 MS(mci_hw->cont_status, AR_MCI_CONT_PRIORITY),
520 value_dbm); 530 value_dbm);
521 else
522 ath_dbg(common, MCI,
523 "MCI CONT_INFO: (rx) pri = %d,pwr = %d dBm\n",
524 ar9003_mci_state(ah,
525 MCI_STATE_CONT_PRIORITY, NULL),
526 value_dbm);
527 } 531 }
528 532
529 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_NACK) 533 if (mci_int_rxmsg & AR_MCI_INTERRUPT_RX_MSG_CONT_NACK)
@@ -538,3 +542,14 @@ void ath_mci_intr(struct ath_softc *sc)
538 mci_int &= ~(AR_MCI_INTERRUPT_RX_INVALID_HDR | 542 mci_int &= ~(AR_MCI_INTERRUPT_RX_INVALID_HDR |
539 AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT); 543 AR_MCI_INTERRUPT_CONT_INFO_TIMEOUT);
540} 544}
545
546void ath_mci_enable(struct ath_softc *sc)
547{
548 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
549
550 if (!common->btcoex_enabled)
551 return;
552
553 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_MCI)
554 sc->sc_ah->imask |= ATH9K_INT_MCI;
555}
diff --git a/drivers/net/wireless/ath/ath9k/mci.h b/drivers/net/wireless/ath/ath9k/mci.h
index c841444f53c2..fc14eea034eb 100644
--- a/drivers/net/wireless/ath/ath9k/mci.h
+++ b/drivers/net/wireless/ath/ath9k/mci.h
@@ -130,4 +130,13 @@ void ath_mci_flush_profile(struct ath_mci_profile *mci);
130int ath_mci_setup(struct ath_softc *sc); 130int ath_mci_setup(struct ath_softc *sc);
131void ath_mci_cleanup(struct ath_softc *sc); 131void ath_mci_cleanup(struct ath_softc *sc);
132void ath_mci_intr(struct ath_softc *sc); 132void ath_mci_intr(struct ath_softc *sc);
133#endif 133
134#ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
135void ath_mci_enable(struct ath_softc *sc);
136#else
137static inline void ath_mci_enable(struct ath_softc *sc)
138{
139}
140#endif /* CONFIG_ATH9K_BTCOEX_SUPPORT */
141
142#endif /* MCI_H*/
diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c
index a856b51255f4..aa0e83ac51f4 100644
--- a/drivers/net/wireless/ath/ath9k/pci.c
+++ b/drivers/net/wireless/ath/ath9k/pci.c
@@ -115,6 +115,9 @@ static void ath_pci_aspm_init(struct ath_common *common)
115 int pos; 115 int pos;
116 u8 aspm; 116 u8 aspm;
117 117
118 if (!ah->is_pciexpress)
119 return;
120
118 pos = pci_pcie_cap(pdev); 121 pos = pci_pcie_cap(pdev);
119 if (!pos) 122 if (!pos)
120 return; 123 return;
@@ -138,6 +141,7 @@ static void ath_pci_aspm_init(struct ath_common *common)
138 aspm &= ~(PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1); 141 aspm &= ~(PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1);
139 pci_write_config_byte(parent, pos + PCI_EXP_LNKCTL, aspm); 142 pci_write_config_byte(parent, pos + PCI_EXP_LNKCTL, aspm);
140 143
144 ath_info(common, "Disabling ASPM since BTCOEX is enabled\n");
141 return; 145 return;
142 } 146 }
143 147
@@ -147,6 +151,7 @@ static void ath_pci_aspm_init(struct ath_common *common)
147 ah->aspm_enabled = true; 151 ah->aspm_enabled = true;
148 /* Initialize PCIe PM and SERDES registers. */ 152 /* Initialize PCIe PM and SERDES registers. */
149 ath9k_hw_configpcipowersave(ah, false); 153 ath9k_hw_configpcipowersave(ah, false);
154 ath_info(common, "ASPM enabled: 0x%x\n", aspm);
150 } 155 }
151} 156}
152 157
@@ -246,7 +251,7 @@ static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
246 sc->mem = mem; 251 sc->mem = mem;
247 252
248 /* Will be cleared in ath9k_start() */ 253 /* Will be cleared in ath9k_start() */
249 sc->sc_flags |= SC_OP_INVALID; 254 set_bit(SC_OP_INVALID, &sc->sc_flags);
250 255
251 ret = request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath9k", sc); 256 ret = request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath9k", sc);
252 if (ret) { 257 if (ret) {
diff --git a/drivers/net/wireless/ath/ath9k/rc.c b/drivers/net/wireless/ath/ath9k/rc.c
index 92a6c0a87f89..e034add9cd5a 100644
--- a/drivers/net/wireless/ath/ath9k/rc.c
+++ b/drivers/net/wireless/ath/ath9k/rc.c
@@ -770,7 +770,7 @@ static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
770 struct ieee80211_tx_rate *rates = tx_info->control.rates; 770 struct ieee80211_tx_rate *rates = tx_info->control.rates;
771 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 771 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
772 __le16 fc = hdr->frame_control; 772 __le16 fc = hdr->frame_control;
773 u8 try_per_rate, i = 0, rix, high_rix; 773 u8 try_per_rate, i = 0, rix;
774 int is_probe = 0; 774 int is_probe = 0;
775 775
776 if (rate_control_send_low(sta, priv_sta, txrc)) 776 if (rate_control_send_low(sta, priv_sta, txrc))
@@ -791,7 +791,6 @@ static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
791 rate_table = ath_rc_priv->rate_table; 791 rate_table = ath_rc_priv->rate_table;
792 rix = ath_rc_get_highest_rix(sc, ath_rc_priv, rate_table, 792 rix = ath_rc_get_highest_rix(sc, ath_rc_priv, rate_table,
793 &is_probe, false); 793 &is_probe, false);
794 high_rix = rix;
795 794
796 /* 795 /*
797 * If we're in HT mode and both us and our peer supports LDPC. 796 * If we're in HT mode and both us and our peer supports LDPC.
@@ -839,16 +838,16 @@ static void ath_get_rate(void *priv, struct ieee80211_sta *sta, void *priv_sta,
839 try_per_rate = 8; 838 try_per_rate = 8;
840 839
841 /* 840 /*
842 * Use a legacy rate as last retry to ensure that the frame 841 * If the last rate in the rate series is MCS and has
843 * is tried in both MCS and legacy rates. 842 * more than 80% of per thresh, then use a legacy rate
843 * as last retry to ensure that the frame is tried in both
844 * MCS and legacy rate.
844 */ 845 */
845 if ((rates[2].flags & IEEE80211_TX_RC_MCS) && 846 ath_rc_get_lower_rix(rate_table, ath_rc_priv, rix, &rix);
846 (!(tx_info->flags & IEEE80211_TX_CTL_AMPDU) || 847 if (WLAN_RC_PHY_HT(rate_table->info[rix].phy) &&
847 (ath_rc_priv->per[high_rix] > 45))) 848 (ath_rc_priv->per[rix] > 45))
848 rix = ath_rc_get_highest_rix(sc, ath_rc_priv, rate_table, 849 rix = ath_rc_get_highest_rix(sc, ath_rc_priv, rate_table,
849 &is_probe, true); 850 &is_probe, true);
850 else
851 ath_rc_get_lower_rix(rate_table, ath_rc_priv, rix, &rix);
852 851
853 /* All other rates in the series have RTS enabled */ 852 /* All other rates in the series have RTS enabled */
854 ath_rc_rate_set_series(rate_table, &rates[i], txrc, 853 ath_rc_rate_set_series(rate_table, &rates[i], txrc,
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index e1fcc68124dc..fbdcc80437fe 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -20,43 +20,6 @@
20 20
21#define SKB_CB_ATHBUF(__skb) (*((struct ath_buf **)__skb->cb)) 21#define SKB_CB_ATHBUF(__skb) (*((struct ath_buf **)__skb->cb))
22 22
23static inline bool ath_is_alt_ant_ratio_better(int alt_ratio, int maxdelta,
24 int mindelta, int main_rssi_avg,
25 int alt_rssi_avg, int pkt_count)
26{
27 return (((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
28 (alt_rssi_avg > main_rssi_avg + maxdelta)) ||
29 (alt_rssi_avg > main_rssi_avg + mindelta)) && (pkt_count > 50);
30}
31
32static inline bool ath_ant_div_comb_alt_check(u8 div_group, int alt_ratio,
33 int curr_main_set, int curr_alt_set,
34 int alt_rssi_avg, int main_rssi_avg)
35{
36 bool result = false;
37 switch (div_group) {
38 case 0:
39 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO)
40 result = true;
41 break;
42 case 1:
43 case 2:
44 if ((((curr_main_set == ATH_ANT_DIV_COMB_LNA2) &&
45 (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) &&
46 (alt_rssi_avg >= (main_rssi_avg - 5))) ||
47 ((curr_main_set == ATH_ANT_DIV_COMB_LNA1) &&
48 (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) &&
49 (alt_rssi_avg >= (main_rssi_avg - 2)))) &&
50 (alt_rssi_avg >= 4))
51 result = true;
52 else
53 result = false;
54 break;
55 }
56
57 return result;
58}
59
60static inline bool ath9k_check_auto_sleep(struct ath_softc *sc) 23static inline bool ath9k_check_auto_sleep(struct ath_softc *sc)
61{ 24{
62 return sc->ps_enabled && 25 return sc->ps_enabled &&
@@ -303,7 +266,7 @@ static void ath_edma_start_recv(struct ath_softc *sc)
303 266
304 ath_opmode_init(sc); 267 ath_opmode_init(sc);
305 268
306 ath9k_hw_startpcureceive(sc->sc_ah, (sc->sc_flags & SC_OP_OFFCHANNEL)); 269 ath9k_hw_startpcureceive(sc->sc_ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL));
307 270
308 spin_unlock_bh(&sc->rx.rxbuflock); 271 spin_unlock_bh(&sc->rx.rxbuflock);
309} 272}
@@ -322,8 +285,8 @@ int ath_rx_init(struct ath_softc *sc, int nbufs)
322 int error = 0; 285 int error = 0;
323 286
324 spin_lock_init(&sc->sc_pcu_lock); 287 spin_lock_init(&sc->sc_pcu_lock);
325 sc->sc_flags &= ~SC_OP_RXFLUSH;
326 spin_lock_init(&sc->rx.rxbuflock); 288 spin_lock_init(&sc->rx.rxbuflock);
289 clear_bit(SC_OP_RXFLUSH, &sc->sc_flags);
327 290
328 common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 + 291 common->rx_bufsize = IEEE80211_MAX_MPDU_LEN / 2 +
329 sc->sc_ah->caps.rx_status_len; 292 sc->sc_ah->caps.rx_status_len;
@@ -500,7 +463,7 @@ int ath_startrecv(struct ath_softc *sc)
500 463
501start_recv: 464start_recv:
502 ath_opmode_init(sc); 465 ath_opmode_init(sc);
503 ath9k_hw_startpcureceive(ah, (sc->sc_flags & SC_OP_OFFCHANNEL)); 466 ath9k_hw_startpcureceive(ah, !!(sc->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL));
504 467
505 spin_unlock_bh(&sc->rx.rxbuflock); 468 spin_unlock_bh(&sc->rx.rxbuflock);
506 469
@@ -535,11 +498,11 @@ bool ath_stoprecv(struct ath_softc *sc)
535 498
536void ath_flushrecv(struct ath_softc *sc) 499void ath_flushrecv(struct ath_softc *sc)
537{ 500{
538 sc->sc_flags |= SC_OP_RXFLUSH; 501 set_bit(SC_OP_RXFLUSH, &sc->sc_flags);
539 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) 502 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA)
540 ath_rx_tasklet(sc, 1, true); 503 ath_rx_tasklet(sc, 1, true);
541 ath_rx_tasklet(sc, 1, false); 504 ath_rx_tasklet(sc, 1, false);
542 sc->sc_flags &= ~SC_OP_RXFLUSH; 505 clear_bit(SC_OP_RXFLUSH, &sc->sc_flags);
543} 506}
544 507
545static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb) 508static bool ath_beacon_dtim_pending_cab(struct sk_buff *skb)
@@ -624,13 +587,13 @@ static void ath_rx_ps(struct ath_softc *sc, struct sk_buff *skb, bool mybeacon)
624 587
625 /* Process Beacon and CAB receive in PS state */ 588 /* Process Beacon and CAB receive in PS state */
626 if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc)) 589 if (((sc->ps_flags & PS_WAIT_FOR_BEACON) || ath9k_check_auto_sleep(sc))
627 && mybeacon) 590 && mybeacon) {
628 ath_rx_ps_beacon(sc, skb); 591 ath_rx_ps_beacon(sc, skb);
629 else if ((sc->ps_flags & PS_WAIT_FOR_CAB) && 592 } else if ((sc->ps_flags & PS_WAIT_FOR_CAB) &&
630 (ieee80211_is_data(hdr->frame_control) || 593 (ieee80211_is_data(hdr->frame_control) ||
631 ieee80211_is_action(hdr->frame_control)) && 594 ieee80211_is_action(hdr->frame_control)) &&
632 is_multicast_ether_addr(hdr->addr1) && 595 is_multicast_ether_addr(hdr->addr1) &&
633 !ieee80211_has_moredata(hdr->frame_control)) { 596 !ieee80211_has_moredata(hdr->frame_control)) {
634 /* 597 /*
635 * No more broadcast/multicast frames to be received at this 598 * No more broadcast/multicast frames to be received at this
636 * point. 599 * point.
@@ -1067,709 +1030,6 @@ static void ath9k_rx_skb_postprocess(struct ath_common *common,
1067 rxs->flag &= ~RX_FLAG_DECRYPTED; 1030 rxs->flag &= ~RX_FLAG_DECRYPTED;
1068} 1031}
1069 1032
1070static void ath_lnaconf_alt_good_scan(struct ath_ant_comb *antcomb,
1071 struct ath_hw_antcomb_conf ant_conf,
1072 int main_rssi_avg)
1073{
1074 antcomb->quick_scan_cnt = 0;
1075
1076 if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
1077 antcomb->rssi_lna2 = main_rssi_avg;
1078 else if (ant_conf.main_lna_conf == ATH_ANT_DIV_COMB_LNA1)
1079 antcomb->rssi_lna1 = main_rssi_avg;
1080
1081 switch ((ant_conf.main_lna_conf << 4) | ant_conf.alt_lna_conf) {
1082 case 0x10: /* LNA2 A-B */
1083 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1084 antcomb->first_quick_scan_conf =
1085 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1086 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
1087 break;
1088 case 0x20: /* LNA1 A-B */
1089 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1090 antcomb->first_quick_scan_conf =
1091 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1092 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
1093 break;
1094 case 0x21: /* LNA1 LNA2 */
1095 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA2;
1096 antcomb->first_quick_scan_conf =
1097 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1098 antcomb->second_quick_scan_conf =
1099 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1100 break;
1101 case 0x12: /* LNA2 LNA1 */
1102 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1;
1103 antcomb->first_quick_scan_conf =
1104 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1105 antcomb->second_quick_scan_conf =
1106 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1107 break;
1108 case 0x13: /* LNA2 A+B */
1109 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1110 antcomb->first_quick_scan_conf =
1111 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1112 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA1;
1113 break;
1114 case 0x23: /* LNA1 A+B */
1115 antcomb->main_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1116 antcomb->first_quick_scan_conf =
1117 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1118 antcomb->second_quick_scan_conf = ATH_ANT_DIV_COMB_LNA2;
1119 break;
1120 default:
1121 break;
1122 }
1123}
1124
1125static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb,
1126 struct ath_hw_antcomb_conf *div_ant_conf,
1127 int main_rssi_avg, int alt_rssi_avg,
1128 int alt_ratio)
1129{
1130 /* alt_good */
1131 switch (antcomb->quick_scan_cnt) {
1132 case 0:
1133 /* set alt to main, and alt to first conf */
1134 div_ant_conf->main_lna_conf = antcomb->main_conf;
1135 div_ant_conf->alt_lna_conf = antcomb->first_quick_scan_conf;
1136 break;
1137 case 1:
1138 /* set alt to main, and alt to first conf */
1139 div_ant_conf->main_lna_conf = antcomb->main_conf;
1140 div_ant_conf->alt_lna_conf = antcomb->second_quick_scan_conf;
1141 antcomb->rssi_first = main_rssi_avg;
1142 antcomb->rssi_second = alt_rssi_avg;
1143
1144 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
1145 /* main is LNA1 */
1146 if (ath_is_alt_ant_ratio_better(alt_ratio,
1147 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
1148 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1149 main_rssi_avg, alt_rssi_avg,
1150 antcomb->total_pkt_count))
1151 antcomb->first_ratio = true;
1152 else
1153 antcomb->first_ratio = false;
1154 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
1155 if (ath_is_alt_ant_ratio_better(alt_ratio,
1156 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
1157 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1158 main_rssi_avg, alt_rssi_avg,
1159 antcomb->total_pkt_count))
1160 antcomb->first_ratio = true;
1161 else
1162 antcomb->first_ratio = false;
1163 } else {
1164 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
1165 (alt_rssi_avg > main_rssi_avg +
1166 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
1167 (alt_rssi_avg > main_rssi_avg)) &&
1168 (antcomb->total_pkt_count > 50))
1169 antcomb->first_ratio = true;
1170 else
1171 antcomb->first_ratio = false;
1172 }
1173 break;
1174 case 2:
1175 antcomb->alt_good = false;
1176 antcomb->scan_not_start = false;
1177 antcomb->scan = false;
1178 antcomb->rssi_first = main_rssi_avg;
1179 antcomb->rssi_third = alt_rssi_avg;
1180
1181 if (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1)
1182 antcomb->rssi_lna1 = alt_rssi_avg;
1183 else if (antcomb->second_quick_scan_conf ==
1184 ATH_ANT_DIV_COMB_LNA2)
1185 antcomb->rssi_lna2 = alt_rssi_avg;
1186 else if (antcomb->second_quick_scan_conf ==
1187 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2) {
1188 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2)
1189 antcomb->rssi_lna2 = main_rssi_avg;
1190 else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1)
1191 antcomb->rssi_lna1 = main_rssi_avg;
1192 }
1193
1194 if (antcomb->rssi_lna2 > antcomb->rssi_lna1 +
1195 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)
1196 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
1197 else
1198 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
1199
1200 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
1201 if (ath_is_alt_ant_ratio_better(alt_ratio,
1202 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
1203 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1204 main_rssi_avg, alt_rssi_avg,
1205 antcomb->total_pkt_count))
1206 antcomb->second_ratio = true;
1207 else
1208 antcomb->second_ratio = false;
1209 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
1210 if (ath_is_alt_ant_ratio_better(alt_ratio,
1211 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
1212 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
1213 main_rssi_avg, alt_rssi_avg,
1214 antcomb->total_pkt_count))
1215 antcomb->second_ratio = true;
1216 else
1217 antcomb->second_ratio = false;
1218 } else {
1219 if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
1220 (alt_rssi_avg > main_rssi_avg +
1221 ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
1222 (alt_rssi_avg > main_rssi_avg)) &&
1223 (antcomb->total_pkt_count > 50))
1224 antcomb->second_ratio = true;
1225 else
1226 antcomb->second_ratio = false;
1227 }
1228
1229 /* set alt to the conf with maximun ratio */
1230 if (antcomb->first_ratio && antcomb->second_ratio) {
1231 if (antcomb->rssi_second > antcomb->rssi_third) {
1232 /* first alt*/
1233 if ((antcomb->first_quick_scan_conf ==
1234 ATH_ANT_DIV_COMB_LNA1) ||
1235 (antcomb->first_quick_scan_conf ==
1236 ATH_ANT_DIV_COMB_LNA2))
1237 /* Set alt LNA1 or LNA2*/
1238 if (div_ant_conf->main_lna_conf ==
1239 ATH_ANT_DIV_COMB_LNA2)
1240 div_ant_conf->alt_lna_conf =
1241 ATH_ANT_DIV_COMB_LNA1;
1242 else
1243 div_ant_conf->alt_lna_conf =
1244 ATH_ANT_DIV_COMB_LNA2;
1245 else
1246 /* Set alt to A+B or A-B */
1247 div_ant_conf->alt_lna_conf =
1248 antcomb->first_quick_scan_conf;
1249 } else if ((antcomb->second_quick_scan_conf ==
1250 ATH_ANT_DIV_COMB_LNA1) ||
1251 (antcomb->second_quick_scan_conf ==
1252 ATH_ANT_DIV_COMB_LNA2)) {
1253 /* Set alt LNA1 or LNA2 */
1254 if (div_ant_conf->main_lna_conf ==
1255 ATH_ANT_DIV_COMB_LNA2)
1256 div_ant_conf->alt_lna_conf =
1257 ATH_ANT_DIV_COMB_LNA1;
1258 else
1259 div_ant_conf->alt_lna_conf =
1260 ATH_ANT_DIV_COMB_LNA2;
1261 } else {
1262 /* Set alt to A+B or A-B */
1263 div_ant_conf->alt_lna_conf =
1264 antcomb->second_quick_scan_conf;
1265 }
1266 } else if (antcomb->first_ratio) {
1267 /* first alt */
1268 if ((antcomb->first_quick_scan_conf ==
1269 ATH_ANT_DIV_COMB_LNA1) ||
1270 (antcomb->first_quick_scan_conf ==
1271 ATH_ANT_DIV_COMB_LNA2))
1272 /* Set alt LNA1 or LNA2 */
1273 if (div_ant_conf->main_lna_conf ==
1274 ATH_ANT_DIV_COMB_LNA2)
1275 div_ant_conf->alt_lna_conf =
1276 ATH_ANT_DIV_COMB_LNA1;
1277 else
1278 div_ant_conf->alt_lna_conf =
1279 ATH_ANT_DIV_COMB_LNA2;
1280 else
1281 /* Set alt to A+B or A-B */
1282 div_ant_conf->alt_lna_conf =
1283 antcomb->first_quick_scan_conf;
1284 } else if (antcomb->second_ratio) {
1285 /* second alt */
1286 if ((antcomb->second_quick_scan_conf ==
1287 ATH_ANT_DIV_COMB_LNA1) ||
1288 (antcomb->second_quick_scan_conf ==
1289 ATH_ANT_DIV_COMB_LNA2))
1290 /* Set alt LNA1 or LNA2 */
1291 if (div_ant_conf->main_lna_conf ==
1292 ATH_ANT_DIV_COMB_LNA2)
1293 div_ant_conf->alt_lna_conf =
1294 ATH_ANT_DIV_COMB_LNA1;
1295 else
1296 div_ant_conf->alt_lna_conf =
1297 ATH_ANT_DIV_COMB_LNA2;
1298 else
1299 /* Set alt to A+B or A-B */
1300 div_ant_conf->alt_lna_conf =
1301 antcomb->second_quick_scan_conf;
1302 } else {
1303 /* main is largest */
1304 if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) ||
1305 (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2))
1306 /* Set alt LNA1 or LNA2 */
1307 if (div_ant_conf->main_lna_conf ==
1308 ATH_ANT_DIV_COMB_LNA2)
1309 div_ant_conf->alt_lna_conf =
1310 ATH_ANT_DIV_COMB_LNA1;
1311 else
1312 div_ant_conf->alt_lna_conf =
1313 ATH_ANT_DIV_COMB_LNA2;
1314 else
1315 /* Set alt to A+B or A-B */
1316 div_ant_conf->alt_lna_conf = antcomb->main_conf;
1317 }
1318 break;
1319 default:
1320 break;
1321 }
1322}
1323
1324static void ath_ant_div_conf_fast_divbias(struct ath_hw_antcomb_conf *ant_conf,
1325 struct ath_ant_comb *antcomb, int alt_ratio)
1326{
1327 if (ant_conf->div_group == 0) {
1328 /* Adjust the fast_div_bias based on main and alt lna conf */
1329 switch ((ant_conf->main_lna_conf << 4) |
1330 ant_conf->alt_lna_conf) {
1331 case 0x01: /* A-B LNA2 */
1332 ant_conf->fast_div_bias = 0x3b;
1333 break;
1334 case 0x02: /* A-B LNA1 */
1335 ant_conf->fast_div_bias = 0x3d;
1336 break;
1337 case 0x03: /* A-B A+B */
1338 ant_conf->fast_div_bias = 0x1;
1339 break;
1340 case 0x10: /* LNA2 A-B */
1341 ant_conf->fast_div_bias = 0x7;
1342 break;
1343 case 0x12: /* LNA2 LNA1 */
1344 ant_conf->fast_div_bias = 0x2;
1345 break;
1346 case 0x13: /* LNA2 A+B */
1347 ant_conf->fast_div_bias = 0x7;
1348 break;
1349 case 0x20: /* LNA1 A-B */
1350 ant_conf->fast_div_bias = 0x6;
1351 break;
1352 case 0x21: /* LNA1 LNA2 */
1353 ant_conf->fast_div_bias = 0x0;
1354 break;
1355 case 0x23: /* LNA1 A+B */
1356 ant_conf->fast_div_bias = 0x6;
1357 break;
1358 case 0x30: /* A+B A-B */
1359 ant_conf->fast_div_bias = 0x1;
1360 break;
1361 case 0x31: /* A+B LNA2 */
1362 ant_conf->fast_div_bias = 0x3b;
1363 break;
1364 case 0x32: /* A+B LNA1 */
1365 ant_conf->fast_div_bias = 0x3d;
1366 break;
1367 default:
1368 break;
1369 }
1370 } else if (ant_conf->div_group == 1) {
1371 /* Adjust the fast_div_bias based on main and alt_lna_conf */
1372 switch ((ant_conf->main_lna_conf << 4) |
1373 ant_conf->alt_lna_conf) {
1374 case 0x01: /* A-B LNA2 */
1375 ant_conf->fast_div_bias = 0x1;
1376 ant_conf->main_gaintb = 0;
1377 ant_conf->alt_gaintb = 0;
1378 break;
1379 case 0x02: /* A-B LNA1 */
1380 ant_conf->fast_div_bias = 0x1;
1381 ant_conf->main_gaintb = 0;
1382 ant_conf->alt_gaintb = 0;
1383 break;
1384 case 0x03: /* A-B A+B */
1385 ant_conf->fast_div_bias = 0x1;
1386 ant_conf->main_gaintb = 0;
1387 ant_conf->alt_gaintb = 0;
1388 break;
1389 case 0x10: /* LNA2 A-B */
1390 if (!(antcomb->scan) &&
1391 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
1392 ant_conf->fast_div_bias = 0x3f;
1393 else
1394 ant_conf->fast_div_bias = 0x1;
1395 ant_conf->main_gaintb = 0;
1396 ant_conf->alt_gaintb = 0;
1397 break;
1398 case 0x12: /* LNA2 LNA1 */
1399 ant_conf->fast_div_bias = 0x1;
1400 ant_conf->main_gaintb = 0;
1401 ant_conf->alt_gaintb = 0;
1402 break;
1403 case 0x13: /* LNA2 A+B */
1404 if (!(antcomb->scan) &&
1405 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
1406 ant_conf->fast_div_bias = 0x3f;
1407 else
1408 ant_conf->fast_div_bias = 0x1;
1409 ant_conf->main_gaintb = 0;
1410 ant_conf->alt_gaintb = 0;
1411 break;
1412 case 0x20: /* LNA1 A-B */
1413 if (!(antcomb->scan) &&
1414 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
1415 ant_conf->fast_div_bias = 0x3f;
1416 else
1417 ant_conf->fast_div_bias = 0x1;
1418 ant_conf->main_gaintb = 0;
1419 ant_conf->alt_gaintb = 0;
1420 break;
1421 case 0x21: /* LNA1 LNA2 */
1422 ant_conf->fast_div_bias = 0x1;
1423 ant_conf->main_gaintb = 0;
1424 ant_conf->alt_gaintb = 0;
1425 break;
1426 case 0x23: /* LNA1 A+B */
1427 if (!(antcomb->scan) &&
1428 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
1429 ant_conf->fast_div_bias = 0x3f;
1430 else
1431 ant_conf->fast_div_bias = 0x1;
1432 ant_conf->main_gaintb = 0;
1433 ant_conf->alt_gaintb = 0;
1434 break;
1435 case 0x30: /* A+B A-B */
1436 ant_conf->fast_div_bias = 0x1;
1437 ant_conf->main_gaintb = 0;
1438 ant_conf->alt_gaintb = 0;
1439 break;
1440 case 0x31: /* A+B LNA2 */
1441 ant_conf->fast_div_bias = 0x1;
1442 ant_conf->main_gaintb = 0;
1443 ant_conf->alt_gaintb = 0;
1444 break;
1445 case 0x32: /* A+B LNA1 */
1446 ant_conf->fast_div_bias = 0x1;
1447 ant_conf->main_gaintb = 0;
1448 ant_conf->alt_gaintb = 0;
1449 break;
1450 default:
1451 break;
1452 }
1453 } else if (ant_conf->div_group == 2) {
1454 /* Adjust the fast_div_bias based on main and alt_lna_conf */
1455 switch ((ant_conf->main_lna_conf << 4) |
1456 ant_conf->alt_lna_conf) {
1457 case 0x01: /* A-B LNA2 */
1458 ant_conf->fast_div_bias = 0x1;
1459 ant_conf->main_gaintb = 0;
1460 ant_conf->alt_gaintb = 0;
1461 break;
1462 case 0x02: /* A-B LNA1 */
1463 ant_conf->fast_div_bias = 0x1;
1464 ant_conf->main_gaintb = 0;
1465 ant_conf->alt_gaintb = 0;
1466 break;
1467 case 0x03: /* A-B A+B */
1468 ant_conf->fast_div_bias = 0x1;
1469 ant_conf->main_gaintb = 0;
1470 ant_conf->alt_gaintb = 0;
1471 break;
1472 case 0x10: /* LNA2 A-B */
1473 if (!(antcomb->scan) &&
1474 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
1475 ant_conf->fast_div_bias = 0x1;
1476 else
1477 ant_conf->fast_div_bias = 0x2;
1478 ant_conf->main_gaintb = 0;
1479 ant_conf->alt_gaintb = 0;
1480 break;
1481 case 0x12: /* LNA2 LNA1 */
1482 ant_conf->fast_div_bias = 0x1;
1483 ant_conf->main_gaintb = 0;
1484 ant_conf->alt_gaintb = 0;
1485 break;
1486 case 0x13: /* LNA2 A+B */
1487 if (!(antcomb->scan) &&
1488 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
1489 ant_conf->fast_div_bias = 0x1;
1490 else
1491 ant_conf->fast_div_bias = 0x2;
1492 ant_conf->main_gaintb = 0;
1493 ant_conf->alt_gaintb = 0;
1494 break;
1495 case 0x20: /* LNA1 A-B */
1496 if (!(antcomb->scan) &&
1497 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
1498 ant_conf->fast_div_bias = 0x1;
1499 else
1500 ant_conf->fast_div_bias = 0x2;
1501 ant_conf->main_gaintb = 0;
1502 ant_conf->alt_gaintb = 0;
1503 break;
1504 case 0x21: /* LNA1 LNA2 */
1505 ant_conf->fast_div_bias = 0x1;
1506 ant_conf->main_gaintb = 0;
1507 ant_conf->alt_gaintb = 0;
1508 break;
1509 case 0x23: /* LNA1 A+B */
1510 if (!(antcomb->scan) &&
1511 (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
1512 ant_conf->fast_div_bias = 0x1;
1513 else
1514 ant_conf->fast_div_bias = 0x2;
1515 ant_conf->main_gaintb = 0;
1516 ant_conf->alt_gaintb = 0;
1517 break;
1518 case 0x30: /* A+B A-B */
1519 ant_conf->fast_div_bias = 0x1;
1520 ant_conf->main_gaintb = 0;
1521 ant_conf->alt_gaintb = 0;
1522 break;
1523 case 0x31: /* A+B LNA2 */
1524 ant_conf->fast_div_bias = 0x1;
1525 ant_conf->main_gaintb = 0;
1526 ant_conf->alt_gaintb = 0;
1527 break;
1528 case 0x32: /* A+B LNA1 */
1529 ant_conf->fast_div_bias = 0x1;
1530 ant_conf->main_gaintb = 0;
1531 ant_conf->alt_gaintb = 0;
1532 break;
1533 default:
1534 break;
1535 }
1536 }
1537}
1538
1539/* Antenna diversity and combining */
1540static void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs)
1541{
1542 struct ath_hw_antcomb_conf div_ant_conf;
1543 struct ath_ant_comb *antcomb = &sc->ant_comb;
1544 int alt_ratio = 0, alt_rssi_avg = 0, main_rssi_avg = 0, curr_alt_set;
1545 int curr_main_set;
1546 int main_rssi = rs->rs_rssi_ctl0;
1547 int alt_rssi = rs->rs_rssi_ctl1;
1548 int rx_ant_conf, main_ant_conf;
1549 bool short_scan = false;
1550
1551 rx_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_CURRENT_SHIFT) &
1552 ATH_ANT_RX_MASK;
1553 main_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_MAIN_SHIFT) &
1554 ATH_ANT_RX_MASK;
1555
1556 /* Record packet only when both main_rssi and alt_rssi is positive */
1557 if (main_rssi > 0 && alt_rssi > 0) {
1558 antcomb->total_pkt_count++;
1559 antcomb->main_total_rssi += main_rssi;
1560 antcomb->alt_total_rssi += alt_rssi;
1561 if (main_ant_conf == rx_ant_conf)
1562 antcomb->main_recv_cnt++;
1563 else
1564 antcomb->alt_recv_cnt++;
1565 }
1566
1567 /* Short scan check */
1568 if (antcomb->scan && antcomb->alt_good) {
1569 if (time_after(jiffies, antcomb->scan_start_time +
1570 msecs_to_jiffies(ATH_ANT_DIV_COMB_SHORT_SCAN_INTR)))
1571 short_scan = true;
1572 else
1573 if (antcomb->total_pkt_count ==
1574 ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT) {
1575 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
1576 antcomb->total_pkt_count);
1577 if (alt_ratio < ATH_ANT_DIV_COMB_ALT_ANT_RATIO)
1578 short_scan = true;
1579 }
1580 }
1581
1582 if (((antcomb->total_pkt_count < ATH_ANT_DIV_COMB_MAX_PKTCOUNT) ||
1583 rs->rs_moreaggr) && !short_scan)
1584 return;
1585
1586 if (antcomb->total_pkt_count) {
1587 alt_ratio = ((antcomb->alt_recv_cnt * 100) /
1588 antcomb->total_pkt_count);
1589 main_rssi_avg = (antcomb->main_total_rssi /
1590 antcomb->total_pkt_count);
1591 alt_rssi_avg = (antcomb->alt_total_rssi /
1592 antcomb->total_pkt_count);
1593 }
1594
1595
1596 ath9k_hw_antdiv_comb_conf_get(sc->sc_ah, &div_ant_conf);
1597 curr_alt_set = div_ant_conf.alt_lna_conf;
1598 curr_main_set = div_ant_conf.main_lna_conf;
1599
1600 antcomb->count++;
1601
1602 if (antcomb->count == ATH_ANT_DIV_COMB_MAX_COUNT) {
1603 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
1604 ath_lnaconf_alt_good_scan(antcomb, div_ant_conf,
1605 main_rssi_avg);
1606 antcomb->alt_good = true;
1607 } else {
1608 antcomb->alt_good = false;
1609 }
1610
1611 antcomb->count = 0;
1612 antcomb->scan = true;
1613 antcomb->scan_not_start = true;
1614 }
1615
1616 if (!antcomb->scan) {
1617 if (ath_ant_div_comb_alt_check(div_ant_conf.div_group,
1618 alt_ratio, curr_main_set, curr_alt_set,
1619 alt_rssi_avg, main_rssi_avg)) {
1620 if (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) {
1621 /* Switch main and alt LNA */
1622 div_ant_conf.main_lna_conf =
1623 ATH_ANT_DIV_COMB_LNA2;
1624 div_ant_conf.alt_lna_conf =
1625 ATH_ANT_DIV_COMB_LNA1;
1626 } else if (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) {
1627 div_ant_conf.main_lna_conf =
1628 ATH_ANT_DIV_COMB_LNA1;
1629 div_ant_conf.alt_lna_conf =
1630 ATH_ANT_DIV_COMB_LNA2;
1631 }
1632
1633 goto div_comb_done;
1634 } else if ((curr_alt_set != ATH_ANT_DIV_COMB_LNA1) &&
1635 (curr_alt_set != ATH_ANT_DIV_COMB_LNA2)) {
1636 /* Set alt to another LNA */
1637 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2)
1638 div_ant_conf.alt_lna_conf =
1639 ATH_ANT_DIV_COMB_LNA1;
1640 else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1)
1641 div_ant_conf.alt_lna_conf =
1642 ATH_ANT_DIV_COMB_LNA2;
1643
1644 goto div_comb_done;
1645 }
1646
1647 if ((alt_rssi_avg < (main_rssi_avg +
1648 div_ant_conf.lna1_lna2_delta)))
1649 goto div_comb_done;
1650 }
1651
1652 if (!antcomb->scan_not_start) {
1653 switch (curr_alt_set) {
1654 case ATH_ANT_DIV_COMB_LNA2:
1655 antcomb->rssi_lna2 = alt_rssi_avg;
1656 antcomb->rssi_lna1 = main_rssi_avg;
1657 antcomb->scan = true;
1658 /* set to A+B */
1659 div_ant_conf.main_lna_conf =
1660 ATH_ANT_DIV_COMB_LNA1;
1661 div_ant_conf.alt_lna_conf =
1662 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1663 break;
1664 case ATH_ANT_DIV_COMB_LNA1:
1665 antcomb->rssi_lna1 = alt_rssi_avg;
1666 antcomb->rssi_lna2 = main_rssi_avg;
1667 antcomb->scan = true;
1668 /* set to A+B */
1669 div_ant_conf.main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
1670 div_ant_conf.alt_lna_conf =
1671 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1672 break;
1673 case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
1674 antcomb->rssi_add = alt_rssi_avg;
1675 antcomb->scan = true;
1676 /* set to A-B */
1677 div_ant_conf.alt_lna_conf =
1678 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1679 break;
1680 case ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2:
1681 antcomb->rssi_sub = alt_rssi_avg;
1682 antcomb->scan = false;
1683 if (antcomb->rssi_lna2 >
1684 (antcomb->rssi_lna1 +
1685 ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) {
1686 /* use LNA2 as main LNA */
1687 if ((antcomb->rssi_add > antcomb->rssi_lna1) &&
1688 (antcomb->rssi_add > antcomb->rssi_sub)) {
1689 /* set to A+B */
1690 div_ant_conf.main_lna_conf =
1691 ATH_ANT_DIV_COMB_LNA2;
1692 div_ant_conf.alt_lna_conf =
1693 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1694 } else if (antcomb->rssi_sub >
1695 antcomb->rssi_lna1) {
1696 /* set to A-B */
1697 div_ant_conf.main_lna_conf =
1698 ATH_ANT_DIV_COMB_LNA2;
1699 div_ant_conf.alt_lna_conf =
1700 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1701 } else {
1702 /* set to LNA1 */
1703 div_ant_conf.main_lna_conf =
1704 ATH_ANT_DIV_COMB_LNA2;
1705 div_ant_conf.alt_lna_conf =
1706 ATH_ANT_DIV_COMB_LNA1;
1707 }
1708 } else {
1709 /* use LNA1 as main LNA */
1710 if ((antcomb->rssi_add > antcomb->rssi_lna2) &&
1711 (antcomb->rssi_add > antcomb->rssi_sub)) {
1712 /* set to A+B */
1713 div_ant_conf.main_lna_conf =
1714 ATH_ANT_DIV_COMB_LNA1;
1715 div_ant_conf.alt_lna_conf =
1716 ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
1717 } else if (antcomb->rssi_sub >
1718 antcomb->rssi_lna1) {
1719 /* set to A-B */
1720 div_ant_conf.main_lna_conf =
1721 ATH_ANT_DIV_COMB_LNA1;
1722 div_ant_conf.alt_lna_conf =
1723 ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
1724 } else {
1725 /* set to LNA2 */
1726 div_ant_conf.main_lna_conf =
1727 ATH_ANT_DIV_COMB_LNA1;
1728 div_ant_conf.alt_lna_conf =
1729 ATH_ANT_DIV_COMB_LNA2;
1730 }
1731 }
1732 break;
1733 default:
1734 break;
1735 }
1736 } else {
1737 if (!antcomb->alt_good) {
1738 antcomb->scan_not_start = false;
1739 /* Set alt to another LNA */
1740 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2) {
1741 div_ant_conf.main_lna_conf =
1742 ATH_ANT_DIV_COMB_LNA2;
1743 div_ant_conf.alt_lna_conf =
1744 ATH_ANT_DIV_COMB_LNA1;
1745 } else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1) {
1746 div_ant_conf.main_lna_conf =
1747 ATH_ANT_DIV_COMB_LNA1;
1748 div_ant_conf.alt_lna_conf =
1749 ATH_ANT_DIV_COMB_LNA2;
1750 }
1751 goto div_comb_done;
1752 }
1753 }
1754
1755 ath_select_ant_div_from_quick_scan(antcomb, &div_ant_conf,
1756 main_rssi_avg, alt_rssi_avg,
1757 alt_ratio);
1758
1759 antcomb->quick_scan_cnt++;
1760
1761div_comb_done:
1762 ath_ant_div_conf_fast_divbias(&div_ant_conf, antcomb, alt_ratio);
1763 ath9k_hw_antdiv_comb_conf_set(sc->sc_ah, &div_ant_conf);
1764
1765 antcomb->scan_start_time = jiffies;
1766 antcomb->total_pkt_count = 0;
1767 antcomb->main_total_rssi = 0;
1768 antcomb->alt_total_rssi = 0;
1769 antcomb->main_recv_cnt = 0;
1770 antcomb->alt_recv_cnt = 0;
1771}
1772
1773int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp) 1033int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1774{ 1034{
1775 struct ath_buf *bf; 1035 struct ath_buf *bf;
@@ -1803,7 +1063,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1803 1063
1804 do { 1064 do {
1805 /* If handling rx interrupt and flush is in progress => exit */ 1065 /* If handling rx interrupt and flush is in progress => exit */
1806 if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0)) 1066 if (test_bit(SC_OP_RXFLUSH, &sc->sc_flags) && (flush == 0))
1807 break; 1067 break;
1808 1068
1809 memset(&rs, 0, sizeof(rs)); 1069 memset(&rs, 0, sizeof(rs));
@@ -1841,13 +1101,14 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1841 else 1101 else
1842 rs.is_mybeacon = false; 1102 rs.is_mybeacon = false;
1843 1103
1104 sc->rx.num_pkts++;
1844 ath_debug_stat_rx(sc, &rs); 1105 ath_debug_stat_rx(sc, &rs);
1845 1106
1846 /* 1107 /*
1847 * If we're asked to flush receive queue, directly 1108 * If we're asked to flush receive queue, directly
1848 * chain it back at the queue without processing it. 1109 * chain it back at the queue without processing it.
1849 */ 1110 */
1850 if (sc->sc_flags & SC_OP_RXFLUSH) { 1111 if (test_bit(SC_OP_RXFLUSH, &sc->sc_flags)) {
1851 RX_STAT_INC(rx_drop_rxflush); 1112 RX_STAT_INC(rx_drop_rxflush);
1852 goto requeue_drop_frag; 1113 goto requeue_drop_frag;
1853 } 1114 }
@@ -1968,7 +1229,6 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
1968 skb_trim(skb, skb->len - 8); 1229 skb_trim(skb, skb->len - 8);
1969 1230
1970 spin_lock_irqsave(&sc->sc_pm_lock, flags); 1231 spin_lock_irqsave(&sc->sc_pm_lock, flags);
1971
1972 if ((sc->ps_flags & (PS_WAIT_FOR_BEACON | 1232 if ((sc->ps_flags & (PS_WAIT_FOR_BEACON |
1973 PS_WAIT_FOR_CAB | 1233 PS_WAIT_FOR_CAB |
1974 PS_WAIT_FOR_PSPOLL_DATA)) || 1234 PS_WAIT_FOR_PSPOLL_DATA)) ||
diff --git a/drivers/net/wireless/ath/ath9k/reg.h b/drivers/net/wireless/ath/ath9k/reg.h
index 458f81b4a7cb..75acefbd4937 100644
--- a/drivers/net/wireless/ath/ath9k/reg.h
+++ b/drivers/net/wireless/ath/ath9k/reg.h
@@ -2098,8 +2098,8 @@ enum {
2098#define AR_MCI_CONT_STATUS 0x1848 2098#define AR_MCI_CONT_STATUS 0x1848
2099#define AR_MCI_CONT_RSSI_POWER 0x000000FF 2099#define AR_MCI_CONT_RSSI_POWER 0x000000FF
2100#define AR_MCI_CONT_RSSI_POWER_S 0 2100#define AR_MCI_CONT_RSSI_POWER_S 0
2101#define AR_MCI_CONT_RRIORITY 0x0000FF00 2101#define AR_MCI_CONT_PRIORITY 0x0000FF00
2102#define AR_MCI_CONT_RRIORITY_S 8 2102#define AR_MCI_CONT_PRIORITY_S 8
2103#define AR_MCI_CONT_TXRX 0x00010000 2103#define AR_MCI_CONT_TXRX 0x00010000
2104#define AR_MCI_CONT_TXRX_S 16 2104#define AR_MCI_CONT_TXRX_S 16
2105 2105
@@ -2211,5 +2211,7 @@ enum {
2211#define AR_BTCOEX_CTRL3_CONT_INFO_TIMEOUT 0x00000fff 2211#define AR_BTCOEX_CTRL3_CONT_INFO_TIMEOUT 0x00000fff
2212#define AR_BTCOEX_CTRL3_CONT_INFO_TIMEOUT_S 0 2212#define AR_BTCOEX_CTRL3_CONT_INFO_TIMEOUT_S 0
2213 2213
2214#define AR_GLB_SWREG_DISCONT_MODE 0x2002c
2215#define AR_GLB_SWREG_DISCONT_EN_BT_WLAN 0x3
2214 2216
2215#endif 2217#endif
diff --git a/drivers/net/wireless/ath/ath9k/xmit.c b/drivers/net/wireless/ath/ath9k/xmit.c
index d59dd01d6cde..f777ddcd1172 100644
--- a/drivers/net/wireless/ath/ath9k/xmit.c
+++ b/drivers/net/wireless/ath/ath9k/xmit.c
@@ -105,19 +105,19 @@ static int ath_max_4ms_framelen[4][32] = {
105/* Aggregation logic */ 105/* Aggregation logic */
106/*********************/ 106/*********************/
107 107
108static void ath_txq_lock(struct ath_softc *sc, struct ath_txq *txq) 108void ath_txq_lock(struct ath_softc *sc, struct ath_txq *txq)
109 __acquires(&txq->axq_lock) 109 __acquires(&txq->axq_lock)
110{ 110{
111 spin_lock_bh(&txq->axq_lock); 111 spin_lock_bh(&txq->axq_lock);
112} 112}
113 113
114static void ath_txq_unlock(struct ath_softc *sc, struct ath_txq *txq) 114void ath_txq_unlock(struct ath_softc *sc, struct ath_txq *txq)
115 __releases(&txq->axq_lock) 115 __releases(&txq->axq_lock)
116{ 116{
117 spin_unlock_bh(&txq->axq_lock); 117 spin_unlock_bh(&txq->axq_lock);
118} 118}
119 119
120static void ath_txq_unlock_complete(struct ath_softc *sc, struct ath_txq *txq) 120void ath_txq_unlock_complete(struct ath_softc *sc, struct ath_txq *txq)
121 __releases(&txq->axq_lock) 121 __releases(&txq->axq_lock)
122{ 122{
123 struct sk_buff_head q; 123 struct sk_buff_head q;
@@ -1536,7 +1536,7 @@ bool ath_drain_all_txq(struct ath_softc *sc, bool retry_tx)
1536 int i; 1536 int i;
1537 u32 npend = 0; 1537 u32 npend = 0;
1538 1538
1539 if (sc->sc_flags & SC_OP_INVALID) 1539 if (test_bit(SC_OP_INVALID, &sc->sc_flags))
1540 return true; 1540 return true;
1541 1541
1542 ath9k_hw_abort_tx_dma(ah); 1542 ath9k_hw_abort_tx_dma(ah);
@@ -1994,6 +1994,7 @@ static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
1994 struct ath_common *common = ath9k_hw_common(sc->sc_ah); 1994 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1995 struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data; 1995 struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data;
1996 int q, padpos, padsize; 1996 int q, padpos, padsize;
1997 unsigned long flags;
1997 1998
1998 ath_dbg(common, XMIT, "TX complete: skb: %p\n", skb); 1999 ath_dbg(common, XMIT, "TX complete: skb: %p\n", skb);
1999 2000
@@ -2012,6 +2013,7 @@ static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
2012 skb_pull(skb, padsize); 2013 skb_pull(skb, padsize);
2013 } 2014 }
2014 2015
2016 spin_lock_irqsave(&sc->sc_pm_lock, flags);
2015 if ((sc->ps_flags & PS_WAIT_FOR_TX_ACK) && !txq->axq_depth) { 2017 if ((sc->ps_flags & PS_WAIT_FOR_TX_ACK) && !txq->axq_depth) {
2016 sc->ps_flags &= ~PS_WAIT_FOR_TX_ACK; 2018 sc->ps_flags &= ~PS_WAIT_FOR_TX_ACK;
2017 ath_dbg(common, PS, 2019 ath_dbg(common, PS,
@@ -2021,6 +2023,7 @@ static void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
2021 PS_WAIT_FOR_PSPOLL_DATA | 2023 PS_WAIT_FOR_PSPOLL_DATA |
2022 PS_WAIT_FOR_TX_ACK)); 2024 PS_WAIT_FOR_TX_ACK));
2023 } 2025 }
2026 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
2024 2027
2025 q = skb_get_queue_mapping(skb); 2028 q = skb_get_queue_mapping(skb);
2026 if (txq == sc->tx.txq_map[q]) { 2029 if (txq == sc->tx.txq_map[q]) {
@@ -2231,46 +2234,6 @@ static void ath_tx_processq(struct ath_softc *sc, struct ath_txq *txq)
2231 ath_txq_unlock_complete(sc, txq); 2234 ath_txq_unlock_complete(sc, txq);
2232} 2235}
2233 2236
2234static void ath_tx_complete_poll_work(struct work_struct *work)
2235{
2236 struct ath_softc *sc = container_of(work, struct ath_softc,
2237 tx_complete_work.work);
2238 struct ath_txq *txq;
2239 int i;
2240 bool needreset = false;
2241#ifdef CONFIG_ATH9K_DEBUGFS
2242 sc->tx_complete_poll_work_seen++;
2243#endif
2244
2245 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
2246 if (ATH_TXQ_SETUP(sc, i)) {
2247 txq = &sc->tx.txq[i];
2248 ath_txq_lock(sc, txq);
2249 if (txq->axq_depth) {
2250 if (txq->axq_tx_inprogress) {
2251 needreset = true;
2252 ath_txq_unlock(sc, txq);
2253 break;
2254 } else {
2255 txq->axq_tx_inprogress = true;
2256 }
2257 }
2258 ath_txq_unlock_complete(sc, txq);
2259 }
2260
2261 if (needreset) {
2262 ath_dbg(ath9k_hw_common(sc->sc_ah), RESET,
2263 "tx hung, resetting the chip\n");
2264 RESET_STAT_INC(sc, RESET_TYPE_TX_HANG);
2265 ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
2266 }
2267
2268 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work,
2269 msecs_to_jiffies(ATH_TX_COMPLETE_POLL_INT));
2270}
2271
2272
2273
2274void ath_tx_tasklet(struct ath_softc *sc) 2237void ath_tx_tasklet(struct ath_softc *sc)
2275{ 2238{
2276 struct ath_hw *ah = sc->sc_ah; 2239 struct ath_hw *ah = sc->sc_ah;
diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c
index cd9c9bc186d9..8b06ca56125e 100644
--- a/drivers/net/wireless/b43legacy/main.c
+++ b/drivers/net/wireless/b43legacy/main.c
@@ -1508,7 +1508,7 @@ static void b43legacy_release_firmware(struct b43legacy_wldev *dev)
1508 1508
1509static void b43legacy_print_fw_helptext(struct b43legacy_wl *wl) 1509static void b43legacy_print_fw_helptext(struct b43legacy_wl *wl)
1510{ 1510{
1511 b43legacyerr(wl, "You must go to http://linuxwireless.org/en/users/" 1511 b43legacyerr(wl, "You must go to http://wireless.kernel.org/en/users/"
1512 "Drivers/b43#devicefirmware " 1512 "Drivers/b43#devicefirmware "
1513 "and download the correct firmware (version 3).\n"); 1513 "and download the correct firmware (version 3).\n");
1514} 1514}
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/Makefile b/drivers/net/wireless/brcm80211/brcmfmac/Makefile
index abb48032753b..9d5170b6df50 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/Makefile
+++ b/drivers/net/wireless/brcm80211/brcmfmac/Makefile
@@ -34,3 +34,5 @@ brcmfmac-$(CONFIG_BRCMFMAC_SDIO) += \
34 sdio_chip.o 34 sdio_chip.o
35brcmfmac-$(CONFIG_BRCMFMAC_USB) += \ 35brcmfmac-$(CONFIG_BRCMFMAC_USB) += \
36 usb.o 36 usb.o
37brcmfmac-$(CONFIG_BRCMDBG) += \
38 dhd_dbg.o \ No newline at end of file
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd.h b/drivers/net/wireless/brcm80211/brcmfmac/dhd.h
index 9f637014486e..a11fe54f5950 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd.h
@@ -613,6 +613,9 @@ struct brcmf_pub {
613 struct work_struct multicast_work; 613 struct work_struct multicast_work;
614 u8 macvalue[ETH_ALEN]; 614 u8 macvalue[ETH_ALEN];
615 atomic_t pend_8021x_cnt; 615 atomic_t pend_8021x_cnt;
616#ifdef DEBUG
617 struct dentry *dbgfs_dir;
618#endif
616}; 619};
617 620
618struct brcmf_if_event { 621struct brcmf_if_event {
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c
new file mode 100644
index 000000000000..7f89540b56da
--- /dev/null
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c
@@ -0,0 +1,126 @@
1/*
2 * Copyright (c) 2012 Broadcom Corporation
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 ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16#include <linux/debugfs.h>
17#include <linux/if_ether.h>
18#include <linux/if.h>
19#include <linux/ieee80211.h>
20#include <linux/module.h>
21
22#include <defs.h>
23#include <brcmu_wifi.h>
24#include <brcmu_utils.h>
25#include "dhd.h"
26#include "dhd_bus.h"
27#include "dhd_dbg.h"
28
29static struct dentry *root_folder;
30
31void brcmf_debugfs_init(void)
32{
33 root_folder = debugfs_create_dir(KBUILD_MODNAME, NULL);
34 if (IS_ERR(root_folder))
35 root_folder = NULL;
36}
37
38void brcmf_debugfs_exit(void)
39{
40 if (!root_folder)
41 return;
42
43 debugfs_remove_recursive(root_folder);
44 root_folder = NULL;
45}
46
47int brcmf_debugfs_attach(struct brcmf_pub *drvr)
48{
49 if (!root_folder)
50 return -ENODEV;
51
52 drvr->dbgfs_dir = debugfs_create_dir(dev_name(drvr->dev), root_folder);
53 return PTR_RET(drvr->dbgfs_dir);
54}
55
56void brcmf_debugfs_detach(struct brcmf_pub *drvr)
57{
58 if (!IS_ERR_OR_NULL(drvr->dbgfs_dir))
59 debugfs_remove_recursive(drvr->dbgfs_dir);
60}
61
62struct dentry *brcmf_debugfs_get_devdir(struct brcmf_pub *drvr)
63{
64 return drvr->dbgfs_dir;
65}
66
67static
68ssize_t brcmf_debugfs_sdio_counter_read(struct file *f, char __user *data,
69 size_t count, loff_t *ppos)
70{
71 struct brcmf_sdio_count *sdcnt = f->private_data;
72 char buf[750];
73 int res;
74
75 /* only allow read from start */
76 if (*ppos > 0)
77 return 0;
78
79 res = scnprintf(buf, sizeof(buf),
80 "intrcount: %u\nlastintrs: %u\n"
81 "pollcnt: %u\nregfails: %u\n"
82 "tx_sderrs: %u\nfcqueued: %u\n"
83 "rxrtx: %u\nrx_toolong: %u\n"
84 "rxc_errors: %u\nrx_hdrfail: %u\n"
85 "rx_badhdr: %u\nrx_badseq: %u\n"
86 "fc_rcvd: %u\nfc_xoff: %u\n"
87 "fc_xon: %u\nrxglomfail: %u\n"
88 "rxglomframes: %u\nrxglompkts: %u\n"
89 "f2rxhdrs: %u\nf2rxdata: %u\n"
90 "f2txdata: %u\nf1regdata: %u\n"
91 "tickcnt: %u\ntx_ctlerrs: %lu\n"
92 "tx_ctlpkts: %lu\nrx_ctlerrs: %lu\n"
93 "rx_ctlpkts: %lu\nrx_readahead: %lu\n",
94 sdcnt->intrcount, sdcnt->lastintrs,
95 sdcnt->pollcnt, sdcnt->regfails,
96 sdcnt->tx_sderrs, sdcnt->fcqueued,
97 sdcnt->rxrtx, sdcnt->rx_toolong,
98 sdcnt->rxc_errors, sdcnt->rx_hdrfail,
99 sdcnt->rx_badhdr, sdcnt->rx_badseq,
100 sdcnt->fc_rcvd, sdcnt->fc_xoff,
101 sdcnt->fc_xon, sdcnt->rxglomfail,
102 sdcnt->rxglomframes, sdcnt->rxglompkts,
103 sdcnt->f2rxhdrs, sdcnt->f2rxdata,
104 sdcnt->f2txdata, sdcnt->f1regdata,
105 sdcnt->tickcnt, sdcnt->tx_ctlerrs,
106 sdcnt->tx_ctlpkts, sdcnt->rx_ctlerrs,
107 sdcnt->rx_ctlpkts, sdcnt->rx_readahead_cnt);
108
109 return simple_read_from_buffer(data, count, ppos, buf, res);
110}
111
112static const struct file_operations brcmf_debugfs_sdio_counter_ops = {
113 .owner = THIS_MODULE,
114 .open = simple_open,
115 .read = brcmf_debugfs_sdio_counter_read
116};
117
118void brcmf_debugfs_create_sdio_count(struct brcmf_pub *drvr,
119 struct brcmf_sdio_count *sdcnt)
120{
121 struct dentry *dentry = drvr->dbgfs_dir;
122
123 if (!IS_ERR_OR_NULL(dentry))
124 debugfs_create_file("counters", S_IRUGO, dentry,
125 sdcnt, &brcmf_debugfs_sdio_counter_ops);
126}
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.h b/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.h
index a2c4576cf9ff..b784920532d3 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.h
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.h
@@ -76,4 +76,63 @@ do { \
76 76
77extern int brcmf_msg_level; 77extern int brcmf_msg_level;
78 78
79/*
80 * hold counter variables used in brcmfmac sdio driver.
81 */
82struct brcmf_sdio_count {
83 uint intrcount; /* Count of device interrupt callbacks */
84 uint lastintrs; /* Count as of last watchdog timer */
85 uint pollcnt; /* Count of active polls */
86 uint regfails; /* Count of R_REG failures */
87 uint tx_sderrs; /* Count of tx attempts with sd errors */
88 uint fcqueued; /* Tx packets that got queued */
89 uint rxrtx; /* Count of rtx requests (NAK to dongle) */
90 uint rx_toolong; /* Receive frames too long to receive */
91 uint rxc_errors; /* SDIO errors when reading control frames */
92 uint rx_hdrfail; /* SDIO errors on header reads */
93 uint rx_badhdr; /* Bad received headers (roosync?) */
94 uint rx_badseq; /* Mismatched rx sequence number */
95 uint fc_rcvd; /* Number of flow-control events received */
96 uint fc_xoff; /* Number which turned on flow-control */
97 uint fc_xon; /* Number which turned off flow-control */
98 uint rxglomfail; /* Failed deglom attempts */
99 uint rxglomframes; /* Number of glom frames (superframes) */
100 uint rxglompkts; /* Number of packets from glom frames */
101 uint f2rxhdrs; /* Number of header reads */
102 uint f2rxdata; /* Number of frame data reads */
103 uint f2txdata; /* Number of f2 frame writes */
104 uint f1regdata; /* Number of f1 register accesses */
105 uint tickcnt; /* Number of watchdog been schedule */
106 ulong tx_ctlerrs; /* Err of sending ctrl frames */
107 ulong tx_ctlpkts; /* Ctrl frames sent to dongle */
108 ulong rx_ctlerrs; /* Err of processing rx ctrl frames */
109 ulong rx_ctlpkts; /* Ctrl frames processed from dongle */
110 ulong rx_readahead_cnt; /* packets where header read-ahead was used */
111};
112
113struct brcmf_pub;
114#ifdef DEBUG
115void brcmf_debugfs_init(void);
116void brcmf_debugfs_exit(void);
117int brcmf_debugfs_attach(struct brcmf_pub *drvr);
118void brcmf_debugfs_detach(struct brcmf_pub *drvr);
119struct dentry *brcmf_debugfs_get_devdir(struct brcmf_pub *drvr);
120void brcmf_debugfs_create_sdio_count(struct brcmf_pub *drvr,
121 struct brcmf_sdio_count *sdcnt);
122#else
123static inline void brcmf_debugfs_init(void)
124{
125}
126static inline void brcmf_debugfs_exit(void)
127{
128}
129static inline int brcmf_debugfs_attach(struct brcmf_pub *drvr)
130{
131 return 0;
132}
133static inline void brcmf_debugfs_detach(struct brcmf_pub *drvr)
134{
135}
136#endif
137
79#endif /* _BRCMF_DBG_H_ */ 138#endif /* _BRCMF_DBG_H_ */
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c
index 8933f9b31a9a..01cf6c03390b 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c
@@ -1007,6 +1007,9 @@ int brcmf_attach(uint bus_hdrlen, struct device *dev)
1007 drvr->bus_if->drvr = drvr; 1007 drvr->bus_if->drvr = drvr;
1008 drvr->dev = dev; 1008 drvr->dev = dev;
1009 1009
1010 /* create device debugfs folder */
1011 brcmf_debugfs_attach(drvr);
1012
1010 /* Attach and link in the protocol */ 1013 /* Attach and link in the protocol */
1011 ret = brcmf_proto_attach(drvr); 1014 ret = brcmf_proto_attach(drvr);
1012 if (ret != 0) { 1015 if (ret != 0) {
@@ -1123,6 +1126,7 @@ void brcmf_detach(struct device *dev)
1123 brcmf_proto_detach(drvr); 1126 brcmf_proto_detach(drvr);
1124 } 1127 }
1125 1128
1129 brcmf_debugfs_detach(drvr);
1126 bus_if->drvr = NULL; 1130 bus_if->drvr = NULL;
1127 kfree(drvr); 1131 kfree(drvr);
1128} 1132}
@@ -1192,6 +1196,8 @@ exit:
1192 1196
1193static void brcmf_driver_init(struct work_struct *work) 1197static void brcmf_driver_init(struct work_struct *work)
1194{ 1198{
1199 brcmf_debugfs_init();
1200
1195#ifdef CONFIG_BRCMFMAC_SDIO 1201#ifdef CONFIG_BRCMFMAC_SDIO
1196 brcmf_sdio_init(); 1202 brcmf_sdio_init();
1197#endif 1203#endif
@@ -1219,6 +1225,7 @@ static void __exit brcmfmac_module_exit(void)
1219#ifdef CONFIG_BRCMFMAC_USB 1225#ifdef CONFIG_BRCMFMAC_USB
1220 brcmf_usb_exit(); 1226 brcmf_usb_exit();
1221#endif 1227#endif
1228 brcmf_debugfs_exit();
1222} 1229}
1223 1230
1224module_init(brcmfmac_module_init); 1231module_init(brcmfmac_module_init);
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
index 1dbf2be478c8..a07fb01bc36b 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
@@ -502,12 +502,9 @@ struct brcmf_sdio {
502 bool intr; /* Use interrupts */ 502 bool intr; /* Use interrupts */
503 bool poll; /* Use polling */ 503 bool poll; /* Use polling */
504 bool ipend; /* Device interrupt is pending */ 504 bool ipend; /* Device interrupt is pending */
505 uint intrcount; /* Count of device interrupt callbacks */
506 uint lastintrs; /* Count as of last watchdog timer */
507 uint spurious; /* Count of spurious interrupts */ 505 uint spurious; /* Count of spurious interrupts */
508 uint pollrate; /* Ticks between device polls */ 506 uint pollrate; /* Ticks between device polls */
509 uint polltick; /* Tick counter */ 507 uint polltick; /* Tick counter */
510 uint pollcnt; /* Count of active polls */
511 508
512#ifdef DEBUG 509#ifdef DEBUG
513 uint console_interval; 510 uint console_interval;
@@ -515,8 +512,6 @@ struct brcmf_sdio {
515 uint console_addr; /* Console address from shared struct */ 512 uint console_addr; /* Console address from shared struct */
516#endif /* DEBUG */ 513#endif /* DEBUG */
517 514
518 uint regfails; /* Count of R_REG failures */
519
520 uint clkstate; /* State of sd and backplane clock(s) */ 515 uint clkstate; /* State of sd and backplane clock(s) */
521 bool activity; /* Activity flag for clock down */ 516 bool activity; /* Activity flag for clock down */
522 s32 idletime; /* Control for activity timeout */ 517 s32 idletime; /* Control for activity timeout */
@@ -531,33 +526,6 @@ struct brcmf_sdio {
531/* Field to decide if rx of control frames happen in rxbuf or lb-pool */ 526/* Field to decide if rx of control frames happen in rxbuf or lb-pool */
532 bool usebufpool; 527 bool usebufpool;
533 528
534 /* Some additional counters */
535 uint tx_sderrs; /* Count of tx attempts with sd errors */
536 uint fcqueued; /* Tx packets that got queued */
537 uint rxrtx; /* Count of rtx requests (NAK to dongle) */
538 uint rx_toolong; /* Receive frames too long to receive */
539 uint rxc_errors; /* SDIO errors when reading control frames */
540 uint rx_hdrfail; /* SDIO errors on header reads */
541 uint rx_badhdr; /* Bad received headers (roosync?) */
542 uint rx_badseq; /* Mismatched rx sequence number */
543 uint fc_rcvd; /* Number of flow-control events received */
544 uint fc_xoff; /* Number which turned on flow-control */
545 uint fc_xon; /* Number which turned off flow-control */
546 uint rxglomfail; /* Failed deglom attempts */
547 uint rxglomframes; /* Number of glom frames (superframes) */
548 uint rxglompkts; /* Number of packets from glom frames */
549 uint f2rxhdrs; /* Number of header reads */
550 uint f2rxdata; /* Number of frame data reads */
551 uint f2txdata; /* Number of f2 frame writes */
552 uint f1regdata; /* Number of f1 register accesses */
553 uint tickcnt; /* Number of watchdog been schedule */
554 unsigned long tx_ctlerrs; /* Err of sending ctrl frames */
555 unsigned long tx_ctlpkts; /* Ctrl frames sent to dongle */
556 unsigned long rx_ctlerrs; /* Err of processing rx ctrl frames */
557 unsigned long rx_ctlpkts; /* Ctrl frames processed from dongle */
558 unsigned long rx_readahead_cnt; /* Number of packets where header
559 * read-ahead was used. */
560
561 u8 *ctrl_frame_buf; 529 u8 *ctrl_frame_buf;
562 u32 ctrl_frame_len; 530 u32 ctrl_frame_len;
563 bool ctrl_frame_stat; 531 bool ctrl_frame_stat;
@@ -583,6 +551,7 @@ struct brcmf_sdio {
583 u32 fw_ptr; 551 u32 fw_ptr;
584 552
585 bool txoff; /* Transmit flow-controlled */ 553 bool txoff; /* Transmit flow-controlled */
554 struct brcmf_sdio_count sdcnt;
586}; 555};
587 556
588/* clkstate */ 557/* clkstate */
@@ -945,7 +914,7 @@ static u32 brcmf_sdbrcm_hostmail(struct brcmf_sdio *bus)
945 if (ret == 0) 914 if (ret == 0)
946 w_sdreg32(bus, SMB_INT_ACK, 915 w_sdreg32(bus, SMB_INT_ACK,
947 offsetof(struct sdpcmd_regs, tosbmailbox)); 916 offsetof(struct sdpcmd_regs, tosbmailbox));
948 bus->f1regdata += 2; 917 bus->sdcnt.f1regdata += 2;
949 918
950 /* Dongle recomposed rx frames, accept them again */ 919 /* Dongle recomposed rx frames, accept them again */
951 if (hmb_data & HMB_DATA_NAKHANDLED) { 920 if (hmb_data & HMB_DATA_NAKHANDLED) {
@@ -984,12 +953,12 @@ static u32 brcmf_sdbrcm_hostmail(struct brcmf_sdio *bus)
984 HMB_DATA_FCDATA_SHIFT; 953 HMB_DATA_FCDATA_SHIFT;
985 954
986 if (fcbits & ~bus->flowcontrol) 955 if (fcbits & ~bus->flowcontrol)
987 bus->fc_xoff++; 956 bus->sdcnt.fc_xoff++;
988 957
989 if (bus->flowcontrol & ~fcbits) 958 if (bus->flowcontrol & ~fcbits)
990 bus->fc_xon++; 959 bus->sdcnt.fc_xon++;
991 960
992 bus->fc_rcvd++; 961 bus->sdcnt.fc_rcvd++;
993 bus->flowcontrol = fcbits; 962 bus->flowcontrol = fcbits;
994 } 963 }
995 964
@@ -1021,7 +990,7 @@ static void brcmf_sdbrcm_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)
1021 990
1022 brcmf_sdio_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, 991 brcmf_sdio_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL,
1023 SFC_RF_TERM, &err); 992 SFC_RF_TERM, &err);
1024 bus->f1regdata++; 993 bus->sdcnt.f1regdata++;
1025 994
1026 /* Wait until the packet has been flushed (device/FIFO stable) */ 995 /* Wait until the packet has been flushed (device/FIFO stable) */
1027 for (lastrbc = retries = 0xffff; retries > 0; retries--) { 996 for (lastrbc = retries = 0xffff; retries > 0; retries--) {
@@ -1029,7 +998,7 @@ static void brcmf_sdbrcm_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)
1029 SBSDIO_FUNC1_RFRAMEBCHI, &err); 998 SBSDIO_FUNC1_RFRAMEBCHI, &err);
1030 lo = brcmf_sdio_regrb(bus->sdiodev, 999 lo = brcmf_sdio_regrb(bus->sdiodev,
1031 SBSDIO_FUNC1_RFRAMEBCLO, &err); 1000 SBSDIO_FUNC1_RFRAMEBCLO, &err);
1032 bus->f1regdata += 2; 1001 bus->sdcnt.f1regdata += 2;
1033 1002
1034 if ((hi == 0) && (lo == 0)) 1003 if ((hi == 0) && (lo == 0))
1035 break; 1004 break;
@@ -1047,11 +1016,11 @@ static void brcmf_sdbrcm_rxfail(struct brcmf_sdio *bus, bool abort, bool rtx)
1047 brcmf_dbg(INFO, "flush took %d iterations\n", 0xffff - retries); 1016 brcmf_dbg(INFO, "flush took %d iterations\n", 0xffff - retries);
1048 1017
1049 if (rtx) { 1018 if (rtx) {
1050 bus->rxrtx++; 1019 bus->sdcnt.rxrtx++;
1051 err = w_sdreg32(bus, SMB_NAK, 1020 err = w_sdreg32(bus, SMB_NAK,
1052 offsetof(struct sdpcmd_regs, tosbmailbox)); 1021 offsetof(struct sdpcmd_regs, tosbmailbox));
1053 1022
1054 bus->f1regdata++; 1023 bus->sdcnt.f1regdata++;
1055 if (err == 0) 1024 if (err == 0)
1056 bus->rxskip = true; 1025 bus->rxskip = true;
1057 } 1026 }
@@ -1243,7 +1212,7 @@ static u8 brcmf_sdbrcm_rxglom(struct brcmf_sdio *bus, u8 rxseq)
1243 dlen); 1212 dlen);
1244 errcode = -1; 1213 errcode = -1;
1245 } 1214 }
1246 bus->f2rxdata++; 1215 bus->sdcnt.f2rxdata++;
1247 1216
1248 /* On failure, kill the superframe, allow a couple retries */ 1217 /* On failure, kill the superframe, allow a couple retries */
1249 if (errcode < 0) { 1218 if (errcode < 0) {
@@ -1256,7 +1225,7 @@ static u8 brcmf_sdbrcm_rxglom(struct brcmf_sdio *bus, u8 rxseq)
1256 } else { 1225 } else {
1257 bus->glomerr = 0; 1226 bus->glomerr = 0;
1258 brcmf_sdbrcm_rxfail(bus, true, false); 1227 brcmf_sdbrcm_rxfail(bus, true, false);
1259 bus->rxglomfail++; 1228 bus->sdcnt.rxglomfail++;
1260 brcmf_sdbrcm_free_glom(bus); 1229 brcmf_sdbrcm_free_glom(bus);
1261 } 1230 }
1262 return 0; 1231 return 0;
@@ -1312,7 +1281,7 @@ static u8 brcmf_sdbrcm_rxglom(struct brcmf_sdio *bus, u8 rxseq)
1312 if (rxseq != seq) { 1281 if (rxseq != seq) {
1313 brcmf_dbg(INFO, "(superframe) rx_seq %d, expected %d\n", 1282 brcmf_dbg(INFO, "(superframe) rx_seq %d, expected %d\n",
1314 seq, rxseq); 1283 seq, rxseq);
1315 bus->rx_badseq++; 1284 bus->sdcnt.rx_badseq++;
1316 rxseq = seq; 1285 rxseq = seq;
1317 } 1286 }
1318 1287
@@ -1376,7 +1345,7 @@ static u8 brcmf_sdbrcm_rxglom(struct brcmf_sdio *bus, u8 rxseq)
1376 } else { 1345 } else {
1377 bus->glomerr = 0; 1346 bus->glomerr = 0;
1378 brcmf_sdbrcm_rxfail(bus, true, false); 1347 brcmf_sdbrcm_rxfail(bus, true, false);
1379 bus->rxglomfail++; 1348 bus->sdcnt.rxglomfail++;
1380 brcmf_sdbrcm_free_glom(bus); 1349 brcmf_sdbrcm_free_glom(bus);
1381 } 1350 }
1382 bus->nextlen = 0; 1351 bus->nextlen = 0;
@@ -1402,7 +1371,7 @@ static u8 brcmf_sdbrcm_rxglom(struct brcmf_sdio *bus, u8 rxseq)
1402 if (rxseq != seq) { 1371 if (rxseq != seq) {
1403 brcmf_dbg(GLOM, "rx_seq %d, expected %d\n", 1372 brcmf_dbg(GLOM, "rx_seq %d, expected %d\n",
1404 seq, rxseq); 1373 seq, rxseq);
1405 bus->rx_badseq++; 1374 bus->sdcnt.rx_badseq++;
1406 rxseq = seq; 1375 rxseq = seq;
1407 } 1376 }
1408 rxseq++; 1377 rxseq++;
@@ -1441,8 +1410,8 @@ static u8 brcmf_sdbrcm_rxglom(struct brcmf_sdio *bus, u8 rxseq)
1441 down(&bus->sdsem); 1410 down(&bus->sdsem);
1442 } 1411 }
1443 1412
1444 bus->rxglomframes++; 1413 bus->sdcnt.rxglomframes++;
1445 bus->rxglompkts += bus->glom.qlen; 1414 bus->sdcnt.rxglompkts += bus->glom.qlen;
1446 } 1415 }
1447 return num; 1416 return num;
1448} 1417}
@@ -1526,7 +1495,7 @@ brcmf_sdbrcm_read_control(struct brcmf_sdio *bus, u8 *hdr, uint len, uint doff)
1526 brcmf_dbg(ERROR, "%d-byte ctl frame (%d-byte ctl data) exceeds %d-byte limit\n", 1495 brcmf_dbg(ERROR, "%d-byte ctl frame (%d-byte ctl data) exceeds %d-byte limit\n",
1527 len, len - doff, bus->sdiodev->bus_if->maxctl); 1496 len, len - doff, bus->sdiodev->bus_if->maxctl);
1528 bus->sdiodev->bus_if->dstats.rx_errors++; 1497 bus->sdiodev->bus_if->dstats.rx_errors++;
1529 bus->rx_toolong++; 1498 bus->sdcnt.rx_toolong++;
1530 brcmf_sdbrcm_rxfail(bus, false, false); 1499 brcmf_sdbrcm_rxfail(bus, false, false);
1531 goto done; 1500 goto done;
1532 } 1501 }
@@ -1536,13 +1505,13 @@ brcmf_sdbrcm_read_control(struct brcmf_sdio *bus, u8 *hdr, uint len, uint doff)
1536 bus->sdiodev->sbwad, 1505 bus->sdiodev->sbwad,
1537 SDIO_FUNC_2, 1506 SDIO_FUNC_2,
1538 F2SYNC, (bus->rxctl + BRCMF_FIRSTREAD), rdlen); 1507 F2SYNC, (bus->rxctl + BRCMF_FIRSTREAD), rdlen);
1539 bus->f2rxdata++; 1508 bus->sdcnt.f2rxdata++;
1540 1509
1541 /* Control frame failures need retransmission */ 1510 /* Control frame failures need retransmission */
1542 if (sdret < 0) { 1511 if (sdret < 0) {
1543 brcmf_dbg(ERROR, "read %d control bytes failed: %d\n", 1512 brcmf_dbg(ERROR, "read %d control bytes failed: %d\n",
1544 rdlen, sdret); 1513 rdlen, sdret);
1545 bus->rxc_errors++; 1514 bus->sdcnt.rxc_errors++;
1546 brcmf_sdbrcm_rxfail(bus, true, true); 1515 brcmf_sdbrcm_rxfail(bus, true, true);
1547 goto done; 1516 goto done;
1548 } 1517 }
@@ -1589,7 +1558,7 @@ brcmf_alloc_pkt_and_read(struct brcmf_sdio *bus, u16 rdlen,
1589 /* Read the entire frame */ 1558 /* Read the entire frame */
1590 sdret = brcmf_sdcard_recv_pkt(bus->sdiodev, bus->sdiodev->sbwad, 1559 sdret = brcmf_sdcard_recv_pkt(bus->sdiodev, bus->sdiodev->sbwad,
1591 SDIO_FUNC_2, F2SYNC, *pkt); 1560 SDIO_FUNC_2, F2SYNC, *pkt);
1592 bus->f2rxdata++; 1561 bus->sdcnt.f2rxdata++;
1593 1562
1594 if (sdret < 0) { 1563 if (sdret < 0) {
1595 brcmf_dbg(ERROR, "(nextlen): read %d bytes failed: %d\n", 1564 brcmf_dbg(ERROR, "(nextlen): read %d bytes failed: %d\n",
@@ -1630,7 +1599,7 @@ brcmf_check_rxbuf(struct brcmf_sdio *bus, struct sk_buff *pkt, u8 *rxbuf,
1630 if ((u16)~(*len ^ check)) { 1599 if ((u16)~(*len ^ check)) {
1631 brcmf_dbg(ERROR, "(nextlen): HW hdr error: nextlen/len/check 0x%04x/0x%04x/0x%04x\n", 1600 brcmf_dbg(ERROR, "(nextlen): HW hdr error: nextlen/len/check 0x%04x/0x%04x/0x%04x\n",
1632 nextlen, *len, check); 1601 nextlen, *len, check);
1633 bus->rx_badhdr++; 1602 bus->sdcnt.rx_badhdr++;
1634 brcmf_sdbrcm_rxfail(bus, false, false); 1603 brcmf_sdbrcm_rxfail(bus, false, false);
1635 goto fail; 1604 goto fail;
1636 } 1605 }
@@ -1746,7 +1715,7 @@ brcmf_sdbrcm_readframes(struct brcmf_sdio *bus, uint maxframes, bool *finished)
1746 bus->nextlen = 0; 1715 bus->nextlen = 0;
1747 } 1716 }
1748 1717
1749 bus->rx_readahead_cnt++; 1718 bus->sdcnt.rx_readahead_cnt++;
1750 1719
1751 /* Handle Flow Control */ 1720 /* Handle Flow Control */
1752 fcbits = SDPCM_FCMASK_VALUE( 1721 fcbits = SDPCM_FCMASK_VALUE(
@@ -1754,12 +1723,12 @@ brcmf_sdbrcm_readframes(struct brcmf_sdio *bus, uint maxframes, bool *finished)
1754 1723
1755 if (bus->flowcontrol != fcbits) { 1724 if (bus->flowcontrol != fcbits) {
1756 if (~bus->flowcontrol & fcbits) 1725 if (~bus->flowcontrol & fcbits)
1757 bus->fc_xoff++; 1726 bus->sdcnt.fc_xoff++;
1758 1727
1759 if (bus->flowcontrol & ~fcbits) 1728 if (bus->flowcontrol & ~fcbits)
1760 bus->fc_xon++; 1729 bus->sdcnt.fc_xon++;
1761 1730
1762 bus->fc_rcvd++; 1731 bus->sdcnt.fc_rcvd++;
1763 bus->flowcontrol = fcbits; 1732 bus->flowcontrol = fcbits;
1764 } 1733 }
1765 1734
@@ -1767,7 +1736,7 @@ brcmf_sdbrcm_readframes(struct brcmf_sdio *bus, uint maxframes, bool *finished)
1767 if (rxseq != seq) { 1736 if (rxseq != seq) {
1768 brcmf_dbg(INFO, "(nextlen): rx_seq %d, expected %d\n", 1737 brcmf_dbg(INFO, "(nextlen): rx_seq %d, expected %d\n",
1769 seq, rxseq); 1738 seq, rxseq);
1770 bus->rx_badseq++; 1739 bus->sdcnt.rx_badseq++;
1771 rxseq = seq; 1740 rxseq = seq;
1772 } 1741 }
1773 1742
@@ -1814,11 +1783,11 @@ brcmf_sdbrcm_readframes(struct brcmf_sdio *bus, uint maxframes, bool *finished)
1814 sdret = brcmf_sdcard_recv_buf(bus->sdiodev, bus->sdiodev->sbwad, 1783 sdret = brcmf_sdcard_recv_buf(bus->sdiodev, bus->sdiodev->sbwad,
1815 SDIO_FUNC_2, F2SYNC, bus->rxhdr, 1784 SDIO_FUNC_2, F2SYNC, bus->rxhdr,
1816 BRCMF_FIRSTREAD); 1785 BRCMF_FIRSTREAD);
1817 bus->f2rxhdrs++; 1786 bus->sdcnt.f2rxhdrs++;
1818 1787
1819 if (sdret < 0) { 1788 if (sdret < 0) {
1820 brcmf_dbg(ERROR, "RXHEADER FAILED: %d\n", sdret); 1789 brcmf_dbg(ERROR, "RXHEADER FAILED: %d\n", sdret);
1821 bus->rx_hdrfail++; 1790 bus->sdcnt.rx_hdrfail++;
1822 brcmf_sdbrcm_rxfail(bus, true, true); 1791 brcmf_sdbrcm_rxfail(bus, true, true);
1823 continue; 1792 continue;
1824 } 1793 }
@@ -1840,7 +1809,7 @@ brcmf_sdbrcm_readframes(struct brcmf_sdio *bus, uint maxframes, bool *finished)
1840 if ((u16) ~(len ^ check)) { 1809 if ((u16) ~(len ^ check)) {
1841 brcmf_dbg(ERROR, "HW hdr err: len/check 0x%04x/0x%04x\n", 1810 brcmf_dbg(ERROR, "HW hdr err: len/check 0x%04x/0x%04x\n",
1842 len, check); 1811 len, check);
1843 bus->rx_badhdr++; 1812 bus->sdcnt.rx_badhdr++;
1844 brcmf_sdbrcm_rxfail(bus, false, false); 1813 brcmf_sdbrcm_rxfail(bus, false, false);
1845 continue; 1814 continue;
1846 } 1815 }
@@ -1861,7 +1830,7 @@ brcmf_sdbrcm_readframes(struct brcmf_sdio *bus, uint maxframes, bool *finished)
1861 if ((doff < SDPCM_HDRLEN) || (doff > len)) { 1830 if ((doff < SDPCM_HDRLEN) || (doff > len)) {
1862 brcmf_dbg(ERROR, "Bad data offset %d: HW len %d, min %d seq %d\n", 1831 brcmf_dbg(ERROR, "Bad data offset %d: HW len %d, min %d seq %d\n",
1863 doff, len, SDPCM_HDRLEN, seq); 1832 doff, len, SDPCM_HDRLEN, seq);
1864 bus->rx_badhdr++; 1833 bus->sdcnt.rx_badhdr++;
1865 brcmf_sdbrcm_rxfail(bus, false, false); 1834 brcmf_sdbrcm_rxfail(bus, false, false);
1866 continue; 1835 continue;
1867 } 1836 }
@@ -1880,19 +1849,19 @@ brcmf_sdbrcm_readframes(struct brcmf_sdio *bus, uint maxframes, bool *finished)
1880 1849
1881 if (bus->flowcontrol != fcbits) { 1850 if (bus->flowcontrol != fcbits) {
1882 if (~bus->flowcontrol & fcbits) 1851 if (~bus->flowcontrol & fcbits)
1883 bus->fc_xoff++; 1852 bus->sdcnt.fc_xoff++;
1884 1853
1885 if (bus->flowcontrol & ~fcbits) 1854 if (bus->flowcontrol & ~fcbits)
1886 bus->fc_xon++; 1855 bus->sdcnt.fc_xon++;
1887 1856
1888 bus->fc_rcvd++; 1857 bus->sdcnt.fc_rcvd++;
1889 bus->flowcontrol = fcbits; 1858 bus->flowcontrol = fcbits;
1890 } 1859 }
1891 1860
1892 /* Check and update sequence number */ 1861 /* Check and update sequence number */
1893 if (rxseq != seq) { 1862 if (rxseq != seq) {
1894 brcmf_dbg(INFO, "rx_seq %d, expected %d\n", seq, rxseq); 1863 brcmf_dbg(INFO, "rx_seq %d, expected %d\n", seq, rxseq);
1895 bus->rx_badseq++; 1864 bus->sdcnt.rx_badseq++;
1896 rxseq = seq; 1865 rxseq = seq;
1897 } 1866 }
1898 1867
@@ -1937,7 +1906,7 @@ brcmf_sdbrcm_readframes(struct brcmf_sdio *bus, uint maxframes, bool *finished)
1937 brcmf_dbg(ERROR, "too long: len %d rdlen %d\n", 1906 brcmf_dbg(ERROR, "too long: len %d rdlen %d\n",
1938 len, rdlen); 1907 len, rdlen);
1939 bus->sdiodev->bus_if->dstats.rx_errors++; 1908 bus->sdiodev->bus_if->dstats.rx_errors++;
1940 bus->rx_toolong++; 1909 bus->sdcnt.rx_toolong++;
1941 brcmf_sdbrcm_rxfail(bus, false, false); 1910 brcmf_sdbrcm_rxfail(bus, false, false);
1942 continue; 1911 continue;
1943 } 1912 }
@@ -1960,7 +1929,7 @@ brcmf_sdbrcm_readframes(struct brcmf_sdio *bus, uint maxframes, bool *finished)
1960 /* Read the remaining frame data */ 1929 /* Read the remaining frame data */
1961 sdret = brcmf_sdcard_recv_pkt(bus->sdiodev, bus->sdiodev->sbwad, 1930 sdret = brcmf_sdcard_recv_pkt(bus->sdiodev, bus->sdiodev->sbwad,
1962 SDIO_FUNC_2, F2SYNC, pkt); 1931 SDIO_FUNC_2, F2SYNC, pkt);
1963 bus->f2rxdata++; 1932 bus->sdcnt.f2rxdata++;
1964 1933
1965 if (sdret < 0) { 1934 if (sdret < 0) {
1966 brcmf_dbg(ERROR, "read %d %s bytes failed: %d\n", rdlen, 1935 brcmf_dbg(ERROR, "read %d %s bytes failed: %d\n", rdlen,
@@ -2147,18 +2116,18 @@ static int brcmf_sdbrcm_txpkt(struct brcmf_sdio *bus, struct sk_buff *pkt,
2147 2116
2148 ret = brcmf_sdcard_send_pkt(bus->sdiodev, bus->sdiodev->sbwad, 2117 ret = brcmf_sdcard_send_pkt(bus->sdiodev, bus->sdiodev->sbwad,
2149 SDIO_FUNC_2, F2SYNC, pkt); 2118 SDIO_FUNC_2, F2SYNC, pkt);
2150 bus->f2txdata++; 2119 bus->sdcnt.f2txdata++;
2151 2120
2152 if (ret < 0) { 2121 if (ret < 0) {
2153 /* On failure, abort the command and terminate the frame */ 2122 /* On failure, abort the command and terminate the frame */
2154 brcmf_dbg(INFO, "sdio error %d, abort command and terminate frame\n", 2123 brcmf_dbg(INFO, "sdio error %d, abort command and terminate frame\n",
2155 ret); 2124 ret);
2156 bus->tx_sderrs++; 2125 bus->sdcnt.tx_sderrs++;
2157 2126
2158 brcmf_sdcard_abort(bus->sdiodev, SDIO_FUNC_2); 2127 brcmf_sdcard_abort(bus->sdiodev, SDIO_FUNC_2);
2159 brcmf_sdio_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, 2128 brcmf_sdio_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL,
2160 SFC_WF_TERM, NULL); 2129 SFC_WF_TERM, NULL);
2161 bus->f1regdata++; 2130 bus->sdcnt.f1regdata++;
2162 2131
2163 for (i = 0; i < 3; i++) { 2132 for (i = 0; i < 3; i++) {
2164 u8 hi, lo; 2133 u8 hi, lo;
@@ -2166,7 +2135,7 @@ static int brcmf_sdbrcm_txpkt(struct brcmf_sdio *bus, struct sk_buff *pkt,
2166 SBSDIO_FUNC1_WFRAMEBCHI, NULL); 2135 SBSDIO_FUNC1_WFRAMEBCHI, NULL);
2167 lo = brcmf_sdio_regrb(bus->sdiodev, 2136 lo = brcmf_sdio_regrb(bus->sdiodev,
2168 SBSDIO_FUNC1_WFRAMEBCLO, NULL); 2137 SBSDIO_FUNC1_WFRAMEBCLO, NULL);
2169 bus->f1regdata += 2; 2138 bus->sdcnt.f1regdata += 2;
2170 if ((hi == 0) && (lo == 0)) 2139 if ((hi == 0) && (lo == 0))
2171 break; 2140 break;
2172 } 2141 }
@@ -2224,7 +2193,7 @@ static uint brcmf_sdbrcm_sendfromq(struct brcmf_sdio *bus, uint maxframes)
2224 ret = r_sdreg32(bus, &intstatus, 2193 ret = r_sdreg32(bus, &intstatus,
2225 offsetof(struct sdpcmd_regs, 2194 offsetof(struct sdpcmd_regs,
2226 intstatus)); 2195 intstatus));
2227 bus->f2txdata++; 2196 bus->sdcnt.f2txdata++;
2228 if (ret != 0) 2197 if (ret != 0)
2229 break; 2198 break;
2230 if (intstatus & bus->hostintmask) 2199 if (intstatus & bus->hostintmask)
@@ -2417,7 +2386,7 @@ static bool brcmf_sdbrcm_dpc(struct brcmf_sdio *bus)
2417 bus->ipend = false; 2386 bus->ipend = false;
2418 err = r_sdreg32(bus, &newstatus, 2387 err = r_sdreg32(bus, &newstatus,
2419 offsetof(struct sdpcmd_regs, intstatus)); 2388 offsetof(struct sdpcmd_regs, intstatus));
2420 bus->f1regdata++; 2389 bus->sdcnt.f1regdata++;
2421 if (err != 0) 2390 if (err != 0)
2422 newstatus = 0; 2391 newstatus = 0;
2423 newstatus &= bus->hostintmask; 2392 newstatus &= bus->hostintmask;
@@ -2426,7 +2395,7 @@ static bool brcmf_sdbrcm_dpc(struct brcmf_sdio *bus)
2426 err = w_sdreg32(bus, newstatus, 2395 err = w_sdreg32(bus, newstatus,
2427 offsetof(struct sdpcmd_regs, 2396 offsetof(struct sdpcmd_regs,
2428 intstatus)); 2397 intstatus));
2429 bus->f1regdata++; 2398 bus->sdcnt.f1regdata++;
2430 } 2399 }
2431 } 2400 }
2432 2401
@@ -2445,7 +2414,7 @@ static bool brcmf_sdbrcm_dpc(struct brcmf_sdio *bus)
2445 2414
2446 err = r_sdreg32(bus, &newstatus, 2415 err = r_sdreg32(bus, &newstatus,
2447 offsetof(struct sdpcmd_regs, intstatus)); 2416 offsetof(struct sdpcmd_regs, intstatus));
2448 bus->f1regdata += 2; 2417 bus->sdcnt.f1regdata += 2;
2449 bus->fcstate = 2418 bus->fcstate =
2450 !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE)); 2419 !!(newstatus & (I_HMB_FC_STATE | I_HMB_FC_CHANGE));
2451 intstatus |= (newstatus & bus->hostintmask); 2420 intstatus |= (newstatus & bus->hostintmask);
@@ -2510,13 +2479,13 @@ clkwait:
2510 terminate the frame */ 2479 terminate the frame */
2511 brcmf_dbg(INFO, "sdio error %d, abort command and terminate frame\n", 2480 brcmf_dbg(INFO, "sdio error %d, abort command and terminate frame\n",
2512 ret); 2481 ret);
2513 bus->tx_sderrs++; 2482 bus->sdcnt.tx_sderrs++;
2514 2483
2515 brcmf_sdcard_abort(bus->sdiodev, SDIO_FUNC_2); 2484 brcmf_sdcard_abort(bus->sdiodev, SDIO_FUNC_2);
2516 2485
2517 brcmf_sdio_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, 2486 brcmf_sdio_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL,
2518 SFC_WF_TERM, &err); 2487 SFC_WF_TERM, &err);
2519 bus->f1regdata++; 2488 bus->sdcnt.f1regdata++;
2520 2489
2521 for (i = 0; i < 3; i++) { 2490 for (i = 0; i < 3; i++) {
2522 u8 hi, lo; 2491 u8 hi, lo;
@@ -2526,7 +2495,7 @@ clkwait:
2526 lo = brcmf_sdio_regrb(bus->sdiodev, 2495 lo = brcmf_sdio_regrb(bus->sdiodev,
2527 SBSDIO_FUNC1_WFRAMEBCLO, 2496 SBSDIO_FUNC1_WFRAMEBCLO,
2528 &err); 2497 &err);
2529 bus->f1regdata += 2; 2498 bus->sdcnt.f1regdata += 2;
2530 if ((hi == 0) && (lo == 0)) 2499 if ((hi == 0) && (lo == 0))
2531 break; 2500 break;
2532 } 2501 }
@@ -2657,7 +2626,7 @@ static int brcmf_sdbrcm_bus_txdata(struct device *dev, struct sk_buff *pkt)
2657 /* Check for existing queue, current flow-control, 2626 /* Check for existing queue, current flow-control,
2658 pending event, or pending clock */ 2627 pending event, or pending clock */
2659 brcmf_dbg(TRACE, "deferring pktq len %d\n", pktq_len(&bus->txq)); 2628 brcmf_dbg(TRACE, "deferring pktq len %d\n", pktq_len(&bus->txq));
2660 bus->fcqueued++; 2629 bus->sdcnt.fcqueued++;
2661 2630
2662 /* Priority based enq */ 2631 /* Priority based enq */
2663 spin_lock_bh(&bus->txqlock); 2632 spin_lock_bh(&bus->txqlock);
@@ -2845,13 +2814,13 @@ static int brcmf_tx_frame(struct brcmf_sdio *bus, u8 *frame, u16 len)
2845 /* On failure, abort the command and terminate the frame */ 2814 /* On failure, abort the command and terminate the frame */
2846 brcmf_dbg(INFO, "sdio error %d, abort command and terminate frame\n", 2815 brcmf_dbg(INFO, "sdio error %d, abort command and terminate frame\n",
2847 ret); 2816 ret);
2848 bus->tx_sderrs++; 2817 bus->sdcnt.tx_sderrs++;
2849 2818
2850 brcmf_sdcard_abort(bus->sdiodev, SDIO_FUNC_2); 2819 brcmf_sdcard_abort(bus->sdiodev, SDIO_FUNC_2);
2851 2820
2852 brcmf_sdio_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL, 2821 brcmf_sdio_regwb(bus->sdiodev, SBSDIO_FUNC1_FRAMECTRL,
2853 SFC_WF_TERM, NULL); 2822 SFC_WF_TERM, NULL);
2854 bus->f1regdata++; 2823 bus->sdcnt.f1regdata++;
2855 2824
2856 for (i = 0; i < 3; i++) { 2825 for (i = 0; i < 3; i++) {
2857 u8 hi, lo; 2826 u8 hi, lo;
@@ -2859,7 +2828,7 @@ static int brcmf_tx_frame(struct brcmf_sdio *bus, u8 *frame, u16 len)
2859 SBSDIO_FUNC1_WFRAMEBCHI, NULL); 2828 SBSDIO_FUNC1_WFRAMEBCHI, NULL);
2860 lo = brcmf_sdio_regrb(bus->sdiodev, 2829 lo = brcmf_sdio_regrb(bus->sdiodev,
2861 SBSDIO_FUNC1_WFRAMEBCLO, NULL); 2830 SBSDIO_FUNC1_WFRAMEBCLO, NULL);
2862 bus->f1regdata += 2; 2831 bus->sdcnt.f1regdata += 2;
2863 if (hi == 0 && lo == 0) 2832 if (hi == 0 && lo == 0)
2864 break; 2833 break;
2865 } 2834 }
@@ -2976,13 +2945,26 @@ brcmf_sdbrcm_bus_txctl(struct device *dev, unsigned char *msg, uint msglen)
2976 up(&bus->sdsem); 2945 up(&bus->sdsem);
2977 2946
2978 if (ret) 2947 if (ret)
2979 bus->tx_ctlerrs++; 2948 bus->sdcnt.tx_ctlerrs++;
2980 else 2949 else
2981 bus->tx_ctlpkts++; 2950 bus->sdcnt.tx_ctlpkts++;
2982 2951
2983 return ret ? -EIO : 0; 2952 return ret ? -EIO : 0;
2984} 2953}
2985 2954
2955#ifdef DEBUG
2956static void brcmf_sdio_debugfs_create(struct brcmf_sdio *bus)
2957{
2958 struct brcmf_pub *drvr = bus->sdiodev->bus_if->drvr;
2959
2960 brcmf_debugfs_create_sdio_count(drvr, &bus->sdcnt);
2961}
2962#else
2963static void brcmf_sdio_debugfs_create(struct brcmf_sdio *bus)
2964{
2965}
2966#endif /* DEBUG */
2967
2986static int 2968static int
2987brcmf_sdbrcm_bus_rxctl(struct device *dev, unsigned char *msg, uint msglen) 2969brcmf_sdbrcm_bus_rxctl(struct device *dev, unsigned char *msg, uint msglen)
2988{ 2970{
@@ -3017,9 +2999,9 @@ brcmf_sdbrcm_bus_rxctl(struct device *dev, unsigned char *msg, uint msglen)
3017 } 2999 }
3018 3000
3019 if (rxlen) 3001 if (rxlen)
3020 bus->rx_ctlpkts++; 3002 bus->sdcnt.rx_ctlpkts++;
3021 else 3003 else
3022 bus->rx_ctlerrs++; 3004 bus->sdcnt.rx_ctlerrs++;
3023 3005
3024 return rxlen ? (int)rxlen : -ETIMEDOUT; 3006 return rxlen ? (int)rxlen : -ETIMEDOUT;
3025} 3007}
@@ -3419,7 +3401,7 @@ static int brcmf_sdbrcm_bus_init(struct device *dev)
3419 return 0; 3401 return 0;
3420 3402
3421 /* Start the watchdog timer */ 3403 /* Start the watchdog timer */
3422 bus->tickcnt = 0; 3404 bus->sdcnt.tickcnt = 0;
3423 brcmf_sdbrcm_wd_timer(bus, BRCMF_WD_POLL_MS); 3405 brcmf_sdbrcm_wd_timer(bus, BRCMF_WD_POLL_MS);
3424 3406
3425 down(&bus->sdsem); 3407 down(&bus->sdsem);
@@ -3512,7 +3494,7 @@ void brcmf_sdbrcm_isr(void *arg)
3512 return; 3494 return;
3513 } 3495 }
3514 /* Count the interrupt call */ 3496 /* Count the interrupt call */
3515 bus->intrcount++; 3497 bus->sdcnt.intrcount++;
3516 bus->ipend = true; 3498 bus->ipend = true;
3517 3499
3518 /* Shouldn't get this interrupt if we're sleeping? */ 3500 /* Shouldn't get this interrupt if we're sleeping? */
@@ -3554,7 +3536,8 @@ static bool brcmf_sdbrcm_bus_watchdog(struct brcmf_sdio *bus)
3554 bus->polltick = 0; 3536 bus->polltick = 0;
3555 3537
3556 /* Check device if no interrupts */ 3538 /* Check device if no interrupts */
3557 if (!bus->intr || (bus->intrcount == bus->lastintrs)) { 3539 if (!bus->intr ||
3540 (bus->sdcnt.intrcount == bus->sdcnt.lastintrs)) {
3558 3541
3559 if (!bus->dpc_sched) { 3542 if (!bus->dpc_sched) {
3560 u8 devpend; 3543 u8 devpend;
@@ -3569,7 +3552,7 @@ static bool brcmf_sdbrcm_bus_watchdog(struct brcmf_sdio *bus)
3569 /* If there is something, make like the ISR and 3552 /* If there is something, make like the ISR and
3570 schedule the DPC */ 3553 schedule the DPC */
3571 if (intstatus) { 3554 if (intstatus) {
3572 bus->pollcnt++; 3555 bus->sdcnt.pollcnt++;
3573 bus->ipend = true; 3556 bus->ipend = true;
3574 3557
3575 bus->dpc_sched = true; 3558 bus->dpc_sched = true;
@@ -3581,7 +3564,7 @@ static bool brcmf_sdbrcm_bus_watchdog(struct brcmf_sdio *bus)
3581 } 3564 }
3582 3565
3583 /* Update interrupt tracking */ 3566 /* Update interrupt tracking */
3584 bus->lastintrs = bus->intrcount; 3567 bus->sdcnt.lastintrs = bus->sdcnt.intrcount;
3585 } 3568 }
3586#ifdef DEBUG 3569#ifdef DEBUG
3587 /* Poll for console output periodically */ 3570 /* Poll for console output periodically */
@@ -3793,7 +3776,7 @@ brcmf_sdbrcm_watchdog_thread(void *data)
3793 if (!wait_for_completion_interruptible(&bus->watchdog_wait)) { 3776 if (!wait_for_completion_interruptible(&bus->watchdog_wait)) {
3794 brcmf_sdbrcm_bus_watchdog(bus); 3777 brcmf_sdbrcm_bus_watchdog(bus);
3795 /* Count the tick for reference */ 3778 /* Count the tick for reference */
3796 bus->tickcnt++; 3779 bus->sdcnt.tickcnt++;
3797 } else 3780 } else
3798 break; 3781 break;
3799 } 3782 }
@@ -3834,7 +3817,6 @@ static void brcmf_sdbrcm_release_dongle(struct brcmf_sdio *bus)
3834static void brcmf_sdbrcm_release(struct brcmf_sdio *bus) 3817static void brcmf_sdbrcm_release(struct brcmf_sdio *bus)
3835{ 3818{
3836 brcmf_dbg(TRACE, "Enter\n"); 3819 brcmf_dbg(TRACE, "Enter\n");
3837
3838 if (bus) { 3820 if (bus) {
3839 /* De-register interrupt handler */ 3821 /* De-register interrupt handler */
3840 brcmf_sdio_intr_unregister(bus->sdiodev); 3822 brcmf_sdio_intr_unregister(bus->sdiodev);
@@ -3938,6 +3920,7 @@ void *brcmf_sdbrcm_probe(u32 regsva, struct brcmf_sdio_dev *sdiodev)
3938 goto fail; 3920 goto fail;
3939 } 3921 }
3940 3922
3923 brcmf_sdio_debugfs_create(bus);
3941 brcmf_dbg(INFO, "completed!!\n"); 3924 brcmf_dbg(INFO, "completed!!\n");
3942 3925
3943 /* if firmware path present try to download and bring up bus */ 3926 /* if firmware path present try to download and bring up bus */
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/aiutils.c b/drivers/net/wireless/brcm80211/brcmsmac/aiutils.c
index 6d8b7213643a..3c6f9b1e8d05 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/aiutils.c
+++ b/drivers/net/wireless/brcm80211/brcmsmac/aiutils.c
@@ -631,9 +631,8 @@ uint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val)
631 cc = sii->icbus->drv_cc.core; 631 cc = sii->icbus->drv_cc.core;
632 632
633 /* mask and set */ 633 /* mask and set */
634 if (mask || val) { 634 if (mask || val)
635 bcma_maskset32(cc, regoff, ~mask, val); 635 bcma_maskset32(cc, regoff, ~mask, val);
636 }
637 636
638 /* readback */ 637 /* readback */
639 w = bcma_read32(cc, regoff); 638 w = bcma_read32(cc, regoff);
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/aiutils.h b/drivers/net/wireless/brcm80211/brcmsmac/aiutils.h
index d9f04a683bdb..d6fa9829af9a 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/aiutils.h
+++ b/drivers/net/wireless/brcm80211/brcmsmac/aiutils.h
@@ -193,7 +193,7 @@ extern void ai_detach(struct si_pub *sih);
193extern uint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val); 193extern uint ai_cc_reg(struct si_pub *sih, uint regoff, u32 mask, u32 val);
194extern void ai_clkctl_init(struct si_pub *sih); 194extern void ai_clkctl_init(struct si_pub *sih);
195extern u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih); 195extern u16 ai_clkctl_fast_pwrup_delay(struct si_pub *sih);
196extern bool ai_clkctl_cc(struct si_pub *sih, uint mode); 196extern bool ai_clkctl_cc(struct si_pub *sih, enum bcma_clkmode mode);
197extern bool ai_deviceremoved(struct si_pub *sih); 197extern bool ai_deviceremoved(struct si_pub *sih);
198 198
199extern void ai_pci_down(struct si_pub *sih); 199extern void ai_pci_down(struct si_pub *sih);
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/ampdu.c b/drivers/net/wireless/brcm80211/brcmsmac/ampdu.c
index 95b5902bc4b3..01b190a25d94 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/ampdu.c
+++ b/drivers/net/wireless/brcm80211/brcmsmac/ampdu.c
@@ -735,10 +735,8 @@ brcms_c_sendampdu(struct ampdu_info *ampdu, struct brcms_txq_info *qi,
735 * a candidate for aggregation 735 * a candidate for aggregation
736 */ 736 */
737 p = pktq_ppeek(&qi->q, prec); 737 p = pktq_ppeek(&qi->q, prec);
738 /* tx_info must be checked with current p */
739 tx_info = IEEE80211_SKB_CB(p);
740
741 if (p) { 738 if (p) {
739 tx_info = IEEE80211_SKB_CB(p);
742 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) && 740 if ((tx_info->flags & IEEE80211_TX_CTL_AMPDU) &&
743 ((u8) (p->priority) == tid)) { 741 ((u8) (p->priority) == tid)) {
744 plen = p->len + AMPDU_MAX_MPDU_OVERHEAD; 742 plen = p->len + AMPDU_MAX_MPDU_OVERHEAD;
@@ -759,6 +757,7 @@ brcms_c_sendampdu(struct ampdu_info *ampdu, struct brcms_txq_info *qi,
759 p = NULL; 757 p = NULL;
760 continue; 758 continue;
761 } 759 }
760 /* next packet fit for aggregation so dequeue */
762 p = brcmu_pktq_pdeq(&qi->q, prec); 761 p = brcmu_pktq_pdeq(&qi->q, prec);
763 } else { 762 } else {
764 p = NULL; 763 p = NULL;
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c b/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c
index 50f92a0b7c41..341e06a0d6ec 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c
+++ b/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c
@@ -721,14 +721,6 @@ static const struct ieee80211_ops brcms_ops = {
721 .flush = brcms_ops_flush, 721 .flush = brcms_ops_flush,
722}; 722};
723 723
724/*
725 * is called in brcms_bcma_probe() context, therefore no locking required.
726 */
727static int brcms_set_hint(struct brcms_info *wl, char *abbrev)
728{
729 return regulatory_hint(wl->pub->ieee_hw->wiphy, abbrev);
730}
731
732void brcms_dpc(unsigned long data) 724void brcms_dpc(unsigned long data)
733{ 725{
734 struct brcms_info *wl; 726 struct brcms_info *wl;
@@ -1068,9 +1060,9 @@ static struct brcms_info *brcms_attach(struct bcma_device *pdev)
1068 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status" 1060 wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
1069 "%d\n", __func__, err); 1061 "%d\n", __func__, err);
1070 1062
1071 if (wl->pub->srom_ccode[0] && brcms_set_hint(wl, wl->pub->srom_ccode)) 1063 if (wl->pub->srom_ccode[0] &&
1072 wiphy_err(wl->wiphy, "%s: regulatory_hint failed, status %d\n", 1064 regulatory_hint(wl->wiphy, wl->pub->srom_ccode))
1073 __func__, err); 1065 wiphy_err(wl->wiphy, "%s: regulatory hint failed\n", __func__);
1074 1066
1075 n_adapters_found++; 1067 n_adapters_found++;
1076 return wl; 1068 return wl;
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c
index 13b261517cce..366718146418 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c
+++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c
@@ -14358,7 +14358,7 @@ void wlc_phy_nphy_tkip_rifs_war(struct brcms_phy *pi, u8 rifs)
14358 14358
14359 wlc_phy_write_txmacreg_nphy(pi, holdoff, delay); 14359 wlc_phy_write_txmacreg_nphy(pi, holdoff, delay);
14360 14360
14361 if (pi && pi->sh && (pi->sh->_rifs_phy != rifs)) 14361 if (pi->sh && (pi->sh->_rifs_phy != rifs))
14362 pi->sh->_rifs_phy = rifs; 14362 pi->sh->_rifs_phy = rifs;
14363} 14363}
14364 14364
diff --git a/drivers/net/wireless/brcm80211/brcmutil/utils.c b/drivers/net/wireless/brcm80211/brcmutil/utils.c
index b45ab34cdfdc..3e6405e06ac0 100644
--- a/drivers/net/wireless/brcm80211/brcmutil/utils.c
+++ b/drivers/net/wireless/brcm80211/brcmutil/utils.c
@@ -43,6 +43,8 @@ EXPORT_SYMBOL(brcmu_pkt_buf_get_skb);
43/* Free the driver packet. Free the tag if present */ 43/* Free the driver packet. Free the tag if present */
44void brcmu_pkt_buf_free_skb(struct sk_buff *skb) 44void brcmu_pkt_buf_free_skb(struct sk_buff *skb)
45{ 45{
46 if (!skb)
47 return;
46 WARN_ON(skb->next); 48 WARN_ON(skb->next);
47 if (skb->destructor) 49 if (skb->destructor)
48 /* cannot kfree_skb() on hard IRQ (net/core/skbuff.c) if 50 /* cannot kfree_skb() on hard IRQ (net/core/skbuff.c) if
diff --git a/drivers/net/wireless/ipw2x00/ipw2200.c b/drivers/net/wireless/ipw2x00/ipw2200.c
index 0036737fe8e3..254b89223276 100644
--- a/drivers/net/wireless/ipw2x00/ipw2200.c
+++ b/drivers/net/wireless/ipw2x00/ipw2200.c
@@ -2701,6 +2701,20 @@ static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
2701 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6); 2701 memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
2702} 2702}
2703 2703
2704static void ipw_read_eeprom(struct ipw_priv *priv)
2705{
2706 int i;
2707 __le16 *eeprom = (__le16 *) priv->eeprom;
2708
2709 IPW_DEBUG_TRACE(">>\n");
2710
2711 /* read entire contents of eeprom into private buffer */
2712 for (i = 0; i < 128; i++)
2713 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i));
2714
2715 IPW_DEBUG_TRACE("<<\n");
2716}
2717
2704/* 2718/*
2705 * Either the device driver (i.e. the host) or the firmware can 2719 * Either the device driver (i.e. the host) or the firmware can
2706 * load eeprom data into the designated region in SRAM. If neither 2720 * load eeprom data into the designated region in SRAM. If neither
@@ -2712,14 +2726,9 @@ static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
2712static void ipw_eeprom_init_sram(struct ipw_priv *priv) 2726static void ipw_eeprom_init_sram(struct ipw_priv *priv)
2713{ 2727{
2714 int i; 2728 int i;
2715 __le16 *eeprom = (__le16 *) priv->eeprom;
2716 2729
2717 IPW_DEBUG_TRACE(">>\n"); 2730 IPW_DEBUG_TRACE(">>\n");
2718 2731
2719 /* read entire contents of eeprom into private buffer */
2720 for (i = 0; i < 128; i++)
2721 eeprom[i] = cpu_to_le16(eeprom_read_u16(priv, (u8) i));
2722
2723 /* 2732 /*
2724 If the data looks correct, then copy it to our private 2733 If the data looks correct, then copy it to our private
2725 copy. Otherwise let the firmware know to perform the operation 2734 copy. Otherwise let the firmware know to perform the operation
@@ -3643,8 +3652,10 @@ static int ipw_load(struct ipw_priv *priv)
3643 /* ack fw init done interrupt */ 3652 /* ack fw init done interrupt */
3644 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE); 3653 ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
3645 3654
3646 /* read eeprom data and initialize the eeprom region of sram */ 3655 /* read eeprom data */
3647 priv->eeprom_delay = 1; 3656 priv->eeprom_delay = 1;
3657 ipw_read_eeprom(priv);
3658 /* initialize the eeprom region of sram */
3648 ipw_eeprom_init_sram(priv); 3659 ipw_eeprom_init_sram(priv);
3649 3660
3650 /* enable interrupts */ 3661 /* enable interrupts */
diff --git a/drivers/net/wireless/iwlegacy/4965-mac.c b/drivers/net/wireless/iwlegacy/4965-mac.c
index 509301a5e7e2..d24eaf89ffb5 100644
--- a/drivers/net/wireless/iwlegacy/4965-mac.c
+++ b/drivers/net/wireless/iwlegacy/4965-mac.c
@@ -5724,7 +5724,8 @@ il4965_mac_setup_register(struct il_priv *il, u32 max_probe_length)
5724 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_ADHOC); 5724 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_ADHOC);
5725 5725
5726 hw->wiphy->flags |= 5726 hw->wiphy->flags |=
5727 WIPHY_FLAG_CUSTOM_REGULATORY | WIPHY_FLAG_DISABLE_BEACON_HINTS; 5727 WIPHY_FLAG_CUSTOM_REGULATORY | WIPHY_FLAG_DISABLE_BEACON_HINTS |
5728 WIPHY_FLAG_IBSS_RSN;
5728 5729
5729 /* 5730 /*
5730 * For now, disable PS by default because it affects 5731 * For now, disable PS by default because it affects
@@ -5873,6 +5874,16 @@ il4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
5873 return -EOPNOTSUPP; 5874 return -EOPNOTSUPP;
5874 } 5875 }
5875 5876
5877 /*
5878 * To support IBSS RSN, don't program group keys in IBSS, the
5879 * hardware will then not attempt to decrypt the frames.
5880 */
5881 if (vif->type == NL80211_IFTYPE_ADHOC &&
5882 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
5883 D_MAC80211("leave - ad-hoc group key\n");
5884 return -EOPNOTSUPP;
5885 }
5886
5876 sta_id = il_sta_id_or_broadcast(il, sta); 5887 sta_id = il_sta_id_or_broadcast(il, sta);
5877 if (sta_id == IL_INVALID_STATION) 5888 if (sta_id == IL_INVALID_STATION)
5878 return -EINVAL; 5889 return -EINVAL;
diff --git a/drivers/net/wireless/iwlwifi/Kconfig b/drivers/net/wireless/iwlwifi/Kconfig
index 2463c0626438..727fbb5db9da 100644
--- a/drivers/net/wireless/iwlwifi/Kconfig
+++ b/drivers/net/wireless/iwlwifi/Kconfig
@@ -6,6 +6,7 @@ config IWLWIFI
6 select LEDS_CLASS 6 select LEDS_CLASS
7 select LEDS_TRIGGERS 7 select LEDS_TRIGGERS
8 select MAC80211_LEDS 8 select MAC80211_LEDS
9 select IWLDVM
9 ---help--- 10 ---help---
10 Select to build the driver supporting the: 11 Select to build the driver supporting the:
11 12
@@ -41,6 +42,10 @@ config IWLWIFI
41 say M here and read <file:Documentation/kbuild/modules.txt>. The 42 say M here and read <file:Documentation/kbuild/modules.txt>. The
42 module will be called iwlwifi. 43 module will be called iwlwifi.
43 44
45config IWLDVM
46 tristate "Intel Wireless WiFi"
47 depends on IWLWIFI
48
44menu "Debugging Options" 49menu "Debugging Options"
45 depends on IWLWIFI 50 depends on IWLWIFI
46 51
diff --git a/drivers/net/wireless/iwlwifi/Makefile b/drivers/net/wireless/iwlwifi/Makefile
index d615eacbf050..170ec330d2a9 100644
--- a/drivers/net/wireless/iwlwifi/Makefile
+++ b/drivers/net/wireless/iwlwifi/Makefile
@@ -1,27 +1,19 @@
1# WIFI 1# common
2obj-$(CONFIG_IWLWIFI) += iwlwifi.o 2obj-$(CONFIG_IWLWIFI) += iwlwifi.o
3iwlwifi-objs := iwl-agn.o iwl-agn-rs.o iwl-mac80211.o 3iwlwifi-objs += iwl-io.o
4iwlwifi-objs += iwl-ucode.o iwl-agn-tx.o iwl-debug.o
5iwlwifi-objs += iwl-agn-lib.o iwl-agn-calib.o iwl-io.o
6iwlwifi-objs += iwl-agn-tt.o iwl-agn-sta.o iwl-agn-rx.o
7
8iwlwifi-objs += iwl-eeprom.o iwl-power.o
9iwlwifi-objs += iwl-scan.o iwl-led.o
10iwlwifi-objs += iwl-agn-rxon.o iwl-agn-devices.o
11iwlwifi-objs += iwl-5000.o
12iwlwifi-objs += iwl-6000.o
13iwlwifi-objs += iwl-1000.o
14iwlwifi-objs += iwl-2000.o
15iwlwifi-objs += iwl-pci.o
16iwlwifi-objs += iwl-drv.o 4iwlwifi-objs += iwl-drv.o
5iwlwifi-objs += iwl-debug.o
17iwlwifi-objs += iwl-notif-wait.o 6iwlwifi-objs += iwl-notif-wait.o
18iwlwifi-objs += iwl-trans-pcie.o iwl-trans-pcie-rx.o iwl-trans-pcie-tx.o 7iwlwifi-objs += iwl-eeprom-read.o iwl-eeprom-parse.o
19 8iwlwifi-objs += pcie/drv.o pcie/rx.o pcie/tx.o pcie/trans.o
9iwlwifi-objs += pcie/1000.o pcie/2000.o pcie/5000.o pcie/6000.o
20 10
21iwlwifi-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-debugfs.o
22iwlwifi-$(CONFIG_IWLWIFI_DEVICE_TRACING) += iwl-devtrace.o 11iwlwifi-$(CONFIG_IWLWIFI_DEVICE_TRACING) += iwl-devtrace.o
23iwlwifi-$(CONFIG_IWLWIFI_DEVICE_TESTMODE) += iwl-testmode.o 12iwlwifi-$(CONFIG_IWLWIFI_DEVICE_TESTMODE) += iwl-test.o
24 13
25CFLAGS_iwl-devtrace.o := -I$(src) 14ccflags-y += -D__CHECK_ENDIAN__ -I$(src)
26 15
27ccflags-y += -D__CHECK_ENDIAN__ 16
17obj-$(CONFIG_IWLDVM) += dvm/
18
19CFLAGS_iwl-devtrace.o := -I$(src)
diff --git a/drivers/net/wireless/iwlwifi/dvm/Makefile b/drivers/net/wireless/iwlwifi/dvm/Makefile
new file mode 100644
index 000000000000..5ff76b204141
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/dvm/Makefile
@@ -0,0 +1,13 @@
1# DVM
2obj-$(CONFIG_IWLDVM) += iwldvm.o
3iwldvm-objs += main.o rs.o mac80211.o ucode.o tx.o
4iwldvm-objs += lib.o calib.o tt.o sta.o rx.o
5
6iwldvm-objs += power.o
7iwldvm-objs += scan.o led.o
8iwldvm-objs += rxon.o devices.o
9
10iwldvm-$(CONFIG_IWLWIFI_DEBUGFS) += debugfs.o
11iwldvm-$(CONFIG_IWLWIFI_DEVICE_TESTMODE) += testmode.o
12
13ccflags-y += -D__CHECK_ENDIAN__ -I$(src)/../
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.h b/drivers/net/wireless/iwlwifi/dvm/agn.h
index 79c0fe06f4db..6d102413dd94 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.h
+++ b/drivers/net/wireless/iwlwifi/dvm/agn.h
@@ -63,9 +63,10 @@
63#ifndef __iwl_agn_h__ 63#ifndef __iwl_agn_h__
64#define __iwl_agn_h__ 64#define __iwl_agn_h__
65 65
66#include "iwl-dev.h"
67#include "iwl-config.h" 66#include "iwl-config.h"
68 67
68#include "dev.h"
69
69/* The first 11 queues (0-10) are used otherwise */ 70/* The first 11 queues (0-10) are used otherwise */
70#define IWLAGN_FIRST_AMPDU_QUEUE 11 71#define IWLAGN_FIRST_AMPDU_QUEUE 11
71 72
@@ -91,7 +92,6 @@ extern struct iwl_lib_ops iwl6030_lib;
91#define STATUS_CT_KILL 1 92#define STATUS_CT_KILL 1
92#define STATUS_ALIVE 2 93#define STATUS_ALIVE 2
93#define STATUS_READY 3 94#define STATUS_READY 3
94#define STATUS_GEO_CONFIGURED 4
95#define STATUS_EXIT_PENDING 5 95#define STATUS_EXIT_PENDING 5
96#define STATUS_STATISTICS 6 96#define STATUS_STATISTICS 6
97#define STATUS_SCANNING 7 97#define STATUS_SCANNING 7
@@ -101,6 +101,7 @@ extern struct iwl_lib_ops iwl6030_lib;
101#define STATUS_CHANNEL_SWITCH_PENDING 11 101#define STATUS_CHANNEL_SWITCH_PENDING 11
102#define STATUS_SCAN_COMPLETE 12 102#define STATUS_SCAN_COMPLETE 12
103#define STATUS_POWER_PMI 13 103#define STATUS_POWER_PMI 13
104#define STATUS_SCAN_ROC_EXPIRED 14
104 105
105struct iwl_ucode_capabilities; 106struct iwl_ucode_capabilities;
106 107
@@ -255,6 +256,10 @@ int __must_check iwl_scan_initiate(struct iwl_priv *priv,
255 enum iwl_scan_type scan_type, 256 enum iwl_scan_type scan_type,
256 enum ieee80211_band band); 257 enum ieee80211_band band);
257 258
259void iwl_scan_roc_expired(struct iwl_priv *priv);
260void iwl_scan_offchannel_skb(struct iwl_priv *priv);
261void iwl_scan_offchannel_skb_status(struct iwl_priv *priv);
262
258/* For faster active scanning, scan will move to the next channel if fewer than 263/* For faster active scanning, scan will move to the next channel if fewer than
259 * PLCP_QUIET_THRESH packets are heard on this channel within 264 * PLCP_QUIET_THRESH packets are heard on this channel within
260 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell 265 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
@@ -390,8 +395,10 @@ static inline __le32 iwl_hw_set_rate_n_flags(u8 rate, u32 flags)
390} 395}
391 396
392extern int iwl_alive_start(struct iwl_priv *priv); 397extern int iwl_alive_start(struct iwl_priv *priv);
393/* svtool */ 398
399/* testmode support */
394#ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE 400#ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
401
395extern int iwlagn_mac_testmode_cmd(struct ieee80211_hw *hw, void *data, 402extern int iwlagn_mac_testmode_cmd(struct ieee80211_hw *hw, void *data,
396 int len); 403 int len);
397extern int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw, 404extern int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw,
@@ -399,13 +406,16 @@ extern int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw,
399 struct netlink_callback *cb, 406 struct netlink_callback *cb,
400 void *data, int len); 407 void *data, int len);
401extern void iwl_testmode_init(struct iwl_priv *priv); 408extern void iwl_testmode_init(struct iwl_priv *priv);
402extern void iwl_testmode_cleanup(struct iwl_priv *priv); 409extern void iwl_testmode_free(struct iwl_priv *priv);
410
403#else 411#else
412
404static inline 413static inline
405int iwlagn_mac_testmode_cmd(struct ieee80211_hw *hw, void *data, int len) 414int iwlagn_mac_testmode_cmd(struct ieee80211_hw *hw, void *data, int len)
406{ 415{
407 return -ENOSYS; 416 return -ENOSYS;
408} 417}
418
409static inline 419static inline
410int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb, 420int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb,
411 struct netlink_callback *cb, 421 struct netlink_callback *cb,
@@ -413,12 +423,12 @@ int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb,
413{ 423{
414 return -ENOSYS; 424 return -ENOSYS;
415} 425}
416static inline 426
417void iwl_testmode_init(struct iwl_priv *priv) 427static inline void iwl_testmode_init(struct iwl_priv *priv)
418{ 428{
419} 429}
420static inline 430
421void iwl_testmode_cleanup(struct iwl_priv *priv) 431static inline void iwl_testmode_free(struct iwl_priv *priv)
422{ 432{
423} 433}
424#endif 434#endif
@@ -437,10 +447,8 @@ static inline void iwl_print_rx_config_cmd(struct iwl_priv *priv,
437 447
438static inline int iwl_is_ready(struct iwl_priv *priv) 448static inline int iwl_is_ready(struct iwl_priv *priv)
439{ 449{
440 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are 450 /* The adapter is 'ready' if READY EXIT_PENDING is not set */
441 * set but EXIT_PENDING is not */
442 return test_bit(STATUS_READY, &priv->status) && 451 return test_bit(STATUS_READY, &priv->status) &&
443 test_bit(STATUS_GEO_CONFIGURED, &priv->status) &&
444 !test_bit(STATUS_EXIT_PENDING, &priv->status); 452 !test_bit(STATUS_EXIT_PENDING, &priv->status);
445} 453}
446 454
@@ -518,85 +526,4 @@ static inline const char *iwl_dvm_get_cmd_string(u8 cmd)
518 return s; 526 return s;
519 return "UNKNOWN"; 527 return "UNKNOWN";
520} 528}
521
522/* API method exported for mvm hybrid state */
523void iwl_setup_deferred_work(struct iwl_priv *priv);
524int iwl_send_wimax_coex(struct iwl_priv *priv);
525int iwl_send_bt_env(struct iwl_priv *priv, u8 action, u8 type);
526void iwl_option_config(struct iwl_priv *priv);
527void iwl_set_hw_params(struct iwl_priv *priv);
528void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags);
529int iwl_init_drv(struct iwl_priv *priv);
530void iwl_uninit_drv(struct iwl_priv *priv);
531void iwl_send_bt_config(struct iwl_priv *priv);
532void iwl_rf_kill_ct_config(struct iwl_priv *priv);
533int iwl_setup_interface(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
534void iwl_teardown_interface(struct iwl_priv *priv,
535 struct ieee80211_vif *vif,
536 bool mode_change);
537int iwl_full_rxon_required(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
538void iwlagn_update_qos(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
539void iwlagn_check_needed_chains(struct iwl_priv *priv,
540 struct iwl_rxon_context *ctx,
541 struct ieee80211_bss_conf *bss_conf);
542void iwlagn_chain_noise_reset(struct iwl_priv *priv);
543int iwlagn_update_beacon(struct iwl_priv *priv,
544 struct ieee80211_vif *vif);
545void iwl_tt_handler(struct iwl_priv *priv);
546void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode);
547void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue);
548void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state);
549void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb);
550void iwl_nic_error(struct iwl_op_mode *op_mode);
551void iwl_cmd_queue_full(struct iwl_op_mode *op_mode);
552void iwl_nic_config(struct iwl_op_mode *op_mode);
553int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
554 struct ieee80211_sta *sta, bool set);
555void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
556 enum ieee80211_rssi_event rssi_event);
557int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw);
558int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw);
559void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop);
560void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue);
561void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
562 struct ieee80211_channel_switch *ch_switch);
563int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
564 struct ieee80211_vif *vif,
565 struct ieee80211_sta *sta,
566 enum ieee80211_sta_state old_state,
567 enum ieee80211_sta_state new_state);
568int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
569 struct ieee80211_vif *vif,
570 enum ieee80211_ampdu_mlme_action action,
571 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
572 u8 buf_size);
573int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
574 struct ieee80211_vif *vif,
575 struct cfg80211_scan_request *req);
576void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
577 struct ieee80211_vif *vif,
578 enum sta_notify_cmd cmd,
579 struct ieee80211_sta *sta);
580void iwlagn_configure_filter(struct ieee80211_hw *hw,
581 unsigned int changed_flags,
582 unsigned int *total_flags,
583 u64 multicast);
584int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
585 struct ieee80211_vif *vif, u16 queue,
586 const struct ieee80211_tx_queue_params *params);
587void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
588 struct ieee80211_vif *vif,
589 struct cfg80211_gtk_rekey_data *data);
590void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
591 struct ieee80211_vif *vif,
592 struct ieee80211_key_conf *keyconf,
593 struct ieee80211_sta *sta,
594 u32 iv32, u16 *phase1key);
595int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
596 struct ieee80211_vif *vif,
597 struct ieee80211_sta *sta,
598 struct ieee80211_key_conf *key);
599void iwlagn_mac_stop(struct ieee80211_hw *hw);
600void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
601int iwlagn_mac_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan);
602#endif /* __iwl_agn_h__ */ 529#endif /* __iwl_agn_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-calib.c b/drivers/net/wireless/iwlwifi/dvm/calib.c
index 95f27f1a423b..f2dd671d7dc8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-calib.c
+++ b/drivers/net/wireless/iwlwifi/dvm/calib.c
@@ -63,10 +63,11 @@
63#include <linux/slab.h> 63#include <linux/slab.h>
64#include <net/mac80211.h> 64#include <net/mac80211.h>
65 65
66#include "iwl-dev.h"
67#include "iwl-agn-calib.h"
68#include "iwl-trans.h" 66#include "iwl-trans.h"
69#include "iwl-agn.h" 67
68#include "dev.h"
69#include "calib.h"
70#include "agn.h"
70 71
71/***************************************************************************** 72/*****************************************************************************
72 * INIT calibrations framework 73 * INIT calibrations framework
@@ -832,14 +833,14 @@ static void iwl_find_disconn_antenna(struct iwl_priv *priv, u32* average_sig,
832 * To be safe, simply mask out any chains that we know 833 * To be safe, simply mask out any chains that we know
833 * are not on the device. 834 * are not on the device.
834 */ 835 */
835 active_chains &= priv->hw_params.valid_rx_ant; 836 active_chains &= priv->eeprom_data->valid_rx_ant;
836 837
837 num_tx_chains = 0; 838 num_tx_chains = 0;
838 for (i = 0; i < NUM_RX_CHAINS; i++) { 839 for (i = 0; i < NUM_RX_CHAINS; i++) {
839 /* loops on all the bits of 840 /* loops on all the bits of
840 * priv->hw_setting.valid_tx_ant */ 841 * priv->hw_setting.valid_tx_ant */
841 u8 ant_msk = (1 << i); 842 u8 ant_msk = (1 << i);
842 if (!(priv->hw_params.valid_tx_ant & ant_msk)) 843 if (!(priv->eeprom_data->valid_tx_ant & ant_msk))
843 continue; 844 continue;
844 845
845 num_tx_chains++; 846 num_tx_chains++;
@@ -853,7 +854,7 @@ static void iwl_find_disconn_antenna(struct iwl_priv *priv, u32* average_sig,
853 * connect the first valid tx chain 854 * connect the first valid tx chain
854 */ 855 */
855 first_chain = 856 first_chain =
856 find_first_chain(priv->hw_params.valid_tx_ant); 857 find_first_chain(priv->eeprom_data->valid_tx_ant);
857 data->disconn_array[first_chain] = 0; 858 data->disconn_array[first_chain] = 0;
858 active_chains |= BIT(first_chain); 859 active_chains |= BIT(first_chain);
859 IWL_DEBUG_CALIB(priv, 860 IWL_DEBUG_CALIB(priv,
@@ -863,13 +864,13 @@ static void iwl_find_disconn_antenna(struct iwl_priv *priv, u32* average_sig,
863 } 864 }
864 } 865 }
865 866
866 if (active_chains != priv->hw_params.valid_rx_ant && 867 if (active_chains != priv->eeprom_data->valid_rx_ant &&
867 active_chains != priv->chain_noise_data.active_chains) 868 active_chains != priv->chain_noise_data.active_chains)
868 IWL_DEBUG_CALIB(priv, 869 IWL_DEBUG_CALIB(priv,
869 "Detected that not all antennas are connected! " 870 "Detected that not all antennas are connected! "
870 "Connected: %#x, valid: %#x.\n", 871 "Connected: %#x, valid: %#x.\n",
871 active_chains, 872 active_chains,
872 priv->hw_params.valid_rx_ant); 873 priv->eeprom_data->valid_rx_ant);
873 874
874 /* Save for use within RXON, TX, SCAN commands, etc. */ 875 /* Save for use within RXON, TX, SCAN commands, etc. */
875 data->active_chains = active_chains; 876 data->active_chains = active_chains;
@@ -1054,7 +1055,7 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv)
1054 priv->cfg->bt_params->advanced_bt_coexist) { 1055 priv->cfg->bt_params->advanced_bt_coexist) {
1055 /* Disable disconnected antenna algorithm for advanced 1056 /* Disable disconnected antenna algorithm for advanced
1056 bt coex, assuming valid antennas are connected */ 1057 bt coex, assuming valid antennas are connected */
1057 data->active_chains = priv->hw_params.valid_rx_ant; 1058 data->active_chains = priv->eeprom_data->valid_rx_ant;
1058 for (i = 0; i < NUM_RX_CHAINS; i++) 1059 for (i = 0; i < NUM_RX_CHAINS; i++)
1059 if (!(data->active_chains & (1<<i))) 1060 if (!(data->active_chains & (1<<i)))
1060 data->disconn_array[i] = 1; 1061 data->disconn_array[i] = 1;
@@ -1083,8 +1084,9 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv)
1083 IWL_DEBUG_CALIB(priv, "min_average_noise = %d, antenna %d\n", 1084 IWL_DEBUG_CALIB(priv, "min_average_noise = %d, antenna %d\n",
1084 min_average_noise, min_average_noise_antenna_i); 1085 min_average_noise, min_average_noise_antenna_i);
1085 1086
1086 iwlagn_gain_computation(priv, average_noise, 1087 iwlagn_gain_computation(
1087 find_first_chain(priv->hw_params.valid_rx_ant)); 1088 priv, average_noise,
1089 find_first_chain(priv->eeprom_data->valid_rx_ant));
1088 1090
1089 /* Some power changes may have been made during the calibration. 1091 /* Some power changes may have been made during the calibration.
1090 * Update and commit the RXON 1092 * Update and commit the RXON
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-calib.h b/drivers/net/wireless/iwlwifi/dvm/calib.h
index dbe13787f272..2349f393cc42 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-calib.h
+++ b/drivers/net/wireless/iwlwifi/dvm/calib.h
@@ -62,8 +62,8 @@
62#ifndef __iwl_calib_h__ 62#ifndef __iwl_calib_h__
63#define __iwl_calib_h__ 63#define __iwl_calib_h__
64 64
65#include "iwl-dev.h" 65#include "dev.h"
66#include "iwl-commands.h" 66#include "commands.h"
67 67
68void iwl_chain_noise_calibration(struct iwl_priv *priv); 68void iwl_chain_noise_calibration(struct iwl_priv *priv);
69void iwl_sensitivity_calibration(struct iwl_priv *priv); 69void iwl_sensitivity_calibration(struct iwl_priv *priv);
diff --git a/drivers/net/wireless/iwlwifi/iwl-commands.h b/drivers/net/wireless/iwlwifi/dvm/commands.h
index 9af6a239b384..64811cd91635 100644
--- a/drivers/net/wireless/iwlwifi/iwl-commands.h
+++ b/drivers/net/wireless/iwlwifi/dvm/commands.h
@@ -61,9 +61,9 @@
61 * 61 *
62 *****************************************************************************/ 62 *****************************************************************************/
63/* 63/*
64 * Please use this file (iwl-commands.h) only for uCode API definitions. 64 * Please use this file (commands.h) only for uCode API definitions.
65 * Please use iwl-xxxx-hw.h for hardware-related definitions. 65 * Please use iwl-xxxx-hw.h for hardware-related definitions.
66 * Please use iwl-dev.h for driver implementation definitions. 66 * Please use dev.h for driver implementation definitions.
67 */ 67 */
68 68
69#ifndef __iwl_commands_h__ 69#ifndef __iwl_commands_h__
@@ -197,9 +197,6 @@ enum {
197 * 197 *
198 *****************************************************************************/ 198 *****************************************************************************/
199 199
200/* iwl_cmd_header flags value */
201#define IWL_CMD_FAILED_MSK 0x40
202
203/** 200/**
204 * iwlagn rate_n_flags bit fields 201 * iwlagn rate_n_flags bit fields
205 * 202 *
diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
index e7c157e5ebeb..8a2d9e643b14 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
@@ -30,16 +30,12 @@
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/debugfs.h> 32#include <linux/debugfs.h>
33
34#include <linux/ieee80211.h> 33#include <linux/ieee80211.h>
35#include <net/mac80211.h> 34#include <net/mac80211.h>
36
37
38#include "iwl-dev.h"
39#include "iwl-debug.h" 35#include "iwl-debug.h"
40#include "iwl-io.h" 36#include "iwl-io.h"
41#include "iwl-agn.h" 37#include "dev.h"
42#include "iwl-modparams.h" 38#include "agn.h"
43 39
44/* create and remove of files */ 40/* create and remove of files */
45#define DEBUGFS_ADD_FILE(name, parent, mode) do { \ 41#define DEBUGFS_ADD_FILE(name, parent, mode) do { \
@@ -307,13 +303,13 @@ static ssize_t iwl_dbgfs_nvm_read(struct file *file,
307 const u8 *ptr; 303 const u8 *ptr;
308 char *buf; 304 char *buf;
309 u16 eeprom_ver; 305 u16 eeprom_ver;
310 size_t eeprom_len = priv->cfg->base_params->eeprom_size; 306 size_t eeprom_len = priv->eeprom_blob_size;
311 buf_size = 4 * eeprom_len + 256; 307 buf_size = 4 * eeprom_len + 256;
312 308
313 if (eeprom_len % 16) 309 if (eeprom_len % 16)
314 return -ENODATA; 310 return -ENODATA;
315 311
316 ptr = priv->eeprom; 312 ptr = priv->eeprom_blob;
317 if (!ptr) 313 if (!ptr)
318 return -ENOMEM; 314 return -ENOMEM;
319 315
@@ -322,11 +318,9 @@ static ssize_t iwl_dbgfs_nvm_read(struct file *file,
322 if (!buf) 318 if (!buf)
323 return -ENOMEM; 319 return -ENOMEM;
324 320
325 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION); 321 eeprom_ver = priv->eeprom_data->eeprom_version;
326 pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, " 322 pos += scnprintf(buf + pos, buf_size - pos,
327 "version: 0x%x\n", 323 "NVM version: 0x%x\n", eeprom_ver);
328 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
329 ? "OTP" : "EEPROM", eeprom_ver);
330 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) { 324 for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
331 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs); 325 pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
332 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos, 326 hex_dump_to_buffer(ptr + ofs, 16 , 16, 2, buf + pos,
@@ -351,9 +345,6 @@ static ssize_t iwl_dbgfs_channels_read(struct file *file, char __user *user_buf,
351 char *buf; 345 char *buf;
352 ssize_t ret; 346 ssize_t ret;
353 347
354 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
355 return -EAGAIN;
356
357 buf = kzalloc(bufsz, GFP_KERNEL); 348 buf = kzalloc(bufsz, GFP_KERNEL);
358 if (!buf) 349 if (!buf)
359 return -ENOMEM; 350 return -ENOMEM;
@@ -426,8 +417,6 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
426 test_bit(STATUS_ALIVE, &priv->status)); 417 test_bit(STATUS_ALIVE, &priv->status));
427 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n", 418 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_READY:\t\t %d\n",
428 test_bit(STATUS_READY, &priv->status)); 419 test_bit(STATUS_READY, &priv->status));
429 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_GEO_CONFIGURED:\t %d\n",
430 test_bit(STATUS_GEO_CONFIGURED, &priv->status));
431 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n", 420 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_EXIT_PENDING:\t %d\n",
432 test_bit(STATUS_EXIT_PENDING, &priv->status)); 421 test_bit(STATUS_EXIT_PENDING, &priv->status));
433 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n", 422 pos += scnprintf(buf + pos, bufsz - pos, "STATUS_STATISTICS:\t %d\n",
@@ -1341,17 +1330,17 @@ static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
1341 if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) { 1330 if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
1342 pos += scnprintf(buf + pos, bufsz - pos, 1331 pos += scnprintf(buf + pos, bufsz - pos,
1343 "tx power: (1/2 dB step)\n"); 1332 "tx power: (1/2 dB step)\n");
1344 if ((priv->hw_params.valid_tx_ant & ANT_A) && 1333 if ((priv->eeprom_data->valid_tx_ant & ANT_A) &&
1345 tx->tx_power.ant_a) 1334 tx->tx_power.ant_a)
1346 pos += scnprintf(buf + pos, bufsz - pos, 1335 pos += scnprintf(buf + pos, bufsz - pos,
1347 fmt_hex, "antenna A:", 1336 fmt_hex, "antenna A:",
1348 tx->tx_power.ant_a); 1337 tx->tx_power.ant_a);
1349 if ((priv->hw_params.valid_tx_ant & ANT_B) && 1338 if ((priv->eeprom_data->valid_tx_ant & ANT_B) &&
1350 tx->tx_power.ant_b) 1339 tx->tx_power.ant_b)
1351 pos += scnprintf(buf + pos, bufsz - pos, 1340 pos += scnprintf(buf + pos, bufsz - pos,
1352 fmt_hex, "antenna B:", 1341 fmt_hex, "antenna B:",
1353 tx->tx_power.ant_b); 1342 tx->tx_power.ant_b);
1354 if ((priv->hw_params.valid_tx_ant & ANT_C) && 1343 if ((priv->eeprom_data->valid_tx_ant & ANT_C) &&
1355 tx->tx_power.ant_c) 1344 tx->tx_power.ant_c)
1356 pos += scnprintf(buf + pos, bufsz - pos, 1345 pos += scnprintf(buf + pos, bufsz - pos,
1357 fmt_hex, "antenna C:", 1346 fmt_hex, "antenna C:",
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/dvm/dev.h
index 70062379d0ec..4620b657948a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/dvm/dev.h
@@ -24,8 +24,8 @@
24 * 24 *
25 *****************************************************************************/ 25 *****************************************************************************/
26/* 26/*
27 * Please use this file (iwl-dev.h) for driver implementation definitions. 27 * Please use this file (dev.h) for driver implementation definitions.
28 * Please use iwl-commands.h for uCode API definitions. 28 * Please use commands.h for uCode API definitions.
29 */ 29 */
30 30
31#ifndef __iwl_dev_h__ 31#ifndef __iwl_dev_h__
@@ -39,17 +39,20 @@
39#include <linux/mutex.h> 39#include <linux/mutex.h>
40 40
41#include "iwl-fw.h" 41#include "iwl-fw.h"
42#include "iwl-eeprom.h" 42#include "iwl-eeprom-parse.h"
43#include "iwl-csr.h" 43#include "iwl-csr.h"
44#include "iwl-debug.h" 44#include "iwl-debug.h"
45#include "iwl-agn-hw.h" 45#include "iwl-agn-hw.h"
46#include "iwl-led.h"
47#include "iwl-power.h"
48#include "iwl-agn-rs.h"
49#include "iwl-agn-tt.h"
50#include "iwl-trans.h"
51#include "iwl-op-mode.h" 46#include "iwl-op-mode.h"
52#include "iwl-notif-wait.h" 47#include "iwl-notif-wait.h"
48#include "iwl-trans.h"
49
50#include "led.h"
51#include "power.h"
52#include "rs.h"
53#include "tt.h"
54
55#include "iwl-test.h"
53 56
54/* CT-KILL constants */ 57/* CT-KILL constants */
55#define CT_KILL_THRESHOLD_LEGACY 110 /* in Celsius */ 58#define CT_KILL_THRESHOLD_LEGACY 110 /* in Celsius */
@@ -88,33 +91,6 @@
88#define IWL_NUM_SCAN_RATES (2) 91#define IWL_NUM_SCAN_RATES (2)
89 92
90/* 93/*
91 * One for each channel, holds all channel setup data
92 * Some of the fields (e.g. eeprom and flags/max_power_avg) are redundant
93 * with one another!
94 */
95struct iwl_channel_info {
96 struct iwl_eeprom_channel eeprom; /* EEPROM regulatory limit */
97 struct iwl_eeprom_channel ht40_eeprom; /* EEPROM regulatory limit for
98 * HT40 channel */
99
100 u8 channel; /* channel number */
101 u8 flags; /* flags copied from EEPROM */
102 s8 max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
103 s8 curr_txpow; /* (dBm) regulatory/spectrum/user (not h/w) limit */
104 s8 min_power; /* always 0 */
105 s8 scan_power; /* (dBm) regul. eeprom, direct scans, any rate */
106
107 u8 group_index; /* 0-4, maps channel to group1/2/3/4/5 */
108 u8 band_index; /* 0-4, maps channel to band1/2/3/4/5 */
109 enum ieee80211_band band;
110
111 /* HT40 channel info */
112 s8 ht40_max_power_avg; /* (dBm) regul. eeprom, normal Tx, any rate */
113 u8 ht40_flags; /* flags copied from EEPROM */
114 u8 ht40_extension_channel; /* HT_IE_EXT_CHANNEL_* */
115};
116
117/*
118 * Minimum number of queues. MAX_NUM is defined in hw specific files. 94 * Minimum number of queues. MAX_NUM is defined in hw specific files.
119 * Set the minimum to accommodate 95 * Set the minimum to accommodate
120 * - 4 standard TX queues 96 * - 4 standard TX queues
@@ -153,29 +129,6 @@ union iwl_ht_rate_supp {
153 }; 129 };
154}; 130};
155 131
156#define CFG_HT_RX_AMPDU_FACTOR_8K (0x0)
157#define CFG_HT_RX_AMPDU_FACTOR_16K (0x1)
158#define CFG_HT_RX_AMPDU_FACTOR_32K (0x2)
159#define CFG_HT_RX_AMPDU_FACTOR_64K (0x3)
160#define CFG_HT_RX_AMPDU_FACTOR_DEF CFG_HT_RX_AMPDU_FACTOR_64K
161#define CFG_HT_RX_AMPDU_FACTOR_MAX CFG_HT_RX_AMPDU_FACTOR_64K
162#define CFG_HT_RX_AMPDU_FACTOR_MIN CFG_HT_RX_AMPDU_FACTOR_8K
163
164/*
165 * Maximal MPDU density for TX aggregation
166 * 4 - 2us density
167 * 5 - 4us density
168 * 6 - 8us density
169 * 7 - 16us density
170 */
171#define CFG_HT_MPDU_DENSITY_2USEC (0x4)
172#define CFG_HT_MPDU_DENSITY_4USEC (0x5)
173#define CFG_HT_MPDU_DENSITY_8USEC (0x6)
174#define CFG_HT_MPDU_DENSITY_16USEC (0x7)
175#define CFG_HT_MPDU_DENSITY_DEF CFG_HT_MPDU_DENSITY_4USEC
176#define CFG_HT_MPDU_DENSITY_MAX CFG_HT_MPDU_DENSITY_16USEC
177#define CFG_HT_MPDU_DENSITY_MIN (0x1)
178
179struct iwl_ht_config { 132struct iwl_ht_config {
180 bool single_chain_sufficient; 133 bool single_chain_sufficient;
181 enum ieee80211_smps_mode smps; /* current smps mode */ 134 enum ieee80211_smps_mode smps; /* current smps mode */
@@ -445,23 +398,6 @@ enum {
445 MEASUREMENT_ACTIVE = (1 << 1), 398 MEASUREMENT_ACTIVE = (1 << 1),
446}; 399};
447 400
448enum iwl_nvm_type {
449 NVM_DEVICE_TYPE_EEPROM = 0,
450 NVM_DEVICE_TYPE_OTP,
451};
452
453/*
454 * Two types of OTP memory access modes
455 * IWL_OTP_ACCESS_ABSOLUTE - absolute address mode,
456 * based on physical memory addressing
457 * IWL_OTP_ACCESS_RELATIVE - relative address mode,
458 * based on logical memory addressing
459 */
460enum iwl_access_mode {
461 IWL_OTP_ACCESS_ABSOLUTE,
462 IWL_OTP_ACCESS_RELATIVE,
463};
464
465/* reply_tx_statistics (for _agn devices) */ 401/* reply_tx_statistics (for _agn devices) */
466struct reply_tx_error_statistics { 402struct reply_tx_error_statistics {
467 u32 pp_delay; 403 u32 pp_delay;
@@ -632,9 +568,6 @@ enum iwl_scan_type {
632 * 568 *
633 * @tx_chains_num: Number of TX chains 569 * @tx_chains_num: Number of TX chains
634 * @rx_chains_num: Number of RX chains 570 * @rx_chains_num: Number of RX chains
635 * @valid_tx_ant: usable antennas for TX
636 * @valid_rx_ant: usable antennas for RX
637 * @ht40_channel: is 40MHz width possible: BIT(IEEE80211_BAND_XXX)
638 * @sku: sku read from EEPROM 571 * @sku: sku read from EEPROM
639 * @ct_kill_threshold: temperature threshold - in hw dependent unit 572 * @ct_kill_threshold: temperature threshold - in hw dependent unit
640 * @ct_kill_exit_threshold: when to reeable the device - in hw dependent unit 573 * @ct_kill_exit_threshold: when to reeable the device - in hw dependent unit
@@ -645,9 +578,6 @@ enum iwl_scan_type {
645struct iwl_hw_params { 578struct iwl_hw_params {
646 u8 tx_chains_num; 579 u8 tx_chains_num;
647 u8 rx_chains_num; 580 u8 rx_chains_num;
648 u8 valid_tx_ant;
649 u8 valid_rx_ant;
650 u8 ht40_channel;
651 bool use_rts_for_aggregation; 581 bool use_rts_for_aggregation;
652 u16 sku; 582 u16 sku;
653 u32 ct_kill_threshold; 583 u32 ct_kill_threshold;
@@ -664,31 +594,10 @@ struct iwl_lib_ops {
664 /* device specific configuration */ 594 /* device specific configuration */
665 void (*nic_config)(struct iwl_priv *priv); 595 void (*nic_config)(struct iwl_priv *priv);
666 596
667 /* eeprom operations (as defined in iwl-eeprom.h) */
668 struct iwl_eeprom_ops eeprom_ops;
669
670 /* temperature */ 597 /* temperature */
671 void (*temperature)(struct iwl_priv *priv); 598 void (*temperature)(struct iwl_priv *priv);
672}; 599};
673 600
674#ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
675struct iwl_testmode_trace {
676 u32 buff_size;
677 u32 total_size;
678 u32 num_chunks;
679 u8 *cpu_addr;
680 u8 *trace_addr;
681 dma_addr_t dma_addr;
682 bool trace_enabled;
683};
684struct iwl_testmode_mem {
685 u32 buff_size;
686 u32 num_chunks;
687 u8 *buff_addr;
688 bool read_in_progress;
689};
690#endif
691
692struct iwl_wipan_noa_data { 601struct iwl_wipan_noa_data {
693 struct rcu_head rcu_head; 602 struct rcu_head rcu_head;
694 u32 length; 603 u32 length;
@@ -735,8 +644,6 @@ struct iwl_priv {
735 644
736 /* ieee device used by generic ieee processing code */ 645 /* ieee device used by generic ieee processing code */
737 struct ieee80211_hw *hw; 646 struct ieee80211_hw *hw;
738 struct ieee80211_channel *ieee_channels;
739 struct ieee80211_rate *ieee_rates;
740 647
741 struct list_head calib_results; 648 struct list_head calib_results;
742 649
@@ -747,16 +654,12 @@ struct iwl_priv {
747 enum ieee80211_band band; 654 enum ieee80211_band band;
748 u8 valid_contexts; 655 u8 valid_contexts;
749 656
750 void (*pre_rx_handler)(struct iwl_priv *priv,
751 struct iwl_rx_cmd_buffer *rxb);
752 int (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv, 657 int (*rx_handlers[REPLY_MAX])(struct iwl_priv *priv,
753 struct iwl_rx_cmd_buffer *rxb, 658 struct iwl_rx_cmd_buffer *rxb,
754 struct iwl_device_cmd *cmd); 659 struct iwl_device_cmd *cmd);
755 660
756 struct iwl_notif_wait_data notif_wait; 661 struct iwl_notif_wait_data notif_wait;
757 662
758 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
759
760 /* spectrum measurement report caching */ 663 /* spectrum measurement report caching */
761 struct iwl_spectrum_notification measure_report; 664 struct iwl_spectrum_notification measure_report;
762 u8 measurement_status; 665 u8 measurement_status;
@@ -787,11 +690,6 @@ struct iwl_priv {
787 bool ucode_loaded; 690 bool ucode_loaded;
788 bool init_ucode_run; /* Don't run init uCode again */ 691 bool init_ucode_run; /* Don't run init uCode again */
789 692
790 /* we allocate array of iwl_channel_info for NIC's valid channels.
791 * Access via channel # using indirect index array */
792 struct iwl_channel_info *channel_info; /* channel info array */
793 u8 channel_count; /* # of channels */
794
795 u8 plcp_delta_threshold; 693 u8 plcp_delta_threshold;
796 694
797 /* thermal calibration */ 695 /* thermal calibration */
@@ -846,6 +744,7 @@ struct iwl_priv {
846 struct iwl_station_entry stations[IWLAGN_STATION_COUNT]; 744 struct iwl_station_entry stations[IWLAGN_STATION_COUNT];
847 unsigned long ucode_key_table; 745 unsigned long ucode_key_table;
848 struct iwl_tid_data tid_data[IWLAGN_STATION_COUNT][IWL_MAX_TID_COUNT]; 746 struct iwl_tid_data tid_data[IWLAGN_STATION_COUNT][IWL_MAX_TID_COUNT];
747 atomic_t num_aux_in_flight;
849 748
850 u8 mac80211_registered; 749 u8 mac80211_registered;
851 750
@@ -950,10 +849,8 @@ struct iwl_priv {
950 849
951 struct delayed_work scan_check; 850 struct delayed_work scan_check;
952 851
953 /* TX Power */ 852 /* TX Power settings */
954 s8 tx_power_user_lmt; 853 s8 tx_power_user_lmt;
955 s8 tx_power_device_lmt;
956 s8 tx_power_lmt_in_half_dbm; /* max tx power in half-dBm format */
957 s8 tx_power_next; 854 s8 tx_power_next;
958 855
959#ifdef CONFIG_IWLWIFI_DEBUGFS 856#ifdef CONFIG_IWLWIFI_DEBUGFS
@@ -964,9 +861,10 @@ struct iwl_priv {
964 void *wowlan_sram; 861 void *wowlan_sram;
965#endif /* CONFIG_IWLWIFI_DEBUGFS */ 862#endif /* CONFIG_IWLWIFI_DEBUGFS */
966 863
967 /* eeprom -- this is in the card's little endian byte order */ 864 struct iwl_eeprom_data *eeprom_data;
968 u8 *eeprom; 865 /* eeprom blob for debugfs/testmode */
969 enum iwl_nvm_type nvm_device_type; 866 u8 *eeprom_blob;
867 size_t eeprom_blob_size;
970 868
971 struct work_struct txpower_work; 869 struct work_struct txpower_work;
972 u32 calib_disabled; 870 u32 calib_disabled;
@@ -979,9 +877,9 @@ struct iwl_priv {
979 struct led_classdev led; 877 struct led_classdev led;
980 unsigned long blink_on, blink_off; 878 unsigned long blink_on, blink_off;
981 bool led_registered; 879 bool led_registered;
880
982#ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE 881#ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
983 struct iwl_testmode_trace testmode_trace; 882 struct iwl_test tst;
984 struct iwl_testmode_mem testmode_mem;
985 u32 tm_fixed_rate; 883 u32 tm_fixed_rate;
986#endif 884#endif
987 885
@@ -1001,8 +899,6 @@ struct iwl_priv {
1001 enum iwl_ucode_type cur_ucode; 899 enum iwl_ucode_type cur_ucode;
1002}; /*iwl_priv */ 900}; /*iwl_priv */
1003 901
1004extern struct kmem_cache *iwl_tx_cmd_pool;
1005
1006static inline struct iwl_rxon_context * 902static inline struct iwl_rxon_context *
1007iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif) 903iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif)
1008{ 904{
@@ -1036,36 +932,4 @@ static inline int iwl_is_any_associated(struct iwl_priv *priv)
1036 return false; 932 return false;
1037} 933}
1038 934
1039static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
1040{
1041 if (ch_info == NULL)
1042 return 0;
1043 return (ch_info->flags & EEPROM_CHANNEL_VALID) ? 1 : 0;
1044}
1045
1046static inline int is_channel_radar(const struct iwl_channel_info *ch_info)
1047{
1048 return (ch_info->flags & EEPROM_CHANNEL_RADAR) ? 1 : 0;
1049}
1050
1051static inline u8 is_channel_a_band(const struct iwl_channel_info *ch_info)
1052{
1053 return ch_info->band == IEEE80211_BAND_5GHZ;
1054}
1055
1056static inline u8 is_channel_bg_band(const struct iwl_channel_info *ch_info)
1057{
1058 return ch_info->band == IEEE80211_BAND_2GHZ;
1059}
1060
1061static inline int is_channel_passive(const struct iwl_channel_info *ch)
1062{
1063 return (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) ? 1 : 0;
1064}
1065
1066static inline int is_channel_ibss(const struct iwl_channel_info *ch)
1067{
1068 return ((ch->flags & EEPROM_CHANNEL_IBSS)) ? 1 : 0;
1069}
1070
1071#endif /* __iwl_dev_h__ */ 935#endif /* __iwl_dev_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-devices.c b/drivers/net/wireless/iwlwifi/dvm/devices.c
index 48533b3a0f9a..0521a6be09d2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-devices.c
+++ b/drivers/net/wireless/iwlwifi/dvm/devices.c
@@ -27,11 +27,14 @@
27/* 27/*
28 * DVM device-specific data & functions 28 * DVM device-specific data & functions
29 */ 29 */
30#include "iwl-agn.h"
31#include "iwl-dev.h"
32#include "iwl-commands.h"
33#include "iwl-io.h" 30#include "iwl-io.h"
34#include "iwl-prph.h" 31#include "iwl-prph.h"
32#include "iwl-eeprom-parse.h"
33
34#include "agn.h"
35#include "dev.h"
36#include "commands.h"
37
35 38
36/* 39/*
37 * 1000 series 40 * 1000 series
@@ -58,11 +61,6 @@ static void iwl1000_set_ct_threshold(struct iwl_priv *priv)
58/* NIC configuration for 1000 series */ 61/* NIC configuration for 1000 series */
59static void iwl1000_nic_config(struct iwl_priv *priv) 62static void iwl1000_nic_config(struct iwl_priv *priv)
60{ 63{
61 /* set CSR_HW_CONFIG_REG for uCode use */
62 iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG,
63 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
64 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
65
66 /* Setting digital SVR for 1000 card to 1.32V */ 64 /* Setting digital SVR for 1000 card to 1.32V */
67 /* locking is acquired in iwl_set_bits_mask_prph() function */ 65 /* locking is acquired in iwl_set_bits_mask_prph() function */
68 iwl_set_bits_mask_prph(priv->trans, APMG_DIGITAL_SVR_REG, 66 iwl_set_bits_mask_prph(priv->trans, APMG_DIGITAL_SVR_REG,
@@ -170,16 +168,6 @@ static const struct iwl_sensitivity_ranges iwl1000_sensitivity = {
170 168
171static void iwl1000_hw_set_hw_params(struct iwl_priv *priv) 169static void iwl1000_hw_set_hw_params(struct iwl_priv *priv)
172{ 170{
173 priv->hw_params.ht40_channel = BIT(IEEE80211_BAND_2GHZ);
174
175 priv->hw_params.tx_chains_num =
176 num_of_ant(priv->hw_params.valid_tx_ant);
177 if (priv->cfg->rx_with_siso_diversity)
178 priv->hw_params.rx_chains_num = 1;
179 else
180 priv->hw_params.rx_chains_num =
181 num_of_ant(priv->hw_params.valid_rx_ant);
182
183 iwl1000_set_ct_threshold(priv); 171 iwl1000_set_ct_threshold(priv);
184 172
185 /* Set initial sensitivity parameters */ 173 /* Set initial sensitivity parameters */
@@ -189,17 +177,6 @@ static void iwl1000_hw_set_hw_params(struct iwl_priv *priv)
189struct iwl_lib_ops iwl1000_lib = { 177struct iwl_lib_ops iwl1000_lib = {
190 .set_hw_params = iwl1000_hw_set_hw_params, 178 .set_hw_params = iwl1000_hw_set_hw_params,
191 .nic_config = iwl1000_nic_config, 179 .nic_config = iwl1000_nic_config,
192 .eeprom_ops = {
193 .regulatory_bands = {
194 EEPROM_REG_BAND_1_CHANNELS,
195 EEPROM_REG_BAND_2_CHANNELS,
196 EEPROM_REG_BAND_3_CHANNELS,
197 EEPROM_REG_BAND_4_CHANNELS,
198 EEPROM_REG_BAND_5_CHANNELS,
199 EEPROM_REG_BAND_24_HT40_CHANNELS,
200 EEPROM_REGULATORY_BAND_NO_HT40,
201 },
202 },
203 .temperature = iwlagn_temperature, 180 .temperature = iwlagn_temperature,
204}; 181};
205 182
@@ -219,8 +196,6 @@ static void iwl2000_set_ct_threshold(struct iwl_priv *priv)
219/* NIC configuration for 2000 series */ 196/* NIC configuration for 2000 series */
220static void iwl2000_nic_config(struct iwl_priv *priv) 197static void iwl2000_nic_config(struct iwl_priv *priv)
221{ 198{
222 iwl_rf_config(priv);
223
224 iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG, 199 iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG,
225 CSR_GP_DRIVER_REG_BIT_RADIO_IQ_INVER); 200 CSR_GP_DRIVER_REG_BIT_RADIO_IQ_INVER);
226} 201}
@@ -251,16 +226,6 @@ static const struct iwl_sensitivity_ranges iwl2000_sensitivity = {
251 226
252static void iwl2000_hw_set_hw_params(struct iwl_priv *priv) 227static void iwl2000_hw_set_hw_params(struct iwl_priv *priv)
253{ 228{
254 priv->hw_params.ht40_channel = BIT(IEEE80211_BAND_2GHZ);
255
256 priv->hw_params.tx_chains_num =
257 num_of_ant(priv->hw_params.valid_tx_ant);
258 if (priv->cfg->rx_with_siso_diversity)
259 priv->hw_params.rx_chains_num = 1;
260 else
261 priv->hw_params.rx_chains_num =
262 num_of_ant(priv->hw_params.valid_rx_ant);
263
264 iwl2000_set_ct_threshold(priv); 229 iwl2000_set_ct_threshold(priv);
265 230
266 /* Set initial sensitivity parameters */ 231 /* Set initial sensitivity parameters */
@@ -270,36 +235,12 @@ static void iwl2000_hw_set_hw_params(struct iwl_priv *priv)
270struct iwl_lib_ops iwl2000_lib = { 235struct iwl_lib_ops iwl2000_lib = {
271 .set_hw_params = iwl2000_hw_set_hw_params, 236 .set_hw_params = iwl2000_hw_set_hw_params,
272 .nic_config = iwl2000_nic_config, 237 .nic_config = iwl2000_nic_config,
273 .eeprom_ops = {
274 .regulatory_bands = {
275 EEPROM_REG_BAND_1_CHANNELS,
276 EEPROM_REG_BAND_2_CHANNELS,
277 EEPROM_REG_BAND_3_CHANNELS,
278 EEPROM_REG_BAND_4_CHANNELS,
279 EEPROM_REG_BAND_5_CHANNELS,
280 EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
281 EEPROM_REGULATORY_BAND_NO_HT40,
282 },
283 .enhanced_txpower = true,
284 },
285 .temperature = iwlagn_temperature, 238 .temperature = iwlagn_temperature,
286}; 239};
287 240
288struct iwl_lib_ops iwl2030_lib = { 241struct iwl_lib_ops iwl2030_lib = {
289 .set_hw_params = iwl2000_hw_set_hw_params, 242 .set_hw_params = iwl2000_hw_set_hw_params,
290 .nic_config = iwl2000_nic_config, 243 .nic_config = iwl2000_nic_config,
291 .eeprom_ops = {
292 .regulatory_bands = {
293 EEPROM_REG_BAND_1_CHANNELS,
294 EEPROM_REG_BAND_2_CHANNELS,
295 EEPROM_REG_BAND_3_CHANNELS,
296 EEPROM_REG_BAND_4_CHANNELS,
297 EEPROM_REG_BAND_5_CHANNELS,
298 EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
299 EEPROM_REGULATORY_BAND_NO_HT40,
300 },
301 .enhanced_txpower = true,
302 },
303 .temperature = iwlagn_temperature, 244 .temperature = iwlagn_temperature,
304}; 245};
305 246
@@ -311,8 +252,6 @@ struct iwl_lib_ops iwl2030_lib = {
311/* NIC configuration for 5000 series */ 252/* NIC configuration for 5000 series */
312static void iwl5000_nic_config(struct iwl_priv *priv) 253static void iwl5000_nic_config(struct iwl_priv *priv)
313{ 254{
314 iwl_rf_config(priv);
315
316 /* W/A : NIC is stuck in a reset state after Early PCIe power off 255 /* W/A : NIC is stuck in a reset state after Early PCIe power off
317 * (PCIe power is lost before PERST# is asserted), 256 * (PCIe power is lost before PERST# is asserted),
318 * causing ME FW to lose ownership and not being able to obtain it back. 257 * causing ME FW to lose ownership and not being able to obtain it back.
@@ -376,11 +315,9 @@ static struct iwl_sensitivity_ranges iwl5150_sensitivity = {
376static s32 iwl_temp_calib_to_offset(struct iwl_priv *priv) 315static s32 iwl_temp_calib_to_offset(struct iwl_priv *priv)
377{ 316{
378 u16 temperature, voltage; 317 u16 temperature, voltage;
379 __le16 *temp_calib = (__le16 *)iwl_eeprom_query_addr(priv,
380 EEPROM_KELVIN_TEMPERATURE);
381 318
382 temperature = le16_to_cpu(temp_calib[0]); 319 temperature = le16_to_cpu(priv->eeprom_data->kelvin_temperature);
383 voltage = le16_to_cpu(temp_calib[1]); 320 voltage = le16_to_cpu(priv->eeprom_data->kelvin_voltage);
384 321
385 /* offset = temp - volt / coeff */ 322 /* offset = temp - volt / coeff */
386 return (s32)(temperature - 323 return (s32)(temperature -
@@ -404,14 +341,6 @@ static void iwl5000_set_ct_threshold(struct iwl_priv *priv)
404 341
405static void iwl5000_hw_set_hw_params(struct iwl_priv *priv) 342static void iwl5000_hw_set_hw_params(struct iwl_priv *priv)
406{ 343{
407 priv->hw_params.ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
408 BIT(IEEE80211_BAND_5GHZ);
409
410 priv->hw_params.tx_chains_num =
411 num_of_ant(priv->hw_params.valid_tx_ant);
412 priv->hw_params.rx_chains_num =
413 num_of_ant(priv->hw_params.valid_rx_ant);
414
415 iwl5000_set_ct_threshold(priv); 344 iwl5000_set_ct_threshold(priv);
416 345
417 /* Set initial sensitivity parameters */ 346 /* Set initial sensitivity parameters */
@@ -420,14 +349,6 @@ static void iwl5000_hw_set_hw_params(struct iwl_priv *priv)
420 349
421static void iwl5150_hw_set_hw_params(struct iwl_priv *priv) 350static void iwl5150_hw_set_hw_params(struct iwl_priv *priv)
422{ 351{
423 priv->hw_params.ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
424 BIT(IEEE80211_BAND_5GHZ);
425
426 priv->hw_params.tx_chains_num =
427 num_of_ant(priv->hw_params.valid_tx_ant);
428 priv->hw_params.rx_chains_num =
429 num_of_ant(priv->hw_params.valid_rx_ant);
430
431 iwl5150_set_ct_threshold(priv); 352 iwl5150_set_ct_threshold(priv);
432 353
433 /* Set initial sensitivity parameters */ 354 /* Set initial sensitivity parameters */
@@ -455,7 +376,6 @@ static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
455 */ 376 */
456 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; 377 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
457 struct iwl5000_channel_switch_cmd cmd; 378 struct iwl5000_channel_switch_cmd cmd;
458 const struct iwl_channel_info *ch_info;
459 u32 switch_time_in_usec, ucode_switch_time; 379 u32 switch_time_in_usec, ucode_switch_time;
460 u16 ch; 380 u16 ch;
461 u32 tsf_low; 381 u32 tsf_low;
@@ -505,14 +425,7 @@ static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
505 } 425 }
506 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n", 426 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
507 cmd.switch_time); 427 cmd.switch_time);
508 ch_info = iwl_get_channel_info(priv, priv->band, ch); 428 cmd.expect_beacon = ch_switch->channel->flags & IEEE80211_CHAN_RADAR;
509 if (ch_info)
510 cmd.expect_beacon = is_channel_radar(ch_info);
511 else {
512 IWL_ERR(priv, "invalid channel switch from %u to %u\n",
513 ctx->active.channel, ch);
514 return -EFAULT;
515 }
516 429
517 return iwl_dvm_send_cmd(priv, &hcmd); 430 return iwl_dvm_send_cmd(priv, &hcmd);
518} 431}
@@ -521,17 +434,6 @@ struct iwl_lib_ops iwl5000_lib = {
521 .set_hw_params = iwl5000_hw_set_hw_params, 434 .set_hw_params = iwl5000_hw_set_hw_params,
522 .set_channel_switch = iwl5000_hw_channel_switch, 435 .set_channel_switch = iwl5000_hw_channel_switch,
523 .nic_config = iwl5000_nic_config, 436 .nic_config = iwl5000_nic_config,
524 .eeprom_ops = {
525 .regulatory_bands = {
526 EEPROM_REG_BAND_1_CHANNELS,
527 EEPROM_REG_BAND_2_CHANNELS,
528 EEPROM_REG_BAND_3_CHANNELS,
529 EEPROM_REG_BAND_4_CHANNELS,
530 EEPROM_REG_BAND_5_CHANNELS,
531 EEPROM_REG_BAND_24_HT40_CHANNELS,
532 EEPROM_REG_BAND_52_HT40_CHANNELS
533 },
534 },
535 .temperature = iwlagn_temperature, 437 .temperature = iwlagn_temperature,
536}; 438};
537 439
@@ -539,17 +441,6 @@ struct iwl_lib_ops iwl5150_lib = {
539 .set_hw_params = iwl5150_hw_set_hw_params, 441 .set_hw_params = iwl5150_hw_set_hw_params,
540 .set_channel_switch = iwl5000_hw_channel_switch, 442 .set_channel_switch = iwl5000_hw_channel_switch,
541 .nic_config = iwl5000_nic_config, 443 .nic_config = iwl5000_nic_config,
542 .eeprom_ops = {
543 .regulatory_bands = {
544 EEPROM_REG_BAND_1_CHANNELS,
545 EEPROM_REG_BAND_2_CHANNELS,
546 EEPROM_REG_BAND_3_CHANNELS,
547 EEPROM_REG_BAND_4_CHANNELS,
548 EEPROM_REG_BAND_5_CHANNELS,
549 EEPROM_REG_BAND_24_HT40_CHANNELS,
550 EEPROM_REG_BAND_52_HT40_CHANNELS
551 },
552 },
553 .temperature = iwl5150_temperature, 444 .temperature = iwl5150_temperature,
554}; 445};
555 446
@@ -570,8 +461,6 @@ static void iwl6000_set_ct_threshold(struct iwl_priv *priv)
570/* NIC configuration for 6000 series */ 461/* NIC configuration for 6000 series */
571static void iwl6000_nic_config(struct iwl_priv *priv) 462static void iwl6000_nic_config(struct iwl_priv *priv)
572{ 463{
573 iwl_rf_config(priv);
574
575 switch (priv->cfg->device_family) { 464 switch (priv->cfg->device_family) {
576 case IWL_DEVICE_FAMILY_6005: 465 case IWL_DEVICE_FAMILY_6005:
577 case IWL_DEVICE_FAMILY_6030: 466 case IWL_DEVICE_FAMILY_6030:
@@ -584,13 +473,13 @@ static void iwl6000_nic_config(struct iwl_priv *priv)
584 break; 473 break;
585 case IWL_DEVICE_FAMILY_6050: 474 case IWL_DEVICE_FAMILY_6050:
586 /* Indicate calibration version to uCode. */ 475 /* Indicate calibration version to uCode. */
587 if (iwl_eeprom_calib_version(priv) >= 6) 476 if (priv->eeprom_data->calib_version >= 6)
588 iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG, 477 iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG,
589 CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6); 478 CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6);
590 break; 479 break;
591 case IWL_DEVICE_FAMILY_6150: 480 case IWL_DEVICE_FAMILY_6150:
592 /* Indicate calibration version to uCode. */ 481 /* Indicate calibration version to uCode. */
593 if (iwl_eeprom_calib_version(priv) >= 6) 482 if (priv->eeprom_data->calib_version >= 6)
594 iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG, 483 iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG,
595 CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6); 484 CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6);
596 iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG, 485 iwl_set_bit(priv->trans, CSR_GP_DRIVER_REG,
@@ -627,17 +516,6 @@ static const struct iwl_sensitivity_ranges iwl6000_sensitivity = {
627 516
628static void iwl6000_hw_set_hw_params(struct iwl_priv *priv) 517static void iwl6000_hw_set_hw_params(struct iwl_priv *priv)
629{ 518{
630 priv->hw_params.ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
631 BIT(IEEE80211_BAND_5GHZ);
632
633 priv->hw_params.tx_chains_num =
634 num_of_ant(priv->hw_params.valid_tx_ant);
635 if (priv->cfg->rx_with_siso_diversity)
636 priv->hw_params.rx_chains_num = 1;
637 else
638 priv->hw_params.rx_chains_num =
639 num_of_ant(priv->hw_params.valid_rx_ant);
640
641 iwl6000_set_ct_threshold(priv); 519 iwl6000_set_ct_threshold(priv);
642 520
643 /* Set initial sensitivity parameters */ 521 /* Set initial sensitivity parameters */
@@ -654,7 +532,6 @@ static int iwl6000_hw_channel_switch(struct iwl_priv *priv,
654 */ 532 */
655 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; 533 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
656 struct iwl6000_channel_switch_cmd cmd; 534 struct iwl6000_channel_switch_cmd cmd;
657 const struct iwl_channel_info *ch_info;
658 u32 switch_time_in_usec, ucode_switch_time; 535 u32 switch_time_in_usec, ucode_switch_time;
659 u16 ch; 536 u16 ch;
660 u32 tsf_low; 537 u32 tsf_low;
@@ -704,14 +581,7 @@ static int iwl6000_hw_channel_switch(struct iwl_priv *priv,
704 } 581 }
705 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n", 582 IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
706 cmd.switch_time); 583 cmd.switch_time);
707 ch_info = iwl_get_channel_info(priv, priv->band, ch); 584 cmd.expect_beacon = ch_switch->channel->flags & IEEE80211_CHAN_RADAR;
708 if (ch_info)
709 cmd.expect_beacon = is_channel_radar(ch_info);
710 else {
711 IWL_ERR(priv, "invalid channel switch from %u to %u\n",
712 ctx->active.channel, ch);
713 return -EFAULT;
714 }
715 585
716 return iwl_dvm_send_cmd(priv, &hcmd); 586 return iwl_dvm_send_cmd(priv, &hcmd);
717} 587}
@@ -720,18 +590,6 @@ struct iwl_lib_ops iwl6000_lib = {
720 .set_hw_params = iwl6000_hw_set_hw_params, 590 .set_hw_params = iwl6000_hw_set_hw_params,
721 .set_channel_switch = iwl6000_hw_channel_switch, 591 .set_channel_switch = iwl6000_hw_channel_switch,
722 .nic_config = iwl6000_nic_config, 592 .nic_config = iwl6000_nic_config,
723 .eeprom_ops = {
724 .regulatory_bands = {
725 EEPROM_REG_BAND_1_CHANNELS,
726 EEPROM_REG_BAND_2_CHANNELS,
727 EEPROM_REG_BAND_3_CHANNELS,
728 EEPROM_REG_BAND_4_CHANNELS,
729 EEPROM_REG_BAND_5_CHANNELS,
730 EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
731 EEPROM_REG_BAND_52_HT40_CHANNELS
732 },
733 .enhanced_txpower = true,
734 },
735 .temperature = iwlagn_temperature, 593 .temperature = iwlagn_temperature,
736}; 594};
737 595
@@ -739,17 +597,5 @@ struct iwl_lib_ops iwl6030_lib = {
739 .set_hw_params = iwl6000_hw_set_hw_params, 597 .set_hw_params = iwl6000_hw_set_hw_params,
740 .set_channel_switch = iwl6000_hw_channel_switch, 598 .set_channel_switch = iwl6000_hw_channel_switch,
741 .nic_config = iwl6000_nic_config, 599 .nic_config = iwl6000_nic_config,
742 .eeprom_ops = {
743 .regulatory_bands = {
744 EEPROM_REG_BAND_1_CHANNELS,
745 EEPROM_REG_BAND_2_CHANNELS,
746 EEPROM_REG_BAND_3_CHANNELS,
747 EEPROM_REG_BAND_4_CHANNELS,
748 EEPROM_REG_BAND_5_CHANNELS,
749 EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
750 EEPROM_REG_BAND_52_HT40_CHANNELS
751 },
752 .enhanced_txpower = true,
753 },
754 .temperature = iwlagn_temperature, 600 .temperature = iwlagn_temperature,
755}; 601};
diff --git a/drivers/net/wireless/iwlwifi/iwl-led.c b/drivers/net/wireless/iwlwifi/dvm/led.c
index 47000419f916..bf479f709091 100644
--- a/drivers/net/wireless/iwlwifi/iwl-led.c
+++ b/drivers/net/wireless/iwlwifi/dvm/led.c
@@ -34,12 +34,11 @@
34#include <net/mac80211.h> 34#include <net/mac80211.h>
35#include <linux/etherdevice.h> 35#include <linux/etherdevice.h>
36#include <asm/unaligned.h> 36#include <asm/unaligned.h>
37
38#include "iwl-dev.h"
39#include "iwl-agn.h"
40#include "iwl-io.h" 37#include "iwl-io.h"
41#include "iwl-trans.h" 38#include "iwl-trans.h"
42#include "iwl-modparams.h" 39#include "iwl-modparams.h"
40#include "dev.h"
41#include "agn.h"
43 42
44/* Throughput OFF time(ms) ON time (ms) 43/* Throughput OFF time(ms) ON time (ms)
45 * >300 25 25 44 * >300 25 25
diff --git a/drivers/net/wireless/iwlwifi/iwl-led.h b/drivers/net/wireless/iwlwifi/dvm/led.h
index b02a853103d3..b02a853103d3 100644
--- a/drivers/net/wireless/iwlwifi/iwl-led.h
+++ b/drivers/net/wireless/iwlwifi/dvm/led.h
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c b/drivers/net/wireless/iwlwifi/dvm/lib.c
index e55ec6c8a920..76f259283c3a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
+++ b/drivers/net/wireless/iwlwifi/dvm/lib.c
@@ -33,13 +33,14 @@
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <net/mac80211.h> 34#include <net/mac80211.h>
35 35
36#include "iwl-dev.h"
37#include "iwl-io.h" 36#include "iwl-io.h"
38#include "iwl-agn-hw.h" 37#include "iwl-agn-hw.h"
39#include "iwl-agn.h"
40#include "iwl-trans.h" 38#include "iwl-trans.h"
41#include "iwl-modparams.h" 39#include "iwl-modparams.h"
42 40
41#include "dev.h"
42#include "agn.h"
43
43int iwlagn_hw_valid_rtc_data_addr(u32 addr) 44int iwlagn_hw_valid_rtc_data_addr(u32 addr)
44{ 45{
45 return (addr >= IWLAGN_RTC_DATA_LOWER_BOUND) && 46 return (addr >= IWLAGN_RTC_DATA_LOWER_BOUND) &&
@@ -58,8 +59,7 @@ int iwlagn_send_tx_power(struct iwl_priv *priv)
58 /* half dBm need to multiply */ 59 /* half dBm need to multiply */
59 tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt); 60 tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
60 61
61 if (priv->tx_power_lmt_in_half_dbm && 62 if (tx_power_cmd.global_lmt > priv->eeprom_data->max_tx_pwr_half_dbm) {
62 priv->tx_power_lmt_in_half_dbm < tx_power_cmd.global_lmt) {
63 /* 63 /*
64 * For the newer devices which using enhanced/extend tx power 64 * For the newer devices which using enhanced/extend tx power
65 * table in EEPROM, the format is in half dBm. driver need to 65 * table in EEPROM, the format is in half dBm. driver need to
@@ -71,7 +71,8 @@ int iwlagn_send_tx_power(struct iwl_priv *priv)
71 * "tx_power_user_lmt" is higher than EEPROM value (in 71 * "tx_power_user_lmt" is higher than EEPROM value (in
72 * half-dBm format), lower the tx power based on EEPROM 72 * half-dBm format), lower the tx power based on EEPROM
73 */ 73 */
74 tx_power_cmd.global_lmt = priv->tx_power_lmt_in_half_dbm; 74 tx_power_cmd.global_lmt =
75 priv->eeprom_data->max_tx_pwr_half_dbm;
75 } 76 }
76 tx_power_cmd.flags = IWLAGN_TX_POWER_NO_CLOSED; 77 tx_power_cmd.flags = IWLAGN_TX_POWER_NO_CLOSED;
77 tx_power_cmd.srv_chan_lmt = IWLAGN_TX_POWER_AUTO; 78 tx_power_cmd.srv_chan_lmt = IWLAGN_TX_POWER_AUTO;
@@ -617,6 +618,11 @@ static bool iwlagn_fill_txpower_mode(struct iwl_priv *priv,
617 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; 618 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
618 int ave_rssi; 619 int ave_rssi;
619 620
621 if (!ctx->vif || (ctx->vif->type != NL80211_IFTYPE_STATION)) {
622 IWL_DEBUG_INFO(priv, "BSS ctx not active or not in sta mode\n");
623 return false;
624 }
625
620 ave_rssi = ieee80211_ave_rssi(ctx->vif); 626 ave_rssi = ieee80211_ave_rssi(ctx->vif);
621 if (!ave_rssi) { 627 if (!ave_rssi) {
622 /* no rssi data, no changes to reduce tx power */ 628 /* no rssi data, no changes to reduce tx power */
@@ -818,7 +824,7 @@ void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
818 if (priv->chain_noise_data.active_chains) 824 if (priv->chain_noise_data.active_chains)
819 active_chains = priv->chain_noise_data.active_chains; 825 active_chains = priv->chain_noise_data.active_chains;
820 else 826 else
821 active_chains = priv->hw_params.valid_rx_ant; 827 active_chains = priv->eeprom_data->valid_rx_ant;
822 828
823 if (priv->cfg->bt_params && 829 if (priv->cfg->bt_params &&
824 priv->cfg->bt_params->advanced_bt_coexist && 830 priv->cfg->bt_params->advanced_bt_coexist &&
@@ -1259,7 +1265,7 @@ int iwl_dvm_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
1259 * the mutex, this ensures we don't try to send two 1265 * the mutex, this ensures we don't try to send two
1260 * (or more) synchronous commands at a time. 1266 * (or more) synchronous commands at a time.
1261 */ 1267 */
1262 if (cmd->flags & CMD_SYNC) 1268 if (!(cmd->flags & CMD_ASYNC))
1263 lockdep_assert_held(&priv->mutex); 1269 lockdep_assert_held(&priv->mutex);
1264 1270
1265 if (priv->ucode_owner == IWL_OWNERSHIP_TM && 1271 if (priv->ucode_owner == IWL_OWNERSHIP_TM &&
diff --git a/drivers/net/wireless/iwlwifi/iwl-mac80211.c b/drivers/net/wireless/iwlwifi/dvm/mac80211.c
index 3ee23134c02b..9d2374862314 100644
--- a/drivers/net/wireless/iwlwifi/iwl-mac80211.c
+++ b/drivers/net/wireless/iwlwifi/dvm/mac80211.c
@@ -38,19 +38,20 @@
38#include <linux/etherdevice.h> 38#include <linux/etherdevice.h>
39#include <linux/if_arp.h> 39#include <linux/if_arp.h>
40 40
41#include <net/ieee80211_radiotap.h>
41#include <net/mac80211.h> 42#include <net/mac80211.h>
42 43
43#include <asm/div64.h> 44#include <asm/div64.h>
44 45
45#include "iwl-eeprom.h"
46#include "iwl-dev.h"
47#include "iwl-io.h" 46#include "iwl-io.h"
48#include "iwl-agn-calib.h"
49#include "iwl-agn.h"
50#include "iwl-trans.h" 47#include "iwl-trans.h"
51#include "iwl-op-mode.h" 48#include "iwl-op-mode.h"
52#include "iwl-modparams.h" 49#include "iwl-modparams.h"
53 50
51#include "dev.h"
52#include "calib.h"
53#include "agn.h"
54
54/***************************************************************************** 55/*****************************************************************************
55 * 56 *
56 * mac80211 entry point functions 57 * mac80211 entry point functions
@@ -154,6 +155,7 @@ int iwlagn_mac_setup_register(struct iwl_priv *priv,
154 IEEE80211_HW_SCAN_WHILE_IDLE; 155 IEEE80211_HW_SCAN_WHILE_IDLE;
155 156
156 hw->offchannel_tx_hw_queue = IWL_AUX_QUEUE; 157 hw->offchannel_tx_hw_queue = IWL_AUX_QUEUE;
158 hw->radiotap_mcs_details |= IEEE80211_RADIOTAP_MCS_HAVE_FMT;
157 159
158 /* 160 /*
159 * Including the following line will crash some AP's. This 161 * Including the following line will crash some AP's. This
@@ -237,12 +239,12 @@ int iwlagn_mac_setup_register(struct iwl_priv *priv,
237 239
238 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; 240 hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
239 241
240 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) 242 if (priv->eeprom_data->bands[IEEE80211_BAND_2GHZ].n_channels)
241 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = 243 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
242 &priv->bands[IEEE80211_BAND_2GHZ]; 244 &priv->eeprom_data->bands[IEEE80211_BAND_2GHZ];
243 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels) 245 if (priv->eeprom_data->bands[IEEE80211_BAND_5GHZ].n_channels)
244 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = 246 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
245 &priv->bands[IEEE80211_BAND_5GHZ]; 247 &priv->eeprom_data->bands[IEEE80211_BAND_5GHZ];
246 248
247 hw->wiphy->hw_version = priv->trans->hw_id; 249 hw->wiphy->hw_version = priv->trans->hw_id;
248 250
@@ -341,7 +343,7 @@ static int iwlagn_mac_start(struct ieee80211_hw *hw)
341 return 0; 343 return 0;
342} 344}
343 345
344void iwlagn_mac_stop(struct ieee80211_hw *hw) 346static void iwlagn_mac_stop(struct ieee80211_hw *hw)
345{ 347{
346 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 348 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
347 349
@@ -369,9 +371,9 @@ void iwlagn_mac_stop(struct ieee80211_hw *hw)
369 IWL_DEBUG_MAC80211(priv, "leave\n"); 371 IWL_DEBUG_MAC80211(priv, "leave\n");
370} 372}
371 373
372void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw, 374static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
373 struct ieee80211_vif *vif, 375 struct ieee80211_vif *vif,
374 struct cfg80211_gtk_rekey_data *data) 376 struct cfg80211_gtk_rekey_data *data)
375{ 377{
376 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 378 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
377 379
@@ -397,7 +399,8 @@ void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
397 399
398#ifdef CONFIG_PM_SLEEP 400#ifdef CONFIG_PM_SLEEP
399 401
400int iwlagn_mac_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) 402static int iwlagn_mac_suspend(struct ieee80211_hw *hw,
403 struct cfg80211_wowlan *wowlan)
401{ 404{
402 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 405 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
403 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; 406 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
@@ -420,8 +423,6 @@ int iwlagn_mac_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
420 if (ret) 423 if (ret)
421 goto error; 424 goto error;
422 425
423 device_set_wakeup_enable(priv->trans->dev, true);
424
425 iwl_trans_wowlan_suspend(priv->trans); 426 iwl_trans_wowlan_suspend(priv->trans);
426 427
427 goto out; 428 goto out;
@@ -475,7 +476,7 @@ static int iwlagn_mac_resume(struct ieee80211_hw *hw)
475 } 476 }
476 477
477 if (priv->wowlan_sram) 478 if (priv->wowlan_sram)
478 _iwl_read_targ_mem_words( 479 _iwl_read_targ_mem_dwords(
479 priv->trans, 0x800000, 480 priv->trans, 0x800000,
480 priv->wowlan_sram, 481 priv->wowlan_sram,
481 img->sec[IWL_UCODE_SECTION_DATA].len / 4); 482 img->sec[IWL_UCODE_SECTION_DATA].len / 4);
@@ -488,8 +489,6 @@ static int iwlagn_mac_resume(struct ieee80211_hw *hw)
488 489
489 priv->wowlan = false; 490 priv->wowlan = false;
490 491
491 device_set_wakeup_enable(priv->trans->dev, false);
492
493 iwlagn_prepare_restart(priv); 492 iwlagn_prepare_restart(priv);
494 493
495 memset((void *)&ctx->active, 0, sizeof(ctx->active)); 494 memset((void *)&ctx->active, 0, sizeof(ctx->active));
@@ -504,9 +503,15 @@ static int iwlagn_mac_resume(struct ieee80211_hw *hw)
504 return 1; 503 return 1;
505} 504}
506 505
506static void iwlagn_mac_set_wakeup(struct ieee80211_hw *hw, bool enabled)
507{
508 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
509
510 device_set_wakeup_enable(priv->trans->dev, enabled);
511}
507#endif 512#endif
508 513
509void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb) 514static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
510{ 515{
511 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 516 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
512 517
@@ -517,21 +522,21 @@ void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
517 dev_kfree_skb_any(skb); 522 dev_kfree_skb_any(skb);
518} 523}
519 524
520void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw, 525static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
521 struct ieee80211_vif *vif, 526 struct ieee80211_vif *vif,
522 struct ieee80211_key_conf *keyconf, 527 struct ieee80211_key_conf *keyconf,
523 struct ieee80211_sta *sta, 528 struct ieee80211_sta *sta,
524 u32 iv32, u16 *phase1key) 529 u32 iv32, u16 *phase1key)
525{ 530{
526 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 531 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
527 532
528 iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key); 533 iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key);
529} 534}
530 535
531int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 536static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
532 struct ieee80211_vif *vif, 537 struct ieee80211_vif *vif,
533 struct ieee80211_sta *sta, 538 struct ieee80211_sta *sta,
534 struct ieee80211_key_conf *key) 539 struct ieee80211_key_conf *key)
535{ 540{
536 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 541 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
537 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; 542 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
@@ -631,11 +636,11 @@ int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
631 return ret; 636 return ret;
632} 637}
633 638
634int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw, 639static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
635 struct ieee80211_vif *vif, 640 struct ieee80211_vif *vif,
636 enum ieee80211_ampdu_mlme_action action, 641 enum ieee80211_ampdu_mlme_action action,
637 struct ieee80211_sta *sta, u16 tid, u16 *ssn, 642 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
638 u8 buf_size) 643 u8 buf_size)
639{ 644{
640 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 645 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
641 int ret = -EINVAL; 646 int ret = -EINVAL;
@@ -662,7 +667,7 @@ int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
662 ret = iwl_sta_rx_agg_stop(priv, sta, tid); 667 ret = iwl_sta_rx_agg_stop(priv, sta, tid);
663 break; 668 break;
664 case IEEE80211_AMPDU_TX_START: 669 case IEEE80211_AMPDU_TX_START:
665 if (!priv->trans->ops->tx_agg_setup) 670 if (!priv->trans->ops->txq_enable)
666 break; 671 break;
667 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG) 672 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_TXAGG)
668 break; 673 break;
@@ -757,11 +762,11 @@ static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw,
757 return ret; 762 return ret;
758} 763}
759 764
760int iwlagn_mac_sta_state(struct ieee80211_hw *hw, 765static int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
761 struct ieee80211_vif *vif, 766 struct ieee80211_vif *vif,
762 struct ieee80211_sta *sta, 767 struct ieee80211_sta *sta,
763 enum ieee80211_sta_state old_state, 768 enum ieee80211_sta_state old_state,
764 enum ieee80211_sta_state new_state) 769 enum ieee80211_sta_state new_state)
765{ 770{
766 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 771 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
767 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; 772 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
@@ -840,11 +845,10 @@ int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
840 return ret; 845 return ret;
841} 846}
842 847
843void iwlagn_mac_channel_switch(struct ieee80211_hw *hw, 848static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
844 struct ieee80211_channel_switch *ch_switch) 849 struct ieee80211_channel_switch *ch_switch)
845{ 850{
846 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 851 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
847 const struct iwl_channel_info *ch_info;
848 struct ieee80211_conf *conf = &hw->conf; 852 struct ieee80211_conf *conf = &hw->conf;
849 struct ieee80211_channel *channel = ch_switch->channel; 853 struct ieee80211_channel *channel = ch_switch->channel;
850 struct iwl_ht_config *ht_conf = &priv->current_ht_config; 854 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
@@ -881,12 +885,6 @@ void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
881 if (le16_to_cpu(ctx->active.channel) == ch) 885 if (le16_to_cpu(ctx->active.channel) == ch)
882 goto out; 886 goto out;
883 887
884 ch_info = iwl_get_channel_info(priv, channel->band, ch);
885 if (!is_channel_valid(ch_info)) {
886 IWL_DEBUG_MAC80211(priv, "invalid channel\n");
887 goto out;
888 }
889
890 priv->current_ht_config.smps = conf->smps_mode; 888 priv->current_ht_config.smps = conf->smps_mode;
891 889
892 /* Configure HT40 channels */ 890 /* Configure HT40 channels */
@@ -935,10 +933,10 @@ void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
935 ieee80211_chswitch_done(ctx->vif, is_success); 933 ieee80211_chswitch_done(ctx->vif, is_success);
936} 934}
937 935
938void iwlagn_configure_filter(struct ieee80211_hw *hw, 936static void iwlagn_configure_filter(struct ieee80211_hw *hw,
939 unsigned int changed_flags, 937 unsigned int changed_flags,
940 unsigned int *total_flags, 938 unsigned int *total_flags,
941 u64 multicast) 939 u64 multicast)
942{ 940{
943 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 941 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
944 __le32 filter_or = 0, filter_nand = 0; 942 __le32 filter_or = 0, filter_nand = 0;
@@ -985,7 +983,7 @@ void iwlagn_configure_filter(struct ieee80211_hw *hw,
985 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; 983 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
986} 984}
987 985
988void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop) 986static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
989{ 987{
990 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 988 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
991 989
@@ -1112,7 +1110,7 @@ static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw,
1112 return err; 1110 return err;
1113} 1111}
1114 1112
1115int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw) 1113static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
1116{ 1114{
1117 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 1115 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1118 1116
@@ -1129,8 +1127,8 @@ int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
1129 return 0; 1127 return 0;
1130} 1128}
1131 1129
1132void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw, 1130static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
1133 enum ieee80211_rssi_event rssi_event) 1131 enum ieee80211_rssi_event rssi_event)
1134{ 1132{
1135 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 1133 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1136 1134
@@ -1154,8 +1152,8 @@ void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
1154 IWL_DEBUG_MAC80211(priv, "leave\n"); 1152 IWL_DEBUG_MAC80211(priv, "leave\n");
1155} 1153}
1156 1154
1157int iwlagn_mac_set_tim(struct ieee80211_hw *hw, 1155static int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
1158 struct ieee80211_sta *sta, bool set) 1156 struct ieee80211_sta *sta, bool set)
1159{ 1157{
1160 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 1158 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1161 1159
@@ -1164,9 +1162,9 @@ int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
1164 return 0; 1162 return 0;
1165} 1163}
1166 1164
1167int iwlagn_mac_conf_tx(struct ieee80211_hw *hw, 1165static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
1168 struct ieee80211_vif *vif, u16 queue, 1166 struct ieee80211_vif *vif, u16 queue,
1169 const struct ieee80211_tx_queue_params *params) 1167 const struct ieee80211_tx_queue_params *params)
1170{ 1168{
1171 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 1169 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1172 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; 1170 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
@@ -1208,7 +1206,7 @@ int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
1208 return 0; 1206 return 0;
1209} 1207}
1210 1208
1211int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw) 1209static int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw)
1212{ 1210{
1213 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 1211 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1214 1212
@@ -1224,7 +1222,8 @@ static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
1224 return iwlagn_commit_rxon(priv, ctx); 1222 return iwlagn_commit_rxon(priv, ctx);
1225} 1223}
1226 1224
1227int iwl_setup_interface(struct iwl_priv *priv, struct iwl_rxon_context *ctx) 1225static int iwl_setup_interface(struct iwl_priv *priv,
1226 struct iwl_rxon_context *ctx)
1228{ 1227{
1229 struct ieee80211_vif *vif = ctx->vif; 1228 struct ieee80211_vif *vif = ctx->vif;
1230 int err, ac; 1229 int err, ac;
@@ -1344,9 +1343,9 @@ static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
1344 return err; 1343 return err;
1345} 1344}
1346 1345
1347void iwl_teardown_interface(struct iwl_priv *priv, 1346static void iwl_teardown_interface(struct iwl_priv *priv,
1348 struct ieee80211_vif *vif, 1347 struct ieee80211_vif *vif,
1349 bool mode_change) 1348 bool mode_change)
1350{ 1349{
1351 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); 1350 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1352 1351
@@ -1487,9 +1486,9 @@ static int iwlagn_mac_change_interface(struct ieee80211_hw *hw,
1487 return err; 1486 return err;
1488} 1487}
1489 1488
1490int iwlagn_mac_hw_scan(struct ieee80211_hw *hw, 1489static int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
1491 struct ieee80211_vif *vif, 1490 struct ieee80211_vif *vif,
1492 struct cfg80211_scan_request *req) 1491 struct cfg80211_scan_request *req)
1493{ 1492{
1494 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 1493 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1495 int ret; 1494 int ret;
@@ -1544,10 +1543,10 @@ static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
1544 iwl_send_add_sta(priv, &cmd, CMD_ASYNC); 1543 iwl_send_add_sta(priv, &cmd, CMD_ASYNC);
1545} 1544}
1546 1545
1547void iwlagn_mac_sta_notify(struct ieee80211_hw *hw, 1546static void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
1548 struct ieee80211_vif *vif, 1547 struct ieee80211_vif *vif,
1549 enum sta_notify_cmd cmd, 1548 enum sta_notify_cmd cmd,
1550 struct ieee80211_sta *sta) 1549 struct ieee80211_sta *sta)
1551{ 1550{
1552 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); 1551 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1553 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; 1552 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
@@ -1584,6 +1583,7 @@ struct ieee80211_ops iwlagn_hw_ops = {
1584#ifdef CONFIG_PM_SLEEP 1583#ifdef CONFIG_PM_SLEEP
1585 .suspend = iwlagn_mac_suspend, 1584 .suspend = iwlagn_mac_suspend,
1586 .resume = iwlagn_mac_resume, 1585 .resume = iwlagn_mac_resume,
1586 .set_wakeup = iwlagn_mac_set_wakeup,
1587#endif 1587#endif
1588 .add_interface = iwlagn_mac_add_interface, 1588 .add_interface = iwlagn_mac_add_interface,
1589 .remove_interface = iwlagn_mac_remove_interface, 1589 .remove_interface = iwlagn_mac_remove_interface,
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/dvm/main.c
index ec36e2b020b6..e620af3d592d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
@@ -44,16 +44,18 @@
44 44
45#include <asm/div64.h> 45#include <asm/div64.h>
46 46
47#include "iwl-eeprom.h" 47#include "iwl-eeprom-read.h"
48#include "iwl-dev.h" 48#include "iwl-eeprom-parse.h"
49#include "iwl-io.h" 49#include "iwl-io.h"
50#include "iwl-agn-calib.h"
51#include "iwl-agn.h"
52#include "iwl-trans.h" 50#include "iwl-trans.h"
53#include "iwl-op-mode.h" 51#include "iwl-op-mode.h"
54#include "iwl-drv.h" 52#include "iwl-drv.h"
55#include "iwl-modparams.h" 53#include "iwl-modparams.h"
56 54
55#include "dev.h"
56#include "calib.h"
57#include "agn.h"
58
57/****************************************************************************** 59/******************************************************************************
58 * 60 *
59 * module boiler plate 61 * module boiler plate
@@ -78,7 +80,8 @@ MODULE_DESCRIPTION(DRV_DESCRIPTION);
78MODULE_VERSION(DRV_VERSION); 80MODULE_VERSION(DRV_VERSION);
79MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); 81MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
80MODULE_LICENSE("GPL"); 82MODULE_LICENSE("GPL");
81MODULE_ALIAS("iwlagn"); 83
84static const struct iwl_op_mode_ops iwl_dvm_ops;
82 85
83void iwl_update_chain_flags(struct iwl_priv *priv) 86void iwl_update_chain_flags(struct iwl_priv *priv)
84{ 87{
@@ -180,7 +183,7 @@ int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
180 rate = info->control.rates[0].idx; 183 rate = info->control.rates[0].idx;
181 184
182 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant, 185 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
183 priv->hw_params.valid_tx_ant); 186 priv->eeprom_data->valid_tx_ant);
184 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant); 187 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
185 188
186 /* In mac80211, rates for 5 GHz start at 0 */ 189 /* In mac80211, rates for 5 GHz start at 0 */
@@ -403,7 +406,7 @@ static void iwl_continuous_event_trace(struct iwl_priv *priv)
403 406
404 base = priv->device_pointers.log_event_table; 407 base = priv->device_pointers.log_event_table;
405 if (iwlagn_hw_valid_rtc_data_addr(base)) { 408 if (iwlagn_hw_valid_rtc_data_addr(base)) {
406 iwl_read_targ_mem_words(priv->trans, base, &read, sizeof(read)); 409 iwl_read_targ_mem_bytes(priv->trans, base, &read, sizeof(read));
407 capacity = read.capacity; 410 capacity = read.capacity;
408 mode = read.mode; 411 mode = read.mode;
409 num_wraps = read.wrap_counter; 412 num_wraps = read.wrap_counter;
@@ -578,7 +581,7 @@ static const u8 iwlagn_pan_ac_to_queue[] = {
578 7, 6, 5, 4, 581 7, 6, 5, 4,
579}; 582};
580 583
581void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags) 584static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
582{ 585{
583 int i; 586 int i;
584 587
@@ -645,7 +648,7 @@ void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
645 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); 648 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
646} 649}
647 650
648void iwl_rf_kill_ct_config(struct iwl_priv *priv) 651static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
649{ 652{
650 struct iwl_ct_kill_config cmd; 653 struct iwl_ct_kill_config cmd;
651 struct iwl_ct_kill_throttling_config adv_cmd; 654 struct iwl_ct_kill_throttling_config adv_cmd;
@@ -726,7 +729,7 @@ static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
726 } 729 }
727} 730}
728 731
729void iwl_send_bt_config(struct iwl_priv *priv) 732static void iwl_send_bt_config(struct iwl_priv *priv)
730{ 733{
731 struct iwl_bt_cmd bt_cmd = { 734 struct iwl_bt_cmd bt_cmd = {
732 .lead_time = BT_LEAD_TIME_DEF, 735 .lead_time = BT_LEAD_TIME_DEF,
@@ -814,7 +817,7 @@ int iwl_alive_start(struct iwl_priv *priv)
814 ieee80211_wake_queues(priv->hw); 817 ieee80211_wake_queues(priv->hw);
815 818
816 /* Configure Tx antenna selection based on H/W config */ 819 /* Configure Tx antenna selection based on H/W config */
817 iwlagn_send_tx_ant_config(priv, priv->hw_params.valid_tx_ant); 820 iwlagn_send_tx_ant_config(priv, priv->eeprom_data->valid_tx_ant);
818 821
819 if (iwl_is_associated_ctx(ctx) && !priv->wowlan) { 822 if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
820 struct iwl_rxon_cmd *active_rxon = 823 struct iwl_rxon_cmd *active_rxon =
@@ -932,11 +935,12 @@ void iwl_down(struct iwl_priv *priv)
932 priv->ucode_loaded = false; 935 priv->ucode_loaded = false;
933 iwl_trans_stop_device(priv->trans); 936 iwl_trans_stop_device(priv->trans);
934 937
938 /* Set num_aux_in_flight must be done after the transport is stopped */
939 atomic_set(&priv->num_aux_in_flight, 0);
940
935 /* Clear out all status bits but a few that are stable across reset */ 941 /* Clear out all status bits but a few that are stable across reset */
936 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << 942 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
937 STATUS_RF_KILL_HW | 943 STATUS_RF_KILL_HW |
938 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
939 STATUS_GEO_CONFIGURED |
940 test_bit(STATUS_FW_ERROR, &priv->status) << 944 test_bit(STATUS_FW_ERROR, &priv->status) <<
941 STATUS_FW_ERROR | 945 STATUS_FW_ERROR |
942 test_bit(STATUS_EXIT_PENDING, &priv->status) << 946 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
@@ -1078,7 +1082,7 @@ static void iwlagn_disable_roc_work(struct work_struct *work)
1078 * 1082 *
1079 *****************************************************************************/ 1083 *****************************************************************************/
1080 1084
1081void iwl_setup_deferred_work(struct iwl_priv *priv) 1085static void iwl_setup_deferred_work(struct iwl_priv *priv)
1082{ 1086{
1083 priv->workqueue = create_singlethread_workqueue(DRV_NAME); 1087 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
1084 1088
@@ -1123,224 +1127,14 @@ void iwl_cancel_deferred_work(struct iwl_priv *priv)
1123 del_timer_sync(&priv->ucode_trace); 1127 del_timer_sync(&priv->ucode_trace);
1124} 1128}
1125 1129
1126static void iwl_init_hw_rates(struct ieee80211_rate *rates) 1130static int iwl_init_drv(struct iwl_priv *priv)
1127{
1128 int i;
1129
1130 for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
1131 rates[i].bitrate = iwl_rates[i].ieee * 5;
1132 rates[i].hw_value = i; /* Rate scaling will work on indexes */
1133 rates[i].hw_value_short = i;
1134 rates[i].flags = 0;
1135 if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
1136 /*
1137 * If CCK != 1M then set short preamble rate flag.
1138 */
1139 rates[i].flags |=
1140 (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
1141 0 : IEEE80211_RATE_SHORT_PREAMBLE;
1142 }
1143 }
1144}
1145
1146#define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
1147#define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
1148static void iwl_init_ht_hw_capab(const struct iwl_priv *priv,
1149 struct ieee80211_sta_ht_cap *ht_info,
1150 enum ieee80211_band band)
1151{
1152 u16 max_bit_rate = 0;
1153 u8 rx_chains_num = priv->hw_params.rx_chains_num;
1154 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1155
1156 ht_info->cap = 0;
1157 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
1158
1159 ht_info->ht_supported = true;
1160
1161 if (priv->cfg->ht_params &&
1162 priv->cfg->ht_params->ht_greenfield_support)
1163 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
1164 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
1165 max_bit_rate = MAX_BIT_RATE_20_MHZ;
1166 if (priv->hw_params.ht40_channel & BIT(band)) {
1167 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
1168 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
1169 ht_info->mcs.rx_mask[4] = 0x01;
1170 max_bit_rate = MAX_BIT_RATE_40_MHZ;
1171 }
1172
1173 if (iwlwifi_mod_params.amsdu_size_8K)
1174 ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
1175
1176 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
1177 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
1178
1179 ht_info->mcs.rx_mask[0] = 0xFF;
1180 if (rx_chains_num >= 2)
1181 ht_info->mcs.rx_mask[1] = 0xFF;
1182 if (rx_chains_num >= 3)
1183 ht_info->mcs.rx_mask[2] = 0xFF;
1184
1185 /* Highest supported Rx data rate */
1186 max_bit_rate *= rx_chains_num;
1187 WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
1188 ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
1189
1190 /* Tx MCS capabilities */
1191 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
1192 if (tx_chains_num != rx_chains_num) {
1193 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
1194 ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
1195 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
1196 }
1197}
1198
1199/**
1200 * iwl_init_geos - Initialize mac80211's geo/channel info based from eeprom
1201 */
1202static int iwl_init_geos(struct iwl_priv *priv)
1203{
1204 struct iwl_channel_info *ch;
1205 struct ieee80211_supported_band *sband;
1206 struct ieee80211_channel *channels;
1207 struct ieee80211_channel *geo_ch;
1208 struct ieee80211_rate *rates;
1209 int i = 0;
1210 s8 max_tx_power = IWLAGN_TX_POWER_TARGET_POWER_MIN;
1211
1212 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
1213 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
1214 IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
1215 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
1216 return 0;
1217 }
1218
1219 channels = kcalloc(priv->channel_count,
1220 sizeof(struct ieee80211_channel), GFP_KERNEL);
1221 if (!channels)
1222 return -ENOMEM;
1223
1224 rates = kcalloc(IWL_RATE_COUNT_LEGACY, sizeof(struct ieee80211_rate),
1225 GFP_KERNEL);
1226 if (!rates) {
1227 kfree(channels);
1228 return -ENOMEM;
1229 }
1230
1231 /* 5.2GHz channels start after the 2.4GHz channels */
1232 sband = &priv->bands[IEEE80211_BAND_5GHZ];
1233 sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
1234 /* just OFDM */
1235 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
1236 sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
1237
1238 if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE)
1239 iwl_init_ht_hw_capab(priv, &sband->ht_cap,
1240 IEEE80211_BAND_5GHZ);
1241
1242 sband = &priv->bands[IEEE80211_BAND_2GHZ];
1243 sband->channels = channels;
1244 /* OFDM & CCK */
1245 sband->bitrates = rates;
1246 sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
1247
1248 if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE)
1249 iwl_init_ht_hw_capab(priv, &sband->ht_cap,
1250 IEEE80211_BAND_2GHZ);
1251
1252 priv->ieee_channels = channels;
1253 priv->ieee_rates = rates;
1254
1255 for (i = 0; i < priv->channel_count; i++) {
1256 ch = &priv->channel_info[i];
1257
1258 /* FIXME: might be removed if scan is OK */
1259 if (!is_channel_valid(ch))
1260 continue;
1261
1262 sband = &priv->bands[ch->band];
1263
1264 geo_ch = &sband->channels[sband->n_channels++];
1265
1266 geo_ch->center_freq =
1267 ieee80211_channel_to_frequency(ch->channel, ch->band);
1268 geo_ch->max_power = ch->max_power_avg;
1269 geo_ch->max_antenna_gain = 0xff;
1270 geo_ch->hw_value = ch->channel;
1271
1272 if (is_channel_valid(ch)) {
1273 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
1274 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
1275
1276 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
1277 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
1278
1279 if (ch->flags & EEPROM_CHANNEL_RADAR)
1280 geo_ch->flags |= IEEE80211_CHAN_RADAR;
1281
1282 geo_ch->flags |= ch->ht40_extension_channel;
1283
1284 if (ch->max_power_avg > max_tx_power)
1285 max_tx_power = ch->max_power_avg;
1286 } else {
1287 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
1288 }
1289
1290 IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
1291 ch->channel, geo_ch->center_freq,
1292 is_channel_a_band(ch) ? "5.2" : "2.4",
1293 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
1294 "restricted" : "valid",
1295 geo_ch->flags);
1296 }
1297
1298 priv->tx_power_device_lmt = max_tx_power;
1299 priv->tx_power_user_lmt = max_tx_power;
1300 priv->tx_power_next = max_tx_power;
1301
1302 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
1303 priv->hw_params.sku & EEPROM_SKU_CAP_BAND_52GHZ) {
1304 IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
1305 "Please send your %s to maintainer.\n",
1306 priv->trans->hw_id_str);
1307 priv->hw_params.sku &= ~EEPROM_SKU_CAP_BAND_52GHZ;
1308 }
1309
1310 if (iwlwifi_mod_params.disable_5ghz)
1311 priv->bands[IEEE80211_BAND_5GHZ].n_channels = 0;
1312
1313 IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
1314 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
1315 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
1316
1317 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
1318
1319 return 0;
1320}
1321
1322/*
1323 * iwl_free_geos - undo allocations in iwl_init_geos
1324 */
1325static void iwl_free_geos(struct iwl_priv *priv)
1326{ 1131{
1327 kfree(priv->ieee_channels);
1328 kfree(priv->ieee_rates);
1329 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
1330}
1331
1332int iwl_init_drv(struct iwl_priv *priv)
1333{
1334 int ret;
1335
1336 spin_lock_init(&priv->sta_lock); 1132 spin_lock_init(&priv->sta_lock);
1337 1133
1338 mutex_init(&priv->mutex); 1134 mutex_init(&priv->mutex);
1339 1135
1340 INIT_LIST_HEAD(&priv->calib_results); 1136 INIT_LIST_HEAD(&priv->calib_results);
1341 1137
1342 priv->ieee_channels = NULL;
1343 priv->ieee_rates = NULL;
1344 priv->band = IEEE80211_BAND_2GHZ; 1138 priv->band = IEEE80211_BAND_2GHZ;
1345 1139
1346 priv->plcp_delta_threshold = 1140 priv->plcp_delta_threshold =
@@ -1371,31 +1165,11 @@ int iwl_init_drv(struct iwl_priv *priv)
1371 priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF; 1165 priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
1372 } 1166 }
1373 1167
1374 ret = iwl_init_channel_map(priv);
1375 if (ret) {
1376 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
1377 goto err;
1378 }
1379
1380 ret = iwl_init_geos(priv);
1381 if (ret) {
1382 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
1383 goto err_free_channel_map;
1384 }
1385 iwl_init_hw_rates(priv->ieee_rates);
1386
1387 return 0; 1168 return 0;
1388
1389err_free_channel_map:
1390 iwl_free_channel_map(priv);
1391err:
1392 return ret;
1393} 1169}
1394 1170
1395void iwl_uninit_drv(struct iwl_priv *priv) 1171static void iwl_uninit_drv(struct iwl_priv *priv)
1396{ 1172{
1397 iwl_free_geos(priv);
1398 iwl_free_channel_map(priv);
1399 kfree(priv->scan_cmd); 1173 kfree(priv->scan_cmd);
1400 kfree(priv->beacon_cmd); 1174 kfree(priv->beacon_cmd);
1401 kfree(rcu_dereference_raw(priv->noa_data)); 1175 kfree(rcu_dereference_raw(priv->noa_data));
@@ -1405,7 +1179,7 @@ void iwl_uninit_drv(struct iwl_priv *priv)
1405#endif 1179#endif
1406} 1180}
1407 1181
1408void iwl_set_hw_params(struct iwl_priv *priv) 1182static void iwl_set_hw_params(struct iwl_priv *priv)
1409{ 1183{
1410 if (priv->cfg->ht_params) 1184 if (priv->cfg->ht_params)
1411 priv->hw_params.use_rts_for_aggregation = 1185 priv->hw_params.use_rts_for_aggregation =
@@ -1421,7 +1195,7 @@ void iwl_set_hw_params(struct iwl_priv *priv)
1421 1195
1422 1196
1423/* show what optional capabilities we have */ 1197/* show what optional capabilities we have */
1424void iwl_option_config(struct iwl_priv *priv) 1198static void iwl_option_config(struct iwl_priv *priv)
1425{ 1199{
1426#ifdef CONFIG_IWLWIFI_DEBUG 1200#ifdef CONFIG_IWLWIFI_DEBUG
1427 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG enabled\n"); 1201 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG enabled\n");
@@ -1454,6 +1228,42 @@ void iwl_option_config(struct iwl_priv *priv)
1454#endif 1228#endif
1455} 1229}
1456 1230
1231static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
1232{
1233 u16 radio_cfg;
1234
1235 priv->hw_params.sku = priv->eeprom_data->sku;
1236
1237 if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE &&
1238 !priv->cfg->ht_params) {
1239 IWL_ERR(priv, "Invalid 11n configuration\n");
1240 return -EINVAL;
1241 }
1242
1243 if (!priv->hw_params.sku) {
1244 IWL_ERR(priv, "Invalid device sku\n");
1245 return -EINVAL;
1246 }
1247
1248 IWL_INFO(priv, "Device SKU: 0x%X\n", priv->hw_params.sku);
1249
1250 radio_cfg = priv->eeprom_data->radio_cfg;
1251
1252 priv->hw_params.tx_chains_num =
1253 num_of_ant(priv->eeprom_data->valid_tx_ant);
1254 if (priv->cfg->rx_with_siso_diversity)
1255 priv->hw_params.rx_chains_num = 1;
1256 else
1257 priv->hw_params.rx_chains_num =
1258 num_of_ant(priv->eeprom_data->valid_rx_ant);
1259
1260 IWL_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
1261 priv->eeprom_data->valid_tx_ant,
1262 priv->eeprom_data->valid_rx_ant);
1263
1264 return 0;
1265}
1266
1457static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans, 1267static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
1458 const struct iwl_cfg *cfg, 1268 const struct iwl_cfg *cfg,
1459 const struct iwl_fw *fw) 1269 const struct iwl_fw *fw)
@@ -1539,7 +1349,7 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
1539 trans_cfg.queue_watchdog_timeout = 1349 trans_cfg.queue_watchdog_timeout =
1540 priv->cfg->base_params->wd_timeout; 1350 priv->cfg->base_params->wd_timeout;
1541 else 1351 else
1542 trans_cfg.queue_watchdog_timeout = IWL_WATCHHDOG_DISABLED; 1352 trans_cfg.queue_watchdog_timeout = IWL_WATCHDOG_DISABLED;
1543 trans_cfg.command_names = iwl_dvm_cmd_strings; 1353 trans_cfg.command_names = iwl_dvm_cmd_strings;
1544 1354
1545 ucode_flags = fw->ucode_capa.flags; 1355 ucode_flags = fw->ucode_capa.flags;
@@ -1599,25 +1409,33 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
1599 goto out_free_hw; 1409 goto out_free_hw;
1600 1410
1601 /* Read the EEPROM */ 1411 /* Read the EEPROM */
1602 if (iwl_eeprom_init(priv, priv->trans->hw_rev)) { 1412 if (iwl_read_eeprom(priv->trans, &priv->eeprom_blob,
1413 &priv->eeprom_blob_size)) {
1603 IWL_ERR(priv, "Unable to init EEPROM\n"); 1414 IWL_ERR(priv, "Unable to init EEPROM\n");
1604 goto out_free_hw; 1415 goto out_free_hw;
1605 } 1416 }
1417
1606 /* Reset chip to save power until we load uCode during "up". */ 1418 /* Reset chip to save power until we load uCode during "up". */
1607 iwl_trans_stop_hw(priv->trans, false); 1419 iwl_trans_stop_hw(priv->trans, false);
1608 1420
1609 if (iwl_eeprom_check_version(priv)) 1421 priv->eeprom_data = iwl_parse_eeprom_data(priv->trans->dev, priv->cfg,
1422 priv->eeprom_blob,
1423 priv->eeprom_blob_size);
1424 if (!priv->eeprom_data)
1425 goto out_free_eeprom_blob;
1426
1427 if (iwl_eeprom_check_version(priv->eeprom_data, priv->trans))
1610 goto out_free_eeprom; 1428 goto out_free_eeprom;
1611 1429
1612 if (iwl_eeprom_init_hw_params(priv)) 1430 if (iwl_eeprom_init_hw_params(priv))
1613 goto out_free_eeprom; 1431 goto out_free_eeprom;
1614 1432
1615 /* extract MAC Address */ 1433 /* extract MAC Address */
1616 iwl_eeprom_get_mac(priv, priv->addresses[0].addr); 1434 memcpy(priv->addresses[0].addr, priv->eeprom_data->hw_addr, ETH_ALEN);
1617 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr); 1435 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
1618 priv->hw->wiphy->addresses = priv->addresses; 1436 priv->hw->wiphy->addresses = priv->addresses;
1619 priv->hw->wiphy->n_addresses = 1; 1437 priv->hw->wiphy->n_addresses = 1;
1620 num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS); 1438 num_mac = priv->eeprom_data->n_hw_addrs;
1621 if (num_mac > 1) { 1439 if (num_mac > 1) {
1622 memcpy(priv->addresses[1].addr, priv->addresses[0].addr, 1440 memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
1623 ETH_ALEN); 1441 ETH_ALEN);
@@ -1711,8 +1529,10 @@ out_destroy_workqueue:
1711 destroy_workqueue(priv->workqueue); 1529 destroy_workqueue(priv->workqueue);
1712 priv->workqueue = NULL; 1530 priv->workqueue = NULL;
1713 iwl_uninit_drv(priv); 1531 iwl_uninit_drv(priv);
1532out_free_eeprom_blob:
1533 kfree(priv->eeprom_blob);
1714out_free_eeprom: 1534out_free_eeprom:
1715 iwl_eeprom_free(priv); 1535 iwl_free_eeprom_data(priv->eeprom_data);
1716out_free_hw: 1536out_free_hw:
1717 ieee80211_free_hw(priv->hw); 1537 ieee80211_free_hw(priv->hw);
1718out: 1538out:
@@ -1720,7 +1540,7 @@ out:
1720 return op_mode; 1540 return op_mode;
1721} 1541}
1722 1542
1723void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode) 1543static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
1724{ 1544{
1725 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 1545 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
1726 1546
@@ -1728,7 +1548,7 @@ void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
1728 1548
1729 iwl_dbgfs_unregister(priv); 1549 iwl_dbgfs_unregister(priv);
1730 1550
1731 iwl_testmode_cleanup(priv); 1551 iwl_testmode_free(priv);
1732 iwlagn_mac_unregister(priv); 1552 iwlagn_mac_unregister(priv);
1733 1553
1734 iwl_tt_exit(priv); 1554 iwl_tt_exit(priv);
@@ -1737,7 +1557,8 @@ void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
1737 priv->ucode_loaded = false; 1557 priv->ucode_loaded = false;
1738 iwl_trans_stop_device(priv->trans); 1558 iwl_trans_stop_device(priv->trans);
1739 1559
1740 iwl_eeprom_free(priv); 1560 kfree(priv->eeprom_blob);
1561 iwl_free_eeprom_data(priv->eeprom_data);
1741 1562
1742 /*netif_stop_queue(dev); */ 1563 /*netif_stop_queue(dev); */
1743 flush_workqueue(priv->workqueue); 1564 flush_workqueue(priv->workqueue);
@@ -1850,7 +1671,7 @@ static void iwl_dump_nic_error_log(struct iwl_priv *priv)
1850 } 1671 }
1851 1672
1852 /*TODO: Update dbgfs with ISR error stats obtained below */ 1673 /*TODO: Update dbgfs with ISR error stats obtained below */
1853 iwl_read_targ_mem_words(trans, base, &table, sizeof(table)); 1674 iwl_read_targ_mem_bytes(trans, base, &table, sizeof(table));
1854 1675
1855 if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) { 1676 if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
1856 IWL_ERR(trans, "Start IWL Error Log Dump:\n"); 1677 IWL_ERR(trans, "Start IWL Error Log Dump:\n");
@@ -2185,7 +2006,7 @@ static void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
2185 } 2006 }
2186} 2007}
2187 2008
2188void iwl_nic_error(struct iwl_op_mode *op_mode) 2009static void iwl_nic_error(struct iwl_op_mode *op_mode)
2189{ 2010{
2190 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 2011 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2191 2012
@@ -2198,7 +2019,7 @@ void iwl_nic_error(struct iwl_op_mode *op_mode)
2198 iwlagn_fw_error(priv, false); 2019 iwlagn_fw_error(priv, false);
2199} 2020}
2200 2021
2201void iwl_cmd_queue_full(struct iwl_op_mode *op_mode) 2022static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
2202{ 2023{
2203 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 2024 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2204 2025
@@ -2208,9 +2029,49 @@ void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
2208 } 2029 }
2209} 2030}
2210 2031
2211void iwl_nic_config(struct iwl_op_mode *op_mode) 2032#define EEPROM_RF_CONFIG_TYPE_MAX 0x3
2033
2034static void iwl_nic_config(struct iwl_op_mode *op_mode)
2212{ 2035{
2213 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 2036 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2037 u16 radio_cfg = priv->eeprom_data->radio_cfg;
2038
2039 /* SKU Control */
2040 iwl_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
2041 CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH |
2042 CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP,
2043 (CSR_HW_REV_STEP(priv->trans->hw_rev) <<
2044 CSR_HW_IF_CONFIG_REG_POS_MAC_STEP) |
2045 (CSR_HW_REV_DASH(priv->trans->hw_rev) <<
2046 CSR_HW_IF_CONFIG_REG_POS_MAC_DASH));
2047
2048 /* write radio config values to register */
2049 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) <= EEPROM_RF_CONFIG_TYPE_MAX) {
2050 u32 reg_val =
2051 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) <<
2052 CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE |
2053 EEPROM_RF_CFG_STEP_MSK(radio_cfg) <<
2054 CSR_HW_IF_CONFIG_REG_POS_PHY_STEP |
2055 EEPROM_RF_CFG_DASH_MSK(radio_cfg) <<
2056 CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;
2057
2058 iwl_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
2059 CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |
2060 CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |
2061 CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH, reg_val);
2062
2063 IWL_INFO(priv, "Radio type=0x%x-0x%x-0x%x\n",
2064 EEPROM_RF_CFG_TYPE_MSK(radio_cfg),
2065 EEPROM_RF_CFG_STEP_MSK(radio_cfg),
2066 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
2067 } else {
2068 WARN_ON(1);
2069 }
2070
2071 /* set CSR_HW_CONFIG_REG for uCode use */
2072 iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG,
2073 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
2074 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
2214 2075
2215 priv->lib->nic_config(priv); 2076 priv->lib->nic_config(priv);
2216} 2077}
@@ -2223,7 +2084,7 @@ static void iwl_wimax_active(struct iwl_op_mode *op_mode)
2223 IWL_ERR(priv, "RF is used by WiMAX\n"); 2084 IWL_ERR(priv, "RF is used by WiMAX\n");
2224} 2085}
2225 2086
2226void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue) 2087static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
2227{ 2088{
2228 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 2089 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2229 int mq = priv->queue_to_mac80211[queue]; 2090 int mq = priv->queue_to_mac80211[queue];
@@ -2242,7 +2103,7 @@ void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
2242 ieee80211_stop_queue(priv->hw, mq); 2103 ieee80211_stop_queue(priv->hw, mq);
2243} 2104}
2244 2105
2245void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue) 2106static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
2246{ 2107{
2247 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 2108 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2248 int mq = priv->queue_to_mac80211[queue]; 2109 int mq = priv->queue_to_mac80211[queue];
@@ -2282,16 +2143,17 @@ void iwlagn_lift_passive_no_rx(struct iwl_priv *priv)
2282 priv->passive_no_rx = false; 2143 priv->passive_no_rx = false;
2283} 2144}
2284 2145
2285void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb) 2146static void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
2286{ 2147{
2148 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2287 struct ieee80211_tx_info *info; 2149 struct ieee80211_tx_info *info;
2288 2150
2289 info = IEEE80211_SKB_CB(skb); 2151 info = IEEE80211_SKB_CB(skb);
2290 kmem_cache_free(iwl_tx_cmd_pool, (info->driver_data[1])); 2152 iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]);
2291 dev_kfree_skb_any(skb); 2153 dev_kfree_skb_any(skb);
2292} 2154}
2293 2155
2294void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state) 2156static void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
2295{ 2157{
2296 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 2158 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2297 2159
@@ -2303,7 +2165,7 @@ void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
2303 wiphy_rfkill_set_hw_state(priv->hw->wiphy, state); 2165 wiphy_rfkill_set_hw_state(priv->hw->wiphy, state);
2304} 2166}
2305 2167
2306const struct iwl_op_mode_ops iwl_dvm_ops = { 2168static const struct iwl_op_mode_ops iwl_dvm_ops = {
2307 .start = iwl_op_mode_dvm_start, 2169 .start = iwl_op_mode_dvm_start,
2308 .stop = iwl_op_mode_dvm_stop, 2170 .stop = iwl_op_mode_dvm_stop,
2309 .rx = iwl_rx_dispatch, 2171 .rx = iwl_rx_dispatch,
@@ -2322,9 +2184,6 @@ const struct iwl_op_mode_ops iwl_dvm_ops = {
2322 * driver and module entry point 2184 * driver and module entry point
2323 * 2185 *
2324 *****************************************************************************/ 2186 *****************************************************************************/
2325
2326struct kmem_cache *iwl_tx_cmd_pool;
2327
2328static int __init iwl_init(void) 2187static int __init iwl_init(void)
2329{ 2188{
2330 2189
@@ -2332,36 +2191,25 @@ static int __init iwl_init(void)
2332 pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n"); 2191 pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
2333 pr_info(DRV_COPYRIGHT "\n"); 2192 pr_info(DRV_COPYRIGHT "\n");
2334 2193
2335 iwl_tx_cmd_pool = kmem_cache_create("iwl_dev_cmd",
2336 sizeof(struct iwl_device_cmd),
2337 sizeof(void *), 0, NULL);
2338 if (!iwl_tx_cmd_pool)
2339 return -ENOMEM;
2340
2341 ret = iwlagn_rate_control_register(); 2194 ret = iwlagn_rate_control_register();
2342 if (ret) { 2195 if (ret) {
2343 pr_err("Unable to register rate control algorithm: %d\n", ret); 2196 pr_err("Unable to register rate control algorithm: %d\n", ret);
2344 goto error_rc_register; 2197 return ret;
2345 } 2198 }
2346 2199
2347 ret = iwl_pci_register_driver(); 2200 ret = iwl_opmode_register("iwldvm", &iwl_dvm_ops);
2348 if (ret) 2201 if (ret) {
2349 goto error_pci_register; 2202 pr_err("Unable to register op_mode: %d\n", ret);
2350 return ret; 2203 iwlagn_rate_control_unregister();
2204 }
2351 2205
2352error_pci_register:
2353 iwlagn_rate_control_unregister();
2354error_rc_register:
2355 kmem_cache_destroy(iwl_tx_cmd_pool);
2356 return ret; 2206 return ret;
2357} 2207}
2208module_init(iwl_init);
2358 2209
2359static void __exit iwl_exit(void) 2210static void __exit iwl_exit(void)
2360{ 2211{
2361 iwl_pci_unregister_driver(); 2212 iwl_opmode_deregister("iwldvm");
2362 iwlagn_rate_control_unregister(); 2213 iwlagn_rate_control_unregister();
2363 kmem_cache_destroy(iwl_tx_cmd_pool);
2364} 2214}
2365
2366module_exit(iwl_exit); 2215module_exit(iwl_exit);
2367module_init(iwl_init);
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.c b/drivers/net/wireless/iwlwifi/dvm/power.c
index 544ddf17f5bd..518cf3715809 100644
--- a/drivers/net/wireless/iwlwifi/iwl-power.c
+++ b/drivers/net/wireless/iwlwifi/dvm/power.c
@@ -31,18 +31,15 @@
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/init.h> 33#include <linux/init.h>
34
35#include <net/mac80211.h> 34#include <net/mac80211.h>
36
37#include "iwl-eeprom.h"
38#include "iwl-dev.h"
39#include "iwl-agn.h"
40#include "iwl-io.h" 35#include "iwl-io.h"
41#include "iwl-commands.h"
42#include "iwl-debug.h" 36#include "iwl-debug.h"
43#include "iwl-power.h"
44#include "iwl-trans.h" 37#include "iwl-trans.h"
45#include "iwl-modparams.h" 38#include "iwl-modparams.h"
39#include "dev.h"
40#include "agn.h"
41#include "commands.h"
42#include "power.h"
46 43
47/* 44/*
48 * Setting power level allows the card to go to sleep when not busy. 45 * Setting power level allows the card to go to sleep when not busy.
diff --git a/drivers/net/wireless/iwlwifi/iwl-power.h b/drivers/net/wireless/iwlwifi/dvm/power.h
index 21afc92efacb..a2cee7f04848 100644
--- a/drivers/net/wireless/iwlwifi/iwl-power.h
+++ b/drivers/net/wireless/iwlwifi/dvm/power.h
@@ -28,7 +28,7 @@
28#ifndef __iwl_power_setting_h__ 28#ifndef __iwl_power_setting_h__
29#define __iwl_power_setting_h__ 29#define __iwl_power_setting_h__
30 30
31#include "iwl-commands.h" 31#include "commands.h"
32 32
33struct iwl_power_mgr { 33struct iwl_power_mgr {
34 struct iwl_powertable_cmd sleep_cmd; 34 struct iwl_powertable_cmd sleep_cmd;
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/dvm/rs.c
index 8cebd7c363fc..6fddd2785e6e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/dvm/rs.c
@@ -35,10 +35,8 @@
35 35
36#include <linux/workqueue.h> 36#include <linux/workqueue.h>
37 37
38#include "iwl-dev.h" 38#include "dev.h"
39#include "iwl-agn.h" 39#include "agn.h"
40#include "iwl-op-mode.h"
41#include "iwl-modparams.h"
42 40
43#define RS_NAME "iwl-agn-rs" 41#define RS_NAME "iwl-agn-rs"
44 42
@@ -819,7 +817,7 @@ static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta,
819 817
820 if (num_of_ant(tbl->ant_type) > 1) 818 if (num_of_ant(tbl->ant_type) > 1)
821 tbl->ant_type = 819 tbl->ant_type =
822 first_antenna(priv->hw_params.valid_tx_ant); 820 first_antenna(priv->eeprom_data->valid_tx_ant);
823 821
824 tbl->is_ht40 = 0; 822 tbl->is_ht40 = 0;
825 tbl->is_SGI = 0; 823 tbl->is_SGI = 0;
@@ -1447,7 +1445,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1447 u32 sz = (sizeof(struct iwl_scale_tbl_info) - 1445 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1448 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); 1446 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1449 u8 start_action; 1447 u8 start_action;
1450 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1448 u8 valid_tx_ant = priv->eeprom_data->valid_tx_ant;
1451 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1449 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1452 int ret = 0; 1450 int ret = 0;
1453 u8 update_search_tbl_counter = 0; 1451 u8 update_search_tbl_counter = 0;
@@ -1465,7 +1463,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1465 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: 1463 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1466 /* avoid antenna B and MIMO */ 1464 /* avoid antenna B and MIMO */
1467 valid_tx_ant = 1465 valid_tx_ant =
1468 first_antenna(priv->hw_params.valid_tx_ant); 1466 first_antenna(priv->eeprom_data->valid_tx_ant);
1469 if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2 && 1467 if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2 &&
1470 tbl->action != IWL_LEGACY_SWITCH_SISO) 1468 tbl->action != IWL_LEGACY_SWITCH_SISO)
1471 tbl->action = IWL_LEGACY_SWITCH_SISO; 1469 tbl->action = IWL_LEGACY_SWITCH_SISO;
@@ -1489,7 +1487,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
1489 else if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2) 1487 else if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2)
1490 tbl->action = IWL_LEGACY_SWITCH_SISO; 1488 tbl->action = IWL_LEGACY_SWITCH_SISO;
1491 valid_tx_ant = 1489 valid_tx_ant =
1492 first_antenna(priv->hw_params.valid_tx_ant); 1490 first_antenna(priv->eeprom_data->valid_tx_ant);
1493 } 1491 }
1494 1492
1495 start_action = tbl->action; 1493 start_action = tbl->action;
@@ -1623,7 +1621,7 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1623 u32 sz = (sizeof(struct iwl_scale_tbl_info) - 1621 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1624 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); 1622 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1625 u8 start_action; 1623 u8 start_action;
1626 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1624 u8 valid_tx_ant = priv->eeprom_data->valid_tx_ant;
1627 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1625 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1628 u8 update_search_tbl_counter = 0; 1626 u8 update_search_tbl_counter = 0;
1629 int ret; 1627 int ret;
@@ -1641,7 +1639,7 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1641 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS: 1639 case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
1642 /* avoid antenna B and MIMO */ 1640 /* avoid antenna B and MIMO */
1643 valid_tx_ant = 1641 valid_tx_ant =
1644 first_antenna(priv->hw_params.valid_tx_ant); 1642 first_antenna(priv->eeprom_data->valid_tx_ant);
1645 if (tbl->action != IWL_SISO_SWITCH_ANTENNA1) 1643 if (tbl->action != IWL_SISO_SWITCH_ANTENNA1)
1646 tbl->action = IWL_SISO_SWITCH_ANTENNA1; 1644 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1647 break; 1645 break;
@@ -1659,7 +1657,7 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
1659 /* configure as 1x1 if bt full concurrency */ 1657 /* configure as 1x1 if bt full concurrency */
1660 if (priv->bt_full_concurrent) { 1658 if (priv->bt_full_concurrent) {
1661 valid_tx_ant = 1659 valid_tx_ant =
1662 first_antenna(priv->hw_params.valid_tx_ant); 1660 first_antenna(priv->eeprom_data->valid_tx_ant);
1663 if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2) 1661 if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2)
1664 tbl->action = IWL_SISO_SWITCH_ANTENNA1; 1662 tbl->action = IWL_SISO_SWITCH_ANTENNA1;
1665 } 1663 }
@@ -1795,7 +1793,7 @@ static int rs_move_mimo2_to_other(struct iwl_priv *priv,
1795 u32 sz = (sizeof(struct iwl_scale_tbl_info) - 1793 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1796 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); 1794 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1797 u8 start_action; 1795 u8 start_action;
1798 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1796 u8 valid_tx_ant = priv->eeprom_data->valid_tx_ant;
1799 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1797 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1800 u8 update_search_tbl_counter = 0; 1798 u8 update_search_tbl_counter = 0;
1801 int ret; 1799 int ret;
@@ -1965,7 +1963,7 @@ static int rs_move_mimo3_to_other(struct iwl_priv *priv,
1965 u32 sz = (sizeof(struct iwl_scale_tbl_info) - 1963 u32 sz = (sizeof(struct iwl_scale_tbl_info) -
1966 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT)); 1964 (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
1967 u8 start_action; 1965 u8 start_action;
1968 u8 valid_tx_ant = priv->hw_params.valid_tx_ant; 1966 u8 valid_tx_ant = priv->eeprom_data->valid_tx_ant;
1969 u8 tx_chains_num = priv->hw_params.tx_chains_num; 1967 u8 tx_chains_num = priv->hw_params.tx_chains_num;
1970 int ret; 1968 int ret;
1971 u8 update_search_tbl_counter = 0; 1969 u8 update_search_tbl_counter = 0;
@@ -2699,7 +2697,7 @@ static void rs_initialize_lq(struct iwl_priv *priv,
2699 2697
2700 i = lq_sta->last_txrate_idx; 2698 i = lq_sta->last_txrate_idx;
2701 2699
2702 valid_tx_ant = priv->hw_params.valid_tx_ant; 2700 valid_tx_ant = priv->eeprom_data->valid_tx_ant;
2703 2701
2704 if (!lq_sta->search_better_tbl) 2702 if (!lq_sta->search_better_tbl)
2705 active_tbl = lq_sta->active_tbl; 2703 active_tbl = lq_sta->active_tbl;
@@ -2893,15 +2891,15 @@ void iwl_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta, u8 sta_i
2893 2891
2894 /* These values will be overridden later */ 2892 /* These values will be overridden later */
2895 lq_sta->lq.general_params.single_stream_ant_msk = 2893 lq_sta->lq.general_params.single_stream_ant_msk =
2896 first_antenna(priv->hw_params.valid_tx_ant); 2894 first_antenna(priv->eeprom_data->valid_tx_ant);
2897 lq_sta->lq.general_params.dual_stream_ant_msk = 2895 lq_sta->lq.general_params.dual_stream_ant_msk =
2898 priv->hw_params.valid_tx_ant & 2896 priv->eeprom_data->valid_tx_ant &
2899 ~first_antenna(priv->hw_params.valid_tx_ant); 2897 ~first_antenna(priv->eeprom_data->valid_tx_ant);
2900 if (!lq_sta->lq.general_params.dual_stream_ant_msk) { 2898 if (!lq_sta->lq.general_params.dual_stream_ant_msk) {
2901 lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB; 2899 lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB;
2902 } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) { 2900 } else if (num_of_ant(priv->eeprom_data->valid_tx_ant) == 2) {
2903 lq_sta->lq.general_params.dual_stream_ant_msk = 2901 lq_sta->lq.general_params.dual_stream_ant_msk =
2904 priv->hw_params.valid_tx_ant; 2902 priv->eeprom_data->valid_tx_ant;
2905 } 2903 }
2906 2904
2907 /* as default allow aggregation for all tids */ 2905 /* as default allow aggregation for all tids */
@@ -2947,7 +2945,7 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
2947 if (priv && priv->bt_full_concurrent) { 2945 if (priv && priv->bt_full_concurrent) {
2948 /* 1x1 only */ 2946 /* 1x1 only */
2949 tbl_type.ant_type = 2947 tbl_type.ant_type =
2950 first_antenna(priv->hw_params.valid_tx_ant); 2948 first_antenna(priv->eeprom_data->valid_tx_ant);
2951 } 2949 }
2952 2950
2953 /* How many times should we repeat the initial rate? */ 2951 /* How many times should we repeat the initial rate? */
@@ -2979,7 +2977,7 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
2979 if (priv->bt_full_concurrent) 2977 if (priv->bt_full_concurrent)
2980 valid_tx_ant = ANT_A; 2978 valid_tx_ant = ANT_A;
2981 else 2979 else
2982 valid_tx_ant = priv->hw_params.valid_tx_ant; 2980 valid_tx_ant = priv->eeprom_data->valid_tx_ant;
2983 } 2981 }
2984 2982
2985 /* Fill rest of rate table */ 2983 /* Fill rest of rate table */
@@ -3013,7 +3011,7 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
3013 if (priv && priv->bt_full_concurrent) { 3011 if (priv && priv->bt_full_concurrent) {
3014 /* 1x1 only */ 3012 /* 1x1 only */
3015 tbl_type.ant_type = 3013 tbl_type.ant_type =
3016 first_antenna(priv->hw_params.valid_tx_ant); 3014 first_antenna(priv->eeprom_data->valid_tx_ant);
3017 } 3015 }
3018 3016
3019 /* Indicate to uCode which entries might be MIMO. 3017 /* Indicate to uCode which entries might be MIMO.
@@ -3100,7 +3098,7 @@ static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
3100 u8 ant_sel_tx; 3098 u8 ant_sel_tx;
3101 3099
3102 priv = lq_sta->drv; 3100 priv = lq_sta->drv;
3103 valid_tx_ant = priv->hw_params.valid_tx_ant; 3101 valid_tx_ant = priv->eeprom_data->valid_tx_ant;
3104 if (lq_sta->dbg_fixed_rate) { 3102 if (lq_sta->dbg_fixed_rate) {
3105 ant_sel_tx = 3103 ant_sel_tx =
3106 ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK) 3104 ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK)
@@ -3171,9 +3169,9 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
3171 desc += sprintf(buff+desc, "fixed rate 0x%X\n", 3169 desc += sprintf(buff+desc, "fixed rate 0x%X\n",
3172 lq_sta->dbg_fixed_rate); 3170 lq_sta->dbg_fixed_rate);
3173 desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n", 3171 desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n",
3174 (priv->hw_params.valid_tx_ant & ANT_A) ? "ANT_A," : "", 3172 (priv->eeprom_data->valid_tx_ant & ANT_A) ? "ANT_A," : "",
3175 (priv->hw_params.valid_tx_ant & ANT_B) ? "ANT_B," : "", 3173 (priv->eeprom_data->valid_tx_ant & ANT_B) ? "ANT_B," : "",
3176 (priv->hw_params.valid_tx_ant & ANT_C) ? "ANT_C" : ""); 3174 (priv->eeprom_data->valid_tx_ant & ANT_C) ? "ANT_C" : "");
3177 desc += sprintf(buff+desc, "lq type %s\n", 3175 desc += sprintf(buff+desc, "lq type %s\n",
3178 (is_legacy(tbl->lq_type)) ? "legacy" : "HT"); 3176 (is_legacy(tbl->lq_type)) ? "legacy" : "HT");
3179 if (is_Ht(tbl->lq_type)) { 3177 if (is_Ht(tbl->lq_type)) {
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.h b/drivers/net/wireless/iwlwifi/dvm/rs.h
index 82d02e1ae89f..ad3aea8f626a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.h
+++ b/drivers/net/wireless/iwlwifi/dvm/rs.h
@@ -29,9 +29,10 @@
29 29
30#include <net/mac80211.h> 30#include <net/mac80211.h>
31 31
32#include "iwl-commands.h"
33#include "iwl-config.h" 32#include "iwl-config.h"
34 33
34#include "commands.h"
35
35struct iwl_rate_info { 36struct iwl_rate_info {
36 u8 plcp; /* uCode API: IWL_RATE_6M_PLCP, etc. */ 37 u8 plcp; /* uCode API: IWL_RATE_6M_PLCP, etc. */
37 u8 plcp_siso; /* uCode API: IWL_RATE_SISO_6M_PLCP, etc. */ 38 u8 plcp_siso; /* uCode API: IWL_RATE_SISO_6M_PLCP, etc. */
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rx.c b/drivers/net/wireless/iwlwifi/dvm/rx.c
index 403de96f9747..c1f7a18e08dd 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rx.c
+++ b/drivers/net/wireless/iwlwifi/dvm/rx.c
@@ -32,12 +32,10 @@
32#include <linux/sched.h> 32#include <linux/sched.h>
33#include <net/mac80211.h> 33#include <net/mac80211.h>
34#include <asm/unaligned.h> 34#include <asm/unaligned.h>
35#include "iwl-eeprom.h"
36#include "iwl-dev.h"
37#include "iwl-io.h" 35#include "iwl-io.h"
38#include "iwl-agn-calib.h" 36#include "dev.h"
39#include "iwl-agn.h" 37#include "calib.h"
40#include "iwl-modparams.h" 38#include "agn.h"
41 39
42#define IWL_CMD_ENTRY(x) [x] = #x 40#define IWL_CMD_ENTRY(x) [x] = #x
43 41
@@ -1012,6 +1010,8 @@ static int iwlagn_rx_reply_rx(struct iwl_priv *priv,
1012 rx_status.flag |= RX_FLAG_40MHZ; 1010 rx_status.flag |= RX_FLAG_40MHZ;
1013 if (rate_n_flags & RATE_MCS_SGI_MSK) 1011 if (rate_n_flags & RATE_MCS_SGI_MSK)
1014 rx_status.flag |= RX_FLAG_SHORT_GI; 1012 rx_status.flag |= RX_FLAG_SHORT_GI;
1013 if (rate_n_flags & RATE_MCS_GF_MSK)
1014 rx_status.flag |= RX_FLAG_HT_GF;
1015 1015
1016 iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status, 1016 iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status,
1017 rxb, &rx_status); 1017 rxb, &rx_status);
@@ -1124,8 +1124,6 @@ int iwl_rx_dispatch(struct iwl_op_mode *op_mode, struct iwl_rx_cmd_buffer *rxb,
1124{ 1124{
1125 struct iwl_rx_packet *pkt = rxb_addr(rxb); 1125 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1126 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 1126 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
1127 void (*pre_rx_handler)(struct iwl_priv *,
1128 struct iwl_rx_cmd_buffer *);
1129 int err = 0; 1127 int err = 0;
1130 1128
1131 /* 1129 /*
@@ -1135,19 +1133,19 @@ int iwl_rx_dispatch(struct iwl_op_mode *op_mode, struct iwl_rx_cmd_buffer *rxb,
1135 */ 1133 */
1136 iwl_notification_wait_notify(&priv->notif_wait, pkt); 1134 iwl_notification_wait_notify(&priv->notif_wait, pkt);
1137 1135
1138 /* RX data may be forwarded to userspace (using pre_rx_handler) in one 1136#ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
1139 * of two cases: the first, that the user owns the uCode through 1137 /*
1140 * testmode - in such case the pre_rx_handler is set and no further 1138 * RX data may be forwarded to userspace in one
1141 * processing takes place. The other case is when the user want to 1139 * of two cases: the user owns the fw through testmode or when
1142 * monitor the rx w/o affecting the regular flow - the pre_rx_handler 1140 * the user requested to monitor the rx w/o affecting the regular flow.
1143 * will be set but the ownership flag != IWL_OWNERSHIP_TM and the flow 1141 * In these cases the iwl_test object will handle forwarding the rx
1142 * data to user space.
1143 * Note that if the ownership flag != IWL_OWNERSHIP_TM the flow
1144 * continues. 1144 * continues.
1145 * We need to use ACCESS_ONCE to prevent a case where the handler
1146 * changes between the check and the call.
1147 */ 1145 */
1148 pre_rx_handler = ACCESS_ONCE(priv->pre_rx_handler); 1146 iwl_test_rx(&priv->tst, rxb);
1149 if (pre_rx_handler) 1147#endif
1150 pre_rx_handler(priv, rxb); 1148
1151 if (priv->ucode_owner != IWL_OWNERSHIP_TM) { 1149 if (priv->ucode_owner != IWL_OWNERSHIP_TM) {
1152 /* Based on type of command response or notification, 1150 /* Based on type of command response or notification,
1153 * handle those that need handling via function in 1151 * handle those that need handling via function in
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c b/drivers/net/wireless/iwlwifi/dvm/rxon.c
index 0a3aa7c83003..6ee940f497f9 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c
+++ b/drivers/net/wireless/iwlwifi/dvm/rxon.c
@@ -25,11 +25,11 @@
25 *****************************************************************************/ 25 *****************************************************************************/
26 26
27#include <linux/etherdevice.h> 27#include <linux/etherdevice.h>
28#include "iwl-dev.h"
29#include "iwl-agn.h"
30#include "iwl-agn-calib.h"
31#include "iwl-trans.h" 28#include "iwl-trans.h"
32#include "iwl-modparams.h" 29#include "iwl-modparams.h"
30#include "dev.h"
31#include "agn.h"
32#include "calib.h"
33 33
34/* 34/*
35 * initialize rxon structure with default values from eeprom 35 * initialize rxon structure with default values from eeprom
@@ -37,8 +37,6 @@
37void iwl_connection_init_rx_config(struct iwl_priv *priv, 37void iwl_connection_init_rx_config(struct iwl_priv *priv,
38 struct iwl_rxon_context *ctx) 38 struct iwl_rxon_context *ctx)
39{ 39{
40 const struct iwl_channel_info *ch_info;
41
42 memset(&ctx->staging, 0, sizeof(ctx->staging)); 40 memset(&ctx->staging, 0, sizeof(ctx->staging));
43 41
44 if (!ctx->vif) { 42 if (!ctx->vif) {
@@ -80,14 +78,8 @@ void iwl_connection_init_rx_config(struct iwl_priv *priv,
80 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; 78 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
81#endif 79#endif
82 80
83 ch_info = iwl_get_channel_info(priv, priv->band, 81 ctx->staging.channel = cpu_to_le16(priv->hw->conf.channel->hw_value);
84 le16_to_cpu(ctx->active.channel)); 82 priv->band = priv->hw->conf.channel->band;
85
86 if (!ch_info)
87 ch_info = &priv->channel_info[0];
88
89 ctx->staging.channel = cpu_to_le16(ch_info->channel);
90 priv->band = ch_info->band;
91 83
92 iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif); 84 iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
93 85
@@ -175,7 +167,8 @@ static int iwlagn_disconn_pan(struct iwl_priv *priv,
175 return ret; 167 return ret;
176} 168}
177 169
178void iwlagn_update_qos(struct iwl_priv *priv, struct iwl_rxon_context *ctx) 170static void iwlagn_update_qos(struct iwl_priv *priv,
171 struct iwl_rxon_context *ctx)
179{ 172{
180 int ret; 173 int ret;
181 174
@@ -202,8 +195,8 @@ void iwlagn_update_qos(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
202 IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n"); 195 IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
203} 196}
204 197
205int iwlagn_update_beacon(struct iwl_priv *priv, 198static int iwlagn_update_beacon(struct iwl_priv *priv,
206 struct ieee80211_vif *vif) 199 struct ieee80211_vif *vif)
207{ 200{
208 lockdep_assert_held(&priv->mutex); 201 lockdep_assert_held(&priv->mutex);
209 202
@@ -215,7 +208,7 @@ int iwlagn_update_beacon(struct iwl_priv *priv,
215} 208}
216 209
217static int iwlagn_send_rxon_assoc(struct iwl_priv *priv, 210static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
218 struct iwl_rxon_context *ctx) 211 struct iwl_rxon_context *ctx)
219{ 212{
220 int ret = 0; 213 int ret = 0;
221 struct iwl_rxon_assoc_cmd rxon_assoc; 214 struct iwl_rxon_assoc_cmd rxon_assoc;
@@ -427,10 +420,10 @@ static int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
427 return -EINVAL; 420 return -EINVAL;
428 } 421 }
429 422
430 if (tx_power > priv->tx_power_device_lmt) { 423 if (tx_power > DIV_ROUND_UP(priv->eeprom_data->max_tx_pwr_half_dbm, 2)) {
431 IWL_WARN(priv, 424 IWL_WARN(priv,
432 "Requested user TXPOWER %d above upper limit %d.\n", 425 "Requested user TXPOWER %d above upper limit %d.\n",
433 tx_power, priv->tx_power_device_lmt); 426 tx_power, priv->eeprom_data->max_tx_pwr_half_dbm);
434 return -EINVAL; 427 return -EINVAL;
435 } 428 }
436 429
@@ -863,8 +856,8 @@ static int iwl_check_rxon_cmd(struct iwl_priv *priv,
863 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that 856 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
864 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required. 857 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
865 */ 858 */
866int iwl_full_rxon_required(struct iwl_priv *priv, 859static int iwl_full_rxon_required(struct iwl_priv *priv,
867 struct iwl_rxon_context *ctx) 860 struct iwl_rxon_context *ctx)
868{ 861{
869 const struct iwl_rxon_cmd *staging = &ctx->staging; 862 const struct iwl_rxon_cmd *staging = &ctx->staging;
870 const struct iwl_rxon_cmd *active = &ctx->active; 863 const struct iwl_rxon_cmd *active = &ctx->active;
@@ -1189,7 +1182,6 @@ int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
1189 struct iwl_rxon_context *ctx; 1182 struct iwl_rxon_context *ctx;
1190 struct ieee80211_conf *conf = &hw->conf; 1183 struct ieee80211_conf *conf = &hw->conf;
1191 struct ieee80211_channel *channel = conf->channel; 1184 struct ieee80211_channel *channel = conf->channel;
1192 const struct iwl_channel_info *ch_info;
1193 int ret = 0; 1185 int ret = 0;
1194 1186
1195 IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed); 1187 IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed);
@@ -1223,14 +1215,6 @@ int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
1223 } 1215 }
1224 1216
1225 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { 1217 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1226 ch_info = iwl_get_channel_info(priv, channel->band,
1227 channel->hw_value);
1228 if (!is_channel_valid(ch_info)) {
1229 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
1230 ret = -EINVAL;
1231 goto out;
1232 }
1233
1234 for_each_context(priv, ctx) { 1218 for_each_context(priv, ctx) {
1235 /* Configure HT40 channels */ 1219 /* Configure HT40 channels */
1236 if (ctx->ht.enabled != conf_is_ht(conf)) 1220 if (ctx->ht.enabled != conf_is_ht(conf))
@@ -1294,9 +1278,9 @@ int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
1294 return ret; 1278 return ret;
1295} 1279}
1296 1280
1297void iwlagn_check_needed_chains(struct iwl_priv *priv, 1281static void iwlagn_check_needed_chains(struct iwl_priv *priv,
1298 struct iwl_rxon_context *ctx, 1282 struct iwl_rxon_context *ctx,
1299 struct ieee80211_bss_conf *bss_conf) 1283 struct ieee80211_bss_conf *bss_conf)
1300{ 1284{
1301 struct ieee80211_vif *vif = ctx->vif; 1285 struct ieee80211_vif *vif = ctx->vif;
1302 struct iwl_rxon_context *tmp; 1286 struct iwl_rxon_context *tmp;
@@ -1388,7 +1372,7 @@ void iwlagn_check_needed_chains(struct iwl_priv *priv,
1388 ht_conf->single_chain_sufficient = !need_multiple; 1372 ht_conf->single_chain_sufficient = !need_multiple;
1389} 1373}
1390 1374
1391void iwlagn_chain_noise_reset(struct iwl_priv *priv) 1375static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
1392{ 1376{
1393 struct iwl_chain_noise_data *data = &priv->chain_noise_data; 1377 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
1394 int ret; 1378 int ret;
diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/dvm/scan.c
index 031d8e21f82f..2f271c96ed39 100644
--- a/drivers/net/wireless/iwlwifi/iwl-scan.c
+++ b/drivers/net/wireless/iwlwifi/dvm/scan.c
@@ -30,11 +30,8 @@
30#include <linux/etherdevice.h> 30#include <linux/etherdevice.h>
31#include <net/mac80211.h> 31#include <net/mac80211.h>
32 32
33#include "iwl-eeprom.h" 33#include "dev.h"
34#include "iwl-dev.h" 34#include "agn.h"
35#include "iwl-io.h"
36#include "iwl-agn.h"
37#include "iwl-trans.h"
38 35
39/* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after 36/* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
40 * sending probe req. This should be set long enough to hear probe responses 37 * sending probe req. This should be set long enough to hear probe responses
@@ -67,7 +64,6 @@ static int iwl_send_scan_abort(struct iwl_priv *priv)
67 * to receive scan abort command or it does not perform 64 * to receive scan abort command or it does not perform
68 * hardware scan currently */ 65 * hardware scan currently */
69 if (!test_bit(STATUS_READY, &priv->status) || 66 if (!test_bit(STATUS_READY, &priv->status) ||
70 !test_bit(STATUS_GEO_CONFIGURED, &priv->status) ||
71 !test_bit(STATUS_SCAN_HW, &priv->status) || 67 !test_bit(STATUS_SCAN_HW, &priv->status) ||
72 test_bit(STATUS_FW_ERROR, &priv->status)) 68 test_bit(STATUS_FW_ERROR, &priv->status))
73 return -EIO; 69 return -EIO;
@@ -101,11 +97,8 @@ static void iwl_complete_scan(struct iwl_priv *priv, bool aborted)
101 ieee80211_scan_completed(priv->hw, aborted); 97 ieee80211_scan_completed(priv->hw, aborted);
102 } 98 }
103 99
104 if (priv->scan_type == IWL_SCAN_ROC) { 100 if (priv->scan_type == IWL_SCAN_ROC)
105 ieee80211_remain_on_channel_expired(priv->hw); 101 iwl_scan_roc_expired(priv);
106 priv->hw_roc_channel = NULL;
107 schedule_delayed_work(&priv->hw_roc_disable_work, 10 * HZ);
108 }
109 102
110 priv->scan_type = IWL_SCAN_NORMAL; 103 priv->scan_type = IWL_SCAN_NORMAL;
111 priv->scan_vif = NULL; 104 priv->scan_vif = NULL;
@@ -134,11 +127,8 @@ static void iwl_process_scan_complete(struct iwl_priv *priv)
134 goto out_settings; 127 goto out_settings;
135 } 128 }
136 129
137 if (priv->scan_type == IWL_SCAN_ROC) { 130 if (priv->scan_type == IWL_SCAN_ROC)
138 ieee80211_remain_on_channel_expired(priv->hw); 131 iwl_scan_roc_expired(priv);
139 priv->hw_roc_channel = NULL;
140 schedule_delayed_work(&priv->hw_roc_disable_work, 10 * HZ);
141 }
142 132
143 if (priv->scan_type != IWL_SCAN_NORMAL && !aborted) { 133 if (priv->scan_type != IWL_SCAN_NORMAL && !aborted) {
144 int err; 134 int err;
@@ -453,27 +443,17 @@ static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
453 443
454/* Return valid, unused, channel for a passive scan to reset the RF */ 444/* Return valid, unused, channel for a passive scan to reset the RF */
455static u8 iwl_get_single_channel_number(struct iwl_priv *priv, 445static u8 iwl_get_single_channel_number(struct iwl_priv *priv,
456 enum ieee80211_band band) 446 enum ieee80211_band band)
457{ 447{
458 const struct iwl_channel_info *ch_info; 448 struct ieee80211_supported_band *sband = priv->hw->wiphy->bands[band];
459 int i;
460 u8 channel = 0;
461 u8 min, max;
462 struct iwl_rxon_context *ctx; 449 struct iwl_rxon_context *ctx;
450 int i;
463 451
464 if (band == IEEE80211_BAND_5GHZ) { 452 for (i = 0; i < sband->n_channels; i++) {
465 min = 14;
466 max = priv->channel_count;
467 } else {
468 min = 0;
469 max = 14;
470 }
471
472 for (i = min; i < max; i++) {
473 bool busy = false; 453 bool busy = false;
474 454
475 for_each_context(priv, ctx) { 455 for_each_context(priv, ctx) {
476 busy = priv->channel_info[i].channel == 456 busy = sband->channels[i].hw_value ==
477 le16_to_cpu(ctx->staging.channel); 457 le16_to_cpu(ctx->staging.channel);
478 if (busy) 458 if (busy)
479 break; 459 break;
@@ -482,13 +462,11 @@ static u8 iwl_get_single_channel_number(struct iwl_priv *priv,
482 if (busy) 462 if (busy)
483 continue; 463 continue;
484 464
485 channel = priv->channel_info[i].channel; 465 if (!(sband->channels[i].flags & IEEE80211_CHAN_DISABLED))
486 ch_info = iwl_get_channel_info(priv, band, channel); 466 return sband->channels[i].hw_value;
487 if (is_channel_valid(ch_info))
488 break;
489 } 467 }
490 468
491 return channel; 469 return 0;
492} 470}
493 471
494static int iwl_get_single_channel_for_scan(struct iwl_priv *priv, 472static int iwl_get_single_channel_for_scan(struct iwl_priv *priv,
@@ -540,7 +518,6 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv,
540{ 518{
541 struct ieee80211_channel *chan; 519 struct ieee80211_channel *chan;
542 const struct ieee80211_supported_band *sband; 520 const struct ieee80211_supported_band *sband;
543 const struct iwl_channel_info *ch_info;
544 u16 passive_dwell = 0; 521 u16 passive_dwell = 0;
545 u16 active_dwell = 0; 522 u16 active_dwell = 0;
546 int added, i; 523 int added, i;
@@ -565,16 +542,7 @@ static int iwl_get_channels_for_scan(struct iwl_priv *priv,
565 channel = chan->hw_value; 542 channel = chan->hw_value;
566 scan_ch->channel = cpu_to_le16(channel); 543 scan_ch->channel = cpu_to_le16(channel);
567 544
568 ch_info = iwl_get_channel_info(priv, band, channel); 545 if (!is_active || (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
569 if (!is_channel_valid(ch_info)) {
570 IWL_DEBUG_SCAN(priv,
571 "Channel %d is INVALID for this band.\n",
572 channel);
573 continue;
574 }
575
576 if (!is_active || is_channel_passive(ch_info) ||
577 (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN))
578 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE; 546 scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE;
579 else 547 else
580 scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE; 548 scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE;
@@ -678,12 +646,12 @@ static int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
678 u16 rx_chain = 0; 646 u16 rx_chain = 0;
679 enum ieee80211_band band; 647 enum ieee80211_band band;
680 u8 n_probes = 0; 648 u8 n_probes = 0;
681 u8 rx_ant = priv->hw_params.valid_rx_ant; 649 u8 rx_ant = priv->eeprom_data->valid_rx_ant;
682 u8 rate; 650 u8 rate;
683 bool is_active = false; 651 bool is_active = false;
684 int chan_mod; 652 int chan_mod;
685 u8 active_chains; 653 u8 active_chains;
686 u8 scan_tx_antennas = priv->hw_params.valid_tx_ant; 654 u8 scan_tx_antennas = priv->eeprom_data->valid_tx_ant;
687 int ret; 655 int ret;
688 int scan_cmd_size = sizeof(struct iwl_scan_cmd) + 656 int scan_cmd_size = sizeof(struct iwl_scan_cmd) +
689 MAX_SCAN_CHANNEL * sizeof(struct iwl_scan_channel) + 657 MAX_SCAN_CHANNEL * sizeof(struct iwl_scan_channel) +
@@ -893,7 +861,7 @@ static int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
893 861
894 /* MIMO is not used here, but value is required */ 862 /* MIMO is not used here, but value is required */
895 rx_chain |= 863 rx_chain |=
896 priv->hw_params.valid_rx_ant << RXON_RX_CHAIN_VALID_POS; 864 priv->eeprom_data->valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
897 rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS; 865 rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
898 rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS; 866 rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
899 rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS; 867 rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
@@ -994,8 +962,10 @@ static int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
994 set_bit(STATUS_SCAN_HW, &priv->status); 962 set_bit(STATUS_SCAN_HW, &priv->status);
995 963
996 ret = iwlagn_set_pan_params(priv); 964 ret = iwlagn_set_pan_params(priv);
997 if (ret) 965 if (ret) {
966 clear_bit(STATUS_SCAN_HW, &priv->status);
998 return ret; 967 return ret;
968 }
999 969
1000 ret = iwl_dvm_send_cmd(priv, &cmd); 970 ret = iwl_dvm_send_cmd(priv, &cmd);
1001 if (ret) { 971 if (ret) {
@@ -1008,7 +978,7 @@ static int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
1008 978
1009void iwl_init_scan_params(struct iwl_priv *priv) 979void iwl_init_scan_params(struct iwl_priv *priv)
1010{ 980{
1011 u8 ant_idx = fls(priv->hw_params.valid_tx_ant) - 1; 981 u8 ant_idx = fls(priv->eeprom_data->valid_tx_ant) - 1;
1012 if (!priv->scan_tx_ant[IEEE80211_BAND_5GHZ]) 982 if (!priv->scan_tx_ant[IEEE80211_BAND_5GHZ])
1013 priv->scan_tx_ant[IEEE80211_BAND_5GHZ] = ant_idx; 983 priv->scan_tx_ant[IEEE80211_BAND_5GHZ] = ant_idx;
1014 if (!priv->scan_tx_ant[IEEE80211_BAND_2GHZ]) 984 if (!priv->scan_tx_ant[IEEE80211_BAND_2GHZ])
@@ -1158,3 +1128,40 @@ void iwl_cancel_scan_deferred_work(struct iwl_priv *priv)
1158 mutex_unlock(&priv->mutex); 1128 mutex_unlock(&priv->mutex);
1159 } 1129 }
1160} 1130}
1131
1132void iwl_scan_roc_expired(struct iwl_priv *priv)
1133{
1134 /*
1135 * The status bit should be set here, to prevent a race
1136 * where the atomic_read returns 1, but before the execution continues
1137 * iwl_scan_offchannel_skb_status() checks if the status bit is set
1138 */
1139 set_bit(STATUS_SCAN_ROC_EXPIRED, &priv->status);
1140
1141 if (atomic_read(&priv->num_aux_in_flight) == 0) {
1142 ieee80211_remain_on_channel_expired(priv->hw);
1143 priv->hw_roc_channel = NULL;
1144 schedule_delayed_work(&priv->hw_roc_disable_work,
1145 10 * HZ);
1146
1147 clear_bit(STATUS_SCAN_ROC_EXPIRED, &priv->status);
1148 } else {
1149 IWL_DEBUG_SCAN(priv, "ROC done with %d frames in aux\n",
1150 atomic_read(&priv->num_aux_in_flight));
1151 }
1152}
1153
1154void iwl_scan_offchannel_skb(struct iwl_priv *priv)
1155{
1156 WARN_ON(!priv->hw_roc_start_notified);
1157 atomic_inc(&priv->num_aux_in_flight);
1158}
1159
1160void iwl_scan_offchannel_skb_status(struct iwl_priv *priv)
1161{
1162 if (atomic_dec_return(&priv->num_aux_in_flight) == 0 &&
1163 test_bit(STATUS_SCAN_ROC_EXPIRED, &priv->status)) {
1164 IWL_DEBUG_SCAN(priv, "0 aux frames. Calling ROC expired\n");
1165 iwl_scan_roc_expired(priv);
1166 }
1167}
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-sta.c b/drivers/net/wireless/iwlwifi/dvm/sta.c
index eb6a8eaf42fc..b29b798f7550 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-sta.c
+++ b/drivers/net/wireless/iwlwifi/dvm/sta.c
@@ -28,10 +28,9 @@
28 *****************************************************************************/ 28 *****************************************************************************/
29#include <linux/etherdevice.h> 29#include <linux/etherdevice.h>
30#include <net/mac80211.h> 30#include <net/mac80211.h>
31
32#include "iwl-dev.h"
33#include "iwl-agn.h"
34#include "iwl-trans.h" 31#include "iwl-trans.h"
32#include "dev.h"
33#include "agn.h"
35 34
36const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; 35const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
37 36
@@ -171,26 +170,6 @@ int iwl_send_add_sta(struct iwl_priv *priv,
171 return cmd.handler_status; 170 return cmd.handler_status;
172} 171}
173 172
174static bool iwl_is_channel_extension(struct iwl_priv *priv,
175 enum ieee80211_band band,
176 u16 channel, u8 extension_chan_offset)
177{
178 const struct iwl_channel_info *ch_info;
179
180 ch_info = iwl_get_channel_info(priv, band, channel);
181 if (!is_channel_valid(ch_info))
182 return false;
183
184 if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
185 return !(ch_info->ht40_extension_channel &
186 IEEE80211_CHAN_NO_HT40PLUS);
187 else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
188 return !(ch_info->ht40_extension_channel &
189 IEEE80211_CHAN_NO_HT40MINUS);
190
191 return false;
192}
193
194bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv, 173bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
195 struct iwl_rxon_context *ctx, 174 struct iwl_rxon_context *ctx,
196 struct ieee80211_sta_ht_cap *ht_cap) 175 struct ieee80211_sta_ht_cap *ht_cap)
@@ -198,21 +177,25 @@ bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
198 if (!ctx->ht.enabled || !ctx->ht.is_40mhz) 177 if (!ctx->ht.enabled || !ctx->ht.is_40mhz)
199 return false; 178 return false;
200 179
180#ifdef CONFIG_IWLWIFI_DEBUGFS
181 if (priv->disable_ht40)
182 return false;
183#endif
184
201 /* 185 /*
202 * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40 186 * Remainder of this function checks ht_cap, but if it's
203 * the bit will not set if it is pure 40MHz case 187 * NULL then we can do HT40 (special case for RXON)
204 */ 188 */
205 if (ht_cap && !ht_cap->ht_supported) 189 if (!ht_cap)
190 return true;
191
192 if (!ht_cap->ht_supported)
206 return false; 193 return false;
207 194
208#ifdef CONFIG_IWLWIFI_DEBUGFS 195 if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
209 if (priv->disable_ht40)
210 return false; 196 return false;
211#endif
212 197
213 return iwl_is_channel_extension(priv, priv->band, 198 return true;
214 le16_to_cpu(ctx->staging.channel),
215 ctx->ht.extension_chan_offset);
216} 199}
217 200
218static void iwl_sta_calc_ht_flags(struct iwl_priv *priv, 201static void iwl_sta_calc_ht_flags(struct iwl_priv *priv,
@@ -236,6 +219,7 @@ static void iwl_sta_calc_ht_flags(struct iwl_priv *priv,
236 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; 219 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2;
237 220
238 IWL_DEBUG_INFO(priv, "STA %pM SM PS mode: %s\n", 221 IWL_DEBUG_INFO(priv, "STA %pM SM PS mode: %s\n",
222 sta->addr,
239 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ? 223 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ?
240 "static" : 224 "static" :
241 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ? 225 (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ?
@@ -649,23 +633,23 @@ static void iwl_sta_fill_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
649 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE) 633 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
650 rate_flags |= RATE_MCS_CCK_MSK; 634 rate_flags |= RATE_MCS_CCK_MSK;
651 635
652 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) << 636 rate_flags |= first_antenna(priv->eeprom_data->valid_tx_ant) <<
653 RATE_MCS_ANT_POS; 637 RATE_MCS_ANT_POS;
654 rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags); 638 rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
655 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) 639 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
656 link_cmd->rs_table[i].rate_n_flags = rate_n_flags; 640 link_cmd->rs_table[i].rate_n_flags = rate_n_flags;
657 641
658 link_cmd->general_params.single_stream_ant_msk = 642 link_cmd->general_params.single_stream_ant_msk =
659 first_antenna(priv->hw_params.valid_tx_ant); 643 first_antenna(priv->eeprom_data->valid_tx_ant);
660 644
661 link_cmd->general_params.dual_stream_ant_msk = 645 link_cmd->general_params.dual_stream_ant_msk =
662 priv->hw_params.valid_tx_ant & 646 priv->eeprom_data->valid_tx_ant &
663 ~first_antenna(priv->hw_params.valid_tx_ant); 647 ~first_antenna(priv->eeprom_data->valid_tx_ant);
664 if (!link_cmd->general_params.dual_stream_ant_msk) { 648 if (!link_cmd->general_params.dual_stream_ant_msk) {
665 link_cmd->general_params.dual_stream_ant_msk = ANT_AB; 649 link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
666 } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) { 650 } else if (num_of_ant(priv->eeprom_data->valid_tx_ant) == 2) {
667 link_cmd->general_params.dual_stream_ant_msk = 651 link_cmd->general_params.dual_stream_ant_msk =
668 priv->hw_params.valid_tx_ant; 652 priv->eeprom_data->valid_tx_ant;
669 } 653 }
670 654
671 link_cmd->agg_params.agg_dis_start_th = 655 link_cmd->agg_params.agg_dis_start_th =
diff --git a/drivers/net/wireless/iwlwifi/dvm/testmode.c b/drivers/net/wireless/iwlwifi/dvm/testmode.c
new file mode 100644
index 000000000000..57b918ce3b5f
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/dvm/testmode.c
@@ -0,0 +1,471 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63
64#include <linux/init.h>
65#include <linux/kernel.h>
66#include <linux/module.h>
67#include <linux/dma-mapping.h>
68#include <net/net_namespace.h>
69#include <linux/netdevice.h>
70#include <net/cfg80211.h>
71#include <net/mac80211.h>
72#include <net/netlink.h>
73
74#include "iwl-debug.h"
75#include "iwl-trans.h"
76#include "dev.h"
77#include "agn.h"
78#include "iwl-test.h"
79#include "iwl-testmode.h"
80
81static int iwl_testmode_send_cmd(struct iwl_op_mode *op_mode,
82 struct iwl_host_cmd *cmd)
83{
84 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
85 return iwl_dvm_send_cmd(priv, cmd);
86}
87
88static bool iwl_testmode_valid_hw_addr(u32 addr)
89{
90 if (iwlagn_hw_valid_rtc_data_addr(addr))
91 return true;
92
93 if (IWLAGN_RTC_INST_LOWER_BOUND <= addr &&
94 addr < IWLAGN_RTC_INST_UPPER_BOUND)
95 return true;
96
97 return false;
98}
99
100static u32 iwl_testmode_get_fw_ver(struct iwl_op_mode *op_mode)
101{
102 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
103 return priv->fw->ucode_ver;
104}
105
106static struct sk_buff*
107iwl_testmode_alloc_reply(struct iwl_op_mode *op_mode, int len)
108{
109 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
110 return cfg80211_testmode_alloc_reply_skb(priv->hw->wiphy, len);
111}
112
113static int iwl_testmode_reply(struct iwl_op_mode *op_mode, struct sk_buff *skb)
114{
115 return cfg80211_testmode_reply(skb);
116}
117
118static struct sk_buff *iwl_testmode_alloc_event(struct iwl_op_mode *op_mode,
119 int len)
120{
121 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
122 return cfg80211_testmode_alloc_event_skb(priv->hw->wiphy, len,
123 GFP_ATOMIC);
124}
125
126static void iwl_testmode_event(struct iwl_op_mode *op_mode, struct sk_buff *skb)
127{
128 return cfg80211_testmode_event(skb, GFP_ATOMIC);
129}
130
131static struct iwl_test_ops tst_ops = {
132 .send_cmd = iwl_testmode_send_cmd,
133 .valid_hw_addr = iwl_testmode_valid_hw_addr,
134 .get_fw_ver = iwl_testmode_get_fw_ver,
135 .alloc_reply = iwl_testmode_alloc_reply,
136 .reply = iwl_testmode_reply,
137 .alloc_event = iwl_testmode_alloc_event,
138 .event = iwl_testmode_event,
139};
140
141void iwl_testmode_init(struct iwl_priv *priv)
142{
143 iwl_test_init(&priv->tst, priv->trans, &tst_ops);
144}
145
146void iwl_testmode_free(struct iwl_priv *priv)
147{
148 iwl_test_free(&priv->tst);
149}
150
151static int iwl_testmode_cfg_init_calib(struct iwl_priv *priv)
152{
153 struct iwl_notification_wait calib_wait;
154 static const u8 calib_complete[] = {
155 CALIBRATION_COMPLETE_NOTIFICATION
156 };
157 int ret;
158
159 iwl_init_notification_wait(&priv->notif_wait, &calib_wait,
160 calib_complete, ARRAY_SIZE(calib_complete),
161 NULL, NULL);
162 ret = iwl_init_alive_start(priv);
163 if (ret) {
164 IWL_ERR(priv, "Fail init calibration: %d\n", ret);
165 goto cfg_init_calib_error;
166 }
167
168 ret = iwl_wait_notification(&priv->notif_wait, &calib_wait, 2 * HZ);
169 if (ret)
170 IWL_ERR(priv, "Error detecting"
171 " CALIBRATION_COMPLETE_NOTIFICATION: %d\n", ret);
172 return ret;
173
174cfg_init_calib_error:
175 iwl_remove_notification(&priv->notif_wait, &calib_wait);
176 return ret;
177}
178
179/*
180 * This function handles the user application commands for driver.
181 *
182 * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the
183 * handlers respectively.
184 *
185 * If it's an unknown commdn ID, -ENOSYS is replied; otherwise, the returned
186 * value of the actual command execution is replied to the user application.
187 *
188 * If there's any message responding to the user space, IWL_TM_ATTR_SYNC_RSP
189 * is used for carry the message while IWL_TM_ATTR_COMMAND must set to
190 * IWL_TM_CMD_DEV2APP_SYNC_RSP.
191 *
192 * @hw: ieee80211_hw object that represents the device
193 * @tb: gnl message fields from the user space
194 */
195static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb)
196{
197 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
198 struct iwl_trans *trans = priv->trans;
199 struct sk_buff *skb;
200 unsigned char *rsp_data_ptr = NULL;
201 int status = 0, rsp_data_len = 0;
202 u32 inst_size = 0, data_size = 0;
203 const struct fw_img *img;
204
205 switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
206 case IWL_TM_CMD_APP2DEV_GET_DEVICENAME:
207 rsp_data_ptr = (unsigned char *)priv->cfg->name;
208 rsp_data_len = strlen(priv->cfg->name);
209 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
210 rsp_data_len + 20);
211 if (!skb) {
212 IWL_ERR(priv, "Memory allocation fail\n");
213 return -ENOMEM;
214 }
215 if (nla_put_u32(skb, IWL_TM_ATTR_COMMAND,
216 IWL_TM_CMD_DEV2APP_SYNC_RSP) ||
217 nla_put(skb, IWL_TM_ATTR_SYNC_RSP,
218 rsp_data_len, rsp_data_ptr))
219 goto nla_put_failure;
220 status = cfg80211_testmode_reply(skb);
221 if (status < 0)
222 IWL_ERR(priv, "Error sending msg : %d\n", status);
223 break;
224
225 case IWL_TM_CMD_APP2DEV_LOAD_INIT_FW:
226 status = iwl_load_ucode_wait_alive(priv, IWL_UCODE_INIT);
227 if (status)
228 IWL_ERR(priv, "Error loading init ucode: %d\n", status);
229 break;
230
231 case IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB:
232 iwl_testmode_cfg_init_calib(priv);
233 priv->ucode_loaded = false;
234 iwl_trans_stop_device(trans);
235 break;
236
237 case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW:
238 status = iwl_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR);
239 if (status) {
240 IWL_ERR(priv,
241 "Error loading runtime ucode: %d\n", status);
242 break;
243 }
244 status = iwl_alive_start(priv);
245 if (status)
246 IWL_ERR(priv,
247 "Error starting the device: %d\n", status);
248 break;
249
250 case IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW:
251 iwl_scan_cancel_timeout(priv, 200);
252 priv->ucode_loaded = false;
253 iwl_trans_stop_device(trans);
254 status = iwl_load_ucode_wait_alive(priv, IWL_UCODE_WOWLAN);
255 if (status) {
256 IWL_ERR(priv,
257 "Error loading WOWLAN ucode: %d\n", status);
258 break;
259 }
260 status = iwl_alive_start(priv);
261 if (status)
262 IWL_ERR(priv,
263 "Error starting the device: %d\n", status);
264 break;
265
266 case IWL_TM_CMD_APP2DEV_GET_EEPROM:
267 if (priv->eeprom_blob) {
268 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
269 priv->eeprom_blob_size + 20);
270 if (!skb) {
271 IWL_ERR(priv, "Memory allocation fail\n");
272 return -ENOMEM;
273 }
274 if (nla_put_u32(skb, IWL_TM_ATTR_COMMAND,
275 IWL_TM_CMD_DEV2APP_EEPROM_RSP) ||
276 nla_put(skb, IWL_TM_ATTR_EEPROM,
277 priv->eeprom_blob_size,
278 priv->eeprom_blob))
279 goto nla_put_failure;
280 status = cfg80211_testmode_reply(skb);
281 if (status < 0)
282 IWL_ERR(priv, "Error sending msg : %d\n",
283 status);
284 } else
285 return -ENODATA;
286 break;
287
288 case IWL_TM_CMD_APP2DEV_FIXRATE_REQ:
289 if (!tb[IWL_TM_ATTR_FIXRATE]) {
290 IWL_ERR(priv, "Missing fixrate setting\n");
291 return -ENOMSG;
292 }
293 priv->tm_fixed_rate = nla_get_u32(tb[IWL_TM_ATTR_FIXRATE]);
294 break;
295
296 case IWL_TM_CMD_APP2DEV_GET_FW_INFO:
297 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20 + 8);
298 if (!skb) {
299 IWL_ERR(priv, "Memory allocation fail\n");
300 return -ENOMEM;
301 }
302 if (!priv->ucode_loaded) {
303 IWL_ERR(priv, "No uCode has not been loaded\n");
304 return -EINVAL;
305 } else {
306 img = &priv->fw->img[priv->cur_ucode];
307 inst_size = img->sec[IWL_UCODE_SECTION_INST].len;
308 data_size = img->sec[IWL_UCODE_SECTION_DATA].len;
309 }
310 if (nla_put_u32(skb, IWL_TM_ATTR_FW_TYPE, priv->cur_ucode) ||
311 nla_put_u32(skb, IWL_TM_ATTR_FW_INST_SIZE, inst_size) ||
312 nla_put_u32(skb, IWL_TM_ATTR_FW_DATA_SIZE, data_size))
313 goto nla_put_failure;
314 status = cfg80211_testmode_reply(skb);
315 if (status < 0)
316 IWL_ERR(priv, "Error sending msg : %d\n", status);
317 break;
318
319 default:
320 IWL_ERR(priv, "Unknown testmode driver command ID\n");
321 return -ENOSYS;
322 }
323 return status;
324
325nla_put_failure:
326 kfree_skb(skb);
327 return -EMSGSIZE;
328}
329
330/*
331 * This function handles the user application switch ucode ownership.
332 *
333 * It retrieves the mandatory fields IWL_TM_ATTR_UCODE_OWNER and
334 * decide who the current owner of the uCode
335 *
336 * If the current owner is OWNERSHIP_TM, then the only host command
337 * can deliver to uCode is from testmode, all the other host commands
338 * will dropped.
339 *
340 * default driver is the owner of uCode in normal operational mode
341 *
342 * @hw: ieee80211_hw object that represents the device
343 * @tb: gnl message fields from the user space
344 */
345static int iwl_testmode_ownership(struct ieee80211_hw *hw, struct nlattr **tb)
346{
347 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
348 u8 owner;
349
350 if (!tb[IWL_TM_ATTR_UCODE_OWNER]) {
351 IWL_ERR(priv, "Missing ucode owner\n");
352 return -ENOMSG;
353 }
354
355 owner = nla_get_u8(tb[IWL_TM_ATTR_UCODE_OWNER]);
356 if (owner == IWL_OWNERSHIP_DRIVER) {
357 priv->ucode_owner = owner;
358 iwl_test_enable_notifications(&priv->tst, false);
359 } else if (owner == IWL_OWNERSHIP_TM) {
360 priv->ucode_owner = owner;
361 iwl_test_enable_notifications(&priv->tst, true);
362 } else {
363 IWL_ERR(priv, "Invalid owner\n");
364 return -EINVAL;
365 }
366 return 0;
367}
368
369/* The testmode gnl message handler that takes the gnl message from the
370 * user space and parses it per the policy iwl_testmode_gnl_msg_policy, then
371 * invoke the corresponding handlers.
372 *
373 * This function is invoked when there is user space application sending
374 * gnl message through the testmode tunnel NL80211_CMD_TESTMODE regulated
375 * by nl80211.
376 *
377 * It retrieves the mandatory field, IWL_TM_ATTR_COMMAND, before
378 * dispatching it to the corresponding handler.
379 *
380 * If IWL_TM_ATTR_COMMAND is missing, -ENOMSG is replied to user application;
381 * -ENOSYS is replied to the user application if the command is unknown;
382 * Otherwise, the command is dispatched to the respective handler.
383 *
384 * @hw: ieee80211_hw object that represents the device
385 * @data: pointer to user space message
386 * @len: length in byte of @data
387 */
388int iwlagn_mac_testmode_cmd(struct ieee80211_hw *hw, void *data, int len)
389{
390 struct nlattr *tb[IWL_TM_ATTR_MAX];
391 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
392 int result;
393
394 result = iwl_test_parse(&priv->tst, tb, data, len);
395 if (result)
396 return result;
397
398 /* in case multiple accesses to the device happens */
399 mutex_lock(&priv->mutex);
400 switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
401 case IWL_TM_CMD_APP2DEV_UCODE:
402 case IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32:
403 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32:
404 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8:
405 case IWL_TM_CMD_APP2DEV_BEGIN_TRACE:
406 case IWL_TM_CMD_APP2DEV_END_TRACE:
407 case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ:
408 case IWL_TM_CMD_APP2DEV_NOTIFICATIONS:
409 case IWL_TM_CMD_APP2DEV_GET_FW_VERSION:
410 case IWL_TM_CMD_APP2DEV_GET_DEVICE_ID:
411 case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_WRITE:
412 result = iwl_test_handle_cmd(&priv->tst, tb);
413 break;
414
415 case IWL_TM_CMD_APP2DEV_GET_DEVICENAME:
416 case IWL_TM_CMD_APP2DEV_LOAD_INIT_FW:
417 case IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB:
418 case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW:
419 case IWL_TM_CMD_APP2DEV_GET_EEPROM:
420 case IWL_TM_CMD_APP2DEV_FIXRATE_REQ:
421 case IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW:
422 case IWL_TM_CMD_APP2DEV_GET_FW_INFO:
423 IWL_DEBUG_INFO(priv, "testmode cmd to driver\n");
424 result = iwl_testmode_driver(hw, tb);
425 break;
426
427 case IWL_TM_CMD_APP2DEV_OWNERSHIP:
428 IWL_DEBUG_INFO(priv, "testmode change uCode ownership\n");
429 result = iwl_testmode_ownership(hw, tb);
430 break;
431
432 default:
433 IWL_ERR(priv, "Unknown testmode command\n");
434 result = -ENOSYS;
435 break;
436 }
437 mutex_unlock(&priv->mutex);
438
439 if (result)
440 IWL_ERR(priv, "Test cmd failed result=%d\n", result);
441 return result;
442}
443
444int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb,
445 struct netlink_callback *cb,
446 void *data, int len)
447{
448 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
449 int result;
450 u32 cmd;
451
452 if (cb->args[3]) {
453 /* offset by 1 since commands start at 0 */
454 cmd = cb->args[3] - 1;
455 } else {
456 struct nlattr *tb[IWL_TM_ATTR_MAX];
457
458 result = iwl_test_parse(&priv->tst, tb, data, len);
459 if (result)
460 return result;
461
462 cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]);
463 cb->args[3] = cmd + 1;
464 }
465
466 /* in case multiple accesses to the device happens */
467 mutex_lock(&priv->mutex);
468 result = iwl_test_dump(&priv->tst, cmd, skb, cb);
469 mutex_unlock(&priv->mutex);
470 return result;
471}
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tt.c b/drivers/net/wireless/iwlwifi/dvm/tt.c
index a5cfe0aceedb..eb864433e59d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-tt.c
+++ b/drivers/net/wireless/iwlwifi/dvm/tt.c
@@ -31,17 +31,14 @@
31#include <linux/module.h> 31#include <linux/module.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/init.h> 33#include <linux/init.h>
34
35#include <net/mac80211.h> 34#include <net/mac80211.h>
36
37#include "iwl-agn.h"
38#include "iwl-eeprom.h"
39#include "iwl-dev.h"
40#include "iwl-io.h" 35#include "iwl-io.h"
41#include "iwl-commands.h"
42#include "iwl-debug.h"
43#include "iwl-agn-tt.h"
44#include "iwl-modparams.h" 36#include "iwl-modparams.h"
37#include "iwl-debug.h"
38#include "agn.h"
39#include "dev.h"
40#include "commands.h"
41#include "tt.h"
45 42
46/* default Thermal Throttling transaction table 43/* default Thermal Throttling transaction table
47 * Current state | Throttling Down | Throttling Up 44 * Current state | Throttling Down | Throttling Up
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tt.h b/drivers/net/wireless/iwlwifi/dvm/tt.h
index 86bbf47501c1..44c7c8f30a2d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-tt.h
+++ b/drivers/net/wireless/iwlwifi/dvm/tt.h
@@ -28,7 +28,7 @@
28#ifndef __iwl_tt_setting_h__ 28#ifndef __iwl_tt_setting_h__
29#define __iwl_tt_setting_h__ 29#define __iwl_tt_setting_h__
30 30
31#include "iwl-commands.h" 31#include "commands.h"
32 32
33#define IWL_ABSOLUTE_ZERO 0 33#define IWL_ABSOLUTE_ZERO 0
34#define IWL_ABSOLUTE_MAX 0xFFFFFFFF 34#define IWL_ABSOLUTE_MAX 0xFFFFFFFF
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c b/drivers/net/wireless/iwlwifi/dvm/tx.c
index 3366e2e2f00f..5971a23aa47d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
+++ b/drivers/net/wireless/iwlwifi/dvm/tx.c
@@ -32,12 +32,11 @@
32#include <linux/init.h> 32#include <linux/init.h>
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/ieee80211.h> 34#include <linux/ieee80211.h>
35
36#include "iwl-dev.h"
37#include "iwl-io.h" 35#include "iwl-io.h"
38#include "iwl-agn-hw.h"
39#include "iwl-agn.h"
40#include "iwl-trans.h" 36#include "iwl-trans.h"
37#include "iwl-agn-hw.h"
38#include "dev.h"
39#include "agn.h"
41 40
42static const u8 tid_to_ac[] = { 41static const u8 tid_to_ac[] = {
43 IEEE80211_AC_BE, 42 IEEE80211_AC_BE,
@@ -187,7 +186,8 @@ static void iwlagn_tx_cmd_build_rate(struct iwl_priv *priv,
187 rate_idx = info->control.rates[0].idx; 186 rate_idx = info->control.rates[0].idx;
188 if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS || 187 if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS ||
189 (rate_idx < 0) || (rate_idx > IWL_RATE_COUNT_LEGACY)) 188 (rate_idx < 0) || (rate_idx > IWL_RATE_COUNT_LEGACY))
190 rate_idx = rate_lowest_index(&priv->bands[info->band], 189 rate_idx = rate_lowest_index(
190 &priv->eeprom_data->bands[info->band],
191 info->control.sta); 191 info->control.sta);
192 /* For 5 GHZ band, remap mac80211 rate indices into driver indices */ 192 /* For 5 GHZ band, remap mac80211 rate indices into driver indices */
193 if (info->band == IEEE80211_BAND_5GHZ) 193 if (info->band == IEEE80211_BAND_5GHZ)
@@ -207,10 +207,11 @@ static void iwlagn_tx_cmd_build_rate(struct iwl_priv *priv,
207 priv->bt_full_concurrent) { 207 priv->bt_full_concurrent) {
208 /* operated as 1x1 in full concurrency mode */ 208 /* operated as 1x1 in full concurrency mode */
209 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant, 209 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
210 first_antenna(priv->hw_params.valid_tx_ant)); 210 first_antenna(priv->eeprom_data->valid_tx_ant));
211 } else 211 } else
212 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant, 212 priv->mgmt_tx_ant = iwl_toggle_tx_ant(
213 priv->hw_params.valid_tx_ant); 213 priv, priv->mgmt_tx_ant,
214 priv->eeprom_data->valid_tx_ant);
214 rate_flags |= iwl_ant_idx_to_flags(priv->mgmt_tx_ant); 215 rate_flags |= iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
215 216
216 /* Set the rate in the TX cmd */ 217 /* Set the rate in the TX cmd */
@@ -296,7 +297,7 @@ int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
296 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 297 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
297 struct iwl_station_priv *sta_priv = NULL; 298 struct iwl_station_priv *sta_priv = NULL;
298 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; 299 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
299 struct iwl_device_cmd *dev_cmd = NULL; 300 struct iwl_device_cmd *dev_cmd;
300 struct iwl_tx_cmd *tx_cmd; 301 struct iwl_tx_cmd *tx_cmd;
301 __le16 fc; 302 __le16 fc;
302 u8 hdr_len; 303 u8 hdr_len;
@@ -378,7 +379,7 @@ int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
378 if (info->flags & IEEE80211_TX_CTL_AMPDU) 379 if (info->flags & IEEE80211_TX_CTL_AMPDU)
379 is_agg = true; 380 is_agg = true;
380 381
381 dev_cmd = kmem_cache_alloc(iwl_tx_cmd_pool, GFP_ATOMIC); 382 dev_cmd = iwl_trans_alloc_tx_cmd(priv->trans);
382 383
383 if (unlikely(!dev_cmd)) 384 if (unlikely(!dev_cmd))
384 goto drop_unlock_priv; 385 goto drop_unlock_priv;
@@ -402,6 +403,7 @@ int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
402 403
403 info->driver_data[0] = ctx; 404 info->driver_data[0] = ctx;
404 info->driver_data[1] = dev_cmd; 405 info->driver_data[1] = dev_cmd;
406 /* From now on, we cannot access info->control */
405 407
406 spin_lock(&priv->sta_lock); 408 spin_lock(&priv->sta_lock);
407 409
@@ -486,11 +488,14 @@ int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
486 if (sta_priv && sta_priv->client && !is_agg) 488 if (sta_priv && sta_priv->client && !is_agg)
487 atomic_inc(&sta_priv->pending_frames); 489 atomic_inc(&sta_priv->pending_frames);
488 490
491 if (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN)
492 iwl_scan_offchannel_skb(priv);
493
489 return 0; 494 return 0;
490 495
491drop_unlock_sta: 496drop_unlock_sta:
492 if (dev_cmd) 497 if (dev_cmd)
493 kmem_cache_free(iwl_tx_cmd_pool, dev_cmd); 498 iwl_trans_free_tx_cmd(priv->trans, dev_cmd);
494 spin_unlock(&priv->sta_lock); 499 spin_unlock(&priv->sta_lock);
495drop_unlock_priv: 500drop_unlock_priv:
496 return -1; 501 return -1;
@@ -597,7 +602,7 @@ turn_off:
597 * time, or we hadn't time to drain the AC queues. 602 * time, or we hadn't time to drain the AC queues.
598 */ 603 */
599 if (agg_state == IWL_AGG_ON) 604 if (agg_state == IWL_AGG_ON)
600 iwl_trans_tx_agg_disable(priv->trans, txq_id); 605 iwl_trans_txq_disable(priv->trans, txq_id);
601 else 606 else
602 IWL_DEBUG_TX_QUEUES(priv, "Don't disable tx agg: %d\n", 607 IWL_DEBUG_TX_QUEUES(priv, "Don't disable tx agg: %d\n",
603 agg_state); 608 agg_state);
@@ -686,9 +691,8 @@ int iwlagn_tx_agg_oper(struct iwl_priv *priv, struct ieee80211_vif *vif,
686 691
687 fifo = ctx->ac_to_fifo[tid_to_ac[tid]]; 692 fifo = ctx->ac_to_fifo[tid_to_ac[tid]];
688 693
689 iwl_trans_tx_agg_setup(priv->trans, q, fifo, 694 iwl_trans_txq_enable(priv->trans, q, fifo, sta_priv->sta_id, tid,
690 sta_priv->sta_id, tid, 695 buf_size, ssn);
691 buf_size, ssn);
692 696
693 /* 697 /*
694 * If the limit is 0, then it wasn't initialised yet, 698 * If the limit is 0, then it wasn't initialised yet,
@@ -753,8 +757,8 @@ static void iwlagn_check_ratid_empty(struct iwl_priv *priv, int sta_id, u8 tid)
753 IWL_DEBUG_TX_QUEUES(priv, 757 IWL_DEBUG_TX_QUEUES(priv,
754 "Can continue DELBA flow ssn = next_recl =" 758 "Can continue DELBA flow ssn = next_recl ="
755 " %d", tid_data->next_reclaimed); 759 " %d", tid_data->next_reclaimed);
756 iwl_trans_tx_agg_disable(priv->trans, 760 iwl_trans_txq_disable(priv->trans,
757 tid_data->agg.txq_id); 761 tid_data->agg.txq_id);
758 iwlagn_dealloc_agg_txq(priv, tid_data->agg.txq_id); 762 iwlagn_dealloc_agg_txq(priv, tid_data->agg.txq_id);
759 tid_data->agg.state = IWL_AGG_OFF; 763 tid_data->agg.state = IWL_AGG_OFF;
760 ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid); 764 ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
@@ -1136,6 +1140,7 @@ int iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb,
1136 struct sk_buff *skb; 1140 struct sk_buff *skb;
1137 struct iwl_rxon_context *ctx; 1141 struct iwl_rxon_context *ctx;
1138 bool is_agg = (txq_id >= IWLAGN_FIRST_AMPDU_QUEUE); 1142 bool is_agg = (txq_id >= IWLAGN_FIRST_AMPDU_QUEUE);
1143 bool is_offchannel_skb;
1139 1144
1140 tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >> 1145 tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >>
1141 IWLAGN_TX_RES_TID_POS; 1146 IWLAGN_TX_RES_TID_POS;
@@ -1149,6 +1154,8 @@ int iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb,
1149 1154
1150 __skb_queue_head_init(&skbs); 1155 __skb_queue_head_init(&skbs);
1151 1156
1157 is_offchannel_skb = false;
1158
1152 if (tx_resp->frame_count == 1) { 1159 if (tx_resp->frame_count == 1) {
1153 u16 next_reclaimed = le16_to_cpu(tx_resp->seq_ctl); 1160 u16 next_reclaimed = le16_to_cpu(tx_resp->seq_ctl);
1154 next_reclaimed = SEQ_TO_SN(next_reclaimed + 0x10); 1161 next_reclaimed = SEQ_TO_SN(next_reclaimed + 0x10);
@@ -1176,7 +1183,8 @@ int iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb,
1176 } 1183 }
1177 1184
1178 /*we can free until ssn % q.n_bd not inclusive */ 1185 /*we can free until ssn % q.n_bd not inclusive */
1179 WARN_ON(iwl_reclaim(priv, sta_id, tid, txq_id, ssn, &skbs)); 1186 WARN_ON_ONCE(iwl_reclaim(priv, sta_id, tid,
1187 txq_id, ssn, &skbs));
1180 iwlagn_check_ratid_empty(priv, sta_id, tid); 1188 iwlagn_check_ratid_empty(priv, sta_id, tid);
1181 freed = 0; 1189 freed = 0;
1182 1190
@@ -1189,8 +1197,8 @@ int iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb,
1189 1197
1190 info = IEEE80211_SKB_CB(skb); 1198 info = IEEE80211_SKB_CB(skb);
1191 ctx = info->driver_data[0]; 1199 ctx = info->driver_data[0];
1192 kmem_cache_free(iwl_tx_cmd_pool, 1200 iwl_trans_free_tx_cmd(priv->trans,
1193 (info->driver_data[1])); 1201 info->driver_data[1]);
1194 1202
1195 memset(&info->status, 0, sizeof(info->status)); 1203 memset(&info->status, 0, sizeof(info->status));
1196 1204
@@ -1225,10 +1233,19 @@ int iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb,
1225 if (!is_agg) 1233 if (!is_agg)
1226 iwlagn_non_agg_tx_status(priv, ctx, hdr->addr1); 1234 iwlagn_non_agg_tx_status(priv, ctx, hdr->addr1);
1227 1235
1236 is_offchannel_skb =
1237 (info->flags & IEEE80211_TX_CTL_TX_OFFCHAN);
1228 freed++; 1238 freed++;
1229 } 1239 }
1230 1240
1231 WARN_ON(!is_agg && freed != 1); 1241 WARN_ON(!is_agg && freed != 1);
1242
1243 /*
1244 * An offchannel frame can be send only on the AUX queue, where
1245 * there is no aggregation (and reordering) so it only is single
1246 * skb is expected to be processed.
1247 */
1248 WARN_ON(is_offchannel_skb && freed != 1);
1232 } 1249 }
1233 1250
1234 iwl_check_abort_status(priv, tx_resp->frame_count, status); 1251 iwl_check_abort_status(priv, tx_resp->frame_count, status);
@@ -1239,6 +1256,9 @@ int iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb,
1239 ieee80211_tx_status(priv->hw, skb); 1256 ieee80211_tx_status(priv->hw, skb);
1240 } 1257 }
1241 1258
1259 if (is_offchannel_skb)
1260 iwl_scan_offchannel_skb_status(priv);
1261
1242 return 0; 1262 return 0;
1243} 1263}
1244 1264
@@ -1341,7 +1361,7 @@ int iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv,
1341 WARN_ON_ONCE(1); 1361 WARN_ON_ONCE(1);
1342 1362
1343 info = IEEE80211_SKB_CB(skb); 1363 info = IEEE80211_SKB_CB(skb);
1344 kmem_cache_free(iwl_tx_cmd_pool, (info->driver_data[1])); 1364 iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]);
1345 1365
1346 if (freed == 1) { 1366 if (freed == 1) {
1347 /* this is the first skb we deliver in this batch */ 1367 /* this is the first skb we deliver in this batch */
diff --git a/drivers/net/wireless/iwlwifi/iwl-ucode.c b/drivers/net/wireless/iwlwifi/dvm/ucode.c
index bc40dc68b0f4..b3a314ba48c7 100644
--- a/drivers/net/wireless/iwlwifi/iwl-ucode.c
+++ b/drivers/net/wireless/iwlwifi/dvm/ucode.c
@@ -30,15 +30,16 @@
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/init.h> 31#include <linux/init.h>
32 32
33#include "iwl-dev.h"
34#include "iwl-io.h" 33#include "iwl-io.h"
35#include "iwl-agn-hw.h" 34#include "iwl-agn-hw.h"
36#include "iwl-agn.h"
37#include "iwl-agn-calib.h"
38#include "iwl-trans.h" 35#include "iwl-trans.h"
39#include "iwl-fh.h" 36#include "iwl-fh.h"
40#include "iwl-op-mode.h" 37#include "iwl-op-mode.h"
41 38
39#include "dev.h"
40#include "agn.h"
41#include "calib.h"
42
42/****************************************************************************** 43/******************************************************************************
43 * 44 *
44 * uCode download functions 45 * uCode download functions
@@ -60,8 +61,7 @@ iwl_get_ucode_image(struct iwl_priv *priv, enum iwl_ucode_type ucode_type)
60static int iwl_set_Xtal_calib(struct iwl_priv *priv) 61static int iwl_set_Xtal_calib(struct iwl_priv *priv)
61{ 62{
62 struct iwl_calib_xtal_freq_cmd cmd; 63 struct iwl_calib_xtal_freq_cmd cmd;
63 __le16 *xtal_calib = 64 __le16 *xtal_calib = priv->eeprom_data->xtal_calib;
64 (__le16 *)iwl_eeprom_query_addr(priv, EEPROM_XTAL);
65 65
66 iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD); 66 iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD);
67 cmd.cap_pin1 = le16_to_cpu(xtal_calib[0]); 67 cmd.cap_pin1 = le16_to_cpu(xtal_calib[0]);
@@ -72,12 +72,10 @@ static int iwl_set_Xtal_calib(struct iwl_priv *priv)
72static int iwl_set_temperature_offset_calib(struct iwl_priv *priv) 72static int iwl_set_temperature_offset_calib(struct iwl_priv *priv)
73{ 73{
74 struct iwl_calib_temperature_offset_cmd cmd; 74 struct iwl_calib_temperature_offset_cmd cmd;
75 __le16 *offset_calib =
76 (__le16 *)iwl_eeprom_query_addr(priv, EEPROM_RAW_TEMPERATURE);
77 75
78 memset(&cmd, 0, sizeof(cmd)); 76 memset(&cmd, 0, sizeof(cmd));
79 iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD); 77 iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
80 memcpy(&cmd.radio_sensor_offset, offset_calib, sizeof(*offset_calib)); 78 cmd.radio_sensor_offset = priv->eeprom_data->raw_temperature;
81 if (!(cmd.radio_sensor_offset)) 79 if (!(cmd.radio_sensor_offset))
82 cmd.radio_sensor_offset = DEFAULT_RADIO_SENSOR_OFFSET; 80 cmd.radio_sensor_offset = DEFAULT_RADIO_SENSOR_OFFSET;
83 81
@@ -89,27 +87,17 @@ static int iwl_set_temperature_offset_calib(struct iwl_priv *priv)
89static int iwl_set_temperature_offset_calib_v2(struct iwl_priv *priv) 87static int iwl_set_temperature_offset_calib_v2(struct iwl_priv *priv)
90{ 88{
91 struct iwl_calib_temperature_offset_v2_cmd cmd; 89 struct iwl_calib_temperature_offset_v2_cmd cmd;
92 __le16 *offset_calib_high = (__le16 *)iwl_eeprom_query_addr(priv,
93 EEPROM_KELVIN_TEMPERATURE);
94 __le16 *offset_calib_low =
95 (__le16 *)iwl_eeprom_query_addr(priv, EEPROM_RAW_TEMPERATURE);
96 struct iwl_eeprom_calib_hdr *hdr;
97 90
98 memset(&cmd, 0, sizeof(cmd)); 91 memset(&cmd, 0, sizeof(cmd));
99 iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD); 92 iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
100 hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv, 93 cmd.radio_sensor_offset_high = priv->eeprom_data->kelvin_temperature;
101 EEPROM_CALIB_ALL); 94 cmd.radio_sensor_offset_low = priv->eeprom_data->raw_temperature;
102 memcpy(&cmd.radio_sensor_offset_high, offset_calib_high, 95 if (!cmd.radio_sensor_offset_low) {
103 sizeof(*offset_calib_high));
104 memcpy(&cmd.radio_sensor_offset_low, offset_calib_low,
105 sizeof(*offset_calib_low));
106 if (!(cmd.radio_sensor_offset_low)) {
107 IWL_DEBUG_CALIB(priv, "no info in EEPROM, use default\n"); 96 IWL_DEBUG_CALIB(priv, "no info in EEPROM, use default\n");
108 cmd.radio_sensor_offset_low = DEFAULT_RADIO_SENSOR_OFFSET; 97 cmd.radio_sensor_offset_low = DEFAULT_RADIO_SENSOR_OFFSET;
109 cmd.radio_sensor_offset_high = DEFAULT_RADIO_SENSOR_OFFSET; 98 cmd.radio_sensor_offset_high = DEFAULT_RADIO_SENSOR_OFFSET;
110 } 99 }
111 memcpy(&cmd.burntVoltageRef, &hdr->voltage, 100 cmd.burntVoltageRef = priv->eeprom_data->calib_voltage;
112 sizeof(hdr->voltage));
113 101
114 IWL_DEBUG_CALIB(priv, "Radio sensor offset high: %d\n", 102 IWL_DEBUG_CALIB(priv, "Radio sensor offset high: %d\n",
115 le16_to_cpu(cmd.radio_sensor_offset_high)); 103 le16_to_cpu(cmd.radio_sensor_offset_high));
@@ -177,7 +165,7 @@ int iwl_init_alive_start(struct iwl_priv *priv)
177 return 0; 165 return 0;
178} 166}
179 167
180int iwl_send_wimax_coex(struct iwl_priv *priv) 168static int iwl_send_wimax_coex(struct iwl_priv *priv)
181{ 169{
182 struct iwl_wimax_coex_cmd coex_cmd; 170 struct iwl_wimax_coex_cmd coex_cmd;
183 171
diff --git a/drivers/net/wireless/iwlwifi/iwl-config.h b/drivers/net/wireless/iwlwifi/iwl-config.h
index 67b28aa7f9be..10e47938b635 100644
--- a/drivers/net/wireless/iwlwifi/iwl-config.h
+++ b/drivers/net/wireless/iwlwifi/iwl-config.h
@@ -113,7 +113,7 @@ enum iwl_led_mode {
113#define IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE 0 113#define IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE 0
114 114
115/* TX queue watchdog timeouts in mSecs */ 115/* TX queue watchdog timeouts in mSecs */
116#define IWL_WATCHHDOG_DISABLED 0 116#define IWL_WATCHDOG_DISABLED 0
117#define IWL_DEF_WD_TIMEOUT 2000 117#define IWL_DEF_WD_TIMEOUT 2000
118#define IWL_LONG_WD_TIMEOUT 10000 118#define IWL_LONG_WD_TIMEOUT 10000
119#define IWL_MAX_WD_TIMEOUT 120000 119#define IWL_MAX_WD_TIMEOUT 120000
@@ -143,7 +143,7 @@ enum iwl_led_mode {
143 * @chain_noise_scale: default chain noise scale used for gain computation 143 * @chain_noise_scale: default chain noise scale used for gain computation
144 * @wd_timeout: TX queues watchdog timeout 144 * @wd_timeout: TX queues watchdog timeout
145 * @max_event_log_size: size of event log buffer size for ucode event logging 145 * @max_event_log_size: size of event log buffer size for ucode event logging
146 * @shadow_reg_enable: HW shadhow register bit 146 * @shadow_reg_enable: HW shadow register support
147 * @hd_v2: v2 of enhanced sensitivity value, used for 2000 series and up 147 * @hd_v2: v2 of enhanced sensitivity value, used for 2000 series and up
148 * @no_idle_support: do not support idle mode 148 * @no_idle_support: do not support idle mode
149 */ 149 */
@@ -182,13 +182,34 @@ struct iwl_bt_params {
182 bool bt_sco_disable; 182 bool bt_sco_disable;
183 bool bt_session_2; 183 bool bt_session_2;
184}; 184};
185
185/* 186/*
186 * @use_rts_for_aggregation: use rts/cts protection for HT traffic 187 * @use_rts_for_aggregation: use rts/cts protection for HT traffic
188 * @ht40_bands: bitmap of bands (using %IEEE80211_BAND_*) that support HT40
187 */ 189 */
188struct iwl_ht_params { 190struct iwl_ht_params {
191 enum ieee80211_smps_mode smps_mode;
189 const bool ht_greenfield_support; /* if used set to true */ 192 const bool ht_greenfield_support; /* if used set to true */
190 bool use_rts_for_aggregation; 193 bool use_rts_for_aggregation;
191 enum ieee80211_smps_mode smps_mode; 194 u8 ht40_bands;
195};
196
197/*
198 * information on how to parse the EEPROM
199 */
200#define EEPROM_REG_BAND_1_CHANNELS 0x08
201#define EEPROM_REG_BAND_2_CHANNELS 0x26
202#define EEPROM_REG_BAND_3_CHANNELS 0x42
203#define EEPROM_REG_BAND_4_CHANNELS 0x5C
204#define EEPROM_REG_BAND_5_CHANNELS 0x74
205#define EEPROM_REG_BAND_24_HT40_CHANNELS 0x82
206#define EEPROM_REG_BAND_52_HT40_CHANNELS 0x92
207#define EEPROM_6000_REG_BAND_24_HT40_CHANNELS 0x80
208#define EEPROM_REGULATORY_BAND_NO_HT40 0
209
210struct iwl_eeprom_params {
211 const u8 regulatory_bands[7];
212 bool enhanced_txpower;
192}; 213};
193 214
194/** 215/**
@@ -243,6 +264,7 @@ struct iwl_cfg {
243 /* params likely to change within a device family */ 264 /* params likely to change within a device family */
244 const struct iwl_ht_params *ht_params; 265 const struct iwl_ht_params *ht_params;
245 const struct iwl_bt_params *bt_params; 266 const struct iwl_bt_params *bt_params;
267 const struct iwl_eeprom_params *eeprom_params;
246 const bool need_temp_offset_calib; /* if used set to true */ 268 const bool need_temp_offset_calib; /* if used set to true */
247 const bool no_xtal_calib; 269 const bool no_xtal_calib;
248 enum iwl_led_mode led_mode; 270 enum iwl_led_mode led_mode;
diff --git a/drivers/net/wireless/iwlwifi/iwl-csr.h b/drivers/net/wireless/iwlwifi/iwl-csr.h
index 59750543fce7..34a5287dfc2f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-csr.h
+++ b/drivers/net/wireless/iwlwifi/iwl-csr.h
@@ -97,13 +97,10 @@
97/* 97/*
98 * Hardware revision info 98 * Hardware revision info
99 * Bit fields: 99 * Bit fields:
100 * 31-8: Reserved 100 * 31-16: Reserved
101 * 7-4: Type of device: see CSR_HW_REV_TYPE_xxx definitions 101 * 15-4: Type of device: see CSR_HW_REV_TYPE_xxx definitions
102 * 3-2: Revision step: 0 = A, 1 = B, 2 = C, 3 = D 102 * 3-2: Revision step: 0 = A, 1 = B, 2 = C, 3 = D
103 * 1-0: "Dash" (-) value, as in A-1, etc. 103 * 1-0: "Dash" (-) value, as in A-1, etc.
104 *
105 * NOTE: Revision step affects calculation of CCK txpower for 4965.
106 * NOTE: See also CSR_HW_REV_WA_REG (work-around for bug in 4965).
107 */ 104 */
108#define CSR_HW_REV (CSR_BASE+0x028) 105#define CSR_HW_REV (CSR_BASE+0x028)
109 106
@@ -155,9 +152,21 @@
155#define CSR_DBG_LINK_PWR_MGMT_REG (CSR_BASE+0x250) 152#define CSR_DBG_LINK_PWR_MGMT_REG (CSR_BASE+0x250)
156 153
157/* Bits for CSR_HW_IF_CONFIG_REG */ 154/* Bits for CSR_HW_IF_CONFIG_REG */
158#define CSR_HW_IF_CONFIG_REG_MSK_BOARD_VER (0x00000C00) 155#define CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH (0x00000003)
159#define CSR_HW_IF_CONFIG_REG_BIT_MAC_SI (0x00000100) 156#define CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP (0x0000000C)
157#define CSR_HW_IF_CONFIG_REG_MSK_BOARD_VER (0x000000C0)
158#define CSR_HW_IF_CONFIG_REG_BIT_MAC_SI (0x00000100)
160#define CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI (0x00000200) 159#define CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI (0x00000200)
160#define CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE (0x00000C00)
161#define CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH (0x00003000)
162#define CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP (0x0000C000)
163
164#define CSR_HW_IF_CONFIG_REG_POS_MAC_DASH (0)
165#define CSR_HW_IF_CONFIG_REG_POS_MAC_STEP (2)
166#define CSR_HW_IF_CONFIG_REG_POS_BOARD_VER (6)
167#define CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE (10)
168#define CSR_HW_IF_CONFIG_REG_POS_PHY_DASH (12)
169#define CSR_HW_IF_CONFIG_REG_POS_PHY_STEP (14)
161 170
162#define CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A (0x00080000) 171#define CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A (0x00080000)
163#define CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM (0x00200000) 172#define CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM (0x00200000)
@@ -270,7 +279,10 @@
270 279
271 280
272/* HW REV */ 281/* HW REV */
273#define CSR_HW_REV_TYPE_MSK (0x00001F0) 282#define CSR_HW_REV_DASH(_val) (((_val) & 0x0000003) >> 0)
283#define CSR_HW_REV_STEP(_val) (((_val) & 0x000000C) >> 2)
284
285#define CSR_HW_REV_TYPE_MSK (0x000FFF0)
274#define CSR_HW_REV_TYPE_5300 (0x0000020) 286#define CSR_HW_REV_TYPE_5300 (0x0000020)
275#define CSR_HW_REV_TYPE_5350 (0x0000030) 287#define CSR_HW_REV_TYPE_5350 (0x0000030)
276#define CSR_HW_REV_TYPE_5100 (0x0000050) 288#define CSR_HW_REV_TYPE_5100 (0x0000050)
diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.c b/drivers/net/wireless/iwlwifi/iwl-debug.c
index 2d1b42847b9b..0f8fcd1d4fe2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debug.c
+++ b/drivers/net/wireless/iwlwifi/iwl-debug.c
@@ -62,6 +62,7 @@
62 *****************************************************************************/ 62 *****************************************************************************/
63 63
64#include <linux/interrupt.h> 64#include <linux/interrupt.h>
65#include <linux/export.h>
65#include "iwl-debug.h" 66#include "iwl-debug.h"
66#include "iwl-devtrace.h" 67#include "iwl-devtrace.h"
67 68
@@ -81,8 +82,11 @@ void __iwl_ ##fn(struct device *dev, const char *fmt, ...) \
81} 82}
82 83
83__iwl_fn(warn) 84__iwl_fn(warn)
85EXPORT_SYMBOL_GPL(__iwl_warn);
84__iwl_fn(info) 86__iwl_fn(info)
87EXPORT_SYMBOL_GPL(__iwl_info);
85__iwl_fn(crit) 88__iwl_fn(crit)
89EXPORT_SYMBOL_GPL(__iwl_crit);
86 90
87void __iwl_err(struct device *dev, bool rfkill_prefix, bool trace_only, 91void __iwl_err(struct device *dev, bool rfkill_prefix, bool trace_only,
88 const char *fmt, ...) 92 const char *fmt, ...)
@@ -103,6 +107,7 @@ void __iwl_err(struct device *dev, bool rfkill_prefix, bool trace_only,
103 trace_iwlwifi_err(&vaf); 107 trace_iwlwifi_err(&vaf);
104 va_end(args); 108 va_end(args);
105} 109}
110EXPORT_SYMBOL_GPL(__iwl_err);
106 111
107#if defined(CONFIG_IWLWIFI_DEBUG) || defined(CONFIG_IWLWIFI_DEVICE_TRACING) 112#if defined(CONFIG_IWLWIFI_DEBUG) || defined(CONFIG_IWLWIFI_DEVICE_TRACING)
108void __iwl_dbg(struct device *dev, 113void __iwl_dbg(struct device *dev,
@@ -125,4 +130,5 @@ void __iwl_dbg(struct device *dev,
125 trace_iwlwifi_dbg(level, in_interrupt(), function, &vaf); 130 trace_iwlwifi_dbg(level, in_interrupt(), function, &vaf);
126 va_end(args); 131 va_end(args);
127} 132}
133EXPORT_SYMBOL_GPL(__iwl_dbg);
128#endif 134#endif
diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
index 8376b842bdba..42b20b0e83bc 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debug.h
+++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
@@ -38,13 +38,14 @@ static inline bool iwl_have_debug_level(u32 level)
38} 38}
39 39
40void __iwl_err(struct device *dev, bool rfkill_prefix, bool only_trace, 40void __iwl_err(struct device *dev, bool rfkill_prefix, bool only_trace,
41 const char *fmt, ...); 41 const char *fmt, ...) __printf(4, 5);
42void __iwl_warn(struct device *dev, const char *fmt, ...); 42void __iwl_warn(struct device *dev, const char *fmt, ...) __printf(2, 3);
43void __iwl_info(struct device *dev, const char *fmt, ...); 43void __iwl_info(struct device *dev, const char *fmt, ...) __printf(2, 3);
44void __iwl_crit(struct device *dev, const char *fmt, ...); 44void __iwl_crit(struct device *dev, const char *fmt, ...) __printf(2, 3);
45 45
46/* No matter what is m (priv, bus, trans), this will work */ 46/* No matter what is m (priv, bus, trans), this will work */
47#define IWL_ERR(m, f, a...) __iwl_err((m)->dev, false, false, f, ## a) 47#define IWL_ERR(m, f, a...) __iwl_err((m)->dev, false, false, f, ## a)
48#define IWL_ERR_DEV(d, f, a...) __iwl_err((d), false, false, f, ## a)
48#define IWL_WARN(m, f, a...) __iwl_warn((m)->dev, f, ## a) 49#define IWL_WARN(m, f, a...) __iwl_warn((m)->dev, f, ## a)
49#define IWL_INFO(m, f, a...) __iwl_info((m)->dev, f, ## a) 50#define IWL_INFO(m, f, a...) __iwl_info((m)->dev, f, ## a)
50#define IWL_CRIT(m, f, a...) __iwl_crit((m)->dev, f, ## a) 51#define IWL_CRIT(m, f, a...) __iwl_crit((m)->dev, f, ## a)
@@ -52,9 +53,9 @@ void __iwl_crit(struct device *dev, const char *fmt, ...);
52#if defined(CONFIG_IWLWIFI_DEBUG) || defined(CONFIG_IWLWIFI_DEVICE_TRACING) 53#if defined(CONFIG_IWLWIFI_DEBUG) || defined(CONFIG_IWLWIFI_DEVICE_TRACING)
53void __iwl_dbg(struct device *dev, 54void __iwl_dbg(struct device *dev,
54 u32 level, bool limit, const char *function, 55 u32 level, bool limit, const char *function,
55 const char *fmt, ...); 56 const char *fmt, ...) __printf(5, 6);
56#else 57#else
57static inline void 58__printf(5, 6) static inline void
58__iwl_dbg(struct device *dev, 59__iwl_dbg(struct device *dev,
59 u32 level, bool limit, const char *function, 60 u32 level, bool limit, const char *function,
60 const char *fmt, ...) 61 const char *fmt, ...)
@@ -69,6 +70,8 @@ do { \
69 70
70#define IWL_DEBUG(m, level, fmt, args...) \ 71#define IWL_DEBUG(m, level, fmt, args...) \
71 __iwl_dbg((m)->dev, level, false, __func__, fmt, ##args) 72 __iwl_dbg((m)->dev, level, false, __func__, fmt, ##args)
73#define IWL_DEBUG_DEV(dev, level, fmt, args...) \
74 __iwl_dbg((dev), level, false, __func__, fmt, ##args)
72#define IWL_DEBUG_LIMIT(m, level, fmt, args...) \ 75#define IWL_DEBUG_LIMIT(m, level, fmt, args...) \
73 __iwl_dbg((m)->dev, level, true, __func__, fmt, ##args) 76 __iwl_dbg((m)->dev, level, true, __func__, fmt, ##args)
74 77
@@ -153,7 +156,7 @@ do { \
153#define IWL_DEBUG_LED(p, f, a...) IWL_DEBUG(p, IWL_DL_LED, f, ## a) 156#define IWL_DEBUG_LED(p, f, a...) IWL_DEBUG(p, IWL_DL_LED, f, ## a)
154#define IWL_DEBUG_WEP(p, f, a...) IWL_DEBUG(p, IWL_DL_WEP, f, ## a) 157#define IWL_DEBUG_WEP(p, f, a...) IWL_DEBUG(p, IWL_DL_WEP, f, ## a)
155#define IWL_DEBUG_HC(p, f, a...) IWL_DEBUG(p, IWL_DL_HCMD, f, ## a) 158#define IWL_DEBUG_HC(p, f, a...) IWL_DEBUG(p, IWL_DL_HCMD, f, ## a)
156#define IWL_DEBUG_EEPROM(p, f, a...) IWL_DEBUG(p, IWL_DL_EEPROM, f, ## a) 159#define IWL_DEBUG_EEPROM(d, f, a...) IWL_DEBUG_DEV(d, IWL_DL_EEPROM, f, ## a)
157#define IWL_DEBUG_CALIB(p, f, a...) IWL_DEBUG(p, IWL_DL_CALIB, f, ## a) 160#define IWL_DEBUG_CALIB(p, f, a...) IWL_DEBUG(p, IWL_DL_CALIB, f, ## a)
158#define IWL_DEBUG_FW(p, f, a...) IWL_DEBUG(p, IWL_DL_FW, f, ## a) 161#define IWL_DEBUG_FW(p, f, a...) IWL_DEBUG(p, IWL_DL_FW, f, ## a)
159#define IWL_DEBUG_RF_KILL(p, f, a...) IWL_DEBUG(p, IWL_DL_RF_KILL, f, ## a) 162#define IWL_DEBUG_RF_KILL(p, f, a...) IWL_DEBUG(p, IWL_DL_RF_KILL, f, ## a)
diff --git a/drivers/net/wireless/iwlwifi/iwl-devtrace.c b/drivers/net/wireless/iwlwifi/iwl-devtrace.c
index 91f45e71e0a2..70191ddbd8f6 100644
--- a/drivers/net/wireless/iwlwifi/iwl-devtrace.c
+++ b/drivers/net/wireless/iwlwifi/iwl-devtrace.c
@@ -42,4 +42,9 @@ EXPORT_TRACEPOINT_SYMBOL(iwlwifi_dev_ucode_event);
42EXPORT_TRACEPOINT_SYMBOL(iwlwifi_dev_ucode_error); 42EXPORT_TRACEPOINT_SYMBOL(iwlwifi_dev_ucode_error);
43EXPORT_TRACEPOINT_SYMBOL(iwlwifi_dev_ucode_cont_event); 43EXPORT_TRACEPOINT_SYMBOL(iwlwifi_dev_ucode_cont_event);
44EXPORT_TRACEPOINT_SYMBOL(iwlwifi_dev_ucode_wrap_event); 44EXPORT_TRACEPOINT_SYMBOL(iwlwifi_dev_ucode_wrap_event);
45EXPORT_TRACEPOINT_SYMBOL(iwlwifi_info);
46EXPORT_TRACEPOINT_SYMBOL(iwlwifi_warn);
47EXPORT_TRACEPOINT_SYMBOL(iwlwifi_crit);
48EXPORT_TRACEPOINT_SYMBOL(iwlwifi_err);
49EXPORT_TRACEPOINT_SYMBOL(iwlwifi_dbg);
45#endif 50#endif
diff --git a/drivers/net/wireless/iwlwifi/iwl-devtrace.h b/drivers/net/wireless/iwlwifi/iwl-devtrace.h
index 06203d6a1d86..65364793021f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-devtrace.h
+++ b/drivers/net/wireless/iwlwifi/iwl-devtrace.h
@@ -28,6 +28,7 @@
28#define __IWLWIFI_DEVICE_TRACE 28#define __IWLWIFI_DEVICE_TRACE
29 29
30#include <linux/tracepoint.h> 30#include <linux/tracepoint.h>
31#include <linux/device.h>
31 32
32 33
33#if !defined(CONFIG_IWLWIFI_DEVICE_TRACING) || defined(__CHECKER__) 34#if !defined(CONFIG_IWLWIFI_DEVICE_TRACING) || defined(__CHECKER__)
diff --git a/drivers/net/wireless/iwlwifi/iwl-drv.c b/drivers/net/wireless/iwlwifi/iwl-drv.c
index fac67a526a30..095547b37a27 100644
--- a/drivers/net/wireless/iwlwifi/iwl-drv.c
+++ b/drivers/net/wireless/iwlwifi/iwl-drv.c
@@ -77,8 +77,33 @@
77/* private includes */ 77/* private includes */
78#include "iwl-fw-file.h" 78#include "iwl-fw-file.h"
79 79
80/******************************************************************************
81 *
82 * module boiler plate
83 *
84 ******************************************************************************/
85
86/*
87 * module name, copyright, version, etc.
88 */
89#define DRV_DESCRIPTION "Intel(R) Wireless WiFi driver for Linux"
90
91#ifdef CONFIG_IWLWIFI_DEBUG
92#define VD "d"
93#else
94#define VD
95#endif
96
97#define DRV_VERSION IWLWIFI_VERSION VD
98
99MODULE_DESCRIPTION(DRV_DESCRIPTION);
100MODULE_VERSION(DRV_VERSION);
101MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
102MODULE_LICENSE("GPL");
103
80/** 104/**
81 * struct iwl_drv - drv common data 105 * struct iwl_drv - drv common data
106 * @list: list of drv structures using this opmode
82 * @fw: the iwl_fw structure 107 * @fw: the iwl_fw structure
83 * @op_mode: the running op_mode 108 * @op_mode: the running op_mode
84 * @trans: transport layer 109 * @trans: transport layer
@@ -89,6 +114,7 @@
89 * @request_firmware_complete: the firmware has been obtained from user space 114 * @request_firmware_complete: the firmware has been obtained from user space
90 */ 115 */
91struct iwl_drv { 116struct iwl_drv {
117 struct list_head list;
92 struct iwl_fw fw; 118 struct iwl_fw fw;
93 119
94 struct iwl_op_mode *op_mode; 120 struct iwl_op_mode *op_mode;
@@ -102,7 +128,19 @@ struct iwl_drv {
102 struct completion request_firmware_complete; 128 struct completion request_firmware_complete;
103}; 129};
104 130
105 131#define DVM_OP_MODE 0
132#define MVM_OP_MODE 1
133
134/* Protects the table contents, i.e. the ops pointer & drv list */
135static struct mutex iwlwifi_opmode_table_mtx;
136static struct iwlwifi_opmode_table {
137 const char *name; /* name: iwldvm, iwlmvm, etc */
138 const struct iwl_op_mode_ops *ops; /* pointer to op_mode ops */
139 struct list_head drv; /* list of devices using this op_mode */
140} iwlwifi_opmode_table[] = { /* ops set when driver is initialized */
141 { .name = "iwldvm", .ops = NULL },
142 { .name = "iwlmvm", .ops = NULL },
143};
106 144
107/* 145/*
108 * struct fw_sec: Just for the image parsing proccess. 146 * struct fw_sec: Just for the image parsing proccess.
@@ -721,7 +759,6 @@ static int validate_sec_sizes(struct iwl_drv *drv,
721 return 0; 759 return 0;
722} 760}
723 761
724
725/** 762/**
726 * iwl_ucode_callback - callback when firmware was loaded 763 * iwl_ucode_callback - callback when firmware was loaded
727 * 764 *
@@ -733,6 +770,7 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
733 struct iwl_drv *drv = context; 770 struct iwl_drv *drv = context;
734 struct iwl_fw *fw = &drv->fw; 771 struct iwl_fw *fw = &drv->fw;
735 struct iwl_ucode_header *ucode; 772 struct iwl_ucode_header *ucode;
773 struct iwlwifi_opmode_table *op;
736 int err; 774 int err;
737 struct iwl_firmware_pieces pieces; 775 struct iwl_firmware_pieces pieces;
738 const unsigned int api_max = drv->cfg->ucode_api_max; 776 const unsigned int api_max = drv->cfg->ucode_api_max;
@@ -740,6 +778,7 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
740 const unsigned int api_min = drv->cfg->ucode_api_min; 778 const unsigned int api_min = drv->cfg->ucode_api_min;
741 u32 api_ver; 779 u32 api_ver;
742 int i; 780 int i;
781 bool load_module = false;
743 782
744 fw->ucode_capa.max_probe_length = 200; 783 fw->ucode_capa.max_probe_length = 200;
745 fw->ucode_capa.standard_phy_calibration_size = 784 fw->ucode_capa.standard_phy_calibration_size =
@@ -862,10 +901,22 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
862 /* We have our copies now, allow OS release its copies */ 901 /* We have our copies now, allow OS release its copies */
863 release_firmware(ucode_raw); 902 release_firmware(ucode_raw);
864 903
865 drv->op_mode = iwl_dvm_ops.start(drv->trans, drv->cfg, &drv->fw); 904 mutex_lock(&iwlwifi_opmode_table_mtx);
905 op = &iwlwifi_opmode_table[DVM_OP_MODE];
866 906
867 if (!drv->op_mode) 907 /* add this device to the list of devices using this op_mode */
868 goto out_unbind; 908 list_add_tail(&drv->list, &op->drv);
909
910 if (op->ops) {
911 const struct iwl_op_mode_ops *ops = op->ops;
912 drv->op_mode = ops->start(drv->trans, drv->cfg, &drv->fw);
913
914 if (!drv->op_mode)
915 goto out_unbind;
916 } else {
917 load_module = true;
918 }
919 mutex_unlock(&iwlwifi_opmode_table_mtx);
869 920
870 /* 921 /*
871 * Complete the firmware request last so that 922 * Complete the firmware request last so that
@@ -873,6 +924,14 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
873 * are doing the start() above. 924 * are doing the start() above.
874 */ 925 */
875 complete(&drv->request_firmware_complete); 926 complete(&drv->request_firmware_complete);
927
928 /*
929 * Load the module last so we don't block anything
930 * else from proceeding if the module fails to load
931 * or hangs loading.
932 */
933 if (load_module)
934 request_module("%s", op->name);
876 return; 935 return;
877 936
878 try_again: 937 try_again:
@@ -906,6 +965,7 @@ struct iwl_drv *iwl_drv_start(struct iwl_trans *trans,
906 drv->cfg = cfg; 965 drv->cfg = cfg;
907 966
908 init_completion(&drv->request_firmware_complete); 967 init_completion(&drv->request_firmware_complete);
968 INIT_LIST_HEAD(&drv->list);
909 969
910 ret = iwl_request_firmware(drv, true); 970 ret = iwl_request_firmware(drv, true);
911 971
@@ -928,6 +988,16 @@ void iwl_drv_stop(struct iwl_drv *drv)
928 988
929 iwl_dealloc_ucode(drv); 989 iwl_dealloc_ucode(drv);
930 990
991 mutex_lock(&iwlwifi_opmode_table_mtx);
992 /*
993 * List is empty (this item wasn't added)
994 * when firmware loading failed -- in that
995 * case we can't remove it from any list.
996 */
997 if (!list_empty(&drv->list))
998 list_del(&drv->list);
999 mutex_unlock(&iwlwifi_opmode_table_mtx);
1000
931 kfree(drv); 1001 kfree(drv);
932} 1002}
933 1003
@@ -943,6 +1013,75 @@ struct iwl_mod_params iwlwifi_mod_params = {
943 .auto_agg = true, 1013 .auto_agg = true,
944 /* the rest are 0 by default */ 1014 /* the rest are 0 by default */
945}; 1015};
1016EXPORT_SYMBOL_GPL(iwlwifi_mod_params);
1017
1018int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops)
1019{
1020 int i;
1021 struct iwl_drv *drv;
1022
1023 mutex_lock(&iwlwifi_opmode_table_mtx);
1024 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1025 if (strcmp(iwlwifi_opmode_table[i].name, name))
1026 continue;
1027 iwlwifi_opmode_table[i].ops = ops;
1028 list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list)
1029 drv->op_mode = ops->start(drv->trans, drv->cfg,
1030 &drv->fw);
1031 mutex_unlock(&iwlwifi_opmode_table_mtx);
1032 return 0;
1033 }
1034 mutex_unlock(&iwlwifi_opmode_table_mtx);
1035 return -EIO;
1036}
1037EXPORT_SYMBOL_GPL(iwl_opmode_register);
1038
1039void iwl_opmode_deregister(const char *name)
1040{
1041 int i;
1042 struct iwl_drv *drv;
1043
1044 mutex_lock(&iwlwifi_opmode_table_mtx);
1045 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
1046 if (strcmp(iwlwifi_opmode_table[i].name, name))
1047 continue;
1048 iwlwifi_opmode_table[i].ops = NULL;
1049
1050 /* call the stop routine for all devices */
1051 list_for_each_entry(drv, &iwlwifi_opmode_table[i].drv, list) {
1052 if (drv->op_mode) {
1053 iwl_op_mode_stop(drv->op_mode);
1054 drv->op_mode = NULL;
1055 }
1056 }
1057 mutex_unlock(&iwlwifi_opmode_table_mtx);
1058 return;
1059 }
1060 mutex_unlock(&iwlwifi_opmode_table_mtx);
1061}
1062EXPORT_SYMBOL_GPL(iwl_opmode_deregister);
1063
1064static int __init iwl_drv_init(void)
1065{
1066 int i;
1067
1068 mutex_init(&iwlwifi_opmode_table_mtx);
1069
1070 for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++)
1071 INIT_LIST_HEAD(&iwlwifi_opmode_table[i].drv);
1072
1073 pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
1074 pr_info(DRV_COPYRIGHT "\n");
1075
1076 return iwl_pci_register_driver();
1077}
1078module_init(iwl_drv_init);
1079
1080static void __exit iwl_drv_exit(void)
1081{
1082 iwl_pci_unregister_driver();
1083}
1084module_exit(iwl_drv_exit);
946 1085
947#ifdef CONFIG_IWLWIFI_DEBUG 1086#ifdef CONFIG_IWLWIFI_DEBUG
948module_param_named(debug, iwlwifi_mod_params.debug_level, uint, 1087module_param_named(debug, iwlwifi_mod_params.debug_level, uint,
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
new file mode 100644
index 000000000000..c87a05cbec12
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.c
@@ -0,0 +1,900 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
62#include <linux/types.h>
63#include <linux/slab.h>
64#include <linux/export.h>
65#include "iwl-modparams.h"
66#include "iwl-eeprom-parse.h"
67
68/* EEPROM offset definitions */
69
70/* indirect access definitions */
71#define ADDRESS_MSK 0x0000FFFF
72#define INDIRECT_TYPE_MSK 0x000F0000
73#define INDIRECT_HOST 0x00010000
74#define INDIRECT_GENERAL 0x00020000
75#define INDIRECT_REGULATORY 0x00030000
76#define INDIRECT_CALIBRATION 0x00040000
77#define INDIRECT_PROCESS_ADJST 0x00050000
78#define INDIRECT_OTHERS 0x00060000
79#define INDIRECT_TXP_LIMIT 0x00070000
80#define INDIRECT_TXP_LIMIT_SIZE 0x00080000
81#define INDIRECT_ADDRESS 0x00100000
82
83/* corresponding link offsets in EEPROM */
84#define EEPROM_LINK_HOST (2*0x64)
85#define EEPROM_LINK_GENERAL (2*0x65)
86#define EEPROM_LINK_REGULATORY (2*0x66)
87#define EEPROM_LINK_CALIBRATION (2*0x67)
88#define EEPROM_LINK_PROCESS_ADJST (2*0x68)
89#define EEPROM_LINK_OTHERS (2*0x69)
90#define EEPROM_LINK_TXP_LIMIT (2*0x6a)
91#define EEPROM_LINK_TXP_LIMIT_SIZE (2*0x6b)
92
93/* General */
94#define EEPROM_DEVICE_ID (2*0x08) /* 2 bytes */
95#define EEPROM_SUBSYSTEM_ID (2*0x0A) /* 2 bytes */
96#define EEPROM_MAC_ADDRESS (2*0x15) /* 6 bytes */
97#define EEPROM_BOARD_REVISION (2*0x35) /* 2 bytes */
98#define EEPROM_BOARD_PBA_NUMBER (2*0x3B+1) /* 9 bytes */
99#define EEPROM_VERSION (2*0x44) /* 2 bytes */
100#define EEPROM_SKU_CAP (2*0x45) /* 2 bytes */
101#define EEPROM_OEM_MODE (2*0x46) /* 2 bytes */
102#define EEPROM_RADIO_CONFIG (2*0x48) /* 2 bytes */
103#define EEPROM_NUM_MAC_ADDRESS (2*0x4C) /* 2 bytes */
104
105/* calibration */
106struct iwl_eeprom_calib_hdr {
107 u8 version;
108 u8 pa_type;
109 __le16 voltage;
110} __packed;
111
112#define EEPROM_CALIB_ALL (INDIRECT_ADDRESS | INDIRECT_CALIBRATION)
113#define EEPROM_XTAL ((2*0x128) | EEPROM_CALIB_ALL)
114
115/* temperature */
116#define EEPROM_KELVIN_TEMPERATURE ((2*0x12A) | EEPROM_CALIB_ALL)
117#define EEPROM_RAW_TEMPERATURE ((2*0x12B) | EEPROM_CALIB_ALL)
118
119/*
120 * EEPROM bands
121 * These are the channel numbers from each band in the order
122 * that they are stored in the EEPROM band information. Note
123 * that EEPROM bands aren't the same as mac80211 bands, and
124 * there are even special "ht40 bands" in the EEPROM.
125 */
126static const u8 iwl_eeprom_band_1[14] = { /* 2.4 GHz */
127 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
128};
129
130static const u8 iwl_eeprom_band_2[] = { /* 4915-5080MHz */
131 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
132};
133
134static const u8 iwl_eeprom_band_3[] = { /* 5170-5320MHz */
135 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
136};
137
138static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */
139 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
140};
141
142static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */
143 145, 149, 153, 157, 161, 165
144};
145
146static const u8 iwl_eeprom_band_6[] = { /* 2.4 ht40 channel */
147 1, 2, 3, 4, 5, 6, 7
148};
149
150static const u8 iwl_eeprom_band_7[] = { /* 5.2 ht40 channel */
151 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
152};
153
154#define IWL_NUM_CHANNELS (ARRAY_SIZE(iwl_eeprom_band_1) + \
155 ARRAY_SIZE(iwl_eeprom_band_2) + \
156 ARRAY_SIZE(iwl_eeprom_band_3) + \
157 ARRAY_SIZE(iwl_eeprom_band_4) + \
158 ARRAY_SIZE(iwl_eeprom_band_5))
159
160/* rate data (static) */
161static struct ieee80211_rate iwl_cfg80211_rates[] = {
162 { .bitrate = 1 * 10, .hw_value = 0, .hw_value_short = 0, },
163 { .bitrate = 2 * 10, .hw_value = 1, .hw_value_short = 1,
164 .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
165 { .bitrate = 5.5 * 10, .hw_value = 2, .hw_value_short = 2,
166 .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
167 { .bitrate = 11 * 10, .hw_value = 3, .hw_value_short = 3,
168 .flags = IEEE80211_RATE_SHORT_PREAMBLE, },
169 { .bitrate = 6 * 10, .hw_value = 4, .hw_value_short = 4, },
170 { .bitrate = 9 * 10, .hw_value = 5, .hw_value_short = 5, },
171 { .bitrate = 12 * 10, .hw_value = 6, .hw_value_short = 6, },
172 { .bitrate = 18 * 10, .hw_value = 7, .hw_value_short = 7, },
173 { .bitrate = 24 * 10, .hw_value = 8, .hw_value_short = 8, },
174 { .bitrate = 36 * 10, .hw_value = 9, .hw_value_short = 9, },
175 { .bitrate = 48 * 10, .hw_value = 10, .hw_value_short = 10, },
176 { .bitrate = 54 * 10, .hw_value = 11, .hw_value_short = 11, },
177};
178#define RATES_24_OFFS 0
179#define N_RATES_24 ARRAY_SIZE(iwl_cfg80211_rates)
180#define RATES_52_OFFS 4
181#define N_RATES_52 (N_RATES_24 - RATES_52_OFFS)
182
183/* EEPROM reading functions */
184
185static u16 iwl_eeprom_query16(const u8 *eeprom, size_t eeprom_size, int offset)
186{
187 if (WARN_ON(offset + sizeof(u16) > eeprom_size))
188 return 0;
189 return le16_to_cpup((__le16 *)(eeprom + offset));
190}
191
192static u32 eeprom_indirect_address(const u8 *eeprom, size_t eeprom_size,
193 u32 address)
194{
195 u16 offset = 0;
196
197 if ((address & INDIRECT_ADDRESS) == 0)
198 return address;
199
200 switch (address & INDIRECT_TYPE_MSK) {
201 case INDIRECT_HOST:
202 offset = iwl_eeprom_query16(eeprom, eeprom_size,
203 EEPROM_LINK_HOST);
204 break;
205 case INDIRECT_GENERAL:
206 offset = iwl_eeprom_query16(eeprom, eeprom_size,
207 EEPROM_LINK_GENERAL);
208 break;
209 case INDIRECT_REGULATORY:
210 offset = iwl_eeprom_query16(eeprom, eeprom_size,
211 EEPROM_LINK_REGULATORY);
212 break;
213 case INDIRECT_TXP_LIMIT:
214 offset = iwl_eeprom_query16(eeprom, eeprom_size,
215 EEPROM_LINK_TXP_LIMIT);
216 break;
217 case INDIRECT_TXP_LIMIT_SIZE:
218 offset = iwl_eeprom_query16(eeprom, eeprom_size,
219 EEPROM_LINK_TXP_LIMIT_SIZE);
220 break;
221 case INDIRECT_CALIBRATION:
222 offset = iwl_eeprom_query16(eeprom, eeprom_size,
223 EEPROM_LINK_CALIBRATION);
224 break;
225 case INDIRECT_PROCESS_ADJST:
226 offset = iwl_eeprom_query16(eeprom, eeprom_size,
227 EEPROM_LINK_PROCESS_ADJST);
228 break;
229 case INDIRECT_OTHERS:
230 offset = iwl_eeprom_query16(eeprom, eeprom_size,
231 EEPROM_LINK_OTHERS);
232 break;
233 default:
234 WARN_ON(1);
235 break;
236 }
237
238 /* translate the offset from words to byte */
239 return (address & ADDRESS_MSK) + (offset << 1);
240}
241
242static const u8 *iwl_eeprom_query_addr(const u8 *eeprom, size_t eeprom_size,
243 u32 offset)
244{
245 u32 address = eeprom_indirect_address(eeprom, eeprom_size, offset);
246
247 if (WARN_ON(address >= eeprom_size))
248 return NULL;
249
250 return &eeprom[address];
251}
252
253static int iwl_eeprom_read_calib(const u8 *eeprom, size_t eeprom_size,
254 struct iwl_eeprom_data *data)
255{
256 struct iwl_eeprom_calib_hdr *hdr;
257
258 hdr = (void *)iwl_eeprom_query_addr(eeprom, eeprom_size,
259 EEPROM_CALIB_ALL);
260 if (!hdr)
261 return -ENODATA;
262 data->calib_version = hdr->version;
263 data->calib_voltage = hdr->voltage;
264
265 return 0;
266}
267
268/**
269 * enum iwl_eeprom_channel_flags - channel flags in EEPROM
270 * @EEPROM_CHANNEL_VALID: channel is usable for this SKU/geo
271 * @EEPROM_CHANNEL_IBSS: usable as an IBSS channel
272 * @EEPROM_CHANNEL_ACTIVE: active scanning allowed
273 * @EEPROM_CHANNEL_RADAR: radar detection required
274 * @EEPROM_CHANNEL_WIDE: 20 MHz channel okay (?)
275 * @EEPROM_CHANNEL_DFS: dynamic freq selection candidate
276 */
277enum iwl_eeprom_channel_flags {
278 EEPROM_CHANNEL_VALID = BIT(0),
279 EEPROM_CHANNEL_IBSS = BIT(1),
280 EEPROM_CHANNEL_ACTIVE = BIT(3),
281 EEPROM_CHANNEL_RADAR = BIT(4),
282 EEPROM_CHANNEL_WIDE = BIT(5),
283 EEPROM_CHANNEL_DFS = BIT(7),
284};
285
286/**
287 * struct iwl_eeprom_channel - EEPROM channel data
288 * @flags: %EEPROM_CHANNEL_* flags
289 * @max_power_avg: max power (in dBm) on this channel, at most 31 dBm
290 */
291struct iwl_eeprom_channel {
292 u8 flags;
293 s8 max_power_avg;
294} __packed;
295
296
297enum iwl_eeprom_enhanced_txpwr_flags {
298 IWL_EEPROM_ENH_TXP_FL_VALID = BIT(0),
299 IWL_EEPROM_ENH_TXP_FL_BAND_52G = BIT(1),
300 IWL_EEPROM_ENH_TXP_FL_OFDM = BIT(2),
301 IWL_EEPROM_ENH_TXP_FL_40MHZ = BIT(3),
302 IWL_EEPROM_ENH_TXP_FL_HT_AP = BIT(4),
303 IWL_EEPROM_ENH_TXP_FL_RES1 = BIT(5),
304 IWL_EEPROM_ENH_TXP_FL_RES2 = BIT(6),
305 IWL_EEPROM_ENH_TXP_FL_COMMON_TYPE = BIT(7),
306};
307
308/**
309 * iwl_eeprom_enhanced_txpwr structure
310 * @flags: entry flags
311 * @channel: channel number
312 * @chain_a_max_pwr: chain a max power in 1/2 dBm
313 * @chain_b_max_pwr: chain b max power in 1/2 dBm
314 * @chain_c_max_pwr: chain c max power in 1/2 dBm
315 * @delta_20_in_40: 20-in-40 deltas (hi/lo)
316 * @mimo2_max_pwr: mimo2 max power in 1/2 dBm
317 * @mimo3_max_pwr: mimo3 max power in 1/2 dBm
318 *
319 * This structure presents the enhanced regulatory tx power limit layout
320 * in an EEPROM image.
321 */
322struct iwl_eeprom_enhanced_txpwr {
323 u8 flags;
324 u8 channel;
325 s8 chain_a_max;
326 s8 chain_b_max;
327 s8 chain_c_max;
328 u8 delta_20_in_40;
329 s8 mimo2_max;
330 s8 mimo3_max;
331} __packed;
332
333static s8 iwl_get_max_txpwr_half_dbm(const struct iwl_eeprom_data *data,
334 struct iwl_eeprom_enhanced_txpwr *txp)
335{
336 s8 result = 0; /* (.5 dBm) */
337
338 /* Take the highest tx power from any valid chains */
339 if (data->valid_tx_ant & ANT_A && txp->chain_a_max > result)
340 result = txp->chain_a_max;
341
342 if (data->valid_tx_ant & ANT_B && txp->chain_b_max > result)
343 result = txp->chain_b_max;
344
345 if (data->valid_tx_ant & ANT_C && txp->chain_c_max > result)
346 result = txp->chain_c_max;
347
348 if ((data->valid_tx_ant == ANT_AB ||
349 data->valid_tx_ant == ANT_BC ||
350 data->valid_tx_ant == ANT_AC) && txp->mimo2_max > result)
351 result = txp->mimo2_max;
352
353 if (data->valid_tx_ant == ANT_ABC && txp->mimo3_max > result)
354 result = txp->mimo3_max;
355
356 return result;
357}
358
359#define EEPROM_TXP_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT)
360#define EEPROM_TXP_ENTRY_LEN sizeof(struct iwl_eeprom_enhanced_txpwr)
361#define EEPROM_TXP_SZ_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT_SIZE)
362
363#define TXP_CHECK_AND_PRINT(x) \
364 ((txp->flags & IWL_EEPROM_ENH_TXP_FL_##x) ? # x " " : "")
365
366static void
367iwl_eeprom_enh_txp_read_element(struct iwl_eeprom_data *data,
368 struct iwl_eeprom_enhanced_txpwr *txp,
369 int n_channels, s8 max_txpower_avg)
370{
371 int ch_idx;
372 enum ieee80211_band band;
373
374 band = txp->flags & IWL_EEPROM_ENH_TXP_FL_BAND_52G ?
375 IEEE80211_BAND_5GHZ : IEEE80211_BAND_2GHZ;
376
377 for (ch_idx = 0; ch_idx < n_channels; ch_idx++) {
378 struct ieee80211_channel *chan = &data->channels[ch_idx];
379
380 /* update matching channel or from common data only */
381 if (txp->channel != 0 && chan->hw_value != txp->channel)
382 continue;
383
384 /* update matching band only */
385 if (band != chan->band)
386 continue;
387
388 if (chan->max_power < max_txpower_avg &&
389 !(txp->flags & IWL_EEPROM_ENH_TXP_FL_40MHZ))
390 chan->max_power = max_txpower_avg;
391 }
392}
393
394static void iwl_eeprom_enhanced_txpower(struct device *dev,
395 struct iwl_eeprom_data *data,
396 const u8 *eeprom, size_t eeprom_size,
397 int n_channels)
398{
399 struct iwl_eeprom_enhanced_txpwr *txp_array, *txp;
400 int idx, entries;
401 __le16 *txp_len;
402 s8 max_txp_avg_halfdbm;
403
404 BUILD_BUG_ON(sizeof(struct iwl_eeprom_enhanced_txpwr) != 8);
405
406 /* the length is in 16-bit words, but we want entries */
407 txp_len = (__le16 *)iwl_eeprom_query_addr(eeprom, eeprom_size,
408 EEPROM_TXP_SZ_OFFS);
409 entries = le16_to_cpup(txp_len) * 2 / EEPROM_TXP_ENTRY_LEN;
410
411 txp_array = (void *)iwl_eeprom_query_addr(eeprom, eeprom_size,
412 EEPROM_TXP_OFFS);
413
414 for (idx = 0; idx < entries; idx++) {
415 txp = &txp_array[idx];
416 /* skip invalid entries */
417 if (!(txp->flags & IWL_EEPROM_ENH_TXP_FL_VALID))
418 continue;
419
420 IWL_DEBUG_EEPROM(dev, "%s %d:\t %s%s%s%s%s%s%s%s (0x%02x)\n",
421 (txp->channel && (txp->flags &
422 IWL_EEPROM_ENH_TXP_FL_COMMON_TYPE)) ?
423 "Common " : (txp->channel) ?
424 "Channel" : "Common",
425 (txp->channel),
426 TXP_CHECK_AND_PRINT(VALID),
427 TXP_CHECK_AND_PRINT(BAND_52G),
428 TXP_CHECK_AND_PRINT(OFDM),
429 TXP_CHECK_AND_PRINT(40MHZ),
430 TXP_CHECK_AND_PRINT(HT_AP),
431 TXP_CHECK_AND_PRINT(RES1),
432 TXP_CHECK_AND_PRINT(RES2),
433 TXP_CHECK_AND_PRINT(COMMON_TYPE),
434 txp->flags);
435 IWL_DEBUG_EEPROM(dev,
436 "\t\t chain_A: 0x%02x chain_B: 0X%02x chain_C: 0X%02x\n",
437 txp->chain_a_max, txp->chain_b_max,
438 txp->chain_c_max);
439 IWL_DEBUG_EEPROM(dev,
440 "\t\t MIMO2: 0x%02x MIMO3: 0x%02x High 20_on_40: 0x%02x Low 20_on_40: 0x%02x\n",
441 txp->mimo2_max, txp->mimo3_max,
442 ((txp->delta_20_in_40 & 0xf0) >> 4),
443 (txp->delta_20_in_40 & 0x0f));
444
445 max_txp_avg_halfdbm = iwl_get_max_txpwr_half_dbm(data, txp);
446
447 iwl_eeprom_enh_txp_read_element(data, txp, n_channels,
448 DIV_ROUND_UP(max_txp_avg_halfdbm, 2));
449
450 if (max_txp_avg_halfdbm > data->max_tx_pwr_half_dbm)
451 data->max_tx_pwr_half_dbm = max_txp_avg_halfdbm;
452 }
453}
454
455static void iwl_init_band_reference(const struct iwl_cfg *cfg,
456 const u8 *eeprom, size_t eeprom_size,
457 int eeprom_band, int *eeprom_ch_count,
458 const struct iwl_eeprom_channel **ch_info,
459 const u8 **eeprom_ch_array)
460{
461 u32 offset = cfg->eeprom_params->regulatory_bands[eeprom_band - 1];
462
463 offset |= INDIRECT_ADDRESS | INDIRECT_REGULATORY;
464
465 *ch_info = (void *)iwl_eeprom_query_addr(eeprom, eeprom_size, offset);
466
467 switch (eeprom_band) {
468 case 1: /* 2.4GHz band */
469 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1);
470 *eeprom_ch_array = iwl_eeprom_band_1;
471 break;
472 case 2: /* 4.9GHz band */
473 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2);
474 *eeprom_ch_array = iwl_eeprom_band_2;
475 break;
476 case 3: /* 5.2GHz band */
477 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3);
478 *eeprom_ch_array = iwl_eeprom_band_3;
479 break;
480 case 4: /* 5.5GHz band */
481 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4);
482 *eeprom_ch_array = iwl_eeprom_band_4;
483 break;
484 case 5: /* 5.7GHz band */
485 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5);
486 *eeprom_ch_array = iwl_eeprom_band_5;
487 break;
488 case 6: /* 2.4GHz ht40 channels */
489 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6);
490 *eeprom_ch_array = iwl_eeprom_band_6;
491 break;
492 case 7: /* 5 GHz ht40 channels */
493 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7);
494 *eeprom_ch_array = iwl_eeprom_band_7;
495 break;
496 default:
497 *eeprom_ch_count = 0;
498 *eeprom_ch_array = NULL;
499 WARN_ON(1);
500 }
501}
502
503#define CHECK_AND_PRINT(x) \
504 ((eeprom_ch->flags & EEPROM_CHANNEL_##x) ? # x " " : "")
505
506static void iwl_mod_ht40_chan_info(struct device *dev,
507 struct iwl_eeprom_data *data, int n_channels,
508 enum ieee80211_band band, u16 channel,
509 const struct iwl_eeprom_channel *eeprom_ch,
510 u8 clear_ht40_extension_channel)
511{
512 struct ieee80211_channel *chan = NULL;
513 int i;
514
515 for (i = 0; i < n_channels; i++) {
516 if (data->channels[i].band != band)
517 continue;
518 if (data->channels[i].hw_value != channel)
519 continue;
520 chan = &data->channels[i];
521 break;
522 }
523
524 if (!chan)
525 return;
526
527 IWL_DEBUG_EEPROM(dev,
528 "HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm): Ad-Hoc %ssupported\n",
529 channel,
530 band == IEEE80211_BAND_5GHZ ? "5.2" : "2.4",
531 CHECK_AND_PRINT(IBSS),
532 CHECK_AND_PRINT(ACTIVE),
533 CHECK_AND_PRINT(RADAR),
534 CHECK_AND_PRINT(WIDE),
535 CHECK_AND_PRINT(DFS),
536 eeprom_ch->flags,
537 eeprom_ch->max_power_avg,
538 ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS) &&
539 !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ? ""
540 : "not ");
541
542 if (eeprom_ch->flags & EEPROM_CHANNEL_VALID)
543 chan->flags &= ~clear_ht40_extension_channel;
544}
545
546#define CHECK_AND_PRINT_I(x) \
547 ((eeprom_ch_info[ch_idx].flags & EEPROM_CHANNEL_##x) ? # x " " : "")
548
549static int iwl_init_channel_map(struct device *dev, const struct iwl_cfg *cfg,
550 struct iwl_eeprom_data *data,
551 const u8 *eeprom, size_t eeprom_size)
552{
553 int band, ch_idx;
554 const struct iwl_eeprom_channel *eeprom_ch_info;
555 const u8 *eeprom_ch_array;
556 int eeprom_ch_count;
557 int n_channels = 0;
558
559 /*
560 * Loop through the 5 EEPROM bands and add them to the parse list
561 */
562 for (band = 1; band <= 5; band++) {
563 struct ieee80211_channel *channel;
564
565 iwl_init_band_reference(cfg, eeprom, eeprom_size, band,
566 &eeprom_ch_count, &eeprom_ch_info,
567 &eeprom_ch_array);
568
569 /* Loop through each band adding each of the channels */
570 for (ch_idx = 0; ch_idx < eeprom_ch_count; ch_idx++) {
571 const struct iwl_eeprom_channel *eeprom_ch;
572
573 eeprom_ch = &eeprom_ch_info[ch_idx];
574
575 if (!(eeprom_ch->flags & EEPROM_CHANNEL_VALID)) {
576 IWL_DEBUG_EEPROM(dev,
577 "Ch. %d Flags %x [%sGHz] - No traffic\n",
578 eeprom_ch_array[ch_idx],
579 eeprom_ch_info[ch_idx].flags,
580 (band != 1) ? "5.2" : "2.4");
581 continue;
582 }
583
584 channel = &data->channels[n_channels];
585 n_channels++;
586
587 channel->hw_value = eeprom_ch_array[ch_idx];
588 channel->band = (band == 1) ? IEEE80211_BAND_2GHZ
589 : IEEE80211_BAND_5GHZ;
590 channel->center_freq =
591 ieee80211_channel_to_frequency(
592 channel->hw_value, channel->band);
593
594 /* set no-HT40, will enable as appropriate later */
595 channel->flags = IEEE80211_CHAN_NO_HT40;
596
597 if (!(eeprom_ch->flags & EEPROM_CHANNEL_IBSS))
598 channel->flags |= IEEE80211_CHAN_NO_IBSS;
599
600 if (!(eeprom_ch->flags & EEPROM_CHANNEL_ACTIVE))
601 channel->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
602
603 if (eeprom_ch->flags & EEPROM_CHANNEL_RADAR)
604 channel->flags |= IEEE80211_CHAN_RADAR;
605
606 /* Initialize regulatory-based run-time data */
607 channel->max_power =
608 eeprom_ch_info[ch_idx].max_power_avg;
609 IWL_DEBUG_EEPROM(dev,
610 "Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x %ddBm): Ad-Hoc %ssupported\n",
611 channel->hw_value,
612 (band != 1) ? "5.2" : "2.4",
613 CHECK_AND_PRINT_I(VALID),
614 CHECK_AND_PRINT_I(IBSS),
615 CHECK_AND_PRINT_I(ACTIVE),
616 CHECK_AND_PRINT_I(RADAR),
617 CHECK_AND_PRINT_I(WIDE),
618 CHECK_AND_PRINT_I(DFS),
619 eeprom_ch_info[ch_idx].flags,
620 eeprom_ch_info[ch_idx].max_power_avg,
621 ((eeprom_ch_info[ch_idx].flags &
622 EEPROM_CHANNEL_IBSS) &&
623 !(eeprom_ch_info[ch_idx].flags &
624 EEPROM_CHANNEL_RADAR))
625 ? "" : "not ");
626 }
627 }
628
629 if (cfg->eeprom_params->enhanced_txpower) {
630 /*
631 * for newer device (6000 series and up)
632 * EEPROM contain enhanced tx power information
633 * driver need to process addition information
634 * to determine the max channel tx power limits
635 */
636 iwl_eeprom_enhanced_txpower(dev, data, eeprom, eeprom_size,
637 n_channels);
638 } else {
639 /* All others use data from channel map */
640 int i;
641
642 data->max_tx_pwr_half_dbm = -128;
643
644 for (i = 0; i < n_channels; i++)
645 data->max_tx_pwr_half_dbm =
646 max_t(s8, data->max_tx_pwr_half_dbm,
647 data->channels[i].max_power * 2);
648 }
649
650 /* Check if we do have HT40 channels */
651 if (cfg->eeprom_params->regulatory_bands[5] ==
652 EEPROM_REGULATORY_BAND_NO_HT40 &&
653 cfg->eeprom_params->regulatory_bands[6] ==
654 EEPROM_REGULATORY_BAND_NO_HT40)
655 return n_channels;
656
657 /* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */
658 for (band = 6; band <= 7; band++) {
659 enum ieee80211_band ieeeband;
660
661 iwl_init_band_reference(cfg, eeprom, eeprom_size, band,
662 &eeprom_ch_count, &eeprom_ch_info,
663 &eeprom_ch_array);
664
665 /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
666 ieeeband = (band == 6) ? IEEE80211_BAND_2GHZ
667 : IEEE80211_BAND_5GHZ;
668
669 /* Loop through each band adding each of the channels */
670 for (ch_idx = 0; ch_idx < eeprom_ch_count; ch_idx++) {
671 /* Set up driver's info for lower half */
672 iwl_mod_ht40_chan_info(dev, data, n_channels, ieeeband,
673 eeprom_ch_array[ch_idx],
674 &eeprom_ch_info[ch_idx],
675 IEEE80211_CHAN_NO_HT40PLUS);
676
677 /* Set up driver's info for upper half */
678 iwl_mod_ht40_chan_info(dev, data, n_channels, ieeeband,
679 eeprom_ch_array[ch_idx] + 4,
680 &eeprom_ch_info[ch_idx],
681 IEEE80211_CHAN_NO_HT40MINUS);
682 }
683 }
684
685 return n_channels;
686}
687
688static int iwl_init_sband_channels(struct iwl_eeprom_data *data,
689 struct ieee80211_supported_band *sband,
690 int n_channels, enum ieee80211_band band)
691{
692 struct ieee80211_channel *chan = &data->channels[0];
693 int n = 0, idx = 0;
694
695 while (chan->band != band && idx < n_channels)
696 chan = &data->channels[++idx];
697
698 sband->channels = &data->channels[idx];
699
700 while (chan->band == band && idx < n_channels) {
701 chan = &data->channels[++idx];
702 n++;
703 }
704
705 sband->n_channels = n;
706
707 return n;
708}
709
710#define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
711#define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
712
713static void iwl_init_ht_hw_capab(const struct iwl_cfg *cfg,
714 struct iwl_eeprom_data *data,
715 struct ieee80211_sta_ht_cap *ht_info,
716 enum ieee80211_band band)
717{
718 int max_bit_rate = 0;
719 u8 rx_chains;
720 u8 tx_chains;
721
722 tx_chains = hweight8(data->valid_tx_ant);
723 if (cfg->rx_with_siso_diversity)
724 rx_chains = 1;
725 else
726 rx_chains = hweight8(data->valid_rx_ant);
727
728 if (!(data->sku & EEPROM_SKU_CAP_11N_ENABLE) || !cfg->ht_params) {
729 ht_info->ht_supported = false;
730 return;
731 }
732
733 ht_info->ht_supported = true;
734 ht_info->cap = 0;
735
736 if (iwlwifi_mod_params.amsdu_size_8K)
737 ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
738
739 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
740 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_4;
741
742 ht_info->mcs.rx_mask[0] = 0xFF;
743 if (rx_chains >= 2)
744 ht_info->mcs.rx_mask[1] = 0xFF;
745 if (rx_chains >= 3)
746 ht_info->mcs.rx_mask[2] = 0xFF;
747
748 if (cfg->ht_params->ht_greenfield_support)
749 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
750 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
751
752 max_bit_rate = MAX_BIT_RATE_20_MHZ;
753
754 if (cfg->ht_params->ht40_bands & BIT(band)) {
755 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
756 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
757 ht_info->mcs.rx_mask[4] = 0x01;
758 max_bit_rate = MAX_BIT_RATE_40_MHZ;
759 }
760
761 /* Highest supported Rx data rate */
762 max_bit_rate *= rx_chains;
763 WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
764 ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
765
766 /* Tx MCS capabilities */
767 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
768 if (tx_chains != rx_chains) {
769 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
770 ht_info->mcs.tx_params |= ((tx_chains - 1) <<
771 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
772 }
773}
774
775static void iwl_init_sbands(struct device *dev, const struct iwl_cfg *cfg,
776 struct iwl_eeprom_data *data,
777 const u8 *eeprom, size_t eeprom_size)
778{
779 int n_channels = iwl_init_channel_map(dev, cfg, data,
780 eeprom, eeprom_size);
781 int n_used = 0;
782 struct ieee80211_supported_band *sband;
783
784 sband = &data->bands[IEEE80211_BAND_2GHZ];
785 sband->band = IEEE80211_BAND_2GHZ;
786 sband->bitrates = &iwl_cfg80211_rates[RATES_24_OFFS];
787 sband->n_bitrates = N_RATES_24;
788 n_used += iwl_init_sband_channels(data, sband, n_channels,
789 IEEE80211_BAND_2GHZ);
790 iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, IEEE80211_BAND_2GHZ);
791
792 sband = &data->bands[IEEE80211_BAND_5GHZ];
793 sband->band = IEEE80211_BAND_5GHZ;
794 sband->bitrates = &iwl_cfg80211_rates[RATES_52_OFFS];
795 sband->n_bitrates = N_RATES_52;
796 n_used += iwl_init_sband_channels(data, sband, n_channels,
797 IEEE80211_BAND_5GHZ);
798 iwl_init_ht_hw_capab(cfg, data, &sband->ht_cap, IEEE80211_BAND_5GHZ);
799
800 if (n_channels != n_used)
801 IWL_ERR_DEV(dev, "EEPROM: used only %d of %d channels\n",
802 n_used, n_channels);
803}
804
805/* EEPROM data functions */
806
807struct iwl_eeprom_data *
808iwl_parse_eeprom_data(struct device *dev, const struct iwl_cfg *cfg,
809 const u8 *eeprom, size_t eeprom_size)
810{
811 struct iwl_eeprom_data *data;
812 const void *tmp;
813
814 if (WARN_ON(!cfg || !cfg->eeprom_params))
815 return NULL;
816
817 data = kzalloc(sizeof(*data) +
818 sizeof(struct ieee80211_channel) * IWL_NUM_CHANNELS,
819 GFP_KERNEL);
820 if (!data)
821 return NULL;
822
823 /* get MAC address(es) */
824 tmp = iwl_eeprom_query_addr(eeprom, eeprom_size, EEPROM_MAC_ADDRESS);
825 if (!tmp)
826 goto err_free;
827 memcpy(data->hw_addr, tmp, ETH_ALEN);
828 data->n_hw_addrs = iwl_eeprom_query16(eeprom, eeprom_size,
829 EEPROM_NUM_MAC_ADDRESS);
830
831 if (iwl_eeprom_read_calib(eeprom, eeprom_size, data))
832 goto err_free;
833
834 tmp = iwl_eeprom_query_addr(eeprom, eeprom_size, EEPROM_XTAL);
835 if (!tmp)
836 goto err_free;
837 memcpy(data->xtal_calib, tmp, sizeof(data->xtal_calib));
838
839 tmp = iwl_eeprom_query_addr(eeprom, eeprom_size,
840 EEPROM_RAW_TEMPERATURE);
841 if (!tmp)
842 goto err_free;
843 data->raw_temperature = *(__le16 *)tmp;
844
845 tmp = iwl_eeprom_query_addr(eeprom, eeprom_size,
846 EEPROM_KELVIN_TEMPERATURE);
847 if (!tmp)
848 goto err_free;
849 data->kelvin_temperature = *(__le16 *)tmp;
850 data->kelvin_voltage = *((__le16 *)tmp + 1);
851
852 data->radio_cfg = iwl_eeprom_query16(eeprom, eeprom_size,
853 EEPROM_RADIO_CONFIG);
854 data->sku = iwl_eeprom_query16(eeprom, eeprom_size,
855 EEPROM_SKU_CAP);
856 data->eeprom_version = iwl_eeprom_query16(eeprom, eeprom_size,
857 EEPROM_VERSION);
858
859 data->valid_tx_ant = EEPROM_RF_CFG_TX_ANT_MSK(data->radio_cfg);
860 data->valid_rx_ant = EEPROM_RF_CFG_RX_ANT_MSK(data->radio_cfg);
861
862 /* check overrides (some devices have wrong EEPROM) */
863 if (cfg->valid_tx_ant)
864 data->valid_tx_ant = cfg->valid_tx_ant;
865 if (cfg->valid_rx_ant)
866 data->valid_rx_ant = cfg->valid_rx_ant;
867
868 if (!data->valid_tx_ant || !data->valid_rx_ant) {
869 IWL_ERR_DEV(dev, "invalid antennas (0x%x, 0x%x)\n",
870 data->valid_tx_ant, data->valid_rx_ant);
871 goto err_free;
872 }
873
874 iwl_init_sbands(dev, cfg, data, eeprom, eeprom_size);
875
876 return data;
877 err_free:
878 kfree(data);
879 return NULL;
880}
881EXPORT_SYMBOL_GPL(iwl_parse_eeprom_data);
882
883/* helper functions */
884int iwl_eeprom_check_version(struct iwl_eeprom_data *data,
885 struct iwl_trans *trans)
886{
887 if (data->eeprom_version >= trans->cfg->eeprom_ver ||
888 data->calib_version >= trans->cfg->eeprom_calib_ver) {
889 IWL_INFO(trans, "device EEPROM VER=0x%x, CALIB=0x%x\n",
890 data->eeprom_version, data->calib_version);
891 return 0;
892 }
893
894 IWL_ERR(trans,
895 "Unsupported (too old) EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
896 data->eeprom_version, trans->cfg->eeprom_ver,
897 data->calib_version, trans->cfg->eeprom_calib_ver);
898 return -EINVAL;
899}
900EXPORT_SYMBOL_GPL(iwl_eeprom_check_version);
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.h b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.h
new file mode 100644
index 000000000000..9c07c670a1ce
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom-parse.h
@@ -0,0 +1,138 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
62#ifndef __iwl_eeprom_parse_h__
63#define __iwl_eeprom_parse_h__
64
65#include <linux/types.h>
66#include <linux/if_ether.h>
67#include "iwl-trans.h"
68
69/* SKU Capabilities (actual values from EEPROM definition) */
70#define EEPROM_SKU_CAP_BAND_24GHZ (1 << 4)
71#define EEPROM_SKU_CAP_BAND_52GHZ (1 << 5)
72#define EEPROM_SKU_CAP_11N_ENABLE (1 << 6)
73#define EEPROM_SKU_CAP_AMT_ENABLE (1 << 7)
74#define EEPROM_SKU_CAP_IPAN_ENABLE (1 << 8)
75
76/* radio config bits (actual values from EEPROM definition) */
77#define EEPROM_RF_CFG_TYPE_MSK(x) (x & 0x3) /* bits 0-1 */
78#define EEPROM_RF_CFG_STEP_MSK(x) ((x >> 2) & 0x3) /* bits 2-3 */
79#define EEPROM_RF_CFG_DASH_MSK(x) ((x >> 4) & 0x3) /* bits 4-5 */
80#define EEPROM_RF_CFG_PNUM_MSK(x) ((x >> 6) & 0x3) /* bits 6-7 */
81#define EEPROM_RF_CFG_TX_ANT_MSK(x) ((x >> 8) & 0xF) /* bits 8-11 */
82#define EEPROM_RF_CFG_RX_ANT_MSK(x) ((x >> 12) & 0xF) /* bits 12-15 */
83
84struct iwl_eeprom_data {
85 int n_hw_addrs;
86 u8 hw_addr[ETH_ALEN];
87
88 u16 radio_config;
89
90 u8 calib_version;
91 __le16 calib_voltage;
92
93 __le16 raw_temperature;
94 __le16 kelvin_temperature;
95 __le16 kelvin_voltage;
96 __le16 xtal_calib[2];
97
98 u16 sku;
99 u16 radio_cfg;
100 u16 eeprom_version;
101 s8 max_tx_pwr_half_dbm;
102
103 u8 valid_tx_ant, valid_rx_ant;
104
105 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
106 struct ieee80211_channel channels[];
107};
108
109/**
110 * iwl_parse_eeprom_data - parse EEPROM data and return values
111 *
112 * @dev: device pointer we're parsing for, for debug only
113 * @cfg: device configuration for parsing and overrides
114 * @eeprom: the EEPROM data
115 * @eeprom_size: length of the EEPROM data
116 *
117 * This function parses all EEPROM values we need and then
118 * returns a (newly allocated) struct containing all the
119 * relevant values for driver use. The struct must be freed
120 * later with iwl_free_eeprom_data().
121 */
122struct iwl_eeprom_data *
123iwl_parse_eeprom_data(struct device *dev, const struct iwl_cfg *cfg,
124 const u8 *eeprom, size_t eeprom_size);
125
126/**
127 * iwl_free_eeprom_data - free EEPROM data
128 * @data: the data to free
129 */
130static inline void iwl_free_eeprom_data(struct iwl_eeprom_data *data)
131{
132 kfree(data);
133}
134
135int iwl_eeprom_check_version(struct iwl_eeprom_data *data,
136 struct iwl_trans *trans);
137
138#endif /* __iwl_eeprom_parse_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom-read.c b/drivers/net/wireless/iwlwifi/iwl-eeprom-read.c
new file mode 100644
index 000000000000..27c7da3c6ed1
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom-read.c
@@ -0,0 +1,463 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
62#include <linux/types.h>
63#include <linux/slab.h>
64#include <linux/export.h>
65
66#include "iwl-debug.h"
67#include "iwl-eeprom-read.h"
68#include "iwl-io.h"
69#include "iwl-prph.h"
70#include "iwl-csr.h"
71
72/*
73 * EEPROM access time values:
74 *
75 * Driver initiates EEPROM read by writing byte address << 1 to CSR_EEPROM_REG.
76 * Driver then polls CSR_EEPROM_REG for CSR_EEPROM_REG_READ_VALID_MSK (0x1).
77 * When polling, wait 10 uSec between polling loops, up to a maximum 5000 uSec.
78 * Driver reads 16-bit value from bits 31-16 of CSR_EEPROM_REG.
79 */
80#define IWL_EEPROM_ACCESS_TIMEOUT 5000 /* uSec */
81
82#define IWL_EEPROM_SEM_TIMEOUT 10 /* microseconds */
83#define IWL_EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
84
85
86/*
87 * The device's EEPROM semaphore prevents conflicts between driver and uCode
88 * when accessing the EEPROM; each access is a series of pulses to/from the
89 * EEPROM chip, not a single event, so even reads could conflict if they
90 * weren't arbitrated by the semaphore.
91 */
92
93#define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
94#define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
95
96static int iwl_eeprom_acquire_semaphore(struct iwl_trans *trans)
97{
98 u16 count;
99 int ret;
100
101 for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
102 /* Request semaphore */
103 iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
104 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
105
106 /* See if we got it */
107 ret = iwl_poll_bit(trans, CSR_HW_IF_CONFIG_REG,
108 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
109 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
110 EEPROM_SEM_TIMEOUT);
111 if (ret >= 0) {
112 IWL_DEBUG_EEPROM(trans->dev,
113 "Acquired semaphore after %d tries.\n",
114 count+1);
115 return ret;
116 }
117 }
118
119 return ret;
120}
121
122static void iwl_eeprom_release_semaphore(struct iwl_trans *trans)
123{
124 iwl_clear_bit(trans, CSR_HW_IF_CONFIG_REG,
125 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
126}
127
128static int iwl_eeprom_verify_signature(struct iwl_trans *trans, bool nvm_is_otp)
129{
130 u32 gp = iwl_read32(trans, CSR_EEPROM_GP) & CSR_EEPROM_GP_VALID_MSK;
131
132 IWL_DEBUG_EEPROM(trans->dev, "EEPROM signature=0x%08x\n", gp);
133
134 switch (gp) {
135 case CSR_EEPROM_GP_BAD_SIG_EEP_GOOD_SIG_OTP:
136 if (!nvm_is_otp) {
137 IWL_ERR(trans, "EEPROM with bad signature: 0x%08x\n",
138 gp);
139 return -ENOENT;
140 }
141 return 0;
142 case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K:
143 case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K:
144 if (nvm_is_otp) {
145 IWL_ERR(trans, "OTP with bad signature: 0x%08x\n", gp);
146 return -ENOENT;
147 }
148 return 0;
149 case CSR_EEPROM_GP_BAD_SIGNATURE_BOTH_EEP_AND_OTP:
150 default:
151 IWL_ERR(trans,
152 "bad EEPROM/OTP signature, type=%s, EEPROM_GP=0x%08x\n",
153 nvm_is_otp ? "OTP" : "EEPROM", gp);
154 return -ENOENT;
155 }
156}
157
158/******************************************************************************
159 *
160 * OTP related functions
161 *
162******************************************************************************/
163
164static void iwl_set_otp_access_absolute(struct iwl_trans *trans)
165{
166 iwl_read32(trans, CSR_OTP_GP_REG);
167
168 iwl_clear_bit(trans, CSR_OTP_GP_REG,
169 CSR_OTP_GP_REG_OTP_ACCESS_MODE);
170}
171
172static int iwl_nvm_is_otp(struct iwl_trans *trans)
173{
174 u32 otpgp;
175
176 /* OTP only valid for CP/PP and after */
177 switch (trans->hw_rev & CSR_HW_REV_TYPE_MSK) {
178 case CSR_HW_REV_TYPE_NONE:
179 IWL_ERR(trans, "Unknown hardware type\n");
180 return -EIO;
181 case CSR_HW_REV_TYPE_5300:
182 case CSR_HW_REV_TYPE_5350:
183 case CSR_HW_REV_TYPE_5100:
184 case CSR_HW_REV_TYPE_5150:
185 return 0;
186 default:
187 otpgp = iwl_read32(trans, CSR_OTP_GP_REG);
188 if (otpgp & CSR_OTP_GP_REG_DEVICE_SELECT)
189 return 1;
190 return 0;
191 }
192}
193
194static int iwl_init_otp_access(struct iwl_trans *trans)
195{
196 int ret;
197
198 /* Enable 40MHz radio clock */
199 iwl_write32(trans, CSR_GP_CNTRL,
200 iwl_read32(trans, CSR_GP_CNTRL) |
201 CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
202
203 /* wait for clock to be ready */
204 ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
205 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
206 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
207 25000);
208 if (ret < 0) {
209 IWL_ERR(trans, "Time out access OTP\n");
210 } else {
211 iwl_set_bits_prph(trans, APMG_PS_CTRL_REG,
212 APMG_PS_CTRL_VAL_RESET_REQ);
213 udelay(5);
214 iwl_clear_bits_prph(trans, APMG_PS_CTRL_REG,
215 APMG_PS_CTRL_VAL_RESET_REQ);
216
217 /*
218 * CSR auto clock gate disable bit -
219 * this is only applicable for HW with OTP shadow RAM
220 */
221 if (trans->cfg->base_params->shadow_ram_support)
222 iwl_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG,
223 CSR_RESET_LINK_PWR_MGMT_DISABLED);
224 }
225 return ret;
226}
227
228static int iwl_read_otp_word(struct iwl_trans *trans, u16 addr,
229 __le16 *eeprom_data)
230{
231 int ret = 0;
232 u32 r;
233 u32 otpgp;
234
235 iwl_write32(trans, CSR_EEPROM_REG,
236 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
237 ret = iwl_poll_bit(trans, CSR_EEPROM_REG,
238 CSR_EEPROM_REG_READ_VALID_MSK,
239 CSR_EEPROM_REG_READ_VALID_MSK,
240 IWL_EEPROM_ACCESS_TIMEOUT);
241 if (ret < 0) {
242 IWL_ERR(trans, "Time out reading OTP[%d]\n", addr);
243 return ret;
244 }
245 r = iwl_read32(trans, CSR_EEPROM_REG);
246 /* check for ECC errors: */
247 otpgp = iwl_read32(trans, CSR_OTP_GP_REG);
248 if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
249 /* stop in this case */
250 /* set the uncorrectable OTP ECC bit for acknowledgement */
251 iwl_set_bit(trans, CSR_OTP_GP_REG,
252 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
253 IWL_ERR(trans, "Uncorrectable OTP ECC error, abort OTP read\n");
254 return -EINVAL;
255 }
256 if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
257 /* continue in this case */
258 /* set the correctable OTP ECC bit for acknowledgement */
259 iwl_set_bit(trans, CSR_OTP_GP_REG,
260 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
261 IWL_ERR(trans, "Correctable OTP ECC error, continue read\n");
262 }
263 *eeprom_data = cpu_to_le16(r >> 16);
264 return 0;
265}
266
267/*
268 * iwl_is_otp_empty: check for empty OTP
269 */
270static bool iwl_is_otp_empty(struct iwl_trans *trans)
271{
272 u16 next_link_addr = 0;
273 __le16 link_value;
274 bool is_empty = false;
275
276 /* locate the beginning of OTP link list */
277 if (!iwl_read_otp_word(trans, next_link_addr, &link_value)) {
278 if (!link_value) {
279 IWL_ERR(trans, "OTP is empty\n");
280 is_empty = true;
281 }
282 } else {
283 IWL_ERR(trans, "Unable to read first block of OTP list.\n");
284 is_empty = true;
285 }
286
287 return is_empty;
288}
289
290
291/*
292 * iwl_find_otp_image: find EEPROM image in OTP
293 * finding the OTP block that contains the EEPROM image.
294 * the last valid block on the link list (the block _before_ the last block)
295 * is the block we should read and used to configure the device.
296 * If all the available OTP blocks are full, the last block will be the block
297 * we should read and used to configure the device.
298 * only perform this operation if shadow RAM is disabled
299 */
300static int iwl_find_otp_image(struct iwl_trans *trans,
301 u16 *validblockaddr)
302{
303 u16 next_link_addr = 0, valid_addr;
304 __le16 link_value = 0;
305 int usedblocks = 0;
306
307 /* set addressing mode to absolute to traverse the link list */
308 iwl_set_otp_access_absolute(trans);
309
310 /* checking for empty OTP or error */
311 if (iwl_is_otp_empty(trans))
312 return -EINVAL;
313
314 /*
315 * start traverse link list
316 * until reach the max number of OTP blocks
317 * different devices have different number of OTP blocks
318 */
319 do {
320 /* save current valid block address
321 * check for more block on the link list
322 */
323 valid_addr = next_link_addr;
324 next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
325 IWL_DEBUG_EEPROM(trans->dev, "OTP blocks %d addr 0x%x\n",
326 usedblocks, next_link_addr);
327 if (iwl_read_otp_word(trans, next_link_addr, &link_value))
328 return -EINVAL;
329 if (!link_value) {
330 /*
331 * reach the end of link list, return success and
332 * set address point to the starting address
333 * of the image
334 */
335 *validblockaddr = valid_addr;
336 /* skip first 2 bytes (link list pointer) */
337 *validblockaddr += 2;
338 return 0;
339 }
340 /* more in the link list, continue */
341 usedblocks++;
342 } while (usedblocks <= trans->cfg->base_params->max_ll_items);
343
344 /* OTP has no valid blocks */
345 IWL_DEBUG_EEPROM(trans->dev, "OTP has no valid blocks\n");
346 return -EINVAL;
347}
348
349/**
350 * iwl_read_eeprom - read EEPROM contents
351 *
352 * Load the EEPROM contents from adapter and return it
353 * and its size.
354 *
355 * NOTE: This routine uses the non-debug IO access functions.
356 */
357int iwl_read_eeprom(struct iwl_trans *trans, u8 **eeprom, size_t *eeprom_size)
358{
359 __le16 *e;
360 u32 gp = iwl_read32(trans, CSR_EEPROM_GP);
361 int sz;
362 int ret;
363 u16 addr;
364 u16 validblockaddr = 0;
365 u16 cache_addr = 0;
366 int nvm_is_otp;
367
368 if (!eeprom || !eeprom_size)
369 return -EINVAL;
370
371 nvm_is_otp = iwl_nvm_is_otp(trans);
372 if (nvm_is_otp < 0)
373 return nvm_is_otp;
374
375 sz = trans->cfg->base_params->eeprom_size;
376 IWL_DEBUG_EEPROM(trans->dev, "NVM size = %d\n", sz);
377
378 e = kmalloc(sz, GFP_KERNEL);
379 if (!e)
380 return -ENOMEM;
381
382 ret = iwl_eeprom_verify_signature(trans, nvm_is_otp);
383 if (ret < 0) {
384 IWL_ERR(trans, "EEPROM not found, EEPROM_GP=0x%08x\n", gp);
385 goto err_free;
386 }
387
388 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
389 ret = iwl_eeprom_acquire_semaphore(trans);
390 if (ret < 0) {
391 IWL_ERR(trans, "Failed to acquire EEPROM semaphore.\n");
392 goto err_free;
393 }
394
395 if (nvm_is_otp) {
396 ret = iwl_init_otp_access(trans);
397 if (ret) {
398 IWL_ERR(trans, "Failed to initialize OTP access.\n");
399 goto err_unlock;
400 }
401
402 iwl_write32(trans, CSR_EEPROM_GP,
403 iwl_read32(trans, CSR_EEPROM_GP) &
404 ~CSR_EEPROM_GP_IF_OWNER_MSK);
405
406 iwl_set_bit(trans, CSR_OTP_GP_REG,
407 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK |
408 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
409 /* traversing the linked list if no shadow ram supported */
410 if (!trans->cfg->base_params->shadow_ram_support) {
411 ret = iwl_find_otp_image(trans, &validblockaddr);
412 if (ret)
413 goto err_unlock;
414 }
415 for (addr = validblockaddr; addr < validblockaddr + sz;
416 addr += sizeof(u16)) {
417 __le16 eeprom_data;
418
419 ret = iwl_read_otp_word(trans, addr, &eeprom_data);
420 if (ret)
421 goto err_unlock;
422 e[cache_addr / 2] = eeprom_data;
423 cache_addr += sizeof(u16);
424 }
425 } else {
426 /* eeprom is an array of 16bit values */
427 for (addr = 0; addr < sz; addr += sizeof(u16)) {
428 u32 r;
429
430 iwl_write32(trans, CSR_EEPROM_REG,
431 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
432
433 ret = iwl_poll_bit(trans, CSR_EEPROM_REG,
434 CSR_EEPROM_REG_READ_VALID_MSK,
435 CSR_EEPROM_REG_READ_VALID_MSK,
436 IWL_EEPROM_ACCESS_TIMEOUT);
437 if (ret < 0) {
438 IWL_ERR(trans,
439 "Time out reading EEPROM[%d]\n", addr);
440 goto err_unlock;
441 }
442 r = iwl_read32(trans, CSR_EEPROM_REG);
443 e[addr / 2] = cpu_to_le16(r >> 16);
444 }
445 }
446
447 IWL_DEBUG_EEPROM(trans->dev, "NVM Type: %s\n",
448 nvm_is_otp ? "OTP" : "EEPROM");
449
450 iwl_eeprom_release_semaphore(trans);
451
452 *eeprom_size = sz;
453 *eeprom = (u8 *)e;
454 return 0;
455
456 err_unlock:
457 iwl_eeprom_release_semaphore(trans);
458 err_free:
459 kfree(e);
460
461 return ret;
462}
463EXPORT_SYMBOL_GPL(iwl_read_eeprom);
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom-read.h b/drivers/net/wireless/iwlwifi/iwl-eeprom-read.h
new file mode 100644
index 000000000000..1337c9d36fee
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-eeprom-read.h
@@ -0,0 +1,70 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
62
63#ifndef __iwl_eeprom_h__
64#define __iwl_eeprom_h__
65
66#include "iwl-trans.h"
67
68int iwl_read_eeprom(struct iwl_trans *trans, u8 **eeprom, size_t *eeprom_size);
69
70#endif /* __iwl_eeprom_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.c b/drivers/net/wireless/iwlwifi/iwl-eeprom.c
deleted file mode 100644
index b8e2b223ac36..000000000000
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.c
+++ /dev/null
@@ -1,1148 +0,0 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
62
63
64#include <linux/kernel.h>
65#include <linux/module.h>
66#include <linux/slab.h>
67#include <linux/init.h>
68
69#include <net/mac80211.h>
70
71#include "iwl-dev.h"
72#include "iwl-debug.h"
73#include "iwl-agn.h"
74#include "iwl-eeprom.h"
75#include "iwl-io.h"
76#include "iwl-prph.h"
77
78/************************** EEPROM BANDS ****************************
79 *
80 * The iwl_eeprom_band definitions below provide the mapping from the
81 * EEPROM contents to the specific channel number supported for each
82 * band.
83 *
84 * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3
85 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
86 * The specific geography and calibration information for that channel
87 * is contained in the eeprom map itself.
88 *
89 * During init, we copy the eeprom information and channel map
90 * information into priv->channel_info_24/52 and priv->channel_map_24/52
91 *
92 * channel_map_24/52 provides the index in the channel_info array for a
93 * given channel. We have to have two separate maps as there is channel
94 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
95 * band_2
96 *
97 * A value of 0xff stored in the channel_map indicates that the channel
98 * is not supported by the hardware at all.
99 *
100 * A value of 0xfe in the channel_map indicates that the channel is not
101 * valid for Tx with the current hardware. This means that
102 * while the system can tune and receive on a given channel, it may not
103 * be able to associate or transmit any frames on that
104 * channel. There is no corresponding channel information for that
105 * entry.
106 *
107 *********************************************************************/
108
109/* 2.4 GHz */
110const u8 iwl_eeprom_band_1[14] = {
111 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
112};
113
114/* 5.2 GHz bands */
115static const u8 iwl_eeprom_band_2[] = { /* 4915-5080MHz */
116 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
117};
118
119static const u8 iwl_eeprom_band_3[] = { /* 5170-5320MHz */
120 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
121};
122
123static const u8 iwl_eeprom_band_4[] = { /* 5500-5700MHz */
124 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
125};
126
127static const u8 iwl_eeprom_band_5[] = { /* 5725-5825MHz */
128 145, 149, 153, 157, 161, 165
129};
130
131static const u8 iwl_eeprom_band_6[] = { /* 2.4 ht40 channel */
132 1, 2, 3, 4, 5, 6, 7
133};
134
135static const u8 iwl_eeprom_band_7[] = { /* 5.2 ht40 channel */
136 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157
137};
138
139/******************************************************************************
140 *
141 * generic NVM functions
142 *
143******************************************************************************/
144
145/*
146 * The device's EEPROM semaphore prevents conflicts between driver and uCode
147 * when accessing the EEPROM; each access is a series of pulses to/from the
148 * EEPROM chip, not a single event, so even reads could conflict if they
149 * weren't arbitrated by the semaphore.
150 */
151
152#define EEPROM_SEM_TIMEOUT 10 /* milliseconds */
153#define EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
154
155static int iwl_eeprom_acquire_semaphore(struct iwl_trans *trans)
156{
157 u16 count;
158 int ret;
159
160 for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
161 /* Request semaphore */
162 iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
163 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
164
165 /* See if we got it */
166 ret = iwl_poll_bit(trans, CSR_HW_IF_CONFIG_REG,
167 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
168 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
169 EEPROM_SEM_TIMEOUT);
170 if (ret >= 0) {
171 IWL_DEBUG_EEPROM(trans,
172 "Acquired semaphore after %d tries.\n",
173 count+1);
174 return ret;
175 }
176 }
177
178 return ret;
179}
180
181static void iwl_eeprom_release_semaphore(struct iwl_trans *trans)
182{
183 iwl_clear_bit(trans, CSR_HW_IF_CONFIG_REG,
184 CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
185
186}
187
188static int iwl_eeprom_verify_signature(struct iwl_priv *priv)
189{
190 u32 gp = iwl_read32(priv->trans, CSR_EEPROM_GP) &
191 CSR_EEPROM_GP_VALID_MSK;
192 int ret = 0;
193
194 IWL_DEBUG_EEPROM(priv, "EEPROM signature=0x%08x\n", gp);
195 switch (gp) {
196 case CSR_EEPROM_GP_BAD_SIG_EEP_GOOD_SIG_OTP:
197 if (priv->nvm_device_type != NVM_DEVICE_TYPE_OTP) {
198 IWL_ERR(priv, "EEPROM with bad signature: 0x%08x\n",
199 gp);
200 ret = -ENOENT;
201 }
202 break;
203 case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K:
204 case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K:
205 if (priv->nvm_device_type != NVM_DEVICE_TYPE_EEPROM) {
206 IWL_ERR(priv, "OTP with bad signature: 0x%08x\n", gp);
207 ret = -ENOENT;
208 }
209 break;
210 case CSR_EEPROM_GP_BAD_SIGNATURE_BOTH_EEP_AND_OTP:
211 default:
212 IWL_ERR(priv, "bad EEPROM/OTP signature, type=%s, "
213 "EEPROM_GP=0x%08x\n",
214 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
215 ? "OTP" : "EEPROM", gp);
216 ret = -ENOENT;
217 break;
218 }
219 return ret;
220}
221
222u16 iwl_eeprom_query16(struct iwl_priv *priv, size_t offset)
223{
224 if (!priv->eeprom)
225 return 0;
226 return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8);
227}
228
229int iwl_eeprom_check_version(struct iwl_priv *priv)
230{
231 u16 eeprom_ver;
232 u16 calib_ver;
233
234 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
235 calib_ver = iwl_eeprom_calib_version(priv);
236
237 if (eeprom_ver < priv->cfg->eeprom_ver ||
238 calib_ver < priv->cfg->eeprom_calib_ver)
239 goto err;
240
241 IWL_INFO(priv, "device EEPROM VER=0x%x, CALIB=0x%x\n",
242 eeprom_ver, calib_ver);
243
244 return 0;
245err:
246 IWL_ERR(priv, "Unsupported (too old) EEPROM VER=0x%x < 0x%x "
247 "CALIB=0x%x < 0x%x\n",
248 eeprom_ver, priv->cfg->eeprom_ver,
249 calib_ver, priv->cfg->eeprom_calib_ver);
250 return -EINVAL;
251
252}
253
254int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
255{
256 u16 radio_cfg;
257
258 priv->hw_params.sku = iwl_eeprom_query16(priv, EEPROM_SKU_CAP);
259 if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE &&
260 !priv->cfg->ht_params) {
261 IWL_ERR(priv, "Invalid 11n configuration\n");
262 return -EINVAL;
263 }
264
265 if (!priv->hw_params.sku) {
266 IWL_ERR(priv, "Invalid device sku\n");
267 return -EINVAL;
268 }
269
270 IWL_INFO(priv, "Device SKU: 0x%X\n", priv->hw_params.sku);
271
272 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
273
274 priv->hw_params.valid_tx_ant = EEPROM_RF_CFG_TX_ANT_MSK(radio_cfg);
275 priv->hw_params.valid_rx_ant = EEPROM_RF_CFG_RX_ANT_MSK(radio_cfg);
276
277 /* check overrides (some devices have wrong EEPROM) */
278 if (priv->cfg->valid_tx_ant)
279 priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant;
280 if (priv->cfg->valid_rx_ant)
281 priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant;
282
283 if (!priv->hw_params.valid_tx_ant || !priv->hw_params.valid_rx_ant) {
284 IWL_ERR(priv, "Invalid chain (0x%X, 0x%X)\n",
285 priv->hw_params.valid_tx_ant,
286 priv->hw_params.valid_rx_ant);
287 return -EINVAL;
288 }
289
290 IWL_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
291 priv->hw_params.valid_tx_ant, priv->hw_params.valid_rx_ant);
292
293 return 0;
294}
295
296u16 iwl_eeprom_calib_version(struct iwl_priv *priv)
297{
298 struct iwl_eeprom_calib_hdr *hdr;
299
300 hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
301 EEPROM_CALIB_ALL);
302 return hdr->version;
303}
304
305static u32 eeprom_indirect_address(struct iwl_priv *priv, u32 address)
306{
307 u16 offset = 0;
308
309 if ((address & INDIRECT_ADDRESS) == 0)
310 return address;
311
312 switch (address & INDIRECT_TYPE_MSK) {
313 case INDIRECT_HOST:
314 offset = iwl_eeprom_query16(priv, EEPROM_LINK_HOST);
315 break;
316 case INDIRECT_GENERAL:
317 offset = iwl_eeprom_query16(priv, EEPROM_LINK_GENERAL);
318 break;
319 case INDIRECT_REGULATORY:
320 offset = iwl_eeprom_query16(priv, EEPROM_LINK_REGULATORY);
321 break;
322 case INDIRECT_TXP_LIMIT:
323 offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT);
324 break;
325 case INDIRECT_TXP_LIMIT_SIZE:
326 offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT_SIZE);
327 break;
328 case INDIRECT_CALIBRATION:
329 offset = iwl_eeprom_query16(priv, EEPROM_LINK_CALIBRATION);
330 break;
331 case INDIRECT_PROCESS_ADJST:
332 offset = iwl_eeprom_query16(priv, EEPROM_LINK_PROCESS_ADJST);
333 break;
334 case INDIRECT_OTHERS:
335 offset = iwl_eeprom_query16(priv, EEPROM_LINK_OTHERS);
336 break;
337 default:
338 IWL_ERR(priv, "illegal indirect type: 0x%X\n",
339 address & INDIRECT_TYPE_MSK);
340 break;
341 }
342
343 /* translate the offset from words to byte */
344 return (address & ADDRESS_MSK) + (offset << 1);
345}
346
347const u8 *iwl_eeprom_query_addr(struct iwl_priv *priv, size_t offset)
348{
349 u32 address = eeprom_indirect_address(priv, offset);
350 BUG_ON(address >= priv->cfg->base_params->eeprom_size);
351 return &priv->eeprom[address];
352}
353
354void iwl_eeprom_get_mac(struct iwl_priv *priv, u8 *mac)
355{
356 const u8 *addr = iwl_eeprom_query_addr(priv,
357 EEPROM_MAC_ADDRESS);
358 memcpy(mac, addr, ETH_ALEN);
359}
360
361/******************************************************************************
362 *
363 * OTP related functions
364 *
365******************************************************************************/
366
367static void iwl_set_otp_access(struct iwl_trans *trans,
368 enum iwl_access_mode mode)
369{
370 iwl_read32(trans, CSR_OTP_GP_REG);
371
372 if (mode == IWL_OTP_ACCESS_ABSOLUTE)
373 iwl_clear_bit(trans, CSR_OTP_GP_REG,
374 CSR_OTP_GP_REG_OTP_ACCESS_MODE);
375 else
376 iwl_set_bit(trans, CSR_OTP_GP_REG,
377 CSR_OTP_GP_REG_OTP_ACCESS_MODE);
378}
379
380static int iwl_get_nvm_type(struct iwl_trans *trans, u32 hw_rev)
381{
382 u32 otpgp;
383 int nvm_type;
384
385 /* OTP only valid for CP/PP and after */
386 switch (hw_rev & CSR_HW_REV_TYPE_MSK) {
387 case CSR_HW_REV_TYPE_NONE:
388 IWL_ERR(trans, "Unknown hardware type\n");
389 return -ENOENT;
390 case CSR_HW_REV_TYPE_5300:
391 case CSR_HW_REV_TYPE_5350:
392 case CSR_HW_REV_TYPE_5100:
393 case CSR_HW_REV_TYPE_5150:
394 nvm_type = NVM_DEVICE_TYPE_EEPROM;
395 break;
396 default:
397 otpgp = iwl_read32(trans, CSR_OTP_GP_REG);
398 if (otpgp & CSR_OTP_GP_REG_DEVICE_SELECT)
399 nvm_type = NVM_DEVICE_TYPE_OTP;
400 else
401 nvm_type = NVM_DEVICE_TYPE_EEPROM;
402 break;
403 }
404 return nvm_type;
405}
406
407static int iwl_init_otp_access(struct iwl_trans *trans)
408{
409 int ret;
410
411 /* Enable 40MHz radio clock */
412 iwl_write32(trans, CSR_GP_CNTRL,
413 iwl_read32(trans, CSR_GP_CNTRL) |
414 CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
415
416 /* wait for clock to be ready */
417 ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
418 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
419 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
420 25000);
421 if (ret < 0)
422 IWL_ERR(trans, "Time out access OTP\n");
423 else {
424 iwl_set_bits_prph(trans, APMG_PS_CTRL_REG,
425 APMG_PS_CTRL_VAL_RESET_REQ);
426 udelay(5);
427 iwl_clear_bits_prph(trans, APMG_PS_CTRL_REG,
428 APMG_PS_CTRL_VAL_RESET_REQ);
429
430 /*
431 * CSR auto clock gate disable bit -
432 * this is only applicable for HW with OTP shadow RAM
433 */
434 if (trans->cfg->base_params->shadow_ram_support)
435 iwl_set_bit(trans, CSR_DBG_LINK_PWR_MGMT_REG,
436 CSR_RESET_LINK_PWR_MGMT_DISABLED);
437 }
438 return ret;
439}
440
441static int iwl_read_otp_word(struct iwl_trans *trans, u16 addr,
442 __le16 *eeprom_data)
443{
444 int ret = 0;
445 u32 r;
446 u32 otpgp;
447
448 iwl_write32(trans, CSR_EEPROM_REG,
449 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
450 ret = iwl_poll_bit(trans, CSR_EEPROM_REG,
451 CSR_EEPROM_REG_READ_VALID_MSK,
452 CSR_EEPROM_REG_READ_VALID_MSK,
453 IWL_EEPROM_ACCESS_TIMEOUT);
454 if (ret < 0) {
455 IWL_ERR(trans, "Time out reading OTP[%d]\n", addr);
456 return ret;
457 }
458 r = iwl_read32(trans, CSR_EEPROM_REG);
459 /* check for ECC errors: */
460 otpgp = iwl_read32(trans, CSR_OTP_GP_REG);
461 if (otpgp & CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK) {
462 /* stop in this case */
463 /* set the uncorrectable OTP ECC bit for acknowledgement */
464 iwl_set_bit(trans, CSR_OTP_GP_REG,
465 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
466 IWL_ERR(trans, "Uncorrectable OTP ECC error, abort OTP read\n");
467 return -EINVAL;
468 }
469 if (otpgp & CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK) {
470 /* continue in this case */
471 /* set the correctable OTP ECC bit for acknowledgement */
472 iwl_set_bit(trans, CSR_OTP_GP_REG,
473 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK);
474 IWL_ERR(trans, "Correctable OTP ECC error, continue read\n");
475 }
476 *eeprom_data = cpu_to_le16(r >> 16);
477 return 0;
478}
479
480/*
481 * iwl_is_otp_empty: check for empty OTP
482 */
483static bool iwl_is_otp_empty(struct iwl_trans *trans)
484{
485 u16 next_link_addr = 0;
486 __le16 link_value;
487 bool is_empty = false;
488
489 /* locate the beginning of OTP link list */
490 if (!iwl_read_otp_word(trans, next_link_addr, &link_value)) {
491 if (!link_value) {
492 IWL_ERR(trans, "OTP is empty\n");
493 is_empty = true;
494 }
495 } else {
496 IWL_ERR(trans, "Unable to read first block of OTP list.\n");
497 is_empty = true;
498 }
499
500 return is_empty;
501}
502
503
504/*
505 * iwl_find_otp_image: find EEPROM image in OTP
506 * finding the OTP block that contains the EEPROM image.
507 * the last valid block on the link list (the block _before_ the last block)
508 * is the block we should read and used to configure the device.
509 * If all the available OTP blocks are full, the last block will be the block
510 * we should read and used to configure the device.
511 * only perform this operation if shadow RAM is disabled
512 */
513static int iwl_find_otp_image(struct iwl_trans *trans,
514 u16 *validblockaddr)
515{
516 u16 next_link_addr = 0, valid_addr;
517 __le16 link_value = 0;
518 int usedblocks = 0;
519
520 /* set addressing mode to absolute to traverse the link list */
521 iwl_set_otp_access(trans, IWL_OTP_ACCESS_ABSOLUTE);
522
523 /* checking for empty OTP or error */
524 if (iwl_is_otp_empty(trans))
525 return -EINVAL;
526
527 /*
528 * start traverse link list
529 * until reach the max number of OTP blocks
530 * different devices have different number of OTP blocks
531 */
532 do {
533 /* save current valid block address
534 * check for more block on the link list
535 */
536 valid_addr = next_link_addr;
537 next_link_addr = le16_to_cpu(link_value) * sizeof(u16);
538 IWL_DEBUG_EEPROM(trans, "OTP blocks %d addr 0x%x\n",
539 usedblocks, next_link_addr);
540 if (iwl_read_otp_word(trans, next_link_addr, &link_value))
541 return -EINVAL;
542 if (!link_value) {
543 /*
544 * reach the end of link list, return success and
545 * set address point to the starting address
546 * of the image
547 */
548 *validblockaddr = valid_addr;
549 /* skip first 2 bytes (link list pointer) */
550 *validblockaddr += 2;
551 return 0;
552 }
553 /* more in the link list, continue */
554 usedblocks++;
555 } while (usedblocks <= trans->cfg->base_params->max_ll_items);
556
557 /* OTP has no valid blocks */
558 IWL_DEBUG_EEPROM(trans, "OTP has no valid blocks\n");
559 return -EINVAL;
560}
561
562/******************************************************************************
563 *
564 * Tx Power related functions
565 *
566******************************************************************************/
567/**
568 * iwl_get_max_txpower_avg - get the highest tx power from all chains.
569 * find the highest tx power from all chains for the channel
570 */
571static s8 iwl_get_max_txpower_avg(struct iwl_priv *priv,
572 struct iwl_eeprom_enhanced_txpwr *enhanced_txpower,
573 int element, s8 *max_txpower_in_half_dbm)
574{
575 s8 max_txpower_avg = 0; /* (dBm) */
576
577 /* Take the highest tx power from any valid chains */
578 if ((priv->hw_params.valid_tx_ant & ANT_A) &&
579 (enhanced_txpower[element].chain_a_max > max_txpower_avg))
580 max_txpower_avg = enhanced_txpower[element].chain_a_max;
581 if ((priv->hw_params.valid_tx_ant & ANT_B) &&
582 (enhanced_txpower[element].chain_b_max > max_txpower_avg))
583 max_txpower_avg = enhanced_txpower[element].chain_b_max;
584 if ((priv->hw_params.valid_tx_ant & ANT_C) &&
585 (enhanced_txpower[element].chain_c_max > max_txpower_avg))
586 max_txpower_avg = enhanced_txpower[element].chain_c_max;
587 if (((priv->hw_params.valid_tx_ant == ANT_AB) |
588 (priv->hw_params.valid_tx_ant == ANT_BC) |
589 (priv->hw_params.valid_tx_ant == ANT_AC)) &&
590 (enhanced_txpower[element].mimo2_max > max_txpower_avg))
591 max_txpower_avg = enhanced_txpower[element].mimo2_max;
592 if ((priv->hw_params.valid_tx_ant == ANT_ABC) &&
593 (enhanced_txpower[element].mimo3_max > max_txpower_avg))
594 max_txpower_avg = enhanced_txpower[element].mimo3_max;
595
596 /*
597 * max. tx power in EEPROM is in 1/2 dBm format
598 * convert from 1/2 dBm to dBm (round-up convert)
599 * but we also do not want to loss 1/2 dBm resolution which
600 * will impact performance
601 */
602 *max_txpower_in_half_dbm = max_txpower_avg;
603 return (max_txpower_avg & 0x01) + (max_txpower_avg >> 1);
604}
605
606static void
607iwl_eeprom_enh_txp_read_element(struct iwl_priv *priv,
608 struct iwl_eeprom_enhanced_txpwr *txp,
609 s8 max_txpower_avg)
610{
611 int ch_idx;
612 bool is_ht40 = txp->flags & IWL_EEPROM_ENH_TXP_FL_40MHZ;
613 enum ieee80211_band band;
614
615 band = txp->flags & IWL_EEPROM_ENH_TXP_FL_BAND_52G ?
616 IEEE80211_BAND_5GHZ : IEEE80211_BAND_2GHZ;
617
618 for (ch_idx = 0; ch_idx < priv->channel_count; ch_idx++) {
619 struct iwl_channel_info *ch_info = &priv->channel_info[ch_idx];
620
621 /* update matching channel or from common data only */
622 if (txp->channel != 0 && ch_info->channel != txp->channel)
623 continue;
624
625 /* update matching band only */
626 if (band != ch_info->band)
627 continue;
628
629 if (ch_info->max_power_avg < max_txpower_avg && !is_ht40) {
630 ch_info->max_power_avg = max_txpower_avg;
631 ch_info->curr_txpow = max_txpower_avg;
632 ch_info->scan_power = max_txpower_avg;
633 }
634
635 if (is_ht40 && ch_info->ht40_max_power_avg < max_txpower_avg)
636 ch_info->ht40_max_power_avg = max_txpower_avg;
637 }
638}
639
640#define EEPROM_TXP_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT)
641#define EEPROM_TXP_ENTRY_LEN sizeof(struct iwl_eeprom_enhanced_txpwr)
642#define EEPROM_TXP_SZ_OFFS (0x00 | INDIRECT_ADDRESS | INDIRECT_TXP_LIMIT_SIZE)
643
644#define TXP_CHECK_AND_PRINT(x) ((txp->flags & IWL_EEPROM_ENH_TXP_FL_##x) \
645 ? # x " " : "")
646
647static void iwl_eeprom_enhanced_txpower(struct iwl_priv *priv)
648{
649 struct iwl_eeprom_enhanced_txpwr *txp_array, *txp;
650 int idx, entries;
651 __le16 *txp_len;
652 s8 max_txp_avg, max_txp_avg_halfdbm;
653
654 BUILD_BUG_ON(sizeof(struct iwl_eeprom_enhanced_txpwr) != 8);
655
656 /* the length is in 16-bit words, but we want entries */
657 txp_len = (__le16 *) iwl_eeprom_query_addr(priv, EEPROM_TXP_SZ_OFFS);
658 entries = le16_to_cpup(txp_len) * 2 / EEPROM_TXP_ENTRY_LEN;
659
660 txp_array = (void *) iwl_eeprom_query_addr(priv, EEPROM_TXP_OFFS);
661
662 for (idx = 0; idx < entries; idx++) {
663 txp = &txp_array[idx];
664 /* skip invalid entries */
665 if (!(txp->flags & IWL_EEPROM_ENH_TXP_FL_VALID))
666 continue;
667
668 IWL_DEBUG_EEPROM(priv, "%s %d:\t %s%s%s%s%s%s%s%s (0x%02x)\n",
669 (txp->channel && (txp->flags &
670 IWL_EEPROM_ENH_TXP_FL_COMMON_TYPE)) ?
671 "Common " : (txp->channel) ?
672 "Channel" : "Common",
673 (txp->channel),
674 TXP_CHECK_AND_PRINT(VALID),
675 TXP_CHECK_AND_PRINT(BAND_52G),
676 TXP_CHECK_AND_PRINT(OFDM),
677 TXP_CHECK_AND_PRINT(40MHZ),
678 TXP_CHECK_AND_PRINT(HT_AP),
679 TXP_CHECK_AND_PRINT(RES1),
680 TXP_CHECK_AND_PRINT(RES2),
681 TXP_CHECK_AND_PRINT(COMMON_TYPE),
682 txp->flags);
683 IWL_DEBUG_EEPROM(priv, "\t\t chain_A: 0x%02x "
684 "chain_B: 0X%02x chain_C: 0X%02x\n",
685 txp->chain_a_max, txp->chain_b_max,
686 txp->chain_c_max);
687 IWL_DEBUG_EEPROM(priv, "\t\t MIMO2: 0x%02x "
688 "MIMO3: 0x%02x High 20_on_40: 0x%02x "
689 "Low 20_on_40: 0x%02x\n",
690 txp->mimo2_max, txp->mimo3_max,
691 ((txp->delta_20_in_40 & 0xf0) >> 4),
692 (txp->delta_20_in_40 & 0x0f));
693
694 max_txp_avg = iwl_get_max_txpower_avg(priv, txp_array, idx,
695 &max_txp_avg_halfdbm);
696
697 /*
698 * Update the user limit values values to the highest
699 * power supported by any channel
700 */
701 if (max_txp_avg > priv->tx_power_user_lmt)
702 priv->tx_power_user_lmt = max_txp_avg;
703 if (max_txp_avg_halfdbm > priv->tx_power_lmt_in_half_dbm)
704 priv->tx_power_lmt_in_half_dbm = max_txp_avg_halfdbm;
705
706 iwl_eeprom_enh_txp_read_element(priv, txp, max_txp_avg);
707 }
708}
709
710/**
711 * iwl_eeprom_init - read EEPROM contents
712 *
713 * Load the EEPROM contents from adapter into priv->eeprom
714 *
715 * NOTE: This routine uses the non-debug IO access functions.
716 */
717int iwl_eeprom_init(struct iwl_priv *priv, u32 hw_rev)
718{
719 __le16 *e;
720 u32 gp = iwl_read32(priv->trans, CSR_EEPROM_GP);
721 int sz;
722 int ret;
723 u16 addr;
724 u16 validblockaddr = 0;
725 u16 cache_addr = 0;
726
727 priv->nvm_device_type = iwl_get_nvm_type(priv->trans, hw_rev);
728 if (priv->nvm_device_type == -ENOENT)
729 return -ENOENT;
730 /* allocate eeprom */
731 sz = priv->cfg->base_params->eeprom_size;
732 IWL_DEBUG_EEPROM(priv, "NVM size = %d\n", sz);
733 priv->eeprom = kzalloc(sz, GFP_KERNEL);
734 if (!priv->eeprom) {
735 ret = -ENOMEM;
736 goto alloc_err;
737 }
738 e = (__le16 *)priv->eeprom;
739
740 ret = iwl_eeprom_verify_signature(priv);
741 if (ret < 0) {
742 IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp);
743 ret = -ENOENT;
744 goto err;
745 }
746
747 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
748 ret = iwl_eeprom_acquire_semaphore(priv->trans);
749 if (ret < 0) {
750 IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n");
751 ret = -ENOENT;
752 goto err;
753 }
754
755 if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) {
756
757 ret = iwl_init_otp_access(priv->trans);
758 if (ret) {
759 IWL_ERR(priv, "Failed to initialize OTP access.\n");
760 ret = -ENOENT;
761 goto done;
762 }
763 iwl_write32(priv->trans, CSR_EEPROM_GP,
764 iwl_read32(priv->trans, CSR_EEPROM_GP) &
765 ~CSR_EEPROM_GP_IF_OWNER_MSK);
766
767 iwl_set_bit(priv->trans, CSR_OTP_GP_REG,
768 CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK |
769 CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
770 /* traversing the linked list if no shadow ram supported */
771 if (!priv->cfg->base_params->shadow_ram_support) {
772 if (iwl_find_otp_image(priv->trans, &validblockaddr)) {
773 ret = -ENOENT;
774 goto done;
775 }
776 }
777 for (addr = validblockaddr; addr < validblockaddr + sz;
778 addr += sizeof(u16)) {
779 __le16 eeprom_data;
780
781 ret = iwl_read_otp_word(priv->trans, addr,
782 &eeprom_data);
783 if (ret)
784 goto done;
785 e[cache_addr / 2] = eeprom_data;
786 cache_addr += sizeof(u16);
787 }
788 } else {
789 /* eeprom is an array of 16bit values */
790 for (addr = 0; addr < sz; addr += sizeof(u16)) {
791 u32 r;
792
793 iwl_write32(priv->trans, CSR_EEPROM_REG,
794 CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
795
796 ret = iwl_poll_bit(priv->trans, CSR_EEPROM_REG,
797 CSR_EEPROM_REG_READ_VALID_MSK,
798 CSR_EEPROM_REG_READ_VALID_MSK,
799 IWL_EEPROM_ACCESS_TIMEOUT);
800 if (ret < 0) {
801 IWL_ERR(priv,
802 "Time out reading EEPROM[%d]\n", addr);
803 goto done;
804 }
805 r = iwl_read32(priv->trans, CSR_EEPROM_REG);
806 e[addr / 2] = cpu_to_le16(r >> 16);
807 }
808 }
809
810 IWL_DEBUG_EEPROM(priv, "NVM Type: %s, version: 0x%x\n",
811 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
812 ? "OTP" : "EEPROM",
813 iwl_eeprom_query16(priv, EEPROM_VERSION));
814
815 ret = 0;
816done:
817 iwl_eeprom_release_semaphore(priv->trans);
818
819err:
820 if (ret)
821 iwl_eeprom_free(priv);
822alloc_err:
823 return ret;
824}
825
826void iwl_eeprom_free(struct iwl_priv *priv)
827{
828 kfree(priv->eeprom);
829 priv->eeprom = NULL;
830}
831
832static void iwl_init_band_reference(struct iwl_priv *priv,
833 int eep_band, int *eeprom_ch_count,
834 const struct iwl_eeprom_channel **eeprom_ch_info,
835 const u8 **eeprom_ch_index)
836{
837 u32 offset = priv->lib->
838 eeprom_ops.regulatory_bands[eep_band - 1];
839 switch (eep_band) {
840 case 1: /* 2.4GHz band */
841 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1);
842 *eeprom_ch_info = (struct iwl_eeprom_channel *)
843 iwl_eeprom_query_addr(priv, offset);
844 *eeprom_ch_index = iwl_eeprom_band_1;
845 break;
846 case 2: /* 4.9GHz band */
847 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2);
848 *eeprom_ch_info = (struct iwl_eeprom_channel *)
849 iwl_eeprom_query_addr(priv, offset);
850 *eeprom_ch_index = iwl_eeprom_band_2;
851 break;
852 case 3: /* 5.2GHz band */
853 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3);
854 *eeprom_ch_info = (struct iwl_eeprom_channel *)
855 iwl_eeprom_query_addr(priv, offset);
856 *eeprom_ch_index = iwl_eeprom_band_3;
857 break;
858 case 4: /* 5.5GHz band */
859 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4);
860 *eeprom_ch_info = (struct iwl_eeprom_channel *)
861 iwl_eeprom_query_addr(priv, offset);
862 *eeprom_ch_index = iwl_eeprom_band_4;
863 break;
864 case 5: /* 5.7GHz band */
865 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5);
866 *eeprom_ch_info = (struct iwl_eeprom_channel *)
867 iwl_eeprom_query_addr(priv, offset);
868 *eeprom_ch_index = iwl_eeprom_band_5;
869 break;
870 case 6: /* 2.4GHz ht40 channels */
871 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6);
872 *eeprom_ch_info = (struct iwl_eeprom_channel *)
873 iwl_eeprom_query_addr(priv, offset);
874 *eeprom_ch_index = iwl_eeprom_band_6;
875 break;
876 case 7: /* 5 GHz ht40 channels */
877 *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7);
878 *eeprom_ch_info = (struct iwl_eeprom_channel *)
879 iwl_eeprom_query_addr(priv, offset);
880 *eeprom_ch_index = iwl_eeprom_band_7;
881 break;
882 default:
883 BUG();
884 return;
885 }
886}
887
888#define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \
889 ? # x " " : "")
890/**
891 * iwl_mod_ht40_chan_info - Copy ht40 channel info into driver's priv.
892 *
893 * Does not set up a command, or touch hardware.
894 */
895static int iwl_mod_ht40_chan_info(struct iwl_priv *priv,
896 enum ieee80211_band band, u16 channel,
897 const struct iwl_eeprom_channel *eeprom_ch,
898 u8 clear_ht40_extension_channel)
899{
900 struct iwl_channel_info *ch_info;
901
902 ch_info = (struct iwl_channel_info *)
903 iwl_get_channel_info(priv, band, channel);
904
905 if (!is_channel_valid(ch_info))
906 return -1;
907
908 IWL_DEBUG_EEPROM(priv, "HT40 Ch. %d [%sGHz] %s%s%s%s%s(0x%02x %ddBm):"
909 " Ad-Hoc %ssupported\n",
910 ch_info->channel,
911 is_channel_a_band(ch_info) ?
912 "5.2" : "2.4",
913 CHECK_AND_PRINT(IBSS),
914 CHECK_AND_PRINT(ACTIVE),
915 CHECK_AND_PRINT(RADAR),
916 CHECK_AND_PRINT(WIDE),
917 CHECK_AND_PRINT(DFS),
918 eeprom_ch->flags,
919 eeprom_ch->max_power_avg,
920 ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS)
921 && !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ?
922 "" : "not ");
923
924 ch_info->ht40_eeprom = *eeprom_ch;
925 ch_info->ht40_max_power_avg = eeprom_ch->max_power_avg;
926 ch_info->ht40_flags = eeprom_ch->flags;
927 if (eeprom_ch->flags & EEPROM_CHANNEL_VALID)
928 ch_info->ht40_extension_channel &= ~clear_ht40_extension_channel;
929
930 return 0;
931}
932
933#define CHECK_AND_PRINT_I(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
934 ? # x " " : "")
935
936/**
937 * iwl_init_channel_map - Set up driver's info for all possible channels
938 */
939int iwl_init_channel_map(struct iwl_priv *priv)
940{
941 int eeprom_ch_count = 0;
942 const u8 *eeprom_ch_index = NULL;
943 const struct iwl_eeprom_channel *eeprom_ch_info = NULL;
944 int band, ch;
945 struct iwl_channel_info *ch_info;
946
947 if (priv->channel_count) {
948 IWL_DEBUG_EEPROM(priv, "Channel map already initialized.\n");
949 return 0;
950 }
951
952 IWL_DEBUG_EEPROM(priv, "Initializing regulatory info from EEPROM\n");
953
954 priv->channel_count =
955 ARRAY_SIZE(iwl_eeprom_band_1) +
956 ARRAY_SIZE(iwl_eeprom_band_2) +
957 ARRAY_SIZE(iwl_eeprom_band_3) +
958 ARRAY_SIZE(iwl_eeprom_band_4) +
959 ARRAY_SIZE(iwl_eeprom_band_5);
960
961 IWL_DEBUG_EEPROM(priv, "Parsing data for %d channels.\n",
962 priv->channel_count);
963
964 priv->channel_info = kcalloc(priv->channel_count,
965 sizeof(struct iwl_channel_info),
966 GFP_KERNEL);
967 if (!priv->channel_info) {
968 IWL_ERR(priv, "Could not allocate channel_info\n");
969 priv->channel_count = 0;
970 return -ENOMEM;
971 }
972
973 ch_info = priv->channel_info;
974
975 /* Loop through the 5 EEPROM bands adding them in order to the
976 * channel map we maintain (that contains additional information than
977 * what just in the EEPROM) */
978 for (band = 1; band <= 5; band++) {
979
980 iwl_init_band_reference(priv, band, &eeprom_ch_count,
981 &eeprom_ch_info, &eeprom_ch_index);
982
983 /* Loop through each band adding each of the channels */
984 for (ch = 0; ch < eeprom_ch_count; ch++) {
985 ch_info->channel = eeprom_ch_index[ch];
986 ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ :
987 IEEE80211_BAND_5GHZ;
988
989 /* permanently store EEPROM's channel regulatory flags
990 * and max power in channel info database. */
991 ch_info->eeprom = eeprom_ch_info[ch];
992
993 /* Copy the run-time flags so they are there even on
994 * invalid channels */
995 ch_info->flags = eeprom_ch_info[ch].flags;
996 /* First write that ht40 is not enabled, and then enable
997 * one by one */
998 ch_info->ht40_extension_channel =
999 IEEE80211_CHAN_NO_HT40;
1000
1001 if (!(is_channel_valid(ch_info))) {
1002 IWL_DEBUG_EEPROM(priv,
1003 "Ch. %d Flags %x [%sGHz] - "
1004 "No traffic\n",
1005 ch_info->channel,
1006 ch_info->flags,
1007 is_channel_a_band(ch_info) ?
1008 "5.2" : "2.4");
1009 ch_info++;
1010 continue;
1011 }
1012
1013 /* Initialize regulatory-based run-time data */
1014 ch_info->max_power_avg = ch_info->curr_txpow =
1015 eeprom_ch_info[ch].max_power_avg;
1016 ch_info->scan_power = eeprom_ch_info[ch].max_power_avg;
1017 ch_info->min_power = 0;
1018
1019 IWL_DEBUG_EEPROM(priv, "Ch. %d [%sGHz] "
1020 "%s%s%s%s%s%s(0x%02x %ddBm):"
1021 " Ad-Hoc %ssupported\n",
1022 ch_info->channel,
1023 is_channel_a_band(ch_info) ?
1024 "5.2" : "2.4",
1025 CHECK_AND_PRINT_I(VALID),
1026 CHECK_AND_PRINT_I(IBSS),
1027 CHECK_AND_PRINT_I(ACTIVE),
1028 CHECK_AND_PRINT_I(RADAR),
1029 CHECK_AND_PRINT_I(WIDE),
1030 CHECK_AND_PRINT_I(DFS),
1031 eeprom_ch_info[ch].flags,
1032 eeprom_ch_info[ch].max_power_avg,
1033 ((eeprom_ch_info[ch].
1034 flags & EEPROM_CHANNEL_IBSS)
1035 && !(eeprom_ch_info[ch].
1036 flags & EEPROM_CHANNEL_RADAR))
1037 ? "" : "not ");
1038
1039 ch_info++;
1040 }
1041 }
1042
1043 /* Check if we do have HT40 channels */
1044 if (priv->lib->eeprom_ops.regulatory_bands[5] ==
1045 EEPROM_REGULATORY_BAND_NO_HT40 &&
1046 priv->lib->eeprom_ops.regulatory_bands[6] ==
1047 EEPROM_REGULATORY_BAND_NO_HT40)
1048 return 0;
1049
1050 /* Two additional EEPROM bands for 2.4 and 5 GHz HT40 channels */
1051 for (band = 6; band <= 7; band++) {
1052 enum ieee80211_band ieeeband;
1053
1054 iwl_init_band_reference(priv, band, &eeprom_ch_count,
1055 &eeprom_ch_info, &eeprom_ch_index);
1056
1057 /* EEPROM band 6 is 2.4, band 7 is 5 GHz */
1058 ieeeband =
1059 (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
1060
1061 /* Loop through each band adding each of the channels */
1062 for (ch = 0; ch < eeprom_ch_count; ch++) {
1063 /* Set up driver's info for lower half */
1064 iwl_mod_ht40_chan_info(priv, ieeeband,
1065 eeprom_ch_index[ch],
1066 &eeprom_ch_info[ch],
1067 IEEE80211_CHAN_NO_HT40PLUS);
1068
1069 /* Set up driver's info for upper half */
1070 iwl_mod_ht40_chan_info(priv, ieeeband,
1071 eeprom_ch_index[ch] + 4,
1072 &eeprom_ch_info[ch],
1073 IEEE80211_CHAN_NO_HT40MINUS);
1074 }
1075 }
1076
1077 /* for newer device (6000 series and up)
1078 * EEPROM contain enhanced tx power information
1079 * driver need to process addition information
1080 * to determine the max channel tx power limits
1081 */
1082 if (priv->lib->eeprom_ops.enhanced_txpower)
1083 iwl_eeprom_enhanced_txpower(priv);
1084
1085 return 0;
1086}
1087
1088/*
1089 * iwl_free_channel_map - undo allocations in iwl_init_channel_map
1090 */
1091void iwl_free_channel_map(struct iwl_priv *priv)
1092{
1093 kfree(priv->channel_info);
1094 priv->channel_count = 0;
1095}
1096
1097/**
1098 * iwl_get_channel_info - Find driver's private channel info
1099 *
1100 * Based on band and channel number.
1101 */
1102const struct iwl_channel_info *iwl_get_channel_info(const struct iwl_priv *priv,
1103 enum ieee80211_band band, u16 channel)
1104{
1105 int i;
1106
1107 switch (band) {
1108 case IEEE80211_BAND_5GHZ:
1109 for (i = 14; i < priv->channel_count; i++) {
1110 if (priv->channel_info[i].channel == channel)
1111 return &priv->channel_info[i];
1112 }
1113 break;
1114 case IEEE80211_BAND_2GHZ:
1115 if (channel >= 1 && channel <= 14)
1116 return &priv->channel_info[channel - 1];
1117 break;
1118 default:
1119 BUG();
1120 }
1121
1122 return NULL;
1123}
1124
1125void iwl_rf_config(struct iwl_priv *priv)
1126{
1127 u16 radio_cfg;
1128
1129 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
1130
1131 /* write radio config values to register */
1132 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) <= EEPROM_RF_CONFIG_TYPE_MAX) {
1133 iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG,
1134 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
1135 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
1136 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
1137 IWL_INFO(priv, "Radio type=0x%x-0x%x-0x%x\n",
1138 EEPROM_RF_CFG_TYPE_MSK(radio_cfg),
1139 EEPROM_RF_CFG_STEP_MSK(radio_cfg),
1140 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
1141 } else
1142 WARN_ON(1);
1143
1144 /* set CSR_HW_CONFIG_REG for uCode use */
1145 iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG,
1146 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
1147 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
1148}
diff --git a/drivers/net/wireless/iwlwifi/iwl-eeprom.h b/drivers/net/wireless/iwlwifi/iwl-eeprom.h
deleted file mode 100644
index 64bfd947caeb..000000000000
--- a/drivers/net/wireless/iwlwifi/iwl-eeprom.h
+++ /dev/null
@@ -1,269 +0,0 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
62
63#ifndef __iwl_eeprom_h__
64#define __iwl_eeprom_h__
65
66#include <net/mac80211.h>
67
68struct iwl_priv;
69
70/*
71 * EEPROM access time values:
72 *
73 * Driver initiates EEPROM read by writing byte address << 1 to CSR_EEPROM_REG.
74 * Driver then polls CSR_EEPROM_REG for CSR_EEPROM_REG_READ_VALID_MSK (0x1).
75 * When polling, wait 10 uSec between polling loops, up to a maximum 5000 uSec.
76 * Driver reads 16-bit value from bits 31-16 of CSR_EEPROM_REG.
77 */
78#define IWL_EEPROM_ACCESS_TIMEOUT 5000 /* uSec */
79
80#define IWL_EEPROM_SEM_TIMEOUT 10 /* microseconds */
81#define IWL_EEPROM_SEM_RETRY_LIMIT 1000 /* number of attempts (not time) */
82
83
84/*
85 * Regulatory channel usage flags in EEPROM struct iwl4965_eeprom_channel.flags.
86 *
87 * IBSS and/or AP operation is allowed *only* on those channels with
88 * (VALID && IBSS && ACTIVE && !RADAR). This restriction is in place because
89 * RADAR detection is not supported by the 4965 driver, but is a
90 * requirement for establishing a new network for legal operation on channels
91 * requiring RADAR detection or restricting ACTIVE scanning.
92 *
93 * NOTE: "WIDE" flag does not indicate anything about "HT40" 40 MHz channels.
94 * It only indicates that 20 MHz channel use is supported; HT40 channel
95 * usage is indicated by a separate set of regulatory flags for each
96 * HT40 channel pair.
97 *
98 * NOTE: Using a channel inappropriately will result in a uCode error!
99 */
100#define IWL_NUM_TX_CALIB_GROUPS 5
101enum {
102 EEPROM_CHANNEL_VALID = (1 << 0), /* usable for this SKU/geo */
103 EEPROM_CHANNEL_IBSS = (1 << 1), /* usable as an IBSS channel */
104 /* Bit 2 Reserved */
105 EEPROM_CHANNEL_ACTIVE = (1 << 3), /* active scanning allowed */
106 EEPROM_CHANNEL_RADAR = (1 << 4), /* radar detection required */
107 EEPROM_CHANNEL_WIDE = (1 << 5), /* 20 MHz channel okay */
108 /* Bit 6 Reserved (was Narrow Channel) */
109 EEPROM_CHANNEL_DFS = (1 << 7), /* dynamic freq selection candidate */
110};
111
112/* SKU Capabilities */
113#define EEPROM_SKU_CAP_BAND_24GHZ (1 << 4)
114#define EEPROM_SKU_CAP_BAND_52GHZ (1 << 5)
115#define EEPROM_SKU_CAP_11N_ENABLE (1 << 6)
116#define EEPROM_SKU_CAP_AMT_ENABLE (1 << 7)
117#define EEPROM_SKU_CAP_IPAN_ENABLE (1 << 8)
118
119/* *regulatory* channel data format in eeprom, one for each channel.
120 * There are separate entries for HT40 (40 MHz) vs. normal (20 MHz) channels. */
121struct iwl_eeprom_channel {
122 u8 flags; /* EEPROM_CHANNEL_* flags copied from EEPROM */
123 s8 max_power_avg; /* max power (dBm) on this chnl, limit 31 */
124} __packed;
125
126enum iwl_eeprom_enhanced_txpwr_flags {
127 IWL_EEPROM_ENH_TXP_FL_VALID = BIT(0),
128 IWL_EEPROM_ENH_TXP_FL_BAND_52G = BIT(1),
129 IWL_EEPROM_ENH_TXP_FL_OFDM = BIT(2),
130 IWL_EEPROM_ENH_TXP_FL_40MHZ = BIT(3),
131 IWL_EEPROM_ENH_TXP_FL_HT_AP = BIT(4),
132 IWL_EEPROM_ENH_TXP_FL_RES1 = BIT(5),
133 IWL_EEPROM_ENH_TXP_FL_RES2 = BIT(6),
134 IWL_EEPROM_ENH_TXP_FL_COMMON_TYPE = BIT(7),
135};
136
137/**
138 * iwl_eeprom_enhanced_txpwr structure
139 * This structure presents the enhanced regulatory tx power limit layout
140 * in eeprom image
141 * Enhanced regulatory tx power portion of eeprom image can be broken down
142 * into individual structures; each one is 8 bytes in size and contain the
143 * following information
144 * @flags: entry flags
145 * @channel: channel number
146 * @chain_a_max_pwr: chain a max power in 1/2 dBm
147 * @chain_b_max_pwr: chain b max power in 1/2 dBm
148 * @chain_c_max_pwr: chain c max power in 1/2 dBm
149 * @delta_20_in_40: 20-in-40 deltas (hi/lo)
150 * @mimo2_max_pwr: mimo2 max power in 1/2 dBm
151 * @mimo3_max_pwr: mimo3 max power in 1/2 dBm
152 *
153 */
154struct iwl_eeprom_enhanced_txpwr {
155 u8 flags;
156 u8 channel;
157 s8 chain_a_max;
158 s8 chain_b_max;
159 s8 chain_c_max;
160 u8 delta_20_in_40;
161 s8 mimo2_max;
162 s8 mimo3_max;
163} __packed;
164
165/* calibration */
166struct iwl_eeprom_calib_hdr {
167 u8 version;
168 u8 pa_type;
169 __le16 voltage;
170} __packed;
171
172#define EEPROM_CALIB_ALL (INDIRECT_ADDRESS | INDIRECT_CALIBRATION)
173#define EEPROM_XTAL ((2*0x128) | EEPROM_CALIB_ALL)
174
175/* temperature */
176#define EEPROM_KELVIN_TEMPERATURE ((2*0x12A) | EEPROM_CALIB_ALL)
177#define EEPROM_RAW_TEMPERATURE ((2*0x12B) | EEPROM_CALIB_ALL)
178
179
180/* agn links */
181#define EEPROM_LINK_HOST (2*0x64)
182#define EEPROM_LINK_GENERAL (2*0x65)
183#define EEPROM_LINK_REGULATORY (2*0x66)
184#define EEPROM_LINK_CALIBRATION (2*0x67)
185#define EEPROM_LINK_PROCESS_ADJST (2*0x68)
186#define EEPROM_LINK_OTHERS (2*0x69)
187#define EEPROM_LINK_TXP_LIMIT (2*0x6a)
188#define EEPROM_LINK_TXP_LIMIT_SIZE (2*0x6b)
189
190/* agn regulatory - indirect access */
191#define EEPROM_REG_BAND_1_CHANNELS ((0x08)\
192 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 28 bytes */
193#define EEPROM_REG_BAND_2_CHANNELS ((0x26)\
194 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 26 bytes */
195#define EEPROM_REG_BAND_3_CHANNELS ((0x42)\
196 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 24 bytes */
197#define EEPROM_REG_BAND_4_CHANNELS ((0x5C)\
198 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 22 bytes */
199#define EEPROM_REG_BAND_5_CHANNELS ((0x74)\
200 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 12 bytes */
201#define EEPROM_REG_BAND_24_HT40_CHANNELS ((0x82)\
202 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 14 bytes */
203#define EEPROM_REG_BAND_52_HT40_CHANNELS ((0x92)\
204 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 22 bytes */
205
206/* 6000 regulatory - indirect access */
207#define EEPROM_6000_REG_BAND_24_HT40_CHANNELS ((0x80)\
208 | INDIRECT_ADDRESS | INDIRECT_REGULATORY) /* 14 bytes */
209/* 2.4 GHz */
210extern const u8 iwl_eeprom_band_1[14];
211
212#define ADDRESS_MSK 0x0000FFFF
213#define INDIRECT_TYPE_MSK 0x000F0000
214#define INDIRECT_HOST 0x00010000
215#define INDIRECT_GENERAL 0x00020000
216#define INDIRECT_REGULATORY 0x00030000
217#define INDIRECT_CALIBRATION 0x00040000
218#define INDIRECT_PROCESS_ADJST 0x00050000
219#define INDIRECT_OTHERS 0x00060000
220#define INDIRECT_TXP_LIMIT 0x00070000
221#define INDIRECT_TXP_LIMIT_SIZE 0x00080000
222#define INDIRECT_ADDRESS 0x00100000
223
224/* General */
225#define EEPROM_DEVICE_ID (2*0x08) /* 2 bytes */
226#define EEPROM_SUBSYSTEM_ID (2*0x0A) /* 2 bytes */
227#define EEPROM_MAC_ADDRESS (2*0x15) /* 6 bytes */
228#define EEPROM_BOARD_REVISION (2*0x35) /* 2 bytes */
229#define EEPROM_BOARD_PBA_NUMBER (2*0x3B+1) /* 9 bytes */
230#define EEPROM_VERSION (2*0x44) /* 2 bytes */
231#define EEPROM_SKU_CAP (2*0x45) /* 2 bytes */
232#define EEPROM_OEM_MODE (2*0x46) /* 2 bytes */
233#define EEPROM_RADIO_CONFIG (2*0x48) /* 2 bytes */
234#define EEPROM_NUM_MAC_ADDRESS (2*0x4C) /* 2 bytes */
235
236/* The following masks are to be applied on EEPROM_RADIO_CONFIG */
237#define EEPROM_RF_CFG_TYPE_MSK(x) (x & 0x3) /* bits 0-1 */
238#define EEPROM_RF_CFG_STEP_MSK(x) ((x >> 2) & 0x3) /* bits 2-3 */
239#define EEPROM_RF_CFG_DASH_MSK(x) ((x >> 4) & 0x3) /* bits 4-5 */
240#define EEPROM_RF_CFG_PNUM_MSK(x) ((x >> 6) & 0x3) /* bits 6-7 */
241#define EEPROM_RF_CFG_TX_ANT_MSK(x) ((x >> 8) & 0xF) /* bits 8-11 */
242#define EEPROM_RF_CFG_RX_ANT_MSK(x) ((x >> 12) & 0xF) /* bits 12-15 */
243
244#define EEPROM_RF_CONFIG_TYPE_MAX 0x3
245
246#define EEPROM_REGULATORY_BAND_NO_HT40 (0)
247
248struct iwl_eeprom_ops {
249 const u32 regulatory_bands[7];
250 bool enhanced_txpower;
251};
252
253
254int iwl_eeprom_init(struct iwl_priv *priv, u32 hw_rev);
255void iwl_eeprom_free(struct iwl_priv *priv);
256int iwl_eeprom_check_version(struct iwl_priv *priv);
257int iwl_eeprom_init_hw_params(struct iwl_priv *priv);
258u16 iwl_eeprom_calib_version(struct iwl_priv *priv);
259const u8 *iwl_eeprom_query_addr(struct iwl_priv *priv, size_t offset);
260u16 iwl_eeprom_query16(struct iwl_priv *priv, size_t offset);
261void iwl_eeprom_get_mac(struct iwl_priv *priv, u8 *mac);
262int iwl_init_channel_map(struct iwl_priv *priv);
263void iwl_free_channel_map(struct iwl_priv *priv);
264const struct iwl_channel_info *iwl_get_channel_info(
265 const struct iwl_priv *priv,
266 enum ieee80211_band band, u16 channel);
267void iwl_rf_config(struct iwl_priv *priv);
268
269#endif /* __iwl_eeprom_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-fh.h b/drivers/net/wireless/iwlwifi/iwl-fh.h
index 74bce97a8600..806046641747 100644
--- a/drivers/net/wireless/iwlwifi/iwl-fh.h
+++ b/drivers/net/wireless/iwlwifi/iwl-fh.h
@@ -421,6 +421,8 @@ static inline unsigned int FH_MEM_CBBC_QUEUE(unsigned int chnl)
421 (FH_SRVC_LOWER_BOUND + ((_chnl) - 9) * 0x4) 421 (FH_SRVC_LOWER_BOUND + ((_chnl) - 9) * 0x4)
422 422
423#define FH_TX_CHICKEN_BITS_REG (FH_MEM_LOWER_BOUND + 0xE98) 423#define FH_TX_CHICKEN_BITS_REG (FH_MEM_LOWER_BOUND + 0xE98)
424#define FH_TX_TRB_REG(_chan) (FH_MEM_LOWER_BOUND + 0x958 + (_chan) * 4)
425
424/* Instruct FH to increment the retry count of a packet when 426/* Instruct FH to increment the retry count of a packet when
425 * it is brought from the memory to TX-FIFO 427 * it is brought from the memory to TX-FIFO
426 */ 428 */
diff --git a/drivers/net/wireless/iwlwifi/iwl-io.c b/drivers/net/wireless/iwlwifi/iwl-io.c
index 081dd34d2387..66c873399aba 100644
--- a/drivers/net/wireless/iwlwifi/iwl-io.c
+++ b/drivers/net/wireless/iwlwifi/iwl-io.c
@@ -27,6 +27,7 @@
27 *****************************************************************************/ 27 *****************************************************************************/
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/device.h> 29#include <linux/device.h>
30#include <linux/export.h>
30 31
31#include "iwl-io.h" 32#include "iwl-io.h"
32#include"iwl-csr.h" 33#include"iwl-csr.h"
@@ -52,6 +53,7 @@ void iwl_set_bit(struct iwl_trans *trans, u32 reg, u32 mask)
52 __iwl_set_bit(trans, reg, mask); 53 __iwl_set_bit(trans, reg, mask);
53 spin_unlock_irqrestore(&trans->reg_lock, flags); 54 spin_unlock_irqrestore(&trans->reg_lock, flags);
54} 55}
56EXPORT_SYMBOL_GPL(iwl_set_bit);
55 57
56void iwl_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask) 58void iwl_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask)
57{ 59{
@@ -61,6 +63,25 @@ void iwl_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask)
61 __iwl_clear_bit(trans, reg, mask); 63 __iwl_clear_bit(trans, reg, mask);
62 spin_unlock_irqrestore(&trans->reg_lock, flags); 64 spin_unlock_irqrestore(&trans->reg_lock, flags);
63} 65}
66EXPORT_SYMBOL_GPL(iwl_clear_bit);
67
68void iwl_set_bits_mask(struct iwl_trans *trans, u32 reg, u32 mask, u32 value)
69{
70 unsigned long flags;
71 u32 v;
72
73#ifdef CONFIG_IWLWIFI_DEBUG
74 WARN_ON_ONCE(value & ~mask);
75#endif
76
77 spin_lock_irqsave(&trans->reg_lock, flags);
78 v = iwl_read32(trans, reg);
79 v &= ~mask;
80 v |= value;
81 iwl_write32(trans, reg, v);
82 spin_unlock_irqrestore(&trans->reg_lock, flags);
83}
84EXPORT_SYMBOL_GPL(iwl_set_bits_mask);
64 85
65int iwl_poll_bit(struct iwl_trans *trans, u32 addr, 86int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
66 u32 bits, u32 mask, int timeout) 87 u32 bits, u32 mask, int timeout)
@@ -76,6 +97,7 @@ int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
76 97
77 return -ETIMEDOUT; 98 return -ETIMEDOUT;
78} 99}
100EXPORT_SYMBOL_GPL(iwl_poll_bit);
79 101
80int iwl_grab_nic_access_silent(struct iwl_trans *trans) 102int iwl_grab_nic_access_silent(struct iwl_trans *trans)
81{ 103{
@@ -117,6 +139,7 @@ int iwl_grab_nic_access_silent(struct iwl_trans *trans)
117 139
118 return 0; 140 return 0;
119} 141}
142EXPORT_SYMBOL_GPL(iwl_grab_nic_access_silent);
120 143
121bool iwl_grab_nic_access(struct iwl_trans *trans) 144bool iwl_grab_nic_access(struct iwl_trans *trans)
122{ 145{
@@ -130,6 +153,7 @@ bool iwl_grab_nic_access(struct iwl_trans *trans)
130 153
131 return true; 154 return true;
132} 155}
156EXPORT_SYMBOL_GPL(iwl_grab_nic_access);
133 157
134void iwl_release_nic_access(struct iwl_trans *trans) 158void iwl_release_nic_access(struct iwl_trans *trans)
135{ 159{
@@ -144,6 +168,7 @@ void iwl_release_nic_access(struct iwl_trans *trans)
144 */ 168 */
145 mmiowb(); 169 mmiowb();
146} 170}
171EXPORT_SYMBOL_GPL(iwl_release_nic_access);
147 172
148u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg) 173u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg)
149{ 174{
@@ -158,6 +183,7 @@ u32 iwl_read_direct32(struct iwl_trans *trans, u32 reg)
158 183
159 return value; 184 return value;
160} 185}
186EXPORT_SYMBOL_GPL(iwl_read_direct32);
161 187
162void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value) 188void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value)
163{ 189{
@@ -170,6 +196,7 @@ void iwl_write_direct32(struct iwl_trans *trans, u32 reg, u32 value)
170 } 196 }
171 spin_unlock_irqrestore(&trans->reg_lock, flags); 197 spin_unlock_irqrestore(&trans->reg_lock, flags);
172} 198}
199EXPORT_SYMBOL_GPL(iwl_write_direct32);
173 200
174int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask, 201int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
175 int timeout) 202 int timeout)
@@ -185,6 +212,7 @@ int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
185 212
186 return -ETIMEDOUT; 213 return -ETIMEDOUT;
187} 214}
215EXPORT_SYMBOL_GPL(iwl_poll_direct_bit);
188 216
189static inline u32 __iwl_read_prph(struct iwl_trans *trans, u32 reg) 217static inline u32 __iwl_read_prph(struct iwl_trans *trans, u32 reg)
190{ 218{
@@ -211,6 +239,7 @@ u32 iwl_read_prph(struct iwl_trans *trans, u32 reg)
211 spin_unlock_irqrestore(&trans->reg_lock, flags); 239 spin_unlock_irqrestore(&trans->reg_lock, flags);
212 return val; 240 return val;
213} 241}
242EXPORT_SYMBOL_GPL(iwl_read_prph);
214 243
215void iwl_write_prph(struct iwl_trans *trans, u32 addr, u32 val) 244void iwl_write_prph(struct iwl_trans *trans, u32 addr, u32 val)
216{ 245{
@@ -223,6 +252,7 @@ void iwl_write_prph(struct iwl_trans *trans, u32 addr, u32 val)
223 } 252 }
224 spin_unlock_irqrestore(&trans->reg_lock, flags); 253 spin_unlock_irqrestore(&trans->reg_lock, flags);
225} 254}
255EXPORT_SYMBOL_GPL(iwl_write_prph);
226 256
227void iwl_set_bits_prph(struct iwl_trans *trans, u32 reg, u32 mask) 257void iwl_set_bits_prph(struct iwl_trans *trans, u32 reg, u32 mask)
228{ 258{
@@ -236,6 +266,7 @@ void iwl_set_bits_prph(struct iwl_trans *trans, u32 reg, u32 mask)
236 } 266 }
237 spin_unlock_irqrestore(&trans->reg_lock, flags); 267 spin_unlock_irqrestore(&trans->reg_lock, flags);
238} 268}
269EXPORT_SYMBOL_GPL(iwl_set_bits_prph);
239 270
240void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 reg, 271void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 reg,
241 u32 bits, u32 mask) 272 u32 bits, u32 mask)
@@ -250,6 +281,7 @@ void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 reg,
250 } 281 }
251 spin_unlock_irqrestore(&trans->reg_lock, flags); 282 spin_unlock_irqrestore(&trans->reg_lock, flags);
252} 283}
284EXPORT_SYMBOL_GPL(iwl_set_bits_mask_prph);
253 285
254void iwl_clear_bits_prph(struct iwl_trans *trans, u32 reg, u32 mask) 286void iwl_clear_bits_prph(struct iwl_trans *trans, u32 reg, u32 mask)
255{ 287{
@@ -264,9 +296,10 @@ void iwl_clear_bits_prph(struct iwl_trans *trans, u32 reg, u32 mask)
264 } 296 }
265 spin_unlock_irqrestore(&trans->reg_lock, flags); 297 spin_unlock_irqrestore(&trans->reg_lock, flags);
266} 298}
299EXPORT_SYMBOL_GPL(iwl_clear_bits_prph);
267 300
268void _iwl_read_targ_mem_words(struct iwl_trans *trans, u32 addr, 301void _iwl_read_targ_mem_dwords(struct iwl_trans *trans, u32 addr,
269 void *buf, int words) 302 void *buf, int dwords)
270{ 303{
271 unsigned long flags; 304 unsigned long flags;
272 int offs; 305 int offs;
@@ -275,24 +308,26 @@ void _iwl_read_targ_mem_words(struct iwl_trans *trans, u32 addr,
275 spin_lock_irqsave(&trans->reg_lock, flags); 308 spin_lock_irqsave(&trans->reg_lock, flags);
276 if (likely(iwl_grab_nic_access(trans))) { 309 if (likely(iwl_grab_nic_access(trans))) {
277 iwl_write32(trans, HBUS_TARG_MEM_RADDR, addr); 310 iwl_write32(trans, HBUS_TARG_MEM_RADDR, addr);
278 for (offs = 0; offs < words; offs++) 311 for (offs = 0; offs < dwords; offs++)
279 vals[offs] = iwl_read32(trans, HBUS_TARG_MEM_RDAT); 312 vals[offs] = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
280 iwl_release_nic_access(trans); 313 iwl_release_nic_access(trans);
281 } 314 }
282 spin_unlock_irqrestore(&trans->reg_lock, flags); 315 spin_unlock_irqrestore(&trans->reg_lock, flags);
283} 316}
317EXPORT_SYMBOL_GPL(_iwl_read_targ_mem_dwords);
284 318
285u32 iwl_read_targ_mem(struct iwl_trans *trans, u32 addr) 319u32 iwl_read_targ_mem(struct iwl_trans *trans, u32 addr)
286{ 320{
287 u32 value; 321 u32 value;
288 322
289 _iwl_read_targ_mem_words(trans, addr, &value, 1); 323 _iwl_read_targ_mem_dwords(trans, addr, &value, 1);
290 324
291 return value; 325 return value;
292} 326}
327EXPORT_SYMBOL_GPL(iwl_read_targ_mem);
293 328
294int _iwl_write_targ_mem_words(struct iwl_trans *trans, u32 addr, 329int _iwl_write_targ_mem_dwords(struct iwl_trans *trans, u32 addr,
295 void *buf, int words) 330 void *buf, int dwords)
296{ 331{
297 unsigned long flags; 332 unsigned long flags;
298 int offs, result = 0; 333 int offs, result = 0;
@@ -301,7 +336,7 @@ int _iwl_write_targ_mem_words(struct iwl_trans *trans, u32 addr,
301 spin_lock_irqsave(&trans->reg_lock, flags); 336 spin_lock_irqsave(&trans->reg_lock, flags);
302 if (likely(iwl_grab_nic_access(trans))) { 337 if (likely(iwl_grab_nic_access(trans))) {
303 iwl_write32(trans, HBUS_TARG_MEM_WADDR, addr); 338 iwl_write32(trans, HBUS_TARG_MEM_WADDR, addr);
304 for (offs = 0; offs < words; offs++) 339 for (offs = 0; offs < dwords; offs++)
305 iwl_write32(trans, HBUS_TARG_MEM_WDAT, vals[offs]); 340 iwl_write32(trans, HBUS_TARG_MEM_WDAT, vals[offs]);
306 iwl_release_nic_access(trans); 341 iwl_release_nic_access(trans);
307 } else 342 } else
@@ -310,8 +345,10 @@ int _iwl_write_targ_mem_words(struct iwl_trans *trans, u32 addr,
310 345
311 return result; 346 return result;
312} 347}
348EXPORT_SYMBOL_GPL(_iwl_write_targ_mem_dwords);
313 349
314int iwl_write_targ_mem(struct iwl_trans *trans, u32 addr, u32 val) 350int iwl_write_targ_mem(struct iwl_trans *trans, u32 addr, u32 val)
315{ 351{
316 return _iwl_write_targ_mem_words(trans, addr, &val, 1); 352 return _iwl_write_targ_mem_dwords(trans, addr, &val, 1);
317} 353}
354EXPORT_SYMBOL_GPL(iwl_write_targ_mem);
diff --git a/drivers/net/wireless/iwlwifi/iwl-io.h b/drivers/net/wireless/iwlwifi/iwl-io.h
index abb3250164ba..50d3819739d1 100644
--- a/drivers/net/wireless/iwlwifi/iwl-io.h
+++ b/drivers/net/wireless/iwlwifi/iwl-io.h
@@ -54,6 +54,8 @@ static inline u32 iwl_read32(struct iwl_trans *trans, u32 ofs)
54void iwl_set_bit(struct iwl_trans *trans, u32 reg, u32 mask); 54void iwl_set_bit(struct iwl_trans *trans, u32 reg, u32 mask);
55void iwl_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask); 55void iwl_clear_bit(struct iwl_trans *trans, u32 reg, u32 mask);
56 56
57void iwl_set_bits_mask(struct iwl_trans *trans, u32 reg, u32 mask, u32 value);
58
57int iwl_poll_bit(struct iwl_trans *trans, u32 addr, 59int iwl_poll_bit(struct iwl_trans *trans, u32 addr,
58 u32 bits, u32 mask, int timeout); 60 u32 bits, u32 mask, int timeout);
59int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask, 61int iwl_poll_direct_bit(struct iwl_trans *trans, u32 addr, u32 mask,
@@ -74,18 +76,18 @@ void iwl_set_bits_mask_prph(struct iwl_trans *trans, u32 reg,
74 u32 bits, u32 mask); 76 u32 bits, u32 mask);
75void iwl_clear_bits_prph(struct iwl_trans *trans, u32 reg, u32 mask); 77void iwl_clear_bits_prph(struct iwl_trans *trans, u32 reg, u32 mask);
76 78
77void _iwl_read_targ_mem_words(struct iwl_trans *trans, u32 addr, 79void _iwl_read_targ_mem_dwords(struct iwl_trans *trans, u32 addr,
78 void *buf, int words); 80 void *buf, int dwords);
79 81
80#define iwl_read_targ_mem_words(trans, addr, buf, bufsize) \ 82#define iwl_read_targ_mem_bytes(trans, addr, buf, bufsize) \
81 do { \ 83 do { \
82 BUILD_BUG_ON((bufsize) % sizeof(u32)); \ 84 BUILD_BUG_ON((bufsize) % sizeof(u32)); \
83 _iwl_read_targ_mem_words(trans, addr, buf, \ 85 _iwl_read_targ_mem_dwords(trans, addr, buf, \
84 (bufsize) / sizeof(u32));\ 86 (bufsize) / sizeof(u32));\
85 } while (0) 87 } while (0)
86 88
87int _iwl_write_targ_mem_words(struct iwl_trans *trans, u32 addr, 89int _iwl_write_targ_mem_dwords(struct iwl_trans *trans, u32 addr,
88 void *buf, int words); 90 void *buf, int dwords);
89 91
90u32 iwl_read_targ_mem(struct iwl_trans *trans, u32 addr); 92u32 iwl_read_targ_mem(struct iwl_trans *trans, u32 addr);
91int iwl_write_targ_mem(struct iwl_trans *trans, u32 addr, u32 val); 93int iwl_write_targ_mem(struct iwl_trans *trans, u32 addr, u32 val);
diff --git a/drivers/net/wireless/iwlwifi/iwl-notif-wait.c b/drivers/net/wireless/iwlwifi/iwl-notif-wait.c
index 0066b899fe5c..5cfed29b1b18 100644
--- a/drivers/net/wireless/iwlwifi/iwl-notif-wait.c
+++ b/drivers/net/wireless/iwlwifi/iwl-notif-wait.c
@@ -61,6 +61,7 @@
61 * 61 *
62 *****************************************************************************/ 62 *****************************************************************************/
63#include <linux/sched.h> 63#include <linux/sched.h>
64#include <linux/export.h>
64 65
65#include "iwl-notif-wait.h" 66#include "iwl-notif-wait.h"
66 67
@@ -71,6 +72,7 @@ void iwl_notification_wait_init(struct iwl_notif_wait_data *notif_wait)
71 INIT_LIST_HEAD(&notif_wait->notif_waits); 72 INIT_LIST_HEAD(&notif_wait->notif_waits);
72 init_waitqueue_head(&notif_wait->notif_waitq); 73 init_waitqueue_head(&notif_wait->notif_waitq);
73} 74}
75EXPORT_SYMBOL_GPL(iwl_notification_wait_init);
74 76
75void iwl_notification_wait_notify(struct iwl_notif_wait_data *notif_wait, 77void iwl_notification_wait_notify(struct iwl_notif_wait_data *notif_wait,
76 struct iwl_rx_packet *pkt) 78 struct iwl_rx_packet *pkt)
@@ -115,6 +117,7 @@ void iwl_notification_wait_notify(struct iwl_notif_wait_data *notif_wait,
115 if (triggered) 117 if (triggered)
116 wake_up_all(&notif_wait->notif_waitq); 118 wake_up_all(&notif_wait->notif_waitq);
117} 119}
120EXPORT_SYMBOL_GPL(iwl_notification_wait_notify);
118 121
119void iwl_abort_notification_waits(struct iwl_notif_wait_data *notif_wait) 122void iwl_abort_notification_waits(struct iwl_notif_wait_data *notif_wait)
120{ 123{
@@ -128,7 +131,7 @@ void iwl_abort_notification_waits(struct iwl_notif_wait_data *notif_wait)
128 131
129 wake_up_all(&notif_wait->notif_waitq); 132 wake_up_all(&notif_wait->notif_waitq);
130} 133}
131 134EXPORT_SYMBOL_GPL(iwl_abort_notification_waits);
132 135
133void 136void
134iwl_init_notification_wait(struct iwl_notif_wait_data *notif_wait, 137iwl_init_notification_wait(struct iwl_notif_wait_data *notif_wait,
@@ -152,6 +155,7 @@ iwl_init_notification_wait(struct iwl_notif_wait_data *notif_wait,
152 list_add(&wait_entry->list, &notif_wait->notif_waits); 155 list_add(&wait_entry->list, &notif_wait->notif_waits);
153 spin_unlock_bh(&notif_wait->notif_wait_lock); 156 spin_unlock_bh(&notif_wait->notif_wait_lock);
154} 157}
158EXPORT_SYMBOL_GPL(iwl_init_notification_wait);
155 159
156int iwl_wait_notification(struct iwl_notif_wait_data *notif_wait, 160int iwl_wait_notification(struct iwl_notif_wait_data *notif_wait,
157 struct iwl_notification_wait *wait_entry, 161 struct iwl_notification_wait *wait_entry,
@@ -175,6 +179,7 @@ int iwl_wait_notification(struct iwl_notif_wait_data *notif_wait,
175 return -ETIMEDOUT; 179 return -ETIMEDOUT;
176 return 0; 180 return 0;
177} 181}
182EXPORT_SYMBOL_GPL(iwl_wait_notification);
178 183
179void iwl_remove_notification(struct iwl_notif_wait_data *notif_wait, 184void iwl_remove_notification(struct iwl_notif_wait_data *notif_wait,
180 struct iwl_notification_wait *wait_entry) 185 struct iwl_notification_wait *wait_entry)
@@ -183,3 +188,4 @@ void iwl_remove_notification(struct iwl_notif_wait_data *notif_wait,
183 list_del(&wait_entry->list); 188 list_del(&wait_entry->list);
184 spin_unlock_bh(&notif_wait->notif_wait_lock); 189 spin_unlock_bh(&notif_wait->notif_wait_lock);
185} 190}
191EXPORT_SYMBOL_GPL(iwl_remove_notification);
diff --git a/drivers/net/wireless/iwlwifi/iwl-op-mode.h b/drivers/net/wireless/iwlwifi/iwl-op-mode.h
index 4ef742b28e08..cd9ef114d3a3 100644
--- a/drivers/net/wireless/iwlwifi/iwl-op-mode.h
+++ b/drivers/net/wireless/iwlwifi/iwl-op-mode.h
@@ -145,6 +145,9 @@ struct iwl_op_mode_ops {
145 void (*wimax_active)(struct iwl_op_mode *op_mode); 145 void (*wimax_active)(struct iwl_op_mode *op_mode);
146}; 146};
147 147
148int iwl_opmode_register(const char *name, const struct iwl_op_mode_ops *ops);
149void iwl_opmode_deregister(const char *name);
150
148/** 151/**
149 * struct iwl_op_mode - operational mode 152 * struct iwl_op_mode - operational mode
150 * 153 *
@@ -218,9 +221,4 @@ static inline void iwl_op_mode_wimax_active(struct iwl_op_mode *op_mode)
218 op_mode->ops->wimax_active(op_mode); 221 op_mode->ops->wimax_active(op_mode);
219} 222}
220 223
221/*****************************************************
222* Op mode layers implementations
223******************************************************/
224extern const struct iwl_op_mode_ops iwl_dvm_ops;
225
226#endif /* __iwl_op_mode_h__ */ 224#endif /* __iwl_op_mode_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-prph.h b/drivers/net/wireless/iwlwifi/iwl-prph.h
index dfd54662e3e6..9253ef1dba72 100644
--- a/drivers/net/wireless/iwlwifi/iwl-prph.h
+++ b/drivers/net/wireless/iwlwifi/iwl-prph.h
@@ -187,7 +187,7 @@
187#define SCD_QUEUE_STTS_REG_POS_ACTIVE (3) 187#define SCD_QUEUE_STTS_REG_POS_ACTIVE (3)
188#define SCD_QUEUE_STTS_REG_POS_WSL (4) 188#define SCD_QUEUE_STTS_REG_POS_WSL (4)
189#define SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN (19) 189#define SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN (19)
190#define SCD_QUEUE_STTS_REG_MSK (0x00FF0000) 190#define SCD_QUEUE_STTS_REG_MSK (0x017F0000)
191 191
192#define SCD_QUEUE_CTX_REG1_CREDIT_POS (8) 192#define SCD_QUEUE_CTX_REG1_CREDIT_POS (8)
193#define SCD_QUEUE_CTX_REG1_CREDIT_MSK (0x00FFFF00) 193#define SCD_QUEUE_CTX_REG1_CREDIT_MSK (0x00FFFF00)
diff --git a/drivers/net/wireless/iwlwifi/iwl-test.c b/drivers/net/wireless/iwlwifi/iwl-test.c
new file mode 100644
index 000000000000..81e8c7126d72
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-test.c
@@ -0,0 +1,856 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63
64#include <linux/export.h>
65#include <net/netlink.h>
66
67#include "iwl-io.h"
68#include "iwl-fh.h"
69#include "iwl-prph.h"
70#include "iwl-trans.h"
71#include "iwl-test.h"
72#include "iwl-csr.h"
73#include "iwl-testmode.h"
74
75/*
76 * Periphery registers absolute lower bound. This is used in order to
77 * differentiate registery access through HBUS_TARG_PRPH_* and
78 * HBUS_TARG_MEM_* accesses.
79 */
80#define IWL_ABS_PRPH_START (0xA00000)
81
82/*
83 * The TLVs used in the gnl message policy between the kernel module and
84 * user space application. iwl_testmode_gnl_msg_policy is to be carried
85 * through the NL80211_CMD_TESTMODE channel regulated by nl80211.
86 * See iwl-testmode.h
87 */
88static
89struct nla_policy iwl_testmode_gnl_msg_policy[IWL_TM_ATTR_MAX] = {
90 [IWL_TM_ATTR_COMMAND] = { .type = NLA_U32, },
91
92 [IWL_TM_ATTR_UCODE_CMD_ID] = { .type = NLA_U8, },
93 [IWL_TM_ATTR_UCODE_CMD_DATA] = { .type = NLA_UNSPEC, },
94
95 [IWL_TM_ATTR_REG_OFFSET] = { .type = NLA_U32, },
96 [IWL_TM_ATTR_REG_VALUE8] = { .type = NLA_U8, },
97 [IWL_TM_ATTR_REG_VALUE32] = { .type = NLA_U32, },
98
99 [IWL_TM_ATTR_SYNC_RSP] = { .type = NLA_UNSPEC, },
100 [IWL_TM_ATTR_UCODE_RX_PKT] = { .type = NLA_UNSPEC, },
101
102 [IWL_TM_ATTR_EEPROM] = { .type = NLA_UNSPEC, },
103
104 [IWL_TM_ATTR_TRACE_ADDR] = { .type = NLA_UNSPEC, },
105 [IWL_TM_ATTR_TRACE_DUMP] = { .type = NLA_UNSPEC, },
106 [IWL_TM_ATTR_TRACE_SIZE] = { .type = NLA_U32, },
107
108 [IWL_TM_ATTR_FIXRATE] = { .type = NLA_U32, },
109
110 [IWL_TM_ATTR_UCODE_OWNER] = { .type = NLA_U8, },
111
112 [IWL_TM_ATTR_MEM_ADDR] = { .type = NLA_U32, },
113 [IWL_TM_ATTR_BUFFER_SIZE] = { .type = NLA_U32, },
114 [IWL_TM_ATTR_BUFFER_DUMP] = { .type = NLA_UNSPEC, },
115
116 [IWL_TM_ATTR_FW_VERSION] = { .type = NLA_U32, },
117 [IWL_TM_ATTR_DEVICE_ID] = { .type = NLA_U32, },
118 [IWL_TM_ATTR_FW_TYPE] = { .type = NLA_U32, },
119 [IWL_TM_ATTR_FW_INST_SIZE] = { .type = NLA_U32, },
120 [IWL_TM_ATTR_FW_DATA_SIZE] = { .type = NLA_U32, },
121
122 [IWL_TM_ATTR_ENABLE_NOTIFICATION] = {.type = NLA_FLAG, },
123};
124
125static inline void iwl_test_trace_clear(struct iwl_test *tst)
126{
127 memset(&tst->trace, 0, sizeof(struct iwl_test_trace));
128}
129
130static void iwl_test_trace_stop(struct iwl_test *tst)
131{
132 if (!tst->trace.enabled)
133 return;
134
135 if (tst->trace.cpu_addr && tst->trace.dma_addr)
136 dma_free_coherent(tst->trans->dev,
137 tst->trace.tsize,
138 tst->trace.cpu_addr,
139 tst->trace.dma_addr);
140
141 iwl_test_trace_clear(tst);
142}
143
144static inline void iwl_test_mem_clear(struct iwl_test *tst)
145{
146 memset(&tst->mem, 0, sizeof(struct iwl_test_mem));
147}
148
149static inline void iwl_test_mem_stop(struct iwl_test *tst)
150{
151 if (!tst->mem.in_read)
152 return;
153
154 iwl_test_mem_clear(tst);
155}
156
157/*
158 * Initializes the test object
159 * During the lifetime of the test object it is assumed that the transport is
160 * started. The test object should be stopped before the transport is stopped.
161 */
162void iwl_test_init(struct iwl_test *tst, struct iwl_trans *trans,
163 struct iwl_test_ops *ops)
164{
165 tst->trans = trans;
166 tst->ops = ops;
167
168 iwl_test_trace_clear(tst);
169 iwl_test_mem_clear(tst);
170}
171EXPORT_SYMBOL_GPL(iwl_test_init);
172
173/*
174 * Stop the test object
175 */
176void iwl_test_free(struct iwl_test *tst)
177{
178 iwl_test_mem_stop(tst);
179 iwl_test_trace_stop(tst);
180}
181EXPORT_SYMBOL_GPL(iwl_test_free);
182
183static inline int iwl_test_send_cmd(struct iwl_test *tst,
184 struct iwl_host_cmd *cmd)
185{
186 return tst->ops->send_cmd(tst->trans->op_mode, cmd);
187}
188
189static inline bool iwl_test_valid_hw_addr(struct iwl_test *tst, u32 addr)
190{
191 return tst->ops->valid_hw_addr(addr);
192}
193
194static inline u32 iwl_test_fw_ver(struct iwl_test *tst)
195{
196 return tst->ops->get_fw_ver(tst->trans->op_mode);
197}
198
199static inline struct sk_buff*
200iwl_test_alloc_reply(struct iwl_test *tst, int len)
201{
202 return tst->ops->alloc_reply(tst->trans->op_mode, len);
203}
204
205static inline int iwl_test_reply(struct iwl_test *tst, struct sk_buff *skb)
206{
207 return tst->ops->reply(tst->trans->op_mode, skb);
208}
209
210static inline struct sk_buff*
211iwl_test_alloc_event(struct iwl_test *tst, int len)
212{
213 return tst->ops->alloc_event(tst->trans->op_mode, len);
214}
215
216static inline void
217iwl_test_event(struct iwl_test *tst, struct sk_buff *skb)
218{
219 return tst->ops->event(tst->trans->op_mode, skb);
220}
221
222/*
223 * This function handles the user application commands to the fw. The fw
224 * commands are sent in a synchronuous manner. In case that the user requested
225 * to get commands response, it is send to the user.
226 */
227static int iwl_test_fw_cmd(struct iwl_test *tst, struct nlattr **tb)
228{
229 struct iwl_host_cmd cmd;
230 struct iwl_rx_packet *pkt;
231 struct sk_buff *skb;
232 void *reply_buf;
233 u32 reply_len;
234 int ret;
235 bool cmd_want_skb;
236
237 memset(&cmd, 0, sizeof(struct iwl_host_cmd));
238
239 if (!tb[IWL_TM_ATTR_UCODE_CMD_ID] ||
240 !tb[IWL_TM_ATTR_UCODE_CMD_DATA]) {
241 IWL_ERR(tst->trans, "Missing fw command mandatory fields\n");
242 return -ENOMSG;
243 }
244
245 cmd.flags = CMD_ON_DEMAND | CMD_SYNC;
246 cmd_want_skb = nla_get_flag(tb[IWL_TM_ATTR_UCODE_CMD_SKB]);
247 if (cmd_want_skb)
248 cmd.flags |= CMD_WANT_SKB;
249
250 cmd.id = nla_get_u8(tb[IWL_TM_ATTR_UCODE_CMD_ID]);
251 cmd.data[0] = nla_data(tb[IWL_TM_ATTR_UCODE_CMD_DATA]);
252 cmd.len[0] = nla_len(tb[IWL_TM_ATTR_UCODE_CMD_DATA]);
253 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
254 IWL_DEBUG_INFO(tst->trans, "test fw cmd=0x%x, flags 0x%x, len %d\n",
255 cmd.id, cmd.flags, cmd.len[0]);
256
257 ret = iwl_test_send_cmd(tst, &cmd);
258 if (ret) {
259 IWL_ERR(tst->trans, "Failed to send hcmd\n");
260 return ret;
261 }
262 if (!cmd_want_skb)
263 return ret;
264
265 /* Handling return of SKB to the user */
266 pkt = cmd.resp_pkt;
267 if (!pkt) {
268 IWL_ERR(tst->trans, "HCMD received a null response packet\n");
269 return ret;
270 }
271
272 reply_len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
273 skb = iwl_test_alloc_reply(tst, reply_len + 20);
274 reply_buf = kmalloc(reply_len, GFP_KERNEL);
275 if (!skb || !reply_buf) {
276 kfree_skb(skb);
277 kfree(reply_buf);
278 return -ENOMEM;
279 }
280
281 /* The reply is in a page, that we cannot send to user space. */
282 memcpy(reply_buf, &(pkt->hdr), reply_len);
283 iwl_free_resp(&cmd);
284
285 if (nla_put_u32(skb, IWL_TM_ATTR_COMMAND,
286 IWL_TM_CMD_DEV2APP_UCODE_RX_PKT) ||
287 nla_put(skb, IWL_TM_ATTR_UCODE_RX_PKT, reply_len, reply_buf))
288 goto nla_put_failure;
289 return iwl_test_reply(tst, skb);
290
291nla_put_failure:
292 IWL_DEBUG_INFO(tst->trans, "Failed creating NL attributes\n");
293 kfree(reply_buf);
294 kfree_skb(skb);
295 return -ENOMSG;
296}
297
298/*
299 * Handles the user application commands for register access.
300 */
301static int iwl_test_reg(struct iwl_test *tst, struct nlattr **tb)
302{
303 u32 ofs, val32, cmd;
304 u8 val8;
305 struct sk_buff *skb;
306 int status = 0;
307 struct iwl_trans *trans = tst->trans;
308
309 if (!tb[IWL_TM_ATTR_REG_OFFSET]) {
310 IWL_ERR(trans, "Missing reg offset\n");
311 return -ENOMSG;
312 }
313
314 ofs = nla_get_u32(tb[IWL_TM_ATTR_REG_OFFSET]);
315 IWL_DEBUG_INFO(trans, "test reg access cmd offset=0x%x\n", ofs);
316
317 cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]);
318
319 /*
320 * Allow access only to FH/CSR/HBUS in direct mode.
321 * Since we don't have the upper bounds for the CSR and HBUS segments,
322 * we will use only the upper bound of FH for sanity check.
323 */
324 if (ofs >= FH_MEM_UPPER_BOUND) {
325 IWL_ERR(trans, "offset out of segment (0x0 - 0x%x)\n",
326 FH_MEM_UPPER_BOUND);
327 return -EINVAL;
328 }
329
330 switch (cmd) {
331 case IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32:
332 val32 = iwl_read_direct32(tst->trans, ofs);
333 IWL_DEBUG_INFO(trans, "32 value to read 0x%x\n", val32);
334
335 skb = iwl_test_alloc_reply(tst, 20);
336 if (!skb) {
337 IWL_ERR(trans, "Memory allocation fail\n");
338 return -ENOMEM;
339 }
340 if (nla_put_u32(skb, IWL_TM_ATTR_REG_VALUE32, val32))
341 goto nla_put_failure;
342 status = iwl_test_reply(tst, skb);
343 if (status < 0)
344 IWL_ERR(trans, "Error sending msg : %d\n", status);
345 break;
346
347 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32:
348 if (!tb[IWL_TM_ATTR_REG_VALUE32]) {
349 IWL_ERR(trans, "Missing value to write\n");
350 return -ENOMSG;
351 } else {
352 val32 = nla_get_u32(tb[IWL_TM_ATTR_REG_VALUE32]);
353 IWL_DEBUG_INFO(trans, "32b write val=0x%x\n", val32);
354 iwl_write_direct32(tst->trans, ofs, val32);
355 }
356 break;
357
358 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8:
359 if (!tb[IWL_TM_ATTR_REG_VALUE8]) {
360 IWL_ERR(trans, "Missing value to write\n");
361 return -ENOMSG;
362 } else {
363 val8 = nla_get_u8(tb[IWL_TM_ATTR_REG_VALUE8]);
364 IWL_DEBUG_INFO(trans, "8b write val=0x%x\n", val8);
365 iwl_write8(tst->trans, ofs, val8);
366 }
367 break;
368
369 default:
370 IWL_ERR(trans, "Unknown test register cmd ID\n");
371 return -ENOMSG;
372 }
373
374 return status;
375
376nla_put_failure:
377 kfree_skb(skb);
378 return -EMSGSIZE;
379}
380
381/*
382 * Handles the request to start FW tracing. Allocates of the trace buffer
383 * and sends a reply to user space with the address of the allocated buffer.
384 */
385static int iwl_test_trace_begin(struct iwl_test *tst, struct nlattr **tb)
386{
387 struct sk_buff *skb;
388 int status = 0;
389
390 if (tst->trace.enabled)
391 return -EBUSY;
392
393 if (!tb[IWL_TM_ATTR_TRACE_SIZE])
394 tst->trace.size = TRACE_BUFF_SIZE_DEF;
395 else
396 tst->trace.size =
397 nla_get_u32(tb[IWL_TM_ATTR_TRACE_SIZE]);
398
399 if (!tst->trace.size)
400 return -EINVAL;
401
402 if (tst->trace.size < TRACE_BUFF_SIZE_MIN ||
403 tst->trace.size > TRACE_BUFF_SIZE_MAX)
404 return -EINVAL;
405
406 tst->trace.tsize = tst->trace.size + TRACE_BUFF_PADD;
407 tst->trace.cpu_addr = dma_alloc_coherent(tst->trans->dev,
408 tst->trace.tsize,
409 &tst->trace.dma_addr,
410 GFP_KERNEL);
411 if (!tst->trace.cpu_addr)
412 return -ENOMEM;
413
414 tst->trace.enabled = true;
415 tst->trace.trace_addr = (u8 *)PTR_ALIGN(tst->trace.cpu_addr, 0x100);
416
417 memset(tst->trace.trace_addr, 0x03B, tst->trace.size);
418
419 skb = iwl_test_alloc_reply(tst, sizeof(tst->trace.dma_addr) + 20);
420 if (!skb) {
421 IWL_ERR(tst->trans, "Memory allocation fail\n");
422 iwl_test_trace_stop(tst);
423 return -ENOMEM;
424 }
425
426 if (nla_put(skb, IWL_TM_ATTR_TRACE_ADDR,
427 sizeof(tst->trace.dma_addr),
428 (u64 *)&tst->trace.dma_addr))
429 goto nla_put_failure;
430
431 status = iwl_test_reply(tst, skb);
432 if (status < 0)
433 IWL_ERR(tst->trans, "Error sending msg : %d\n", status);
434
435 tst->trace.nchunks = DIV_ROUND_UP(tst->trace.size,
436 DUMP_CHUNK_SIZE);
437
438 return status;
439
440nla_put_failure:
441 kfree_skb(skb);
442 if (nla_get_u32(tb[IWL_TM_ATTR_COMMAND]) ==
443 IWL_TM_CMD_APP2DEV_BEGIN_TRACE)
444 iwl_test_trace_stop(tst);
445 return -EMSGSIZE;
446}
447
448/*
449 * Handles indirect read from the periphery or the SRAM. The read is performed
450 * to a temporary buffer. The user space application should later issue a dump
451 */
452static int iwl_test_indirect_read(struct iwl_test *tst, u32 addr, u32 size)
453{
454 struct iwl_trans *trans = tst->trans;
455 unsigned long flags;
456 int i;
457
458 if (size & 0x3)
459 return -EINVAL;
460
461 tst->mem.size = size;
462 tst->mem.addr = kmalloc(tst->mem.size, GFP_KERNEL);
463 if (tst->mem.addr == NULL)
464 return -ENOMEM;
465
466 /* Hard-coded periphery absolute address */
467 if (IWL_ABS_PRPH_START <= addr &&
468 addr < IWL_ABS_PRPH_START + PRPH_END) {
469 spin_lock_irqsave(&trans->reg_lock, flags);
470 iwl_grab_nic_access(trans);
471 iwl_write32(trans, HBUS_TARG_PRPH_RADDR,
472 addr | (3 << 24));
473 for (i = 0; i < size; i += 4)
474 *(u32 *)(tst->mem.addr + i) =
475 iwl_read32(trans, HBUS_TARG_PRPH_RDAT);
476 iwl_release_nic_access(trans);
477 spin_unlock_irqrestore(&trans->reg_lock, flags);
478 } else { /* target memory (SRAM) */
479 _iwl_read_targ_mem_dwords(trans, addr,
480 tst->mem.addr,
481 tst->mem.size / 4);
482 }
483
484 tst->mem.nchunks =
485 DIV_ROUND_UP(tst->mem.size, DUMP_CHUNK_SIZE);
486 tst->mem.in_read = true;
487 return 0;
488
489}
490
491/*
492 * Handles indirect write to the periphery or SRAM. The is performed to a
493 * temporary buffer.
494 */
495static int iwl_test_indirect_write(struct iwl_test *tst, u32 addr,
496 u32 size, unsigned char *buf)
497{
498 struct iwl_trans *trans = tst->trans;
499 u32 val, i;
500 unsigned long flags;
501
502 if (IWL_ABS_PRPH_START <= addr &&
503 addr < IWL_ABS_PRPH_START + PRPH_END) {
504 /* Periphery writes can be 1-3 bytes long, or DWORDs */
505 if (size < 4) {
506 memcpy(&val, buf, size);
507 spin_lock_irqsave(&trans->reg_lock, flags);
508 iwl_grab_nic_access(trans);
509 iwl_write32(trans, HBUS_TARG_PRPH_WADDR,
510 (addr & 0x0000FFFF) |
511 ((size - 1) << 24));
512 iwl_write32(trans, HBUS_TARG_PRPH_WDAT, val);
513 iwl_release_nic_access(trans);
514 /* needed after consecutive writes w/o read */
515 mmiowb();
516 spin_unlock_irqrestore(&trans->reg_lock, flags);
517 } else {
518 if (size % 4)
519 return -EINVAL;
520 for (i = 0; i < size; i += 4)
521 iwl_write_prph(trans, addr+i,
522 *(u32 *)(buf+i));
523 }
524 } else if (iwl_test_valid_hw_addr(tst, addr)) {
525 _iwl_write_targ_mem_dwords(trans, addr, buf, size / 4);
526 } else {
527 return -EINVAL;
528 }
529 return 0;
530}
531
532/*
533 * Handles the user application commands for indirect read/write
534 * to/from the periphery or the SRAM.
535 */
536static int iwl_test_indirect_mem(struct iwl_test *tst, struct nlattr **tb)
537{
538 u32 addr, size, cmd;
539 unsigned char *buf;
540
541 /* Both read and write should be blocked, for atomicity */
542 if (tst->mem.in_read)
543 return -EBUSY;
544
545 cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]);
546 if (!tb[IWL_TM_ATTR_MEM_ADDR]) {
547 IWL_ERR(tst->trans, "Error finding memory offset address\n");
548 return -ENOMSG;
549 }
550 addr = nla_get_u32(tb[IWL_TM_ATTR_MEM_ADDR]);
551 if (!tb[IWL_TM_ATTR_BUFFER_SIZE]) {
552 IWL_ERR(tst->trans, "Error finding size for memory reading\n");
553 return -ENOMSG;
554 }
555 size = nla_get_u32(tb[IWL_TM_ATTR_BUFFER_SIZE]);
556
557 if (cmd == IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ) {
558 return iwl_test_indirect_read(tst, addr, size);
559 } else {
560 if (!tb[IWL_TM_ATTR_BUFFER_DUMP])
561 return -EINVAL;
562 buf = (unsigned char *)nla_data(tb[IWL_TM_ATTR_BUFFER_DUMP]);
563 return iwl_test_indirect_write(tst, addr, size, buf);
564 }
565}
566
567/*
568 * Enable notifications to user space
569 */
570static int iwl_test_notifications(struct iwl_test *tst,
571 struct nlattr **tb)
572{
573 tst->notify = nla_get_flag(tb[IWL_TM_ATTR_ENABLE_NOTIFICATION]);
574 return 0;
575}
576
577/*
578 * Handles the request to get the device id
579 */
580static int iwl_test_get_dev_id(struct iwl_test *tst, struct nlattr **tb)
581{
582 u32 devid = tst->trans->hw_id;
583 struct sk_buff *skb;
584 int status;
585
586 IWL_DEBUG_INFO(tst->trans, "hw version: 0x%x\n", devid);
587
588 skb = iwl_test_alloc_reply(tst, 20);
589 if (!skb) {
590 IWL_ERR(tst->trans, "Memory allocation fail\n");
591 return -ENOMEM;
592 }
593
594 if (nla_put_u32(skb, IWL_TM_ATTR_DEVICE_ID, devid))
595 goto nla_put_failure;
596 status = iwl_test_reply(tst, skb);
597 if (status < 0)
598 IWL_ERR(tst->trans, "Error sending msg : %d\n", status);
599
600 return 0;
601
602nla_put_failure:
603 kfree_skb(skb);
604 return -EMSGSIZE;
605}
606
607/*
608 * Handles the request to get the FW version
609 */
610static int iwl_test_get_fw_ver(struct iwl_test *tst, struct nlattr **tb)
611{
612 struct sk_buff *skb;
613 int status;
614 u32 ver = iwl_test_fw_ver(tst);
615
616 IWL_DEBUG_INFO(tst->trans, "uCode version raw: 0x%x\n", ver);
617
618 skb = iwl_test_alloc_reply(tst, 20);
619 if (!skb) {
620 IWL_ERR(tst->trans, "Memory allocation fail\n");
621 return -ENOMEM;
622 }
623
624 if (nla_put_u32(skb, IWL_TM_ATTR_FW_VERSION, ver))
625 goto nla_put_failure;
626
627 status = iwl_test_reply(tst, skb);
628 if (status < 0)
629 IWL_ERR(tst->trans, "Error sending msg : %d\n", status);
630
631 return 0;
632
633nla_put_failure:
634 kfree_skb(skb);
635 return -EMSGSIZE;
636}
637
638/*
639 * Parse the netlink message and validate that the IWL_TM_ATTR_CMD exists
640 */
641int iwl_test_parse(struct iwl_test *tst, struct nlattr **tb,
642 void *data, int len)
643{
644 int result;
645
646 result = nla_parse(tb, IWL_TM_ATTR_MAX - 1, data, len,
647 iwl_testmode_gnl_msg_policy);
648 if (result) {
649 IWL_ERR(tst->trans, "Fail parse gnl msg: %d\n", result);
650 return result;
651 }
652
653 /* IWL_TM_ATTR_COMMAND is absolutely mandatory */
654 if (!tb[IWL_TM_ATTR_COMMAND]) {
655 IWL_ERR(tst->trans, "Missing testmode command type\n");
656 return -ENOMSG;
657 }
658 return 0;
659}
660EXPORT_SYMBOL_GPL(iwl_test_parse);
661
662/*
663 * Handle test commands.
664 * Returns 1 for unknown commands (not handled by the test object); negative
665 * value in case of error.
666 */
667int iwl_test_handle_cmd(struct iwl_test *tst, struct nlattr **tb)
668{
669 int result;
670
671 switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
672 case IWL_TM_CMD_APP2DEV_UCODE:
673 IWL_DEBUG_INFO(tst->trans, "test cmd to uCode\n");
674 result = iwl_test_fw_cmd(tst, tb);
675 break;
676
677 case IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32:
678 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32:
679 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8:
680 IWL_DEBUG_INFO(tst->trans, "test cmd to register\n");
681 result = iwl_test_reg(tst, tb);
682 break;
683
684 case IWL_TM_CMD_APP2DEV_BEGIN_TRACE:
685 IWL_DEBUG_INFO(tst->trans, "test uCode trace cmd to driver\n");
686 result = iwl_test_trace_begin(tst, tb);
687 break;
688
689 case IWL_TM_CMD_APP2DEV_END_TRACE:
690 iwl_test_trace_stop(tst);
691 result = 0;
692 break;
693
694 case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ:
695 case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_WRITE:
696 IWL_DEBUG_INFO(tst->trans, "test indirect memory cmd\n");
697 result = iwl_test_indirect_mem(tst, tb);
698 break;
699
700 case IWL_TM_CMD_APP2DEV_NOTIFICATIONS:
701 IWL_DEBUG_INFO(tst->trans, "test notifications cmd\n");
702 result = iwl_test_notifications(tst, tb);
703 break;
704
705 case IWL_TM_CMD_APP2DEV_GET_FW_VERSION:
706 IWL_DEBUG_INFO(tst->trans, "test get FW ver cmd\n");
707 result = iwl_test_get_fw_ver(tst, tb);
708 break;
709
710 case IWL_TM_CMD_APP2DEV_GET_DEVICE_ID:
711 IWL_DEBUG_INFO(tst->trans, "test Get device ID cmd\n");
712 result = iwl_test_get_dev_id(tst, tb);
713 break;
714
715 default:
716 IWL_DEBUG_INFO(tst->trans, "Unknown test command\n");
717 result = 1;
718 break;
719 }
720 return result;
721}
722EXPORT_SYMBOL_GPL(iwl_test_handle_cmd);
723
724static int iwl_test_trace_dump(struct iwl_test *tst, struct sk_buff *skb,
725 struct netlink_callback *cb)
726{
727 int idx, length;
728
729 if (!tst->trace.enabled || !tst->trace.trace_addr)
730 return -EFAULT;
731
732 idx = cb->args[4];
733 if (idx >= tst->trace.nchunks)
734 return -ENOENT;
735
736 length = DUMP_CHUNK_SIZE;
737 if (((idx + 1) == tst->trace.nchunks) &&
738 (tst->trace.size % DUMP_CHUNK_SIZE))
739 length = tst->trace.size %
740 DUMP_CHUNK_SIZE;
741
742 if (nla_put(skb, IWL_TM_ATTR_TRACE_DUMP, length,
743 tst->trace.trace_addr + (DUMP_CHUNK_SIZE * idx)))
744 goto nla_put_failure;
745
746 cb->args[4] = ++idx;
747 return 0;
748
749 nla_put_failure:
750 return -ENOBUFS;
751}
752
753static int iwl_test_buffer_dump(struct iwl_test *tst, struct sk_buff *skb,
754 struct netlink_callback *cb)
755{
756 int idx, length;
757
758 if (!tst->mem.in_read)
759 return -EFAULT;
760
761 idx = cb->args[4];
762 if (idx >= tst->mem.nchunks) {
763 iwl_test_mem_stop(tst);
764 return -ENOENT;
765 }
766
767 length = DUMP_CHUNK_SIZE;
768 if (((idx + 1) == tst->mem.nchunks) &&
769 (tst->mem.size % DUMP_CHUNK_SIZE))
770 length = tst->mem.size % DUMP_CHUNK_SIZE;
771
772 if (nla_put(skb, IWL_TM_ATTR_BUFFER_DUMP, length,
773 tst->mem.addr + (DUMP_CHUNK_SIZE * idx)))
774 goto nla_put_failure;
775
776 cb->args[4] = ++idx;
777 return 0;
778
779 nla_put_failure:
780 return -ENOBUFS;
781}
782
783/*
784 * Handle dump commands.
785 * Returns 1 for unknown commands (not handled by the test object); negative
786 * value in case of error.
787 */
788int iwl_test_dump(struct iwl_test *tst, u32 cmd, struct sk_buff *skb,
789 struct netlink_callback *cb)
790{
791 int result;
792
793 switch (cmd) {
794 case IWL_TM_CMD_APP2DEV_READ_TRACE:
795 IWL_DEBUG_INFO(tst->trans, "uCode trace cmd\n");
796 result = iwl_test_trace_dump(tst, skb, cb);
797 break;
798
799 case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_DUMP:
800 IWL_DEBUG_INFO(tst->trans, "testmode sram dump cmd\n");
801 result = iwl_test_buffer_dump(tst, skb, cb);
802 break;
803
804 default:
805 result = 1;
806 break;
807 }
808 return result;
809}
810EXPORT_SYMBOL_GPL(iwl_test_dump);
811
812/*
813 * Multicast a spontaneous messages from the device to the user space.
814 */
815static void iwl_test_send_rx(struct iwl_test *tst,
816 struct iwl_rx_cmd_buffer *rxb)
817{
818 struct sk_buff *skb;
819 struct iwl_rx_packet *data;
820 int length;
821
822 data = rxb_addr(rxb);
823 length = le32_to_cpu(data->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
824
825 /* the length doesn't include len_n_flags field, so add it manually */
826 length += sizeof(__le32);
827
828 skb = iwl_test_alloc_event(tst, length + 20);
829 if (skb == NULL) {
830 IWL_ERR(tst->trans, "Out of memory for message to user\n");
831 return;
832 }
833
834 if (nla_put_u32(skb, IWL_TM_ATTR_COMMAND,
835 IWL_TM_CMD_DEV2APP_UCODE_RX_PKT) ||
836 nla_put(skb, IWL_TM_ATTR_UCODE_RX_PKT, length, data))
837 goto nla_put_failure;
838
839 iwl_test_event(tst, skb);
840 return;
841
842nla_put_failure:
843 kfree_skb(skb);
844 IWL_ERR(tst->trans, "Ouch, overran buffer, check allocation!\n");
845}
846
847/*
848 * Called whenever a Rx frames is recevied from the device. If notifications to
849 * the user space are requested, sends the frames to the user.
850 */
851void iwl_test_rx(struct iwl_test *tst, struct iwl_rx_cmd_buffer *rxb)
852{
853 if (tst->notify)
854 iwl_test_send_rx(tst, rxb);
855}
856EXPORT_SYMBOL_GPL(iwl_test_rx);
diff --git a/drivers/net/wireless/iwlwifi/iwl-test.h b/drivers/net/wireless/iwlwifi/iwl-test.h
new file mode 100644
index 000000000000..e13ffa8acc02
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-test.h
@@ -0,0 +1,161 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63
64#ifndef __IWL_TEST_H__
65#define __IWL_TEST_H__
66
67#include <linux/types.h>
68#include "iwl-trans.h"
69
70struct iwl_test_trace {
71 u32 size;
72 u32 tsize;
73 u32 nchunks;
74 u8 *cpu_addr;
75 u8 *trace_addr;
76 dma_addr_t dma_addr;
77 bool enabled;
78};
79
80struct iwl_test_mem {
81 u32 size;
82 u32 nchunks;
83 u8 *addr;
84 bool in_read;
85};
86
87/*
88 * struct iwl_test_ops: callback to the op mode
89 *
90 * The structure defines the callbacks that the op_mode should handle,
91 * inorder to handle logic that is out of the scope of iwl_test. The
92 * op_mode must set all the callbacks.
93
94 * @send_cmd: handler that is used by the test object to request the
95 * op_mode to send a command to the fw.
96 *
97 * @valid_hw_addr: handler that is used by the test object to request the
98 * op_mode to check if the given address is a valid address.
99 *
100 * @get_fw_ver: handler used to get the FW version.
101 *
102 * @alloc_reply: handler used by the test object to request the op_mode
103 * to allocate an skb for sending a reply to the user, and initialize
104 * the skb. It is assumed that the test object only fills the required
105 * attributes.
106 *
107 * @reply: handler used by the test object to request the op_mode to reply
108 * to a request. The skb is an skb previously allocated by the the
109 * alloc_reply callback.
110 I
111 * @alloc_event: handler used by the test object to request the op_mode
112 * to allocate an skb for sending an event, and initialize
113 * the skb. It is assumed that the test object only fills the required
114 * attributes.
115 *
116 * @reply: handler used by the test object to request the op_mode to send
117 * an event. The skb is an skb previously allocated by the the
118 * alloc_event callback.
119 */
120struct iwl_test_ops {
121 int (*send_cmd)(struct iwl_op_mode *op_modes,
122 struct iwl_host_cmd *cmd);
123 bool (*valid_hw_addr)(u32 addr);
124 u32 (*get_fw_ver)(struct iwl_op_mode *op_mode);
125
126 struct sk_buff *(*alloc_reply)(struct iwl_op_mode *op_mode, int len);
127 int (*reply)(struct iwl_op_mode *op_mode, struct sk_buff *skb);
128 struct sk_buff* (*alloc_event)(struct iwl_op_mode *op_mode, int len);
129 void (*event)(struct iwl_op_mode *op_mode, struct sk_buff *skb);
130};
131
132struct iwl_test {
133 struct iwl_trans *trans;
134 struct iwl_test_ops *ops;
135 struct iwl_test_trace trace;
136 struct iwl_test_mem mem;
137 bool notify;
138};
139
140void iwl_test_init(struct iwl_test *tst, struct iwl_trans *trans,
141 struct iwl_test_ops *ops);
142
143void iwl_test_free(struct iwl_test *tst);
144
145int iwl_test_parse(struct iwl_test *tst, struct nlattr **tb,
146 void *data, int len);
147
148int iwl_test_handle_cmd(struct iwl_test *tst, struct nlattr **tb);
149
150int iwl_test_dump(struct iwl_test *tst, u32 cmd, struct sk_buff *skb,
151 struct netlink_callback *cb);
152
153void iwl_test_rx(struct iwl_test *tst, struct iwl_rx_cmd_buffer *rxb);
154
155static inline void iwl_test_enable_notifications(struct iwl_test *tst,
156 bool enable)
157{
158 tst->notify = enable;
159}
160
161#endif
diff --git a/drivers/net/wireless/iwlwifi/iwl-testmode.c b/drivers/net/wireless/iwlwifi/iwl-testmode.c
deleted file mode 100644
index 060aac3e22f1..000000000000
--- a/drivers/net/wireless/iwlwifi/iwl-testmode.c
+++ /dev/null
@@ -1,1114 +0,0 @@
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called LICENSE.GPL.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2010 - 2012 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63#include <linux/init.h>
64#include <linux/kernel.h>
65#include <linux/module.h>
66#include <linux/dma-mapping.h>
67#include <net/net_namespace.h>
68#include <linux/netdevice.h>
69#include <net/cfg80211.h>
70#include <net/mac80211.h>
71#include <net/netlink.h>
72
73#include "iwl-dev.h"
74#include "iwl-debug.h"
75#include "iwl-io.h"
76#include "iwl-agn.h"
77#include "iwl-testmode.h"
78#include "iwl-trans.h"
79#include "iwl-fh.h"
80#include "iwl-prph.h"
81
82
83/* Periphery registers absolute lower bound. This is used in order to
84 * differentiate registery access through HBUS_TARG_PRPH_* and
85 * HBUS_TARG_MEM_* accesses.
86 */
87#define IWL_TM_ABS_PRPH_START (0xA00000)
88
89/* The TLVs used in the gnl message policy between the kernel module and
90 * user space application. iwl_testmode_gnl_msg_policy is to be carried
91 * through the NL80211_CMD_TESTMODE channel regulated by nl80211.
92 * See iwl-testmode.h
93 */
94static
95struct nla_policy iwl_testmode_gnl_msg_policy[IWL_TM_ATTR_MAX] = {
96 [IWL_TM_ATTR_COMMAND] = { .type = NLA_U32, },
97
98 [IWL_TM_ATTR_UCODE_CMD_ID] = { .type = NLA_U8, },
99 [IWL_TM_ATTR_UCODE_CMD_DATA] = { .type = NLA_UNSPEC, },
100
101 [IWL_TM_ATTR_REG_OFFSET] = { .type = NLA_U32, },
102 [IWL_TM_ATTR_REG_VALUE8] = { .type = NLA_U8, },
103 [IWL_TM_ATTR_REG_VALUE32] = { .type = NLA_U32, },
104
105 [IWL_TM_ATTR_SYNC_RSP] = { .type = NLA_UNSPEC, },
106 [IWL_TM_ATTR_UCODE_RX_PKT] = { .type = NLA_UNSPEC, },
107
108 [IWL_TM_ATTR_EEPROM] = { .type = NLA_UNSPEC, },
109
110 [IWL_TM_ATTR_TRACE_ADDR] = { .type = NLA_UNSPEC, },
111 [IWL_TM_ATTR_TRACE_DUMP] = { .type = NLA_UNSPEC, },
112 [IWL_TM_ATTR_TRACE_SIZE] = { .type = NLA_U32, },
113
114 [IWL_TM_ATTR_FIXRATE] = { .type = NLA_U32, },
115
116 [IWL_TM_ATTR_UCODE_OWNER] = { .type = NLA_U8, },
117
118 [IWL_TM_ATTR_MEM_ADDR] = { .type = NLA_U32, },
119 [IWL_TM_ATTR_BUFFER_SIZE] = { .type = NLA_U32, },
120 [IWL_TM_ATTR_BUFFER_DUMP] = { .type = NLA_UNSPEC, },
121
122 [IWL_TM_ATTR_FW_VERSION] = { .type = NLA_U32, },
123 [IWL_TM_ATTR_DEVICE_ID] = { .type = NLA_U32, },
124 [IWL_TM_ATTR_FW_TYPE] = { .type = NLA_U32, },
125 [IWL_TM_ATTR_FW_INST_SIZE] = { .type = NLA_U32, },
126 [IWL_TM_ATTR_FW_DATA_SIZE] = { .type = NLA_U32, },
127
128 [IWL_TM_ATTR_ENABLE_NOTIFICATION] = {.type = NLA_FLAG, },
129};
130
131/*
132 * See the struct iwl_rx_packet in iwl-commands.h for the format of the
133 * received events from the device
134 */
135static inline int get_event_length(struct iwl_rx_cmd_buffer *rxb)
136{
137 struct iwl_rx_packet *pkt = rxb_addr(rxb);
138 if (pkt)
139 return le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
140 else
141 return 0;
142}
143
144
145/*
146 * This function multicasts the spontaneous messages from the device to the
147 * user space. It is invoked whenever there is a received messages
148 * from the device. This function is called within the ISR of the rx handlers
149 * in iwlagn driver.
150 *
151 * The parsing of the message content is left to the user space application,
152 * The message content is treated as unattacked raw data and is encapsulated
153 * with IWL_TM_ATTR_UCODE_RX_PKT multicasting to the user space.
154 *
155 * @priv: the instance of iwlwifi device
156 * @rxb: pointer to rx data content received by the ISR
157 *
158 * See the message policies and TLVs in iwl_testmode_gnl_msg_policy[].
159 * For the messages multicasting to the user application, the mandatory
160 * TLV fields are :
161 * IWL_TM_ATTR_COMMAND must be IWL_TM_CMD_DEV2APP_UCODE_RX_PKT
162 * IWL_TM_ATTR_UCODE_RX_PKT for carrying the message content
163 */
164
165static void iwl_testmode_ucode_rx_pkt(struct iwl_priv *priv,
166 struct iwl_rx_cmd_buffer *rxb)
167{
168 struct ieee80211_hw *hw = priv->hw;
169 struct sk_buff *skb;
170 void *data;
171 int length;
172
173 data = (void *)rxb_addr(rxb);
174 length = get_event_length(rxb);
175
176 if (!data || length == 0)
177 return;
178
179 skb = cfg80211_testmode_alloc_event_skb(hw->wiphy, 20 + length,
180 GFP_ATOMIC);
181 if (skb == NULL) {
182 IWL_ERR(priv,
183 "Run out of memory for messages to user space ?\n");
184 return;
185 }
186 if (nla_put_u32(skb, IWL_TM_ATTR_COMMAND, IWL_TM_CMD_DEV2APP_UCODE_RX_PKT) ||
187 /* the length doesn't include len_n_flags field, so add it manually */
188 nla_put(skb, IWL_TM_ATTR_UCODE_RX_PKT, length + sizeof(__le32), data))
189 goto nla_put_failure;
190 cfg80211_testmode_event(skb, GFP_ATOMIC);
191 return;
192
193nla_put_failure:
194 kfree_skb(skb);
195 IWL_ERR(priv, "Ouch, overran buffer, check allocation!\n");
196}
197
198void iwl_testmode_init(struct iwl_priv *priv)
199{
200 priv->pre_rx_handler = NULL;
201 priv->testmode_trace.trace_enabled = false;
202 priv->testmode_mem.read_in_progress = false;
203}
204
205static void iwl_mem_cleanup(struct iwl_priv *priv)
206{
207 if (priv->testmode_mem.read_in_progress) {
208 kfree(priv->testmode_mem.buff_addr);
209 priv->testmode_mem.buff_addr = NULL;
210 priv->testmode_mem.buff_size = 0;
211 priv->testmode_mem.num_chunks = 0;
212 priv->testmode_mem.read_in_progress = false;
213 }
214}
215
216static void iwl_trace_cleanup(struct iwl_priv *priv)
217{
218 if (priv->testmode_trace.trace_enabled) {
219 if (priv->testmode_trace.cpu_addr &&
220 priv->testmode_trace.dma_addr)
221 dma_free_coherent(priv->trans->dev,
222 priv->testmode_trace.total_size,
223 priv->testmode_trace.cpu_addr,
224 priv->testmode_trace.dma_addr);
225 priv->testmode_trace.trace_enabled = false;
226 priv->testmode_trace.cpu_addr = NULL;
227 priv->testmode_trace.trace_addr = NULL;
228 priv->testmode_trace.dma_addr = 0;
229 priv->testmode_trace.buff_size = 0;
230 priv->testmode_trace.total_size = 0;
231 }
232}
233
234
235void iwl_testmode_cleanup(struct iwl_priv *priv)
236{
237 iwl_trace_cleanup(priv);
238 iwl_mem_cleanup(priv);
239}
240
241
242/*
243 * This function handles the user application commands to the ucode.
244 *
245 * It retrieves the mandatory fields IWL_TM_ATTR_UCODE_CMD_ID and
246 * IWL_TM_ATTR_UCODE_CMD_DATA and calls to the handler to send the
247 * host command to the ucode.
248 *
249 * If any mandatory field is missing, -ENOMSG is replied to the user space
250 * application; otherwise, waits for the host command to be sent and checks
251 * the return code. In case or error, it is returned, otherwise a reply is
252 * allocated and the reply RX packet
253 * is returned.
254 *
255 * @hw: ieee80211_hw object that represents the device
256 * @tb: gnl message fields from the user space
257 */
258static int iwl_testmode_ucode(struct ieee80211_hw *hw, struct nlattr **tb)
259{
260 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
261 struct iwl_host_cmd cmd;
262 struct iwl_rx_packet *pkt;
263 struct sk_buff *skb;
264 void *reply_buf;
265 u32 reply_len;
266 int ret;
267 bool cmd_want_skb;
268
269 memset(&cmd, 0, sizeof(struct iwl_host_cmd));
270
271 if (!tb[IWL_TM_ATTR_UCODE_CMD_ID] ||
272 !tb[IWL_TM_ATTR_UCODE_CMD_DATA]) {
273 IWL_ERR(priv, "Missing ucode command mandatory fields\n");
274 return -ENOMSG;
275 }
276
277 cmd.flags = CMD_ON_DEMAND | CMD_SYNC;
278 cmd_want_skb = nla_get_flag(tb[IWL_TM_ATTR_UCODE_CMD_SKB]);
279 if (cmd_want_skb)
280 cmd.flags |= CMD_WANT_SKB;
281
282 cmd.id = nla_get_u8(tb[IWL_TM_ATTR_UCODE_CMD_ID]);
283 cmd.data[0] = nla_data(tb[IWL_TM_ATTR_UCODE_CMD_DATA]);
284 cmd.len[0] = nla_len(tb[IWL_TM_ATTR_UCODE_CMD_DATA]);
285 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
286 IWL_DEBUG_INFO(priv, "testmode ucode command ID 0x%x, flags 0x%x,"
287 " len %d\n", cmd.id, cmd.flags, cmd.len[0]);
288
289 ret = iwl_dvm_send_cmd(priv, &cmd);
290 if (ret) {
291 IWL_ERR(priv, "Failed to send hcmd\n");
292 return ret;
293 }
294 if (!cmd_want_skb)
295 return ret;
296
297 /* Handling return of SKB to the user */
298 pkt = cmd.resp_pkt;
299 if (!pkt) {
300 IWL_ERR(priv, "HCMD received a null response packet\n");
301 return ret;
302 }
303
304 reply_len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
305 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, reply_len + 20);
306 reply_buf = kmalloc(reply_len, GFP_KERNEL);
307 if (!skb || !reply_buf) {
308 kfree_skb(skb);
309 kfree(reply_buf);
310 return -ENOMEM;
311 }
312
313 /* The reply is in a page, that we cannot send to user space. */
314 memcpy(reply_buf, &(pkt->hdr), reply_len);
315 iwl_free_resp(&cmd);
316
317 if (nla_put_u32(skb, IWL_TM_ATTR_COMMAND, IWL_TM_CMD_DEV2APP_UCODE_RX_PKT) ||
318 nla_put(skb, IWL_TM_ATTR_UCODE_RX_PKT, reply_len, reply_buf))
319 goto nla_put_failure;
320 return cfg80211_testmode_reply(skb);
321
322nla_put_failure:
323 IWL_DEBUG_INFO(priv, "Failed creating NL attributes\n");
324 return -ENOMSG;
325}
326
327
328/*
329 * This function handles the user application commands for register access.
330 *
331 * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the
332 * handlers respectively.
333 *
334 * If it's an unknown commdn ID, -ENOSYS is returned; or -ENOMSG if the
335 * mandatory fields(IWL_TM_ATTR_REG_OFFSET,IWL_TM_ATTR_REG_VALUE32,
336 * IWL_TM_ATTR_REG_VALUE8) are missing; Otherwise 0 is replied indicating
337 * the success of the command execution.
338 *
339 * If IWL_TM_ATTR_COMMAND is IWL_TM_CMD_APP2DEV_REG_READ32, the register read
340 * value is returned with IWL_TM_ATTR_REG_VALUE32.
341 *
342 * @hw: ieee80211_hw object that represents the device
343 * @tb: gnl message fields from the user space
344 */
345static int iwl_testmode_reg(struct ieee80211_hw *hw, struct nlattr **tb)
346{
347 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
348 u32 ofs, val32, cmd;
349 u8 val8;
350 struct sk_buff *skb;
351 int status = 0;
352
353 if (!tb[IWL_TM_ATTR_REG_OFFSET]) {
354 IWL_ERR(priv, "Missing register offset\n");
355 return -ENOMSG;
356 }
357 ofs = nla_get_u32(tb[IWL_TM_ATTR_REG_OFFSET]);
358 IWL_INFO(priv, "testmode register access command offset 0x%x\n", ofs);
359
360 /* Allow access only to FH/CSR/HBUS in direct mode.
361 Since we don't have the upper bounds for the CSR and HBUS segments,
362 we will use only the upper bound of FH for sanity check. */
363 cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]);
364 if ((cmd == IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32 ||
365 cmd == IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32 ||
366 cmd == IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8) &&
367 (ofs >= FH_MEM_UPPER_BOUND)) {
368 IWL_ERR(priv, "offset out of segment (0x0 - 0x%x)\n",
369 FH_MEM_UPPER_BOUND);
370 return -EINVAL;
371 }
372
373 switch (cmd) {
374 case IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32:
375 val32 = iwl_read_direct32(priv->trans, ofs);
376 IWL_INFO(priv, "32bit value to read 0x%x\n", val32);
377
378 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20);
379 if (!skb) {
380 IWL_ERR(priv, "Memory allocation fail\n");
381 return -ENOMEM;
382 }
383 if (nla_put_u32(skb, IWL_TM_ATTR_REG_VALUE32, val32))
384 goto nla_put_failure;
385 status = cfg80211_testmode_reply(skb);
386 if (status < 0)
387 IWL_ERR(priv, "Error sending msg : %d\n", status);
388 break;
389 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32:
390 if (!tb[IWL_TM_ATTR_REG_VALUE32]) {
391 IWL_ERR(priv, "Missing value to write\n");
392 return -ENOMSG;
393 } else {
394 val32 = nla_get_u32(tb[IWL_TM_ATTR_REG_VALUE32]);
395 IWL_INFO(priv, "32bit value to write 0x%x\n", val32);
396 iwl_write_direct32(priv->trans, ofs, val32);
397 }
398 break;
399 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8:
400 if (!tb[IWL_TM_ATTR_REG_VALUE8]) {
401 IWL_ERR(priv, "Missing value to write\n");
402 return -ENOMSG;
403 } else {
404 val8 = nla_get_u8(tb[IWL_TM_ATTR_REG_VALUE8]);
405 IWL_INFO(priv, "8bit value to write 0x%x\n", val8);
406 iwl_write8(priv->trans, ofs, val8);
407 }
408 break;
409 default:
410 IWL_ERR(priv, "Unknown testmode register command ID\n");
411 return -ENOSYS;
412 }
413
414 return status;
415
416nla_put_failure:
417 kfree_skb(skb);
418 return -EMSGSIZE;
419}
420
421
422static int iwl_testmode_cfg_init_calib(struct iwl_priv *priv)
423{
424 struct iwl_notification_wait calib_wait;
425 static const u8 calib_complete[] = {
426 CALIBRATION_COMPLETE_NOTIFICATION
427 };
428 int ret;
429
430 iwl_init_notification_wait(&priv->notif_wait, &calib_wait,
431 calib_complete, ARRAY_SIZE(calib_complete),
432 NULL, NULL);
433 ret = iwl_init_alive_start(priv);
434 if (ret) {
435 IWL_ERR(priv, "Fail init calibration: %d\n", ret);
436 goto cfg_init_calib_error;
437 }
438
439 ret = iwl_wait_notification(&priv->notif_wait, &calib_wait, 2 * HZ);
440 if (ret)
441 IWL_ERR(priv, "Error detecting"
442 " CALIBRATION_COMPLETE_NOTIFICATION: %d\n", ret);
443 return ret;
444
445cfg_init_calib_error:
446 iwl_remove_notification(&priv->notif_wait, &calib_wait);
447 return ret;
448}
449
450/*
451 * This function handles the user application commands for driver.
452 *
453 * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the
454 * handlers respectively.
455 *
456 * If it's an unknown commdn ID, -ENOSYS is replied; otherwise, the returned
457 * value of the actual command execution is replied to the user application.
458 *
459 * If there's any message responding to the user space, IWL_TM_ATTR_SYNC_RSP
460 * is used for carry the message while IWL_TM_ATTR_COMMAND must set to
461 * IWL_TM_CMD_DEV2APP_SYNC_RSP.
462 *
463 * @hw: ieee80211_hw object that represents the device
464 * @tb: gnl message fields from the user space
465 */
466static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb)
467{
468 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
469 struct iwl_trans *trans = priv->trans;
470 struct sk_buff *skb;
471 unsigned char *rsp_data_ptr = NULL;
472 int status = 0, rsp_data_len = 0;
473 u32 devid, inst_size = 0, data_size = 0;
474 const struct fw_img *img;
475
476 switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
477 case IWL_TM_CMD_APP2DEV_GET_DEVICENAME:
478 rsp_data_ptr = (unsigned char *)priv->cfg->name;
479 rsp_data_len = strlen(priv->cfg->name);
480 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
481 rsp_data_len + 20);
482 if (!skb) {
483 IWL_ERR(priv, "Memory allocation fail\n");
484 return -ENOMEM;
485 }
486 if (nla_put_u32(skb, IWL_TM_ATTR_COMMAND,
487 IWL_TM_CMD_DEV2APP_SYNC_RSP) ||
488 nla_put(skb, IWL_TM_ATTR_SYNC_RSP,
489 rsp_data_len, rsp_data_ptr))
490 goto nla_put_failure;
491 status = cfg80211_testmode_reply(skb);
492 if (status < 0)
493 IWL_ERR(priv, "Error sending msg : %d\n", status);
494 break;
495
496 case IWL_TM_CMD_APP2DEV_LOAD_INIT_FW:
497 status = iwl_load_ucode_wait_alive(priv, IWL_UCODE_INIT);
498 if (status)
499 IWL_ERR(priv, "Error loading init ucode: %d\n", status);
500 break;
501
502 case IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB:
503 iwl_testmode_cfg_init_calib(priv);
504 priv->ucode_loaded = false;
505 iwl_trans_stop_device(trans);
506 break;
507
508 case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW:
509 status = iwl_load_ucode_wait_alive(priv, IWL_UCODE_REGULAR);
510 if (status) {
511 IWL_ERR(priv,
512 "Error loading runtime ucode: %d\n", status);
513 break;
514 }
515 status = iwl_alive_start(priv);
516 if (status)
517 IWL_ERR(priv,
518 "Error starting the device: %d\n", status);
519 break;
520
521 case IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW:
522 iwl_scan_cancel_timeout(priv, 200);
523 priv->ucode_loaded = false;
524 iwl_trans_stop_device(trans);
525 status = iwl_load_ucode_wait_alive(priv, IWL_UCODE_WOWLAN);
526 if (status) {
527 IWL_ERR(priv,
528 "Error loading WOWLAN ucode: %d\n", status);
529 break;
530 }
531 status = iwl_alive_start(priv);
532 if (status)
533 IWL_ERR(priv,
534 "Error starting the device: %d\n", status);
535 break;
536
537 case IWL_TM_CMD_APP2DEV_GET_EEPROM:
538 if (priv->eeprom) {
539 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
540 priv->cfg->base_params->eeprom_size + 20);
541 if (!skb) {
542 IWL_ERR(priv, "Memory allocation fail\n");
543 return -ENOMEM;
544 }
545 if (nla_put_u32(skb, IWL_TM_ATTR_COMMAND,
546 IWL_TM_CMD_DEV2APP_EEPROM_RSP) ||
547 nla_put(skb, IWL_TM_ATTR_EEPROM,
548 priv->cfg->base_params->eeprom_size,
549 priv->eeprom))
550 goto nla_put_failure;
551 status = cfg80211_testmode_reply(skb);
552 if (status < 0)
553 IWL_ERR(priv, "Error sending msg : %d\n",
554 status);
555 } else
556 return -EFAULT;
557 break;
558
559 case IWL_TM_CMD_APP2DEV_FIXRATE_REQ:
560 if (!tb[IWL_TM_ATTR_FIXRATE]) {
561 IWL_ERR(priv, "Missing fixrate setting\n");
562 return -ENOMSG;
563 }
564 priv->tm_fixed_rate = nla_get_u32(tb[IWL_TM_ATTR_FIXRATE]);
565 break;
566
567 case IWL_TM_CMD_APP2DEV_GET_FW_VERSION:
568 IWL_INFO(priv, "uCode version raw: 0x%x\n",
569 priv->fw->ucode_ver);
570
571 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20);
572 if (!skb) {
573 IWL_ERR(priv, "Memory allocation fail\n");
574 return -ENOMEM;
575 }
576 if (nla_put_u32(skb, IWL_TM_ATTR_FW_VERSION,
577 priv->fw->ucode_ver))
578 goto nla_put_failure;
579 status = cfg80211_testmode_reply(skb);
580 if (status < 0)
581 IWL_ERR(priv, "Error sending msg : %d\n", status);
582 break;
583
584 case IWL_TM_CMD_APP2DEV_GET_DEVICE_ID:
585 devid = priv->trans->hw_id;
586 IWL_INFO(priv, "hw version: 0x%x\n", devid);
587
588 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20);
589 if (!skb) {
590 IWL_ERR(priv, "Memory allocation fail\n");
591 return -ENOMEM;
592 }
593 if (nla_put_u32(skb, IWL_TM_ATTR_DEVICE_ID, devid))
594 goto nla_put_failure;
595 status = cfg80211_testmode_reply(skb);
596 if (status < 0)
597 IWL_ERR(priv, "Error sending msg : %d\n", status);
598 break;
599
600 case IWL_TM_CMD_APP2DEV_GET_FW_INFO:
601 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy, 20 + 8);
602 if (!skb) {
603 IWL_ERR(priv, "Memory allocation fail\n");
604 return -ENOMEM;
605 }
606 if (!priv->ucode_loaded) {
607 IWL_ERR(priv, "No uCode has not been loaded\n");
608 return -EINVAL;
609 } else {
610 img = &priv->fw->img[priv->cur_ucode];
611 inst_size = img->sec[IWL_UCODE_SECTION_INST].len;
612 data_size = img->sec[IWL_UCODE_SECTION_DATA].len;
613 }
614 if (nla_put_u32(skb, IWL_TM_ATTR_FW_TYPE, priv->cur_ucode) ||
615 nla_put_u32(skb, IWL_TM_ATTR_FW_INST_SIZE, inst_size) ||
616 nla_put_u32(skb, IWL_TM_ATTR_FW_DATA_SIZE, data_size))
617 goto nla_put_failure;
618 status = cfg80211_testmode_reply(skb);
619 if (status < 0)
620 IWL_ERR(priv, "Error sending msg : %d\n", status);
621 break;
622
623 default:
624 IWL_ERR(priv, "Unknown testmode driver command ID\n");
625 return -ENOSYS;
626 }
627 return status;
628
629nla_put_failure:
630 kfree_skb(skb);
631 return -EMSGSIZE;
632}
633
634
635/*
636 * This function handles the user application commands for uCode trace
637 *
638 * It retrieves command ID carried with IWL_TM_ATTR_COMMAND and calls to the
639 * handlers respectively.
640 *
641 * If it's an unknown commdn ID, -ENOSYS is replied; otherwise, the returned
642 * value of the actual command execution is replied to the user application.
643 *
644 * @hw: ieee80211_hw object that represents the device
645 * @tb: gnl message fields from the user space
646 */
647static int iwl_testmode_trace(struct ieee80211_hw *hw, struct nlattr **tb)
648{
649 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
650 struct sk_buff *skb;
651 int status = 0;
652 struct device *dev = priv->trans->dev;
653
654 switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
655 case IWL_TM_CMD_APP2DEV_BEGIN_TRACE:
656 if (priv->testmode_trace.trace_enabled)
657 return -EBUSY;
658
659 if (!tb[IWL_TM_ATTR_TRACE_SIZE])
660 priv->testmode_trace.buff_size = TRACE_BUFF_SIZE_DEF;
661 else
662 priv->testmode_trace.buff_size =
663 nla_get_u32(tb[IWL_TM_ATTR_TRACE_SIZE]);
664 if (!priv->testmode_trace.buff_size)
665 return -EINVAL;
666 if (priv->testmode_trace.buff_size < TRACE_BUFF_SIZE_MIN ||
667 priv->testmode_trace.buff_size > TRACE_BUFF_SIZE_MAX)
668 return -EINVAL;
669
670 priv->testmode_trace.total_size =
671 priv->testmode_trace.buff_size + TRACE_BUFF_PADD;
672 priv->testmode_trace.cpu_addr =
673 dma_alloc_coherent(dev,
674 priv->testmode_trace.total_size,
675 &priv->testmode_trace.dma_addr,
676 GFP_KERNEL);
677 if (!priv->testmode_trace.cpu_addr)
678 return -ENOMEM;
679 priv->testmode_trace.trace_enabled = true;
680 priv->testmode_trace.trace_addr = (u8 *)PTR_ALIGN(
681 priv->testmode_trace.cpu_addr, 0x100);
682 memset(priv->testmode_trace.trace_addr, 0x03B,
683 priv->testmode_trace.buff_size);
684 skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
685 sizeof(priv->testmode_trace.dma_addr) + 20);
686 if (!skb) {
687 IWL_ERR(priv, "Memory allocation fail\n");
688 iwl_trace_cleanup(priv);
689 return -ENOMEM;
690 }
691 if (nla_put(skb, IWL_TM_ATTR_TRACE_ADDR,
692 sizeof(priv->testmode_trace.dma_addr),
693 (u64 *)&priv->testmode_trace.dma_addr))
694 goto nla_put_failure;
695 status = cfg80211_testmode_reply(skb);
696 if (status < 0) {
697 IWL_ERR(priv, "Error sending msg : %d\n", status);
698 }
699 priv->testmode_trace.num_chunks =
700 DIV_ROUND_UP(priv->testmode_trace.buff_size,
701 DUMP_CHUNK_SIZE);
702 break;
703
704 case IWL_TM_CMD_APP2DEV_END_TRACE:
705 iwl_trace_cleanup(priv);
706 break;
707 default:
708 IWL_ERR(priv, "Unknown testmode mem command ID\n");
709 return -ENOSYS;
710 }
711 return status;
712
713nla_put_failure:
714 kfree_skb(skb);
715 if (nla_get_u32(tb[IWL_TM_ATTR_COMMAND]) ==
716 IWL_TM_CMD_APP2DEV_BEGIN_TRACE)
717 iwl_trace_cleanup(priv);
718 return -EMSGSIZE;
719}
720
721static int iwl_testmode_trace_dump(struct ieee80211_hw *hw,
722 struct sk_buff *skb,
723 struct netlink_callback *cb)
724{
725 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
726 int idx, length;
727
728 if (priv->testmode_trace.trace_enabled &&
729 priv->testmode_trace.trace_addr) {
730 idx = cb->args[4];
731 if (idx >= priv->testmode_trace.num_chunks)
732 return -ENOENT;
733 length = DUMP_CHUNK_SIZE;
734 if (((idx + 1) == priv->testmode_trace.num_chunks) &&
735 (priv->testmode_trace.buff_size % DUMP_CHUNK_SIZE))
736 length = priv->testmode_trace.buff_size %
737 DUMP_CHUNK_SIZE;
738
739 if (nla_put(skb, IWL_TM_ATTR_TRACE_DUMP, length,
740 priv->testmode_trace.trace_addr +
741 (DUMP_CHUNK_SIZE * idx)))
742 goto nla_put_failure;
743 idx++;
744 cb->args[4] = idx;
745 return 0;
746 } else
747 return -EFAULT;
748
749 nla_put_failure:
750 return -ENOBUFS;
751}
752
753/*
754 * This function handles the user application switch ucode ownership.
755 *
756 * It retrieves the mandatory fields IWL_TM_ATTR_UCODE_OWNER and
757 * decide who the current owner of the uCode
758 *
759 * If the current owner is OWNERSHIP_TM, then the only host command
760 * can deliver to uCode is from testmode, all the other host commands
761 * will dropped.
762 *
763 * default driver is the owner of uCode in normal operational mode
764 *
765 * @hw: ieee80211_hw object that represents the device
766 * @tb: gnl message fields from the user space
767 */
768static int iwl_testmode_ownership(struct ieee80211_hw *hw, struct nlattr **tb)
769{
770 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
771 u8 owner;
772
773 if (!tb[IWL_TM_ATTR_UCODE_OWNER]) {
774 IWL_ERR(priv, "Missing ucode owner\n");
775 return -ENOMSG;
776 }
777
778 owner = nla_get_u8(tb[IWL_TM_ATTR_UCODE_OWNER]);
779 if (owner == IWL_OWNERSHIP_DRIVER) {
780 priv->ucode_owner = owner;
781 priv->pre_rx_handler = NULL;
782 } else if (owner == IWL_OWNERSHIP_TM) {
783 priv->pre_rx_handler = iwl_testmode_ucode_rx_pkt;
784 priv->ucode_owner = owner;
785 } else {
786 IWL_ERR(priv, "Invalid owner\n");
787 return -EINVAL;
788 }
789 return 0;
790}
791
792static int iwl_testmode_indirect_read(struct iwl_priv *priv, u32 addr, u32 size)
793{
794 struct iwl_trans *trans = priv->trans;
795 unsigned long flags;
796 int i;
797
798 if (size & 0x3)
799 return -EINVAL;
800 priv->testmode_mem.buff_size = size;
801 priv->testmode_mem.buff_addr =
802 kmalloc(priv->testmode_mem.buff_size, GFP_KERNEL);
803 if (priv->testmode_mem.buff_addr == NULL)
804 return -ENOMEM;
805
806 /* Hard-coded periphery absolute address */
807 if (IWL_TM_ABS_PRPH_START <= addr &&
808 addr < IWL_TM_ABS_PRPH_START + PRPH_END) {
809 spin_lock_irqsave(&trans->reg_lock, flags);
810 iwl_grab_nic_access(trans);
811 iwl_write32(trans, HBUS_TARG_PRPH_RADDR,
812 addr | (3 << 24));
813 for (i = 0; i < size; i += 4)
814 *(u32 *)(priv->testmode_mem.buff_addr + i) =
815 iwl_read32(trans, HBUS_TARG_PRPH_RDAT);
816 iwl_release_nic_access(trans);
817 spin_unlock_irqrestore(&trans->reg_lock, flags);
818 } else { /* target memory (SRAM) */
819 _iwl_read_targ_mem_words(trans, addr,
820 priv->testmode_mem.buff_addr,
821 priv->testmode_mem.buff_size / 4);
822 }
823
824 priv->testmode_mem.num_chunks =
825 DIV_ROUND_UP(priv->testmode_mem.buff_size, DUMP_CHUNK_SIZE);
826 priv->testmode_mem.read_in_progress = true;
827 return 0;
828
829}
830
831static int iwl_testmode_indirect_write(struct iwl_priv *priv, u32 addr,
832 u32 size, unsigned char *buf)
833{
834 struct iwl_trans *trans = priv->trans;
835 u32 val, i;
836 unsigned long flags;
837
838 if (IWL_TM_ABS_PRPH_START <= addr &&
839 addr < IWL_TM_ABS_PRPH_START + PRPH_END) {
840 /* Periphery writes can be 1-3 bytes long, or DWORDs */
841 if (size < 4) {
842 memcpy(&val, buf, size);
843 spin_lock_irqsave(&trans->reg_lock, flags);
844 iwl_grab_nic_access(trans);
845 iwl_write32(trans, HBUS_TARG_PRPH_WADDR,
846 (addr & 0x0000FFFF) |
847 ((size - 1) << 24));
848 iwl_write32(trans, HBUS_TARG_PRPH_WDAT, val);
849 iwl_release_nic_access(trans);
850 /* needed after consecutive writes w/o read */
851 mmiowb();
852 spin_unlock_irqrestore(&trans->reg_lock, flags);
853 } else {
854 if (size % 4)
855 return -EINVAL;
856 for (i = 0; i < size; i += 4)
857 iwl_write_prph(trans, addr+i,
858 *(u32 *)(buf+i));
859 }
860 } else if (iwlagn_hw_valid_rtc_data_addr(addr) ||
861 (IWLAGN_RTC_INST_LOWER_BOUND <= addr &&
862 addr < IWLAGN_RTC_INST_UPPER_BOUND)) {
863 _iwl_write_targ_mem_words(trans, addr, buf, size/4);
864 } else
865 return -EINVAL;
866 return 0;
867}
868
869/*
870 * This function handles the user application commands for SRAM data dump
871 *
872 * It retrieves the mandatory fields IWL_TM_ATTR_SRAM_ADDR and
873 * IWL_TM_ATTR_SRAM_SIZE to decide the memory area for SRAM data reading
874 *
875 * Several error will be retured, -EBUSY if the SRAM data retrieved by
876 * previous command has not been delivered to userspace, or -ENOMSG if
877 * the mandatory fields (IWL_TM_ATTR_SRAM_ADDR,IWL_TM_ATTR_SRAM_SIZE)
878 * are missing, or -ENOMEM if the buffer allocation fails.
879 *
880 * Otherwise 0 is replied indicating the success of the SRAM reading.
881 *
882 * @hw: ieee80211_hw object that represents the device
883 * @tb: gnl message fields from the user space
884 */
885static int iwl_testmode_indirect_mem(struct ieee80211_hw *hw,
886 struct nlattr **tb)
887{
888 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
889 u32 addr, size, cmd;
890 unsigned char *buf;
891
892 /* Both read and write should be blocked, for atomicity */
893 if (priv->testmode_mem.read_in_progress)
894 return -EBUSY;
895
896 cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]);
897 if (!tb[IWL_TM_ATTR_MEM_ADDR]) {
898 IWL_ERR(priv, "Error finding memory offset address\n");
899 return -ENOMSG;
900 }
901 addr = nla_get_u32(tb[IWL_TM_ATTR_MEM_ADDR]);
902 if (!tb[IWL_TM_ATTR_BUFFER_SIZE]) {
903 IWL_ERR(priv, "Error finding size for memory reading\n");
904 return -ENOMSG;
905 }
906 size = nla_get_u32(tb[IWL_TM_ATTR_BUFFER_SIZE]);
907
908 if (cmd == IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ)
909 return iwl_testmode_indirect_read(priv, addr, size);
910 else {
911 if (!tb[IWL_TM_ATTR_BUFFER_DUMP])
912 return -EINVAL;
913 buf = (unsigned char *) nla_data(tb[IWL_TM_ATTR_BUFFER_DUMP]);
914 return iwl_testmode_indirect_write(priv, addr, size, buf);
915 }
916}
917
918static int iwl_testmode_buffer_dump(struct ieee80211_hw *hw,
919 struct sk_buff *skb,
920 struct netlink_callback *cb)
921{
922 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
923 int idx, length;
924
925 if (priv->testmode_mem.read_in_progress) {
926 idx = cb->args[4];
927 if (idx >= priv->testmode_mem.num_chunks) {
928 iwl_mem_cleanup(priv);
929 return -ENOENT;
930 }
931 length = DUMP_CHUNK_SIZE;
932 if (((idx + 1) == priv->testmode_mem.num_chunks) &&
933 (priv->testmode_mem.buff_size % DUMP_CHUNK_SIZE))
934 length = priv->testmode_mem.buff_size %
935 DUMP_CHUNK_SIZE;
936
937 if (nla_put(skb, IWL_TM_ATTR_BUFFER_DUMP, length,
938 priv->testmode_mem.buff_addr +
939 (DUMP_CHUNK_SIZE * idx)))
940 goto nla_put_failure;
941 idx++;
942 cb->args[4] = idx;
943 return 0;
944 } else
945 return -EFAULT;
946
947 nla_put_failure:
948 return -ENOBUFS;
949}
950
951static int iwl_testmode_notifications(struct ieee80211_hw *hw,
952 struct nlattr **tb)
953{
954 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
955 bool enable;
956
957 enable = nla_get_flag(tb[IWL_TM_ATTR_ENABLE_NOTIFICATION]);
958 if (enable)
959 priv->pre_rx_handler = iwl_testmode_ucode_rx_pkt;
960 else
961 priv->pre_rx_handler = NULL;
962 return 0;
963}
964
965
966/* The testmode gnl message handler that takes the gnl message from the
967 * user space and parses it per the policy iwl_testmode_gnl_msg_policy, then
968 * invoke the corresponding handlers.
969 *
970 * This function is invoked when there is user space application sending
971 * gnl message through the testmode tunnel NL80211_CMD_TESTMODE regulated
972 * by nl80211.
973 *
974 * It retrieves the mandatory field, IWL_TM_ATTR_COMMAND, before
975 * dispatching it to the corresponding handler.
976 *
977 * If IWL_TM_ATTR_COMMAND is missing, -ENOMSG is replied to user application;
978 * -ENOSYS is replied to the user application if the command is unknown;
979 * Otherwise, the command is dispatched to the respective handler.
980 *
981 * @hw: ieee80211_hw object that represents the device
982 * @data: pointer to user space message
983 * @len: length in byte of @data
984 */
985int iwlagn_mac_testmode_cmd(struct ieee80211_hw *hw, void *data, int len)
986{
987 struct nlattr *tb[IWL_TM_ATTR_MAX];
988 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
989 int result;
990
991 result = nla_parse(tb, IWL_TM_ATTR_MAX - 1, data, len,
992 iwl_testmode_gnl_msg_policy);
993 if (result != 0) {
994 IWL_ERR(priv, "Error parsing the gnl message : %d\n", result);
995 return result;
996 }
997
998 /* IWL_TM_ATTR_COMMAND is absolutely mandatory */
999 if (!tb[IWL_TM_ATTR_COMMAND]) {
1000 IWL_ERR(priv, "Missing testmode command type\n");
1001 return -ENOMSG;
1002 }
1003 /* in case multiple accesses to the device happens */
1004 mutex_lock(&priv->mutex);
1005
1006 switch (nla_get_u32(tb[IWL_TM_ATTR_COMMAND])) {
1007 case IWL_TM_CMD_APP2DEV_UCODE:
1008 IWL_DEBUG_INFO(priv, "testmode cmd to uCode\n");
1009 result = iwl_testmode_ucode(hw, tb);
1010 break;
1011 case IWL_TM_CMD_APP2DEV_DIRECT_REG_READ32:
1012 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE32:
1013 case IWL_TM_CMD_APP2DEV_DIRECT_REG_WRITE8:
1014 IWL_DEBUG_INFO(priv, "testmode cmd to register\n");
1015 result = iwl_testmode_reg(hw, tb);
1016 break;
1017 case IWL_TM_CMD_APP2DEV_GET_DEVICENAME:
1018 case IWL_TM_CMD_APP2DEV_LOAD_INIT_FW:
1019 case IWL_TM_CMD_APP2DEV_CFG_INIT_CALIB:
1020 case IWL_TM_CMD_APP2DEV_LOAD_RUNTIME_FW:
1021 case IWL_TM_CMD_APP2DEV_GET_EEPROM:
1022 case IWL_TM_CMD_APP2DEV_FIXRATE_REQ:
1023 case IWL_TM_CMD_APP2DEV_LOAD_WOWLAN_FW:
1024 case IWL_TM_CMD_APP2DEV_GET_FW_VERSION:
1025 case IWL_TM_CMD_APP2DEV_GET_DEVICE_ID:
1026 case IWL_TM_CMD_APP2DEV_GET_FW_INFO:
1027 IWL_DEBUG_INFO(priv, "testmode cmd to driver\n");
1028 result = iwl_testmode_driver(hw, tb);
1029 break;
1030
1031 case IWL_TM_CMD_APP2DEV_BEGIN_TRACE:
1032 case IWL_TM_CMD_APP2DEV_END_TRACE:
1033 case IWL_TM_CMD_APP2DEV_READ_TRACE:
1034 IWL_DEBUG_INFO(priv, "testmode uCode trace cmd to driver\n");
1035 result = iwl_testmode_trace(hw, tb);
1036 break;
1037
1038 case IWL_TM_CMD_APP2DEV_OWNERSHIP:
1039 IWL_DEBUG_INFO(priv, "testmode change uCode ownership\n");
1040 result = iwl_testmode_ownership(hw, tb);
1041 break;
1042
1043 case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_READ:
1044 case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_WRITE:
1045 IWL_DEBUG_INFO(priv, "testmode indirect memory cmd "
1046 "to driver\n");
1047 result = iwl_testmode_indirect_mem(hw, tb);
1048 break;
1049
1050 case IWL_TM_CMD_APP2DEV_NOTIFICATIONS:
1051 IWL_DEBUG_INFO(priv, "testmode notifications cmd "
1052 "to driver\n");
1053 result = iwl_testmode_notifications(hw, tb);
1054 break;
1055
1056 default:
1057 IWL_ERR(priv, "Unknown testmode command\n");
1058 result = -ENOSYS;
1059 break;
1060 }
1061
1062 mutex_unlock(&priv->mutex);
1063 return result;
1064}
1065
1066int iwlagn_mac_testmode_dump(struct ieee80211_hw *hw, struct sk_buff *skb,
1067 struct netlink_callback *cb,
1068 void *data, int len)
1069{
1070 struct nlattr *tb[IWL_TM_ATTR_MAX];
1071 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1072 int result;
1073 u32 cmd;
1074
1075 if (cb->args[3]) {
1076 /* offset by 1 since commands start at 0 */
1077 cmd = cb->args[3] - 1;
1078 } else {
1079 result = nla_parse(tb, IWL_TM_ATTR_MAX - 1, data, len,
1080 iwl_testmode_gnl_msg_policy);
1081 if (result) {
1082 IWL_ERR(priv,
1083 "Error parsing the gnl message : %d\n", result);
1084 return result;
1085 }
1086
1087 /* IWL_TM_ATTR_COMMAND is absolutely mandatory */
1088 if (!tb[IWL_TM_ATTR_COMMAND]) {
1089 IWL_ERR(priv, "Missing testmode command type\n");
1090 return -ENOMSG;
1091 }
1092 cmd = nla_get_u32(tb[IWL_TM_ATTR_COMMAND]);
1093 cb->args[3] = cmd + 1;
1094 }
1095
1096 /* in case multiple accesses to the device happens */
1097 mutex_lock(&priv->mutex);
1098 switch (cmd) {
1099 case IWL_TM_CMD_APP2DEV_READ_TRACE:
1100 IWL_DEBUG_INFO(priv, "uCode trace cmd to driver\n");
1101 result = iwl_testmode_trace_dump(hw, skb, cb);
1102 break;
1103 case IWL_TM_CMD_APP2DEV_INDIRECT_BUFFER_DUMP:
1104 IWL_DEBUG_INFO(priv, "testmode sram dump cmd to driver\n");
1105 result = iwl_testmode_buffer_dump(hw, skb, cb);
1106 break;
1107 default:
1108 result = -EINVAL;
1109 break;
1110 }
1111
1112 mutex_unlock(&priv->mutex);
1113 return result;
1114}
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans.h b/drivers/net/wireless/iwlwifi/iwl-trans.h
index 79a1e7ae4995..00efde8e5536 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans.h
+++ b/drivers/net/wireless/iwlwifi/iwl-trans.h
@@ -154,6 +154,9 @@ struct iwl_cmd_header {
154 __le16 sequence; 154 __le16 sequence;
155} __packed; 155} __packed;
156 156
157/* iwl_cmd_header flags value */
158#define IWL_CMD_FAILED_MSK 0x40
159
157 160
158#define FH_RSCSR_FRAME_SIZE_MSK 0x00003FFF /* bits 0-13 */ 161#define FH_RSCSR_FRAME_SIZE_MSK 0x00003FFF /* bits 0-13 */
159#define FH_RSCSR_FRAME_INVALID 0x55550000 162#define FH_RSCSR_FRAME_INVALID 0x55550000
@@ -280,6 +283,8 @@ static inline struct page *rxb_steal_page(struct iwl_rx_cmd_buffer *r)
280 283
281#define MAX_NO_RECLAIM_CMDS 6 284#define MAX_NO_RECLAIM_CMDS 6
282 285
286#define IWL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
287
283/* 288/*
284 * Maximum number of HW queues the transport layer 289 * Maximum number of HW queues the transport layer
285 * currently supports 290 * currently supports
@@ -350,10 +355,10 @@ struct iwl_trans;
350 * Must be atomic 355 * Must be atomic
351 * @reclaim: free packet until ssn. Returns a list of freed packets. 356 * @reclaim: free packet until ssn. Returns a list of freed packets.
352 * Must be atomic 357 * Must be atomic
353 * @tx_agg_setup: setup a tx queue for AMPDU - will be called once the HW is 358 * @txq_enable: setup a tx queue for AMPDU - will be called once the HW is
354 * ready and a successful ADDBA response has been received. 359 * ready and a successful ADDBA response has been received.
355 * May sleep 360 * May sleep
356 * @tx_agg_disable: de-configure a Tx queue to send AMPDUs 361 * @txq_disable: de-configure a Tx queue to send AMPDUs
357 * Must be atomic 362 * Must be atomic
358 * @wait_tx_queue_empty: wait until all tx queues are empty 363 * @wait_tx_queue_empty: wait until all tx queues are empty
359 * May sleep 364 * May sleep
@@ -386,9 +391,9 @@ struct iwl_trans_ops {
386 void (*reclaim)(struct iwl_trans *trans, int queue, int ssn, 391 void (*reclaim)(struct iwl_trans *trans, int queue, int ssn,
387 struct sk_buff_head *skbs); 392 struct sk_buff_head *skbs);
388 393
389 void (*tx_agg_setup)(struct iwl_trans *trans, int queue, int fifo, 394 void (*txq_enable)(struct iwl_trans *trans, int queue, int fifo,
390 int sta_id, int tid, int frame_limit, u16 ssn); 395 int sta_id, int tid, int frame_limit, u16 ssn);
391 void (*tx_agg_disable)(struct iwl_trans *trans, int queue); 396 void (*txq_disable)(struct iwl_trans *trans, int queue);
392 397
393 int (*dbgfs_register)(struct iwl_trans *trans, struct dentry* dir); 398 int (*dbgfs_register)(struct iwl_trans *trans, struct dentry* dir);
394 int (*wait_tx_queue_empty)(struct iwl_trans *trans); 399 int (*wait_tx_queue_empty)(struct iwl_trans *trans);
@@ -428,6 +433,11 @@ enum iwl_trans_state {
428 * @hw_id_str: a string with info about HW ID. Set during transport allocation. 433 * @hw_id_str: a string with info about HW ID. Set during transport allocation.
429 * @pm_support: set to true in start_hw if link pm is supported 434 * @pm_support: set to true in start_hw if link pm is supported
430 * @wait_command_queue: the wait_queue for SYNC host commands 435 * @wait_command_queue: the wait_queue for SYNC host commands
436 * @dev_cmd_pool: pool for Tx cmd allocation - for internal use only.
437 * The user should use iwl_trans_{alloc,free}_tx_cmd.
438 * @dev_cmd_headroom: room needed for the transport's private use before the
439 * device_cmd for Tx - for internal use only
440 * The user should use iwl_trans_{alloc,free}_tx_cmd.
431 */ 441 */
432struct iwl_trans { 442struct iwl_trans {
433 const struct iwl_trans_ops *ops; 443 const struct iwl_trans_ops *ops;
@@ -445,6 +455,10 @@ struct iwl_trans {
445 455
446 wait_queue_head_t wait_command_queue; 456 wait_queue_head_t wait_command_queue;
447 457
458 /* The following fields are internal only */
459 struct kmem_cache *dev_cmd_pool;
460 size_t dev_cmd_headroom;
461
448 /* pointer to trans specific struct */ 462 /* pointer to trans specific struct */
449 /*Ensure that this pointer will always be aligned to sizeof pointer */ 463 /*Ensure that this pointer will always be aligned to sizeof pointer */
450 char trans_specific[0] __aligned(sizeof(void *)); 464 char trans_specific[0] __aligned(sizeof(void *));
@@ -520,6 +534,26 @@ static inline int iwl_trans_send_cmd(struct iwl_trans *trans,
520 return trans->ops->send_cmd(trans, cmd); 534 return trans->ops->send_cmd(trans, cmd);
521} 535}
522 536
537static inline struct iwl_device_cmd *
538iwl_trans_alloc_tx_cmd(struct iwl_trans *trans)
539{
540 u8 *dev_cmd_ptr = kmem_cache_alloc(trans->dev_cmd_pool, GFP_ATOMIC);
541
542 if (unlikely(dev_cmd_ptr == NULL))
543 return NULL;
544
545 return (struct iwl_device_cmd *)
546 (dev_cmd_ptr + trans->dev_cmd_headroom);
547}
548
549static inline void iwl_trans_free_tx_cmd(struct iwl_trans *trans,
550 struct iwl_device_cmd *dev_cmd)
551{
552 u8 *dev_cmd_ptr = (u8 *)dev_cmd - trans->dev_cmd_headroom;
553
554 kmem_cache_free(trans->dev_cmd_pool, dev_cmd_ptr);
555}
556
523static inline int iwl_trans_tx(struct iwl_trans *trans, struct sk_buff *skb, 557static inline int iwl_trans_tx(struct iwl_trans *trans, struct sk_buff *skb,
524 struct iwl_device_cmd *dev_cmd, int queue) 558 struct iwl_device_cmd *dev_cmd, int queue)
525{ 559{
@@ -538,24 +572,24 @@ static inline void iwl_trans_reclaim(struct iwl_trans *trans, int queue,
538 trans->ops->reclaim(trans, queue, ssn, skbs); 572 trans->ops->reclaim(trans, queue, ssn, skbs);
539} 573}
540 574
541static inline void iwl_trans_tx_agg_disable(struct iwl_trans *trans, int queue) 575static inline void iwl_trans_txq_disable(struct iwl_trans *trans, int queue)
542{ 576{
543 WARN_ONCE(trans->state != IWL_TRANS_FW_ALIVE, 577 WARN_ONCE(trans->state != IWL_TRANS_FW_ALIVE,
544 "%s bad state = %d", __func__, trans->state); 578 "%s bad state = %d", __func__, trans->state);
545 579
546 trans->ops->tx_agg_disable(trans, queue); 580 trans->ops->txq_disable(trans, queue);
547} 581}
548 582
549static inline void iwl_trans_tx_agg_setup(struct iwl_trans *trans, int queue, 583static inline void iwl_trans_txq_enable(struct iwl_trans *trans, int queue,
550 int fifo, int sta_id, int tid, 584 int fifo, int sta_id, int tid,
551 int frame_limit, u16 ssn) 585 int frame_limit, u16 ssn)
552{ 586{
553 might_sleep(); 587 might_sleep();
554 588
555 WARN_ONCE(trans->state != IWL_TRANS_FW_ALIVE, 589 WARN_ONCE(trans->state != IWL_TRANS_FW_ALIVE,
556 "%s bad state = %d", __func__, trans->state); 590 "%s bad state = %d", __func__, trans->state);
557 591
558 trans->ops->tx_agg_setup(trans, queue, fifo, sta_id, tid, 592 trans->ops->txq_enable(trans, queue, fifo, sta_id, tid,
559 frame_limit, ssn); 593 frame_limit, ssn);
560} 594}
561 595
diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/pcie/1000.c
index 2629a6602dfa..81b83f484f08 100644
--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
+++ b/drivers/net/wireless/iwlwifi/pcie/1000.c
@@ -27,9 +27,9 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/stringify.h> 28#include <linux/stringify.h>
29#include "iwl-config.h" 29#include "iwl-config.h"
30#include "iwl-cfg.h"
31#include "iwl-csr.h" 30#include "iwl-csr.h"
32#include "iwl-agn-hw.h" 31#include "iwl-agn-hw.h"
32#include "cfg.h"
33 33
34/* Highest firmware API version supported */ 34/* Highest firmware API version supported */
35#define IWL1000_UCODE_API_MAX 5 35#define IWL1000_UCODE_API_MAX 5
@@ -64,13 +64,26 @@ static const struct iwl_base_params iwl1000_base_params = {
64 .support_ct_kill_exit = true, 64 .support_ct_kill_exit = true,
65 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF, 65 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF,
66 .chain_noise_scale = 1000, 66 .chain_noise_scale = 1000,
67 .wd_timeout = IWL_WATCHHDOG_DISABLED, 67 .wd_timeout = IWL_WATCHDOG_DISABLED,
68 .max_event_log_size = 128, 68 .max_event_log_size = 128,
69}; 69};
70 70
71static const struct iwl_ht_params iwl1000_ht_params = { 71static const struct iwl_ht_params iwl1000_ht_params = {
72 .ht_greenfield_support = true, 72 .ht_greenfield_support = true,
73 .use_rts_for_aggregation = true, /* use rts/cts protection */ 73 .use_rts_for_aggregation = true, /* use rts/cts protection */
74 .ht40_bands = BIT(IEEE80211_BAND_2GHZ),
75};
76
77static const struct iwl_eeprom_params iwl1000_eeprom_params = {
78 .regulatory_bands = {
79 EEPROM_REG_BAND_1_CHANNELS,
80 EEPROM_REG_BAND_2_CHANNELS,
81 EEPROM_REG_BAND_3_CHANNELS,
82 EEPROM_REG_BAND_4_CHANNELS,
83 EEPROM_REG_BAND_5_CHANNELS,
84 EEPROM_REG_BAND_24_HT40_CHANNELS,
85 EEPROM_REGULATORY_BAND_NO_HT40,
86 }
74}; 87};
75 88
76#define IWL_DEVICE_1000 \ 89#define IWL_DEVICE_1000 \
@@ -84,6 +97,7 @@ static const struct iwl_ht_params iwl1000_ht_params = {
84 .eeprom_ver = EEPROM_1000_EEPROM_VERSION, \ 97 .eeprom_ver = EEPROM_1000_EEPROM_VERSION, \
85 .eeprom_calib_ver = EEPROM_1000_TX_POWER_VERSION, \ 98 .eeprom_calib_ver = EEPROM_1000_TX_POWER_VERSION, \
86 .base_params = &iwl1000_base_params, \ 99 .base_params = &iwl1000_base_params, \
100 .eeprom_params = &iwl1000_eeprom_params, \
87 .led_mode = IWL_LED_BLINK 101 .led_mode = IWL_LED_BLINK
88 102
89const struct iwl_cfg iwl1000_bgn_cfg = { 103const struct iwl_cfg iwl1000_bgn_cfg = {
@@ -108,6 +122,7 @@ const struct iwl_cfg iwl1000_bg_cfg = {
108 .eeprom_ver = EEPROM_1000_EEPROM_VERSION, \ 122 .eeprom_ver = EEPROM_1000_EEPROM_VERSION, \
109 .eeprom_calib_ver = EEPROM_1000_TX_POWER_VERSION, \ 123 .eeprom_calib_ver = EEPROM_1000_TX_POWER_VERSION, \
110 .base_params = &iwl1000_base_params, \ 124 .base_params = &iwl1000_base_params, \
125 .eeprom_params = &iwl1000_eeprom_params, \
111 .led_mode = IWL_LED_RF_STATE, \ 126 .led_mode = IWL_LED_RF_STATE, \
112 .rx_with_siso_diversity = true 127 .rx_with_siso_diversity = true
113 128
diff --git a/drivers/net/wireless/iwlwifi/iwl-2000.c b/drivers/net/wireless/iwlwifi/pcie/2000.c
index 8133105ac645..fd4e78f56fa6 100644
--- a/drivers/net/wireless/iwlwifi/iwl-2000.c
+++ b/drivers/net/wireless/iwlwifi/pcie/2000.c
@@ -27,9 +27,9 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/stringify.h> 28#include <linux/stringify.h>
29#include "iwl-config.h" 29#include "iwl-config.h"
30#include "iwl-cfg.h"
31#include "iwl-agn-hw.h" 30#include "iwl-agn-hw.h"
32#include "iwl-commands.h" /* needed for BT for now */ 31#include "cfg.h"
32#include "dvm/commands.h" /* needed for BT for now */
33 33
34/* Highest firmware API version supported */ 34/* Highest firmware API version supported */
35#define IWL2030_UCODE_API_MAX 6 35#define IWL2030_UCODE_API_MAX 6
@@ -104,6 +104,7 @@ static const struct iwl_base_params iwl2030_base_params = {
104static const struct iwl_ht_params iwl2000_ht_params = { 104static const struct iwl_ht_params iwl2000_ht_params = {
105 .ht_greenfield_support = true, 105 .ht_greenfield_support = true,
106 .use_rts_for_aggregation = true, /* use rts/cts protection */ 106 .use_rts_for_aggregation = true, /* use rts/cts protection */
107 .ht40_bands = BIT(IEEE80211_BAND_2GHZ),
107}; 108};
108 109
109static const struct iwl_bt_params iwl2030_bt_params = { 110static const struct iwl_bt_params iwl2030_bt_params = {
@@ -116,6 +117,19 @@ static const struct iwl_bt_params iwl2030_bt_params = {
116 .bt_session_2 = true, 117 .bt_session_2 = true,
117}; 118};
118 119
120static const struct iwl_eeprom_params iwl20x0_eeprom_params = {
121 .regulatory_bands = {
122 EEPROM_REG_BAND_1_CHANNELS,
123 EEPROM_REG_BAND_2_CHANNELS,
124 EEPROM_REG_BAND_3_CHANNELS,
125 EEPROM_REG_BAND_4_CHANNELS,
126 EEPROM_REG_BAND_5_CHANNELS,
127 EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
128 EEPROM_REGULATORY_BAND_NO_HT40,
129 },
130 .enhanced_txpower = true,
131};
132
119#define IWL_DEVICE_2000 \ 133#define IWL_DEVICE_2000 \
120 .fw_name_pre = IWL2000_FW_PRE, \ 134 .fw_name_pre = IWL2000_FW_PRE, \
121 .ucode_api_max = IWL2000_UCODE_API_MAX, \ 135 .ucode_api_max = IWL2000_UCODE_API_MAX, \
@@ -127,6 +141,7 @@ static const struct iwl_bt_params iwl2030_bt_params = {
127 .eeprom_ver = EEPROM_2000_EEPROM_VERSION, \ 141 .eeprom_ver = EEPROM_2000_EEPROM_VERSION, \
128 .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION, \ 142 .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION, \
129 .base_params = &iwl2000_base_params, \ 143 .base_params = &iwl2000_base_params, \
144 .eeprom_params = &iwl20x0_eeprom_params, \
130 .need_temp_offset_calib = true, \ 145 .need_temp_offset_calib = true, \
131 .temp_offset_v2 = true, \ 146 .temp_offset_v2 = true, \
132 .led_mode = IWL_LED_RF_STATE 147 .led_mode = IWL_LED_RF_STATE
@@ -155,6 +170,7 @@ const struct iwl_cfg iwl2000_2bgn_d_cfg = {
155 .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION, \ 170 .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION, \
156 .base_params = &iwl2030_base_params, \ 171 .base_params = &iwl2030_base_params, \
157 .bt_params = &iwl2030_bt_params, \ 172 .bt_params = &iwl2030_bt_params, \
173 .eeprom_params = &iwl20x0_eeprom_params, \
158 .need_temp_offset_calib = true, \ 174 .need_temp_offset_calib = true, \
159 .temp_offset_v2 = true, \ 175 .temp_offset_v2 = true, \
160 .led_mode = IWL_LED_RF_STATE, \ 176 .led_mode = IWL_LED_RF_STATE, \
@@ -177,6 +193,7 @@ const struct iwl_cfg iwl2030_2bgn_cfg = {
177 .eeprom_ver = EEPROM_2000_EEPROM_VERSION, \ 193 .eeprom_ver = EEPROM_2000_EEPROM_VERSION, \
178 .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION, \ 194 .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION, \
179 .base_params = &iwl2000_base_params, \ 195 .base_params = &iwl2000_base_params, \
196 .eeprom_params = &iwl20x0_eeprom_params, \
180 .need_temp_offset_calib = true, \ 197 .need_temp_offset_calib = true, \
181 .temp_offset_v2 = true, \ 198 .temp_offset_v2 = true, \
182 .led_mode = IWL_LED_RF_STATE, \ 199 .led_mode = IWL_LED_RF_STATE, \
@@ -207,6 +224,7 @@ const struct iwl_cfg iwl105_bgn_d_cfg = {
207 .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION, \ 224 .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION, \
208 .base_params = &iwl2030_base_params, \ 225 .base_params = &iwl2030_base_params, \
209 .bt_params = &iwl2030_bt_params, \ 226 .bt_params = &iwl2030_bt_params, \
227 .eeprom_params = &iwl20x0_eeprom_params, \
210 .need_temp_offset_calib = true, \ 228 .need_temp_offset_calib = true, \
211 .temp_offset_v2 = true, \ 229 .temp_offset_v2 = true, \
212 .led_mode = IWL_LED_RF_STATE, \ 230 .led_mode = IWL_LED_RF_STATE, \
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/pcie/5000.c
index 8e26bc825f23..d1665fa6d15a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/pcie/5000.c
@@ -27,9 +27,9 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/stringify.h> 28#include <linux/stringify.h>
29#include "iwl-config.h" 29#include "iwl-config.h"
30#include "iwl-cfg.h"
31#include "iwl-agn-hw.h" 30#include "iwl-agn-hw.h"
32#include "iwl-csr.h" 31#include "iwl-csr.h"
32#include "cfg.h"
33 33
34/* Highest firmware API version supported */ 34/* Highest firmware API version supported */
35#define IWL5000_UCODE_API_MAX 5 35#define IWL5000_UCODE_API_MAX 5
@@ -62,13 +62,26 @@ static const struct iwl_base_params iwl5000_base_params = {
62 .led_compensation = 51, 62 .led_compensation = 51,
63 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, 63 .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
64 .chain_noise_scale = 1000, 64 .chain_noise_scale = 1000,
65 .wd_timeout = IWL_WATCHHDOG_DISABLED, 65 .wd_timeout = IWL_WATCHDOG_DISABLED,
66 .max_event_log_size = 512, 66 .max_event_log_size = 512,
67 .no_idle_support = true, 67 .no_idle_support = true,
68}; 68};
69 69
70static const struct iwl_ht_params iwl5000_ht_params = { 70static const struct iwl_ht_params iwl5000_ht_params = {
71 .ht_greenfield_support = true, 71 .ht_greenfield_support = true,
72 .ht40_bands = BIT(IEEE80211_BAND_2GHZ) | BIT(IEEE80211_BAND_5GHZ),
73};
74
75static const struct iwl_eeprom_params iwl5000_eeprom_params = {
76 .regulatory_bands = {
77 EEPROM_REG_BAND_1_CHANNELS,
78 EEPROM_REG_BAND_2_CHANNELS,
79 EEPROM_REG_BAND_3_CHANNELS,
80 EEPROM_REG_BAND_4_CHANNELS,
81 EEPROM_REG_BAND_5_CHANNELS,
82 EEPROM_REG_BAND_24_HT40_CHANNELS,
83 EEPROM_REG_BAND_52_HT40_CHANNELS
84 },
72}; 85};
73 86
74#define IWL_DEVICE_5000 \ 87#define IWL_DEVICE_5000 \
@@ -82,6 +95,7 @@ static const struct iwl_ht_params iwl5000_ht_params = {
82 .eeprom_ver = EEPROM_5000_EEPROM_VERSION, \ 95 .eeprom_ver = EEPROM_5000_EEPROM_VERSION, \
83 .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION, \ 96 .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION, \
84 .base_params = &iwl5000_base_params, \ 97 .base_params = &iwl5000_base_params, \
98 .eeprom_params = &iwl5000_eeprom_params, \
85 .led_mode = IWL_LED_BLINK 99 .led_mode = IWL_LED_BLINK
86 100
87const struct iwl_cfg iwl5300_agn_cfg = { 101const struct iwl_cfg iwl5300_agn_cfg = {
@@ -128,6 +142,7 @@ const struct iwl_cfg iwl5350_agn_cfg = {
128 .eeprom_ver = EEPROM_5050_EEPROM_VERSION, 142 .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
129 .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION, 143 .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
130 .base_params = &iwl5000_base_params, 144 .base_params = &iwl5000_base_params,
145 .eeprom_params = &iwl5000_eeprom_params,
131 .ht_params = &iwl5000_ht_params, 146 .ht_params = &iwl5000_ht_params,
132 .led_mode = IWL_LED_BLINK, 147 .led_mode = IWL_LED_BLINK,
133 .internal_wimax_coex = true, 148 .internal_wimax_coex = true,
@@ -144,6 +159,7 @@ const struct iwl_cfg iwl5350_agn_cfg = {
144 .eeprom_ver = EEPROM_5050_EEPROM_VERSION, \ 159 .eeprom_ver = EEPROM_5050_EEPROM_VERSION, \
145 .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION, \ 160 .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION, \
146 .base_params = &iwl5000_base_params, \ 161 .base_params = &iwl5000_base_params, \
162 .eeprom_params = &iwl5000_eeprom_params, \
147 .no_xtal_calib = true, \ 163 .no_xtal_calib = true, \
148 .led_mode = IWL_LED_BLINK, \ 164 .led_mode = IWL_LED_BLINK, \
149 .internal_wimax_coex = true 165 .internal_wimax_coex = true
diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/pcie/6000.c
index e5e8ada4aaf6..4a57624afc40 100644
--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
+++ b/drivers/net/wireless/iwlwifi/pcie/6000.c
@@ -27,9 +27,9 @@
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/stringify.h> 28#include <linux/stringify.h>
29#include "iwl-config.h" 29#include "iwl-config.h"
30#include "iwl-cfg.h"
31#include "iwl-agn-hw.h" 30#include "iwl-agn-hw.h"
32#include "iwl-commands.h" /* needed for BT for now */ 31#include "cfg.h"
32#include "dvm/commands.h" /* needed for BT for now */
33 33
34/* Highest firmware API version supported */ 34/* Highest firmware API version supported */
35#define IWL6000_UCODE_API_MAX 6 35#define IWL6000_UCODE_API_MAX 6
@@ -127,6 +127,7 @@ static const struct iwl_base_params iwl6000_g2_base_params = {
127static const struct iwl_ht_params iwl6000_ht_params = { 127static const struct iwl_ht_params iwl6000_ht_params = {
128 .ht_greenfield_support = true, 128 .ht_greenfield_support = true,
129 .use_rts_for_aggregation = true, /* use rts/cts protection */ 129 .use_rts_for_aggregation = true, /* use rts/cts protection */
130 .ht40_bands = BIT(IEEE80211_BAND_2GHZ) | BIT(IEEE80211_BAND_5GHZ),
130}; 131};
131 132
132static const struct iwl_bt_params iwl6000_bt_params = { 133static const struct iwl_bt_params iwl6000_bt_params = {
@@ -138,6 +139,19 @@ static const struct iwl_bt_params iwl6000_bt_params = {
138 .bt_sco_disable = true, 139 .bt_sco_disable = true,
139}; 140};
140 141
142static const struct iwl_eeprom_params iwl6000_eeprom_params = {
143 .regulatory_bands = {
144 EEPROM_REG_BAND_1_CHANNELS,
145 EEPROM_REG_BAND_2_CHANNELS,
146 EEPROM_REG_BAND_3_CHANNELS,
147 EEPROM_REG_BAND_4_CHANNELS,
148 EEPROM_REG_BAND_5_CHANNELS,
149 EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
150 EEPROM_REG_BAND_52_HT40_CHANNELS
151 },
152 .enhanced_txpower = true,
153};
154
141#define IWL_DEVICE_6005 \ 155#define IWL_DEVICE_6005 \
142 .fw_name_pre = IWL6005_FW_PRE, \ 156 .fw_name_pre = IWL6005_FW_PRE, \
143 .ucode_api_max = IWL6000G2_UCODE_API_MAX, \ 157 .ucode_api_max = IWL6000G2_UCODE_API_MAX, \
@@ -149,6 +163,7 @@ static const struct iwl_bt_params iwl6000_bt_params = {
149 .eeprom_ver = EEPROM_6005_EEPROM_VERSION, \ 163 .eeprom_ver = EEPROM_6005_EEPROM_VERSION, \
150 .eeprom_calib_ver = EEPROM_6005_TX_POWER_VERSION, \ 164 .eeprom_calib_ver = EEPROM_6005_TX_POWER_VERSION, \
151 .base_params = &iwl6000_g2_base_params, \ 165 .base_params = &iwl6000_g2_base_params, \
166 .eeprom_params = &iwl6000_eeprom_params, \
152 .need_temp_offset_calib = true, \ 167 .need_temp_offset_calib = true, \
153 .led_mode = IWL_LED_RF_STATE 168 .led_mode = IWL_LED_RF_STATE
154 169
@@ -204,6 +219,7 @@ const struct iwl_cfg iwl6005_2agn_mow2_cfg = {
204 .eeprom_calib_ver = EEPROM_6030_TX_POWER_VERSION, \ 219 .eeprom_calib_ver = EEPROM_6030_TX_POWER_VERSION, \
205 .base_params = &iwl6000_g2_base_params, \ 220 .base_params = &iwl6000_g2_base_params, \
206 .bt_params = &iwl6000_bt_params, \ 221 .bt_params = &iwl6000_bt_params, \
222 .eeprom_params = &iwl6000_eeprom_params, \
207 .need_temp_offset_calib = true, \ 223 .need_temp_offset_calib = true, \
208 .led_mode = IWL_LED_RF_STATE, \ 224 .led_mode = IWL_LED_RF_STATE, \
209 .adv_pm = true \ 225 .adv_pm = true \
@@ -242,6 +258,7 @@ const struct iwl_cfg iwl6030_2bg_cfg = {
242 .eeprom_calib_ver = EEPROM_6030_TX_POWER_VERSION, \ 258 .eeprom_calib_ver = EEPROM_6030_TX_POWER_VERSION, \
243 .base_params = &iwl6000_g2_base_params, \ 259 .base_params = &iwl6000_g2_base_params, \
244 .bt_params = &iwl6000_bt_params, \ 260 .bt_params = &iwl6000_bt_params, \
261 .eeprom_params = &iwl6000_eeprom_params, \
245 .need_temp_offset_calib = true, \ 262 .need_temp_offset_calib = true, \
246 .led_mode = IWL_LED_RF_STATE, \ 263 .led_mode = IWL_LED_RF_STATE, \
247 .adv_pm = true 264 .adv_pm = true
@@ -292,6 +309,7 @@ const struct iwl_cfg iwl130_bg_cfg = {
292 .eeprom_ver = EEPROM_6000_EEPROM_VERSION, \ 309 .eeprom_ver = EEPROM_6000_EEPROM_VERSION, \
293 .eeprom_calib_ver = EEPROM_6000_TX_POWER_VERSION, \ 310 .eeprom_calib_ver = EEPROM_6000_TX_POWER_VERSION, \
294 .base_params = &iwl6000_base_params, \ 311 .base_params = &iwl6000_base_params, \
312 .eeprom_params = &iwl6000_eeprom_params, \
295 .led_mode = IWL_LED_BLINK 313 .led_mode = IWL_LED_BLINK
296 314
297const struct iwl_cfg iwl6000i_2agn_cfg = { 315const struct iwl_cfg iwl6000i_2agn_cfg = {
@@ -322,6 +340,7 @@ const struct iwl_cfg iwl6000i_2bg_cfg = {
322 .eeprom_ver = EEPROM_6050_EEPROM_VERSION, \ 340 .eeprom_ver = EEPROM_6050_EEPROM_VERSION, \
323 .eeprom_calib_ver = EEPROM_6050_TX_POWER_VERSION, \ 341 .eeprom_calib_ver = EEPROM_6050_TX_POWER_VERSION, \
324 .base_params = &iwl6050_base_params, \ 342 .base_params = &iwl6050_base_params, \
343 .eeprom_params = &iwl6000_eeprom_params, \
325 .led_mode = IWL_LED_BLINK, \ 344 .led_mode = IWL_LED_BLINK, \
326 .internal_wimax_coex = true 345 .internal_wimax_coex = true
327 346
@@ -346,6 +365,7 @@ const struct iwl_cfg iwl6050_2abg_cfg = {
346 .eeprom_ver = EEPROM_6150_EEPROM_VERSION, \ 365 .eeprom_ver = EEPROM_6150_EEPROM_VERSION, \
347 .eeprom_calib_ver = EEPROM_6150_TX_POWER_VERSION, \ 366 .eeprom_calib_ver = EEPROM_6150_TX_POWER_VERSION, \
348 .base_params = &iwl6050_base_params, \ 367 .base_params = &iwl6050_base_params, \
368 .eeprom_params = &iwl6000_eeprom_params, \
349 .led_mode = IWL_LED_BLINK, \ 369 .led_mode = IWL_LED_BLINK, \
350 .internal_wimax_coex = true 370 .internal_wimax_coex = true
351 371
@@ -372,6 +392,7 @@ const struct iwl_cfg iwl6000_3agn_cfg = {
372 .eeprom_ver = EEPROM_6000_EEPROM_VERSION, 392 .eeprom_ver = EEPROM_6000_EEPROM_VERSION,
373 .eeprom_calib_ver = EEPROM_6000_TX_POWER_VERSION, 393 .eeprom_calib_ver = EEPROM_6000_TX_POWER_VERSION,
374 .base_params = &iwl6000_base_params, 394 .base_params = &iwl6000_base_params,
395 .eeprom_params = &iwl6000_eeprom_params,
375 .ht_params = &iwl6000_ht_params, 396 .ht_params = &iwl6000_ht_params,
376 .led_mode = IWL_LED_BLINK, 397 .led_mode = IWL_LED_BLINK,
377}; 398};
diff --git a/drivers/net/wireless/iwlwifi/iwl-cfg.h b/drivers/net/wireless/iwlwifi/pcie/cfg.h
index 82152311d73b..82152311d73b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-cfg.h
+++ b/drivers/net/wireless/iwlwifi/pcie/cfg.h
diff --git a/drivers/net/wireless/iwlwifi/iwl-pci.c b/drivers/net/wireless/iwlwifi/pcie/drv.c
index 0c8a1c2d8847..f4c3500b68c6 100644
--- a/drivers/net/wireless/iwlwifi/iwl-pci.c
+++ b/drivers/net/wireless/iwlwifi/pcie/drv.c
@@ -68,10 +68,11 @@
68#include <linux/pci-aspm.h> 68#include <linux/pci-aspm.h>
69 69
70#include "iwl-trans.h" 70#include "iwl-trans.h"
71#include "iwl-cfg.h"
72#include "iwl-drv.h" 71#include "iwl-drv.h"
73#include "iwl-trans.h" 72#include "iwl-trans.h"
74#include "iwl-trans-pcie-int.h" 73
74#include "cfg.h"
75#include "internal.h"
75 76
76#define IWL_PCI_DEVICE(dev, subdev, cfg) \ 77#define IWL_PCI_DEVICE(dev, subdev, cfg) \
77 .vendor = PCI_VENDOR_ID_INTEL, .device = (dev), \ 78 .vendor = PCI_VENDOR_ID_INTEL, .device = (dev), \
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-int.h b/drivers/net/wireless/iwlwifi/pcie/internal.h
index e959207c630a..5024fb662bf6 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-int.h
+++ b/drivers/net/wireless/iwlwifi/pcie/internal.h
@@ -313,7 +313,7 @@ void iwl_bg_rx_replenish(struct work_struct *data);
313void iwl_irq_tasklet(struct iwl_trans *trans); 313void iwl_irq_tasklet(struct iwl_trans *trans);
314void iwlagn_rx_replenish(struct iwl_trans *trans); 314void iwlagn_rx_replenish(struct iwl_trans *trans);
315void iwl_rx_queue_update_write_ptr(struct iwl_trans *trans, 315void iwl_rx_queue_update_write_ptr(struct iwl_trans *trans,
316 struct iwl_rx_queue *q); 316 struct iwl_rx_queue *q);
317 317
318/***************************************************** 318/*****************************************************
319* ICT 319* ICT
@@ -328,7 +328,7 @@ irqreturn_t iwl_isr_ict(int irq, void *data);
328* TX / HCMD 328* TX / HCMD
329******************************************************/ 329******************************************************/
330void iwl_txq_update_write_ptr(struct iwl_trans *trans, 330void iwl_txq_update_write_ptr(struct iwl_trans *trans,
331 struct iwl_tx_queue *txq); 331 struct iwl_tx_queue *txq);
332int iwlagn_txq_attach_buf_to_tfd(struct iwl_trans *trans, 332int iwlagn_txq_attach_buf_to_tfd(struct iwl_trans *trans,
333 struct iwl_tx_queue *txq, 333 struct iwl_tx_queue *txq,
334 dma_addr_t addr, u16 len, u8 reset); 334 dma_addr_t addr, u16 len, u8 reset);
@@ -337,17 +337,13 @@ int iwl_trans_pcie_send_cmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd);
337void iwl_tx_cmd_complete(struct iwl_trans *trans, 337void iwl_tx_cmd_complete(struct iwl_trans *trans,
338 struct iwl_rx_cmd_buffer *rxb, int handler_status); 338 struct iwl_rx_cmd_buffer *rxb, int handler_status);
339void iwl_trans_txq_update_byte_cnt_tbl(struct iwl_trans *trans, 339void iwl_trans_txq_update_byte_cnt_tbl(struct iwl_trans *trans,
340 struct iwl_tx_queue *txq, 340 struct iwl_tx_queue *txq,
341 u16 byte_cnt); 341 u16 byte_cnt);
342void iwl_trans_pcie_tx_agg_disable(struct iwl_trans *trans, int queue); 342void iwl_trans_pcie_txq_enable(struct iwl_trans *trans, int txq_id, int fifo,
343void iwl_trans_set_wr_ptrs(struct iwl_trans *trans, int txq_id, u32 index); 343 int sta_id, int tid, int frame_limit, u16 ssn);
344void iwl_trans_tx_queue_set_status(struct iwl_trans *trans, 344void iwl_trans_pcie_txq_disable(struct iwl_trans *trans, int queue);
345 struct iwl_tx_queue *txq, 345void iwl_txq_free_tfd(struct iwl_trans *trans, struct iwl_tx_queue *txq,
346 int tx_fifo_id, bool active); 346 enum dma_data_direction dma_dir);
347void iwl_trans_pcie_tx_agg_setup(struct iwl_trans *trans, int queue, int fifo,
348 int sta_id, int tid, int frame_limit, u16 ssn);
349void iwlagn_txq_free_tfd(struct iwl_trans *trans, struct iwl_tx_queue *txq,
350 enum dma_data_direction dma_dir);
351int iwl_tx_queue_reclaim(struct iwl_trans *trans, int txq_id, int index, 347int iwl_tx_queue_reclaim(struct iwl_trans *trans, int txq_id, int index,
352 struct sk_buff_head *skbs); 348 struct sk_buff_head *skbs);
353int iwl_queue_space(const struct iwl_queue *q); 349int iwl_queue_space(const struct iwl_queue *q);
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c b/drivers/net/wireless/iwlwifi/pcie/rx.c
index 08517d3c80bb..d6860c070c16 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c
+++ b/drivers/net/wireless/iwlwifi/pcie/rx.c
@@ -32,7 +32,7 @@
32 32
33#include "iwl-prph.h" 33#include "iwl-prph.h"
34#include "iwl-io.h" 34#include "iwl-io.h"
35#include "iwl-trans-pcie-int.h" 35#include "internal.h"
36#include "iwl-op-mode.h" 36#include "iwl-op-mode.h"
37 37
38#ifdef CONFIG_IWLWIFI_IDI 38#ifdef CONFIG_IWLWIFI_IDI
@@ -130,7 +130,7 @@ static int iwl_rx_queue_space(const struct iwl_rx_queue *q)
130 * iwl_rx_queue_update_write_ptr - Update the write pointer for the RX queue 130 * iwl_rx_queue_update_write_ptr - Update the write pointer for the RX queue
131 */ 131 */
132void iwl_rx_queue_update_write_ptr(struct iwl_trans *trans, 132void iwl_rx_queue_update_write_ptr(struct iwl_trans *trans,
133 struct iwl_rx_queue *q) 133 struct iwl_rx_queue *q)
134{ 134{
135 unsigned long flags; 135 unsigned long flags;
136 u32 reg; 136 u32 reg;
@@ -201,9 +201,7 @@ static inline __le32 iwlagn_dma_addr2rbd_ptr(dma_addr_t dma_addr)
201 */ 201 */
202static void iwlagn_rx_queue_restock(struct iwl_trans *trans) 202static void iwlagn_rx_queue_restock(struct iwl_trans *trans)
203{ 203{
204 struct iwl_trans_pcie *trans_pcie = 204 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
205 IWL_TRANS_GET_PCIE_TRANS(trans);
206
207 struct iwl_rx_queue *rxq = &trans_pcie->rxq; 205 struct iwl_rx_queue *rxq = &trans_pcie->rxq;
208 struct list_head *element; 206 struct list_head *element;
209 struct iwl_rx_mem_buffer *rxb; 207 struct iwl_rx_mem_buffer *rxb;
@@ -253,9 +251,7 @@ static void iwlagn_rx_queue_restock(struct iwl_trans *trans)
253 */ 251 */
254static void iwlagn_rx_allocate(struct iwl_trans *trans, gfp_t priority) 252static void iwlagn_rx_allocate(struct iwl_trans *trans, gfp_t priority)
255{ 253{
256 struct iwl_trans_pcie *trans_pcie = 254 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
257 IWL_TRANS_GET_PCIE_TRANS(trans);
258
259 struct iwl_rx_queue *rxq = &trans_pcie->rxq; 255 struct iwl_rx_queue *rxq = &trans_pcie->rxq;
260 struct list_head *element; 256 struct list_head *element;
261 struct iwl_rx_mem_buffer *rxb; 257 struct iwl_rx_mem_buffer *rxb;
@@ -278,8 +274,7 @@ static void iwlagn_rx_allocate(struct iwl_trans *trans, gfp_t priority)
278 gfp_mask |= __GFP_COMP; 274 gfp_mask |= __GFP_COMP;
279 275
280 /* Alloc a new receive buffer */ 276 /* Alloc a new receive buffer */
281 page = alloc_pages(gfp_mask, 277 page = alloc_pages(gfp_mask, trans_pcie->rx_page_order);
282 trans_pcie->rx_page_order);
283 if (!page) { 278 if (!page) {
284 if (net_ratelimit()) 279 if (net_ratelimit())
285 IWL_DEBUG_INFO(trans, "alloc_pages failed, " 280 IWL_DEBUG_INFO(trans, "alloc_pages failed, "
@@ -315,9 +310,10 @@ static void iwlagn_rx_allocate(struct iwl_trans *trans, gfp_t priority)
315 BUG_ON(rxb->page); 310 BUG_ON(rxb->page);
316 rxb->page = page; 311 rxb->page = page;
317 /* Get physical address of the RB */ 312 /* Get physical address of the RB */
318 rxb->page_dma = dma_map_page(trans->dev, page, 0, 313 rxb->page_dma =
319 PAGE_SIZE << trans_pcie->rx_page_order, 314 dma_map_page(trans->dev, page, 0,
320 DMA_FROM_DEVICE); 315 PAGE_SIZE << trans_pcie->rx_page_order,
316 DMA_FROM_DEVICE);
321 /* dma address must be no more than 36 bits */ 317 /* dma address must be no more than 36 bits */
322 BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36)); 318 BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36));
323 /* and also 256 byte aligned! */ 319 /* and also 256 byte aligned! */
@@ -465,8 +461,8 @@ static void iwl_rx_handle_rxbuf(struct iwl_trans *trans,
465 if (rxb->page != NULL) { 461 if (rxb->page != NULL) {
466 rxb->page_dma = 462 rxb->page_dma =
467 dma_map_page(trans->dev, rxb->page, 0, 463 dma_map_page(trans->dev, rxb->page, 0,
468 PAGE_SIZE << trans_pcie->rx_page_order, 464 PAGE_SIZE << trans_pcie->rx_page_order,
469 DMA_FROM_DEVICE); 465 DMA_FROM_DEVICE);
470 list_add_tail(&rxb->list, &rxq->rx_free); 466 list_add_tail(&rxb->list, &rxq->rx_free);
471 rxq->free_count++; 467 rxq->free_count++;
472 } else 468 } else
@@ -497,7 +493,7 @@ static void iwl_rx_handle(struct iwl_trans *trans)
497 493
498 /* Rx interrupt, but nothing sent from uCode */ 494 /* Rx interrupt, but nothing sent from uCode */
499 if (i == r) 495 if (i == r)
500 IWL_DEBUG_RX(trans, "r = %d, i = %d\n", r, i); 496 IWL_DEBUG_RX(trans, "HW = SW = %d\n", r);
501 497
502 /* calculate total frames need to be restock after handling RX */ 498 /* calculate total frames need to be restock after handling RX */
503 total_empty = r - rxq->write_actual; 499 total_empty = r - rxq->write_actual;
@@ -513,8 +509,8 @@ static void iwl_rx_handle(struct iwl_trans *trans)
513 rxb = rxq->queue[i]; 509 rxb = rxq->queue[i];
514 rxq->queue[i] = NULL; 510 rxq->queue[i] = NULL;
515 511
516 IWL_DEBUG_RX(trans, "rxbuf: r = %d, i = %d (%p)\n", rxb); 512 IWL_DEBUG_RX(trans, "rxbuf: HW = %d, SW = %d (%p)\n",
517 513 r, i, rxb);
518 iwl_rx_handle_rxbuf(trans, rxb); 514 iwl_rx_handle_rxbuf(trans, rxb);
519 515
520 i = (i + 1) & RX_QUEUE_MASK; 516 i = (i + 1) & RX_QUEUE_MASK;
@@ -546,12 +542,12 @@ static void iwl_irq_handle_error(struct iwl_trans *trans)
546 /* W/A for WiFi/WiMAX coex and WiMAX own the RF */ 542 /* W/A for WiFi/WiMAX coex and WiMAX own the RF */
547 if (trans->cfg->internal_wimax_coex && 543 if (trans->cfg->internal_wimax_coex &&
548 (!(iwl_read_prph(trans, APMG_CLK_CTRL_REG) & 544 (!(iwl_read_prph(trans, APMG_CLK_CTRL_REG) &
549 APMS_CLK_VAL_MRB_FUNC_MODE) || 545 APMS_CLK_VAL_MRB_FUNC_MODE) ||
550 (iwl_read_prph(trans, APMG_PS_CTRL_REG) & 546 (iwl_read_prph(trans, APMG_PS_CTRL_REG) &
551 APMG_PS_CTRL_VAL_RESET_REQ))) { 547 APMG_PS_CTRL_VAL_RESET_REQ))) {
552 struct iwl_trans_pcie *trans_pcie; 548 struct iwl_trans_pcie *trans_pcie =
549 IWL_TRANS_GET_PCIE_TRANS(trans);
553 550
554 trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
555 clear_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status); 551 clear_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status);
556 iwl_op_mode_wimax_active(trans->op_mode); 552 iwl_op_mode_wimax_active(trans->op_mode);
557 wake_up(&trans->wait_command_queue); 553 wake_up(&trans->wait_command_queue);
@@ -567,6 +563,8 @@ static void iwl_irq_handle_error(struct iwl_trans *trans)
567/* tasklet for iwlagn interrupt */ 563/* tasklet for iwlagn interrupt */
568void iwl_irq_tasklet(struct iwl_trans *trans) 564void iwl_irq_tasklet(struct iwl_trans *trans)
569{ 565{
566 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
567 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
570 u32 inta = 0; 568 u32 inta = 0;
571 u32 handled = 0; 569 u32 handled = 0;
572 unsigned long flags; 570 unsigned long flags;
@@ -575,10 +573,6 @@ void iwl_irq_tasklet(struct iwl_trans *trans)
575 u32 inta_mask; 573 u32 inta_mask;
576#endif 574#endif
577 575
578 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
579 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
580
581
582 spin_lock_irqsave(&trans_pcie->irq_lock, flags); 576 spin_lock_irqsave(&trans_pcie->irq_lock, flags);
583 577
584 /* Ack/clear/reset pending uCode interrupts. 578 /* Ack/clear/reset pending uCode interrupts.
@@ -593,7 +587,7 @@ void iwl_irq_tasklet(struct iwl_trans *trans)
593 * interrupt coalescing can still be achieved. 587 * interrupt coalescing can still be achieved.
594 */ 588 */
595 iwl_write32(trans, CSR_INT, 589 iwl_write32(trans, CSR_INT,
596 trans_pcie->inta | ~trans_pcie->inta_mask); 590 trans_pcie->inta | ~trans_pcie->inta_mask);
597 591
598 inta = trans_pcie->inta; 592 inta = trans_pcie->inta;
599 593
@@ -602,7 +596,7 @@ void iwl_irq_tasklet(struct iwl_trans *trans)
602 /* just for debug */ 596 /* just for debug */
603 inta_mask = iwl_read32(trans, CSR_INT_MASK); 597 inta_mask = iwl_read32(trans, CSR_INT_MASK);
604 IWL_DEBUG_ISR(trans, "inta 0x%08x, enabled 0x%08x\n", 598 IWL_DEBUG_ISR(trans, "inta 0x%08x, enabled 0x%08x\n",
605 inta, inta_mask); 599 inta, inta_mask);
606 } 600 }
607#endif 601#endif
608 602
@@ -651,7 +645,7 @@ void iwl_irq_tasklet(struct iwl_trans *trans)
651 645
652 hw_rfkill = iwl_is_rfkill_set(trans); 646 hw_rfkill = iwl_is_rfkill_set(trans);
653 IWL_WARN(trans, "RF_KILL bit toggled to %s.\n", 647 IWL_WARN(trans, "RF_KILL bit toggled to %s.\n",
654 hw_rfkill ? "disable radio" : "enable radio"); 648 hw_rfkill ? "disable radio" : "enable radio");
655 649
656 isr_stats->rfkill++; 650 isr_stats->rfkill++;
657 651
@@ -693,7 +687,7 @@ void iwl_irq_tasklet(struct iwl_trans *trans)
693 * Rx "responses" (frame-received notification), and other 687 * Rx "responses" (frame-received notification), and other
694 * notifications from uCode come through here*/ 688 * notifications from uCode come through here*/
695 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX | 689 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
696 CSR_INT_BIT_RX_PERIODIC)) { 690 CSR_INT_BIT_RX_PERIODIC)) {
697 IWL_DEBUG_ISR(trans, "Rx interrupt\n"); 691 IWL_DEBUG_ISR(trans, "Rx interrupt\n");
698 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { 692 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
699 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); 693 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
@@ -733,7 +727,7 @@ void iwl_irq_tasklet(struct iwl_trans *trans)
733 */ 727 */
734 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) 728 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
735 iwl_write8(trans, CSR_INT_PERIODIC_REG, 729 iwl_write8(trans, CSR_INT_PERIODIC_REG,
736 CSR_INT_PERIODIC_ENA); 730 CSR_INT_PERIODIC_ENA);
737 731
738 isr_stats->rx++; 732 isr_stats->rx++;
739 } 733 }
@@ -782,8 +776,7 @@ void iwl_irq_tasklet(struct iwl_trans *trans)
782/* Free dram table */ 776/* Free dram table */
783void iwl_free_isr_ict(struct iwl_trans *trans) 777void iwl_free_isr_ict(struct iwl_trans *trans)
784{ 778{
785 struct iwl_trans_pcie *trans_pcie = 779 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
786 IWL_TRANS_GET_PCIE_TRANS(trans);
787 780
788 if (trans_pcie->ict_tbl) { 781 if (trans_pcie->ict_tbl) {
789 dma_free_coherent(trans->dev, ICT_SIZE, 782 dma_free_coherent(trans->dev, ICT_SIZE,
@@ -802,8 +795,7 @@ void iwl_free_isr_ict(struct iwl_trans *trans)
802 */ 795 */
803int iwl_alloc_isr_ict(struct iwl_trans *trans) 796int iwl_alloc_isr_ict(struct iwl_trans *trans)
804{ 797{
805 struct iwl_trans_pcie *trans_pcie = 798 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
806 IWL_TRANS_GET_PCIE_TRANS(trans);
807 799
808 trans_pcie->ict_tbl = 800 trans_pcie->ict_tbl =
809 dma_alloc_coherent(trans->dev, ICT_SIZE, 801 dma_alloc_coherent(trans->dev, ICT_SIZE,
@@ -837,10 +829,9 @@ int iwl_alloc_isr_ict(struct iwl_trans *trans)
837 */ 829 */
838void iwl_reset_ict(struct iwl_trans *trans) 830void iwl_reset_ict(struct iwl_trans *trans)
839{ 831{
832 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
840 u32 val; 833 u32 val;
841 unsigned long flags; 834 unsigned long flags;
842 struct iwl_trans_pcie *trans_pcie =
843 IWL_TRANS_GET_PCIE_TRANS(trans);
844 835
845 if (!trans_pcie->ict_tbl) 836 if (!trans_pcie->ict_tbl)
846 return; 837 return;
@@ -868,9 +859,7 @@ void iwl_reset_ict(struct iwl_trans *trans)
868/* Device is going down disable ict interrupt usage */ 859/* Device is going down disable ict interrupt usage */
869void iwl_disable_ict(struct iwl_trans *trans) 860void iwl_disable_ict(struct iwl_trans *trans)
870{ 861{
871 struct iwl_trans_pcie *trans_pcie = 862 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
872 IWL_TRANS_GET_PCIE_TRANS(trans);
873
874 unsigned long flags; 863 unsigned long flags;
875 864
876 spin_lock_irqsave(&trans_pcie->irq_lock, flags); 865 spin_lock_irqsave(&trans_pcie->irq_lock, flags);
@@ -934,7 +923,7 @@ static irqreturn_t iwl_isr(int irq, void *data)
934 if (likely(inta)) 923 if (likely(inta))
935 tasklet_schedule(&trans_pcie->irq_tasklet); 924 tasklet_schedule(&trans_pcie->irq_tasklet);
936 else if (test_bit(STATUS_INT_ENABLED, &trans_pcie->status) && 925 else if (test_bit(STATUS_INT_ENABLED, &trans_pcie->status) &&
937 !trans_pcie->inta) 926 !trans_pcie->inta)
938 iwl_enable_interrupts(trans); 927 iwl_enable_interrupts(trans);
939 928
940 unplugged: 929 unplugged:
@@ -945,7 +934,7 @@ static irqreturn_t iwl_isr(int irq, void *data)
945 /* re-enable interrupts here since we don't have anything to service. */ 934 /* re-enable interrupts here since we don't have anything to service. */
946 /* only Re-enable if disabled by irq and no schedules tasklet. */ 935 /* only Re-enable if disabled by irq and no schedules tasklet. */
947 if (test_bit(STATUS_INT_ENABLED, &trans_pcie->status) && 936 if (test_bit(STATUS_INT_ENABLED, &trans_pcie->status) &&
948 !trans_pcie->inta) 937 !trans_pcie->inta)
949 iwl_enable_interrupts(trans); 938 iwl_enable_interrupts(trans);
950 939
951 spin_unlock_irqrestore(&trans_pcie->irq_lock, flags); 940 spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
@@ -1036,7 +1025,7 @@ irqreturn_t iwl_isr_ict(int irq, void *data)
1036 1025
1037 inta = (0xff & val) | ((0xff00 & val) << 16); 1026 inta = (0xff & val) | ((0xff00 & val) << 16);
1038 IWL_DEBUG_ISR(trans, "ISR inta 0x%08x, enabled 0x%08x ict 0x%08x\n", 1027 IWL_DEBUG_ISR(trans, "ISR inta 0x%08x, enabled 0x%08x ict 0x%08x\n",
1039 inta, inta_mask, val); 1028 inta, inta_mask, val);
1040 1029
1041 inta &= trans_pcie->inta_mask; 1030 inta &= trans_pcie->inta_mask;
1042 trans_pcie->inta |= inta; 1031 trans_pcie->inta |= inta;
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
index 79c6b91417f9..cc935168ae52 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
@@ -70,15 +70,12 @@
70 70
71#include "iwl-drv.h" 71#include "iwl-drv.h"
72#include "iwl-trans.h" 72#include "iwl-trans.h"
73#include "iwl-trans-pcie-int.h"
74#include "iwl-csr.h" 73#include "iwl-csr.h"
75#include "iwl-prph.h" 74#include "iwl-prph.h"
76#include "iwl-eeprom.h"
77#include "iwl-agn-hw.h" 75#include "iwl-agn-hw.h"
76#include "internal.h"
78/* FIXME: need to abstract out TX command (once we know what it looks like) */ 77/* FIXME: need to abstract out TX command (once we know what it looks like) */
79#include "iwl-commands.h" 78#include "dvm/commands.h"
80
81#define IWL_MASK(lo, hi) ((1 << (hi)) | ((1 << (hi)) - (1 << (lo))))
82 79
83#define SCD_QUEUECHAIN_SEL_ALL(trans, trans_pcie) \ 80#define SCD_QUEUECHAIN_SEL_ALL(trans, trans_pcie) \
84 (((1<<trans->cfg->base_params->num_of_queues) - 1) &\ 81 (((1<<trans->cfg->base_params->num_of_queues) - 1) &\
@@ -86,8 +83,7 @@
86 83
87static int iwl_trans_rx_alloc(struct iwl_trans *trans) 84static int iwl_trans_rx_alloc(struct iwl_trans *trans)
88{ 85{
89 struct iwl_trans_pcie *trans_pcie = 86 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
90 IWL_TRANS_GET_PCIE_TRANS(trans);
91 struct iwl_rx_queue *rxq = &trans_pcie->rxq; 87 struct iwl_rx_queue *rxq = &trans_pcie->rxq;
92 struct device *dev = trans->dev; 88 struct device *dev = trans->dev;
93 89
@@ -114,7 +110,7 @@ static int iwl_trans_rx_alloc(struct iwl_trans *trans)
114 110
115err_rb_stts: 111err_rb_stts:
116 dma_free_coherent(dev, sizeof(__le32) * RX_QUEUE_SIZE, 112 dma_free_coherent(dev, sizeof(__le32) * RX_QUEUE_SIZE,
117 rxq->bd, rxq->bd_dma); 113 rxq->bd, rxq->bd_dma);
118 memset(&rxq->bd_dma, 0, sizeof(rxq->bd_dma)); 114 memset(&rxq->bd_dma, 0, sizeof(rxq->bd_dma));
119 rxq->bd = NULL; 115 rxq->bd = NULL;
120err_bd: 116err_bd:
@@ -123,8 +119,7 @@ err_bd:
123 119
124static void iwl_trans_rxq_free_rx_bufs(struct iwl_trans *trans) 120static void iwl_trans_rxq_free_rx_bufs(struct iwl_trans *trans)
125{ 121{
126 struct iwl_trans_pcie *trans_pcie = 122 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
127 IWL_TRANS_GET_PCIE_TRANS(trans);
128 struct iwl_rx_queue *rxq = &trans_pcie->rxq; 123 struct iwl_rx_queue *rxq = &trans_pcie->rxq;
129 int i; 124 int i;
130 125
@@ -134,8 +129,8 @@ static void iwl_trans_rxq_free_rx_bufs(struct iwl_trans *trans)
134 * to an SKB, so we need to unmap and free potential storage */ 129 * to an SKB, so we need to unmap and free potential storage */
135 if (rxq->pool[i].page != NULL) { 130 if (rxq->pool[i].page != NULL) {
136 dma_unmap_page(trans->dev, rxq->pool[i].page_dma, 131 dma_unmap_page(trans->dev, rxq->pool[i].page_dma,
137 PAGE_SIZE << trans_pcie->rx_page_order, 132 PAGE_SIZE << trans_pcie->rx_page_order,
138 DMA_FROM_DEVICE); 133 DMA_FROM_DEVICE);
139 __free_pages(rxq->pool[i].page, 134 __free_pages(rxq->pool[i].page,
140 trans_pcie->rx_page_order); 135 trans_pcie->rx_page_order);
141 rxq->pool[i].page = NULL; 136 rxq->pool[i].page = NULL;
@@ -193,8 +188,7 @@ static void iwl_trans_rx_hw_init(struct iwl_trans *trans,
193 188
194static int iwl_rx_init(struct iwl_trans *trans) 189static int iwl_rx_init(struct iwl_trans *trans)
195{ 190{
196 struct iwl_trans_pcie *trans_pcie = 191 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
197 IWL_TRANS_GET_PCIE_TRANS(trans);
198 struct iwl_rx_queue *rxq = &trans_pcie->rxq; 192 struct iwl_rx_queue *rxq = &trans_pcie->rxq;
199 193
200 int i, err; 194 int i, err;
@@ -236,10 +230,8 @@ static int iwl_rx_init(struct iwl_trans *trans)
236 230
237static void iwl_trans_pcie_rx_free(struct iwl_trans *trans) 231static void iwl_trans_pcie_rx_free(struct iwl_trans *trans)
238{ 232{
239 struct iwl_trans_pcie *trans_pcie = 233 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
240 IWL_TRANS_GET_PCIE_TRANS(trans);
241 struct iwl_rx_queue *rxq = &trans_pcie->rxq; 234 struct iwl_rx_queue *rxq = &trans_pcie->rxq;
242
243 unsigned long flags; 235 unsigned long flags;
244 236
245 /*if rxq->bd is NULL, it means that nothing has been allocated, 237 /*if rxq->bd is NULL, it means that nothing has been allocated,
@@ -274,11 +266,11 @@ static int iwl_trans_rx_stop(struct iwl_trans *trans)
274 /* stop Rx DMA */ 266 /* stop Rx DMA */
275 iwl_write_direct32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); 267 iwl_write_direct32(trans, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
276 return iwl_poll_direct_bit(trans, FH_MEM_RSSR_RX_STATUS_REG, 268 return iwl_poll_direct_bit(trans, FH_MEM_RSSR_RX_STATUS_REG,
277 FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000); 269 FH_RSSR_CHNL0_RX_STATUS_CHNL_IDLE, 1000);
278} 270}
279 271
280static inline int iwlagn_alloc_dma_ptr(struct iwl_trans *trans, 272static int iwlagn_alloc_dma_ptr(struct iwl_trans *trans,
281 struct iwl_dma_ptr *ptr, size_t size) 273 struct iwl_dma_ptr *ptr, size_t size)
282{ 274{
283 if (WARN_ON(ptr->addr)) 275 if (WARN_ON(ptr->addr))
284 return -EINVAL; 276 return -EINVAL;
@@ -291,8 +283,8 @@ static inline int iwlagn_alloc_dma_ptr(struct iwl_trans *trans,
291 return 0; 283 return 0;
292} 284}
293 285
294static inline void iwlagn_free_dma_ptr(struct iwl_trans *trans, 286static void iwlagn_free_dma_ptr(struct iwl_trans *trans,
295 struct iwl_dma_ptr *ptr) 287 struct iwl_dma_ptr *ptr)
296{ 288{
297 if (unlikely(!ptr->addr)) 289 if (unlikely(!ptr->addr))
298 return; 290 return;
@@ -306,6 +298,10 @@ static void iwl_trans_pcie_queue_stuck_timer(unsigned long data)
306 struct iwl_tx_queue *txq = (void *)data; 298 struct iwl_tx_queue *txq = (void *)data;
307 struct iwl_trans_pcie *trans_pcie = txq->trans_pcie; 299 struct iwl_trans_pcie *trans_pcie = txq->trans_pcie;
308 struct iwl_trans *trans = iwl_trans_pcie_get_trans(trans_pcie); 300 struct iwl_trans *trans = iwl_trans_pcie_get_trans(trans_pcie);
301 u32 scd_sram_addr = trans_pcie->scd_base_addr +
302 SCD_TX_STTS_MEM_LOWER_BOUND + (16 * txq->q.id);
303 u8 buf[16];
304 int i;
309 305
310 spin_lock(&txq->lock); 306 spin_lock(&txq->lock);
311 /* check if triggered erroneously */ 307 /* check if triggered erroneously */
@@ -315,26 +311,51 @@ static void iwl_trans_pcie_queue_stuck_timer(unsigned long data)
315 } 311 }
316 spin_unlock(&txq->lock); 312 spin_unlock(&txq->lock);
317 313
318
319 IWL_ERR(trans, "Queue %d stuck for %u ms.\n", txq->q.id, 314 IWL_ERR(trans, "Queue %d stuck for %u ms.\n", txq->q.id,
320 jiffies_to_msecs(trans_pcie->wd_timeout)); 315 jiffies_to_msecs(trans_pcie->wd_timeout));
321 IWL_ERR(trans, "Current SW read_ptr %d write_ptr %d\n", 316 IWL_ERR(trans, "Current SW read_ptr %d write_ptr %d\n",
322 txq->q.read_ptr, txq->q.write_ptr); 317 txq->q.read_ptr, txq->q.write_ptr);
323 IWL_ERR(trans, "Current HW read_ptr %d write_ptr %d\n", 318
324 iwl_read_prph(trans, SCD_QUEUE_RDPTR(txq->q.id)) 319 iwl_read_targ_mem_bytes(trans, scd_sram_addr, buf, sizeof(buf));
325 & (TFD_QUEUE_SIZE_MAX - 1), 320
326 iwl_read_prph(trans, SCD_QUEUE_WRPTR(txq->q.id))); 321 iwl_print_hex_error(trans, buf, sizeof(buf));
322
323 for (i = 0; i < FH_TCSR_CHNL_NUM; i++)
324 IWL_ERR(trans, "FH TRBs(%d) = 0x%08x\n", i,
325 iwl_read_direct32(trans, FH_TX_TRB_REG(i)));
326
327 for (i = 0; i < trans->cfg->base_params->num_of_queues; i++) {
328 u32 status = iwl_read_prph(trans, SCD_QUEUE_STATUS_BITS(i));
329 u8 fifo = (status >> SCD_QUEUE_STTS_REG_POS_TXF) & 0x7;
330 bool active = !!(status & BIT(SCD_QUEUE_STTS_REG_POS_ACTIVE));
331 u32 tbl_dw =
332 iwl_read_targ_mem(trans,
333 trans_pcie->scd_base_addr +
334 SCD_TRANS_TBL_OFFSET_QUEUE(i));
335
336 if (i & 0x1)
337 tbl_dw = (tbl_dw & 0xFFFF0000) >> 16;
338 else
339 tbl_dw = tbl_dw & 0x0000FFFF;
340
341 IWL_ERR(trans,
342 "Q %d is %sactive and mapped to fifo %d ra_tid 0x%04x [%d,%d]\n",
343 i, active ? "" : "in", fifo, tbl_dw,
344 iwl_read_prph(trans,
345 SCD_QUEUE_RDPTR(i)) & (txq->q.n_bd - 1),
346 iwl_read_prph(trans, SCD_QUEUE_WRPTR(i)));
347 }
327 348
328 iwl_op_mode_nic_error(trans->op_mode); 349 iwl_op_mode_nic_error(trans->op_mode);
329} 350}
330 351
331static int iwl_trans_txq_alloc(struct iwl_trans *trans, 352static int iwl_trans_txq_alloc(struct iwl_trans *trans,
332 struct iwl_tx_queue *txq, int slots_num, 353 struct iwl_tx_queue *txq, int slots_num,
333 u32 txq_id) 354 u32 txq_id)
334{ 355{
356 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
335 size_t tfd_sz = sizeof(struct iwl_tfd) * TFD_QUEUE_SIZE_MAX; 357 size_t tfd_sz = sizeof(struct iwl_tfd) * TFD_QUEUE_SIZE_MAX;
336 int i; 358 int i;
337 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
338 359
339 if (WARN_ON(txq->entries || txq->tfds)) 360 if (WARN_ON(txq->entries || txq->tfds))
340 return -EINVAL; 361 return -EINVAL;
@@ -435,7 +456,7 @@ static void iwl_tx_queue_unmap(struct iwl_trans *trans, int txq_id)
435 456
436 spin_lock_bh(&txq->lock); 457 spin_lock_bh(&txq->lock);
437 while (q->write_ptr != q->read_ptr) { 458 while (q->write_ptr != q->read_ptr) {
438 iwlagn_txq_free_tfd(trans, txq, dma_dir); 459 iwl_txq_free_tfd(trans, txq, dma_dir);
439 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd); 460 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd);
440 } 461 }
441 spin_unlock_bh(&txq->lock); 462 spin_unlock_bh(&txq->lock);
@@ -455,6 +476,7 @@ static void iwl_tx_queue_free(struct iwl_trans *trans, int txq_id)
455 struct iwl_tx_queue *txq = &trans_pcie->txq[txq_id]; 476 struct iwl_tx_queue *txq = &trans_pcie->txq[txq_id];
456 struct device *dev = trans->dev; 477 struct device *dev = trans->dev;
457 int i; 478 int i;
479
458 if (WARN_ON(!txq)) 480 if (WARN_ON(!txq))
459 return; 481 return;
460 482
@@ -574,11 +596,11 @@ error:
574} 596}
575static int iwl_tx_init(struct iwl_trans *trans) 597static int iwl_tx_init(struct iwl_trans *trans)
576{ 598{
599 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
577 int ret; 600 int ret;
578 int txq_id, slots_num; 601 int txq_id, slots_num;
579 unsigned long flags; 602 unsigned long flags;
580 bool alloc = false; 603 bool alloc = false;
581 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
582 604
583 if (!trans_pcie->txq) { 605 if (!trans_pcie->txq) {
584 ret = iwl_trans_tx_alloc(trans); 606 ret = iwl_trans_tx_alloc(trans);
@@ -643,10 +665,9 @@ static void iwl_set_pwr_vmain(struct iwl_trans *trans)
643 665
644static u16 iwl_pciexp_link_ctrl(struct iwl_trans *trans) 666static u16 iwl_pciexp_link_ctrl(struct iwl_trans *trans)
645{ 667{
668 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
646 int pos; 669 int pos;
647 u16 pci_lnk_ctl; 670 u16 pci_lnk_ctl;
648 struct iwl_trans_pcie *trans_pcie =
649 IWL_TRANS_GET_PCIE_TRANS(trans);
650 671
651 struct pci_dev *pci_dev = trans_pcie->pci_dev; 672 struct pci_dev *pci_dev = trans_pcie->pci_dev;
652 673
@@ -700,14 +721,14 @@ static int iwl_apm_init(struct iwl_trans *trans)
700 721
701 /* Disable L0S exit timer (platform NMI Work/Around) */ 722 /* Disable L0S exit timer (platform NMI Work/Around) */
702 iwl_set_bit(trans, CSR_GIO_CHICKEN_BITS, 723 iwl_set_bit(trans, CSR_GIO_CHICKEN_BITS,
703 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); 724 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
704 725
705 /* 726 /*
706 * Disable L0s without affecting L1; 727 * Disable L0s without affecting L1;
707 * don't wait for ICH L0s (ICH bug W/A) 728 * don't wait for ICH L0s (ICH bug W/A)
708 */ 729 */
709 iwl_set_bit(trans, CSR_GIO_CHICKEN_BITS, 730 iwl_set_bit(trans, CSR_GIO_CHICKEN_BITS,
710 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX); 731 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
711 732
712 /* Set FH wait threshold to maximum (HW error during stress W/A) */ 733 /* Set FH wait threshold to maximum (HW error during stress W/A) */
713 iwl_set_bit(trans, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL); 734 iwl_set_bit(trans, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
@@ -717,7 +738,7 @@ static int iwl_apm_init(struct iwl_trans *trans)
717 * wake device's PCI Express link L1a -> L0s 738 * wake device's PCI Express link L1a -> L0s
718 */ 739 */
719 iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, 740 iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
720 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A); 741 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
721 742
722 iwl_apm_config(trans); 743 iwl_apm_config(trans);
723 744
@@ -738,8 +759,8 @@ static int iwl_apm_init(struct iwl_trans *trans)
738 * and accesses to uCode SRAM. 759 * and accesses to uCode SRAM.
739 */ 760 */
740 ret = iwl_poll_bit(trans, CSR_GP_CNTRL, 761 ret = iwl_poll_bit(trans, CSR_GP_CNTRL,
741 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 762 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
742 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); 763 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
743 if (ret < 0) { 764 if (ret < 0) {
744 IWL_DEBUG_INFO(trans, "Failed to init the card\n"); 765 IWL_DEBUG_INFO(trans, "Failed to init the card\n");
745 goto out; 766 goto out;
@@ -773,8 +794,8 @@ static int iwl_apm_stop_master(struct iwl_trans *trans)
773 iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER); 794 iwl_set_bit(trans, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
774 795
775 ret = iwl_poll_bit(trans, CSR_RESET, 796 ret = iwl_poll_bit(trans, CSR_RESET,
776 CSR_RESET_REG_FLAG_MASTER_DISABLED, 797 CSR_RESET_REG_FLAG_MASTER_DISABLED,
777 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100); 798 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
778 if (ret) 799 if (ret)
779 IWL_WARN(trans, "Master Disable Timed Out, 100 usec\n"); 800 IWL_WARN(trans, "Master Disable Timed Out, 100 usec\n");
780 801
@@ -816,8 +837,7 @@ static int iwl_nic_init(struct iwl_trans *trans)
816 iwl_apm_init(trans); 837 iwl_apm_init(trans);
817 838
818 /* Set interrupt coalescing calibration timer to default (512 usecs) */ 839 /* Set interrupt coalescing calibration timer to default (512 usecs) */
819 iwl_write8(trans, CSR_INT_COALESCING, 840 iwl_write8(trans, CSR_INT_COALESCING, IWL_HOST_INT_CALIB_TIMEOUT_DEF);
820 IWL_HOST_INT_CALIB_TIMEOUT_DEF);
821 841
822 spin_unlock_irqrestore(&trans_pcie->irq_lock, flags); 842 spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
823 843
@@ -836,8 +856,8 @@ static int iwl_nic_init(struct iwl_trans *trans)
836 856
837 if (trans->cfg->base_params->shadow_reg_enable) { 857 if (trans->cfg->base_params->shadow_reg_enable) {
838 /* enable shadow regs in HW */ 858 /* enable shadow regs in HW */
839 iwl_set_bit(trans, CSR_MAC_SHADOW_REG_CTRL, 859 iwl_set_bit(trans, CSR_MAC_SHADOW_REG_CTRL, 0x800FFFFF);
840 0x800FFFFF); 860 IWL_DEBUG_INFO(trans, "Enabling shadow registers in device\n");
841 } 861 }
842 862
843 return 0; 863 return 0;
@@ -851,13 +871,13 @@ static int iwl_set_hw_ready(struct iwl_trans *trans)
851 int ret; 871 int ret;
852 872
853 iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, 873 iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
854 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY); 874 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
855 875
856 /* See if we got it */ 876 /* See if we got it */
857 ret = iwl_poll_bit(trans, CSR_HW_IF_CONFIG_REG, 877 ret = iwl_poll_bit(trans, CSR_HW_IF_CONFIG_REG,
858 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY, 878 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
859 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY, 879 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
860 HW_READY_TIMEOUT); 880 HW_READY_TIMEOUT);
861 881
862 IWL_DEBUG_INFO(trans, "hardware%s ready\n", ret < 0 ? " not" : ""); 882 IWL_DEBUG_INFO(trans, "hardware%s ready\n", ret < 0 ? " not" : "");
863 return ret; 883 return ret;
@@ -877,11 +897,11 @@ static int iwl_prepare_card_hw(struct iwl_trans *trans)
877 897
878 /* If HW is not ready, prepare the conditions to check again */ 898 /* If HW is not ready, prepare the conditions to check again */
879 iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG, 899 iwl_set_bit(trans, CSR_HW_IF_CONFIG_REG,
880 CSR_HW_IF_CONFIG_REG_PREPARE); 900 CSR_HW_IF_CONFIG_REG_PREPARE);
881 901
882 ret = iwl_poll_bit(trans, CSR_HW_IF_CONFIG_REG, 902 ret = iwl_poll_bit(trans, CSR_HW_IF_CONFIG_REG,
883 ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 903 ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
884 CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000); 904 CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
885 905
886 if (ret < 0) 906 if (ret < 0)
887 return ret; 907 return ret;
@@ -908,32 +928,33 @@ static int iwl_load_section(struct iwl_trans *trans, u8 section_num,
908 trans_pcie->ucode_write_complete = false; 928 trans_pcie->ucode_write_complete = false;
909 929
910 iwl_write_direct32(trans, 930 iwl_write_direct32(trans,
911 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL), 931 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
912 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE); 932 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
913 933
914 iwl_write_direct32(trans, 934 iwl_write_direct32(trans,
915 FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr); 935 FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL),
936 dst_addr);
916 937
917 iwl_write_direct32(trans, 938 iwl_write_direct32(trans,
918 FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL), 939 FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
919 phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK); 940 phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
920 941
921 iwl_write_direct32(trans, 942 iwl_write_direct32(trans,
922 FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL), 943 FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL),
923 (iwl_get_dma_hi_addr(phy_addr) 944 (iwl_get_dma_hi_addr(phy_addr)
924 << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt); 945 << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt);
925 946
926 iwl_write_direct32(trans, 947 iwl_write_direct32(trans,
927 FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL), 948 FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
928 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM | 949 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
929 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX | 950 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
930 FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID); 951 FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
931 952
932 iwl_write_direct32(trans, 953 iwl_write_direct32(trans,
933 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL), 954 FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
934 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | 955 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
935 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE | 956 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE |
936 FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD); 957 FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
937 958
938 IWL_DEBUG_FW(trans, "[%d] uCode section being loaded...\n", 959 IWL_DEBUG_FW(trans, "[%d] uCode section being loaded...\n",
939 section_num); 960 section_num);
@@ -1038,6 +1059,10 @@ static void iwl_tx_start(struct iwl_trans *trans)
1038 1059
1039 spin_lock_irqsave(&trans_pcie->irq_lock, flags); 1060 spin_lock_irqsave(&trans_pcie->irq_lock, flags);
1040 1061
1062 /* make sure all queue are not stopped/used */
1063 memset(trans_pcie->queue_stopped, 0, sizeof(trans_pcie->queue_stopped));
1064 memset(trans_pcie->queue_used, 0, sizeof(trans_pcie->queue_used));
1065
1041 trans_pcie->scd_base_addr = 1066 trans_pcie->scd_base_addr =
1042 iwl_read_prph(trans, SCD_SRAM_BASE_ADDR); 1067 iwl_read_prph(trans, SCD_SRAM_BASE_ADDR);
1043 a = trans_pcie->scd_base_addr + SCD_CONTEXT_MEM_LOWER_BOUND; 1068 a = trans_pcie->scd_base_addr + SCD_CONTEXT_MEM_LOWER_BOUND;
@@ -1063,64 +1088,32 @@ static void iwl_tx_start(struct iwl_trans *trans)
1063 */ 1088 */
1064 iwl_write_prph(trans, SCD_CHAINEXT_EN, 0); 1089 iwl_write_prph(trans, SCD_CHAINEXT_EN, 0);
1065 1090
1091 for (i = 0; i < trans_pcie->n_q_to_fifo; i++) {
1092 int fifo = trans_pcie->setup_q_to_fifo[i];
1093
1094 iwl_trans_pcie_txq_enable(trans, i, fifo, IWL_INVALID_STATION,
1095 IWL_TID_NON_QOS, SCD_FRAME_LIMIT, 0);
1096 }
1097
1098 /* Activate all Tx DMA/FIFO channels */
1099 iwl_trans_txq_set_sched(trans, IWL_MASK(0, 7));
1100
1066 /* Enable DMA channel */ 1101 /* Enable DMA channel */
1067 for (chan = 0; chan < FH_TCSR_CHNL_NUM ; chan++) 1102 for (chan = 0; chan < FH_TCSR_CHNL_NUM ; chan++)
1068 iwl_write_direct32(trans, FH_TCSR_CHNL_TX_CONFIG_REG(chan), 1103 iwl_write_direct32(trans, FH_TCSR_CHNL_TX_CONFIG_REG(chan),
1069 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | 1104 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
1070 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE); 1105 FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
1071 1106
1072 /* Update FH chicken bits */ 1107 /* Update FH chicken bits */
1073 reg_val = iwl_read_direct32(trans, FH_TX_CHICKEN_BITS_REG); 1108 reg_val = iwl_read_direct32(trans, FH_TX_CHICKEN_BITS_REG);
1074 iwl_write_direct32(trans, FH_TX_CHICKEN_BITS_REG, 1109 iwl_write_direct32(trans, FH_TX_CHICKEN_BITS_REG,
1075 reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN); 1110 reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
1076 1111
1077 iwl_write_prph(trans, SCD_QUEUECHAIN_SEL,
1078 SCD_QUEUECHAIN_SEL_ALL(trans, trans_pcie));
1079 iwl_write_prph(trans, SCD_AGGR_SEL, 0);
1080
1081 /* initiate the queues */
1082 for (i = 0; i < trans->cfg->base_params->num_of_queues; i++) {
1083 iwl_write_prph(trans, SCD_QUEUE_RDPTR(i), 0);
1084 iwl_write_direct32(trans, HBUS_TARG_WRPTR, 0 | (i << 8));
1085 iwl_write_targ_mem(trans, trans_pcie->scd_base_addr +
1086 SCD_CONTEXT_QUEUE_OFFSET(i), 0);
1087 iwl_write_targ_mem(trans, trans_pcie->scd_base_addr +
1088 SCD_CONTEXT_QUEUE_OFFSET(i) +
1089 sizeof(u32),
1090 ((SCD_WIN_SIZE <<
1091 SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
1092 SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
1093 ((SCD_FRAME_LIMIT <<
1094 SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
1095 SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
1096 }
1097
1098 iwl_write_prph(trans, SCD_INTERRUPT_MASK,
1099 IWL_MASK(0, trans->cfg->base_params->num_of_queues));
1100
1101 /* Activate all Tx DMA/FIFO channels */
1102 iwl_trans_txq_set_sched(trans, IWL_MASK(0, 7));
1103
1104 iwl_trans_set_wr_ptrs(trans, trans_pcie->cmd_queue, 0);
1105
1106 /* make sure all queue are not stopped/used */
1107 memset(trans_pcie->queue_stopped, 0, sizeof(trans_pcie->queue_stopped));
1108 memset(trans_pcie->queue_used, 0, sizeof(trans_pcie->queue_used));
1109
1110 for (i = 0; i < trans_pcie->n_q_to_fifo; i++) {
1111 int fifo = trans_pcie->setup_q_to_fifo[i];
1112
1113 set_bit(i, trans_pcie->queue_used);
1114
1115 iwl_trans_tx_queue_set_status(trans, &trans_pcie->txq[i],
1116 fifo, true);
1117 }
1118
1119 spin_unlock_irqrestore(&trans_pcie->irq_lock, flags); 1112 spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
1120 1113
1121 /* Enable L1-Active */ 1114 /* Enable L1-Active */
1122 iwl_clear_bits_prph(trans, APMG_PCIDEV_STT_REG, 1115 iwl_clear_bits_prph(trans, APMG_PCIDEV_STT_REG,
1123 APMG_PCIDEV_STT_VAL_L1_ACT_DIS); 1116 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
1124} 1117}
1125 1118
1126static void iwl_trans_pcie_fw_alive(struct iwl_trans *trans) 1119static void iwl_trans_pcie_fw_alive(struct iwl_trans *trans)
@@ -1134,9 +1127,9 @@ static void iwl_trans_pcie_fw_alive(struct iwl_trans *trans)
1134 */ 1127 */
1135static int iwl_trans_tx_stop(struct iwl_trans *trans) 1128static int iwl_trans_tx_stop(struct iwl_trans *trans)
1136{ 1129{
1130 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1137 int ch, txq_id, ret; 1131 int ch, txq_id, ret;
1138 unsigned long flags; 1132 unsigned long flags;
1139 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1140 1133
1141 /* Turn off all Tx DMA fifos */ 1134 /* Turn off all Tx DMA fifos */
1142 spin_lock_irqsave(&trans_pcie->irq_lock, flags); 1135 spin_lock_irqsave(&trans_pcie->irq_lock, flags);
@@ -1148,13 +1141,13 @@ static int iwl_trans_tx_stop(struct iwl_trans *trans)
1148 iwl_write_direct32(trans, 1141 iwl_write_direct32(trans,
1149 FH_TCSR_CHNL_TX_CONFIG_REG(ch), 0x0); 1142 FH_TCSR_CHNL_TX_CONFIG_REG(ch), 0x0);
1150 ret = iwl_poll_direct_bit(trans, FH_TSSR_TX_STATUS_REG, 1143 ret = iwl_poll_direct_bit(trans, FH_TSSR_TX_STATUS_REG,
1151 FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(ch), 1144 FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE(ch), 1000);
1152 1000);
1153 if (ret < 0) 1145 if (ret < 0)
1154 IWL_ERR(trans, "Failing on timeout while stopping" 1146 IWL_ERR(trans,
1155 " DMA channel %d [0x%08x]", ch, 1147 "Failing on timeout while stopping DMA channel %d [0x%08x]",
1156 iwl_read_direct32(trans, 1148 ch,
1157 FH_TSSR_TX_STATUS_REG)); 1149 iwl_read_direct32(trans,
1150 FH_TSSR_TX_STATUS_REG));
1158 } 1151 }
1159 spin_unlock_irqrestore(&trans_pcie->irq_lock, flags); 1152 spin_unlock_irqrestore(&trans_pcie->irq_lock, flags);
1160 1153
@@ -1173,8 +1166,8 @@ static int iwl_trans_tx_stop(struct iwl_trans *trans)
1173 1166
1174static void iwl_trans_pcie_stop_device(struct iwl_trans *trans) 1167static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
1175{ 1168{
1176 unsigned long flags;
1177 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); 1169 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1170 unsigned long flags;
1178 1171
1179 /* tell the device to stop sending interrupts */ 1172 /* tell the device to stop sending interrupts */
1180 spin_lock_irqsave(&trans_pcie->irq_lock, flags); 1173 spin_lock_irqsave(&trans_pcie->irq_lock, flags);
@@ -1204,7 +1197,7 @@ static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
1204 1197
1205 /* Make sure (redundant) we've released our request to stay awake */ 1198 /* Make sure (redundant) we've released our request to stay awake */
1206 iwl_clear_bit(trans, CSR_GP_CNTRL, 1199 iwl_clear_bit(trans, CSR_GP_CNTRL,
1207 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); 1200 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
1208 1201
1209 /* Stop the device, and put it in low power state */ 1202 /* Stop the device, and put it in low power state */
1210 iwl_apm_stop(trans); 1203 iwl_apm_stop(trans);
@@ -1273,13 +1266,27 @@ static int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
1273 1266
1274 spin_lock(&txq->lock); 1267 spin_lock(&txq->lock);
1275 1268
1269 /* In AGG mode, the index in the ring must correspond to the WiFi
1270 * sequence number. This is a HW requirements to help the SCD to parse
1271 * the BA.
1272 * Check here that the packets are in the right place on the ring.
1273 */
1274#ifdef CONFIG_IWLWIFI_DEBUG
1275 wifi_seq = SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
1276 WARN_ONCE((iwl_read_prph(trans, SCD_AGGR_SEL) & BIT(txq_id)) &&
1277 ((wifi_seq & 0xff) != q->write_ptr),
1278 "Q: %d WiFi Seq %d tfdNum %d",
1279 txq_id, wifi_seq, q->write_ptr);
1280#endif
1281
1276 /* Set up driver data for this TFD */ 1282 /* Set up driver data for this TFD */
1277 txq->entries[q->write_ptr].skb = skb; 1283 txq->entries[q->write_ptr].skb = skb;
1278 txq->entries[q->write_ptr].cmd = dev_cmd; 1284 txq->entries[q->write_ptr].cmd = dev_cmd;
1279 1285
1280 dev_cmd->hdr.cmd = REPLY_TX; 1286 dev_cmd->hdr.cmd = REPLY_TX;
1281 dev_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) | 1287 dev_cmd->hdr.sequence =
1282 INDEX_TO_SEQ(q->write_ptr))); 1288 cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
1289 INDEX_TO_SEQ(q->write_ptr)));
1283 1290
1284 /* Set up first empty entry in queue's array of Tx/cmd buffers */ 1291 /* Set up first empty entry in queue's array of Tx/cmd buffers */
1285 out_meta = &txq->entries[q->write_ptr].meta; 1292 out_meta = &txq->entries[q->write_ptr].meta;
@@ -1344,7 +1351,7 @@ static int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
1344 1351
1345 /* take back ownership of DMA buffer to enable update */ 1352 /* take back ownership of DMA buffer to enable update */
1346 dma_sync_single_for_cpu(trans->dev, txcmd_phys, firstlen, 1353 dma_sync_single_for_cpu(trans->dev, txcmd_phys, firstlen,
1347 DMA_BIDIRECTIONAL); 1354 DMA_BIDIRECTIONAL);
1348 tx_cmd->dram_lsb_ptr = cpu_to_le32(scratch_phys); 1355 tx_cmd->dram_lsb_ptr = cpu_to_le32(scratch_phys);
1349 tx_cmd->dram_msb_ptr = iwl_get_dma_hi_addr(scratch_phys); 1356 tx_cmd->dram_msb_ptr = iwl_get_dma_hi_addr(scratch_phys);
1350 1357
@@ -1356,7 +1363,7 @@ static int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
1356 iwl_trans_txq_update_byte_cnt_tbl(trans, txq, le16_to_cpu(tx_cmd->len)); 1363 iwl_trans_txq_update_byte_cnt_tbl(trans, txq, le16_to_cpu(tx_cmd->len));
1357 1364
1358 dma_sync_single_for_device(trans->dev, txcmd_phys, firstlen, 1365 dma_sync_single_for_device(trans->dev, txcmd_phys, firstlen,
1359 DMA_BIDIRECTIONAL); 1366 DMA_BIDIRECTIONAL);
1360 1367
1361 trace_iwlwifi_dev_tx(trans->dev, 1368 trace_iwlwifi_dev_tx(trans->dev,
1362 &((struct iwl_tfd *)txq->tfds)[txq->q.write_ptr], 1369 &((struct iwl_tfd *)txq->tfds)[txq->q.write_ptr],
@@ -1365,7 +1372,8 @@ static int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
1365 skb->data + hdr_len, secondlen); 1372 skb->data + hdr_len, secondlen);
1366 1373
1367 /* start timer if queue currently empty */ 1374 /* start timer if queue currently empty */
1368 if (q->read_ptr == q->write_ptr && trans_pcie->wd_timeout) 1375 if (txq->need_update && q->read_ptr == q->write_ptr &&
1376 trans_pcie->wd_timeout)
1369 mod_timer(&txq->stuck_timer, jiffies + trans_pcie->wd_timeout); 1377 mod_timer(&txq->stuck_timer, jiffies + trans_pcie->wd_timeout);
1370 1378
1371 /* Tell device the write index *just past* this latest filled TFD */ 1379 /* Tell device the write index *just past* this latest filled TFD */
@@ -1395,8 +1403,7 @@ static int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
1395 1403
1396static int iwl_trans_pcie_start_hw(struct iwl_trans *trans) 1404static int iwl_trans_pcie_start_hw(struct iwl_trans *trans)
1397{ 1405{
1398 struct iwl_trans_pcie *trans_pcie = 1406 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1399 IWL_TRANS_GET_PCIE_TRANS(trans);
1400 int err; 1407 int err;
1401 bool hw_rfkill; 1408 bool hw_rfkill;
1402 1409
@@ -1409,7 +1416,7 @@ static int iwl_trans_pcie_start_hw(struct iwl_trans *trans)
1409 iwl_alloc_isr_ict(trans); 1416 iwl_alloc_isr_ict(trans);
1410 1417
1411 err = request_irq(trans_pcie->irq, iwl_isr_ict, IRQF_SHARED, 1418 err = request_irq(trans_pcie->irq, iwl_isr_ict, IRQF_SHARED,
1412 DRV_NAME, trans); 1419 DRV_NAME, trans);
1413 if (err) { 1420 if (err) {
1414 IWL_ERR(trans, "Error allocating IRQ %d\n", 1421 IWL_ERR(trans, "Error allocating IRQ %d\n",
1415 trans_pcie->irq); 1422 trans_pcie->irq);
@@ -1447,9 +1454,9 @@ error:
1447static void iwl_trans_pcie_stop_hw(struct iwl_trans *trans, 1454static void iwl_trans_pcie_stop_hw(struct iwl_trans *trans,
1448 bool op_mode_leaving) 1455 bool op_mode_leaving)
1449{ 1456{
1457 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1450 bool hw_rfkill; 1458 bool hw_rfkill;
1451 unsigned long flags; 1459 unsigned long flags;
1452 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1453 1460
1454 iwl_apm_stop(trans); 1461 iwl_apm_stop(trans);
1455 1462
@@ -1553,8 +1560,7 @@ static void iwl_trans_pcie_configure(struct iwl_trans *trans,
1553 1560
1554void iwl_trans_pcie_free(struct iwl_trans *trans) 1561void iwl_trans_pcie_free(struct iwl_trans *trans)
1555{ 1562{
1556 struct iwl_trans_pcie *trans_pcie = 1563 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1557 IWL_TRANS_GET_PCIE_TRANS(trans);
1558 1564
1559 iwl_trans_pcie_tx_free(trans); 1565 iwl_trans_pcie_tx_free(trans);
1560#ifndef CONFIG_IWLWIFI_IDI 1566#ifndef CONFIG_IWLWIFI_IDI
@@ -1569,6 +1575,7 @@ void iwl_trans_pcie_free(struct iwl_trans *trans)
1569 iounmap(trans_pcie->hw_base); 1575 iounmap(trans_pcie->hw_base);
1570 pci_release_regions(trans_pcie->pci_dev); 1576 pci_release_regions(trans_pcie->pci_dev);
1571 pci_disable_device(trans_pcie->pci_dev); 1577 pci_disable_device(trans_pcie->pci_dev);
1578 kmem_cache_destroy(trans->dev_cmd_pool);
1572 1579
1573 kfree(trans); 1580 kfree(trans);
1574} 1581}
@@ -1816,8 +1823,8 @@ static const struct file_operations iwl_dbgfs_##name##_ops = { \
1816}; 1823};
1817 1824
1818static ssize_t iwl_dbgfs_tx_queue_read(struct file *file, 1825static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
1819 char __user *user_buf, 1826 char __user *user_buf,
1820 size_t count, loff_t *ppos) 1827 size_t count, loff_t *ppos)
1821{ 1828{
1822 struct iwl_trans *trans = file->private_data; 1829 struct iwl_trans *trans = file->private_data;
1823 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); 1830 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
@@ -1853,11 +1860,11 @@ static ssize_t iwl_dbgfs_tx_queue_read(struct file *file,
1853} 1860}
1854 1861
1855static ssize_t iwl_dbgfs_rx_queue_read(struct file *file, 1862static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
1856 char __user *user_buf, 1863 char __user *user_buf,
1857 size_t count, loff_t *ppos) { 1864 size_t count, loff_t *ppos)
1865{
1858 struct iwl_trans *trans = file->private_data; 1866 struct iwl_trans *trans = file->private_data;
1859 struct iwl_trans_pcie *trans_pcie = 1867 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1860 IWL_TRANS_GET_PCIE_TRANS(trans);
1861 struct iwl_rx_queue *rxq = &trans_pcie->rxq; 1868 struct iwl_rx_queue *rxq = &trans_pcie->rxq;
1862 char buf[256]; 1869 char buf[256];
1863 int pos = 0; 1870 int pos = 0;
@@ -1881,11 +1888,10 @@ static ssize_t iwl_dbgfs_rx_queue_read(struct file *file,
1881 1888
1882static ssize_t iwl_dbgfs_interrupt_read(struct file *file, 1889static ssize_t iwl_dbgfs_interrupt_read(struct file *file,
1883 char __user *user_buf, 1890 char __user *user_buf,
1884 size_t count, loff_t *ppos) { 1891 size_t count, loff_t *ppos)
1885 1892{
1886 struct iwl_trans *trans = file->private_data; 1893 struct iwl_trans *trans = file->private_data;
1887 struct iwl_trans_pcie *trans_pcie = 1894 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1888 IWL_TRANS_GET_PCIE_TRANS(trans);
1889 struct isr_statistics *isr_stats = &trans_pcie->isr_stats; 1895 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
1890 1896
1891 int pos = 0; 1897 int pos = 0;
@@ -1943,8 +1949,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
1943 size_t count, loff_t *ppos) 1949 size_t count, loff_t *ppos)
1944{ 1950{
1945 struct iwl_trans *trans = file->private_data; 1951 struct iwl_trans *trans = file->private_data;
1946 struct iwl_trans_pcie *trans_pcie = 1952 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
1947 IWL_TRANS_GET_PCIE_TRANS(trans);
1948 struct isr_statistics *isr_stats = &trans_pcie->isr_stats; 1953 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
1949 1954
1950 char buf[8]; 1955 char buf[8];
@@ -1964,8 +1969,8 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
1964} 1969}
1965 1970
1966static ssize_t iwl_dbgfs_csr_write(struct file *file, 1971static ssize_t iwl_dbgfs_csr_write(struct file *file,
1967 const char __user *user_buf, 1972 const char __user *user_buf,
1968 size_t count, loff_t *ppos) 1973 size_t count, loff_t *ppos)
1969{ 1974{
1970 struct iwl_trans *trans = file->private_data; 1975 struct iwl_trans *trans = file->private_data;
1971 char buf[8]; 1976 char buf[8];
@@ -1985,8 +1990,8 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
1985} 1990}
1986 1991
1987static ssize_t iwl_dbgfs_fh_reg_read(struct file *file, 1992static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
1988 char __user *user_buf, 1993 char __user *user_buf,
1989 size_t count, loff_t *ppos) 1994 size_t count, loff_t *ppos)
1990{ 1995{
1991 struct iwl_trans *trans = file->private_data; 1996 struct iwl_trans *trans = file->private_data;
1992 char *buf; 1997 char *buf;
@@ -2029,7 +2034,7 @@ DEBUGFS_WRITE_FILE_OPS(fw_restart);
2029 * 2034 *
2030 */ 2035 */
2031static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans, 2036static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
2032 struct dentry *dir) 2037 struct dentry *dir)
2033{ 2038{
2034 DEBUGFS_ADD_FILE(rx_queue, dir, S_IRUSR); 2039 DEBUGFS_ADD_FILE(rx_queue, dir, S_IRUSR);
2035 DEBUGFS_ADD_FILE(tx_queue, dir, S_IRUSR); 2040 DEBUGFS_ADD_FILE(tx_queue, dir, S_IRUSR);
@@ -2041,9 +2046,10 @@ static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
2041} 2046}
2042#else 2047#else
2043static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans, 2048static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
2044 struct dentry *dir) 2049 struct dentry *dir)
2045{ return 0; } 2050{
2046 2051 return 0;
2052}
2047#endif /*CONFIG_IWLWIFI_DEBUGFS */ 2053#endif /*CONFIG_IWLWIFI_DEBUGFS */
2048 2054
2049static const struct iwl_trans_ops trans_ops_pcie = { 2055static const struct iwl_trans_ops trans_ops_pcie = {
@@ -2060,8 +2066,8 @@ static const struct iwl_trans_ops trans_ops_pcie = {
2060 .tx = iwl_trans_pcie_tx, 2066 .tx = iwl_trans_pcie_tx,
2061 .reclaim = iwl_trans_pcie_reclaim, 2067 .reclaim = iwl_trans_pcie_reclaim,
2062 2068
2063 .tx_agg_disable = iwl_trans_pcie_tx_agg_disable, 2069 .txq_disable = iwl_trans_pcie_txq_disable,
2064 .tx_agg_setup = iwl_trans_pcie_tx_agg_setup, 2070 .txq_enable = iwl_trans_pcie_txq_enable,
2065 2071
2066 .dbgfs_register = iwl_trans_pcie_dbgfs_register, 2072 .dbgfs_register = iwl_trans_pcie_dbgfs_register,
2067 2073
@@ -2084,11 +2090,12 @@ struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
2084{ 2090{
2085 struct iwl_trans_pcie *trans_pcie; 2091 struct iwl_trans_pcie *trans_pcie;
2086 struct iwl_trans *trans; 2092 struct iwl_trans *trans;
2093 char cmd_pool_name[100];
2087 u16 pci_cmd; 2094 u16 pci_cmd;
2088 int err; 2095 int err;
2089 2096
2090 trans = kzalloc(sizeof(struct iwl_trans) + 2097 trans = kzalloc(sizeof(struct iwl_trans) +
2091 sizeof(struct iwl_trans_pcie), GFP_KERNEL); 2098 sizeof(struct iwl_trans_pcie), GFP_KERNEL);
2092 2099
2093 if (WARN_ON(!trans)) 2100 if (WARN_ON(!trans))
2094 return NULL; 2101 return NULL;
@@ -2104,7 +2111,7 @@ struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
2104 /* W/A - seems to solve weird behavior. We need to remove this if we 2111 /* W/A - seems to solve weird behavior. We need to remove this if we
2105 * don't want to stay in L1 all the time. This wastes a lot of power */ 2112 * don't want to stay in L1 all the time. This wastes a lot of power */
2106 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | 2113 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
2107 PCIE_LINK_STATE_CLKPM); 2114 PCIE_LINK_STATE_CLKPM);
2108 2115
2109 if (pci_enable_device(pdev)) { 2116 if (pci_enable_device(pdev)) {
2110 err = -ENODEV; 2117 err = -ENODEV;
@@ -2120,7 +2127,7 @@ struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
2120 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); 2127 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2121 if (!err) 2128 if (!err)
2122 err = pci_set_consistent_dma_mask(pdev, 2129 err = pci_set_consistent_dma_mask(pdev,
2123 DMA_BIT_MASK(32)); 2130 DMA_BIT_MASK(32));
2124 /* both attempts failed: */ 2131 /* both attempts failed: */
2125 if (err) { 2132 if (err) {
2126 dev_printk(KERN_ERR, &pdev->dev, 2133 dev_printk(KERN_ERR, &pdev->dev,
@@ -2143,13 +2150,13 @@ struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
2143 } 2150 }
2144 2151
2145 dev_printk(KERN_INFO, &pdev->dev, 2152 dev_printk(KERN_INFO, &pdev->dev,
2146 "pci_resource_len = 0x%08llx\n", 2153 "pci_resource_len = 0x%08llx\n",
2147 (unsigned long long) pci_resource_len(pdev, 0)); 2154 (unsigned long long) pci_resource_len(pdev, 0));
2148 dev_printk(KERN_INFO, &pdev->dev, 2155 dev_printk(KERN_INFO, &pdev->dev,
2149 "pci_resource_base = %p\n", trans_pcie->hw_base); 2156 "pci_resource_base = %p\n", trans_pcie->hw_base);
2150 2157
2151 dev_printk(KERN_INFO, &pdev->dev, 2158 dev_printk(KERN_INFO, &pdev->dev,
2152 "HW Revision ID = 0x%X\n", pdev->revision); 2159 "HW Revision ID = 0x%X\n", pdev->revision);
2153 2160
2154 /* We disable the RETRY_TIMEOUT register (0x41) to keep 2161 /* We disable the RETRY_TIMEOUT register (0x41) to keep
2155 * PCI Tx retries from interfering with C3 CPU state */ 2162 * PCI Tx retries from interfering with C3 CPU state */
@@ -2158,7 +2165,7 @@ struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
2158 err = pci_enable_msi(pdev); 2165 err = pci_enable_msi(pdev);
2159 if (err) 2166 if (err)
2160 dev_printk(KERN_ERR, &pdev->dev, 2167 dev_printk(KERN_ERR, &pdev->dev,
2161 "pci_enable_msi failed(0X%x)", err); 2168 "pci_enable_msi failed(0X%x)", err);
2162 2169
2163 trans->dev = &pdev->dev; 2170 trans->dev = &pdev->dev;
2164 trans_pcie->irq = pdev->irq; 2171 trans_pcie->irq = pdev->irq;
@@ -2180,8 +2187,25 @@ struct iwl_trans *iwl_trans_pcie_alloc(struct pci_dev *pdev,
2180 init_waitqueue_head(&trans->wait_command_queue); 2187 init_waitqueue_head(&trans->wait_command_queue);
2181 spin_lock_init(&trans->reg_lock); 2188 spin_lock_init(&trans->reg_lock);
2182 2189
2190 snprintf(cmd_pool_name, sizeof(cmd_pool_name), "iwl_cmd_pool:%s",
2191 dev_name(trans->dev));
2192
2193 trans->dev_cmd_headroom = 0;
2194 trans->dev_cmd_pool =
2195 kmem_cache_create(cmd_pool_name,
2196 sizeof(struct iwl_device_cmd)
2197 + trans->dev_cmd_headroom,
2198 sizeof(void *),
2199 SLAB_HWCACHE_ALIGN,
2200 NULL);
2201
2202 if (!trans->dev_cmd_pool)
2203 goto out_pci_disable_msi;
2204
2183 return trans; 2205 return trans;
2184 2206
2207out_pci_disable_msi:
2208 pci_disable_msi(pdev);
2185out_pci_release_regions: 2209out_pci_release_regions:
2186 pci_release_regions(pdev); 2210 pci_release_regions(pdev);
2187out_pci_disable_device: 2211out_pci_disable_device:
@@ -2190,4 +2214,3 @@ out_no_pci:
2190 kfree(trans); 2214 kfree(trans);
2191 return NULL; 2215 return NULL;
2192} 2216}
2193
diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-tx.c b/drivers/net/wireless/iwlwifi/pcie/tx.c
index a8750238ee09..6baf8deef519 100644
--- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie-tx.c
+++ b/drivers/net/wireless/iwlwifi/pcie/tx.c
@@ -34,11 +34,10 @@
34#include "iwl-csr.h" 34#include "iwl-csr.h"
35#include "iwl-prph.h" 35#include "iwl-prph.h"
36#include "iwl-io.h" 36#include "iwl-io.h"
37#include "iwl-agn-hw.h"
38#include "iwl-op-mode.h" 37#include "iwl-op-mode.h"
39#include "iwl-trans-pcie-int.h" 38#include "internal.h"
40/* FIXME: need to abstract out TX command (once we know what it looks like) */ 39/* FIXME: need to abstract out TX command (once we know what it looks like) */
41#include "iwl-commands.h" 40#include "dvm/commands.h"
42 41
43#define IWL_TX_CRC_SIZE 4 42#define IWL_TX_CRC_SIZE 4
44#define IWL_TX_DELIMITER_SIZE 4 43#define IWL_TX_DELIMITER_SIZE 4
@@ -47,12 +46,11 @@
47 * iwl_trans_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array 46 * iwl_trans_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
48 */ 47 */
49void iwl_trans_txq_update_byte_cnt_tbl(struct iwl_trans *trans, 48void iwl_trans_txq_update_byte_cnt_tbl(struct iwl_trans *trans,
50 struct iwl_tx_queue *txq, 49 struct iwl_tx_queue *txq,
51 u16 byte_cnt) 50 u16 byte_cnt)
52{ 51{
53 struct iwlagn_scd_bc_tbl *scd_bc_tbl; 52 struct iwlagn_scd_bc_tbl *scd_bc_tbl;
54 struct iwl_trans_pcie *trans_pcie = 53 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
55 IWL_TRANS_GET_PCIE_TRANS(trans);
56 int write_ptr = txq->q.write_ptr; 54 int write_ptr = txq->q.write_ptr;
57 int txq_id = txq->q.id; 55 int txq_id = txq->q.id;
58 u8 sec_ctl = 0; 56 u8 sec_ctl = 0;
@@ -178,8 +176,8 @@ static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
178 return tfd->num_tbs & 0x1f; 176 return tfd->num_tbs & 0x1f;
179} 177}
180 178
181static void iwlagn_unmap_tfd(struct iwl_trans *trans, struct iwl_cmd_meta *meta, 179static void iwl_unmap_tfd(struct iwl_trans *trans, struct iwl_cmd_meta *meta,
182 struct iwl_tfd *tfd, enum dma_data_direction dma_dir) 180 struct iwl_tfd *tfd, enum dma_data_direction dma_dir)
183{ 181{
184 int i; 182 int i;
185 int num_tbs; 183 int num_tbs;
@@ -209,7 +207,7 @@ static void iwlagn_unmap_tfd(struct iwl_trans *trans, struct iwl_cmd_meta *meta,
209} 207}
210 208
211/** 209/**
212 * iwlagn_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr] 210 * iwl_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
213 * @trans - transport private data 211 * @trans - transport private data
214 * @txq - tx queue 212 * @txq - tx queue
215 * @dma_dir - the direction of the DMA mapping 213 * @dma_dir - the direction of the DMA mapping
@@ -217,8 +215,8 @@ static void iwlagn_unmap_tfd(struct iwl_trans *trans, struct iwl_cmd_meta *meta,
217 * Does NOT advance any TFD circular buffer read/write indexes 215 * Does NOT advance any TFD circular buffer read/write indexes
218 * Does NOT free the TFD itself (which is within circular buffer) 216 * Does NOT free the TFD itself (which is within circular buffer)
219 */ 217 */
220void iwlagn_txq_free_tfd(struct iwl_trans *trans, struct iwl_tx_queue *txq, 218void iwl_txq_free_tfd(struct iwl_trans *trans, struct iwl_tx_queue *txq,
221 enum dma_data_direction dma_dir) 219 enum dma_data_direction dma_dir)
222{ 220{
223 struct iwl_tfd *tfd_tmp = txq->tfds; 221 struct iwl_tfd *tfd_tmp = txq->tfds;
224 222
@@ -229,8 +227,8 @@ void iwlagn_txq_free_tfd(struct iwl_trans *trans, struct iwl_tx_queue *txq,
229 lockdep_assert_held(&txq->lock); 227 lockdep_assert_held(&txq->lock);
230 228
231 /* We have only q->n_window txq->entries, but we use q->n_bd tfds */ 229 /* We have only q->n_window txq->entries, but we use q->n_bd tfds */
232 iwlagn_unmap_tfd(trans, &txq->entries[idx].meta, 230 iwl_unmap_tfd(trans, &txq->entries[idx].meta, &tfd_tmp[rd_ptr],
233 &tfd_tmp[rd_ptr], dma_dir); 231 dma_dir);
234 232
235 /* free SKB */ 233 /* free SKB */
236 if (txq->entries) { 234 if (txq->entries) {
@@ -270,7 +268,7 @@ int iwlagn_txq_attach_buf_to_tfd(struct iwl_trans *trans,
270 /* Each TFD can point to a maximum 20 Tx buffers */ 268 /* Each TFD can point to a maximum 20 Tx buffers */
271 if (num_tbs >= IWL_NUM_OF_TBS) { 269 if (num_tbs >= IWL_NUM_OF_TBS) {
272 IWL_ERR(trans, "Error can not send more than %d chunks\n", 270 IWL_ERR(trans, "Error can not send more than %d chunks\n",
273 IWL_NUM_OF_TBS); 271 IWL_NUM_OF_TBS);
274 return -EINVAL; 272 return -EINVAL;
275 } 273 }
276 274
@@ -279,7 +277,7 @@ int iwlagn_txq_attach_buf_to_tfd(struct iwl_trans *trans,
279 277
280 if (unlikely(addr & ~IWL_TX_DMA_MASK)) 278 if (unlikely(addr & ~IWL_TX_DMA_MASK))
281 IWL_ERR(trans, "Unaligned address = %llx\n", 279 IWL_ERR(trans, "Unaligned address = %llx\n",
282 (unsigned long long)addr); 280 (unsigned long long)addr);
283 281
284 iwl_tfd_set_tb(tfd, num_tbs, addr, len); 282 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
285 283
@@ -382,16 +380,14 @@ static void iwlagn_txq_inval_byte_cnt_tbl(struct iwl_trans *trans,
382 tfd_offset[TFD_QUEUE_SIZE_MAX + read_ptr] = bc_ent; 380 tfd_offset[TFD_QUEUE_SIZE_MAX + read_ptr] = bc_ent;
383} 381}
384 382
385static int iwlagn_tx_queue_set_q2ratid(struct iwl_trans *trans, u16 ra_tid, 383static int iwl_txq_set_ratid_map(struct iwl_trans *trans, u16 ra_tid,
386 u16 txq_id) 384 u16 txq_id)
387{ 385{
386 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
388 u32 tbl_dw_addr; 387 u32 tbl_dw_addr;
389 u32 tbl_dw; 388 u32 tbl_dw;
390 u16 scd_q2ratid; 389 u16 scd_q2ratid;
391 390
392 struct iwl_trans_pcie *trans_pcie =
393 IWL_TRANS_GET_PCIE_TRANS(trans);
394
395 scd_q2ratid = ra_tid & SCD_QUEUE_RA_TID_MAP_RATID_MSK; 391 scd_q2ratid = ra_tid & SCD_QUEUE_RA_TID_MAP_RATID_MSK;
396 392
397 tbl_dw_addr = trans_pcie->scd_base_addr + 393 tbl_dw_addr = trans_pcie->scd_base_addr +
@@ -409,7 +405,7 @@ static int iwlagn_tx_queue_set_q2ratid(struct iwl_trans *trans, u16 ra_tid,
409 return 0; 405 return 0;
410} 406}
411 407
412static void iwlagn_tx_queue_stop_scheduler(struct iwl_trans *trans, u16 txq_id) 408static inline void iwl_txq_set_inactive(struct iwl_trans *trans, u16 txq_id)
413{ 409{
414 /* Simply stop the queue, but don't change any configuration; 410 /* Simply stop the queue, but don't change any configuration;
415 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */ 411 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
@@ -419,102 +415,87 @@ static void iwlagn_tx_queue_stop_scheduler(struct iwl_trans *trans, u16 txq_id)
419 (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN)); 415 (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
420} 416}
421 417
422void iwl_trans_set_wr_ptrs(struct iwl_trans *trans, 418void iwl_trans_pcie_txq_enable(struct iwl_trans *trans, int txq_id, int fifo,
423 int txq_id, u32 index) 419 int sta_id, int tid, int frame_limit, u16 ssn)
424{
425 IWL_DEBUG_TX_QUEUES(trans, "Q %d WrPtr: %d\n", txq_id, index & 0xff);
426 iwl_write_direct32(trans, HBUS_TARG_WRPTR,
427 (index & 0xff) | (txq_id << 8));
428 iwl_write_prph(trans, SCD_QUEUE_RDPTR(txq_id), index);
429}
430
431void iwl_trans_tx_queue_set_status(struct iwl_trans *trans,
432 struct iwl_tx_queue *txq,
433 int tx_fifo_id, bool active)
434{
435 int txq_id = txq->q.id;
436
437 iwl_write_prph(trans, SCD_QUEUE_STATUS_BITS(txq_id),
438 (active << SCD_QUEUE_STTS_REG_POS_ACTIVE) |
439 (tx_fifo_id << SCD_QUEUE_STTS_REG_POS_TXF) |
440 (1 << SCD_QUEUE_STTS_REG_POS_WSL) |
441 SCD_QUEUE_STTS_REG_MSK);
442
443 if (active)
444 IWL_DEBUG_TX_QUEUES(trans, "Activate queue %d on FIFO %d\n",
445 txq_id, tx_fifo_id);
446 else
447 IWL_DEBUG_TX_QUEUES(trans, "Deactivate queue %d\n", txq_id);
448}
449
450void iwl_trans_pcie_tx_agg_setup(struct iwl_trans *trans, int txq_id, int fifo,
451 int sta_id, int tid, int frame_limit, u16 ssn)
452{ 420{
453 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); 421 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
454 unsigned long flags;
455 u16 ra_tid = BUILD_RAxTID(sta_id, tid);
456 422
457 if (test_and_set_bit(txq_id, trans_pcie->queue_used)) 423 if (test_and_set_bit(txq_id, trans_pcie->queue_used))
458 WARN_ONCE(1, "queue %d already used - expect issues", txq_id); 424 WARN_ONCE(1, "queue %d already used - expect issues", txq_id);
459 425
460 spin_lock_irqsave(&trans_pcie->irq_lock, flags);
461
462 /* Stop this Tx queue before configuring it */ 426 /* Stop this Tx queue before configuring it */
463 iwlagn_tx_queue_stop_scheduler(trans, txq_id); 427 iwl_txq_set_inactive(trans, txq_id);
464 428
465 /* Map receiver-address / traffic-ID to this queue */ 429 /* Set this queue as a chain-building queue unless it is CMD queue */
466 iwlagn_tx_queue_set_q2ratid(trans, ra_tid, txq_id); 430 if (txq_id != trans_pcie->cmd_queue)
431 iwl_set_bits_prph(trans, SCD_QUEUECHAIN_SEL, BIT(txq_id));
467 432
468 /* Set this queue as a chain-building queue */ 433 /* If this queue is mapped to a certain station: it is an AGG queue */
469 iwl_set_bits_prph(trans, SCD_QUEUECHAIN_SEL, BIT(txq_id)); 434 if (sta_id != IWL_INVALID_STATION) {
435 u16 ra_tid = BUILD_RAxTID(sta_id, tid);
470 436
471 /* enable aggregations for the queue */ 437 /* Map receiver-address / traffic-ID to this queue */
472 iwl_set_bits_prph(trans, SCD_AGGR_SEL, BIT(txq_id)); 438 iwl_txq_set_ratid_map(trans, ra_tid, txq_id);
439
440 /* enable aggregations for the queue */
441 iwl_set_bits_prph(trans, SCD_AGGR_SEL, BIT(txq_id));
442 } else {
443 /*
444 * disable aggregations for the queue, this will also make the
445 * ra_tid mapping configuration irrelevant since it is now a
446 * non-AGG queue.
447 */
448 iwl_clear_bits_prph(trans, SCD_AGGR_SEL, BIT(txq_id));
449 }
473 450
474 /* Place first TFD at index corresponding to start sequence number. 451 /* Place first TFD at index corresponding to start sequence number.
475 * Assumes that ssn_idx is valid (!= 0xFFF) */ 452 * Assumes that ssn_idx is valid (!= 0xFFF) */
476 trans_pcie->txq[txq_id].q.read_ptr = (ssn & 0xff); 453 trans_pcie->txq[txq_id].q.read_ptr = (ssn & 0xff);
477 trans_pcie->txq[txq_id].q.write_ptr = (ssn & 0xff); 454 trans_pcie->txq[txq_id].q.write_ptr = (ssn & 0xff);
478 iwl_trans_set_wr_ptrs(trans, txq_id, ssn); 455
456 iwl_write_direct32(trans, HBUS_TARG_WRPTR,
457 (ssn & 0xff) | (txq_id << 8));
458 iwl_write_prph(trans, SCD_QUEUE_RDPTR(txq_id), ssn);
479 459
480 /* Set up Tx window size and frame limit for this queue */ 460 /* Set up Tx window size and frame limit for this queue */
481 iwl_write_targ_mem(trans, trans_pcie->scd_base_addr + 461 iwl_write_targ_mem(trans, trans_pcie->scd_base_addr +
462 SCD_CONTEXT_QUEUE_OFFSET(txq_id), 0);
463 iwl_write_targ_mem(trans, trans_pcie->scd_base_addr +
482 SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32), 464 SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
483 ((frame_limit << SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) & 465 ((frame_limit << SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
484 SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) | 466 SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
485 ((frame_limit << SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) & 467 ((frame_limit << SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
486 SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK)); 468 SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
487 469
488 iwl_set_bits_prph(trans, SCD_INTERRUPT_MASK, (1 << txq_id));
489
490 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */ 470 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
491 iwl_trans_tx_queue_set_status(trans, &trans_pcie->txq[txq_id], 471 iwl_write_prph(trans, SCD_QUEUE_STATUS_BITS(txq_id),
492 fifo, true); 472 (1 << SCD_QUEUE_STTS_REG_POS_ACTIVE) |
493 473 (fifo << SCD_QUEUE_STTS_REG_POS_TXF) |
494 spin_unlock_irqrestore(&trans_pcie->irq_lock, flags); 474 (1 << SCD_QUEUE_STTS_REG_POS_WSL) |
475 SCD_QUEUE_STTS_REG_MSK);
476 IWL_DEBUG_TX_QUEUES(trans, "Activate queue %d on FIFO %d WrPtr: %d\n",
477 txq_id, fifo, ssn & 0xff);
495} 478}
496 479
497void iwl_trans_pcie_tx_agg_disable(struct iwl_trans *trans, int txq_id) 480void iwl_trans_pcie_txq_disable(struct iwl_trans *trans, int txq_id)
498{ 481{
499 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans); 482 struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
483 u16 rd_ptr, wr_ptr;
484 int n_bd = trans_pcie->txq[txq_id].q.n_bd;
500 485
501 if (!test_and_clear_bit(txq_id, trans_pcie->queue_used)) { 486 if (!test_and_clear_bit(txq_id, trans_pcie->queue_used)) {
502 WARN_ONCE(1, "queue %d not used", txq_id); 487 WARN_ONCE(1, "queue %d not used", txq_id);
503 return; 488 return;
504 } 489 }
505 490
506 iwlagn_tx_queue_stop_scheduler(trans, txq_id); 491 rd_ptr = iwl_read_prph(trans, SCD_QUEUE_RDPTR(txq_id)) & (n_bd - 1);
507 492 wr_ptr = iwl_read_prph(trans, SCD_QUEUE_WRPTR(txq_id));
508 iwl_clear_bits_prph(trans, SCD_AGGR_SEL, BIT(txq_id));
509 493
510 trans_pcie->txq[txq_id].q.read_ptr = 0; 494 WARN_ONCE(rd_ptr != wr_ptr, "queue %d isn't empty: [%d,%d]",
511 trans_pcie->txq[txq_id].q.write_ptr = 0; 495 txq_id, rd_ptr, wr_ptr);
512 iwl_trans_set_wr_ptrs(trans, txq_id, 0);
513 496
514 iwl_clear_bits_prph(trans, SCD_INTERRUPT_MASK, BIT(txq_id)); 497 iwl_txq_set_inactive(trans, txq_id);
515 498 IWL_DEBUG_TX_QUEUES(trans, "Deactivate queue %d\n", txq_id);
516 iwl_trans_tx_queue_set_status(trans, &trans_pcie->txq[txq_id],
517 0, false);
518} 499}
519 500
520/*************** HOST COMMAND QUEUE FUNCTIONS *****/ 501/*************** HOST COMMAND QUEUE FUNCTIONS *****/
@@ -615,13 +596,13 @@ static int iwl_enqueue_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
615 } 596 }
616 597
617 IWL_DEBUG_HC(trans, 598 IWL_DEBUG_HC(trans,
618 "Sending command %s (#%x), seq: 0x%04X, %d bytes at %d[%d]:%d\n", 599 "Sending command %s (#%x), seq: 0x%04X, %d bytes at %d[%d]:%d\n",
619 trans_pcie_get_cmd_string(trans_pcie, out_cmd->hdr.cmd), 600 trans_pcie_get_cmd_string(trans_pcie, out_cmd->hdr.cmd),
620 out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), cmd_size, 601 out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence),
621 q->write_ptr, idx, trans_pcie->cmd_queue); 602 cmd_size, q->write_ptr, idx, trans_pcie->cmd_queue);
622 603
623 phys_addr = dma_map_single(trans->dev, &out_cmd->hdr, copy_size, 604 phys_addr = dma_map_single(trans->dev, &out_cmd->hdr, copy_size,
624 DMA_BIDIRECTIONAL); 605 DMA_BIDIRECTIONAL);
625 if (unlikely(dma_mapping_error(trans->dev, phys_addr))) { 606 if (unlikely(dma_mapping_error(trans->dev, phys_addr))) {
626 idx = -ENOMEM; 607 idx = -ENOMEM;
627 goto out; 608 goto out;
@@ -630,8 +611,7 @@ static int iwl_enqueue_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
630 dma_unmap_addr_set(out_meta, mapping, phys_addr); 611 dma_unmap_addr_set(out_meta, mapping, phys_addr);
631 dma_unmap_len_set(out_meta, len, copy_size); 612 dma_unmap_len_set(out_meta, len, copy_size);
632 613
633 iwlagn_txq_attach_buf_to_tfd(trans, txq, 614 iwlagn_txq_attach_buf_to_tfd(trans, txq, phys_addr, copy_size, 1);
634 phys_addr, copy_size, 1);
635#ifdef CONFIG_IWLWIFI_DEVICE_TRACING 615#ifdef CONFIG_IWLWIFI_DEVICE_TRACING
636 trace_bufs[0] = &out_cmd->hdr; 616 trace_bufs[0] = &out_cmd->hdr;
637 trace_lens[0] = copy_size; 617 trace_lens[0] = copy_size;
@@ -643,13 +623,12 @@ static int iwl_enqueue_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
643 continue; 623 continue;
644 if (!(cmd->dataflags[i] & IWL_HCMD_DFL_NOCOPY)) 624 if (!(cmd->dataflags[i] & IWL_HCMD_DFL_NOCOPY))
645 continue; 625 continue;
646 phys_addr = dma_map_single(trans->dev, 626 phys_addr = dma_map_single(trans->dev, (void *)cmd->data[i],
647 (void *)cmd->data[i],
648 cmd->len[i], DMA_BIDIRECTIONAL); 627 cmd->len[i], DMA_BIDIRECTIONAL);
649 if (dma_mapping_error(trans->dev, phys_addr)) { 628 if (dma_mapping_error(trans->dev, phys_addr)) {
650 iwlagn_unmap_tfd(trans, out_meta, 629 iwl_unmap_tfd(trans, out_meta,
651 &txq->tfds[q->write_ptr], 630 &txq->tfds[q->write_ptr],
652 DMA_BIDIRECTIONAL); 631 DMA_BIDIRECTIONAL);
653 idx = -ENOMEM; 632 idx = -ENOMEM;
654 goto out; 633 goto out;
655 } 634 }
@@ -723,9 +702,10 @@ static void iwl_hcmd_queue_reclaim(struct iwl_trans *trans, int txq_id,
723 lockdep_assert_held(&txq->lock); 702 lockdep_assert_held(&txq->lock);
724 703
725 if ((idx >= q->n_bd) || (iwl_queue_used(q, idx) == 0)) { 704 if ((idx >= q->n_bd) || (iwl_queue_used(q, idx) == 0)) {
726 IWL_ERR(trans, "%s: Read index for DMA queue txq id (%d), " 705 IWL_ERR(trans,
727 "index %d is out of range [0-%d] %d %d.\n", __func__, 706 "%s: Read index for DMA queue txq id (%d), index %d is out of range [0-%d] %d %d.\n",
728 txq_id, idx, q->n_bd, q->write_ptr, q->read_ptr); 707 __func__, txq_id, idx, q->n_bd,
708 q->write_ptr, q->read_ptr);
729 return; 709 return;
730 } 710 }
731 711
@@ -733,8 +713,8 @@ static void iwl_hcmd_queue_reclaim(struct iwl_trans *trans, int txq_id,
733 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { 713 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
734 714
735 if (nfreed++ > 0) { 715 if (nfreed++ > 0) {
736 IWL_ERR(trans, "HCMD skipped: index (%d) %d %d\n", idx, 716 IWL_ERR(trans, "HCMD skipped: index (%d) %d %d\n",
737 q->write_ptr, q->read_ptr); 717 idx, q->write_ptr, q->read_ptr);
738 iwl_op_mode_nic_error(trans->op_mode); 718 iwl_op_mode_nic_error(trans->op_mode);
739 } 719 }
740 720
@@ -771,9 +751,9 @@ void iwl_tx_cmd_complete(struct iwl_trans *trans, struct iwl_rx_cmd_buffer *rxb,
771 * in the queue management code. */ 751 * in the queue management code. */
772 if (WARN(txq_id != trans_pcie->cmd_queue, 752 if (WARN(txq_id != trans_pcie->cmd_queue,
773 "wrong command queue %d (should be %d), sequence 0x%X readp=%d writep=%d\n", 753 "wrong command queue %d (should be %d), sequence 0x%X readp=%d writep=%d\n",
774 txq_id, trans_pcie->cmd_queue, sequence, 754 txq_id, trans_pcie->cmd_queue, sequence,
775 trans_pcie->txq[trans_pcie->cmd_queue].q.read_ptr, 755 trans_pcie->txq[trans_pcie->cmd_queue].q.read_ptr,
776 trans_pcie->txq[trans_pcie->cmd_queue].q.write_ptr)) { 756 trans_pcie->txq[trans_pcie->cmd_queue].q.write_ptr)) {
777 iwl_print_hex_error(trans, pkt, 32); 757 iwl_print_hex_error(trans, pkt, 32);
778 return; 758 return;
779 } 759 }
@@ -784,8 +764,7 @@ void iwl_tx_cmd_complete(struct iwl_trans *trans, struct iwl_rx_cmd_buffer *rxb,
784 cmd = txq->entries[cmd_index].cmd; 764 cmd = txq->entries[cmd_index].cmd;
785 meta = &txq->entries[cmd_index].meta; 765 meta = &txq->entries[cmd_index].meta;
786 766
787 iwlagn_unmap_tfd(trans, meta, &txq->tfds[index], 767 iwl_unmap_tfd(trans, meta, &txq->tfds[index], DMA_BIDIRECTIONAL);
788 DMA_BIDIRECTIONAL);
789 768
790 /* Input error checking is done when commands are added to queue. */ 769 /* Input error checking is done when commands are added to queue. */
791 if (meta->flags & CMD_WANT_SKB) { 770 if (meta->flags & CMD_WANT_SKB) {
@@ -870,8 +849,9 @@ static int iwl_send_cmd_sync(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
870 } 849 }
871 850
872 ret = wait_event_timeout(trans->wait_command_queue, 851 ret = wait_event_timeout(trans->wait_command_queue,
873 !test_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status), 852 !test_bit(STATUS_HCMD_ACTIVE,
874 HOST_COMPLETE_TIMEOUT); 853 &trans_pcie->status),
854 HOST_COMPLETE_TIMEOUT);
875 if (!ret) { 855 if (!ret) {
876 if (test_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status)) { 856 if (test_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status)) {
877 struct iwl_tx_queue *txq = 857 struct iwl_tx_queue *txq =
@@ -956,10 +936,10 @@ int iwl_tx_queue_reclaim(struct iwl_trans *trans, int txq_id, int index,
956 936
957 if ((index >= q->n_bd) || 937 if ((index >= q->n_bd) ||
958 (iwl_queue_used(q, last_to_free) == 0)) { 938 (iwl_queue_used(q, last_to_free) == 0)) {
959 IWL_ERR(trans, "%s: Read index for DMA queue txq id (%d), " 939 IWL_ERR(trans,
960 "last_to_free %d is out of range [0-%d] %d %d.\n", 940 "%s: Read index for DMA queue txq id (%d), last_to_free %d is out of range [0-%d] %d %d.\n",
961 __func__, txq_id, last_to_free, q->n_bd, 941 __func__, txq_id, last_to_free, q->n_bd,
962 q->write_ptr, q->read_ptr); 942 q->write_ptr, q->read_ptr);
963 return 0; 943 return 0;
964 } 944 }
965 945
@@ -979,7 +959,7 @@ int iwl_tx_queue_reclaim(struct iwl_trans *trans, int txq_id, int index,
979 959
980 iwlagn_txq_inval_byte_cnt_tbl(trans, txq); 960 iwlagn_txq_inval_byte_cnt_tbl(trans, txq);
981 961
982 iwlagn_txq_free_tfd(trans, txq, DMA_TO_DEVICE); 962 iwl_txq_free_tfd(trans, txq, DMA_TO_DEVICE);
983 freed++; 963 freed++;
984 } 964 }
985 965
diff --git a/drivers/net/wireless/libertas/cfg.c b/drivers/net/wireless/libertas/cfg.c
index 2fa879b015b6..f4a203049fb4 100644
--- a/drivers/net/wireless/libertas/cfg.c
+++ b/drivers/net/wireless/libertas/cfg.c
@@ -435,24 +435,40 @@ static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len)
435 * Set Channel 435 * Set Channel
436 */ 436 */
437 437
438static int lbs_cfg_set_channel(struct wiphy *wiphy, 438static int lbs_cfg_set_monitor_channel(struct wiphy *wiphy,
439 struct net_device *netdev, 439 struct ieee80211_channel *channel,
440 struct ieee80211_channel *channel, 440 enum nl80211_channel_type channel_type)
441 enum nl80211_channel_type channel_type)
442{ 441{
443 struct lbs_private *priv = wiphy_priv(wiphy); 442 struct lbs_private *priv = wiphy_priv(wiphy);
444 int ret = -ENOTSUPP; 443 int ret = -ENOTSUPP;
445 444
446 lbs_deb_enter_args(LBS_DEB_CFG80211, "iface %s freq %d, type %d", 445 lbs_deb_enter_args(LBS_DEB_CFG80211, "freq %d, type %d",
447 netdev_name(netdev), channel->center_freq, channel_type); 446 channel->center_freq, channel_type);
448 447
449 if (channel_type != NL80211_CHAN_NO_HT) 448 if (channel_type != NL80211_CHAN_NO_HT)
450 goto out; 449 goto out;
451 450
452 if (netdev == priv->mesh_dev) 451 ret = lbs_set_channel(priv, channel->hw_value);
453 ret = lbs_mesh_set_channel(priv, channel->hw_value); 452
454 else 453 out:
455 ret = lbs_set_channel(priv, channel->hw_value); 454 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
455 return ret;
456}
457
458static int lbs_cfg_set_mesh_channel(struct wiphy *wiphy,
459 struct net_device *netdev,
460 struct ieee80211_channel *channel)
461{
462 struct lbs_private *priv = wiphy_priv(wiphy);
463 int ret = -ENOTSUPP;
464
465 lbs_deb_enter_args(LBS_DEB_CFG80211, "iface %s freq %d",
466 netdev_name(netdev), channel->center_freq);
467
468 if (netdev != priv->mesh_dev)
469 goto out;
470
471 ret = lbs_mesh_set_channel(priv, channel->hw_value);
456 472
457 out: 473 out:
458 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret); 474 lbs_deb_leave_args(LBS_DEB_CFG80211, "ret %d", ret);
@@ -2029,7 +2045,8 @@ static int lbs_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2029 */ 2045 */
2030 2046
2031static struct cfg80211_ops lbs_cfg80211_ops = { 2047static struct cfg80211_ops lbs_cfg80211_ops = {
2032 .set_channel = lbs_cfg_set_channel, 2048 .set_monitor_channel = lbs_cfg_set_monitor_channel,
2049 .libertas_set_mesh_channel = lbs_cfg_set_mesh_channel,
2033 .scan = lbs_cfg_scan, 2050 .scan = lbs_cfg_scan,
2034 .connect = lbs_cfg_connect, 2051 .connect = lbs_cfg_connect,
2035 .disconnect = lbs_cfg_disconnect, 2052 .disconnect = lbs_cfg_disconnect,
diff --git a/drivers/net/wireless/libertas/dev.h b/drivers/net/wireless/libertas/dev.h
index 672005430aca..60996ce89f77 100644
--- a/drivers/net/wireless/libertas/dev.h
+++ b/drivers/net/wireless/libertas/dev.h
@@ -58,6 +58,7 @@ struct lbs_private {
58 uint16_t mesh_tlv; 58 uint16_t mesh_tlv;
59 u8 mesh_ssid[IEEE80211_MAX_SSID_LEN + 1]; 59 u8 mesh_ssid[IEEE80211_MAX_SSID_LEN + 1];
60 u8 mesh_ssid_len; 60 u8 mesh_ssid_len;
61 u8 mesh_channel;
61#endif 62#endif
62 63
63 /* Debugfs */ 64 /* Debugfs */
diff --git a/drivers/net/wireless/libertas/mesh.c b/drivers/net/wireless/libertas/mesh.c
index e87c031b298f..97807751ebcf 100644
--- a/drivers/net/wireless/libertas/mesh.c
+++ b/drivers/net/wireless/libertas/mesh.c
@@ -131,16 +131,13 @@ static int lbs_mesh_config(struct lbs_private *priv, uint16_t action,
131 131
132int lbs_mesh_set_channel(struct lbs_private *priv, u8 channel) 132int lbs_mesh_set_channel(struct lbs_private *priv, u8 channel)
133{ 133{
134 priv->mesh_channel = channel;
134 return lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, channel); 135 return lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, channel);
135} 136}
136 137
137static uint16_t lbs_mesh_get_channel(struct lbs_private *priv) 138static uint16_t lbs_mesh_get_channel(struct lbs_private *priv)
138{ 139{
139 struct wireless_dev *mesh_wdev = priv->mesh_dev->ieee80211_ptr; 140 return priv->mesh_channel ?: 1;
140 if (mesh_wdev->channel)
141 return mesh_wdev->channel->hw_value;
142 else
143 return 1;
144} 141}
145 142
146/*************************************************************************** 143/***************************************************************************
diff --git a/drivers/net/wireless/mwifiex/init.c b/drivers/net/wireless/mwifiex/init.c
index c1cb004db913..0f18ef6a30c8 100644
--- a/drivers/net/wireless/mwifiex/init.c
+++ b/drivers/net/wireless/mwifiex/init.c
@@ -57,6 +57,68 @@ static int mwifiex_add_bss_prio_tbl(struct mwifiex_private *priv)
57 return 0; 57 return 0;
58} 58}
59 59
60static void scan_delay_timer_fn(unsigned long data)
61{
62 struct mwifiex_private *priv = (struct mwifiex_private *)data;
63 struct mwifiex_adapter *adapter = priv->adapter;
64 struct cmd_ctrl_node *cmd_node, *tmp_node;
65 unsigned long flags;
66
67 if (!mwifiex_wmm_lists_empty(adapter)) {
68 if (adapter->scan_delay_cnt == MWIFIEX_MAX_SCAN_DELAY_CNT) {
69 /*
70 * Abort scan operation by cancelling all pending scan
71 * command
72 */
73 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
74 list_for_each_entry_safe(cmd_node, tmp_node,
75 &adapter->scan_pending_q,
76 list) {
77 list_del(&cmd_node->list);
78 cmd_node->wait_q_enabled = false;
79 mwifiex_insert_cmd_to_free_q(adapter, cmd_node);
80 }
81 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
82 flags);
83
84 spin_lock_irqsave(&adapter->mwifiex_cmd_lock, flags);
85 adapter->scan_processing = false;
86 spin_unlock_irqrestore(&adapter->mwifiex_cmd_lock,
87 flags);
88
89 if (priv->user_scan_cfg) {
90 dev_dbg(priv->adapter->dev,
91 "info: %s: scan aborted\n", __func__);
92 cfg80211_scan_done(priv->scan_request, 1);
93 priv->scan_request = NULL;
94 kfree(priv->user_scan_cfg);
95 priv->user_scan_cfg = NULL;
96 }
97 } else {
98 /*
99 * Tx data queue is still not empty, delay scan
100 * operation further by 20msec.
101 */
102 mod_timer(&priv->scan_delay_timer, jiffies +
103 msecs_to_jiffies(MWIFIEX_SCAN_DELAY_MSEC));
104 adapter->scan_delay_cnt++;
105 }
106 } else {
107 /*
108 * Tx data queue is empty. Get scan command from scan_pending_q
109 * and put to cmd_pending_q to resume scan operation
110 */
111 adapter->scan_delay_cnt = 0;
112 spin_lock_irqsave(&adapter->scan_pending_q_lock, flags);
113 cmd_node = list_first_entry(&adapter->scan_pending_q,
114 struct cmd_ctrl_node, list);
115 list_del(&cmd_node->list);
116 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags);
117
118 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true);
119 }
120}
121
60/* 122/*
61 * This function initializes the private structure and sets default 123 * This function initializes the private structure and sets default
62 * values to the members. 124 * values to the members.
@@ -136,6 +198,9 @@ static int mwifiex_init_priv(struct mwifiex_private *priv)
136 198
137 priv->scan_block = false; 199 priv->scan_block = false;
138 200
201 setup_timer(&priv->scan_delay_timer, scan_delay_timer_fn,
202 (unsigned long)priv);
203
139 return mwifiex_add_bss_prio_tbl(priv); 204 return mwifiex_add_bss_prio_tbl(priv);
140} 205}
141 206
diff --git a/drivers/net/wireless/mwifiex/main.c b/drivers/net/wireless/mwifiex/main.c
index 3192855c31c0..0f06f07a70e6 100644
--- a/drivers/net/wireless/mwifiex/main.c
+++ b/drivers/net/wireless/mwifiex/main.c
@@ -244,8 +244,8 @@ process_start:
244 } 244 }
245 } 245 }
246 246
247 if (!adapter->scan_processing && !adapter->data_sent && 247 if ((!adapter->scan_processing || adapter->scan_delay_cnt) &&
248 !mwifiex_wmm_lists_empty(adapter)) { 248 !adapter->data_sent && !mwifiex_wmm_lists_empty(adapter)) {
249 mwifiex_wmm_process_tx(adapter); 249 mwifiex_wmm_process_tx(adapter);
250 if (adapter->hs_activated) { 250 if (adapter->hs_activated) {
251 adapter->is_hs_configured = false; 251 adapter->is_hs_configured = false;
diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
index bd3b0bf94b9e..5b32221077c4 100644
--- a/drivers/net/wireless/mwifiex/main.h
+++ b/drivers/net/wireless/mwifiex/main.h
@@ -79,14 +79,17 @@ enum {
79 79
80#define SCAN_BEACON_ENTRY_PAD 6 80#define SCAN_BEACON_ENTRY_PAD 6
81 81
82#define MWIFIEX_PASSIVE_SCAN_CHAN_TIME 200 82#define MWIFIEX_PASSIVE_SCAN_CHAN_TIME 110
83#define MWIFIEX_ACTIVE_SCAN_CHAN_TIME 200 83#define MWIFIEX_ACTIVE_SCAN_CHAN_TIME 30
84#define MWIFIEX_SPECIFIC_SCAN_CHAN_TIME 110 84#define MWIFIEX_SPECIFIC_SCAN_CHAN_TIME 30
85 85
86#define SCAN_RSSI(RSSI) (0x100 - ((u8)(RSSI))) 86#define SCAN_RSSI(RSSI) (0x100 - ((u8)(RSSI)))
87 87
88#define MWIFIEX_MAX_TOTAL_SCAN_TIME (MWIFIEX_TIMER_10S - MWIFIEX_TIMER_1S) 88#define MWIFIEX_MAX_TOTAL_SCAN_TIME (MWIFIEX_TIMER_10S - MWIFIEX_TIMER_1S)
89 89
90#define MWIFIEX_MAX_SCAN_DELAY_CNT 50
91#define MWIFIEX_SCAN_DELAY_MSEC 20
92
90#define RSN_GTK_OUI_OFFSET 2 93#define RSN_GTK_OUI_OFFSET 2
91 94
92#define MWIFIEX_OUI_NOT_PRESENT 0 95#define MWIFIEX_OUI_NOT_PRESENT 0
@@ -482,6 +485,7 @@ struct mwifiex_private {
482 u16 proberesp_idx; 485 u16 proberesp_idx;
483 u16 assocresp_idx; 486 u16 assocresp_idx;
484 u16 rsn_idx; 487 u16 rsn_idx;
488 struct timer_list scan_delay_timer;
485}; 489};
486 490
487enum mwifiex_ba_status { 491enum mwifiex_ba_status {
@@ -686,6 +690,7 @@ struct mwifiex_adapter {
686 struct completion fw_load; 690 struct completion fw_load;
687 u8 country_code[IEEE80211_COUNTRY_STRING_LEN]; 691 u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
688 u16 max_mgmt_ie_index; 692 u16 max_mgmt_ie_index;
693 u8 scan_delay_cnt;
689}; 694};
690 695
691int mwifiex_init_lock_list(struct mwifiex_adapter *adapter); 696int mwifiex_init_lock_list(struct mwifiex_adapter *adapter);
diff --git a/drivers/net/wireless/mwifiex/scan.c b/drivers/net/wireless/mwifiex/scan.c
index 74f045715723..efaf26ccd6ba 100644
--- a/drivers/net/wireless/mwifiex/scan.c
+++ b/drivers/net/wireless/mwifiex/scan.c
@@ -28,7 +28,10 @@
28/* The maximum number of channels the firmware can scan per command */ 28/* The maximum number of channels the firmware can scan per command */
29#define MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN 14 29#define MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN 14
30 30
31#define MWIFIEX_CHANNELS_PER_SCAN_CMD 4 31#define MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD 4
32#define MWIFIEX_LIMIT_1_CHANNEL_PER_SCAN_CMD 15
33#define MWIFIEX_LIMIT_2_CHANNELS_PER_SCAN_CMD 27
34#define MWIFIEX_LIMIT_3_CHANNELS_PER_SCAN_CMD 35
32 35
33/* Memory needed to store a max sized Channel List TLV for a firmware scan */ 36/* Memory needed to store a max sized Channel List TLV for a firmware scan */
34#define CHAN_TLV_MAX_SIZE (sizeof(struct mwifiex_ie_types_header) \ 37#define CHAN_TLV_MAX_SIZE (sizeof(struct mwifiex_ie_types_header) \
@@ -471,7 +474,7 @@ mwifiex_is_network_compatible(struct mwifiex_private *priv,
471 * This routine is used for any scan that is not provided with a 474 * This routine is used for any scan that is not provided with a
472 * specific channel list to scan. 475 * specific channel list to scan.
473 */ 476 */
474static void 477static int
475mwifiex_scan_create_channel_list(struct mwifiex_private *priv, 478mwifiex_scan_create_channel_list(struct mwifiex_private *priv,
476 const struct mwifiex_user_scan_cfg 479 const struct mwifiex_user_scan_cfg
477 *user_scan_in, 480 *user_scan_in,
@@ -528,6 +531,7 @@ mwifiex_scan_create_channel_list(struct mwifiex_private *priv,
528 } 531 }
529 532
530 } 533 }
534 return chan_idx;
531} 535}
532 536
533/* 537/*
@@ -727,6 +731,7 @@ mwifiex_config_scan(struct mwifiex_private *priv,
727 u32 num_probes; 731 u32 num_probes;
728 u32 ssid_len; 732 u32 ssid_len;
729 u32 chan_idx; 733 u32 chan_idx;
734 u32 chan_num;
730 u32 scan_type; 735 u32 scan_type;
731 u16 scan_dur; 736 u16 scan_dur;
732 u8 channel; 737 u8 channel;
@@ -850,7 +855,7 @@ mwifiex_config_scan(struct mwifiex_private *priv,
850 if (*filtered_scan) 855 if (*filtered_scan)
851 *max_chan_per_scan = MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN; 856 *max_chan_per_scan = MWIFIEX_MAX_CHANNELS_PER_SPECIFIC_SCAN;
852 else 857 else
853 *max_chan_per_scan = MWIFIEX_CHANNELS_PER_SCAN_CMD; 858 *max_chan_per_scan = MWIFIEX_DEF_CHANNELS_PER_SCAN_CMD;
854 859
855 /* If the input config or adapter has the number of Probes set, 860 /* If the input config or adapter has the number of Probes set,
856 add tlv */ 861 add tlv */
@@ -962,13 +967,28 @@ mwifiex_config_scan(struct mwifiex_private *priv,
962 dev_dbg(adapter->dev, 967 dev_dbg(adapter->dev,
963 "info: Scan: Scanning current channel only\n"); 968 "info: Scan: Scanning current channel only\n");
964 } 969 }
965 970 chan_num = chan_idx;
966 } else { 971 } else {
967 dev_dbg(adapter->dev, 972 dev_dbg(adapter->dev,
968 "info: Scan: Creating full region channel list\n"); 973 "info: Scan: Creating full region channel list\n");
969 mwifiex_scan_create_channel_list(priv, user_scan_in, 974 chan_num = mwifiex_scan_create_channel_list(priv, user_scan_in,
970 scan_chan_list, 975 scan_chan_list,
971 *filtered_scan); 976 *filtered_scan);
977 }
978
979 /*
980 * In associated state we will reduce the number of channels scanned per
981 * scan command to avoid any traffic delay/loss. This number is decided
982 * based on total number of channels to be scanned due to constraints
983 * of command buffers.
984 */
985 if (priv->media_connected) {
986 if (chan_num < MWIFIEX_LIMIT_1_CHANNEL_PER_SCAN_CMD)
987 *max_chan_per_scan = 1;
988 else if (chan_num < MWIFIEX_LIMIT_2_CHANNELS_PER_SCAN_CMD)
989 *max_chan_per_scan = 2;
990 else if (chan_num < MWIFIEX_LIMIT_3_CHANNELS_PER_SCAN_CMD)
991 *max_chan_per_scan = 3;
972 } 992 }
973} 993}
974 994
@@ -1772,14 +1792,23 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
1772 priv->user_scan_cfg = NULL; 1792 priv->user_scan_cfg = NULL;
1773 } 1793 }
1774 } else { 1794 } else {
1775 /* Get scan command from scan_pending_q and put to 1795 if (!mwifiex_wmm_lists_empty(adapter)) {
1776 cmd_pending_q */ 1796 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1777 cmd_node = list_first_entry(&adapter->scan_pending_q, 1797 flags);
1778 struct cmd_ctrl_node, list); 1798 adapter->scan_delay_cnt = 1;
1779 list_del(&cmd_node->list); 1799 mod_timer(&priv->scan_delay_timer, jiffies +
1780 spin_unlock_irqrestore(&adapter->scan_pending_q_lock, flags); 1800 msecs_to_jiffies(MWIFIEX_SCAN_DELAY_MSEC));
1781 1801 } else {
1782 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node, true); 1802 /* Get scan command from scan_pending_q and put to
1803 cmd_pending_q */
1804 cmd_node = list_first_entry(&adapter->scan_pending_q,
1805 struct cmd_ctrl_node, list);
1806 list_del(&cmd_node->list);
1807 spin_unlock_irqrestore(&adapter->scan_pending_q_lock,
1808 flags);
1809 mwifiex_insert_cmd_to_pending_q(adapter, cmd_node,
1810 true);
1811 }
1783 } 1812 }
1784 1813
1785done: 1814done:
diff --git a/drivers/net/wireless/orinoco/cfg.c b/drivers/net/wireless/orinoco/cfg.c
index f7b15b8934fa..e15675585fb1 100644
--- a/drivers/net/wireless/orinoco/cfg.c
+++ b/drivers/net/wireless/orinoco/cfg.c
@@ -160,10 +160,9 @@ static int orinoco_scan(struct wiphy *wiphy, struct net_device *dev,
160 return err; 160 return err;
161} 161}
162 162
163static int orinoco_set_channel(struct wiphy *wiphy, 163static int orinoco_set_monitor_channel(struct wiphy *wiphy,
164 struct net_device *netdev, 164 struct ieee80211_channel *chan,
165 struct ieee80211_channel *chan, 165 enum nl80211_channel_type channel_type)
166 enum nl80211_channel_type channel_type)
167{ 166{
168 struct orinoco_private *priv = wiphy_priv(wiphy); 167 struct orinoco_private *priv = wiphy_priv(wiphy);
169 int err = 0; 168 int err = 0;
@@ -286,7 +285,7 @@ static int orinoco_set_wiphy_params(struct wiphy *wiphy, u32 changed)
286 285
287const struct cfg80211_ops orinoco_cfg_ops = { 286const struct cfg80211_ops orinoco_cfg_ops = {
288 .change_virtual_intf = orinoco_change_vif, 287 .change_virtual_intf = orinoco_change_vif,
289 .set_channel = orinoco_set_channel, 288 .set_monitor_channel = orinoco_set_monitor_channel,
290 .scan = orinoco_scan, 289 .scan = orinoco_scan,
291 .set_wiphy_params = orinoco_set_wiphy_params, 290 .set_wiphy_params = orinoco_set_wiphy_params,
292}; 291};
diff --git a/drivers/net/wireless/rt2x00/rt2800.h b/drivers/net/wireless/rt2x00/rt2800.h
index 9348521e0832..1ca88cdc6ece 100644
--- a/drivers/net/wireless/rt2x00/rt2800.h
+++ b/drivers/net/wireless/rt2x00/rt2800.h
@@ -51,6 +51,7 @@
51 * RF3320 2.4G 1T1R(RT3350/RT3370/RT3390) 51 * RF3320 2.4G 1T1R(RT3350/RT3370/RT3390)
52 * RF3322 2.4G 2T2R(RT3352/RT3371/RT3372/RT3391/RT3392) 52 * RF3322 2.4G 2T2R(RT3352/RT3371/RT3372/RT3391/RT3392)
53 * RF3053 2.4G/5G 3T3R(RT3883/RT3563/RT3573/RT3593/RT3662) 53 * RF3053 2.4G/5G 3T3R(RT3883/RT3563/RT3573/RT3593/RT3662)
54 * RF5360 2.4G 1T1R
54 * RF5370 2.4G 1T1R 55 * RF5370 2.4G 1T1R
55 * RF5390 2.4G 1T1R 56 * RF5390 2.4G 1T1R
56 */ 57 */
@@ -67,9 +68,11 @@
67#define RF3320 0x000b 68#define RF3320 0x000b
68#define RF3322 0x000c 69#define RF3322 0x000c
69#define RF3053 0x000d 70#define RF3053 0x000d
71#define RF5360 0x5360
70#define RF5370 0x5370 72#define RF5370 0x5370
71#define RF5372 0x5372 73#define RF5372 0x5372
72#define RF5390 0x5390 74#define RF5390 0x5390
75#define RF5392 0x5392
73 76
74/* 77/*
75 * Chipset revisions. 78 * Chipset revisions.
@@ -1944,6 +1947,11 @@ struct mac_iveiv_entry {
1944#define RFCSR49_TX FIELD8(0x3f) 1947#define RFCSR49_TX FIELD8(0x3f)
1945 1948
1946/* 1949/*
1950 * RFCSR 50:
1951 */
1952#define RFCSR50_TX FIELD8(0x3f)
1953
1954/*
1947 * RF registers 1955 * RF registers
1948 */ 1956 */
1949 1957
diff --git a/drivers/net/wireless/rt2x00/rt2800lib.c b/drivers/net/wireless/rt2x00/rt2800lib.c
index dfc90d34be6d..4d3747c3010b 100644
--- a/drivers/net/wireless/rt2x00/rt2800lib.c
+++ b/drivers/net/wireless/rt2x00/rt2800lib.c
@@ -1958,7 +1958,22 @@ static void rt2800_config_channel_rf53xx(struct rt2x00_dev *rt2x00dev,
1958 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1); 1958 rt2x00_set_field8(&rfcsr, RFCSR49_TX, info->default_power1);
1959 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr); 1959 rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
1960 1960
1961 if (rt2x00_rt(rt2x00dev, RT5392)) {
1962 rt2800_rfcsr_read(rt2x00dev, 50, &rfcsr);
1963 if (info->default_power1 > RT5390_POWER_BOUND)
1964 rt2x00_set_field8(&rfcsr, RFCSR50_TX,
1965 RT5390_POWER_BOUND);
1966 else
1967 rt2x00_set_field8(&rfcsr, RFCSR50_TX,
1968 info->default_power2);
1969 rt2800_rfcsr_write(rt2x00dev, 50, rfcsr);
1970 }
1971
1961 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr); 1972 rt2800_rfcsr_read(rt2x00dev, 1, &rfcsr);
1973 if (rt2x00_rt(rt2x00dev, RT5392)) {
1974 rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
1975 rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
1976 }
1962 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1); 1977 rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
1963 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1); 1978 rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
1964 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1); 1979 rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
@@ -2060,9 +2075,11 @@ static void rt2800_config_channel(struct rt2x00_dev *rt2x00dev,
2060 case RF3052: 2075 case RF3052:
2061 rt2800_config_channel_rf3052(rt2x00dev, conf, rf, info); 2076 rt2800_config_channel_rf3052(rt2x00dev, conf, rf, info);
2062 break; 2077 break;
2078 case RF5360:
2063 case RF5370: 2079 case RF5370:
2064 case RF5372: 2080 case RF5372:
2065 case RF5390: 2081 case RF5390:
2082 case RF5392:
2066 rt2800_config_channel_rf53xx(rt2x00dev, conf, rf, info); 2083 rt2800_config_channel_rf53xx(rt2x00dev, conf, rf, info);
2067 break; 2084 break;
2068 default: 2085 default:
@@ -2549,9 +2566,11 @@ void rt2800_vco_calibration(struct rt2x00_dev *rt2x00dev)
2549 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1); 2566 rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
2550 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr); 2567 rt2800_rfcsr_write(rt2x00dev, 7, rfcsr);
2551 break; 2568 break;
2569 case RF5360:
2552 case RF5370: 2570 case RF5370:
2553 case RF5372: 2571 case RF5372:
2554 case RF5390: 2572 case RF5390:
2573 case RF5392:
2555 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr); 2574 rt2800_rfcsr_read(rt2x00dev, 3, &rfcsr);
2556 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1); 2575 rt2x00_set_field8(&rfcsr, RFCSR30_RF_CALIBRATION, 1);
2557 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr); 2576 rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
@@ -4263,9 +4282,11 @@ int rt2800_init_eeprom(struct rt2x00_dev *rt2x00dev)
4263 case RF3022: 4282 case RF3022:
4264 case RF3052: 4283 case RF3052:
4265 case RF3320: 4284 case RF3320:
4285 case RF5360:
4266 case RF5370: 4286 case RF5370:
4267 case RF5372: 4287 case RF5372:
4268 case RF5390: 4288 case RF5390:
4289 case RF5392:
4269 break; 4290 break;
4270 default: 4291 default:
4271 ERROR(rt2x00dev, "Invalid RF chipset 0x%04x detected.\n", 4292 ERROR(rt2x00dev, "Invalid RF chipset 0x%04x detected.\n",
@@ -4577,9 +4598,11 @@ int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
4577 rt2x00_rf(rt2x00dev, RF3021) || 4598 rt2x00_rf(rt2x00dev, RF3021) ||
4578 rt2x00_rf(rt2x00dev, RF3022) || 4599 rt2x00_rf(rt2x00dev, RF3022) ||
4579 rt2x00_rf(rt2x00dev, RF3320) || 4600 rt2x00_rf(rt2x00dev, RF3320) ||
4601 rt2x00_rf(rt2x00dev, RF5360) ||
4580 rt2x00_rf(rt2x00dev, RF5370) || 4602 rt2x00_rf(rt2x00dev, RF5370) ||
4581 rt2x00_rf(rt2x00dev, RF5372) || 4603 rt2x00_rf(rt2x00dev, RF5372) ||
4582 rt2x00_rf(rt2x00dev, RF5390)) { 4604 rt2x00_rf(rt2x00dev, RF5390) ||
4605 rt2x00_rf(rt2x00dev, RF5392)) {
4583 spec->num_channels = 14; 4606 spec->num_channels = 14;
4584 spec->channels = rf_vals_3x; 4607 spec->channels = rf_vals_3x;
4585 } else if (rt2x00_rf(rt2x00dev, RF3052)) { 4608 } else if (rt2x00_rf(rt2x00dev, RF3052)) {
@@ -4662,9 +4685,11 @@ int rt2800_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
4662 case RF3022: 4685 case RF3022:
4663 case RF3320: 4686 case RF3320:
4664 case RF3052: 4687 case RF3052:
4688 case RF5360:
4665 case RF5370: 4689 case RF5370:
4666 case RF5372: 4690 case RF5372:
4667 case RF5390: 4691 case RF5390:
4692 case RF5392:
4668 __set_bit(CAPABILITY_VCO_RECALIBRATION, &rt2x00dev->cap_flags); 4693 __set_bit(CAPABILITY_VCO_RECALIBRATION, &rt2x00dev->cap_flags);
4669 break; 4694 break;
4670 } 4695 }
diff --git a/drivers/net/wireless/rt2x00/rt2800pci.c b/drivers/net/wireless/rt2x00/rt2800pci.c
index cad25bfebd7a..206158b67426 100644
--- a/drivers/net/wireless/rt2x00/rt2800pci.c
+++ b/drivers/net/wireless/rt2x00/rt2800pci.c
@@ -1188,6 +1188,7 @@ static DEFINE_PCI_DEVICE_TABLE(rt2800pci_device_table) = {
1188 { PCI_DEVICE(0x1814, 0x3593) }, 1188 { PCI_DEVICE(0x1814, 0x3593) },
1189#endif 1189#endif
1190#ifdef CONFIG_RT2800PCI_RT53XX 1190#ifdef CONFIG_RT2800PCI_RT53XX
1191 { PCI_DEVICE(0x1814, 0x5360) },
1191 { PCI_DEVICE(0x1814, 0x5362) }, 1192 { PCI_DEVICE(0x1814, 0x5362) },
1192 { PCI_DEVICE(0x1814, 0x5390) }, 1193 { PCI_DEVICE(0x1814, 0x5390) },
1193 { PCI_DEVICE(0x1814, 0x5392) }, 1194 { PCI_DEVICE(0x1814, 0x5392) },
diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c
index bf78317a6adb..20a504072895 100644
--- a/drivers/net/wireless/rt2x00/rt2800usb.c
+++ b/drivers/net/wireless/rt2x00/rt2800usb.c
@@ -1137,6 +1137,8 @@ static struct usb_device_id rt2800usb_device_table[] = {
1137#ifdef CONFIG_RT2800USB_RT33XX 1137#ifdef CONFIG_RT2800USB_RT33XX
1138 /* Belkin */ 1138 /* Belkin */
1139 { USB_DEVICE(0x050d, 0x945b) }, 1139 { USB_DEVICE(0x050d, 0x945b) },
1140 /* D-Link */
1141 { USB_DEVICE(0x2001, 0x3c17) },
1140 /* Panasonic */ 1142 /* Panasonic */
1141 { USB_DEVICE(0x083a, 0xb511) }, 1143 { USB_DEVICE(0x083a, 0xb511) },
1142 /* Philips */ 1144 /* Philips */
@@ -1237,7 +1239,6 @@ static struct usb_device_id rt2800usb_device_table[] = {
1237 /* D-Link */ 1239 /* D-Link */
1238 { USB_DEVICE(0x07d1, 0x3c0b) }, 1240 { USB_DEVICE(0x07d1, 0x3c0b) },
1239 { USB_DEVICE(0x07d1, 0x3c17) }, 1241 { USB_DEVICE(0x07d1, 0x3c17) },
1240 { USB_DEVICE(0x2001, 0x3c17) },
1241 /* Encore */ 1242 /* Encore */
1242 { USB_DEVICE(0x203d, 0x14a1) }, 1243 { USB_DEVICE(0x203d, 0x14a1) },
1243 /* Gemtek */ 1244 /* Gemtek */
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index e5404e576251..a6b88bd4a1a5 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -1161,6 +1161,8 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
1161 BIT(NL80211_IFTYPE_MESH_POINT) | 1161 BIT(NL80211_IFTYPE_MESH_POINT) |
1162 BIT(NL80211_IFTYPE_WDS); 1162 BIT(NL80211_IFTYPE_WDS);
1163 1163
1164 rt2x00dev->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
1165
1164 /* 1166 /*
1165 * Initialize work. 1167 * Initialize work.
1166 */ 1168 */
diff --git a/drivers/net/wireless/rt2x00/rt2x00mac.c b/drivers/net/wireless/rt2x00/rt2x00mac.c
index dd24b2663b5e..4ff26c2159bf 100644
--- a/drivers/net/wireless/rt2x00/rt2x00mac.c
+++ b/drivers/net/wireless/rt2x00/rt2x00mac.c
@@ -506,9 +506,19 @@ int rt2x00mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
506 506
507 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags)) 507 if (!test_bit(DEVICE_STATE_PRESENT, &rt2x00dev->flags))
508 return 0; 508 return 0;
509 else if (!test_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags)) 509
510 if (!test_bit(CAPABILITY_HW_CRYPTO, &rt2x00dev->cap_flags))
511 return -EOPNOTSUPP;
512
513 /*
514 * To support IBSS RSN, don't program group keys in IBSS, the
515 * hardware will then not attempt to decrypt the frames.
516 */
517 if (vif->type == NL80211_IFTYPE_ADHOC &&
518 !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE))
510 return -EOPNOTSUPP; 519 return -EOPNOTSUPP;
511 else if (key->keylen > 32) 520
521 if (key->keylen > 32)
512 return -ENOSPC; 522 return -ENOSPC;
513 523
514 memset(&crypto, 0, sizeof(crypto)); 524 memset(&crypto, 0, sizeof(crypto));
diff --git a/drivers/net/wireless/ti/Kconfig b/drivers/net/wireless/ti/Kconfig
index 1a72932e2213..be800119d0a3 100644
--- a/drivers/net/wireless/ti/Kconfig
+++ b/drivers/net/wireless/ti/Kconfig
@@ -8,6 +8,7 @@ menuconfig WL_TI
8if WL_TI 8if WL_TI
9source "drivers/net/wireless/ti/wl1251/Kconfig" 9source "drivers/net/wireless/ti/wl1251/Kconfig"
10source "drivers/net/wireless/ti/wl12xx/Kconfig" 10source "drivers/net/wireless/ti/wl12xx/Kconfig"
11source "drivers/net/wireless/ti/wl18xx/Kconfig"
11 12
12# keep last for automatic dependencies 13# keep last for automatic dependencies
13source "drivers/net/wireless/ti/wlcore/Kconfig" 14source "drivers/net/wireless/ti/wlcore/Kconfig"
diff --git a/drivers/net/wireless/ti/Makefile b/drivers/net/wireless/ti/Makefile
index 0a565622d4a4..4d6823983c04 100644
--- a/drivers/net/wireless/ti/Makefile
+++ b/drivers/net/wireless/ti/Makefile
@@ -2,3 +2,4 @@ obj-$(CONFIG_WLCORE) += wlcore/
2obj-$(CONFIG_WL12XX) += wl12xx/ 2obj-$(CONFIG_WL12XX) += wl12xx/
3obj-$(CONFIG_WL12XX_PLATFORM_DATA) += wlcore/ 3obj-$(CONFIG_WL12XX_PLATFORM_DATA) += wlcore/
4obj-$(CONFIG_WL1251) += wl1251/ 4obj-$(CONFIG_WL1251) += wl1251/
5obj-$(CONFIG_WL18XX) += wl18xx/
diff --git a/drivers/net/wireless/ti/wl12xx/Makefile b/drivers/net/wireless/ti/wl12xx/Makefile
index 87f64b14db35..da509aa7d009 100644
--- a/drivers/net/wireless/ti/wl12xx/Makefile
+++ b/drivers/net/wireless/ti/wl12xx/Makefile
@@ -1,3 +1,3 @@
1wl12xx-objs = main.o cmd.o acx.o 1wl12xx-objs = main.o cmd.o acx.o debugfs.o
2 2
3obj-$(CONFIG_WL12XX) += wl12xx.o 3obj-$(CONFIG_WL12XX) += wl12xx.o
diff --git a/drivers/net/wireless/ti/wl12xx/acx.h b/drivers/net/wireless/ti/wl12xx/acx.h
index d1f5aba0afce..2a26868b837d 100644
--- a/drivers/net/wireless/ti/wl12xx/acx.h
+++ b/drivers/net/wireless/ti/wl12xx/acx.h
@@ -24,6 +24,21 @@
24#define __WL12XX_ACX_H__ 24#define __WL12XX_ACX_H__
25 25
26#include "../wlcore/wlcore.h" 26#include "../wlcore/wlcore.h"
27#include "../wlcore/acx.h"
28
29#define WL12XX_ACX_ALL_EVENTS_VECTOR (WL1271_ACX_INTR_WATCHDOG | \
30 WL1271_ACX_INTR_INIT_COMPLETE | \
31 WL1271_ACX_INTR_EVENT_A | \
32 WL1271_ACX_INTR_EVENT_B | \
33 WL1271_ACX_INTR_CMD_COMPLETE | \
34 WL1271_ACX_INTR_HW_AVAILABLE | \
35 WL1271_ACX_INTR_DATA)
36
37#define WL12XX_INTR_MASK (WL1271_ACX_INTR_WATCHDOG | \
38 WL1271_ACX_INTR_EVENT_A | \
39 WL1271_ACX_INTR_EVENT_B | \
40 WL1271_ACX_INTR_HW_AVAILABLE | \
41 WL1271_ACX_INTR_DATA)
27 42
28struct wl1271_acx_host_config_bitmap { 43struct wl1271_acx_host_config_bitmap {
29 struct acx_header header; 44 struct acx_header header;
@@ -31,6 +46,228 @@ struct wl1271_acx_host_config_bitmap {
31 __le32 host_cfg_bitmap; 46 __le32 host_cfg_bitmap;
32} __packed; 47} __packed;
33 48
49struct wl12xx_acx_tx_statistics {
50 __le32 internal_desc_overflow;
51} __packed;
52
53struct wl12xx_acx_rx_statistics {
54 __le32 out_of_mem;
55 __le32 hdr_overflow;
56 __le32 hw_stuck;
57 __le32 dropped;
58 __le32 fcs_err;
59 __le32 xfr_hint_trig;
60 __le32 path_reset;
61 __le32 reset_counter;
62} __packed;
63
64struct wl12xx_acx_dma_statistics {
65 __le32 rx_requested;
66 __le32 rx_errors;
67 __le32 tx_requested;
68 __le32 tx_errors;
69} __packed;
70
71struct wl12xx_acx_isr_statistics {
72 /* host command complete */
73 __le32 cmd_cmplt;
74
75 /* fiqisr() */
76 __le32 fiqs;
77
78 /* (INT_STS_ND & INT_TRIG_RX_HEADER) */
79 __le32 rx_headers;
80
81 /* (INT_STS_ND & INT_TRIG_RX_CMPLT) */
82 __le32 rx_completes;
83
84 /* (INT_STS_ND & INT_TRIG_NO_RX_BUF) */
85 __le32 rx_mem_overflow;
86
87 /* (INT_STS_ND & INT_TRIG_S_RX_RDY) */
88 __le32 rx_rdys;
89
90 /* irqisr() */
91 __le32 irqs;
92
93 /* (INT_STS_ND & INT_TRIG_TX_PROC) */
94 __le32 tx_procs;
95
96 /* (INT_STS_ND & INT_TRIG_DECRYPT_DONE) */
97 __le32 decrypt_done;
98
99 /* (INT_STS_ND & INT_TRIG_DMA0) */
100 __le32 dma0_done;
101
102 /* (INT_STS_ND & INT_TRIG_DMA1) */
103 __le32 dma1_done;
104
105 /* (INT_STS_ND & INT_TRIG_TX_EXC_CMPLT) */
106 __le32 tx_exch_complete;
107
108 /* (INT_STS_ND & INT_TRIG_COMMAND) */
109 __le32 commands;
110
111 /* (INT_STS_ND & INT_TRIG_RX_PROC) */
112 __le32 rx_procs;
113
114 /* (INT_STS_ND & INT_TRIG_PM_802) */
115 __le32 hw_pm_mode_changes;
116
117 /* (INT_STS_ND & INT_TRIG_ACKNOWLEDGE) */
118 __le32 host_acknowledges;
119
120 /* (INT_STS_ND & INT_TRIG_PM_PCI) */
121 __le32 pci_pm;
122
123 /* (INT_STS_ND & INT_TRIG_ACM_WAKEUP) */
124 __le32 wakeups;
125
126 /* (INT_STS_ND & INT_TRIG_LOW_RSSI) */
127 __le32 low_rssi;
128} __packed;
129
130struct wl12xx_acx_wep_statistics {
131 /* WEP address keys configured */
132 __le32 addr_key_count;
133
134 /* default keys configured */
135 __le32 default_key_count;
136
137 __le32 reserved;
138
139 /* number of times that WEP key not found on lookup */
140 __le32 key_not_found;
141
142 /* number of times that WEP key decryption failed */
143 __le32 decrypt_fail;
144
145 /* WEP packets decrypted */
146 __le32 packets;
147
148 /* WEP decrypt interrupts */
149 __le32 interrupt;
150} __packed;
151
152#define ACX_MISSED_BEACONS_SPREAD 10
153
154struct wl12xx_acx_pwr_statistics {
155 /* the amount of enters into power save mode (both PD & ELP) */
156 __le32 ps_enter;
157
158 /* the amount of enters into ELP mode */
159 __le32 elp_enter;
160
161 /* the amount of missing beacon interrupts to the host */
162 __le32 missing_bcns;
163
164 /* the amount of wake on host-access times */
165 __le32 wake_on_host;
166
167 /* the amount of wake on timer-expire */
168 __le32 wake_on_timer_exp;
169
170 /* the number of packets that were transmitted with PS bit set */
171 __le32 tx_with_ps;
172
173 /* the number of packets that were transmitted with PS bit clear */
174 __le32 tx_without_ps;
175
176 /* the number of received beacons */
177 __le32 rcvd_beacons;
178
179 /* the number of entering into PowerOn (power save off) */
180 __le32 power_save_off;
181
182 /* the number of entries into power save mode */
183 __le16 enable_ps;
184
185 /*
186 * the number of exits from power save, not including failed PS
187 * transitions
188 */
189 __le16 disable_ps;
190
191 /*
192 * the number of times the TSF counter was adjusted because
193 * of drift
194 */
195 __le32 fix_tsf_ps;
196
197 /* Gives statistics about the spread continuous missed beacons.
198 * The 16 LSB are dedicated for the PS mode.
199 * The 16 MSB are dedicated for the PS mode.
200 * cont_miss_bcns_spread[0] - single missed beacon.
201 * cont_miss_bcns_spread[1] - two continuous missed beacons.
202 * cont_miss_bcns_spread[2] - three continuous missed beacons.
203 * ...
204 * cont_miss_bcns_spread[9] - ten and more continuous missed beacons.
205 */
206 __le32 cont_miss_bcns_spread[ACX_MISSED_BEACONS_SPREAD];
207
208 /* the number of beacons in awake mode */
209 __le32 rcvd_awake_beacons;
210} __packed;
211
212struct wl12xx_acx_mic_statistics {
213 __le32 rx_pkts;
214 __le32 calc_failure;
215} __packed;
216
217struct wl12xx_acx_aes_statistics {
218 __le32 encrypt_fail;
219 __le32 decrypt_fail;
220 __le32 encrypt_packets;
221 __le32 decrypt_packets;
222 __le32 encrypt_interrupt;
223 __le32 decrypt_interrupt;
224} __packed;
225
226struct wl12xx_acx_event_statistics {
227 __le32 heart_beat;
228 __le32 calibration;
229 __le32 rx_mismatch;
230 __le32 rx_mem_empty;
231 __le32 rx_pool;
232 __le32 oom_late;
233 __le32 phy_transmit_error;
234 __le32 tx_stuck;
235} __packed;
236
237struct wl12xx_acx_ps_statistics {
238 __le32 pspoll_timeouts;
239 __le32 upsd_timeouts;
240 __le32 upsd_max_sptime;
241 __le32 upsd_max_apturn;
242 __le32 pspoll_max_apturn;
243 __le32 pspoll_utilization;
244 __le32 upsd_utilization;
245} __packed;
246
247struct wl12xx_acx_rxpipe_statistics {
248 __le32 rx_prep_beacon_drop;
249 __le32 descr_host_int_trig_rx_data;
250 __le32 beacon_buffer_thres_host_int_trig_rx_data;
251 __le32 missed_beacon_host_int_trig_rx_data;
252 __le32 tx_xfr_host_int_trig_rx_data;
253} __packed;
254
255struct wl12xx_acx_statistics {
256 struct acx_header header;
257
258 struct wl12xx_acx_tx_statistics tx;
259 struct wl12xx_acx_rx_statistics rx;
260 struct wl12xx_acx_dma_statistics dma;
261 struct wl12xx_acx_isr_statistics isr;
262 struct wl12xx_acx_wep_statistics wep;
263 struct wl12xx_acx_pwr_statistics pwr;
264 struct wl12xx_acx_aes_statistics aes;
265 struct wl12xx_acx_mic_statistics mic;
266 struct wl12xx_acx_event_statistics event;
267 struct wl12xx_acx_ps_statistics ps;
268 struct wl12xx_acx_rxpipe_statistics rxpipe;
269} __packed;
270
34int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap); 271int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap);
35 272
36#endif /* __WL12XX_ACX_H__ */ 273#endif /* __WL12XX_ACX_H__ */
diff --git a/drivers/net/wireless/ti/wl12xx/cmd.c b/drivers/net/wireless/ti/wl12xx/cmd.c
index 8ffaeb5f2147..50ba7480b790 100644
--- a/drivers/net/wireless/ti/wl12xx/cmd.c
+++ b/drivers/net/wireless/ti/wl12xx/cmd.c
@@ -65,6 +65,7 @@ int wl1271_cmd_general_parms(struct wl1271 *wl)
65 struct wl1271_general_parms_cmd *gen_parms; 65 struct wl1271_general_parms_cmd *gen_parms;
66 struct wl1271_ini_general_params *gp = 66 struct wl1271_ini_general_params *gp =
67 &((struct wl1271_nvs_file *)wl->nvs)->general_params; 67 &((struct wl1271_nvs_file *)wl->nvs)->general_params;
68 struct wl12xx_priv *priv = wl->priv;
68 bool answer = false; 69 bool answer = false;
69 int ret; 70 int ret;
70 71
@@ -88,7 +89,7 @@ int wl1271_cmd_general_parms(struct wl1271 *wl)
88 answer = true; 89 answer = true;
89 90
90 /* Override the REF CLK from the NVS with the one from platform data */ 91 /* Override the REF CLK from the NVS with the one from platform data */
91 gen_parms->general_params.ref_clock = wl->ref_clock; 92 gen_parms->general_params.ref_clock = priv->ref_clock;
92 93
93 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer); 94 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
94 if (ret < 0) { 95 if (ret < 0) {
@@ -118,6 +119,7 @@ int wl128x_cmd_general_parms(struct wl1271 *wl)
118 struct wl128x_general_parms_cmd *gen_parms; 119 struct wl128x_general_parms_cmd *gen_parms;
119 struct wl128x_ini_general_params *gp = 120 struct wl128x_ini_general_params *gp =
120 &((struct wl128x_nvs_file *)wl->nvs)->general_params; 121 &((struct wl128x_nvs_file *)wl->nvs)->general_params;
122 struct wl12xx_priv *priv = wl->priv;
121 bool answer = false; 123 bool answer = false;
122 int ret; 124 int ret;
123 125
@@ -141,8 +143,8 @@ int wl128x_cmd_general_parms(struct wl1271 *wl)
141 answer = true; 143 answer = true;
142 144
143 /* Replace REF and TCXO CLKs with the ones from platform data */ 145 /* Replace REF and TCXO CLKs with the ones from platform data */
144 gen_parms->general_params.ref_clock = wl->ref_clock; 146 gen_parms->general_params.ref_clock = priv->ref_clock;
145 gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock; 147 gen_parms->general_params.tcxo_ref_clock = priv->tcxo_clock;
146 148
147 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer); 149 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
148 if (ret < 0) { 150 if (ret < 0) {
diff --git a/drivers/net/wireless/ti/wl12xx/debugfs.c b/drivers/net/wireless/ti/wl12xx/debugfs.c
new file mode 100644
index 000000000000..0521cbf858cf
--- /dev/null
+++ b/drivers/net/wireless/ti/wl12xx/debugfs.c
@@ -0,0 +1,243 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Copyright (C) 2011-2012 Texas Instruments
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include "../wlcore/debugfs.h"
24#include "../wlcore/wlcore.h"
25
26#include "wl12xx.h"
27#include "acx.h"
28#include "debugfs.h"
29
30#define WL12XX_DEBUGFS_FWSTATS_FILE(a, b, c) \
31 DEBUGFS_FWSTATS_FILE(a, b, c, wl12xx_acx_statistics)
32
33WL12XX_DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
34
35WL12XX_DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
36WL12XX_DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u");
37WL12XX_DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u");
38WL12XX_DEBUGFS_FWSTATS_FILE(rx, dropped, "%u");
39WL12XX_DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u");
40WL12XX_DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u");
41WL12XX_DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u");
42WL12XX_DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u");
43
44WL12XX_DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u");
45WL12XX_DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u");
46WL12XX_DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u");
47WL12XX_DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u");
48
49WL12XX_DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u");
50WL12XX_DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u");
51WL12XX_DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u");
52WL12XX_DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u");
53WL12XX_DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u");
54WL12XX_DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
55WL12XX_DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u");
56WL12XX_DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u");
57WL12XX_DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u");
58WL12XX_DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u");
59WL12XX_DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u");
60WL12XX_DEBUGFS_FWSTATS_FILE(isr, commands, "%u");
61WL12XX_DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u");
62WL12XX_DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u");
63WL12XX_DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u");
64WL12XX_DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u");
65WL12XX_DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u");
66WL12XX_DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u");
67
68WL12XX_DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
69WL12XX_DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
70/* skipping wep.reserved */
71WL12XX_DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u");
72WL12XX_DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u");
73WL12XX_DEBUGFS_FWSTATS_FILE(wep, packets, "%u");
74WL12XX_DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u");
75
76WL12XX_DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u");
77WL12XX_DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u");
78WL12XX_DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u");
79WL12XX_DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u");
80WL12XX_DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u");
81WL12XX_DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u");
82WL12XX_DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u");
83WL12XX_DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u");
84WL12XX_DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u");
85WL12XX_DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u");
86WL12XX_DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u");
87WL12XX_DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u");
88/* skipping cont_miss_bcns_spread for now */
89WL12XX_DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
90
91WL12XX_DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
92WL12XX_DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
93
94WL12XX_DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u");
95WL12XX_DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u");
96WL12XX_DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u");
97WL12XX_DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u");
98WL12XX_DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u");
99WL12XX_DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u");
100
101WL12XX_DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u");
102WL12XX_DEBUGFS_FWSTATS_FILE(event, calibration, "%u");
103WL12XX_DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u");
104WL12XX_DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u");
105WL12XX_DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u");
106WL12XX_DEBUGFS_FWSTATS_FILE(event, oom_late, "%u");
107WL12XX_DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u");
108WL12XX_DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u");
109
110WL12XX_DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u");
111WL12XX_DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u");
112WL12XX_DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u");
113WL12XX_DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u");
114WL12XX_DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u");
115WL12XX_DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u");
116WL12XX_DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u");
117
118WL12XX_DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u");
119WL12XX_DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u");
120WL12XX_DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data,
121 "%u");
122WL12XX_DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u");
123WL12XX_DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u");
124
125int wl12xx_debugfs_add_files(struct wl1271 *wl,
126 struct dentry *rootdir)
127{
128 int ret = 0;
129 struct dentry *entry, *stats, *moddir;
130
131 moddir = debugfs_create_dir(KBUILD_MODNAME, rootdir);
132 if (!moddir || IS_ERR(moddir)) {
133 entry = moddir;
134 goto err;
135 }
136
137 stats = debugfs_create_dir("fw_stats", moddir);
138 if (!stats || IS_ERR(stats)) {
139 entry = stats;
140 goto err;
141 }
142
143 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
144
145 DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
146 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
147 DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
148 DEBUGFS_FWSTATS_ADD(rx, dropped);
149 DEBUGFS_FWSTATS_ADD(rx, fcs_err);
150 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
151 DEBUGFS_FWSTATS_ADD(rx, path_reset);
152 DEBUGFS_FWSTATS_ADD(rx, reset_counter);
153
154 DEBUGFS_FWSTATS_ADD(dma, rx_requested);
155 DEBUGFS_FWSTATS_ADD(dma, rx_errors);
156 DEBUGFS_FWSTATS_ADD(dma, tx_requested);
157 DEBUGFS_FWSTATS_ADD(dma, tx_errors);
158
159 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
160 DEBUGFS_FWSTATS_ADD(isr, fiqs);
161 DEBUGFS_FWSTATS_ADD(isr, rx_headers);
162 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
163 DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
164 DEBUGFS_FWSTATS_ADD(isr, irqs);
165 DEBUGFS_FWSTATS_ADD(isr, tx_procs);
166 DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
167 DEBUGFS_FWSTATS_ADD(isr, dma0_done);
168 DEBUGFS_FWSTATS_ADD(isr, dma1_done);
169 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
170 DEBUGFS_FWSTATS_ADD(isr, commands);
171 DEBUGFS_FWSTATS_ADD(isr, rx_procs);
172 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
173 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
174 DEBUGFS_FWSTATS_ADD(isr, pci_pm);
175 DEBUGFS_FWSTATS_ADD(isr, wakeups);
176 DEBUGFS_FWSTATS_ADD(isr, low_rssi);
177
178 DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
179 DEBUGFS_FWSTATS_ADD(wep, default_key_count);
180 /* skipping wep.reserved */
181 DEBUGFS_FWSTATS_ADD(wep, key_not_found);
182 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
183 DEBUGFS_FWSTATS_ADD(wep, packets);
184 DEBUGFS_FWSTATS_ADD(wep, interrupt);
185
186 DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
187 DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
188 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
189 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
190 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
191 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
192 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
193 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
194 DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
195 DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
196 DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
197 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
198 /* skipping cont_miss_bcns_spread for now */
199 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
200
201 DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
202 DEBUGFS_FWSTATS_ADD(mic, calc_failure);
203
204 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
205 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
206 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
207 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
208 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
209 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
210
211 DEBUGFS_FWSTATS_ADD(event, heart_beat);
212 DEBUGFS_FWSTATS_ADD(event, calibration);
213 DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
214 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
215 DEBUGFS_FWSTATS_ADD(event, rx_pool);
216 DEBUGFS_FWSTATS_ADD(event, oom_late);
217 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
218 DEBUGFS_FWSTATS_ADD(event, tx_stuck);
219
220 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
221 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
222 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
223 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
224 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
225 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
226 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
227
228 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
229 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
230 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
231 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
232 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
233
234 return 0;
235
236err:
237 if (IS_ERR(entry))
238 ret = PTR_ERR(entry);
239 else
240 ret = -ENOMEM;
241
242 return ret;
243}
diff --git a/drivers/net/wireless/ti/wl12xx/debugfs.h b/drivers/net/wireless/ti/wl12xx/debugfs.h
new file mode 100644
index 000000000000..96898e291b78
--- /dev/null
+++ b/drivers/net/wireless/ti/wl12xx/debugfs.h
@@ -0,0 +1,28 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2012 Texas Instruments. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#ifndef __WL12XX_DEBUGFS_H__
23#define __WL12XX_DEBUGFS_H__
24
25int wl12xx_debugfs_add_files(struct wl1271 *wl,
26 struct dentry *rootdir);
27
28#endif /* __WL12XX_DEBUGFS_H__ */
diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
index d7dd3def07b5..85d1600ee340 100644
--- a/drivers/net/wireless/ti/wl12xx/main.c
+++ b/drivers/net/wireless/ti/wl12xx/main.c
@@ -39,6 +39,10 @@
39#include "reg.h" 39#include "reg.h"
40#include "cmd.h" 40#include "cmd.h"
41#include "acx.h" 41#include "acx.h"
42#include "debugfs.h"
43
44static char *fref_param;
45static char *tcxo_param;
42 46
43static struct wlcore_conf wl12xx_conf = { 47static struct wlcore_conf wl12xx_conf = {
44 .sg = { 48 .sg = {
@@ -212,7 +216,7 @@ static struct wlcore_conf wl12xx_conf = {
212 .suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM, 216 .suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM,
213 .suspend_listen_interval = 3, 217 .suspend_listen_interval = 3,
214 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED, 218 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
215 .bcn_filt_ie_count = 2, 219 .bcn_filt_ie_count = 3,
216 .bcn_filt_ie = { 220 .bcn_filt_ie = {
217 [0] = { 221 [0] = {
218 .ie = WLAN_EID_CHANNEL_SWITCH, 222 .ie = WLAN_EID_CHANNEL_SWITCH,
@@ -222,9 +226,13 @@ static struct wlcore_conf wl12xx_conf = {
222 .ie = WLAN_EID_HT_OPERATION, 226 .ie = WLAN_EID_HT_OPERATION,
223 .rule = CONF_BCN_RULE_PASS_ON_CHANGE, 227 .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
224 }, 228 },
229 [2] = {
230 .ie = WLAN_EID_ERP_INFO,
231 .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
232 },
225 }, 233 },
226 .synch_fail_thold = 10, 234 .synch_fail_thold = 12,
227 .bss_lose_timeout = 100, 235 .bss_lose_timeout = 400,
228 .beacon_rx_timeout = 10000, 236 .beacon_rx_timeout = 10000,
229 .broadcast_timeout = 20000, 237 .broadcast_timeout = 20000,
230 .rx_broadcast_in_ps = 1, 238 .rx_broadcast_in_ps = 1,
@@ -234,7 +242,7 @@ static struct wlcore_conf wl12xx_conf = {
234 .psm_entry_retries = 8, 242 .psm_entry_retries = 8,
235 .psm_exit_retries = 16, 243 .psm_exit_retries = 16,
236 .psm_entry_nullfunc_retries = 3, 244 .psm_entry_nullfunc_retries = 3,
237 .dynamic_ps_timeout = 40, 245 .dynamic_ps_timeout = 200,
238 .forced_ps = false, 246 .forced_ps = false,
239 .keep_alive_interval = 55000, 247 .keep_alive_interval = 55000,
240 .max_listen_interval = 20, 248 .max_listen_interval = 20,
@@ -245,7 +253,7 @@ static struct wlcore_conf wl12xx_conf = {
245 }, 253 },
246 .pm_config = { 254 .pm_config = {
247 .host_clk_settling_time = 5000, 255 .host_clk_settling_time = 5000,
248 .host_fast_wakeup_support = false 256 .host_fast_wakeup_support = CONF_FAST_WAKEUP_DISABLE,
249 }, 257 },
250 .roam_trigger = { 258 .roam_trigger = {
251 .trigger_pacing = 1, 259 .trigger_pacing = 1,
@@ -305,8 +313,8 @@ static struct wlcore_conf wl12xx_conf = {
305 .swallow_period = 5, 313 .swallow_period = 5,
306 .n_divider_fref_set_1 = 0xff, /* default */ 314 .n_divider_fref_set_1 = 0xff, /* default */
307 .n_divider_fref_set_2 = 12, 315 .n_divider_fref_set_2 = 12,
308 .m_divider_fref_set_1 = 148, 316 .m_divider_fref_set_1 = 0xffff,
309 .m_divider_fref_set_2 = 0xffff, /* default */ 317 .m_divider_fref_set_2 = 148, /* default */
310 .coex_pll_stabilization_time = 0xffffffff, /* default */ 318 .coex_pll_stabilization_time = 0xffffffff, /* default */
311 .ldo_stabilization_time = 0xffff, /* default */ 319 .ldo_stabilization_time = 0xffff, /* default */
312 .fm_disturbed_band_margin = 0xff, /* default */ 320 .fm_disturbed_band_margin = 0xff, /* default */
@@ -593,7 +601,7 @@ static void wl127x_prepare_read(struct wl1271 *wl, u32 rx_desc, u32 len)
593{ 601{
594 if (wl->chip.id != CHIP_ID_1283_PG20) { 602 if (wl->chip.id != CHIP_ID_1283_PG20) {
595 struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map; 603 struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
596 struct wl1271_rx_mem_pool_addr rx_mem_addr; 604 struct wl127x_rx_mem_pool_addr rx_mem_addr;
597 605
598 /* 606 /*
599 * Choose the block we want to read 607 * Choose the block we want to read
@@ -621,10 +629,8 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
621 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete", 629 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
622 wl->chip.id); 630 wl->chip.id);
623 631
624 /* clear the alignment quirk, since we don't support it */ 632 wl->quirks |= WLCORE_QUIRK_LEGACY_NVS |
625 wl->quirks &= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN; 633 WLCORE_QUIRK_TKIP_HEADER_SPACE;
626
627 wl->quirks |= WLCORE_QUIRK_LEGACY_NVS;
628 wl->sr_fw_name = WL127X_FW_NAME_SINGLE; 634 wl->sr_fw_name = WL127X_FW_NAME_SINGLE;
629 wl->mr_fw_name = WL127X_FW_NAME_MULTI; 635 wl->mr_fw_name = WL127X_FW_NAME_MULTI;
630 memcpy(&wl->conf.mem, &wl12xx_default_priv_conf.mem_wl127x, 636 memcpy(&wl->conf.mem, &wl12xx_default_priv_conf.mem_wl127x,
@@ -639,10 +645,8 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
639 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)", 645 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
640 wl->chip.id); 646 wl->chip.id);
641 647
642 /* clear the alignment quirk, since we don't support it */ 648 wl->quirks |= WLCORE_QUIRK_LEGACY_NVS |
643 wl->quirks &= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN; 649 WLCORE_QUIRK_TKIP_HEADER_SPACE;
644
645 wl->quirks |= WLCORE_QUIRK_LEGACY_NVS;
646 wl->plt_fw_name = WL127X_PLT_FW_NAME; 650 wl->plt_fw_name = WL127X_PLT_FW_NAME;
647 wl->sr_fw_name = WL127X_FW_NAME_SINGLE; 651 wl->sr_fw_name = WL127X_FW_NAME_SINGLE;
648 wl->mr_fw_name = WL127X_FW_NAME_MULTI; 652 wl->mr_fw_name = WL127X_FW_NAME_MULTI;
@@ -660,6 +664,11 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
660 wl->plt_fw_name = WL128X_PLT_FW_NAME; 664 wl->plt_fw_name = WL128X_PLT_FW_NAME;
661 wl->sr_fw_name = WL128X_FW_NAME_SINGLE; 665 wl->sr_fw_name = WL128X_FW_NAME_SINGLE;
662 wl->mr_fw_name = WL128X_FW_NAME_MULTI; 666 wl->mr_fw_name = WL128X_FW_NAME_MULTI;
667
668 /* wl128x requires TX blocksize alignment */
669 wl->quirks |= WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN |
670 WLCORE_QUIRK_TKIP_HEADER_SPACE;
671
663 break; 672 break;
664 case CHIP_ID_1283_PG10: 673 case CHIP_ID_1283_PG10:
665 default: 674 default:
@@ -773,6 +782,7 @@ static int wl128x_configure_mcs_pll(struct wl1271 *wl, int clk)
773 u16 spare_reg; 782 u16 spare_reg;
774 u16 pll_config; 783 u16 pll_config;
775 u8 input_freq; 784 u8 input_freq;
785 struct wl12xx_priv *priv = wl->priv;
776 786
777 /* Mask bits [3:1] in the sys_clk_cfg register */ 787 /* Mask bits [3:1] in the sys_clk_cfg register */
778 spare_reg = wl12xx_top_reg_read(wl, WL_SPARE_REG); 788 spare_reg = wl12xx_top_reg_read(wl, WL_SPARE_REG);
@@ -782,8 +792,8 @@ static int wl128x_configure_mcs_pll(struct wl1271 *wl, int clk)
782 wl12xx_top_reg_write(wl, WL_SPARE_REG, spare_reg); 792 wl12xx_top_reg_write(wl, WL_SPARE_REG, spare_reg);
783 793
784 /* Handle special cases of the TCXO clock */ 794 /* Handle special cases of the TCXO clock */
785 if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_8 || 795 if (priv->tcxo_clock == WL12XX_TCXOCLOCK_16_8 ||
786 wl->tcxo_clock == WL12XX_TCXOCLOCK_33_6) 796 priv->tcxo_clock == WL12XX_TCXOCLOCK_33_6)
787 return wl128x_manually_configure_mcs_pll(wl); 797 return wl128x_manually_configure_mcs_pll(wl);
788 798
789 /* Set the input frequency according to the selected clock source */ 799 /* Set the input frequency according to the selected clock source */
@@ -808,11 +818,12 @@ static int wl128x_configure_mcs_pll(struct wl1271 *wl, int clk)
808 */ 818 */
809static int wl128x_boot_clk(struct wl1271 *wl, int *selected_clock) 819static int wl128x_boot_clk(struct wl1271 *wl, int *selected_clock)
810{ 820{
821 struct wl12xx_priv *priv = wl->priv;
811 u16 sys_clk_cfg; 822 u16 sys_clk_cfg;
812 823
813 /* For XTAL-only modes, FREF will be used after switching from TCXO */ 824 /* For XTAL-only modes, FREF will be used after switching from TCXO */
814 if (wl->ref_clock == WL12XX_REFCLOCK_26_XTAL || 825 if (priv->ref_clock == WL12XX_REFCLOCK_26_XTAL ||
815 wl->ref_clock == WL12XX_REFCLOCK_38_XTAL) { 826 priv->ref_clock == WL12XX_REFCLOCK_38_XTAL) {
816 if (!wl128x_switch_tcxo_to_fref(wl)) 827 if (!wl128x_switch_tcxo_to_fref(wl))
817 return -EINVAL; 828 return -EINVAL;
818 goto fref_clk; 829 goto fref_clk;
@@ -826,8 +837,8 @@ static int wl128x_boot_clk(struct wl1271 *wl, int *selected_clock)
826 goto fref_clk; 837 goto fref_clk;
827 838
828 /* If TCXO is either 32.736MHz or 16.368MHz, switch to FREF */ 839 /* If TCXO is either 32.736MHz or 16.368MHz, switch to FREF */
829 if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_368 || 840 if (priv->tcxo_clock == WL12XX_TCXOCLOCK_16_368 ||
830 wl->tcxo_clock == WL12XX_TCXOCLOCK_32_736) { 841 priv->tcxo_clock == WL12XX_TCXOCLOCK_32_736) {
831 if (!wl128x_switch_tcxo_to_fref(wl)) 842 if (!wl128x_switch_tcxo_to_fref(wl))
832 return -EINVAL; 843 return -EINVAL;
833 goto fref_clk; 844 goto fref_clk;
@@ -836,14 +847,14 @@ static int wl128x_boot_clk(struct wl1271 *wl, int *selected_clock)
836 /* TCXO clock is selected */ 847 /* TCXO clock is selected */
837 if (!wl128x_is_tcxo_valid(wl)) 848 if (!wl128x_is_tcxo_valid(wl))
838 return -EINVAL; 849 return -EINVAL;
839 *selected_clock = wl->tcxo_clock; 850 *selected_clock = priv->tcxo_clock;
840 goto config_mcs_pll; 851 goto config_mcs_pll;
841 852
842fref_clk: 853fref_clk:
843 /* FREF clock is selected */ 854 /* FREF clock is selected */
844 if (!wl128x_is_fref_valid(wl)) 855 if (!wl128x_is_fref_valid(wl))
845 return -EINVAL; 856 return -EINVAL;
846 *selected_clock = wl->ref_clock; 857 *selected_clock = priv->ref_clock;
847 858
848config_mcs_pll: 859config_mcs_pll:
849 return wl128x_configure_mcs_pll(wl, *selected_clock); 860 return wl128x_configure_mcs_pll(wl, *selected_clock);
@@ -851,25 +862,27 @@ config_mcs_pll:
851 862
852static int wl127x_boot_clk(struct wl1271 *wl) 863static int wl127x_boot_clk(struct wl1271 *wl)
853{ 864{
865 struct wl12xx_priv *priv = wl->priv;
854 u32 pause; 866 u32 pause;
855 u32 clk; 867 u32 clk;
856 868
857 if (WL127X_PG_GET_MAJOR(wl->hw_pg_ver) < 3) 869 if (WL127X_PG_GET_MAJOR(wl->hw_pg_ver) < 3)
858 wl->quirks |= WLCORE_QUIRK_END_OF_TRANSACTION; 870 wl->quirks |= WLCORE_QUIRK_END_OF_TRANSACTION;
859 871
860 if (wl->ref_clock == CONF_REF_CLK_19_2_E || 872 if (priv->ref_clock == CONF_REF_CLK_19_2_E ||
861 wl->ref_clock == CONF_REF_CLK_38_4_E || 873 priv->ref_clock == CONF_REF_CLK_38_4_E ||
862 wl->ref_clock == CONF_REF_CLK_38_4_M_XTAL) 874 priv->ref_clock == CONF_REF_CLK_38_4_M_XTAL)
863 /* ref clk: 19.2/38.4/38.4-XTAL */ 875 /* ref clk: 19.2/38.4/38.4-XTAL */
864 clk = 0x3; 876 clk = 0x3;
865 else if (wl->ref_clock == CONF_REF_CLK_26_E || 877 else if (priv->ref_clock == CONF_REF_CLK_26_E ||
866 wl->ref_clock == CONF_REF_CLK_52_E) 878 priv->ref_clock == CONF_REF_CLK_26_M_XTAL ||
879 priv->ref_clock == CONF_REF_CLK_52_E)
867 /* ref clk: 26/52 */ 880 /* ref clk: 26/52 */
868 clk = 0x5; 881 clk = 0x5;
869 else 882 else
870 return -EINVAL; 883 return -EINVAL;
871 884
872 if (wl->ref_clock != CONF_REF_CLK_19_2_E) { 885 if (priv->ref_clock != CONF_REF_CLK_19_2_E) {
873 u16 val; 886 u16 val;
874 /* Set clock type (open drain) */ 887 /* Set clock type (open drain) */
875 val = wl12xx_top_reg_read(wl, OCP_REG_CLK_TYPE); 888 val = wl12xx_top_reg_read(wl, OCP_REG_CLK_TYPE);
@@ -939,6 +952,7 @@ static int wl1271_boot_soft_reset(struct wl1271 *wl)
939 952
940static int wl12xx_pre_boot(struct wl1271 *wl) 953static int wl12xx_pre_boot(struct wl1271 *wl)
941{ 954{
955 struct wl12xx_priv *priv = wl->priv;
942 int ret = 0; 956 int ret = 0;
943 u32 clk; 957 u32 clk;
944 int selected_clock = -1; 958 int selected_clock = -1;
@@ -970,7 +984,7 @@ static int wl12xx_pre_boot(struct wl1271 *wl)
970 if (wl->chip.id == CHIP_ID_1283_PG20) 984 if (wl->chip.id == CHIP_ID_1283_PG20)
971 clk |= ((selected_clock & 0x3) << 1) << 4; 985 clk |= ((selected_clock & 0x3) << 1) << 4;
972 else 986 else
973 clk |= (wl->ref_clock << 1) << 4; 987 clk |= (priv->ref_clock << 1) << 4;
974 988
975 wl1271_write32(wl, WL12XX_DRPW_SCRATCH_START, clk); 989 wl1271_write32(wl, WL12XX_DRPW_SCRATCH_START, clk);
976 990
@@ -989,7 +1003,7 @@ out:
989 1003
990static void wl12xx_pre_upload(struct wl1271 *wl) 1004static void wl12xx_pre_upload(struct wl1271 *wl)
991{ 1005{
992 u32 tmp; 1006 u32 tmp, polarity;
993 1007
994 /* write firmware's last address (ie. it's length) to 1008 /* write firmware's last address (ie. it's length) to
995 * ACX_EEPROMLESS_IND_REG */ 1009 * ACX_EEPROMLESS_IND_REG */
@@ -1009,23 +1023,23 @@ static void wl12xx_pre_upload(struct wl1271 *wl)
1009 1023
1010 if (wl->chip.id == CHIP_ID_1283_PG20) 1024 if (wl->chip.id == CHIP_ID_1283_PG20)
1011 wl12xx_top_reg_write(wl, SDIO_IO_DS, HCI_IO_DS_6MA); 1025 wl12xx_top_reg_write(wl, SDIO_IO_DS, HCI_IO_DS_6MA);
1012}
1013
1014static void wl12xx_enable_interrupts(struct wl1271 *wl)
1015{
1016 u32 polarity;
1017 1026
1027 /* polarity must be set before the firmware is loaded */
1018 polarity = wl12xx_top_reg_read(wl, OCP_REG_POLARITY); 1028 polarity = wl12xx_top_reg_read(wl, OCP_REG_POLARITY);
1019 1029
1020 /* We use HIGH polarity, so unset the LOW bit */ 1030 /* We use HIGH polarity, so unset the LOW bit */
1021 polarity &= ~POLARITY_LOW; 1031 polarity &= ~POLARITY_LOW;
1022 wl12xx_top_reg_write(wl, OCP_REG_POLARITY, polarity); 1032 wl12xx_top_reg_write(wl, OCP_REG_POLARITY, polarity);
1023 1033
1024 wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_ALL_EVENTS_VECTOR); 1034}
1035
1036static void wl12xx_enable_interrupts(struct wl1271 *wl)
1037{
1038 wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL12XX_ACX_ALL_EVENTS_VECTOR);
1025 1039
1026 wlcore_enable_interrupts(wl); 1040 wlcore_enable_interrupts(wl);
1027 wlcore_write_reg(wl, REG_INTERRUPT_MASK, 1041 wlcore_write_reg(wl, REG_INTERRUPT_MASK,
1028 WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK)); 1042 WL1271_ACX_INTR_ALL & ~(WL12XX_INTR_MASK));
1029 1043
1030 wl1271_write32(wl, WL12XX_HI_CFG, HI_CFG_DEF_VAL); 1044 wl1271_write32(wl, WL12XX_HI_CFG, HI_CFG_DEF_VAL);
1031} 1045}
@@ -1149,7 +1163,8 @@ static u32 wl12xx_get_rx_packet_len(struct wl1271 *wl, void *rx_data,
1149 1163
1150static void wl12xx_tx_delayed_compl(struct wl1271 *wl) 1164static void wl12xx_tx_delayed_compl(struct wl1271 *wl)
1151{ 1165{
1152 if (wl->fw_status->tx_results_counter == (wl->tx_results_count & 0xff)) 1166 if (wl->fw_status_1->tx_results_counter ==
1167 (wl->tx_results_count & 0xff))
1153 return; 1168 return;
1154 1169
1155 wl1271_tx_complete(wl); 1170 wl1271_tx_complete(wl);
@@ -1288,10 +1303,90 @@ static void wl12xx_get_mac(struct wl1271 *wl)
1288 wl12xx_get_fuse_mac(wl); 1303 wl12xx_get_fuse_mac(wl);
1289} 1304}
1290 1305
1306static void wl12xx_set_tx_desc_csum(struct wl1271 *wl,
1307 struct wl1271_tx_hw_descr *desc,
1308 struct sk_buff *skb)
1309{
1310 desc->wl12xx_reserved = 0;
1311}
1312
1313static int wl12xx_plt_init(struct wl1271 *wl)
1314{
1315 int ret;
1316
1317 ret = wl->ops->boot(wl);
1318 if (ret < 0)
1319 goto out;
1320
1321 ret = wl->ops->hw_init(wl);
1322 if (ret < 0)
1323 goto out_irq_disable;
1324
1325 ret = wl1271_acx_init_mem_config(wl);
1326 if (ret < 0)
1327 goto out_irq_disable;
1328
1329 ret = wl12xx_acx_mem_cfg(wl);
1330 if (ret < 0)
1331 goto out_free_memmap;
1332
1333 /* Enable data path */
1334 ret = wl1271_cmd_data_path(wl, 1);
1335 if (ret < 0)
1336 goto out_free_memmap;
1337
1338 /* Configure for CAM power saving (ie. always active) */
1339 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
1340 if (ret < 0)
1341 goto out_free_memmap;
1342
1343 /* configure PM */
1344 ret = wl1271_acx_pm_config(wl);
1345 if (ret < 0)
1346 goto out_free_memmap;
1347
1348 goto out;
1349
1350out_free_memmap:
1351 kfree(wl->target_mem_map);
1352 wl->target_mem_map = NULL;
1353
1354out_irq_disable:
1355 mutex_unlock(&wl->mutex);
1356 /* Unlocking the mutex in the middle of handling is
1357 inherently unsafe. In this case we deem it safe to do,
1358 because we need to let any possibly pending IRQ out of
1359 the system (and while we are WL1271_STATE_OFF the IRQ
1360 work function will not do anything.) Also, any other
1361 possible concurrent operations will fail due to the
1362 current state, hence the wl1271 struct should be safe. */
1363 wlcore_disable_interrupts(wl);
1364 mutex_lock(&wl->mutex);
1365out:
1366 return ret;
1367}
1368
1369static int wl12xx_get_spare_blocks(struct wl1271 *wl, bool is_gem)
1370{
1371 if (is_gem)
1372 return WL12XX_TX_HW_BLOCK_GEM_SPARE;
1373
1374 return WL12XX_TX_HW_BLOCK_SPARE_DEFAULT;
1375}
1376
1377static int wl12xx_set_key(struct wl1271 *wl, enum set_key_cmd cmd,
1378 struct ieee80211_vif *vif,
1379 struct ieee80211_sta *sta,
1380 struct ieee80211_key_conf *key_conf)
1381{
1382 return wlcore_set_key(wl, cmd, vif, sta, key_conf);
1383}
1384
1291static struct wlcore_ops wl12xx_ops = { 1385static struct wlcore_ops wl12xx_ops = {
1292 .identify_chip = wl12xx_identify_chip, 1386 .identify_chip = wl12xx_identify_chip,
1293 .identify_fw = wl12xx_identify_fw, 1387 .identify_fw = wl12xx_identify_fw,
1294 .boot = wl12xx_boot, 1388 .boot = wl12xx_boot,
1389 .plt_init = wl12xx_plt_init,
1295 .trigger_cmd = wl12xx_trigger_cmd, 1390 .trigger_cmd = wl12xx_trigger_cmd,
1296 .ack_event = wl12xx_ack_event, 1391 .ack_event = wl12xx_ack_event,
1297 .calc_tx_blocks = wl12xx_calc_tx_blocks, 1392 .calc_tx_blocks = wl12xx_calc_tx_blocks,
@@ -1306,6 +1401,13 @@ static struct wlcore_ops wl12xx_ops = {
1306 .sta_get_ap_rate_mask = wl12xx_sta_get_ap_rate_mask, 1401 .sta_get_ap_rate_mask = wl12xx_sta_get_ap_rate_mask,
1307 .get_pg_ver = wl12xx_get_pg_ver, 1402 .get_pg_ver = wl12xx_get_pg_ver,
1308 .get_mac = wl12xx_get_mac, 1403 .get_mac = wl12xx_get_mac,
1404 .set_tx_desc_csum = wl12xx_set_tx_desc_csum,
1405 .set_rx_csum = NULL,
1406 .ap_get_mimo_wide_rate_mask = NULL,
1407 .debugfs_init = wl12xx_debugfs_add_files,
1408 .get_spare_blocks = wl12xx_get_spare_blocks,
1409 .set_key = wl12xx_set_key,
1410 .pre_pkt_send = NULL,
1309}; 1411};
1310 1412
1311static struct ieee80211_sta_ht_cap wl12xx_ht_cap = { 1413static struct ieee80211_sta_ht_cap wl12xx_ht_cap = {
@@ -1323,6 +1425,7 @@ static struct ieee80211_sta_ht_cap wl12xx_ht_cap = {
1323 1425
1324static int __devinit wl12xx_probe(struct platform_device *pdev) 1426static int __devinit wl12xx_probe(struct platform_device *pdev)
1325{ 1427{
1428 struct wl12xx_platform_data *pdata = pdev->dev.platform_data;
1326 struct wl1271 *wl; 1429 struct wl1271 *wl;
1327 struct ieee80211_hw *hw; 1430 struct ieee80211_hw *hw;
1328 struct wl12xx_priv *priv; 1431 struct wl12xx_priv *priv;
@@ -1334,19 +1437,65 @@ static int __devinit wl12xx_probe(struct platform_device *pdev)
1334 } 1437 }
1335 1438
1336 wl = hw->priv; 1439 wl = hw->priv;
1440 priv = wl->priv;
1337 wl->ops = &wl12xx_ops; 1441 wl->ops = &wl12xx_ops;
1338 wl->ptable = wl12xx_ptable; 1442 wl->ptable = wl12xx_ptable;
1339 wl->rtable = wl12xx_rtable; 1443 wl->rtable = wl12xx_rtable;
1340 wl->num_tx_desc = 16; 1444 wl->num_tx_desc = 16;
1341 wl->normal_tx_spare = WL12XX_TX_HW_BLOCK_SPARE_DEFAULT; 1445 wl->num_rx_desc = 8;
1342 wl->gem_tx_spare = WL12XX_TX_HW_BLOCK_GEM_SPARE;
1343 wl->band_rate_to_idx = wl12xx_band_rate_to_idx; 1446 wl->band_rate_to_idx = wl12xx_band_rate_to_idx;
1344 wl->hw_tx_rate_tbl_size = WL12XX_CONF_HW_RXTX_RATE_MAX; 1447 wl->hw_tx_rate_tbl_size = WL12XX_CONF_HW_RXTX_RATE_MAX;
1345 wl->hw_min_ht_rate = WL12XX_CONF_HW_RXTX_RATE_MCS0; 1448 wl->hw_min_ht_rate = WL12XX_CONF_HW_RXTX_RATE_MCS0;
1346 wl->fw_status_priv_len = 0; 1449 wl->fw_status_priv_len = 0;
1347 memcpy(&wl->ht_cap, &wl12xx_ht_cap, sizeof(wl12xx_ht_cap)); 1450 wl->stats.fw_stats_len = sizeof(struct wl12xx_acx_statistics);
1451 memcpy(&wl->ht_cap[IEEE80211_BAND_2GHZ], &wl12xx_ht_cap,
1452 sizeof(wl12xx_ht_cap));
1453 memcpy(&wl->ht_cap[IEEE80211_BAND_5GHZ], &wl12xx_ht_cap,
1454 sizeof(wl12xx_ht_cap));
1348 wl12xx_conf_init(wl); 1455 wl12xx_conf_init(wl);
1349 1456
1457 if (!fref_param) {
1458 priv->ref_clock = pdata->board_ref_clock;
1459 } else {
1460 if (!strcmp(fref_param, "19.2"))
1461 priv->ref_clock = WL12XX_REFCLOCK_19;
1462 else if (!strcmp(fref_param, "26"))
1463 priv->ref_clock = WL12XX_REFCLOCK_26;
1464 else if (!strcmp(fref_param, "26x"))
1465 priv->ref_clock = WL12XX_REFCLOCK_26_XTAL;
1466 else if (!strcmp(fref_param, "38.4"))
1467 priv->ref_clock = WL12XX_REFCLOCK_38;
1468 else if (!strcmp(fref_param, "38.4x"))
1469 priv->ref_clock = WL12XX_REFCLOCK_38_XTAL;
1470 else if (!strcmp(fref_param, "52"))
1471 priv->ref_clock = WL12XX_REFCLOCK_52;
1472 else
1473 wl1271_error("Invalid fref parameter %s", fref_param);
1474 }
1475
1476 if (!tcxo_param) {
1477 priv->tcxo_clock = pdata->board_tcxo_clock;
1478 } else {
1479 if (!strcmp(tcxo_param, "19.2"))
1480 priv->tcxo_clock = WL12XX_TCXOCLOCK_19_2;
1481 else if (!strcmp(tcxo_param, "26"))
1482 priv->tcxo_clock = WL12XX_TCXOCLOCK_26;
1483 else if (!strcmp(tcxo_param, "38.4"))
1484 priv->tcxo_clock = WL12XX_TCXOCLOCK_38_4;
1485 else if (!strcmp(tcxo_param, "52"))
1486 priv->tcxo_clock = WL12XX_TCXOCLOCK_52;
1487 else if (!strcmp(tcxo_param, "16.368"))
1488 priv->tcxo_clock = WL12XX_TCXOCLOCK_16_368;
1489 else if (!strcmp(tcxo_param, "32.736"))
1490 priv->tcxo_clock = WL12XX_TCXOCLOCK_32_736;
1491 else if (!strcmp(tcxo_param, "16.8"))
1492 priv->tcxo_clock = WL12XX_TCXOCLOCK_16_8;
1493 else if (!strcmp(tcxo_param, "33.6"))
1494 priv->tcxo_clock = WL12XX_TCXOCLOCK_33_6;
1495 else
1496 wl1271_error("Invalid tcxo parameter %s", tcxo_param);
1497 }
1498
1350 return wlcore_probe(wl, pdev); 1499 return wlcore_probe(wl, pdev);
1351} 1500}
1352 1501
@@ -1378,6 +1527,13 @@ static void __exit wl12xx_exit(void)
1378} 1527}
1379module_exit(wl12xx_exit); 1528module_exit(wl12xx_exit);
1380 1529
1530module_param_named(fref, fref_param, charp, 0);
1531MODULE_PARM_DESC(fref, "FREF clock: 19.2, 26, 26x, 38.4, 38.4x, 52");
1532
1533module_param_named(tcxo, tcxo_param, charp, 0);
1534MODULE_PARM_DESC(tcxo,
1535 "TCXO clock: 19.2, 26, 38.4, 52, 16.368, 32.736, 16.8, 33.6");
1536
1381MODULE_LICENSE("GPL v2"); 1537MODULE_LICENSE("GPL v2");
1382MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>"); 1538MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
1383MODULE_FIRMWARE(WL127X_FW_NAME_SINGLE); 1539MODULE_FIRMWARE(WL127X_FW_NAME_SINGLE);
diff --git a/drivers/net/wireless/ti/wl12xx/wl12xx.h b/drivers/net/wireless/ti/wl12xx/wl12xx.h
index 74cd332e23ef..de1132410876 100644
--- a/drivers/net/wireless/ti/wl12xx/wl12xx.h
+++ b/drivers/net/wireless/ti/wl12xx/wl12xx.h
@@ -24,8 +24,16 @@
24 24
25#include "conf.h" 25#include "conf.h"
26 26
27struct wl127x_rx_mem_pool_addr {
28 u32 addr;
29 u32 addr_extra;
30};
31
27struct wl12xx_priv { 32struct wl12xx_priv {
28 struct wl12xx_priv_conf conf; 33 struct wl12xx_priv_conf conf;
34
35 int ref_clock;
36 int tcxo_clock;
29}; 37};
30 38
31#endif /* __WL12XX_PRIV_H__ */ 39#endif /* __WL12XX_PRIV_H__ */
diff --git a/drivers/net/wireless/ti/wl18xx/Kconfig b/drivers/net/wireless/ti/wl18xx/Kconfig
new file mode 100644
index 000000000000..1cfdb2548821
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/Kconfig
@@ -0,0 +1,7 @@
1config WL18XX
2 tristate "TI wl18xx support"
3 depends on MAC80211
4 select WLCORE
5 ---help---
6 This module adds support for wireless adapters based on TI
7 WiLink 8 chipsets.
diff --git a/drivers/net/wireless/ti/wl18xx/Makefile b/drivers/net/wireless/ti/wl18xx/Makefile
new file mode 100644
index 000000000000..67c098734c7f
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/Makefile
@@ -0,0 +1,3 @@
1wl18xx-objs = main.o acx.o tx.o io.o debugfs.o
2
3obj-$(CONFIG_WL18XX) += wl18xx.o
diff --git a/drivers/net/wireless/ti/wl18xx/acx.c b/drivers/net/wireless/ti/wl18xx/acx.c
new file mode 100644
index 000000000000..72840e23bf59
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/acx.c
@@ -0,0 +1,111 @@
1/*
2 * This file is part of wl18xx
3 *
4 * Copyright (C) 2011 Texas Instruments Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#include "../wlcore/cmd.h"
23#include "../wlcore/debug.h"
24#include "../wlcore/acx.h"
25
26#include "acx.h"
27
28int wl18xx_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap,
29 u32 sdio_blk_size, u32 extra_mem_blks,
30 u32 len_field_size)
31{
32 struct wl18xx_acx_host_config_bitmap *bitmap_conf;
33 int ret;
34
35 wl1271_debug(DEBUG_ACX, "acx cfg bitmap %d blk %d spare %d field %d",
36 host_cfg_bitmap, sdio_blk_size, extra_mem_blks,
37 len_field_size);
38
39 bitmap_conf = kzalloc(sizeof(*bitmap_conf), GFP_KERNEL);
40 if (!bitmap_conf) {
41 ret = -ENOMEM;
42 goto out;
43 }
44
45 bitmap_conf->host_cfg_bitmap = cpu_to_le32(host_cfg_bitmap);
46 bitmap_conf->host_sdio_block_size = cpu_to_le32(sdio_blk_size);
47 bitmap_conf->extra_mem_blocks = cpu_to_le32(extra_mem_blks);
48 bitmap_conf->length_field_size = cpu_to_le32(len_field_size);
49
50 ret = wl1271_cmd_configure(wl, ACX_HOST_IF_CFG_BITMAP,
51 bitmap_conf, sizeof(*bitmap_conf));
52 if (ret < 0) {
53 wl1271_warning("wl1271 bitmap config opt failed: %d", ret);
54 goto out;
55 }
56
57out:
58 kfree(bitmap_conf);
59
60 return ret;
61}
62
63int wl18xx_acx_set_checksum_state(struct wl1271 *wl)
64{
65 struct wl18xx_acx_checksum_state *acx;
66 int ret;
67
68 wl1271_debug(DEBUG_ACX, "acx checksum state");
69
70 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
71 if (!acx) {
72 ret = -ENOMEM;
73 goto out;
74 }
75
76 acx->checksum_state = CHECKSUM_OFFLOAD_ENABLED;
77
78 ret = wl1271_cmd_configure(wl, ACX_CHECKSUM_CONFIG, acx, sizeof(*acx));
79 if (ret < 0) {
80 wl1271_warning("failed to set Tx checksum state: %d", ret);
81 goto out;
82 }
83
84out:
85 kfree(acx);
86 return ret;
87}
88
89int wl18xx_acx_clear_statistics(struct wl1271 *wl)
90{
91 struct wl18xx_acx_clear_statistics *acx;
92 int ret = 0;
93
94 wl1271_debug(DEBUG_ACX, "acx clear statistics");
95
96 acx = kzalloc(sizeof(*acx), GFP_KERNEL);
97 if (!acx) {
98 ret = -ENOMEM;
99 goto out;
100 }
101
102 ret = wl1271_cmd_configure(wl, ACX_CLEAR_STATISTICS, acx, sizeof(*acx));
103 if (ret < 0) {
104 wl1271_warning("failed to clear firmware statistics: %d", ret);
105 goto out;
106 }
107
108out:
109 kfree(acx);
110 return ret;
111}
diff --git a/drivers/net/wireless/ti/wl18xx/acx.h b/drivers/net/wireless/ti/wl18xx/acx.h
new file mode 100644
index 000000000000..ebbaf611e97b
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/acx.h
@@ -0,0 +1,291 @@
1/*
2 * This file is part of wl18xx
3 *
4 * Copyright (C) 2011 Texas Instruments. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#ifndef __WL18XX_ACX_H__
23#define __WL18XX_ACX_H__
24
25#include "../wlcore/wlcore.h"
26#include "../wlcore/acx.h"
27
28enum {
29 ACX_CLEAR_STATISTICS = 0x0047,
30};
31
32/* numbers of bits the length field takes (add 1 for the actual number) */
33#define WL18XX_HOST_IF_LEN_SIZE_FIELD 15
34
35#define WL18XX_ACX_EVENTS_VECTOR_PG1 (WL1271_ACX_INTR_WATCHDOG | \
36 WL1271_ACX_INTR_INIT_COMPLETE | \
37 WL1271_ACX_INTR_EVENT_A | \
38 WL1271_ACX_INTR_EVENT_B | \
39 WL1271_ACX_INTR_CMD_COMPLETE | \
40 WL1271_ACX_INTR_HW_AVAILABLE | \
41 WL1271_ACX_INTR_DATA)
42
43#define WL18XX_ACX_EVENTS_VECTOR_PG2 (WL18XX_ACX_EVENTS_VECTOR_PG1 | \
44 WL1271_ACX_SW_INTR_WATCHDOG)
45
46#define WL18XX_INTR_MASK_PG1 (WL1271_ACX_INTR_WATCHDOG | \
47 WL1271_ACX_INTR_EVENT_A | \
48 WL1271_ACX_INTR_EVENT_B | \
49 WL1271_ACX_INTR_HW_AVAILABLE | \
50 WL1271_ACX_INTR_DATA)
51
52#define WL18XX_INTR_MASK_PG2 (WL18XX_INTR_MASK_PG1 | \
53 WL1271_ACX_SW_INTR_WATCHDOG)
54
55struct wl18xx_acx_host_config_bitmap {
56 struct acx_header header;
57
58 __le32 host_cfg_bitmap;
59
60 __le32 host_sdio_block_size;
61
62 /* extra mem blocks per frame in TX. */
63 __le32 extra_mem_blocks;
64
65 /*
66 * number of bits of the length field in the first TX word
67 * (up to 15 - for using the entire 16 bits).
68 */
69 __le32 length_field_size;
70
71} __packed;
72
73enum {
74 CHECKSUM_OFFLOAD_DISABLED = 0,
75 CHECKSUM_OFFLOAD_ENABLED = 1,
76 CHECKSUM_OFFLOAD_FAKE_RX = 2,
77 CHECKSUM_OFFLOAD_INVALID = 0xFF
78};
79
80struct wl18xx_acx_checksum_state {
81 struct acx_header header;
82
83 /* enum acx_checksum_state */
84 u8 checksum_state;
85 u8 pad[3];
86} __packed;
87
88
89struct wl18xx_acx_error_stats {
90 u32 error_frame;
91 u32 error_null_Frame_tx_start;
92 u32 error_numll_frame_cts_start;
93 u32 error_bar_retry;
94 u32 error_frame_cts_nul_flid;
95} __packed;
96
97struct wl18xx_acx_debug_stats {
98 u32 debug1;
99 u32 debug2;
100 u32 debug3;
101 u32 debug4;
102 u32 debug5;
103 u32 debug6;
104} __packed;
105
106struct wl18xx_acx_ring_stats {
107 u32 prepared_descs;
108 u32 tx_cmplt;
109} __packed;
110
111struct wl18xx_acx_tx_stats {
112 u32 tx_prepared_descs;
113 u32 tx_cmplt;
114 u32 tx_template_prepared;
115 u32 tx_data_prepared;
116 u32 tx_template_programmed;
117 u32 tx_data_programmed;
118 u32 tx_burst_programmed;
119 u32 tx_starts;
120 u32 tx_imm_resp;
121 u32 tx_start_templates;
122 u32 tx_start_int_templates;
123 u32 tx_start_fw_gen;
124 u32 tx_start_data;
125 u32 tx_start_null_frame;
126 u32 tx_exch;
127 u32 tx_retry_template;
128 u32 tx_retry_data;
129 u32 tx_exch_pending;
130 u32 tx_exch_expiry;
131 u32 tx_done_template;
132 u32 tx_done_data;
133 u32 tx_done_int_template;
134 u32 tx_frame_checksum;
135 u32 tx_checksum_result;
136 u32 frag_called;
137 u32 frag_mpdu_alloc_failed;
138 u32 frag_init_called;
139 u32 frag_in_process_called;
140 u32 frag_tkip_called;
141 u32 frag_key_not_found;
142 u32 frag_need_fragmentation;
143 u32 frag_bad_mblk_num;
144 u32 frag_failed;
145 u32 frag_cache_hit;
146 u32 frag_cache_miss;
147} __packed;
148
149struct wl18xx_acx_rx_stats {
150 u32 rx_beacon_early_term;
151 u32 rx_out_of_mpdu_nodes;
152 u32 rx_hdr_overflow;
153 u32 rx_dropped_frame;
154 u32 rx_done_stage;
155 u32 rx_done;
156 u32 rx_defrag;
157 u32 rx_defrag_end;
158 u32 rx_cmplt;
159 u32 rx_pre_complt;
160 u32 rx_cmplt_task;
161 u32 rx_phy_hdr;
162 u32 rx_timeout;
163 u32 rx_timeout_wa;
164 u32 rx_wa_density_dropped_frame;
165 u32 rx_wa_ba_not_expected;
166 u32 rx_frame_checksum;
167 u32 rx_checksum_result;
168 u32 defrag_called;
169 u32 defrag_init_called;
170 u32 defrag_in_process_called;
171 u32 defrag_tkip_called;
172 u32 defrag_need_defrag;
173 u32 defrag_decrypt_failed;
174 u32 decrypt_key_not_found;
175 u32 defrag_need_decrypt;
176 u32 rx_tkip_replays;
177} __packed;
178
179struct wl18xx_acx_isr_stats {
180 u32 irqs;
181} __packed;
182
183#define PWR_STAT_MAX_CONT_MISSED_BCNS_SPREAD 10
184
185struct wl18xx_acx_pwr_stats {
186 u32 missing_bcns_cnt;
187 u32 rcvd_bcns_cnt;
188 u32 connection_out_of_sync;
189 u32 cont_miss_bcns_spread[PWR_STAT_MAX_CONT_MISSED_BCNS_SPREAD];
190 u32 rcvd_awake_bcns_cnt;
191} __packed;
192
193struct wl18xx_acx_event_stats {
194 u32 calibration;
195 u32 rx_mismatch;
196 u32 rx_mem_empty;
197} __packed;
198
199struct wl18xx_acx_ps_poll_stats {
200 u32 ps_poll_timeouts;
201 u32 upsd_timeouts;
202 u32 upsd_max_ap_turn;
203 u32 ps_poll_max_ap_turn;
204 u32 ps_poll_utilization;
205 u32 upsd_utilization;
206} __packed;
207
208struct wl18xx_acx_rx_filter_stats {
209 u32 beacon_filter;
210 u32 arp_filter;
211 u32 mc_filter;
212 u32 dup_filter;
213 u32 data_filter;
214 u32 ibss_filter;
215 u32 protection_filter;
216 u32 accum_arp_pend_requests;
217 u32 max_arp_queue_dep;
218} __packed;
219
220struct wl18xx_acx_rx_rate_stats {
221 u32 rx_frames_per_rates[50];
222} __packed;
223
224#define AGGR_STATS_TX_AGG 16
225#define AGGR_STATS_TX_RATE 16
226#define AGGR_STATS_RX_SIZE_LEN 16
227
228struct wl18xx_acx_aggr_stats {
229 u32 tx_agg_vs_rate[AGGR_STATS_TX_AGG * AGGR_STATS_TX_RATE];
230 u32 rx_size[AGGR_STATS_RX_SIZE_LEN];
231} __packed;
232
233#define PIPE_STATS_HW_FIFO 11
234
235struct wl18xx_acx_pipeline_stats {
236 u32 hs_tx_stat_fifo_int;
237 u32 hs_rx_stat_fifo_int;
238 u32 tcp_tx_stat_fifo_int;
239 u32 tcp_rx_stat_fifo_int;
240 u32 enc_tx_stat_fifo_int;
241 u32 enc_rx_stat_fifo_int;
242 u32 rx_complete_stat_fifo_int;
243 u32 pre_proc_swi;
244 u32 post_proc_swi;
245 u32 sec_frag_swi;
246 u32 pre_to_defrag_swi;
247 u32 defrag_to_csum_swi;
248 u32 csum_to_rx_xfer_swi;
249 u32 dec_packet_in;
250 u32 dec_packet_in_fifo_full;
251 u32 dec_packet_out;
252 u32 cs_rx_packet_in;
253 u32 cs_rx_packet_out;
254 u16 pipeline_fifo_full[PIPE_STATS_HW_FIFO];
255} __packed;
256
257struct wl18xx_acx_mem_stats {
258 u32 rx_free_mem_blks;
259 u32 tx_free_mem_blks;
260 u32 fwlog_free_mem_blks;
261 u32 fw_gen_free_mem_blks;
262} __packed;
263
264struct wl18xx_acx_statistics {
265 struct acx_header header;
266
267 struct wl18xx_acx_error_stats error;
268 struct wl18xx_acx_debug_stats debug;
269 struct wl18xx_acx_tx_stats tx;
270 struct wl18xx_acx_rx_stats rx;
271 struct wl18xx_acx_isr_stats isr;
272 struct wl18xx_acx_pwr_stats pwr;
273 struct wl18xx_acx_ps_poll_stats ps_poll;
274 struct wl18xx_acx_rx_filter_stats rx_filter;
275 struct wl18xx_acx_rx_rate_stats rx_rate;
276 struct wl18xx_acx_aggr_stats aggr_size;
277 struct wl18xx_acx_pipeline_stats pipeline;
278 struct wl18xx_acx_mem_stats mem;
279} __packed;
280
281struct wl18xx_acx_clear_statistics {
282 struct acx_header header;
283};
284
285int wl18xx_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap,
286 u32 sdio_blk_size, u32 extra_mem_blks,
287 u32 len_field_size);
288int wl18xx_acx_set_checksum_state(struct wl1271 *wl);
289int wl18xx_acx_clear_statistics(struct wl1271 *wl);
290
291#endif /* __WL18XX_ACX_H__ */
diff --git a/drivers/net/wireless/ti/wl18xx/conf.h b/drivers/net/wireless/ti/wl18xx/conf.h
new file mode 100644
index 000000000000..fac0b7e87e75
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/conf.h
@@ -0,0 +1,92 @@
1/*
2 * This file is part of wl18xx
3 *
4 * Copyright (C) 2011 Texas Instruments Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#ifndef __WL18XX_CONF_H__
23#define __WL18XX_CONF_H__
24
25#define WL18XX_CONF_MAGIC 0x10e100ca
26#define WL18XX_CONF_VERSION (WLCORE_CONF_VERSION | 0x0002)
27#define WL18XX_CONF_MASK 0x0000ffff
28#define WL18XX_CONF_SIZE (WLCORE_CONF_SIZE + \
29 sizeof(struct wl18xx_priv_conf))
30
31#define NUM_OF_CHANNELS_11_ABG 150
32#define NUM_OF_CHANNELS_11_P 7
33#define WL18XX_NUM_OF_SUB_BANDS 9
34#define SRF_TABLE_LEN 16
35#define PIN_MUXING_SIZE 2
36
37struct wl18xx_mac_and_phy_params {
38 u8 phy_standalone;
39 u8 rdl;
40 u8 enable_clpc;
41 u8 enable_tx_low_pwr_on_siso_rdl;
42 u8 auto_detect;
43 u8 dedicated_fem;
44
45 u8 low_band_component;
46
47 /* Bit 0: One Hot, Bit 1: Control Enable, Bit 2: 1.8V, Bit 3: 3V */
48 u8 low_band_component_type;
49
50 u8 high_band_component;
51
52 /* Bit 0: One Hot, Bit 1: Control Enable, Bit 2: 1.8V, Bit 3: 3V */
53 u8 high_band_component_type;
54 u8 number_of_assembled_ant2_4;
55 u8 number_of_assembled_ant5;
56 u8 pin_muxing_platform_options[PIN_MUXING_SIZE];
57 u8 external_pa_dc2dc;
58 u8 tcxo_ldo_voltage;
59 u8 xtal_itrim_val;
60 u8 srf_state;
61 u8 srf1[SRF_TABLE_LEN];
62 u8 srf2[SRF_TABLE_LEN];
63 u8 srf3[SRF_TABLE_LEN];
64 u8 io_configuration;
65 u8 sdio_configuration;
66 u8 settings;
67 u8 rx_profile;
68 u8 per_chan_pwr_limit_arr_11abg[NUM_OF_CHANNELS_11_ABG];
69 u8 pwr_limit_reference_11_abg;
70 u8 per_chan_pwr_limit_arr_11p[NUM_OF_CHANNELS_11_P];
71 u8 pwr_limit_reference_11p;
72 u8 per_sub_band_tx_trace_loss[WL18XX_NUM_OF_SUB_BANDS];
73 u8 per_sub_band_rx_trace_loss[WL18XX_NUM_OF_SUB_BANDS];
74 u8 primary_clock_setting_time;
75 u8 clock_valid_on_wake_up;
76 u8 secondary_clock_setting_time;
77 u8 board_type;
78 /* enable point saturation */
79 u8 psat;
80 /* low/medium/high Tx power in dBm */
81 s8 low_power_val;
82 s8 med_power_val;
83 s8 high_power_val;
84 u8 padding[1];
85} __packed;
86
87struct wl18xx_priv_conf {
88 /* this structure is copied wholesale to FW */
89 struct wl18xx_mac_and_phy_params phy;
90} __packed;
91
92#endif /* __WL18XX_CONF_H__ */
diff --git a/drivers/net/wireless/ti/wl18xx/debugfs.c b/drivers/net/wireless/ti/wl18xx/debugfs.c
new file mode 100644
index 000000000000..3ce6f1039af3
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/debugfs.c
@@ -0,0 +1,403 @@
1/*
2 * This file is part of wl18xx
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 * Copyright (C) 2011-2012 Texas Instruments
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * version 2 as published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301 USA
20 *
21 */
22
23#include "../wlcore/debugfs.h"
24#include "../wlcore/wlcore.h"
25
26#include "wl18xx.h"
27#include "acx.h"
28#include "debugfs.h"
29
30#define WL18XX_DEBUGFS_FWSTATS_FILE(a, b, c) \
31 DEBUGFS_FWSTATS_FILE(a, b, c, wl18xx_acx_statistics)
32#define WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(a, b, c) \
33 DEBUGFS_FWSTATS_FILE_ARRAY(a, b, c, wl18xx_acx_statistics)
34
35
36WL18XX_DEBUGFS_FWSTATS_FILE(debug, debug1, "%u");
37WL18XX_DEBUGFS_FWSTATS_FILE(debug, debug2, "%u");
38WL18XX_DEBUGFS_FWSTATS_FILE(debug, debug3, "%u");
39WL18XX_DEBUGFS_FWSTATS_FILE(debug, debug4, "%u");
40WL18XX_DEBUGFS_FWSTATS_FILE(debug, debug5, "%u");
41WL18XX_DEBUGFS_FWSTATS_FILE(debug, debug6, "%u");
42
43WL18XX_DEBUGFS_FWSTATS_FILE(error, error_frame, "%u");
44WL18XX_DEBUGFS_FWSTATS_FILE(error, error_null_Frame_tx_start, "%u");
45WL18XX_DEBUGFS_FWSTATS_FILE(error, error_numll_frame_cts_start, "%u");
46WL18XX_DEBUGFS_FWSTATS_FILE(error, error_bar_retry, "%u");
47WL18XX_DEBUGFS_FWSTATS_FILE(error, error_frame_cts_nul_flid, "%u");
48
49WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_prepared_descs, "%u");
50WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_cmplt, "%u");
51WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_template_prepared, "%u");
52WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_data_prepared, "%u");
53WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_template_programmed, "%u");
54WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_data_programmed, "%u");
55WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_burst_programmed, "%u");
56WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_starts, "%u");
57WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_imm_resp, "%u");
58WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_start_templates, "%u");
59WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_start_int_templates, "%u");
60WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_start_fw_gen, "%u");
61WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_start_data, "%u");
62WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_start_null_frame, "%u");
63WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_exch, "%u");
64WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_retry_template, "%u");
65WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_retry_data, "%u");
66WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_exch_pending, "%u");
67WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_exch_expiry, "%u");
68WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_done_template, "%u");
69WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_done_data, "%u");
70WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_done_int_template, "%u");
71WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_frame_checksum, "%u");
72WL18XX_DEBUGFS_FWSTATS_FILE(tx, tx_checksum_result, "%u");
73WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_called, "%u");
74WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_mpdu_alloc_failed, "%u");
75WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_init_called, "%u");
76WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_in_process_called, "%u");
77WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_tkip_called, "%u");
78WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_key_not_found, "%u");
79WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_need_fragmentation, "%u");
80WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_bad_mblk_num, "%u");
81WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_failed, "%u");
82WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_cache_hit, "%u");
83WL18XX_DEBUGFS_FWSTATS_FILE(tx, frag_cache_miss, "%u");
84
85WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_beacon_early_term, "%u");
86WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_out_of_mpdu_nodes, "%u");
87WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_hdr_overflow, "%u");
88WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_dropped_frame, "%u");
89WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_done, "%u");
90WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_defrag, "%u");
91WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_defrag_end, "%u");
92WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_cmplt, "%u");
93WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_pre_complt, "%u");
94WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_cmplt_task, "%u");
95WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_phy_hdr, "%u");
96WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_timeout, "%u");
97WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_timeout_wa, "%u");
98WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_wa_density_dropped_frame, "%u");
99WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_wa_ba_not_expected, "%u");
100WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_frame_checksum, "%u");
101WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_checksum_result, "%u");
102WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_called, "%u");
103WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_init_called, "%u");
104WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_in_process_called, "%u");
105WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_tkip_called, "%u");
106WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_need_defrag, "%u");
107WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_decrypt_failed, "%u");
108WL18XX_DEBUGFS_FWSTATS_FILE(rx, decrypt_key_not_found, "%u");
109WL18XX_DEBUGFS_FWSTATS_FILE(rx, defrag_need_decrypt, "%u");
110WL18XX_DEBUGFS_FWSTATS_FILE(rx, rx_tkip_replays, "%u");
111
112WL18XX_DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
113
114WL18XX_DEBUGFS_FWSTATS_FILE(pwr, missing_bcns_cnt, "%u");
115WL18XX_DEBUGFS_FWSTATS_FILE(pwr, rcvd_bcns_cnt, "%u");
116WL18XX_DEBUGFS_FWSTATS_FILE(pwr, connection_out_of_sync, "%u");
117WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(pwr, cont_miss_bcns_spread,
118 PWR_STAT_MAX_CONT_MISSED_BCNS_SPREAD);
119WL18XX_DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_bcns_cnt, "%u");
120
121
122WL18XX_DEBUGFS_FWSTATS_FILE(ps_poll, ps_poll_timeouts, "%u");
123WL18XX_DEBUGFS_FWSTATS_FILE(ps_poll, upsd_timeouts, "%u");
124WL18XX_DEBUGFS_FWSTATS_FILE(ps_poll, upsd_max_ap_turn, "%u");
125WL18XX_DEBUGFS_FWSTATS_FILE(ps_poll, ps_poll_max_ap_turn, "%u");
126WL18XX_DEBUGFS_FWSTATS_FILE(ps_poll, ps_poll_utilization, "%u");
127WL18XX_DEBUGFS_FWSTATS_FILE(ps_poll, upsd_utilization, "%u");
128
129WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, beacon_filter, "%u");
130WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, arp_filter, "%u");
131WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, mc_filter, "%u");
132WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, dup_filter, "%u");
133WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, data_filter, "%u");
134WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, ibss_filter, "%u");
135WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, protection_filter, "%u");
136WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, accum_arp_pend_requests, "%u");
137WL18XX_DEBUGFS_FWSTATS_FILE(rx_filter, max_arp_queue_dep, "%u");
138
139WL18XX_DEBUGFS_FWSTATS_FILE(rx_rate, rx_frames_per_rates, "%u");
140
141WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(aggr_size, tx_agg_vs_rate,
142 AGGR_STATS_TX_AGG*AGGR_STATS_TX_RATE);
143WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(aggr_size, rx_size,
144 AGGR_STATS_RX_SIZE_LEN);
145
146WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, hs_tx_stat_fifo_int, "%u");
147WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, tcp_tx_stat_fifo_int, "%u");
148WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, tcp_rx_stat_fifo_int, "%u");
149WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, enc_tx_stat_fifo_int, "%u");
150WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, enc_rx_stat_fifo_int, "%u");
151WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, rx_complete_stat_fifo_int, "%u");
152WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, pre_proc_swi, "%u");
153WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, post_proc_swi, "%u");
154WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, sec_frag_swi, "%u");
155WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, pre_to_defrag_swi, "%u");
156WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, defrag_to_csum_swi, "%u");
157WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, csum_to_rx_xfer_swi, "%u");
158WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, dec_packet_in, "%u");
159WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, dec_packet_in_fifo_full, "%u");
160WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, dec_packet_out, "%u");
161WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, cs_rx_packet_in, "%u");
162WL18XX_DEBUGFS_FWSTATS_FILE(pipeline, cs_rx_packet_out, "%u");
163
164WL18XX_DEBUGFS_FWSTATS_FILE_ARRAY(pipeline, pipeline_fifo_full,
165 PIPE_STATS_HW_FIFO);
166
167WL18XX_DEBUGFS_FWSTATS_FILE(mem, rx_free_mem_blks, "%u");
168WL18XX_DEBUGFS_FWSTATS_FILE(mem, tx_free_mem_blks, "%u");
169WL18XX_DEBUGFS_FWSTATS_FILE(mem, fwlog_free_mem_blks, "%u");
170WL18XX_DEBUGFS_FWSTATS_FILE(mem, fw_gen_free_mem_blks, "%u");
171
172static ssize_t conf_read(struct file *file, char __user *user_buf,
173 size_t count, loff_t *ppos)
174{
175 struct wl1271 *wl = file->private_data;
176 struct wl18xx_priv *priv = wl->priv;
177 struct wlcore_conf_header header;
178 char *buf, *pos;
179 size_t len;
180 int ret;
181
182 len = WL18XX_CONF_SIZE;
183 buf = kmalloc(len, GFP_KERNEL);
184 if (!buf)
185 return -ENOMEM;
186
187 header.magic = cpu_to_le32(WL18XX_CONF_MAGIC);
188 header.version = cpu_to_le32(WL18XX_CONF_VERSION);
189 header.checksum = 0;
190
191 mutex_lock(&wl->mutex);
192
193 pos = buf;
194 memcpy(pos, &header, sizeof(header));
195 pos += sizeof(header);
196 memcpy(pos, &wl->conf, sizeof(wl->conf));
197 pos += sizeof(wl->conf);
198 memcpy(pos, &priv->conf, sizeof(priv->conf));
199
200 mutex_unlock(&wl->mutex);
201
202 ret = simple_read_from_buffer(user_buf, count, ppos, buf, len);
203
204 kfree(buf);
205 return ret;
206}
207
208static const struct file_operations conf_ops = {
209 .read = conf_read,
210 .open = simple_open,
211 .llseek = default_llseek,
212};
213
214static ssize_t clear_fw_stats_write(struct file *file,
215 const char __user *user_buf,
216 size_t count, loff_t *ppos)
217{
218 struct wl1271 *wl = file->private_data;
219 int ret;
220
221 mutex_lock(&wl->mutex);
222
223 if (wl->state == WL1271_STATE_OFF)
224 goto out;
225
226 ret = wl18xx_acx_clear_statistics(wl);
227 if (ret < 0) {
228 count = ret;
229 goto out;
230 }
231out:
232 mutex_unlock(&wl->mutex);
233 return count;
234}
235
236static const struct file_operations clear_fw_stats_ops = {
237 .write = clear_fw_stats_write,
238 .open = simple_open,
239 .llseek = default_llseek,
240};
241
242int wl18xx_debugfs_add_files(struct wl1271 *wl,
243 struct dentry *rootdir)
244{
245 int ret = 0;
246 struct dentry *entry, *stats, *moddir;
247
248 moddir = debugfs_create_dir(KBUILD_MODNAME, rootdir);
249 if (!moddir || IS_ERR(moddir)) {
250 entry = moddir;
251 goto err;
252 }
253
254 stats = debugfs_create_dir("fw_stats", moddir);
255 if (!stats || IS_ERR(stats)) {
256 entry = stats;
257 goto err;
258 }
259
260 DEBUGFS_ADD(clear_fw_stats, stats);
261
262 DEBUGFS_FWSTATS_ADD(debug, debug1);
263 DEBUGFS_FWSTATS_ADD(debug, debug2);
264 DEBUGFS_FWSTATS_ADD(debug, debug3);
265 DEBUGFS_FWSTATS_ADD(debug, debug4);
266 DEBUGFS_FWSTATS_ADD(debug, debug5);
267 DEBUGFS_FWSTATS_ADD(debug, debug6);
268
269 DEBUGFS_FWSTATS_ADD(error, error_frame);
270 DEBUGFS_FWSTATS_ADD(error, error_null_Frame_tx_start);
271 DEBUGFS_FWSTATS_ADD(error, error_numll_frame_cts_start);
272 DEBUGFS_FWSTATS_ADD(error, error_bar_retry);
273 DEBUGFS_FWSTATS_ADD(error, error_frame_cts_nul_flid);
274
275 DEBUGFS_FWSTATS_ADD(tx, tx_prepared_descs);
276 DEBUGFS_FWSTATS_ADD(tx, tx_cmplt);
277 DEBUGFS_FWSTATS_ADD(tx, tx_template_prepared);
278 DEBUGFS_FWSTATS_ADD(tx, tx_data_prepared);
279 DEBUGFS_FWSTATS_ADD(tx, tx_template_programmed);
280 DEBUGFS_FWSTATS_ADD(tx, tx_data_programmed);
281 DEBUGFS_FWSTATS_ADD(tx, tx_burst_programmed);
282 DEBUGFS_FWSTATS_ADD(tx, tx_starts);
283 DEBUGFS_FWSTATS_ADD(tx, tx_imm_resp);
284 DEBUGFS_FWSTATS_ADD(tx, tx_start_templates);
285 DEBUGFS_FWSTATS_ADD(tx, tx_start_int_templates);
286 DEBUGFS_FWSTATS_ADD(tx, tx_start_fw_gen);
287 DEBUGFS_FWSTATS_ADD(tx, tx_start_data);
288 DEBUGFS_FWSTATS_ADD(tx, tx_start_null_frame);
289 DEBUGFS_FWSTATS_ADD(tx, tx_exch);
290 DEBUGFS_FWSTATS_ADD(tx, tx_retry_template);
291 DEBUGFS_FWSTATS_ADD(tx, tx_retry_data);
292 DEBUGFS_FWSTATS_ADD(tx, tx_exch_pending);
293 DEBUGFS_FWSTATS_ADD(tx, tx_exch_expiry);
294 DEBUGFS_FWSTATS_ADD(tx, tx_done_template);
295 DEBUGFS_FWSTATS_ADD(tx, tx_done_data);
296 DEBUGFS_FWSTATS_ADD(tx, tx_done_int_template);
297 DEBUGFS_FWSTATS_ADD(tx, tx_frame_checksum);
298 DEBUGFS_FWSTATS_ADD(tx, tx_checksum_result);
299 DEBUGFS_FWSTATS_ADD(tx, frag_called);
300 DEBUGFS_FWSTATS_ADD(tx, frag_mpdu_alloc_failed);
301 DEBUGFS_FWSTATS_ADD(tx, frag_init_called);
302 DEBUGFS_FWSTATS_ADD(tx, frag_in_process_called);
303 DEBUGFS_FWSTATS_ADD(tx, frag_tkip_called);
304 DEBUGFS_FWSTATS_ADD(tx, frag_key_not_found);
305 DEBUGFS_FWSTATS_ADD(tx, frag_need_fragmentation);
306 DEBUGFS_FWSTATS_ADD(tx, frag_bad_mblk_num);
307 DEBUGFS_FWSTATS_ADD(tx, frag_failed);
308 DEBUGFS_FWSTATS_ADD(tx, frag_cache_hit);
309 DEBUGFS_FWSTATS_ADD(tx, frag_cache_miss);
310
311 DEBUGFS_FWSTATS_ADD(rx, rx_beacon_early_term);
312 DEBUGFS_FWSTATS_ADD(rx, rx_out_of_mpdu_nodes);
313 DEBUGFS_FWSTATS_ADD(rx, rx_hdr_overflow);
314 DEBUGFS_FWSTATS_ADD(rx, rx_dropped_frame);
315 DEBUGFS_FWSTATS_ADD(rx, rx_done);
316 DEBUGFS_FWSTATS_ADD(rx, rx_defrag);
317 DEBUGFS_FWSTATS_ADD(rx, rx_defrag_end);
318 DEBUGFS_FWSTATS_ADD(rx, rx_cmplt);
319 DEBUGFS_FWSTATS_ADD(rx, rx_pre_complt);
320 DEBUGFS_FWSTATS_ADD(rx, rx_cmplt_task);
321 DEBUGFS_FWSTATS_ADD(rx, rx_phy_hdr);
322 DEBUGFS_FWSTATS_ADD(rx, rx_timeout);
323 DEBUGFS_FWSTATS_ADD(rx, rx_timeout_wa);
324 DEBUGFS_FWSTATS_ADD(rx, rx_wa_density_dropped_frame);
325 DEBUGFS_FWSTATS_ADD(rx, rx_wa_ba_not_expected);
326 DEBUGFS_FWSTATS_ADD(rx, rx_frame_checksum);
327 DEBUGFS_FWSTATS_ADD(rx, rx_checksum_result);
328 DEBUGFS_FWSTATS_ADD(rx, defrag_called);
329 DEBUGFS_FWSTATS_ADD(rx, defrag_init_called);
330 DEBUGFS_FWSTATS_ADD(rx, defrag_in_process_called);
331 DEBUGFS_FWSTATS_ADD(rx, defrag_tkip_called);
332 DEBUGFS_FWSTATS_ADD(rx, defrag_need_defrag);
333 DEBUGFS_FWSTATS_ADD(rx, defrag_decrypt_failed);
334 DEBUGFS_FWSTATS_ADD(rx, decrypt_key_not_found);
335 DEBUGFS_FWSTATS_ADD(rx, defrag_need_decrypt);
336 DEBUGFS_FWSTATS_ADD(rx, rx_tkip_replays);
337
338 DEBUGFS_FWSTATS_ADD(isr, irqs);
339
340 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns_cnt);
341 DEBUGFS_FWSTATS_ADD(pwr, rcvd_bcns_cnt);
342 DEBUGFS_FWSTATS_ADD(pwr, connection_out_of_sync);
343 DEBUGFS_FWSTATS_ADD(pwr, cont_miss_bcns_spread);
344 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_bcns_cnt);
345
346 DEBUGFS_FWSTATS_ADD(ps_poll, ps_poll_timeouts);
347 DEBUGFS_FWSTATS_ADD(ps_poll, upsd_timeouts);
348 DEBUGFS_FWSTATS_ADD(ps_poll, upsd_max_ap_turn);
349 DEBUGFS_FWSTATS_ADD(ps_poll, ps_poll_max_ap_turn);
350 DEBUGFS_FWSTATS_ADD(ps_poll, ps_poll_utilization);
351 DEBUGFS_FWSTATS_ADD(ps_poll, upsd_utilization);
352
353 DEBUGFS_FWSTATS_ADD(rx_filter, beacon_filter);
354 DEBUGFS_FWSTATS_ADD(rx_filter, arp_filter);
355 DEBUGFS_FWSTATS_ADD(rx_filter, mc_filter);
356 DEBUGFS_FWSTATS_ADD(rx_filter, dup_filter);
357 DEBUGFS_FWSTATS_ADD(rx_filter, data_filter);
358 DEBUGFS_FWSTATS_ADD(rx_filter, ibss_filter);
359 DEBUGFS_FWSTATS_ADD(rx_filter, protection_filter);
360 DEBUGFS_FWSTATS_ADD(rx_filter, accum_arp_pend_requests);
361 DEBUGFS_FWSTATS_ADD(rx_filter, max_arp_queue_dep);
362
363 DEBUGFS_FWSTATS_ADD(rx_rate, rx_frames_per_rates);
364
365 DEBUGFS_FWSTATS_ADD(aggr_size, tx_agg_vs_rate);
366 DEBUGFS_FWSTATS_ADD(aggr_size, rx_size);
367
368 DEBUGFS_FWSTATS_ADD(pipeline, hs_tx_stat_fifo_int);
369 DEBUGFS_FWSTATS_ADD(pipeline, tcp_tx_stat_fifo_int);
370 DEBUGFS_FWSTATS_ADD(pipeline, tcp_rx_stat_fifo_int);
371 DEBUGFS_FWSTATS_ADD(pipeline, enc_tx_stat_fifo_int);
372 DEBUGFS_FWSTATS_ADD(pipeline, enc_rx_stat_fifo_int);
373 DEBUGFS_FWSTATS_ADD(pipeline, rx_complete_stat_fifo_int);
374 DEBUGFS_FWSTATS_ADD(pipeline, pre_proc_swi);
375 DEBUGFS_FWSTATS_ADD(pipeline, post_proc_swi);
376 DEBUGFS_FWSTATS_ADD(pipeline, sec_frag_swi);
377 DEBUGFS_FWSTATS_ADD(pipeline, pre_to_defrag_swi);
378 DEBUGFS_FWSTATS_ADD(pipeline, defrag_to_csum_swi);
379 DEBUGFS_FWSTATS_ADD(pipeline, csum_to_rx_xfer_swi);
380 DEBUGFS_FWSTATS_ADD(pipeline, dec_packet_in);
381 DEBUGFS_FWSTATS_ADD(pipeline, dec_packet_in_fifo_full);
382 DEBUGFS_FWSTATS_ADD(pipeline, dec_packet_out);
383 DEBUGFS_FWSTATS_ADD(pipeline, cs_rx_packet_in);
384 DEBUGFS_FWSTATS_ADD(pipeline, cs_rx_packet_out);
385 DEBUGFS_FWSTATS_ADD(pipeline, pipeline_fifo_full);
386
387 DEBUGFS_FWSTATS_ADD(mem, rx_free_mem_blks);
388 DEBUGFS_FWSTATS_ADD(mem, tx_free_mem_blks);
389 DEBUGFS_FWSTATS_ADD(mem, fwlog_free_mem_blks);
390 DEBUGFS_FWSTATS_ADD(mem, fw_gen_free_mem_blks);
391
392 DEBUGFS_ADD(conf, moddir);
393
394 return 0;
395
396err:
397 if (IS_ERR(entry))
398 ret = PTR_ERR(entry);
399 else
400 ret = -ENOMEM;
401
402 return ret;
403}
diff --git a/drivers/net/wireless/ti/wl18xx/debugfs.h b/drivers/net/wireless/ti/wl18xx/debugfs.h
new file mode 100644
index 000000000000..ed679bebf620
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/debugfs.h
@@ -0,0 +1,28 @@
1/*
2 * This file is part of wl18xx
3 *
4 * Copyright (C) 2012 Texas Instruments. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#ifndef __WL18XX_DEBUGFS_H__
23#define __WL18XX_DEBUGFS_H__
24
25int wl18xx_debugfs_add_files(struct wl1271 *wl,
26 struct dentry *rootdir);
27
28#endif /* __WL18XX_DEBUGFS_H__ */
diff --git a/drivers/net/wireless/ti/wl18xx/io.c b/drivers/net/wireless/ti/wl18xx/io.c
new file mode 100644
index 000000000000..598c057e722b
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/io.c
@@ -0,0 +1,60 @@
1/*
2 * This file is part of wl18xx
3 *
4 * Copyright (C) 2011 Texas Instruments
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#include "../wlcore/wlcore.h"
23#include "../wlcore/io.h"
24
25#include "io.h"
26
27void wl18xx_top_reg_write(struct wl1271 *wl, int addr, u16 val)
28{
29 u32 tmp;
30
31 if (WARN_ON(addr % 2))
32 return;
33
34 if ((addr % 4) == 0) {
35 tmp = wl1271_read32(wl, addr);
36 tmp = (tmp & 0xffff0000) | val;
37 wl1271_write32(wl, addr, tmp);
38 } else {
39 tmp = wl1271_read32(wl, addr - 2);
40 tmp = (tmp & 0xffff) | (val << 16);
41 wl1271_write32(wl, addr - 2, tmp);
42 }
43}
44
45u16 wl18xx_top_reg_read(struct wl1271 *wl, int addr)
46{
47 u32 val;
48
49 if (WARN_ON(addr % 2))
50 return 0;
51
52 if ((addr % 4) == 0) {
53 /* address is 4-bytes aligned */
54 val = wl1271_read32(wl, addr);
55 return val & 0xffff;
56 } else {
57 val = wl1271_read32(wl, addr - 2);
58 return (val & 0xffff0000) >> 16;
59 }
60}
diff --git a/drivers/net/wireless/ti/wl18xx/io.h b/drivers/net/wireless/ti/wl18xx/io.h
new file mode 100644
index 000000000000..be4e126ff617
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/io.h
@@ -0,0 +1,28 @@
1/*
2 * This file is part of wl18xx
3 *
4 * Copyright (C) 2011 Texas Instruments
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#ifndef __WL18XX_IO_H__
23#define __WL18XX_IO_H__
24
25void wl18xx_top_reg_write(struct wl1271 *wl, int addr, u16 val);
26u16 wl18xx_top_reg_read(struct wl1271 *wl, int addr);
27
28#endif /* __WL18XX_IO_H__ */
diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
new file mode 100644
index 000000000000..ed9c3650e08a
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/main.c
@@ -0,0 +1,1463 @@
1/*
2 * This file is part of wl18xx
3 *
4 * Copyright (C) 2011 Texas Instruments
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#include <linux/module.h>
23#include <linux/platform_device.h>
24#include <linux/ip.h>
25#include <linux/firmware.h>
26
27#include "../wlcore/wlcore.h"
28#include "../wlcore/debug.h"
29#include "../wlcore/io.h"
30#include "../wlcore/acx.h"
31#include "../wlcore/tx.h"
32#include "../wlcore/rx.h"
33#include "../wlcore/io.h"
34#include "../wlcore/boot.h"
35
36#include "reg.h"
37#include "conf.h"
38#include "acx.h"
39#include "tx.h"
40#include "wl18xx.h"
41#include "io.h"
42#include "debugfs.h"
43
44#define WL18XX_RX_CHECKSUM_MASK 0x40
45
46static char *ht_mode_param = "wide";
47static char *board_type_param = "hdk";
48static bool checksum_param = false;
49static bool enable_11a_param = true;
50
51/* phy paramters */
52static int dc2dc_param = -1;
53static int n_antennas_2_param = -1;
54static int n_antennas_5_param = -1;
55static int low_band_component_param = -1;
56static int low_band_component_type_param = -1;
57static int high_band_component_param = -1;
58static int high_band_component_type_param = -1;
59static int pwr_limit_reference_11_abg_param = -1;
60
61static const u8 wl18xx_rate_to_idx_2ghz[] = {
62 /* MCS rates are used only with 11n */
63 15, /* WL18XX_CONF_HW_RXTX_RATE_MCS15 */
64 14, /* WL18XX_CONF_HW_RXTX_RATE_MCS14 */
65 13, /* WL18XX_CONF_HW_RXTX_RATE_MCS13 */
66 12, /* WL18XX_CONF_HW_RXTX_RATE_MCS12 */
67 11, /* WL18XX_CONF_HW_RXTX_RATE_MCS11 */
68 10, /* WL18XX_CONF_HW_RXTX_RATE_MCS10 */
69 9, /* WL18XX_CONF_HW_RXTX_RATE_MCS9 */
70 8, /* WL18XX_CONF_HW_RXTX_RATE_MCS8 */
71 7, /* WL18XX_CONF_HW_RXTX_RATE_MCS7 */
72 6, /* WL18XX_CONF_HW_RXTX_RATE_MCS6 */
73 5, /* WL18XX_CONF_HW_RXTX_RATE_MCS5 */
74 4, /* WL18XX_CONF_HW_RXTX_RATE_MCS4 */
75 3, /* WL18XX_CONF_HW_RXTX_RATE_MCS3 */
76 2, /* WL18XX_CONF_HW_RXTX_RATE_MCS2 */
77 1, /* WL18XX_CONF_HW_RXTX_RATE_MCS1 */
78 0, /* WL18XX_CONF_HW_RXTX_RATE_MCS0 */
79
80 11, /* WL18XX_CONF_HW_RXTX_RATE_54 */
81 10, /* WL18XX_CONF_HW_RXTX_RATE_48 */
82 9, /* WL18XX_CONF_HW_RXTX_RATE_36 */
83 8, /* WL18XX_CONF_HW_RXTX_RATE_24 */
84
85 /* TI-specific rate */
86 CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_22 */
87
88 7, /* WL18XX_CONF_HW_RXTX_RATE_18 */
89 6, /* WL18XX_CONF_HW_RXTX_RATE_12 */
90 3, /* WL18XX_CONF_HW_RXTX_RATE_11 */
91 5, /* WL18XX_CONF_HW_RXTX_RATE_9 */
92 4, /* WL18XX_CONF_HW_RXTX_RATE_6 */
93 2, /* WL18XX_CONF_HW_RXTX_RATE_5_5 */
94 1, /* WL18XX_CONF_HW_RXTX_RATE_2 */
95 0 /* WL18XX_CONF_HW_RXTX_RATE_1 */
96};
97
98static const u8 wl18xx_rate_to_idx_5ghz[] = {
99 /* MCS rates are used only with 11n */
100 15, /* WL18XX_CONF_HW_RXTX_RATE_MCS15 */
101 14, /* WL18XX_CONF_HW_RXTX_RATE_MCS14 */
102 13, /* WL18XX_CONF_HW_RXTX_RATE_MCS13 */
103 12, /* WL18XX_CONF_HW_RXTX_RATE_MCS12 */
104 11, /* WL18XX_CONF_HW_RXTX_RATE_MCS11 */
105 10, /* WL18XX_CONF_HW_RXTX_RATE_MCS10 */
106 9, /* WL18XX_CONF_HW_RXTX_RATE_MCS9 */
107 8, /* WL18XX_CONF_HW_RXTX_RATE_MCS8 */
108 7, /* WL18XX_CONF_HW_RXTX_RATE_MCS7 */
109 6, /* WL18XX_CONF_HW_RXTX_RATE_MCS6 */
110 5, /* WL18XX_CONF_HW_RXTX_RATE_MCS5 */
111 4, /* WL18XX_CONF_HW_RXTX_RATE_MCS4 */
112 3, /* WL18XX_CONF_HW_RXTX_RATE_MCS3 */
113 2, /* WL18XX_CONF_HW_RXTX_RATE_MCS2 */
114 1, /* WL18XX_CONF_HW_RXTX_RATE_MCS1 */
115 0, /* WL18XX_CONF_HW_RXTX_RATE_MCS0 */
116
117 7, /* WL18XX_CONF_HW_RXTX_RATE_54 */
118 6, /* WL18XX_CONF_HW_RXTX_RATE_48 */
119 5, /* WL18XX_CONF_HW_RXTX_RATE_36 */
120 4, /* WL18XX_CONF_HW_RXTX_RATE_24 */
121
122 /* TI-specific rate */
123 CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_22 */
124
125 3, /* WL18XX_CONF_HW_RXTX_RATE_18 */
126 2, /* WL18XX_CONF_HW_RXTX_RATE_12 */
127 CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_11 */
128 1, /* WL18XX_CONF_HW_RXTX_RATE_9 */
129 0, /* WL18XX_CONF_HW_RXTX_RATE_6 */
130 CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_5_5 */
131 CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_2 */
132 CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL18XX_CONF_HW_RXTX_RATE_1 */
133};
134
135static const u8 *wl18xx_band_rate_to_idx[] = {
136 [IEEE80211_BAND_2GHZ] = wl18xx_rate_to_idx_2ghz,
137 [IEEE80211_BAND_5GHZ] = wl18xx_rate_to_idx_5ghz
138};
139
140enum wl18xx_hw_rates {
141 WL18XX_CONF_HW_RXTX_RATE_MCS15 = 0,
142 WL18XX_CONF_HW_RXTX_RATE_MCS14,
143 WL18XX_CONF_HW_RXTX_RATE_MCS13,
144 WL18XX_CONF_HW_RXTX_RATE_MCS12,
145 WL18XX_CONF_HW_RXTX_RATE_MCS11,
146 WL18XX_CONF_HW_RXTX_RATE_MCS10,
147 WL18XX_CONF_HW_RXTX_RATE_MCS9,
148 WL18XX_CONF_HW_RXTX_RATE_MCS8,
149 WL18XX_CONF_HW_RXTX_RATE_MCS7,
150 WL18XX_CONF_HW_RXTX_RATE_MCS6,
151 WL18XX_CONF_HW_RXTX_RATE_MCS5,
152 WL18XX_CONF_HW_RXTX_RATE_MCS4,
153 WL18XX_CONF_HW_RXTX_RATE_MCS3,
154 WL18XX_CONF_HW_RXTX_RATE_MCS2,
155 WL18XX_CONF_HW_RXTX_RATE_MCS1,
156 WL18XX_CONF_HW_RXTX_RATE_MCS0,
157 WL18XX_CONF_HW_RXTX_RATE_54,
158 WL18XX_CONF_HW_RXTX_RATE_48,
159 WL18XX_CONF_HW_RXTX_RATE_36,
160 WL18XX_CONF_HW_RXTX_RATE_24,
161 WL18XX_CONF_HW_RXTX_RATE_22,
162 WL18XX_CONF_HW_RXTX_RATE_18,
163 WL18XX_CONF_HW_RXTX_RATE_12,
164 WL18XX_CONF_HW_RXTX_RATE_11,
165 WL18XX_CONF_HW_RXTX_RATE_9,
166 WL18XX_CONF_HW_RXTX_RATE_6,
167 WL18XX_CONF_HW_RXTX_RATE_5_5,
168 WL18XX_CONF_HW_RXTX_RATE_2,
169 WL18XX_CONF_HW_RXTX_RATE_1,
170 WL18XX_CONF_HW_RXTX_RATE_MAX,
171};
172
173static struct wlcore_conf wl18xx_conf = {
174 .sg = {
175 .params = {
176 [CONF_SG_ACL_BT_MASTER_MIN_BR] = 10,
177 [CONF_SG_ACL_BT_MASTER_MAX_BR] = 180,
178 [CONF_SG_ACL_BT_SLAVE_MIN_BR] = 10,
179 [CONF_SG_ACL_BT_SLAVE_MAX_BR] = 180,
180 [CONF_SG_ACL_BT_MASTER_MIN_EDR] = 10,
181 [CONF_SG_ACL_BT_MASTER_MAX_EDR] = 80,
182 [CONF_SG_ACL_BT_SLAVE_MIN_EDR] = 10,
183 [CONF_SG_ACL_BT_SLAVE_MAX_EDR] = 80,
184 [CONF_SG_ACL_WLAN_PS_MASTER_BR] = 8,
185 [CONF_SG_ACL_WLAN_PS_SLAVE_BR] = 8,
186 [CONF_SG_ACL_WLAN_PS_MASTER_EDR] = 20,
187 [CONF_SG_ACL_WLAN_PS_SLAVE_EDR] = 20,
188 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR] = 20,
189 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR] = 35,
190 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR] = 16,
191 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR] = 35,
192 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR] = 32,
193 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR] = 50,
194 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR] = 28,
195 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR] = 50,
196 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR] = 10,
197 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR] = 20,
198 [CONF_SG_ACL_PASSIVE_SCAN_BT_BR] = 75,
199 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR] = 15,
200 [CONF_SG_ACL_PASSIVE_SCAN_BT_EDR] = 27,
201 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR] = 17,
202 /* active scan params */
203 [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
204 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
205 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
206 /* passive scan params */
207 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR] = 800,
208 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR] = 200,
209 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
210 /* passive scan in dual antenna params */
211 [CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN] = 0,
212 [CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN] = 0,
213 [CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN] = 0,
214 /* general params */
215 [CONF_SG_STA_FORCE_PS_IN_BT_SCO] = 1,
216 [CONF_SG_ANTENNA_CONFIGURATION] = 0,
217 [CONF_SG_BEACON_MISS_PERCENT] = 60,
218 [CONF_SG_DHCP_TIME] = 5000,
219 [CONF_SG_RXT] = 1200,
220 [CONF_SG_TXT] = 1000,
221 [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
222 [CONF_SG_GENERAL_USAGE_BIT_MAP] = 3,
223 [CONF_SG_HV3_MAX_SERVED] = 6,
224 [CONF_SG_PS_POLL_TIMEOUT] = 10,
225 [CONF_SG_UPSD_TIMEOUT] = 10,
226 [CONF_SG_CONSECUTIVE_CTS_THRESHOLD] = 2,
227 [CONF_SG_STA_RX_WINDOW_AFTER_DTIM] = 5,
228 [CONF_SG_STA_CONNECTION_PROTECTION_TIME] = 30,
229 /* AP params */
230 [CONF_AP_BEACON_MISS_TX] = 3,
231 [CONF_AP_RX_WINDOW_AFTER_BEACON] = 10,
232 [CONF_AP_BEACON_WINDOW_INTERVAL] = 2,
233 [CONF_AP_CONNECTION_PROTECTION_TIME] = 0,
234 [CONF_AP_BT_ACL_VAL_BT_SERVE_TIME] = 25,
235 [CONF_AP_BT_ACL_VAL_WL_SERVE_TIME] = 25,
236 /* CTS Diluting params */
237 [CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH] = 0,
238 [CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER] = 0,
239 },
240 .state = CONF_SG_PROTECTIVE,
241 },
242 .rx = {
243 .rx_msdu_life_time = 512000,
244 .packet_detection_threshold = 0,
245 .ps_poll_timeout = 15,
246 .upsd_timeout = 15,
247 .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
248 .rx_cca_threshold = 0,
249 .irq_blk_threshold = 0xFFFF,
250 .irq_pkt_threshold = 0,
251 .irq_timeout = 600,
252 .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
253 },
254 .tx = {
255 .tx_energy_detection = 0,
256 .sta_rc_conf = {
257 .enabled_rates = 0,
258 .short_retry_limit = 10,
259 .long_retry_limit = 10,
260 .aflags = 0,
261 },
262 .ac_conf_count = 4,
263 .ac_conf = {
264 [CONF_TX_AC_BE] = {
265 .ac = CONF_TX_AC_BE,
266 .cw_min = 15,
267 .cw_max = 63,
268 .aifsn = 3,
269 .tx_op_limit = 0,
270 },
271 [CONF_TX_AC_BK] = {
272 .ac = CONF_TX_AC_BK,
273 .cw_min = 15,
274 .cw_max = 63,
275 .aifsn = 7,
276 .tx_op_limit = 0,
277 },
278 [CONF_TX_AC_VI] = {
279 .ac = CONF_TX_AC_VI,
280 .cw_min = 15,
281 .cw_max = 63,
282 .aifsn = CONF_TX_AIFS_PIFS,
283 .tx_op_limit = 3008,
284 },
285 [CONF_TX_AC_VO] = {
286 .ac = CONF_TX_AC_VO,
287 .cw_min = 15,
288 .cw_max = 63,
289 .aifsn = CONF_TX_AIFS_PIFS,
290 .tx_op_limit = 1504,
291 },
292 },
293 .max_tx_retries = 100,
294 .ap_aging_period = 300,
295 .tid_conf_count = 4,
296 .tid_conf = {
297 [CONF_TX_AC_BE] = {
298 .queue_id = CONF_TX_AC_BE,
299 .channel_type = CONF_CHANNEL_TYPE_EDCF,
300 .tsid = CONF_TX_AC_BE,
301 .ps_scheme = CONF_PS_SCHEME_LEGACY,
302 .ack_policy = CONF_ACK_POLICY_LEGACY,
303 .apsd_conf = {0, 0},
304 },
305 [CONF_TX_AC_BK] = {
306 .queue_id = CONF_TX_AC_BK,
307 .channel_type = CONF_CHANNEL_TYPE_EDCF,
308 .tsid = CONF_TX_AC_BK,
309 .ps_scheme = CONF_PS_SCHEME_LEGACY,
310 .ack_policy = CONF_ACK_POLICY_LEGACY,
311 .apsd_conf = {0, 0},
312 },
313 [CONF_TX_AC_VI] = {
314 .queue_id = CONF_TX_AC_VI,
315 .channel_type = CONF_CHANNEL_TYPE_EDCF,
316 .tsid = CONF_TX_AC_VI,
317 .ps_scheme = CONF_PS_SCHEME_LEGACY,
318 .ack_policy = CONF_ACK_POLICY_LEGACY,
319 .apsd_conf = {0, 0},
320 },
321 [CONF_TX_AC_VO] = {
322 .queue_id = CONF_TX_AC_VO,
323 .channel_type = CONF_CHANNEL_TYPE_EDCF,
324 .tsid = CONF_TX_AC_VO,
325 .ps_scheme = CONF_PS_SCHEME_LEGACY,
326 .ack_policy = CONF_ACK_POLICY_LEGACY,
327 .apsd_conf = {0, 0},
328 },
329 },
330 .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
331 .tx_compl_timeout = 350,
332 .tx_compl_threshold = 10,
333 .basic_rate = CONF_HW_BIT_RATE_1MBPS,
334 .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS,
335 .tmpl_short_retry_limit = 10,
336 .tmpl_long_retry_limit = 10,
337 .tx_watchdog_timeout = 5000,
338 },
339 .conn = {
340 .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
341 .listen_interval = 1,
342 .suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM,
343 .suspend_listen_interval = 3,
344 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
345 .bcn_filt_ie_count = 3,
346 .bcn_filt_ie = {
347 [0] = {
348 .ie = WLAN_EID_CHANNEL_SWITCH,
349 .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
350 },
351 [1] = {
352 .ie = WLAN_EID_HT_OPERATION,
353 .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
354 },
355 [2] = {
356 .ie = WLAN_EID_ERP_INFO,
357 .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
358 },
359 },
360 .synch_fail_thold = 12,
361 .bss_lose_timeout = 400,
362 .beacon_rx_timeout = 10000,
363 .broadcast_timeout = 20000,
364 .rx_broadcast_in_ps = 1,
365 .ps_poll_threshold = 10,
366 .bet_enable = CONF_BET_MODE_ENABLE,
367 .bet_max_consecutive = 50,
368 .psm_entry_retries = 8,
369 .psm_exit_retries = 16,
370 .psm_entry_nullfunc_retries = 3,
371 .dynamic_ps_timeout = 200,
372 .forced_ps = false,
373 .keep_alive_interval = 55000,
374 .max_listen_interval = 20,
375 },
376 .itrim = {
377 .enable = false,
378 .timeout = 50000,
379 },
380 .pm_config = {
381 .host_clk_settling_time = 5000,
382 .host_fast_wakeup_support = CONF_FAST_WAKEUP_DISABLE,
383 },
384 .roam_trigger = {
385 .trigger_pacing = 1,
386 .avg_weight_rssi_beacon = 20,
387 .avg_weight_rssi_data = 10,
388 .avg_weight_snr_beacon = 20,
389 .avg_weight_snr_data = 10,
390 },
391 .scan = {
392 .min_dwell_time_active = 7500,
393 .max_dwell_time_active = 30000,
394 .min_dwell_time_passive = 100000,
395 .max_dwell_time_passive = 100000,
396 .num_probe_reqs = 2,
397 .split_scan_timeout = 50000,
398 },
399 .sched_scan = {
400 /*
401 * Values are in TU/1000 but since sched scan FW command
402 * params are in TUs rounding up may occur.
403 */
404 .base_dwell_time = 7500,
405 .max_dwell_time_delta = 22500,
406 /* based on 250bits per probe @1Mbps */
407 .dwell_time_delta_per_probe = 2000,
408 /* based on 250bits per probe @6Mbps (plus a bit more) */
409 .dwell_time_delta_per_probe_5 = 350,
410 .dwell_time_passive = 100000,
411 .dwell_time_dfs = 150000,
412 .num_probe_reqs = 2,
413 .rssi_threshold = -90,
414 .snr_threshold = 0,
415 },
416 .ht = {
417 .rx_ba_win_size = 10,
418 .tx_ba_win_size = 64,
419 .inactivity_timeout = 10000,
420 .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP,
421 },
422 .mem = {
423 .num_stations = 1,
424 .ssid_profiles = 1,
425 .rx_block_num = 40,
426 .tx_min_block_num = 40,
427 .dynamic_memory = 1,
428 .min_req_tx_blocks = 45,
429 .min_req_rx_blocks = 22,
430 .tx_min = 27,
431 },
432 .fm_coex = {
433 .enable = true,
434 .swallow_period = 5,
435 .n_divider_fref_set_1 = 0xff, /* default */
436 .n_divider_fref_set_2 = 12,
437 .m_divider_fref_set_1 = 0xffff,
438 .m_divider_fref_set_2 = 148, /* default */
439 .coex_pll_stabilization_time = 0xffffffff, /* default */
440 .ldo_stabilization_time = 0xffff, /* default */
441 .fm_disturbed_band_margin = 0xff, /* default */
442 .swallow_clk_diff = 0xff, /* default */
443 },
444 .rx_streaming = {
445 .duration = 150,
446 .queues = 0x1,
447 .interval = 20,
448 .always = 0,
449 },
450 .fwlog = {
451 .mode = WL12XX_FWLOG_ON_DEMAND,
452 .mem_blocks = 2,
453 .severity = 0,
454 .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED,
455 .output = WL12XX_FWLOG_OUTPUT_HOST,
456 .threshold = 0,
457 },
458 .rate = {
459 .rate_retry_score = 32000,
460 .per_add = 8192,
461 .per_th1 = 2048,
462 .per_th2 = 4096,
463 .max_per = 8100,
464 .inverse_curiosity_factor = 5,
465 .tx_fail_low_th = 4,
466 .tx_fail_high_th = 10,
467 .per_alpha_shift = 4,
468 .per_add_shift = 13,
469 .per_beta1_shift = 10,
470 .per_beta2_shift = 8,
471 .rate_check_up = 2,
472 .rate_check_down = 12,
473 .rate_retry_policy = {
474 0x00, 0x00, 0x00, 0x00, 0x00,
475 0x00, 0x00, 0x00, 0x00, 0x00,
476 0x00, 0x00, 0x00,
477 },
478 },
479 .hangover = {
480 .recover_time = 0,
481 .hangover_period = 20,
482 .dynamic_mode = 1,
483 .early_termination_mode = 1,
484 .max_period = 20,
485 .min_period = 1,
486 .increase_delta = 1,
487 .decrease_delta = 2,
488 .quiet_time = 4,
489 .increase_time = 1,
490 .window_size = 16,
491 },
492};
493
494static struct wl18xx_priv_conf wl18xx_default_priv_conf = {
495 .phy = {
496 .phy_standalone = 0x00,
497 .primary_clock_setting_time = 0x05,
498 .clock_valid_on_wake_up = 0x00,
499 .secondary_clock_setting_time = 0x05,
500 .rdl = 0x01,
501 .auto_detect = 0x00,
502 .dedicated_fem = FEM_NONE,
503 .low_band_component = COMPONENT_2_WAY_SWITCH,
504 .low_band_component_type = 0x05,
505 .high_band_component = COMPONENT_2_WAY_SWITCH,
506 .high_band_component_type = 0x09,
507 .tcxo_ldo_voltage = 0x00,
508 .xtal_itrim_val = 0x04,
509 .srf_state = 0x00,
510 .io_configuration = 0x01,
511 .sdio_configuration = 0x00,
512 .settings = 0x00,
513 .enable_clpc = 0x00,
514 .enable_tx_low_pwr_on_siso_rdl = 0x00,
515 .rx_profile = 0x00,
516 .pwr_limit_reference_11_abg = 0xc8,
517 .psat = 0,
518 .low_power_val = 0x00,
519 .med_power_val = 0x0a,
520 .high_power_val = 0x1e,
521 .external_pa_dc2dc = 0,
522 .number_of_assembled_ant2_4 = 1,
523 .number_of_assembled_ant5 = 1,
524 },
525};
526
527static const struct wlcore_partition_set wl18xx_ptable[PART_TABLE_LEN] = {
528 [PART_TOP_PRCM_ELP_SOC] = {
529 .mem = { .start = 0x00A02000, .size = 0x00010000 },
530 .reg = { .start = 0x00807000, .size = 0x00005000 },
531 .mem2 = { .start = 0x00800000, .size = 0x0000B000 },
532 .mem3 = { .start = 0x00000000, .size = 0x00000000 },
533 },
534 [PART_DOWN] = {
535 .mem = { .start = 0x00000000, .size = 0x00014000 },
536 .reg = { .start = 0x00810000, .size = 0x0000BFFF },
537 .mem2 = { .start = 0x00000000, .size = 0x00000000 },
538 .mem3 = { .start = 0x00000000, .size = 0x00000000 },
539 },
540 [PART_BOOT] = {
541 .mem = { .start = 0x00700000, .size = 0x0000030c },
542 .reg = { .start = 0x00802000, .size = 0x00014578 },
543 .mem2 = { .start = 0x00B00404, .size = 0x00001000 },
544 .mem3 = { .start = 0x00C00000, .size = 0x00000400 },
545 },
546 [PART_WORK] = {
547 .mem = { .start = 0x00800000, .size = 0x000050FC },
548 .reg = { .start = 0x00B00404, .size = 0x00001000 },
549 .mem2 = { .start = 0x00C00000, .size = 0x00000400 },
550 .mem3 = { .start = 0x00000000, .size = 0x00000000 },
551 },
552 [PART_PHY_INIT] = {
553 .mem = { .start = 0x80926000,
554 .size = sizeof(struct wl18xx_mac_and_phy_params) },
555 .reg = { .start = 0x00000000, .size = 0x00000000 },
556 .mem2 = { .start = 0x00000000, .size = 0x00000000 },
557 .mem3 = { .start = 0x00000000, .size = 0x00000000 },
558 },
559};
560
561static const int wl18xx_rtable[REG_TABLE_LEN] = {
562 [REG_ECPU_CONTROL] = WL18XX_REG_ECPU_CONTROL,
563 [REG_INTERRUPT_NO_CLEAR] = WL18XX_REG_INTERRUPT_NO_CLEAR,
564 [REG_INTERRUPT_ACK] = WL18XX_REG_INTERRUPT_ACK,
565 [REG_COMMAND_MAILBOX_PTR] = WL18XX_REG_COMMAND_MAILBOX_PTR,
566 [REG_EVENT_MAILBOX_PTR] = WL18XX_REG_EVENT_MAILBOX_PTR,
567 [REG_INTERRUPT_TRIG] = WL18XX_REG_INTERRUPT_TRIG_H,
568 [REG_INTERRUPT_MASK] = WL18XX_REG_INTERRUPT_MASK,
569 [REG_PC_ON_RECOVERY] = WL18XX_SCR_PAD4,
570 [REG_CHIP_ID_B] = WL18XX_REG_CHIP_ID_B,
571 [REG_CMD_MBOX_ADDRESS] = WL18XX_CMD_MBOX_ADDRESS,
572
573 /* data access memory addresses, used with partition translation */
574 [REG_SLV_MEM_DATA] = WL18XX_SLV_MEM_DATA,
575 [REG_SLV_REG_DATA] = WL18XX_SLV_REG_DATA,
576
577 /* raw data access memory addresses */
578 [REG_RAW_FW_STATUS_ADDR] = WL18XX_FW_STATUS_ADDR,
579};
580
581static const struct wl18xx_clk_cfg wl18xx_clk_table[NUM_CLOCK_CONFIGS] = {
582 [CLOCK_CONFIG_16_2_M] = { 7, 104, 801, 4, true },
583 [CLOCK_CONFIG_16_368_M] = { 9, 132, 3751, 4, true },
584 [CLOCK_CONFIG_16_8_M] = { 7, 100, 0, 0, false },
585 [CLOCK_CONFIG_19_2_M] = { 8, 100, 0, 0, false },
586 [CLOCK_CONFIG_26_M] = { 13, 120, 0, 0, false },
587 [CLOCK_CONFIG_32_736_M] = { 9, 132, 3751, 4, true },
588 [CLOCK_CONFIG_33_6_M] = { 7, 100, 0, 0, false },
589 [CLOCK_CONFIG_38_468_M] = { 8, 100, 0, 0, false },
590 [CLOCK_CONFIG_52_M] = { 13, 120, 0, 0, false },
591};
592
593/* TODO: maybe move to a new header file? */
594#define WL18XX_FW_NAME "ti-connectivity/wl18xx-fw.bin"
595
596static int wl18xx_identify_chip(struct wl1271 *wl)
597{
598 int ret = 0;
599
600 switch (wl->chip.id) {
601 case CHIP_ID_185x_PG20:
602 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (185x PG20)",
603 wl->chip.id);
604 wl->sr_fw_name = WL18XX_FW_NAME;
605 /* wl18xx uses the same firmware for PLT */
606 wl->plt_fw_name = WL18XX_FW_NAME;
607 wl->quirks |= WLCORE_QUIRK_NO_ELP |
608 WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN |
609 WLCORE_QUIRK_TX_PAD_LAST_FRAME;
610
611 break;
612 case CHIP_ID_185x_PG10:
613 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (185x PG10)",
614 wl->chip.id);
615 wl->sr_fw_name = WL18XX_FW_NAME;
616 /* wl18xx uses the same firmware for PLT */
617 wl->plt_fw_name = WL18XX_FW_NAME;
618 wl->quirks |= WLCORE_QUIRK_NO_ELP |
619 WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED |
620 WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN |
621 WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN;
622
623 /* PG 1.0 has some problems with MCS_13, so disable it */
624 wl->ht_cap[IEEE80211_BAND_2GHZ].mcs.rx_mask[1] &= ~BIT(5);
625
626 break;
627 default:
628 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
629 ret = -ENODEV;
630 goto out;
631 }
632
633out:
634 return ret;
635}
636
637static void wl18xx_set_clk(struct wl1271 *wl)
638{
639 u32 clk_freq;
640
641 wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
642
643 /* TODO: PG2: apparently we need to read the clk type */
644
645 clk_freq = wl18xx_top_reg_read(wl, PRIMARY_CLK_DETECT);
646 wl1271_debug(DEBUG_BOOT, "clock freq %d (%d, %d, %d, %d, %s)", clk_freq,
647 wl18xx_clk_table[clk_freq].n, wl18xx_clk_table[clk_freq].m,
648 wl18xx_clk_table[clk_freq].p, wl18xx_clk_table[clk_freq].q,
649 wl18xx_clk_table[clk_freq].swallow ? "swallow" : "spit");
650
651 wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_N, wl18xx_clk_table[clk_freq].n);
652 wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_M, wl18xx_clk_table[clk_freq].m);
653
654 if (wl18xx_clk_table[clk_freq].swallow) {
655 /* first the 16 lower bits */
656 wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_Q_FACTOR_CFG_1,
657 wl18xx_clk_table[clk_freq].q &
658 PLLSH_WCS_PLL_Q_FACTOR_CFG_1_MASK);
659 /* then the 16 higher bits, masked out */
660 wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_Q_FACTOR_CFG_2,
661 (wl18xx_clk_table[clk_freq].q >> 16) &
662 PLLSH_WCS_PLL_Q_FACTOR_CFG_2_MASK);
663
664 /* first the 16 lower bits */
665 wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_P_FACTOR_CFG_1,
666 wl18xx_clk_table[clk_freq].p &
667 PLLSH_WCS_PLL_P_FACTOR_CFG_1_MASK);
668 /* then the 16 higher bits, masked out */
669 wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_P_FACTOR_CFG_2,
670 (wl18xx_clk_table[clk_freq].p >> 16) &
671 PLLSH_WCS_PLL_P_FACTOR_CFG_2_MASK);
672 } else {
673 wl18xx_top_reg_write(wl, PLLSH_WCS_PLL_SWALLOW_EN,
674 PLLSH_WCS_PLL_SWALLOW_EN_VAL2);
675 }
676}
677
678static void wl18xx_boot_soft_reset(struct wl1271 *wl)
679{
680 /* disable Rx/Tx */
681 wl1271_write32(wl, WL18XX_ENABLE, 0x0);
682
683 /* disable auto calibration on start*/
684 wl1271_write32(wl, WL18XX_SPARE_A2, 0xffff);
685}
686
687static int wl18xx_pre_boot(struct wl1271 *wl)
688{
689 wl18xx_set_clk(wl);
690
691 /* Continue the ELP wake up sequence */
692 wl1271_write32(wl, WL18XX_WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
693 udelay(500);
694
695 wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
696
697 /* Disable interrupts */
698 wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
699
700 wl18xx_boot_soft_reset(wl);
701
702 return 0;
703}
704
705static void wl18xx_pre_upload(struct wl1271 *wl)
706{
707 u32 tmp;
708
709 wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
710
711 /* TODO: check if this is all needed */
712 wl1271_write32(wl, WL18XX_EEPROMLESS_IND, WL18XX_EEPROMLESS_IND);
713
714 tmp = wlcore_read_reg(wl, REG_CHIP_ID_B);
715
716 wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp);
717
718 tmp = wl1271_read32(wl, WL18XX_SCR_PAD2);
719}
720
721static void wl18xx_set_mac_and_phy(struct wl1271 *wl)
722{
723 struct wl18xx_priv *priv = wl->priv;
724 size_t len;
725
726 /* the parameters struct is smaller for PG1 */
727 if (wl->chip.id == CHIP_ID_185x_PG10)
728 len = offsetof(struct wl18xx_mac_and_phy_params, psat) + 1;
729 else
730 len = sizeof(struct wl18xx_mac_and_phy_params);
731
732 wlcore_set_partition(wl, &wl->ptable[PART_PHY_INIT]);
733 wl1271_write(wl, WL18XX_PHY_INIT_MEM_ADDR, (u8 *)&priv->conf.phy, len,
734 false);
735}
736
737static void wl18xx_enable_interrupts(struct wl1271 *wl)
738{
739 u32 event_mask, intr_mask;
740
741 if (wl->chip.id == CHIP_ID_185x_PG10) {
742 event_mask = WL18XX_ACX_EVENTS_VECTOR_PG1;
743 intr_mask = WL18XX_INTR_MASK_PG1;
744 } else {
745 event_mask = WL18XX_ACX_EVENTS_VECTOR_PG2;
746 intr_mask = WL18XX_INTR_MASK_PG2;
747 }
748
749 wlcore_write_reg(wl, REG_INTERRUPT_MASK, event_mask);
750
751 wlcore_enable_interrupts(wl);
752 wlcore_write_reg(wl, REG_INTERRUPT_MASK,
753 WL1271_ACX_INTR_ALL & ~intr_mask);
754}
755
756static int wl18xx_boot(struct wl1271 *wl)
757{
758 int ret;
759
760 ret = wl18xx_pre_boot(wl);
761 if (ret < 0)
762 goto out;
763
764 wl18xx_pre_upload(wl);
765
766 ret = wlcore_boot_upload_firmware(wl);
767 if (ret < 0)
768 goto out;
769
770 wl18xx_set_mac_and_phy(wl);
771
772 ret = wlcore_boot_run_firmware(wl);
773 if (ret < 0)
774 goto out;
775
776 wl18xx_enable_interrupts(wl);
777
778out:
779 return ret;
780}
781
782static void wl18xx_trigger_cmd(struct wl1271 *wl, int cmd_box_addr,
783 void *buf, size_t len)
784{
785 struct wl18xx_priv *priv = wl->priv;
786
787 memcpy(priv->cmd_buf, buf, len);
788 memset(priv->cmd_buf + len, 0, WL18XX_CMD_MAX_SIZE - len);
789
790 wl1271_write(wl, cmd_box_addr, priv->cmd_buf, WL18XX_CMD_MAX_SIZE,
791 false);
792}
793
794static void wl18xx_ack_event(struct wl1271 *wl)
795{
796 wlcore_write_reg(wl, REG_INTERRUPT_TRIG, WL18XX_INTR_TRIG_EVENT_ACK);
797}
798
799static u32 wl18xx_calc_tx_blocks(struct wl1271 *wl, u32 len, u32 spare_blks)
800{
801 u32 blk_size = WL18XX_TX_HW_BLOCK_SIZE;
802 return (len + blk_size - 1) / blk_size + spare_blks;
803}
804
805static void
806wl18xx_set_tx_desc_blocks(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
807 u32 blks, u32 spare_blks)
808{
809 desc->wl18xx_mem.total_mem_blocks = blks;
810}
811
812static void
813wl18xx_set_tx_desc_data_len(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
814 struct sk_buff *skb)
815{
816 desc->length = cpu_to_le16(skb->len);
817
818 /* if only the last frame is to be padded, we unset this bit on Tx */
819 if (wl->quirks & WLCORE_QUIRK_TX_PAD_LAST_FRAME)
820 desc->wl18xx_mem.ctrl = WL18XX_TX_CTRL_NOT_PADDED;
821 else
822 desc->wl18xx_mem.ctrl = 0;
823
824 wl1271_debug(DEBUG_TX, "tx_fill_hdr: hlid: %d "
825 "len: %d life: %d mem: %d", desc->hlid,
826 le16_to_cpu(desc->length),
827 le16_to_cpu(desc->life_time),
828 desc->wl18xx_mem.total_mem_blocks);
829}
830
831static enum wl_rx_buf_align
832wl18xx_get_rx_buf_align(struct wl1271 *wl, u32 rx_desc)
833{
834 if (rx_desc & RX_BUF_PADDED_PAYLOAD)
835 return WLCORE_RX_BUF_PADDED;
836
837 return WLCORE_RX_BUF_ALIGNED;
838}
839
840static u32 wl18xx_get_rx_packet_len(struct wl1271 *wl, void *rx_data,
841 u32 data_len)
842{
843 struct wl1271_rx_descriptor *desc = rx_data;
844
845 /* invalid packet */
846 if (data_len < sizeof(*desc))
847 return 0;
848
849 return data_len - sizeof(*desc);
850}
851
852static void wl18xx_tx_immediate_completion(struct wl1271 *wl)
853{
854 wl18xx_tx_immediate_complete(wl);
855}
856
857static int wl18xx_set_host_cfg_bitmap(struct wl1271 *wl, u32 extra_mem_blk)
858{
859 int ret;
860 u32 sdio_align_size = 0;
861 u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE |
862 HOST_IF_CFG_ADD_RX_ALIGNMENT;
863
864 /* Enable Tx SDIO padding */
865 if (wl->quirks & WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN) {
866 host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
867 sdio_align_size = WL12XX_BUS_BLOCK_SIZE;
868 }
869
870 /* Enable Rx SDIO padding */
871 if (wl->quirks & WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN) {
872 host_cfg_bitmap |= HOST_IF_CFG_RX_PAD_TO_SDIO_BLK;
873 sdio_align_size = WL12XX_BUS_BLOCK_SIZE;
874 }
875
876 ret = wl18xx_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap,
877 sdio_align_size, extra_mem_blk,
878 WL18XX_HOST_IF_LEN_SIZE_FIELD);
879 if (ret < 0)
880 return ret;
881
882 return 0;
883}
884
885static int wl18xx_hw_init(struct wl1271 *wl)
886{
887 int ret;
888 struct wl18xx_priv *priv = wl->priv;
889
890 /* (re)init private structures. Relevant on recovery as well. */
891 priv->last_fw_rls_idx = 0;
892 priv->extra_spare_vif_count = 0;
893
894 /* set the default amount of spare blocks in the bitmap */
895 ret = wl18xx_set_host_cfg_bitmap(wl, WL18XX_TX_HW_BLOCK_SPARE);
896 if (ret < 0)
897 return ret;
898
899 if (checksum_param) {
900 ret = wl18xx_acx_set_checksum_state(wl);
901 if (ret != 0)
902 return ret;
903 }
904
905 return ret;
906}
907
908static void wl18xx_set_tx_desc_csum(struct wl1271 *wl,
909 struct wl1271_tx_hw_descr *desc,
910 struct sk_buff *skb)
911{
912 u32 ip_hdr_offset;
913 struct iphdr *ip_hdr;
914
915 if (!checksum_param) {
916 desc->wl18xx_checksum_data = 0;
917 return;
918 }
919
920 if (skb->ip_summed != CHECKSUM_PARTIAL) {
921 desc->wl18xx_checksum_data = 0;
922 return;
923 }
924
925 ip_hdr_offset = skb_network_header(skb) - skb_mac_header(skb);
926 if (WARN_ON(ip_hdr_offset >= (1<<7))) {
927 desc->wl18xx_checksum_data = 0;
928 return;
929 }
930
931 desc->wl18xx_checksum_data = ip_hdr_offset << 1;
932
933 /* FW is interested only in the LSB of the protocol TCP=0 UDP=1 */
934 ip_hdr = (void *)skb_network_header(skb);
935 desc->wl18xx_checksum_data |= (ip_hdr->protocol & 0x01);
936}
937
938static void wl18xx_set_rx_csum(struct wl1271 *wl,
939 struct wl1271_rx_descriptor *desc,
940 struct sk_buff *skb)
941{
942 if (desc->status & WL18XX_RX_CHECKSUM_MASK)
943 skb->ip_summed = CHECKSUM_UNNECESSARY;
944}
945
946/*
947 * TODO: instead of having these two functions to get the rate mask,
948 * we should modify the wlvif->rate_set instead
949 */
950static u32 wl18xx_sta_get_ap_rate_mask(struct wl1271 *wl,
951 struct wl12xx_vif *wlvif)
952{
953 u32 hw_rate_set = wlvif->rate_set;
954
955 if (wlvif->channel_type == NL80211_CHAN_HT40MINUS ||
956 wlvif->channel_type == NL80211_CHAN_HT40PLUS) {
957 wl1271_debug(DEBUG_ACX, "using wide channel rate mask");
958 hw_rate_set |= CONF_TX_RATE_USE_WIDE_CHAN;
959
960 /* we don't support MIMO in wide-channel mode */
961 hw_rate_set &= ~CONF_TX_MIMO_RATES;
962 }
963
964 return hw_rate_set;
965}
966
967static u32 wl18xx_ap_get_mimo_wide_rate_mask(struct wl1271 *wl,
968 struct wl12xx_vif *wlvif)
969{
970 if ((wlvif->channel_type == NL80211_CHAN_HT40MINUS ||
971 wlvif->channel_type == NL80211_CHAN_HT40PLUS) &&
972 !strcmp(ht_mode_param, "wide")) {
973 wl1271_debug(DEBUG_ACX, "using wide channel rate mask");
974 return CONF_TX_RATE_USE_WIDE_CHAN;
975 } else if (!strcmp(ht_mode_param, "mimo")) {
976 wl1271_debug(DEBUG_ACX, "using MIMO rate mask");
977
978 /*
979 * PG 1.0 has some problems with MCS_13, so disable it
980 *
981 * TODO: instead of hacking this in here, we should
982 * make it more general and change a bit in the
983 * wlvif->rate_set instead.
984 */
985 if (wl->chip.id == CHIP_ID_185x_PG10)
986 return CONF_TX_MIMO_RATES & ~CONF_HW_BIT_RATE_MCS_13;
987
988 return CONF_TX_MIMO_RATES;
989 } else {
990 return 0;
991 }
992}
993
994static s8 wl18xx_get_pg_ver(struct wl1271 *wl)
995{
996 u32 fuse;
997
998 wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
999
1000 fuse = wl1271_read32(wl, WL18XX_REG_FUSE_DATA_1_3);
1001 fuse = (fuse & WL18XX_PG_VER_MASK) >> WL18XX_PG_VER_OFFSET;
1002
1003 wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
1004
1005 return (s8)fuse;
1006}
1007
1008#define WL18XX_CONF_FILE_NAME "ti-connectivity/wl18xx-conf.bin"
1009static int wl18xx_conf_init(struct wl1271 *wl, struct device *dev)
1010{
1011 struct wl18xx_priv *priv = wl->priv;
1012 struct wlcore_conf_file *conf_file;
1013 const struct firmware *fw;
1014 int ret;
1015
1016 ret = request_firmware(&fw, WL18XX_CONF_FILE_NAME, dev);
1017 if (ret < 0) {
1018 wl1271_error("could not get configuration binary %s: %d",
1019 WL18XX_CONF_FILE_NAME, ret);
1020 goto out_fallback;
1021 }
1022
1023 if (fw->size != WL18XX_CONF_SIZE) {
1024 wl1271_error("configuration binary file size is wrong, "
1025 "expected %ld got %zd",
1026 WL18XX_CONF_SIZE, fw->size);
1027 ret = -EINVAL;
1028 goto out;
1029 }
1030
1031 conf_file = (struct wlcore_conf_file *) fw->data;
1032
1033 if (conf_file->header.magic != cpu_to_le32(WL18XX_CONF_MAGIC)) {
1034 wl1271_error("configuration binary file magic number mismatch, "
1035 "expected 0x%0x got 0x%0x", WL18XX_CONF_MAGIC,
1036 conf_file->header.magic);
1037 ret = -EINVAL;
1038 goto out;
1039 }
1040
1041 if (conf_file->header.version != cpu_to_le32(WL18XX_CONF_VERSION)) {
1042 wl1271_error("configuration binary file version not supported, "
1043 "expected 0x%08x got 0x%08x",
1044 WL18XX_CONF_VERSION, conf_file->header.version);
1045 ret = -EINVAL;
1046 goto out;
1047 }
1048
1049 memcpy(&wl->conf, &conf_file->core, sizeof(wl18xx_conf));
1050 memcpy(&priv->conf, &conf_file->priv, sizeof(priv->conf));
1051
1052 goto out;
1053
1054out_fallback:
1055 wl1271_warning("falling back to default config");
1056
1057 /* apply driver default configuration */
1058 memcpy(&wl->conf, &wl18xx_conf, sizeof(wl18xx_conf));
1059 /* apply default private configuration */
1060 memcpy(&priv->conf, &wl18xx_default_priv_conf, sizeof(priv->conf));
1061
1062 /* For now we just fallback */
1063 return 0;
1064
1065out:
1066 release_firmware(fw);
1067 return ret;
1068}
1069
1070static int wl18xx_plt_init(struct wl1271 *wl)
1071{
1072 wl1271_write32(wl, WL18XX_SCR_PAD8, WL18XX_SCR_PAD8_PLT);
1073
1074 return wl->ops->boot(wl);
1075}
1076
1077static void wl18xx_get_mac(struct wl1271 *wl)
1078{
1079 u32 mac1, mac2;
1080
1081 wlcore_set_partition(wl, &wl->ptable[PART_TOP_PRCM_ELP_SOC]);
1082
1083 mac1 = wl1271_read32(wl, WL18XX_REG_FUSE_BD_ADDR_1);
1084 mac2 = wl1271_read32(wl, WL18XX_REG_FUSE_BD_ADDR_2);
1085
1086 /* these are the two parts of the BD_ADDR */
1087 wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
1088 ((mac1 & 0xff000000) >> 24);
1089 wl->fuse_nic_addr = (mac1 & 0xffffff);
1090
1091 wlcore_set_partition(wl, &wl->ptable[PART_DOWN]);
1092}
1093
1094static int wl18xx_handle_static_data(struct wl1271 *wl,
1095 struct wl1271_static_data *static_data)
1096{
1097 struct wl18xx_static_data_priv *static_data_priv =
1098 (struct wl18xx_static_data_priv *) static_data->priv;
1099
1100 wl1271_info("PHY firmware version: %s", static_data_priv->phy_version);
1101
1102 return 0;
1103}
1104
1105static int wl18xx_get_spare_blocks(struct wl1271 *wl, bool is_gem)
1106{
1107 struct wl18xx_priv *priv = wl->priv;
1108
1109 /* If we have VIFs requiring extra spare, indulge them */
1110 if (priv->extra_spare_vif_count)
1111 return WL18XX_TX_HW_EXTRA_BLOCK_SPARE;
1112
1113 return WL18XX_TX_HW_BLOCK_SPARE;
1114}
1115
1116static int wl18xx_set_key(struct wl1271 *wl, enum set_key_cmd cmd,
1117 struct ieee80211_vif *vif,
1118 struct ieee80211_sta *sta,
1119 struct ieee80211_key_conf *key_conf)
1120{
1121 struct wl18xx_priv *priv = wl->priv;
1122 bool change_spare = false;
1123 int ret;
1124
1125 /*
1126 * when adding the first or removing the last GEM/TKIP interface,
1127 * we have to adjust the number of spare blocks.
1128 */
1129 change_spare = (key_conf->cipher == WL1271_CIPHER_SUITE_GEM ||
1130 key_conf->cipher == WLAN_CIPHER_SUITE_TKIP) &&
1131 ((priv->extra_spare_vif_count == 0 && cmd == SET_KEY) ||
1132 (priv->extra_spare_vif_count == 1 && cmd == DISABLE_KEY));
1133
1134 /* no need to change spare - just regular set_key */
1135 if (!change_spare)
1136 return wlcore_set_key(wl, cmd, vif, sta, key_conf);
1137
1138 /*
1139 * stop the queues and flush to ensure the next packets are
1140 * in sync with FW spare block accounting
1141 */
1142 wlcore_stop_queues(wl, WLCORE_QUEUE_STOP_REASON_SPARE_BLK);
1143 wl1271_tx_flush(wl);
1144
1145 ret = wlcore_set_key(wl, cmd, vif, sta, key_conf);
1146 if (ret < 0)
1147 goto out;
1148
1149 /* key is now set, change the spare blocks */
1150 if (cmd == SET_KEY) {
1151 ret = wl18xx_set_host_cfg_bitmap(wl,
1152 WL18XX_TX_HW_EXTRA_BLOCK_SPARE);
1153 if (ret < 0)
1154 goto out;
1155
1156 priv->extra_spare_vif_count++;
1157 } else {
1158 ret = wl18xx_set_host_cfg_bitmap(wl,
1159 WL18XX_TX_HW_BLOCK_SPARE);
1160 if (ret < 0)
1161 goto out;
1162
1163 priv->extra_spare_vif_count--;
1164 }
1165
1166out:
1167 wlcore_wake_queues(wl, WLCORE_QUEUE_STOP_REASON_SPARE_BLK);
1168 return ret;
1169}
1170
1171static u32 wl18xx_pre_pkt_send(struct wl1271 *wl,
1172 u32 buf_offset, u32 last_len)
1173{
1174 if (wl->quirks & WLCORE_QUIRK_TX_PAD_LAST_FRAME) {
1175 struct wl1271_tx_hw_descr *last_desc;
1176
1177 /* get the last TX HW descriptor written to the aggr buf */
1178 last_desc = (struct wl1271_tx_hw_descr *)(wl->aggr_buf +
1179 buf_offset - last_len);
1180
1181 /* the last frame is padded up to an SDIO block */
1182 last_desc->wl18xx_mem.ctrl &= ~WL18XX_TX_CTRL_NOT_PADDED;
1183 return ALIGN(buf_offset, WL12XX_BUS_BLOCK_SIZE);
1184 }
1185
1186 /* no modifications */
1187 return buf_offset;
1188}
1189
1190static struct wlcore_ops wl18xx_ops = {
1191 .identify_chip = wl18xx_identify_chip,
1192 .boot = wl18xx_boot,
1193 .plt_init = wl18xx_plt_init,
1194 .trigger_cmd = wl18xx_trigger_cmd,
1195 .ack_event = wl18xx_ack_event,
1196 .calc_tx_blocks = wl18xx_calc_tx_blocks,
1197 .set_tx_desc_blocks = wl18xx_set_tx_desc_blocks,
1198 .set_tx_desc_data_len = wl18xx_set_tx_desc_data_len,
1199 .get_rx_buf_align = wl18xx_get_rx_buf_align,
1200 .get_rx_packet_len = wl18xx_get_rx_packet_len,
1201 .tx_immediate_compl = wl18xx_tx_immediate_completion,
1202 .tx_delayed_compl = NULL,
1203 .hw_init = wl18xx_hw_init,
1204 .set_tx_desc_csum = wl18xx_set_tx_desc_csum,
1205 .get_pg_ver = wl18xx_get_pg_ver,
1206 .set_rx_csum = wl18xx_set_rx_csum,
1207 .sta_get_ap_rate_mask = wl18xx_sta_get_ap_rate_mask,
1208 .ap_get_mimo_wide_rate_mask = wl18xx_ap_get_mimo_wide_rate_mask,
1209 .get_mac = wl18xx_get_mac,
1210 .debugfs_init = wl18xx_debugfs_add_files,
1211 .handle_static_data = wl18xx_handle_static_data,
1212 .get_spare_blocks = wl18xx_get_spare_blocks,
1213 .set_key = wl18xx_set_key,
1214 .pre_pkt_send = wl18xx_pre_pkt_send,
1215};
1216
1217/* HT cap appropriate for wide channels */
1218static struct ieee80211_sta_ht_cap wl18xx_siso40_ht_cap = {
1219 .cap = IEEE80211_HT_CAP_SGI_20 | IEEE80211_HT_CAP_SGI_40 |
1220 IEEE80211_HT_CAP_SUP_WIDTH_20_40 | IEEE80211_HT_CAP_DSSSCCK40,
1221 .ht_supported = true,
1222 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
1223 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
1224 .mcs = {
1225 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
1226 .rx_highest = cpu_to_le16(150),
1227 .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
1228 },
1229};
1230
1231/* HT cap appropriate for SISO 20 */
1232static struct ieee80211_sta_ht_cap wl18xx_siso20_ht_cap = {
1233 .cap = IEEE80211_HT_CAP_SGI_20,
1234 .ht_supported = true,
1235 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
1236 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
1237 .mcs = {
1238 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
1239 .rx_highest = cpu_to_le16(72),
1240 .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
1241 },
1242};
1243
1244/* HT cap appropriate for MIMO rates in 20mhz channel */
1245static struct ieee80211_sta_ht_cap wl18xx_mimo_ht_cap_2ghz = {
1246 .cap = IEEE80211_HT_CAP_SGI_20,
1247 .ht_supported = true,
1248 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
1249 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
1250 .mcs = {
1251 .rx_mask = { 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0, },
1252 .rx_highest = cpu_to_le16(144),
1253 .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
1254 },
1255};
1256
1257static struct ieee80211_sta_ht_cap wl18xx_mimo_ht_cap_5ghz = {
1258 .cap = IEEE80211_HT_CAP_SGI_20,
1259 .ht_supported = true,
1260 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K,
1261 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_16,
1262 .mcs = {
1263 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
1264 .rx_highest = cpu_to_le16(72),
1265 .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
1266 },
1267};
1268
1269static int __devinit wl18xx_probe(struct platform_device *pdev)
1270{
1271 struct wl1271 *wl;
1272 struct ieee80211_hw *hw;
1273 struct wl18xx_priv *priv;
1274 int ret;
1275
1276 hw = wlcore_alloc_hw(sizeof(*priv));
1277 if (IS_ERR(hw)) {
1278 wl1271_error("can't allocate hw");
1279 ret = PTR_ERR(hw);
1280 goto out;
1281 }
1282
1283 wl = hw->priv;
1284 priv = wl->priv;
1285 wl->ops = &wl18xx_ops;
1286 wl->ptable = wl18xx_ptable;
1287 wl->rtable = wl18xx_rtable;
1288 wl->num_tx_desc = 32;
1289 wl->num_rx_desc = 16;
1290 wl->band_rate_to_idx = wl18xx_band_rate_to_idx;
1291 wl->hw_tx_rate_tbl_size = WL18XX_CONF_HW_RXTX_RATE_MAX;
1292 wl->hw_min_ht_rate = WL18XX_CONF_HW_RXTX_RATE_MCS0;
1293 wl->fw_status_priv_len = sizeof(struct wl18xx_fw_status_priv);
1294 wl->stats.fw_stats_len = sizeof(struct wl18xx_acx_statistics);
1295 wl->static_data_priv_len = sizeof(struct wl18xx_static_data_priv);
1296
1297 if (!strcmp(ht_mode_param, "wide")) {
1298 memcpy(&wl->ht_cap[IEEE80211_BAND_2GHZ],
1299 &wl18xx_siso40_ht_cap,
1300 sizeof(wl18xx_siso40_ht_cap));
1301 memcpy(&wl->ht_cap[IEEE80211_BAND_5GHZ],
1302 &wl18xx_siso40_ht_cap,
1303 sizeof(wl18xx_siso40_ht_cap));
1304 } else if (!strcmp(ht_mode_param, "mimo")) {
1305 memcpy(&wl->ht_cap[IEEE80211_BAND_2GHZ],
1306 &wl18xx_mimo_ht_cap_2ghz,
1307 sizeof(wl18xx_mimo_ht_cap_2ghz));
1308 memcpy(&wl->ht_cap[IEEE80211_BAND_5GHZ],
1309 &wl18xx_mimo_ht_cap_5ghz,
1310 sizeof(wl18xx_mimo_ht_cap_5ghz));
1311 } else if (!strcmp(ht_mode_param, "siso20")) {
1312 memcpy(&wl->ht_cap[IEEE80211_BAND_2GHZ],
1313 &wl18xx_siso20_ht_cap,
1314 sizeof(wl18xx_siso20_ht_cap));
1315 memcpy(&wl->ht_cap[IEEE80211_BAND_5GHZ],
1316 &wl18xx_siso20_ht_cap,
1317 sizeof(wl18xx_siso20_ht_cap));
1318 } else {
1319 wl1271_error("invalid ht_mode '%s'", ht_mode_param);
1320 ret = -EINVAL;
1321 goto out_free;
1322 }
1323
1324 ret = wl18xx_conf_init(wl, &pdev->dev);
1325 if (ret < 0)
1326 goto out_free;
1327
1328 if (!strcmp(board_type_param, "fpga")) {
1329 priv->conf.phy.board_type = BOARD_TYPE_FPGA_18XX;
1330 } else if (!strcmp(board_type_param, "hdk")) {
1331 priv->conf.phy.board_type = BOARD_TYPE_HDK_18XX;
1332 /* HACK! Just for now we hardcode HDK to 0x06 */
1333 priv->conf.phy.low_band_component_type = 0x06;
1334 } else if (!strcmp(board_type_param, "dvp")) {
1335 priv->conf.phy.board_type = BOARD_TYPE_DVP_18XX;
1336 } else if (!strcmp(board_type_param, "evb")) {
1337 priv->conf.phy.board_type = BOARD_TYPE_EVB_18XX;
1338 } else if (!strcmp(board_type_param, "com8")) {
1339 priv->conf.phy.board_type = BOARD_TYPE_COM8_18XX;
1340 /* HACK! Just for now we hardcode COM8 to 0x06 */
1341 priv->conf.phy.low_band_component_type = 0x06;
1342 } else {
1343 wl1271_error("invalid board type '%s'", board_type_param);
1344 ret = -EINVAL;
1345 goto out_free;
1346 }
1347
1348 /* If the module param is set, update it in conf */
1349 if (low_band_component_param != -1)
1350 priv->conf.phy.low_band_component = low_band_component_param;
1351 if (low_band_component_type_param != -1)
1352 priv->conf.phy.low_band_component_type =
1353 low_band_component_type_param;
1354 if (high_band_component_param != -1)
1355 priv->conf.phy.high_band_component = high_band_component_param;
1356 if (high_band_component_type_param != -1)
1357 priv->conf.phy.high_band_component_type =
1358 high_band_component_type_param;
1359 if (pwr_limit_reference_11_abg_param != -1)
1360 priv->conf.phy.pwr_limit_reference_11_abg =
1361 pwr_limit_reference_11_abg_param;
1362 if (n_antennas_2_param != -1)
1363 priv->conf.phy.number_of_assembled_ant2_4 = n_antennas_2_param;
1364 if (n_antennas_5_param != -1)
1365 priv->conf.phy.number_of_assembled_ant5 = n_antennas_5_param;
1366 if (dc2dc_param != -1)
1367 priv->conf.phy.external_pa_dc2dc = dc2dc_param;
1368
1369 if (!checksum_param) {
1370 wl18xx_ops.set_rx_csum = NULL;
1371 wl18xx_ops.init_vif = NULL;
1372 }
1373
1374 wl->enable_11a = enable_11a_param;
1375
1376 return wlcore_probe(wl, pdev);
1377
1378out_free:
1379 wlcore_free_hw(wl);
1380out:
1381 return ret;
1382}
1383
1384static const struct platform_device_id wl18xx_id_table[] __devinitconst = {
1385 { "wl18xx", 0 },
1386 { } /* Terminating Entry */
1387};
1388MODULE_DEVICE_TABLE(platform, wl18xx_id_table);
1389
1390static struct platform_driver wl18xx_driver = {
1391 .probe = wl18xx_probe,
1392 .remove = __devexit_p(wlcore_remove),
1393 .id_table = wl18xx_id_table,
1394 .driver = {
1395 .name = "wl18xx_driver",
1396 .owner = THIS_MODULE,
1397 }
1398};
1399
1400static int __init wl18xx_init(void)
1401{
1402 return platform_driver_register(&wl18xx_driver);
1403}
1404module_init(wl18xx_init);
1405
1406static void __exit wl18xx_exit(void)
1407{
1408 platform_driver_unregister(&wl18xx_driver);
1409}
1410module_exit(wl18xx_exit);
1411
1412module_param_named(ht_mode, ht_mode_param, charp, S_IRUSR);
1413MODULE_PARM_DESC(ht_mode, "Force HT mode: wide (default), mimo or siso20");
1414
1415module_param_named(board_type, board_type_param, charp, S_IRUSR);
1416MODULE_PARM_DESC(board_type, "Board type: fpga, hdk (default), evb, com8 or "
1417 "dvp");
1418
1419module_param_named(checksum, checksum_param, bool, S_IRUSR);
1420MODULE_PARM_DESC(checksum, "Enable TCP checksum: boolean (defaults to false)");
1421
1422module_param_named(enable_11a, enable_11a_param, bool, S_IRUSR);
1423MODULE_PARM_DESC(enable_11a, "Enable 11a (5GHz): boolean (defaults to true)");
1424
1425module_param_named(dc2dc, dc2dc_param, int, S_IRUSR);
1426MODULE_PARM_DESC(dc2dc, "External DC2DC: u8 (defaults to 0)");
1427
1428module_param_named(n_antennas_2, n_antennas_2_param, int, S_IRUSR);
1429MODULE_PARM_DESC(n_antennas_2,
1430 "Number of installed 2.4GHz antennas: 1 (default) or 2");
1431
1432module_param_named(n_antennas_5, n_antennas_5_param, int, S_IRUSR);
1433MODULE_PARM_DESC(n_antennas_5,
1434 "Number of installed 5GHz antennas: 1 (default) or 2");
1435
1436module_param_named(low_band_component, low_band_component_param, int,
1437 S_IRUSR);
1438MODULE_PARM_DESC(low_band_component, "Low band component: u8 "
1439 "(default is 0x01)");
1440
1441module_param_named(low_band_component_type, low_band_component_type_param,
1442 int, S_IRUSR);
1443MODULE_PARM_DESC(low_band_component_type, "Low band component type: u8 "
1444 "(default is 0x05 or 0x06 depending on the board_type)");
1445
1446module_param_named(high_band_component, high_band_component_param, int,
1447 S_IRUSR);
1448MODULE_PARM_DESC(high_band_component, "High band component: u8, "
1449 "(default is 0x01)");
1450
1451module_param_named(high_band_component_type, high_band_component_type_param,
1452 int, S_IRUSR);
1453MODULE_PARM_DESC(high_band_component_type, "High band component type: u8 "
1454 "(default is 0x09)");
1455
1456module_param_named(pwr_limit_reference_11_abg,
1457 pwr_limit_reference_11_abg_param, int, S_IRUSR);
1458MODULE_PARM_DESC(pwr_limit_reference_11_abg, "Power limit reference: u8 "
1459 "(default is 0xc8)");
1460
1461MODULE_LICENSE("GPL v2");
1462MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
1463MODULE_FIRMWARE(WL18XX_FW_NAME);
diff --git a/drivers/net/wireless/ti/wl18xx/reg.h b/drivers/net/wireless/ti/wl18xx/reg.h
new file mode 100644
index 000000000000..937b71d8783f
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/reg.h
@@ -0,0 +1,191 @@
1/*
2 * This file is part of wlcore
3 *
4 * Copyright (C) 2011 Texas Instruments Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#ifndef __REG_H__
23#define __REG_H__
24
25#define WL18XX_REGISTERS_BASE 0x00800000
26#define WL18XX_CODE_BASE 0x00000000
27#define WL18XX_DATA_BASE 0x00400000
28#define WL18XX_DOUBLE_BUFFER_BASE 0x00600000
29#define WL18XX_MCU_KEY_SEARCH_BASE 0x00700000
30#define WL18XX_PHY_BASE 0x00900000
31#define WL18XX_TOP_OCP_BASE 0x00A00000
32#define WL18XX_PACKET_RAM_BASE 0x00B00000
33#define WL18XX_HOST_BASE 0x00C00000
34
35#define WL18XX_REGISTERS_DOWN_SIZE 0x0000B000
36
37#define WL18XX_REG_BOOT_PART_START 0x00802000
38#define WL18XX_REG_BOOT_PART_SIZE 0x00014578
39
40#define WL18XX_PHY_INIT_MEM_ADDR 0x80926000
41
42#define WL18XX_SDIO_WSPI_BASE (WL18XX_REGISTERS_BASE)
43#define WL18XX_REG_CONFIG_BASE (WL18XX_REGISTERS_BASE + 0x02000)
44#define WL18XX_WGCM_REGS_BASE (WL18XX_REGISTERS_BASE + 0x03000)
45#define WL18XX_ENC_BASE (WL18XX_REGISTERS_BASE + 0x04000)
46#define WL18XX_INTERRUPT_BASE (WL18XX_REGISTERS_BASE + 0x05000)
47#define WL18XX_UART_BASE (WL18XX_REGISTERS_BASE + 0x06000)
48#define WL18XX_WELP_BASE (WL18XX_REGISTERS_BASE + 0x07000)
49#define WL18XX_TCP_CKSM_BASE (WL18XX_REGISTERS_BASE + 0x08000)
50#define WL18XX_FIFO_BASE (WL18XX_REGISTERS_BASE + 0x09000)
51#define WL18XX_OCP_BRIDGE_BASE (WL18XX_REGISTERS_BASE + 0x0A000)
52#define WL18XX_PMAC_RX_BASE (WL18XX_REGISTERS_BASE + 0x14800)
53#define WL18XX_PMAC_ACM_BASE (WL18XX_REGISTERS_BASE + 0x14C00)
54#define WL18XX_PMAC_TX_BASE (WL18XX_REGISTERS_BASE + 0x15000)
55#define WL18XX_PMAC_CSR_BASE (WL18XX_REGISTERS_BASE + 0x15400)
56
57#define WL18XX_REG_ECPU_CONTROL (WL18XX_REGISTERS_BASE + 0x02004)
58#define WL18XX_REG_INTERRUPT_NO_CLEAR (WL18XX_REGISTERS_BASE + 0x050E8)
59#define WL18XX_REG_INTERRUPT_ACK (WL18XX_REGISTERS_BASE + 0x050F0)
60#define WL18XX_REG_INTERRUPT_TRIG (WL18XX_REGISTERS_BASE + 0x5074)
61#define WL18XX_REG_INTERRUPT_TRIG_H (WL18XX_REGISTERS_BASE + 0x5078)
62#define WL18XX_REG_INTERRUPT_MASK (WL18XX_REGISTERS_BASE + 0x0050DC)
63
64#define WL18XX_REG_CHIP_ID_B (WL18XX_REGISTERS_BASE + 0x01542C)
65
66#define WL18XX_SLV_MEM_DATA (WL18XX_HOST_BASE + 0x0018)
67#define WL18XX_SLV_REG_DATA (WL18XX_HOST_BASE + 0x0008)
68
69/* Scratch Pad registers*/
70#define WL18XX_SCR_PAD0 (WL18XX_REGISTERS_BASE + 0x0154EC)
71#define WL18XX_SCR_PAD1 (WL18XX_REGISTERS_BASE + 0x0154F0)
72#define WL18XX_SCR_PAD2 (WL18XX_REGISTERS_BASE + 0x0154F4)
73#define WL18XX_SCR_PAD3 (WL18XX_REGISTERS_BASE + 0x0154F8)
74#define WL18XX_SCR_PAD4 (WL18XX_REGISTERS_BASE + 0x0154FC)
75#define WL18XX_SCR_PAD4_SET (WL18XX_REGISTERS_BASE + 0x015504)
76#define WL18XX_SCR_PAD4_CLR (WL18XX_REGISTERS_BASE + 0x015500)
77#define WL18XX_SCR_PAD5 (WL18XX_REGISTERS_BASE + 0x015508)
78#define WL18XX_SCR_PAD5_SET (WL18XX_REGISTERS_BASE + 0x015510)
79#define WL18XX_SCR_PAD5_CLR (WL18XX_REGISTERS_BASE + 0x01550C)
80#define WL18XX_SCR_PAD6 (WL18XX_REGISTERS_BASE + 0x015514)
81#define WL18XX_SCR_PAD7 (WL18XX_REGISTERS_BASE + 0x015518)
82#define WL18XX_SCR_PAD8 (WL18XX_REGISTERS_BASE + 0x01551C)
83#define WL18XX_SCR_PAD9 (WL18XX_REGISTERS_BASE + 0x015520)
84
85/* Spare registers*/
86#define WL18XX_SPARE_A1 (WL18XX_REGISTERS_BASE + 0x002194)
87#define WL18XX_SPARE_A2 (WL18XX_REGISTERS_BASE + 0x002198)
88#define WL18XX_SPARE_A3 (WL18XX_REGISTERS_BASE + 0x00219C)
89#define WL18XX_SPARE_A4 (WL18XX_REGISTERS_BASE + 0x0021A0)
90#define WL18XX_SPARE_A5 (WL18XX_REGISTERS_BASE + 0x0021A4)
91#define WL18XX_SPARE_A6 (WL18XX_REGISTERS_BASE + 0x0021A8)
92#define WL18XX_SPARE_A7 (WL18XX_REGISTERS_BASE + 0x0021AC)
93#define WL18XX_SPARE_A8 (WL18XX_REGISTERS_BASE + 0x0021B0)
94#define WL18XX_SPARE_B1 (WL18XX_REGISTERS_BASE + 0x015524)
95#define WL18XX_SPARE_B2 (WL18XX_REGISTERS_BASE + 0x015528)
96#define WL18XX_SPARE_B3 (WL18XX_REGISTERS_BASE + 0x01552C)
97#define WL18XX_SPARE_B4 (WL18XX_REGISTERS_BASE + 0x015530)
98#define WL18XX_SPARE_B5 (WL18XX_REGISTERS_BASE + 0x015534)
99#define WL18XX_SPARE_B6 (WL18XX_REGISTERS_BASE + 0x015538)
100#define WL18XX_SPARE_B7 (WL18XX_REGISTERS_BASE + 0x01553C)
101#define WL18XX_SPARE_B8 (WL18XX_REGISTERS_BASE + 0x015540)
102
103#define WL18XX_REG_COMMAND_MAILBOX_PTR (WL18XX_SCR_PAD0)
104#define WL18XX_REG_EVENT_MAILBOX_PTR (WL18XX_SCR_PAD1)
105#define WL18XX_EEPROMLESS_IND (WL18XX_SCR_PAD4)
106
107#define WL18XX_WELP_ARM_COMMAND (WL18XX_REGISTERS_BASE + 0x7100)
108#define WL18XX_ENABLE (WL18XX_REGISTERS_BASE + 0x01543C)
109
110/* PRCM registers */
111#define PLATFORM_DETECTION 0xA0E3E0
112#define OCS_EN 0xA02080
113#define PRIMARY_CLK_DETECT 0xA020A6
114#define PLLSH_WCS_PLL_N 0xA02362
115#define PLLSH_WCS_PLL_M 0xA02360
116#define PLLSH_WCS_PLL_Q_FACTOR_CFG_1 0xA02364
117#define PLLSH_WCS_PLL_Q_FACTOR_CFG_2 0xA02366
118#define PLLSH_WCS_PLL_P_FACTOR_CFG_1 0xA02368
119#define PLLSH_WCS_PLL_P_FACTOR_CFG_2 0xA0236A
120#define PLLSH_WCS_PLL_SWALLOW_EN 0xA0236C
121#define PLLSH_WL_PLL_EN 0xA02392
122
123#define PLLSH_WCS_PLL_Q_FACTOR_CFG_1_MASK 0xFFFF
124#define PLLSH_WCS_PLL_Q_FACTOR_CFG_2_MASK 0x007F
125#define PLLSH_WCS_PLL_P_FACTOR_CFG_1_MASK 0xFFFF
126#define PLLSH_WCS_PLL_P_FACTOR_CFG_2_MASK 0x000F
127
128#define PLLSH_WCS_PLL_SWALLOW_EN_VAL1 0x1
129#define PLLSH_WCS_PLL_SWALLOW_EN_VAL2 0x12
130
131#define WL18XX_REG_FUSE_DATA_1_3 0xA0260C
132#define WL18XX_PG_VER_MASK 0x70
133#define WL18XX_PG_VER_OFFSET 4
134
135#define WL18XX_REG_FUSE_BD_ADDR_1 0xA02602
136#define WL18XX_REG_FUSE_BD_ADDR_2 0xA02606
137
138#define WL18XX_CMD_MBOX_ADDRESS 0xB007B4
139
140#define WL18XX_FW_STATUS_ADDR 0x50F8
141
142#define CHIP_ID_185x_PG10 (0x06030101)
143#define CHIP_ID_185x_PG20 (0x06030111)
144
145/*
146 * Host Command Interrupt. Setting this bit masks
147 * the interrupt that the host issues to inform
148 * the FW that it has sent a command
149 * to the Wlan hardware Command Mailbox.
150 */
151#define WL18XX_INTR_TRIG_CMD BIT(28)
152
153/*
154 * Host Event Acknowlegde Interrupt. The host
155 * sets this bit to acknowledge that it received
156 * the unsolicited information from the event
157 * mailbox.
158 */
159#define WL18XX_INTR_TRIG_EVENT_ACK BIT(29)
160
161/*
162 * To boot the firmware in PLT mode we need to write this value in
163 * SCR_PAD8 before starting.
164 */
165#define WL18XX_SCR_PAD8_PLT 0xBABABEBE
166
167enum {
168 COMPONENT_NO_SWITCH = 0x0,
169 COMPONENT_2_WAY_SWITCH = 0x1,
170 COMPONENT_3_WAY_SWITCH = 0x2,
171 COMPONENT_MATCHING = 0x3,
172};
173
174enum {
175 FEM_NONE = 0x0,
176 FEM_VENDOR_1 = 0x1,
177 FEM_VENDOR_2 = 0x2,
178 FEM_VENDOR_3 = 0x3,
179};
180
181enum {
182 BOARD_TYPE_EVB_18XX = 0,
183 BOARD_TYPE_DVP_18XX = 1,
184 BOARD_TYPE_HDK_18XX = 2,
185 BOARD_TYPE_FPGA_18XX = 3,
186 BOARD_TYPE_COM8_18XX = 4,
187
188 NUM_BOARD_TYPES,
189};
190
191#endif /* __REG_H__ */
diff --git a/drivers/net/wireless/ti/wl18xx/tx.c b/drivers/net/wireless/ti/wl18xx/tx.c
new file mode 100644
index 000000000000..5b1fb10d9fd7
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/tx.c
@@ -0,0 +1,127 @@
1/*
2 * This file is part of wl18xx
3 *
4 * Copyright (C) 2011 Texas Instruments Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#include "../wlcore/wlcore.h"
23#include "../wlcore/cmd.h"
24#include "../wlcore/debug.h"
25#include "../wlcore/acx.h"
26#include "../wlcore/tx.h"
27
28#include "wl18xx.h"
29#include "tx.h"
30
31static void wl18xx_tx_complete_packet(struct wl1271 *wl, u8 tx_stat_byte)
32{
33 struct ieee80211_tx_info *info;
34 struct sk_buff *skb;
35 int id = tx_stat_byte & WL18XX_TX_STATUS_DESC_ID_MASK;
36 bool tx_success;
37
38 /* check for id legality */
39 if (unlikely(id >= wl->num_tx_desc || wl->tx_frames[id] == NULL)) {
40 wl1271_warning("illegal id in tx completion: %d", id);
41 return;
42 }
43
44 /* a zero bit indicates Tx success */
45 tx_success = !(tx_stat_byte & BIT(WL18XX_TX_STATUS_STAT_BIT_IDX));
46
47
48 skb = wl->tx_frames[id];
49 info = IEEE80211_SKB_CB(skb);
50
51 if (wl12xx_is_dummy_packet(wl, skb)) {
52 wl1271_free_tx_id(wl, id);
53 return;
54 }
55
56 /* update the TX status info */
57 if (tx_success && !(info->flags & IEEE80211_TX_CTL_NO_ACK))
58 info->flags |= IEEE80211_TX_STAT_ACK;
59
60 /* no real data about Tx completion */
61 info->status.rates[0].idx = -1;
62 info->status.rates[0].count = 0;
63 info->status.rates[0].flags = 0;
64 info->status.ack_signal = -1;
65
66 if (!tx_success)
67 wl->stats.retry_count++;
68
69 /*
70 * TODO: update sequence number for encryption? seems to be
71 * unsupported for now. needed for recovery with encryption.
72 */
73
74 /* remove private header from packet */
75 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
76
77 /* remove TKIP header space if present */
78 if ((wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) &&
79 info->control.hw_key &&
80 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
81 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
82 memmove(skb->data + WL1271_EXTRA_SPACE_TKIP, skb->data, hdrlen);
83 skb_pull(skb, WL1271_EXTRA_SPACE_TKIP);
84 }
85
86 wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p success %d",
87 id, skb, tx_success);
88
89 /* return the packet to the stack */
90 skb_queue_tail(&wl->deferred_tx_queue, skb);
91 queue_work(wl->freezable_wq, &wl->netstack_work);
92 wl1271_free_tx_id(wl, id);
93}
94
95void wl18xx_tx_immediate_complete(struct wl1271 *wl)
96{
97 struct wl18xx_fw_status_priv *status_priv =
98 (struct wl18xx_fw_status_priv *)wl->fw_status_2->priv;
99 struct wl18xx_priv *priv = wl->priv;
100 u8 i;
101
102 /* nothing to do here */
103 if (priv->last_fw_rls_idx == status_priv->fw_release_idx)
104 return;
105
106 /* freed Tx descriptors */
107 wl1271_debug(DEBUG_TX, "last released desc = %d, current idx = %d",
108 priv->last_fw_rls_idx, status_priv->fw_release_idx);
109
110 if (status_priv->fw_release_idx >= WL18XX_FW_MAX_TX_STATUS_DESC) {
111 wl1271_error("invalid desc release index %d",
112 status_priv->fw_release_idx);
113 WARN_ON(1);
114 return;
115 }
116
117 for (i = priv->last_fw_rls_idx;
118 i != status_priv->fw_release_idx;
119 i = (i + 1) % WL18XX_FW_MAX_TX_STATUS_DESC) {
120 wl18xx_tx_complete_packet(wl,
121 status_priv->released_tx_desc[i]);
122
123 wl->tx_results_count++;
124 }
125
126 priv->last_fw_rls_idx = status_priv->fw_release_idx;
127}
diff --git a/drivers/net/wireless/ti/wl18xx/tx.h b/drivers/net/wireless/ti/wl18xx/tx.h
new file mode 100644
index 000000000000..ccddc548e44a
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/tx.h
@@ -0,0 +1,46 @@
1/*
2 * This file is part of wl18xx
3 *
4 * Copyright (C) 2011 Texas Instruments. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#ifndef __WL18XX_TX_H__
23#define __WL18XX_TX_H__
24
25#include "../wlcore/wlcore.h"
26
27#define WL18XX_TX_HW_BLOCK_SPARE 1
28/* for special cases - namely, TKIP and GEM */
29#define WL18XX_TX_HW_EXTRA_BLOCK_SPARE 2
30#define WL18XX_TX_HW_BLOCK_SIZE 268
31
32#define WL18XX_TX_STATUS_DESC_ID_MASK 0x7F
33#define WL18XX_TX_STATUS_STAT_BIT_IDX 7
34
35/* Indicates this TX HW frame is not padded to SDIO block size */
36#define WL18XX_TX_CTRL_NOT_PADDED BIT(7)
37
38/*
39 * The FW uses a special bit to indicate a wide channel should be used in
40 * the rate policy.
41 */
42#define CONF_TX_RATE_USE_WIDE_CHAN BIT(31)
43
44void wl18xx_tx_immediate_complete(struct wl1271 *wl);
45
46#endif /* __WL12XX_TX_H__ */
diff --git a/drivers/net/wireless/ti/wl18xx/wl18xx.h b/drivers/net/wireless/ti/wl18xx/wl18xx.h
new file mode 100644
index 000000000000..bc67a4750615
--- /dev/null
+++ b/drivers/net/wireless/ti/wl18xx/wl18xx.h
@@ -0,0 +1,88 @@
1/*
2 * This file is part of wl18xx
3 *
4 * Copyright (C) 2011 Texas Instruments Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
19 *
20 */
21
22#ifndef __WL18XX_PRIV_H__
23#define __WL18XX_PRIV_H__
24
25#include "conf.h"
26
27#define WL18XX_CMD_MAX_SIZE 740
28
29struct wl18xx_priv {
30 /* buffer for sending commands to FW */
31 u8 cmd_buf[WL18XX_CMD_MAX_SIZE];
32
33 struct wl18xx_priv_conf conf;
34
35 /* Index of last released Tx desc in FW */
36 u8 last_fw_rls_idx;
37
38 /* number of VIFs requiring extra spare mem-blocks */
39 int extra_spare_vif_count;
40};
41
42#define WL18XX_FW_MAX_TX_STATUS_DESC 33
43
44struct wl18xx_fw_status_priv {
45 /*
46 * Index in released_tx_desc for first byte that holds
47 * released tx host desc
48 */
49 u8 fw_release_idx;
50
51 /*
52 * Array of host Tx descriptors, where fw_release_idx
53 * indicated the first released idx.
54 */
55 u8 released_tx_desc[WL18XX_FW_MAX_TX_STATUS_DESC];
56
57 u8 padding[2];
58};
59
60#define WL18XX_PHY_VERSION_MAX_LEN 20
61
62struct wl18xx_static_data_priv {
63 char phy_version[WL18XX_PHY_VERSION_MAX_LEN];
64};
65
66struct wl18xx_clk_cfg {
67 u32 n;
68 u32 m;
69 u32 p;
70 u32 q;
71 bool swallow;
72};
73
74enum {
75 CLOCK_CONFIG_16_2_M = 1,
76 CLOCK_CONFIG_16_368_M,
77 CLOCK_CONFIG_16_8_M,
78 CLOCK_CONFIG_19_2_M,
79 CLOCK_CONFIG_26_M,
80 CLOCK_CONFIG_32_736_M,
81 CLOCK_CONFIG_33_6_M,
82 CLOCK_CONFIG_38_468_M,
83 CLOCK_CONFIG_52_M,
84
85 NUM_CLOCK_CONFIGS,
86};
87
88#endif /* __WL18XX_PRIV_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/acx.c b/drivers/net/wireless/ti/wlcore/acx.c
index f3d6fa508269..b9ec42c83757 100644
--- a/drivers/net/wireless/ti/wlcore/acx.c
+++ b/drivers/net/wireless/ti/wlcore/acx.c
@@ -86,6 +86,7 @@ out:
86 kfree(auth); 86 kfree(auth);
87 return ret; 87 return ret;
88} 88}
89EXPORT_SYMBOL_GPL(wl1271_acx_sleep_auth);
89 90
90int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif, 91int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif,
91 int power) 92 int power)
@@ -708,14 +709,14 @@ out:
708 return ret; 709 return ret;
709} 710}
710 711
711int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats) 712int wl1271_acx_statistics(struct wl1271 *wl, void *stats)
712{ 713{
713 int ret; 714 int ret;
714 715
715 wl1271_debug(DEBUG_ACX, "acx statistics"); 716 wl1271_debug(DEBUG_ACX, "acx statistics");
716 717
717 ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats, 718 ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
718 sizeof(*stats)); 719 wl->stats.fw_stats_len);
719 if (ret < 0) { 720 if (ret < 0) {
720 wl1271_warning("acx statistics failed: %d", ret); 721 wl1271_warning("acx statistics failed: %d", ret);
721 return -ENOMEM; 722 return -ENOMEM;
@@ -997,6 +998,7 @@ out:
997 kfree(mem_conf); 998 kfree(mem_conf);
998 return ret; 999 return ret;
999} 1000}
1001EXPORT_SYMBOL_GPL(wl12xx_acx_mem_cfg);
1000 1002
1001int wl1271_acx_init_mem_config(struct wl1271 *wl) 1003int wl1271_acx_init_mem_config(struct wl1271 *wl)
1002{ 1004{
@@ -1027,6 +1029,7 @@ int wl1271_acx_init_mem_config(struct wl1271 *wl)
1027 1029
1028 return 0; 1030 return 0;
1029} 1031}
1032EXPORT_SYMBOL_GPL(wl1271_acx_init_mem_config);
1030 1033
1031int wl1271_acx_init_rx_interrupt(struct wl1271 *wl) 1034int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
1032{ 1035{
@@ -1150,6 +1153,7 @@ out:
1150 kfree(acx); 1153 kfree(acx);
1151 return ret; 1154 return ret;
1152} 1155}
1156EXPORT_SYMBOL_GPL(wl1271_acx_pm_config);
1153 1157
1154int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1158int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1155 bool enable) 1159 bool enable)
diff --git a/drivers/net/wireless/ti/wlcore/acx.h b/drivers/net/wireless/ti/wlcore/acx.h
index e6a74869a5ff..c0181258b722 100644
--- a/drivers/net/wireless/ti/wlcore/acx.h
+++ b/drivers/net/wireless/ti/wlcore/acx.h
@@ -51,21 +51,18 @@
51#define WL1271_ACX_INTR_TRACE_A BIT(7) 51#define WL1271_ACX_INTR_TRACE_A BIT(7)
52/* Trace message on MBOX #B */ 52/* Trace message on MBOX #B */
53#define WL1271_ACX_INTR_TRACE_B BIT(8) 53#define WL1271_ACX_INTR_TRACE_B BIT(8)
54/* SW FW Initiated interrupt Watchdog timer expiration */
55#define WL1271_ACX_SW_INTR_WATCHDOG BIT(9)
54 56
55#define WL1271_ACX_INTR_ALL 0xFFFFFFFF 57#define WL1271_ACX_INTR_ALL 0xFFFFFFFF
56#define WL1271_ACX_ALL_EVENTS_VECTOR (WL1271_ACX_INTR_WATCHDOG | \ 58
57 WL1271_ACX_INTR_INIT_COMPLETE | \ 59/* all possible interrupts - only appropriate ones will be masked in */
58 WL1271_ACX_INTR_EVENT_A | \ 60#define WLCORE_ALL_INTR_MASK (WL1271_ACX_INTR_WATCHDOG | \
59 WL1271_ACX_INTR_EVENT_B | \ 61 WL1271_ACX_INTR_EVENT_A | \
60 WL1271_ACX_INTR_CMD_COMPLETE | \ 62 WL1271_ACX_INTR_EVENT_B | \
61 WL1271_ACX_INTR_HW_AVAILABLE | \ 63 WL1271_ACX_INTR_HW_AVAILABLE | \
62 WL1271_ACX_INTR_DATA) 64 WL1271_ACX_INTR_DATA | \
63 65 WL1271_ACX_SW_INTR_WATCHDOG)
64#define WL1271_INTR_MASK (WL1271_ACX_INTR_WATCHDOG | \
65 WL1271_ACX_INTR_EVENT_A | \
66 WL1271_ACX_INTR_EVENT_B | \
67 WL1271_ACX_INTR_HW_AVAILABLE | \
68 WL1271_ACX_INTR_DATA)
69 66
70/* Target's information element */ 67/* Target's information element */
71struct acx_header { 68struct acx_header {
@@ -417,228 +414,6 @@ struct acx_ctsprotect {
417 u8 padding[2]; 414 u8 padding[2];
418} __packed; 415} __packed;
419 416
420struct acx_tx_statistics {
421 __le32 internal_desc_overflow;
422} __packed;
423
424struct acx_rx_statistics {
425 __le32 out_of_mem;
426 __le32 hdr_overflow;
427 __le32 hw_stuck;
428 __le32 dropped;
429 __le32 fcs_err;
430 __le32 xfr_hint_trig;
431 __le32 path_reset;
432 __le32 reset_counter;
433} __packed;
434
435struct acx_dma_statistics {
436 __le32 rx_requested;
437 __le32 rx_errors;
438 __le32 tx_requested;
439 __le32 tx_errors;
440} __packed;
441
442struct acx_isr_statistics {
443 /* host command complete */
444 __le32 cmd_cmplt;
445
446 /* fiqisr() */
447 __le32 fiqs;
448
449 /* (INT_STS_ND & INT_TRIG_RX_HEADER) */
450 __le32 rx_headers;
451
452 /* (INT_STS_ND & INT_TRIG_RX_CMPLT) */
453 __le32 rx_completes;
454
455 /* (INT_STS_ND & INT_TRIG_NO_RX_BUF) */
456 __le32 rx_mem_overflow;
457
458 /* (INT_STS_ND & INT_TRIG_S_RX_RDY) */
459 __le32 rx_rdys;
460
461 /* irqisr() */
462 __le32 irqs;
463
464 /* (INT_STS_ND & INT_TRIG_TX_PROC) */
465 __le32 tx_procs;
466
467 /* (INT_STS_ND & INT_TRIG_DECRYPT_DONE) */
468 __le32 decrypt_done;
469
470 /* (INT_STS_ND & INT_TRIG_DMA0) */
471 __le32 dma0_done;
472
473 /* (INT_STS_ND & INT_TRIG_DMA1) */
474 __le32 dma1_done;
475
476 /* (INT_STS_ND & INT_TRIG_TX_EXC_CMPLT) */
477 __le32 tx_exch_complete;
478
479 /* (INT_STS_ND & INT_TRIG_COMMAND) */
480 __le32 commands;
481
482 /* (INT_STS_ND & INT_TRIG_RX_PROC) */
483 __le32 rx_procs;
484
485 /* (INT_STS_ND & INT_TRIG_PM_802) */
486 __le32 hw_pm_mode_changes;
487
488 /* (INT_STS_ND & INT_TRIG_ACKNOWLEDGE) */
489 __le32 host_acknowledges;
490
491 /* (INT_STS_ND & INT_TRIG_PM_PCI) */
492 __le32 pci_pm;
493
494 /* (INT_STS_ND & INT_TRIG_ACM_WAKEUP) */
495 __le32 wakeups;
496
497 /* (INT_STS_ND & INT_TRIG_LOW_RSSI) */
498 __le32 low_rssi;
499} __packed;
500
501struct acx_wep_statistics {
502 /* WEP address keys configured */
503 __le32 addr_key_count;
504
505 /* default keys configured */
506 __le32 default_key_count;
507
508 __le32 reserved;
509
510 /* number of times that WEP key not found on lookup */
511 __le32 key_not_found;
512
513 /* number of times that WEP key decryption failed */
514 __le32 decrypt_fail;
515
516 /* WEP packets decrypted */
517 __le32 packets;
518
519 /* WEP decrypt interrupts */
520 __le32 interrupt;
521} __packed;
522
523#define ACX_MISSED_BEACONS_SPREAD 10
524
525struct acx_pwr_statistics {
526 /* the amount of enters into power save mode (both PD & ELP) */
527 __le32 ps_enter;
528
529 /* the amount of enters into ELP mode */
530 __le32 elp_enter;
531
532 /* the amount of missing beacon interrupts to the host */
533 __le32 missing_bcns;
534
535 /* the amount of wake on host-access times */
536 __le32 wake_on_host;
537
538 /* the amount of wake on timer-expire */
539 __le32 wake_on_timer_exp;
540
541 /* the number of packets that were transmitted with PS bit set */
542 __le32 tx_with_ps;
543
544 /* the number of packets that were transmitted with PS bit clear */
545 __le32 tx_without_ps;
546
547 /* the number of received beacons */
548 __le32 rcvd_beacons;
549
550 /* the number of entering into PowerOn (power save off) */
551 __le32 power_save_off;
552
553 /* the number of entries into power save mode */
554 __le16 enable_ps;
555
556 /*
557 * the number of exits from power save, not including failed PS
558 * transitions
559 */
560 __le16 disable_ps;
561
562 /*
563 * the number of times the TSF counter was adjusted because
564 * of drift
565 */
566 __le32 fix_tsf_ps;
567
568 /* Gives statistics about the spread continuous missed beacons.
569 * The 16 LSB are dedicated for the PS mode.
570 * The 16 MSB are dedicated for the PS mode.
571 * cont_miss_bcns_spread[0] - single missed beacon.
572 * cont_miss_bcns_spread[1] - two continuous missed beacons.
573 * cont_miss_bcns_spread[2] - three continuous missed beacons.
574 * ...
575 * cont_miss_bcns_spread[9] - ten and more continuous missed beacons.
576 */
577 __le32 cont_miss_bcns_spread[ACX_MISSED_BEACONS_SPREAD];
578
579 /* the number of beacons in awake mode */
580 __le32 rcvd_awake_beacons;
581} __packed;
582
583struct acx_mic_statistics {
584 __le32 rx_pkts;
585 __le32 calc_failure;
586} __packed;
587
588struct acx_aes_statistics {
589 __le32 encrypt_fail;
590 __le32 decrypt_fail;
591 __le32 encrypt_packets;
592 __le32 decrypt_packets;
593 __le32 encrypt_interrupt;
594 __le32 decrypt_interrupt;
595} __packed;
596
597struct acx_event_statistics {
598 __le32 heart_beat;
599 __le32 calibration;
600 __le32 rx_mismatch;
601 __le32 rx_mem_empty;
602 __le32 rx_pool;
603 __le32 oom_late;
604 __le32 phy_transmit_error;
605 __le32 tx_stuck;
606} __packed;
607
608struct acx_ps_statistics {
609 __le32 pspoll_timeouts;
610 __le32 upsd_timeouts;
611 __le32 upsd_max_sptime;
612 __le32 upsd_max_apturn;
613 __le32 pspoll_max_apturn;
614 __le32 pspoll_utilization;
615 __le32 upsd_utilization;
616} __packed;
617
618struct acx_rxpipe_statistics {
619 __le32 rx_prep_beacon_drop;
620 __le32 descr_host_int_trig_rx_data;
621 __le32 beacon_buffer_thres_host_int_trig_rx_data;
622 __le32 missed_beacon_host_int_trig_rx_data;
623 __le32 tx_xfr_host_int_trig_rx_data;
624} __packed;
625
626struct acx_statistics {
627 struct acx_header header;
628
629 struct acx_tx_statistics tx;
630 struct acx_rx_statistics rx;
631 struct acx_dma_statistics dma;
632 struct acx_isr_statistics isr;
633 struct acx_wep_statistics wep;
634 struct acx_pwr_statistics pwr;
635 struct acx_aes_statistics aes;
636 struct acx_mic_statistics mic;
637 struct acx_event_statistics event;
638 struct acx_ps_statistics ps;
639 struct acx_rxpipe_statistics rxpipe;
640} __packed;
641
642struct acx_rate_class { 417struct acx_rate_class {
643 __le32 enabled_rates; 418 __le32 enabled_rates;
644 u8 short_retry_limit; 419 u8 short_retry_limit;
@@ -828,6 +603,8 @@ struct wl1271_acx_keep_alive_config {
828#define HOST_IF_CFG_RX_FIFO_ENABLE BIT(0) 603#define HOST_IF_CFG_RX_FIFO_ENABLE BIT(0)
829#define HOST_IF_CFG_TX_EXTRA_BLKS_SWAP BIT(1) 604#define HOST_IF_CFG_TX_EXTRA_BLKS_SWAP BIT(1)
830#define HOST_IF_CFG_TX_PAD_TO_SDIO_BLK BIT(3) 605#define HOST_IF_CFG_TX_PAD_TO_SDIO_BLK BIT(3)
606#define HOST_IF_CFG_RX_PAD_TO_SDIO_BLK BIT(4)
607#define HOST_IF_CFG_ADD_RX_ALIGNMENT BIT(6)
831 608
832enum { 609enum {
833 WL1271_ACX_TRIG_TYPE_LEVEL = 0, 610 WL1271_ACX_TRIG_TYPE_LEVEL = 0,
@@ -946,7 +723,7 @@ struct wl1271_acx_ht_information {
946 u8 padding[2]; 723 u8 padding[2];
947} __packed; 724} __packed;
948 725
949#define RX_BA_MAX_SESSIONS 2 726#define RX_BA_MAX_SESSIONS 3
950 727
951struct wl1271_acx_ba_initiator_policy { 728struct wl1271_acx_ba_initiator_policy {
952 struct acx_header header; 729 struct acx_header header;
@@ -1243,6 +1020,7 @@ enum {
1243 ACX_CONFIG_HANGOVER = 0x0042, 1020 ACX_CONFIG_HANGOVER = 0x0042,
1244 ACX_FEATURE_CFG = 0x0043, 1021 ACX_FEATURE_CFG = 0x0043,
1245 ACX_PROTECTION_CFG = 0x0044, 1022 ACX_PROTECTION_CFG = 0x0044,
1023 ACX_CHECKSUM_CONFIG = 0x0045,
1246}; 1024};
1247 1025
1248 1026
@@ -1281,7 +1059,7 @@ int wl1271_acx_set_preamble(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1281 enum acx_preamble_type preamble); 1059 enum acx_preamble_type preamble);
1282int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif, 1060int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1283 enum acx_ctsprotect_type ctsprotect); 1061 enum acx_ctsprotect_type ctsprotect);
1284int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats); 1062int wl1271_acx_statistics(struct wl1271 *wl, void *stats);
1285int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif); 1063int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif);
1286int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c, 1064int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
1287 u8 idx); 1065 u8 idx);
diff --git a/drivers/net/wireless/ti/wlcore/boot.c b/drivers/net/wireless/ti/wlcore/boot.c
index 9b98230f84ce..0fda500c01c9 100644
--- a/drivers/net/wireless/ti/wlcore/boot.c
+++ b/drivers/net/wireless/ti/wlcore/boot.c
@@ -45,10 +45,17 @@ static void wl1271_boot_set_ecpu_ctrl(struct wl1271 *wl, u32 flag)
45 wlcore_write_reg(wl, REG_ECPU_CONTROL, cpu_ctrl); 45 wlcore_write_reg(wl, REG_ECPU_CONTROL, cpu_ctrl);
46} 46}
47 47
48static int wlcore_parse_fw_ver(struct wl1271 *wl) 48static int wlcore_boot_parse_fw_ver(struct wl1271 *wl,
49 struct wl1271_static_data *static_data)
49{ 50{
50 int ret; 51 int ret;
51 52
53 strncpy(wl->chip.fw_ver_str, static_data->fw_version,
54 sizeof(wl->chip.fw_ver_str));
55
56 /* make sure the string is NULL-terminated */
57 wl->chip.fw_ver_str[sizeof(wl->chip.fw_ver_str) - 1] = '\0';
58
52 ret = sscanf(wl->chip.fw_ver_str + 4, "%u.%u.%u.%u.%u", 59 ret = sscanf(wl->chip.fw_ver_str + 4, "%u.%u.%u.%u.%u",
53 &wl->chip.fw_ver[0], &wl->chip.fw_ver[1], 60 &wl->chip.fw_ver[0], &wl->chip.fw_ver[1],
54 &wl->chip.fw_ver[2], &wl->chip.fw_ver[3], 61 &wl->chip.fw_ver[2], &wl->chip.fw_ver[3],
@@ -57,43 +64,43 @@ static int wlcore_parse_fw_ver(struct wl1271 *wl)
57 if (ret != 5) { 64 if (ret != 5) {
58 wl1271_warning("fw version incorrect value"); 65 wl1271_warning("fw version incorrect value");
59 memset(wl->chip.fw_ver, 0, sizeof(wl->chip.fw_ver)); 66 memset(wl->chip.fw_ver, 0, sizeof(wl->chip.fw_ver));
60 return -EINVAL; 67 ret = -EINVAL;
68 goto out;
61 } 69 }
62 70
63 ret = wlcore_identify_fw(wl); 71 ret = wlcore_identify_fw(wl);
64 if (ret < 0) 72 if (ret < 0)
65 return ret; 73 goto out;
66 74out:
67 return 0; 75 return ret;
68} 76}
69 77
70static int wlcore_boot_fw_version(struct wl1271 *wl) 78static int wlcore_boot_static_data(struct wl1271 *wl)
71{ 79{
72 struct wl1271_static_data *static_data; 80 struct wl1271_static_data *static_data;
81 size_t len = sizeof(*static_data) + wl->static_data_priv_len;
73 int ret; 82 int ret;
74 83
75 static_data = kmalloc(sizeof(*static_data), GFP_KERNEL | GFP_DMA); 84 static_data = kmalloc(len, GFP_KERNEL);
76 if (!static_data) { 85 if (!static_data) {
77 wl1271_error("Couldn't allocate memory for static data!"); 86 ret = -ENOMEM;
78 return -ENOMEM; 87 goto out;
79 } 88 }
80 89
81 wl1271_read(wl, wl->cmd_box_addr, static_data, sizeof(*static_data), 90 wl1271_read(wl, wl->cmd_box_addr, static_data, len, false);
82 false);
83
84 strncpy(wl->chip.fw_ver_str, static_data->fw_version,
85 sizeof(wl->chip.fw_ver_str));
86
87 kfree(static_data);
88 91
89 /* make sure the string is NULL-terminated */ 92 ret = wlcore_boot_parse_fw_ver(wl, static_data);
90 wl->chip.fw_ver_str[sizeof(wl->chip.fw_ver_str) - 1] = '\0'; 93 if (ret < 0)
94 goto out_free;
91 95
92 ret = wlcore_parse_fw_ver(wl); 96 ret = wlcore_handle_static_data(wl, static_data);
93 if (ret < 0) 97 if (ret < 0)
94 return ret; 98 goto out_free;
95 99
96 return 0; 100out_free:
101 kfree(static_data);
102out:
103 return ret;
97} 104}
98 105
99static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf, 106static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
@@ -204,8 +211,10 @@ int wlcore_boot_upload_nvs(struct wl1271 *wl)
204 u32 dest_addr, val; 211 u32 dest_addr, val;
205 u8 *nvs_ptr, *nvs_aligned; 212 u8 *nvs_ptr, *nvs_aligned;
206 213
207 if (wl->nvs == NULL) 214 if (wl->nvs == NULL) {
215 wl1271_error("NVS file is needed during boot");
208 return -ENODEV; 216 return -ENODEV;
217 }
209 218
210 if (wl->quirks & WLCORE_QUIRK_LEGACY_NVS) { 219 if (wl->quirks & WLCORE_QUIRK_LEGACY_NVS) {
211 struct wl1271_nvs_file *nvs = 220 struct wl1271_nvs_file *nvs =
@@ -400,9 +409,9 @@ int wlcore_boot_run_firmware(struct wl1271 *wl)
400 wl1271_debug(DEBUG_MAILBOX, "MBOX ptrs: 0x%x 0x%x", 409 wl1271_debug(DEBUG_MAILBOX, "MBOX ptrs: 0x%x 0x%x",
401 wl->mbox_ptr[0], wl->mbox_ptr[1]); 410 wl->mbox_ptr[0], wl->mbox_ptr[1]);
402 411
403 ret = wlcore_boot_fw_version(wl); 412 ret = wlcore_boot_static_data(wl);
404 if (ret < 0) { 413 if (ret < 0) {
405 wl1271_error("couldn't boot firmware"); 414 wl1271_error("error getting static data");
406 return ret; 415 return ret;
407 } 416 }
408 417
diff --git a/drivers/net/wireless/ti/wlcore/boot.h b/drivers/net/wireless/ti/wlcore/boot.h
index 094981dd2227..a525225f990c 100644
--- a/drivers/net/wireless/ti/wlcore/boot.h
+++ b/drivers/net/wireless/ti/wlcore/boot.h
@@ -40,6 +40,7 @@ struct wl1271_static_data {
40 u8 fw_version[WL1271_FW_VERSION_MAX_LEN]; 40 u8 fw_version[WL1271_FW_VERSION_MAX_LEN];
41 u32 hw_version; 41 u32 hw_version;
42 u8 tx_power_table[WL1271_NO_SUBBANDS][WL1271_NO_POWER_LEVELS]; 42 u8 tx_power_table[WL1271_NO_SUBBANDS][WL1271_NO_POWER_LEVELS];
43 u8 priv[0];
43}; 44};
44 45
45/* number of times we try to read the INIT interrupt */ 46/* number of times we try to read the INIT interrupt */
diff --git a/drivers/net/wireless/ti/wlcore/cmd.c b/drivers/net/wireless/ti/wlcore/cmd.c
index 5b128a971449..885364ca4344 100644
--- a/drivers/net/wireless/ti/wlcore/cmd.c
+++ b/drivers/net/wireless/ti/wlcore/cmd.c
@@ -36,6 +36,7 @@
36#include "cmd.h" 36#include "cmd.h"
37#include "event.h" 37#include "event.h"
38#include "tx.h" 38#include "tx.h"
39#include "hw_ops.h"
39 40
40#define WL1271_CMD_FAST_POLL_COUNT 50 41#define WL1271_CMD_FAST_POLL_COUNT 50
41 42
@@ -291,6 +292,23 @@ static int wl12xx_get_new_session_id(struct wl1271 *wl,
291 return wlvif->session_counter; 292 return wlvif->session_counter;
292} 293}
293 294
295static u8 wlcore_get_native_channel_type(u8 nl_channel_type)
296{
297 switch (nl_channel_type) {
298 case NL80211_CHAN_NO_HT:
299 return WLCORE_CHAN_NO_HT;
300 case NL80211_CHAN_HT20:
301 return WLCORE_CHAN_HT20;
302 case NL80211_CHAN_HT40MINUS:
303 return WLCORE_CHAN_HT40MINUS;
304 case NL80211_CHAN_HT40PLUS:
305 return WLCORE_CHAN_HT40PLUS;
306 default:
307 WARN_ON(1);
308 return WLCORE_CHAN_NO_HT;
309 }
310}
311
294static int wl12xx_cmd_role_start_dev(struct wl1271 *wl, 312static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
295 struct wl12xx_vif *wlvif) 313 struct wl12xx_vif *wlvif)
296{ 314{
@@ -407,6 +425,7 @@ int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
407 memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len); 425 memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
408 memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN); 426 memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
409 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set); 427 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
428 cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type);
410 429
411 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) { 430 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
412 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid); 431 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
@@ -482,6 +501,7 @@ int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
482 struct wl12xx_cmd_role_start *cmd; 501 struct wl12xx_cmd_role_start *cmd;
483 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); 502 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
484 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 503 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
504 u32 supported_rates;
485 int ret; 505 int ret;
486 506
487 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id); 507 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
@@ -519,6 +539,7 @@ int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
519 /* FIXME: Change when adding DFS */ 539 /* FIXME: Change when adding DFS */
520 cmd->ap.reset_tsf = 1; /* By default reset AP TSF */ 540 cmd->ap.reset_tsf = 1; /* By default reset AP TSF */
521 cmd->channel = wlvif->channel; 541 cmd->channel = wlvif->channel;
542 cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type);
522 543
523 if (!bss_conf->hidden_ssid) { 544 if (!bss_conf->hidden_ssid) {
524 /* take the SSID from the beacon for backward compatibility */ 545 /* take the SSID from the beacon for backward compatibility */
@@ -531,7 +552,13 @@ int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
531 memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len); 552 memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
532 } 553 }
533 554
534 cmd->ap.local_rates = cpu_to_le32(0xffffffff); 555 supported_rates = CONF_TX_AP_ENABLED_RATES | CONF_TX_MCS_RATES |
556 wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
557
558 wl1271_debug(DEBUG_CMD, "cmd role start ap with supported_rates 0x%08x",
559 supported_rates);
560
561 cmd->ap.local_rates = cpu_to_le32(supported_rates);
535 562
536 switch (wlvif->band) { 563 switch (wlvif->band) {
537 case IEEE80211_BAND_2GHZ: 564 case IEEE80211_BAND_2GHZ:
@@ -797,6 +824,7 @@ out:
797 kfree(cmd); 824 kfree(cmd);
798 return ret; 825 return ret;
799} 826}
827EXPORT_SYMBOL_GPL(wl1271_cmd_data_path);
800 828
801int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif, 829int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
802 u8 ps_mode, u16 auto_ps_timeout) 830 u8 ps_mode, u16 auto_ps_timeout)
@@ -1018,7 +1046,7 @@ out:
1018 1046
1019int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif) 1047int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1020{ 1048{
1021 int ret, extra; 1049 int ret, extra = 0;
1022 u16 fc; 1050 u16 fc;
1023 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); 1051 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1024 struct sk_buff *skb; 1052 struct sk_buff *skb;
@@ -1057,7 +1085,8 @@ int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1057 /* encryption space */ 1085 /* encryption space */
1058 switch (wlvif->encryption_type) { 1086 switch (wlvif->encryption_type) {
1059 case KEY_TKIP: 1087 case KEY_TKIP:
1060 extra = WL1271_EXTRA_SPACE_TKIP; 1088 if (wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE)
1089 extra = WL1271_EXTRA_SPACE_TKIP;
1061 break; 1090 break;
1062 case KEY_AES: 1091 case KEY_AES:
1063 extra = WL1271_EXTRA_SPACE_AES; 1092 extra = WL1271_EXTRA_SPACE_AES;
@@ -1346,13 +1375,18 @@ int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1346 1375
1347 for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++) 1376 for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
1348 if (sta->wme && (sta->uapsd_queues & BIT(i))) 1377 if (sta->wme && (sta->uapsd_queues & BIT(i)))
1349 cmd->psd_type[i] = WL1271_PSD_UPSD_TRIGGER; 1378 cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] =
1379 WL1271_PSD_UPSD_TRIGGER;
1350 else 1380 else
1351 cmd->psd_type[i] = WL1271_PSD_LEGACY; 1381 cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] =
1382 WL1271_PSD_LEGACY;
1383
1352 1384
1353 sta_rates = sta->supp_rates[wlvif->band]; 1385 sta_rates = sta->supp_rates[wlvif->band];
1354 if (sta->ht_cap.ht_supported) 1386 if (sta->ht_cap.ht_supported)
1355 sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET; 1387 sta_rates |=
1388 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET) |
1389 (sta->ht_cap.mcs.rx_mask[1] << HW_MIMO_RATES_OFFSET);
1356 1390
1357 cmd->supported_rates = 1391 cmd->supported_rates =
1358 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates, 1392 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
@@ -1573,19 +1607,25 @@ out:
1573int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id) 1607int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
1574{ 1608{
1575 int ret = 0; 1609 int ret = 0;
1610 bool is_first_roc;
1576 1611
1577 if (WARN_ON(test_bit(role_id, wl->roc_map))) 1612 if (WARN_ON(test_bit(role_id, wl->roc_map)))
1578 return 0; 1613 return 0;
1579 1614
1615 is_first_roc = (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >=
1616 WL12XX_MAX_ROLES);
1617
1580 ret = wl12xx_cmd_roc(wl, wlvif, role_id); 1618 ret = wl12xx_cmd_roc(wl, wlvif, role_id);
1581 if (ret < 0) 1619 if (ret < 0)
1582 goto out; 1620 goto out;
1583 1621
1584 ret = wl1271_cmd_wait_for_event(wl, 1622 if (is_first_roc) {
1585 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID); 1623 ret = wl1271_cmd_wait_for_event(wl,
1586 if (ret < 0) { 1624 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
1587 wl1271_error("cmd roc event completion error"); 1625 if (ret < 0) {
1588 goto out; 1626 wl1271_error("cmd roc event completion error");
1627 goto out;
1628 }
1589 } 1629 }
1590 1630
1591 __set_bit(role_id, wl->roc_map); 1631 __set_bit(role_id, wl->roc_map);
diff --git a/drivers/net/wireless/ti/wlcore/cmd.h b/drivers/net/wireless/ti/wlcore/cmd.h
index a46ae07cb77e..85171f2bf68e 100644
--- a/drivers/net/wireless/ti/wlcore/cmd.h
+++ b/drivers/net/wireless/ti/wlcore/cmd.h
@@ -192,7 +192,7 @@ enum cmd_templ {
192#define WL1271_COMMAND_TIMEOUT 2000 192#define WL1271_COMMAND_TIMEOUT 2000
193#define WL1271_CMD_TEMPL_DFLT_SIZE 252 193#define WL1271_CMD_TEMPL_DFLT_SIZE 252
194#define WL1271_CMD_TEMPL_MAX_SIZE 512 194#define WL1271_CMD_TEMPL_MAX_SIZE 512
195#define WL1271_EVENT_TIMEOUT 750 195#define WL1271_EVENT_TIMEOUT 1000
196 196
197struct wl1271_cmd_header { 197struct wl1271_cmd_header {
198 __le16 id; 198 __le16 id;
@@ -266,13 +266,22 @@ enum wlcore_band {
266 WLCORE_BAND_MAX_RADIO = 0x7F, 266 WLCORE_BAND_MAX_RADIO = 0x7F,
267}; 267};
268 268
269enum wlcore_channel_type {
270 WLCORE_CHAN_NO_HT,
271 WLCORE_CHAN_HT20,
272 WLCORE_CHAN_HT40MINUS,
273 WLCORE_CHAN_HT40PLUS
274};
275
269struct wl12xx_cmd_role_start { 276struct wl12xx_cmd_role_start {
270 struct wl1271_cmd_header header; 277 struct wl1271_cmd_header header;
271 278
272 u8 role_id; 279 u8 role_id;
273 u8 band; 280 u8 band;
274 u8 channel; 281 u8 channel;
275 u8 padding; 282
283 /* enum wlcore_channel_type */
284 u8 channel_type;
276 285
277 union { 286 union {
278 struct { 287 struct {
diff --git a/drivers/net/wireless/ti/wlcore/conf.h b/drivers/net/wireless/ti/wlcore/conf.h
index fef0db4213bc..03c635872335 100644
--- a/drivers/net/wireless/ti/wlcore/conf.h
+++ b/drivers/net/wireless/ti/wlcore/conf.h
@@ -45,7 +45,15 @@ enum {
45 CONF_HW_BIT_RATE_MCS_4 = BIT(17), 45 CONF_HW_BIT_RATE_MCS_4 = BIT(17),
46 CONF_HW_BIT_RATE_MCS_5 = BIT(18), 46 CONF_HW_BIT_RATE_MCS_5 = BIT(18),
47 CONF_HW_BIT_RATE_MCS_6 = BIT(19), 47 CONF_HW_BIT_RATE_MCS_6 = BIT(19),
48 CONF_HW_BIT_RATE_MCS_7 = BIT(20) 48 CONF_HW_BIT_RATE_MCS_7 = BIT(20),
49 CONF_HW_BIT_RATE_MCS_8 = BIT(21),
50 CONF_HW_BIT_RATE_MCS_9 = BIT(22),
51 CONF_HW_BIT_RATE_MCS_10 = BIT(23),
52 CONF_HW_BIT_RATE_MCS_11 = BIT(24),
53 CONF_HW_BIT_RATE_MCS_12 = BIT(25),
54 CONF_HW_BIT_RATE_MCS_13 = BIT(26),
55 CONF_HW_BIT_RATE_MCS_14 = BIT(27),
56 CONF_HW_BIT_RATE_MCS_15 = BIT(28),
49}; 57};
50 58
51enum { 59enum {
@@ -310,7 +318,7 @@ enum {
310struct conf_sg_settings { 318struct conf_sg_settings {
311 u32 params[CONF_SG_PARAMS_MAX]; 319 u32 params[CONF_SG_PARAMS_MAX];
312 u8 state; 320 u8 state;
313}; 321} __packed;
314 322
315enum conf_rx_queue_type { 323enum conf_rx_queue_type {
316 CONF_RX_QUEUE_TYPE_LOW_PRIORITY, /* All except the high priority */ 324 CONF_RX_QUEUE_TYPE_LOW_PRIORITY, /* All except the high priority */
@@ -394,7 +402,7 @@ struct conf_rx_settings {
394 * Range: RX_QUEUE_TYPE_RX_LOW_PRIORITY, RX_QUEUE_TYPE_RX_HIGH_PRIORITY, 402 * Range: RX_QUEUE_TYPE_RX_LOW_PRIORITY, RX_QUEUE_TYPE_RX_HIGH_PRIORITY,
395 */ 403 */
396 u8 queue_type; 404 u8 queue_type;
397}; 405} __packed;
398 406
399#define CONF_TX_MAX_RATE_CLASSES 10 407#define CONF_TX_MAX_RATE_CLASSES 10
400 408
@@ -435,6 +443,12 @@ struct conf_rx_settings {
435 CONF_HW_BIT_RATE_MCS_5 | CONF_HW_BIT_RATE_MCS_6 | \ 443 CONF_HW_BIT_RATE_MCS_5 | CONF_HW_BIT_RATE_MCS_6 | \
436 CONF_HW_BIT_RATE_MCS_7) 444 CONF_HW_BIT_RATE_MCS_7)
437 445
446#define CONF_TX_MIMO_RATES (CONF_HW_BIT_RATE_MCS_8 | \
447 CONF_HW_BIT_RATE_MCS_9 | CONF_HW_BIT_RATE_MCS_10 | \
448 CONF_HW_BIT_RATE_MCS_11 | CONF_HW_BIT_RATE_MCS_12 | \
449 CONF_HW_BIT_RATE_MCS_13 | CONF_HW_BIT_RATE_MCS_14 | \
450 CONF_HW_BIT_RATE_MCS_15)
451
438/* 452/*
439 * Default rates for management traffic when operating in AP mode. This 453 * Default rates for management traffic when operating in AP mode. This
440 * should be configured according to the basic rate set of the AP 454 * should be configured according to the basic rate set of the AP
@@ -487,7 +501,7 @@ struct conf_tx_rate_class {
487 * the policy (0 - long preamble, 1 - short preamble. 501 * the policy (0 - long preamble, 1 - short preamble.
488 */ 502 */
489 u8 aflags; 503 u8 aflags;
490}; 504} __packed;
491 505
492#define CONF_TX_MAX_AC_COUNT 4 506#define CONF_TX_MAX_AC_COUNT 4
493 507
@@ -504,7 +518,7 @@ enum conf_tx_ac {
504 CONF_TX_AC_VI = 2, /* video */ 518 CONF_TX_AC_VI = 2, /* video */
505 CONF_TX_AC_VO = 3, /* voice */ 519 CONF_TX_AC_VO = 3, /* voice */
506 CONF_TX_AC_CTS2SELF = 4, /* fictitious AC, follows AC_VO */ 520 CONF_TX_AC_CTS2SELF = 4, /* fictitious AC, follows AC_VO */
507 CONF_TX_AC_ANY_TID = 0x1f 521 CONF_TX_AC_ANY_TID = 0xff
508}; 522};
509 523
510struct conf_tx_ac_category { 524struct conf_tx_ac_category {
@@ -544,7 +558,7 @@ struct conf_tx_ac_category {
544 * Range: u16 558 * Range: u16
545 */ 559 */
546 u16 tx_op_limit; 560 u16 tx_op_limit;
547}; 561} __packed;
548 562
549#define CONF_TX_MAX_TID_COUNT 8 563#define CONF_TX_MAX_TID_COUNT 8
550 564
@@ -578,7 +592,7 @@ struct conf_tx_tid {
578 u8 ps_scheme; 592 u8 ps_scheme;
579 u8 ack_policy; 593 u8 ack_policy;
580 u32 apsd_conf[2]; 594 u32 apsd_conf[2];
581}; 595} __packed;
582 596
583struct conf_tx_settings { 597struct conf_tx_settings {
584 /* 598 /*
@@ -664,7 +678,7 @@ struct conf_tx_settings {
664 678
665 /* Time in ms for Tx watchdog timer to expire */ 679 /* Time in ms for Tx watchdog timer to expire */
666 u32 tx_watchdog_timeout; 680 u32 tx_watchdog_timeout;
667}; 681} __packed;
668 682
669enum { 683enum {
670 CONF_WAKE_UP_EVENT_BEACON = 0x01, /* Wake on every Beacon*/ 684 CONF_WAKE_UP_EVENT_BEACON = 0x01, /* Wake on every Beacon*/
@@ -711,7 +725,7 @@ struct conf_bcn_filt_rule {
711 * Version for the vendor specifie IE (221) 725 * Version for the vendor specifie IE (221)
712 */ 726 */
713 u8 version[CONF_BCN_IE_VER_LEN]; 727 u8 version[CONF_BCN_IE_VER_LEN];
714}; 728} __packed;
715 729
716#define CONF_MAX_RSSI_SNR_TRIGGERS 8 730#define CONF_MAX_RSSI_SNR_TRIGGERS 8
717 731
@@ -762,7 +776,7 @@ struct conf_sig_weights {
762 * Range: u8 776 * Range: u8
763 */ 777 */
764 u8 snr_pkt_avg_weight; 778 u8 snr_pkt_avg_weight;
765}; 779} __packed;
766 780
767enum conf_bcn_filt_mode { 781enum conf_bcn_filt_mode {
768 CONF_BCN_FILT_MODE_DISABLED = 0, 782 CONF_BCN_FILT_MODE_DISABLED = 0,
@@ -810,7 +824,7 @@ struct conf_conn_settings {
810 * 824 *
811 * Range: CONF_BCN_FILT_MODE_* 825 * Range: CONF_BCN_FILT_MODE_*
812 */ 826 */
813 enum conf_bcn_filt_mode bcn_filt_mode; 827 u8 bcn_filt_mode;
814 828
815 /* 829 /*
816 * Configure Beacon filter pass-thru rules. 830 * Configure Beacon filter pass-thru rules.
@@ -937,7 +951,7 @@ struct conf_conn_settings {
937 * Range: u16 951 * Range: u16
938 */ 952 */
939 u8 max_listen_interval; 953 u8 max_listen_interval;
940}; 954} __packed;
941 955
942enum { 956enum {
943 CONF_REF_CLK_19_2_E, 957 CONF_REF_CLK_19_2_E,
@@ -965,6 +979,11 @@ struct conf_itrim_settings {
965 979
966 /* moderation timeout in microsecs from the last TX */ 980 /* moderation timeout in microsecs from the last TX */
967 u32 timeout; 981 u32 timeout;
982} __packed;
983
984enum conf_fast_wakeup {
985 CONF_FAST_WAKEUP_ENABLE,
986 CONF_FAST_WAKEUP_DISABLE,
968}; 987};
969 988
970struct conf_pm_config_settings { 989struct conf_pm_config_settings {
@@ -978,10 +997,10 @@ struct conf_pm_config_settings {
978 /* 997 /*
979 * Host fast wakeup support 998 * Host fast wakeup support
980 * 999 *
981 * Range: true, false 1000 * Range: enum conf_fast_wakeup
982 */ 1001 */
983 bool host_fast_wakeup_support; 1002 u8 host_fast_wakeup_support;
984}; 1003} __packed;
985 1004
986struct conf_roam_trigger_settings { 1005struct conf_roam_trigger_settings {
987 /* 1006 /*
@@ -1018,7 +1037,7 @@ struct conf_roam_trigger_settings {
1018 * Range: 0 - 255 1037 * Range: 0 - 255
1019 */ 1038 */
1020 u8 avg_weight_snr_data; 1039 u8 avg_weight_snr_data;
1021}; 1040} __packed;
1022 1041
1023struct conf_scan_settings { 1042struct conf_scan_settings {
1024 /* 1043 /*
@@ -1064,7 +1083,7 @@ struct conf_scan_settings {
1064 * Range: u32 Microsecs 1083 * Range: u32 Microsecs
1065 */ 1084 */
1066 u32 split_scan_timeout; 1085 u32 split_scan_timeout;
1067}; 1086} __packed;
1068 1087
1069struct conf_sched_scan_settings { 1088struct conf_sched_scan_settings {
1070 /* 1089 /*
@@ -1102,7 +1121,7 @@ struct conf_sched_scan_settings {
1102 1121
1103 /* SNR threshold to be used for filtering */ 1122 /* SNR threshold to be used for filtering */
1104 s8 snr_threshold; 1123 s8 snr_threshold;
1105}; 1124} __packed;
1106 1125
1107struct conf_ht_setting { 1126struct conf_ht_setting {
1108 u8 rx_ba_win_size; 1127 u8 rx_ba_win_size;
@@ -1111,7 +1130,7 @@ struct conf_ht_setting {
1111 1130
1112 /* bitmap of enabled TIDs for TX BA sessions */ 1131 /* bitmap of enabled TIDs for TX BA sessions */
1113 u8 tx_ba_tid_bitmap; 1132 u8 tx_ba_tid_bitmap;
1114}; 1133} __packed;
1115 1134
1116struct conf_memory_settings { 1135struct conf_memory_settings {
1117 /* Number of stations supported in IBSS mode */ 1136 /* Number of stations supported in IBSS mode */
@@ -1151,7 +1170,7 @@ struct conf_memory_settings {
1151 * Range: 0-120 1170 * Range: 0-120
1152 */ 1171 */
1153 u8 tx_min; 1172 u8 tx_min;
1154}; 1173} __packed;
1155 1174
1156struct conf_fm_coex { 1175struct conf_fm_coex {
1157 u8 enable; 1176 u8 enable;
@@ -1164,7 +1183,7 @@ struct conf_fm_coex {
1164 u16 ldo_stabilization_time; 1183 u16 ldo_stabilization_time;
1165 u8 fm_disturbed_band_margin; 1184 u8 fm_disturbed_band_margin;
1166 u8 swallow_clk_diff; 1185 u8 swallow_clk_diff;
1167}; 1186} __packed;
1168 1187
1169struct conf_rx_streaming_settings { 1188struct conf_rx_streaming_settings {
1170 /* 1189 /*
@@ -1193,7 +1212,7 @@ struct conf_rx_streaming_settings {
1193 * enable rx streaming also when there is no coex activity 1212 * enable rx streaming also when there is no coex activity
1194 */ 1213 */
1195 u8 always; 1214 u8 always;
1196}; 1215} __packed;
1197 1216
1198struct conf_fwlog { 1217struct conf_fwlog {
1199 /* Continuous or on-demand */ 1218 /* Continuous or on-demand */
@@ -1217,7 +1236,7 @@ struct conf_fwlog {
1217 1236
1218 /* Regulates the frequency of log messages */ 1237 /* Regulates the frequency of log messages */
1219 u8 threshold; 1238 u8 threshold;
1220}; 1239} __packed;
1221 1240
1222#define ACX_RATE_MGMT_NUM_OF_RATES 13 1241#define ACX_RATE_MGMT_NUM_OF_RATES 13
1223struct conf_rate_policy_settings { 1242struct conf_rate_policy_settings {
@@ -1236,7 +1255,7 @@ struct conf_rate_policy_settings {
1236 u8 rate_check_up; 1255 u8 rate_check_up;
1237 u8 rate_check_down; 1256 u8 rate_check_down;
1238 u8 rate_retry_policy[ACX_RATE_MGMT_NUM_OF_RATES]; 1257 u8 rate_retry_policy[ACX_RATE_MGMT_NUM_OF_RATES];
1239}; 1258} __packed;
1240 1259
1241struct conf_hangover_settings { 1260struct conf_hangover_settings {
1242 u32 recover_time; 1261 u32 recover_time;
@@ -1250,7 +1269,23 @@ struct conf_hangover_settings {
1250 u8 quiet_time; 1269 u8 quiet_time;
1251 u8 increase_time; 1270 u8 increase_time;
1252 u8 window_size; 1271 u8 window_size;
1253}; 1272} __packed;
1273
1274/*
1275 * The conf version consists of 4 bytes. The two MSB are the wlcore
1276 * version, the two LSB are the lower driver's private conf
1277 * version.
1278 */
1279#define WLCORE_CONF_VERSION (0x0001 << 16)
1280#define WLCORE_CONF_MASK 0xffff0000
1281#define WLCORE_CONF_SIZE (sizeof(struct wlcore_conf_header) + \
1282 sizeof(struct wlcore_conf))
1283
1284struct wlcore_conf_header {
1285 __le32 magic;
1286 __le32 version;
1287 __le32 checksum;
1288} __packed;
1254 1289
1255struct wlcore_conf { 1290struct wlcore_conf {
1256 struct conf_sg_settings sg; 1291 struct conf_sg_settings sg;
@@ -1269,6 +1304,12 @@ struct wlcore_conf {
1269 struct conf_fwlog fwlog; 1304 struct conf_fwlog fwlog;
1270 struct conf_rate_policy_settings rate; 1305 struct conf_rate_policy_settings rate;
1271 struct conf_hangover_settings hangover; 1306 struct conf_hangover_settings hangover;
1272}; 1307} __packed;
1308
1309struct wlcore_conf_file {
1310 struct wlcore_conf_header header;
1311 struct wlcore_conf core;
1312 u8 priv[0];
1313} __packed;
1273 1314
1274#endif 1315#endif
diff --git a/drivers/net/wireless/ti/wlcore/debugfs.c b/drivers/net/wireless/ti/wlcore/debugfs.c
index d5aea1ff5ad1..689a847005c9 100644
--- a/drivers/net/wireless/ti/wlcore/debugfs.c
+++ b/drivers/net/wireless/ti/wlcore/debugfs.c
@@ -25,6 +25,7 @@
25 25
26#include <linux/skbuff.h> 26#include <linux/skbuff.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/module.h>
28 29
29#include "wlcore.h" 30#include "wlcore.h"
30#include "debug.h" 31#include "debug.h"
@@ -32,14 +33,14 @@
32#include "ps.h" 33#include "ps.h"
33#include "io.h" 34#include "io.h"
34#include "tx.h" 35#include "tx.h"
36#include "hw_ops.h"
35 37
36/* ms */ 38/* ms */
37#define WL1271_DEBUGFS_STATS_LIFETIME 1000 39#define WL1271_DEBUGFS_STATS_LIFETIME 1000
38 40
39/* debugfs macros idea from mac80211 */ 41/* debugfs macros idea from mac80211 */
40#define DEBUGFS_FORMAT_BUFFER_SIZE 100 42int wl1271_format_buffer(char __user *userbuf, size_t count,
41static int wl1271_format_buffer(char __user *userbuf, size_t count, 43 loff_t *ppos, char *fmt, ...)
42 loff_t *ppos, char *fmt, ...)
43{ 44{
44 va_list args; 45 va_list args;
45 char buf[DEBUGFS_FORMAT_BUFFER_SIZE]; 46 char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
@@ -51,59 +52,9 @@ static int wl1271_format_buffer(char __user *userbuf, size_t count,
51 52
52 return simple_read_from_buffer(userbuf, count, ppos, buf, res); 53 return simple_read_from_buffer(userbuf, count, ppos, buf, res);
53} 54}
55EXPORT_SYMBOL_GPL(wl1271_format_buffer);
54 56
55#define DEBUGFS_READONLY_FILE(name, fmt, value...) \ 57void wl1271_debugfs_update_stats(struct wl1271 *wl)
56static ssize_t name## _read(struct file *file, char __user *userbuf, \
57 size_t count, loff_t *ppos) \
58{ \
59 struct wl1271 *wl = file->private_data; \
60 return wl1271_format_buffer(userbuf, count, ppos, \
61 fmt "\n", ##value); \
62} \
63 \
64static const struct file_operations name## _ops = { \
65 .read = name## _read, \
66 .open = simple_open, \
67 .llseek = generic_file_llseek, \
68};
69
70#define DEBUGFS_ADD(name, parent) \
71 entry = debugfs_create_file(#name, 0400, parent, \
72 wl, &name## _ops); \
73 if (!entry || IS_ERR(entry)) \
74 goto err; \
75
76#define DEBUGFS_ADD_PREFIX(prefix, name, parent) \
77 do { \
78 entry = debugfs_create_file(#name, 0400, parent, \
79 wl, &prefix## _## name## _ops); \
80 if (!entry || IS_ERR(entry)) \
81 goto err; \
82 } while (0);
83
84#define DEBUGFS_FWSTATS_FILE(sub, name, fmt) \
85static ssize_t sub## _ ##name## _read(struct file *file, \
86 char __user *userbuf, \
87 size_t count, loff_t *ppos) \
88{ \
89 struct wl1271 *wl = file->private_data; \
90 \
91 wl1271_debugfs_update_stats(wl); \
92 \
93 return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
94 wl->stats.fw_stats->sub.name); \
95} \
96 \
97static const struct file_operations sub## _ ##name## _ops = { \
98 .read = sub## _ ##name## _read, \
99 .open = simple_open, \
100 .llseek = generic_file_llseek, \
101};
102
103#define DEBUGFS_FWSTATS_ADD(sub, name) \
104 DEBUGFS_ADD(sub## _ ##name, stats)
105
106static void wl1271_debugfs_update_stats(struct wl1271 *wl)
107{ 58{
108 int ret; 59 int ret;
109 60
@@ -125,97 +76,7 @@ static void wl1271_debugfs_update_stats(struct wl1271 *wl)
125out: 76out:
126 mutex_unlock(&wl->mutex); 77 mutex_unlock(&wl->mutex);
127} 78}
128 79EXPORT_SYMBOL_GPL(wl1271_debugfs_update_stats);
129DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
130
131DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
132DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u");
133DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u");
134DEBUGFS_FWSTATS_FILE(rx, dropped, "%u");
135DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u");
136DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u");
137DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u");
138DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u");
139
140DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u");
141DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u");
142DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u");
143DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u");
144
145DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u");
146DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u");
147DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u");
148DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u");
149DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u");
150DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
151DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u");
152DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u");
153DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u");
154DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u");
155DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u");
156DEBUGFS_FWSTATS_FILE(isr, commands, "%u");
157DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u");
158DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u");
159DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u");
160DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u");
161DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u");
162DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u");
163
164DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
165DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
166/* skipping wep.reserved */
167DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u");
168DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u");
169DEBUGFS_FWSTATS_FILE(wep, packets, "%u");
170DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u");
171
172DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u");
173DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u");
174DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u");
175DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u");
176DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u");
177DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u");
178DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u");
179DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u");
180DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u");
181DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u");
182DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u");
183DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u");
184/* skipping cont_miss_bcns_spread for now */
185DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
186
187DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
188DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
189
190DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u");
191DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u");
192DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u");
193DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u");
194DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u");
195DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u");
196
197DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u");
198DEBUGFS_FWSTATS_FILE(event, calibration, "%u");
199DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u");
200DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u");
201DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u");
202DEBUGFS_FWSTATS_FILE(event, oom_late, "%u");
203DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u");
204DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u");
205
206DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u");
207DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u");
208DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u");
209DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u");
210DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u");
211DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u");
212DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u");
213
214DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u");
215DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u");
216DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u");
217DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u");
218DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u");
219 80
220DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count); 81DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
221DEBUGFS_READONLY_FILE(excessive_retries, "%u", 82DEBUGFS_READONLY_FILE(excessive_retries, "%u",
@@ -241,6 +102,89 @@ static const struct file_operations tx_queue_len_ops = {
241 .llseek = default_llseek, 102 .llseek = default_llseek,
242}; 103};
243 104
105static void chip_op_handler(struct wl1271 *wl, unsigned long value,
106 void *arg)
107{
108 int ret;
109 int (*chip_op) (struct wl1271 *wl);
110
111 if (!arg) {
112 wl1271_warning("debugfs chip_op_handler with no callback");
113 return;
114 }
115
116 ret = wl1271_ps_elp_wakeup(wl);
117 if (ret < 0)
118 return;
119
120 chip_op = arg;
121 chip_op(wl);
122
123 wl1271_ps_elp_sleep(wl);
124}
125
126
127static inline void no_write_handler(struct wl1271 *wl,
128 unsigned long value,
129 unsigned long param)
130{
131}
132
133#define WL12XX_CONF_DEBUGFS(param, conf_sub_struct, \
134 min_val, max_val, write_handler_locked, \
135 write_handler_arg) \
136 static ssize_t param##_read(struct file *file, \
137 char __user *user_buf, \
138 size_t count, loff_t *ppos) \
139 { \
140 struct wl1271 *wl = file->private_data; \
141 return wl1271_format_buffer(user_buf, count, \
142 ppos, "%d\n", \
143 wl->conf.conf_sub_struct.param); \
144 } \
145 \
146 static ssize_t param##_write(struct file *file, \
147 const char __user *user_buf, \
148 size_t count, loff_t *ppos) \
149 { \
150 struct wl1271 *wl = file->private_data; \
151 unsigned long value; \
152 int ret; \
153 \
154 ret = kstrtoul_from_user(user_buf, count, 10, &value); \
155 if (ret < 0) { \
156 wl1271_warning("illegal value for " #param); \
157 return -EINVAL; \
158 } \
159 \
160 if (value < min_val || value > max_val) { \
161 wl1271_warning(#param " is not in valid range"); \
162 return -ERANGE; \
163 } \
164 \
165 mutex_lock(&wl->mutex); \
166 wl->conf.conf_sub_struct.param = value; \
167 \
168 write_handler_locked(wl, value, write_handler_arg); \
169 \
170 mutex_unlock(&wl->mutex); \
171 return count; \
172 } \
173 \
174 static const struct file_operations param##_ops = { \
175 .read = param##_read, \
176 .write = param##_write, \
177 .open = simple_open, \
178 .llseek = default_llseek, \
179 };
180
181WL12XX_CONF_DEBUGFS(irq_pkt_threshold, rx, 0, 65535,
182 chip_op_handler, wl1271_acx_init_rx_interrupt)
183WL12XX_CONF_DEBUGFS(irq_blk_threshold, rx, 0, 65535,
184 chip_op_handler, wl1271_acx_init_rx_interrupt)
185WL12XX_CONF_DEBUGFS(irq_timeout, rx, 0, 100,
186 chip_op_handler, wl1271_acx_init_rx_interrupt)
187
244static ssize_t gpio_power_read(struct file *file, char __user *user_buf, 188static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
245 size_t count, loff_t *ppos) 189 size_t count, loff_t *ppos)
246{ 190{
@@ -535,8 +479,7 @@ static ssize_t driver_state_read(struct file *file, char __user *user_buf,
535 DRIVER_STATE_PRINT_LHEX(ap_ps_map); 479 DRIVER_STATE_PRINT_LHEX(ap_ps_map);
536 DRIVER_STATE_PRINT_HEX(quirks); 480 DRIVER_STATE_PRINT_HEX(quirks);
537 DRIVER_STATE_PRINT_HEX(irq); 481 DRIVER_STATE_PRINT_HEX(irq);
538 DRIVER_STATE_PRINT_HEX(ref_clock); 482 /* TODO: ref_clock and tcxo_clock were moved to wl12xx priv */
539 DRIVER_STATE_PRINT_HEX(tcxo_clock);
540 DRIVER_STATE_PRINT_HEX(hw_pg_ver); 483 DRIVER_STATE_PRINT_HEX(hw_pg_ver);
541 DRIVER_STATE_PRINT_HEX(platform_quirks); 484 DRIVER_STATE_PRINT_HEX(platform_quirks);
542 DRIVER_STATE_PRINT_HEX(chip.id); 485 DRIVER_STATE_PRINT_HEX(chip.id);
@@ -647,7 +590,6 @@ static ssize_t vifs_state_read(struct file *file, char __user *user_buf,
647 VIF_STATE_PRINT_INT(last_rssi_event); 590 VIF_STATE_PRINT_INT(last_rssi_event);
648 VIF_STATE_PRINT_INT(ba_support); 591 VIF_STATE_PRINT_INT(ba_support);
649 VIF_STATE_PRINT_INT(ba_allowed); 592 VIF_STATE_PRINT_INT(ba_allowed);
650 VIF_STATE_PRINT_INT(is_gem);
651 VIF_STATE_PRINT_LLHEX(tx_security_seq); 593 VIF_STATE_PRINT_LLHEX(tx_security_seq);
652 VIF_STATE_PRINT_INT(tx_security_last_seq_lsb); 594 VIF_STATE_PRINT_INT(tx_security_last_seq_lsb);
653 } 595 }
@@ -1002,108 +944,30 @@ static const struct file_operations beacon_filtering_ops = {
1002 .llseek = default_llseek, 944 .llseek = default_llseek,
1003}; 945};
1004 946
1005static int wl1271_debugfs_add_files(struct wl1271 *wl, 947static ssize_t fw_stats_raw_read(struct file *file,
1006 struct dentry *rootdir) 948 char __user *userbuf,
949 size_t count, loff_t *ppos)
1007{ 950{
1008 int ret = 0; 951 struct wl1271 *wl = file->private_data;
1009 struct dentry *entry, *stats, *streaming;
1010 952
1011 stats = debugfs_create_dir("fw-statistics", rootdir); 953 wl1271_debugfs_update_stats(wl);
1012 if (!stats || IS_ERR(stats)) {
1013 entry = stats;
1014 goto err;
1015 }
1016 954
1017 DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow); 955 return simple_read_from_buffer(userbuf, count, ppos,
1018 956 wl->stats.fw_stats,
1019 DEBUGFS_FWSTATS_ADD(rx, out_of_mem); 957 wl->stats.fw_stats_len);
1020 DEBUGFS_FWSTATS_ADD(rx, hdr_overflow); 958}
1021 DEBUGFS_FWSTATS_ADD(rx, hw_stuck); 959
1022 DEBUGFS_FWSTATS_ADD(rx, dropped); 960static const struct file_operations fw_stats_raw_ops = {
1023 DEBUGFS_FWSTATS_ADD(rx, fcs_err); 961 .read = fw_stats_raw_read,
1024 DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig); 962 .open = simple_open,
1025 DEBUGFS_FWSTATS_ADD(rx, path_reset); 963 .llseek = default_llseek,
1026 DEBUGFS_FWSTATS_ADD(rx, reset_counter); 964};
1027 965
1028 DEBUGFS_FWSTATS_ADD(dma, rx_requested); 966static int wl1271_debugfs_add_files(struct wl1271 *wl,
1029 DEBUGFS_FWSTATS_ADD(dma, rx_errors); 967 struct dentry *rootdir)
1030 DEBUGFS_FWSTATS_ADD(dma, tx_requested); 968{
1031 DEBUGFS_FWSTATS_ADD(dma, tx_errors); 969 int ret = 0;
1032 970 struct dentry *entry, *streaming;
1033 DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
1034 DEBUGFS_FWSTATS_ADD(isr, fiqs);
1035 DEBUGFS_FWSTATS_ADD(isr, rx_headers);
1036 DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
1037 DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
1038 DEBUGFS_FWSTATS_ADD(isr, irqs);
1039 DEBUGFS_FWSTATS_ADD(isr, tx_procs);
1040 DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
1041 DEBUGFS_FWSTATS_ADD(isr, dma0_done);
1042 DEBUGFS_FWSTATS_ADD(isr, dma1_done);
1043 DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
1044 DEBUGFS_FWSTATS_ADD(isr, commands);
1045 DEBUGFS_FWSTATS_ADD(isr, rx_procs);
1046 DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
1047 DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
1048 DEBUGFS_FWSTATS_ADD(isr, pci_pm);
1049 DEBUGFS_FWSTATS_ADD(isr, wakeups);
1050 DEBUGFS_FWSTATS_ADD(isr, low_rssi);
1051
1052 DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
1053 DEBUGFS_FWSTATS_ADD(wep, default_key_count);
1054 /* skipping wep.reserved */
1055 DEBUGFS_FWSTATS_ADD(wep, key_not_found);
1056 DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
1057 DEBUGFS_FWSTATS_ADD(wep, packets);
1058 DEBUGFS_FWSTATS_ADD(wep, interrupt);
1059
1060 DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
1061 DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
1062 DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
1063 DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
1064 DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
1065 DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
1066 DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
1067 DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
1068 DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
1069 DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
1070 DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
1071 DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
1072 /* skipping cont_miss_bcns_spread for now */
1073 DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
1074
1075 DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
1076 DEBUGFS_FWSTATS_ADD(mic, calc_failure);
1077
1078 DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
1079 DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
1080 DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
1081 DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
1082 DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
1083 DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
1084
1085 DEBUGFS_FWSTATS_ADD(event, heart_beat);
1086 DEBUGFS_FWSTATS_ADD(event, calibration);
1087 DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
1088 DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
1089 DEBUGFS_FWSTATS_ADD(event, rx_pool);
1090 DEBUGFS_FWSTATS_ADD(event, oom_late);
1091 DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
1092 DEBUGFS_FWSTATS_ADD(event, tx_stuck);
1093
1094 DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
1095 DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
1096 DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
1097 DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
1098 DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
1099 DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
1100 DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
1101
1102 DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
1103 DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
1104 DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
1105 DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
1106 DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
1107 971
1108 DEBUGFS_ADD(tx_queue_len, rootdir); 972 DEBUGFS_ADD(tx_queue_len, rootdir);
1109 DEBUGFS_ADD(retry_count, rootdir); 973 DEBUGFS_ADD(retry_count, rootdir);
@@ -1120,6 +984,10 @@ static int wl1271_debugfs_add_files(struct wl1271 *wl,
1120 DEBUGFS_ADD(dynamic_ps_timeout, rootdir); 984 DEBUGFS_ADD(dynamic_ps_timeout, rootdir);
1121 DEBUGFS_ADD(forced_ps, rootdir); 985 DEBUGFS_ADD(forced_ps, rootdir);
1122 DEBUGFS_ADD(split_scan_timeout, rootdir); 986 DEBUGFS_ADD(split_scan_timeout, rootdir);
987 DEBUGFS_ADD(irq_pkt_threshold, rootdir);
988 DEBUGFS_ADD(irq_blk_threshold, rootdir);
989 DEBUGFS_ADD(irq_timeout, rootdir);
990 DEBUGFS_ADD(fw_stats_raw, rootdir);
1123 991
1124 streaming = debugfs_create_dir("rx_streaming", rootdir); 992 streaming = debugfs_create_dir("rx_streaming", rootdir);
1125 if (!streaming || IS_ERR(streaming)) 993 if (!streaming || IS_ERR(streaming))
@@ -1145,7 +1013,7 @@ void wl1271_debugfs_reset(struct wl1271 *wl)
1145 if (!wl->stats.fw_stats) 1013 if (!wl->stats.fw_stats)
1146 return; 1014 return;
1147 1015
1148 memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats)); 1016 memset(wl->stats.fw_stats, 0, wl->stats.fw_stats_len);
1149 wl->stats.retry_count = 0; 1017 wl->stats.retry_count = 0;
1150 wl->stats.excessive_retries = 0; 1018 wl->stats.excessive_retries = 0;
1151} 1019}
@@ -1160,34 +1028,34 @@ int wl1271_debugfs_init(struct wl1271 *wl)
1160 1028
1161 if (IS_ERR(rootdir)) { 1029 if (IS_ERR(rootdir)) {
1162 ret = PTR_ERR(rootdir); 1030 ret = PTR_ERR(rootdir);
1163 goto err; 1031 goto out;
1164 } 1032 }
1165 1033
1166 wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats), 1034 wl->stats.fw_stats = kzalloc(wl->stats.fw_stats_len, GFP_KERNEL);
1167 GFP_KERNEL);
1168
1169 if (!wl->stats.fw_stats) { 1035 if (!wl->stats.fw_stats) {
1170 ret = -ENOMEM; 1036 ret = -ENOMEM;
1171 goto err_fw; 1037 goto out_remove;
1172 } 1038 }
1173 1039
1174 wl->stats.fw_stats_update = jiffies; 1040 wl->stats.fw_stats_update = jiffies;
1175 1041
1176 ret = wl1271_debugfs_add_files(wl, rootdir); 1042 ret = wl1271_debugfs_add_files(wl, rootdir);
1043 if (ret < 0)
1044 goto out_exit;
1177 1045
1046 ret = wlcore_debugfs_init(wl, rootdir);
1178 if (ret < 0) 1047 if (ret < 0)
1179 goto err_file; 1048 goto out_exit;
1180 1049
1181 return 0; 1050 goto out;
1182 1051
1183err_file: 1052out_exit:
1184 kfree(wl->stats.fw_stats); 1053 wl1271_debugfs_exit(wl);
1185 wl->stats.fw_stats = NULL;
1186 1054
1187err_fw: 1055out_remove:
1188 debugfs_remove_recursive(rootdir); 1056 debugfs_remove_recursive(rootdir);
1189 1057
1190err: 1058out:
1191 return ret; 1059 return ret;
1192} 1060}
1193 1061
diff --git a/drivers/net/wireless/ti/wlcore/debugfs.h b/drivers/net/wireless/ti/wlcore/debugfs.h
index a8d3aef011ff..f7381dd69009 100644
--- a/drivers/net/wireless/ti/wlcore/debugfs.h
+++ b/drivers/net/wireless/ti/wlcore/debugfs.h
@@ -26,8 +26,95 @@
26 26
27#include "wlcore.h" 27#include "wlcore.h"
28 28
29int wl1271_format_buffer(char __user *userbuf, size_t count,
30 loff_t *ppos, char *fmt, ...);
31
29int wl1271_debugfs_init(struct wl1271 *wl); 32int wl1271_debugfs_init(struct wl1271 *wl);
30void wl1271_debugfs_exit(struct wl1271 *wl); 33void wl1271_debugfs_exit(struct wl1271 *wl);
31void wl1271_debugfs_reset(struct wl1271 *wl); 34void wl1271_debugfs_reset(struct wl1271 *wl);
35void wl1271_debugfs_update_stats(struct wl1271 *wl);
36
37#define DEBUGFS_FORMAT_BUFFER_SIZE 256
38
39#define DEBUGFS_READONLY_FILE(name, fmt, value...) \
40static ssize_t name## _read(struct file *file, char __user *userbuf, \
41 size_t count, loff_t *ppos) \
42{ \
43 struct wl1271 *wl = file->private_data; \
44 return wl1271_format_buffer(userbuf, count, ppos, \
45 fmt "\n", ##value); \
46} \
47 \
48static const struct file_operations name## _ops = { \
49 .read = name## _read, \
50 .open = simple_open, \
51 .llseek = generic_file_llseek, \
52};
53
54#define DEBUGFS_ADD(name, parent) \
55 do { \
56 entry = debugfs_create_file(#name, 0400, parent, \
57 wl, &name## _ops); \
58 if (!entry || IS_ERR(entry)) \
59 goto err; \
60 } while (0);
61
62
63#define DEBUGFS_ADD_PREFIX(prefix, name, parent) \
64 do { \
65 entry = debugfs_create_file(#name, 0400, parent, \
66 wl, &prefix## _## name## _ops); \
67 if (!entry || IS_ERR(entry)) \
68 goto err; \
69 } while (0);
70
71#define DEBUGFS_FWSTATS_FILE(sub, name, fmt, struct_type) \
72static ssize_t sub## _ ##name## _read(struct file *file, \
73 char __user *userbuf, \
74 size_t count, loff_t *ppos) \
75{ \
76 struct wl1271 *wl = file->private_data; \
77 struct struct_type *stats = wl->stats.fw_stats; \
78 \
79 wl1271_debugfs_update_stats(wl); \
80 \
81 return wl1271_format_buffer(userbuf, count, ppos, fmt "\n", \
82 stats->sub.name); \
83} \
84 \
85static const struct file_operations sub## _ ##name## _ops = { \
86 .read = sub## _ ##name## _read, \
87 .open = simple_open, \
88 .llseek = generic_file_llseek, \
89};
90
91#define DEBUGFS_FWSTATS_FILE_ARRAY(sub, name, len, struct_type) \
92static ssize_t sub## _ ##name## _read(struct file *file, \
93 char __user *userbuf, \
94 size_t count, loff_t *ppos) \
95{ \
96 struct wl1271 *wl = file->private_data; \
97 struct struct_type *stats = wl->stats.fw_stats; \
98 char buf[DEBUGFS_FORMAT_BUFFER_SIZE] = ""; \
99 int res, i; \
100 \
101 wl1271_debugfs_update_stats(wl); \
102 \
103 for (i = 0; i < len; i++) \
104 res = snprintf(buf, sizeof(buf), "%s[%d] = %d\n", \
105 buf, i, stats->sub.name[i]); \
106 \
107 return wl1271_format_buffer(userbuf, count, ppos, "%s", buf); \
108} \
109 \
110static const struct file_operations sub## _ ##name## _ops = { \
111 .read = sub## _ ##name## _read, \
112 .open = simple_open, \
113 .llseek = generic_file_llseek, \
114};
115
116#define DEBUGFS_FWSTATS_ADD(sub, name) \
117 DEBUGFS_ADD(sub## _ ##name, stats)
118
32 119
33#endif /* WL1271_DEBUGFS_H */ 120#endif /* WL1271_DEBUGFS_H */
diff --git a/drivers/net/wireless/ti/wlcore/event.c b/drivers/net/wireless/ti/wlcore/event.c
index 28e2a633c3be..c976f0409865 100644
--- a/drivers/net/wireless/ti/wlcore/event.c
+++ b/drivers/net/wireless/ti/wlcore/event.c
@@ -148,15 +148,33 @@ static int wl1271_event_process(struct wl1271 *wl)
148 int delay = wl->conf.conn.synch_fail_thold * 148 int delay = wl->conf.conn.synch_fail_thold *
149 wl->conf.conn.bss_lose_timeout; 149 wl->conf.conn.bss_lose_timeout;
150 wl1271_info("Beacon loss detected."); 150 wl1271_info("Beacon loss detected.");
151 cancel_delayed_work_sync(&wl->connection_loss_work); 151
152 /*
153 * if the work is already queued, it should take place. We
154 * don't want to delay the connection loss indication
155 * any more.
156 */
152 ieee80211_queue_delayed_work(wl->hw, &wl->connection_loss_work, 157 ieee80211_queue_delayed_work(wl->hw, &wl->connection_loss_work,
153 msecs_to_jiffies(delay)); 158 msecs_to_jiffies(delay));
159
160 wl12xx_for_each_wlvif_sta(wl, wlvif) {
161 vif = wl12xx_wlvif_to_vif(wlvif);
162
163 ieee80211_cqm_rssi_notify(
164 vif,
165 NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
166 GFP_KERNEL);
167 }
154 } 168 }
155 169
156 if (vector & REGAINED_BSS_EVENT_ID) { 170 if (vector & REGAINED_BSS_EVENT_ID) {
157 /* TODO: check for multi-role */ 171 /* TODO: check for multi-role */
158 wl1271_info("Beacon regained."); 172 wl1271_info("Beacon regained.");
159 cancel_delayed_work_sync(&wl->connection_loss_work); 173 cancel_delayed_work(&wl->connection_loss_work);
174
175 /* sanity check - we can't lose and gain the beacon together */
176 WARN(vector & BSS_LOSE_EVENT_ID,
177 "Concurrent beacon loss and gain from FW");
160 } 178 }
161 179
162 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) { 180 if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
diff --git a/drivers/net/wireless/ti/wlcore/hw_ops.h b/drivers/net/wireless/ti/wlcore/hw_ops.h
index 9384b4d56c24..9e7787ba9610 100644
--- a/drivers/net/wireless/ti/wlcore/hw_ops.h
+++ b/drivers/net/wireless/ti/wlcore/hw_ops.h
@@ -119,4 +119,82 @@ static inline int wlcore_identify_fw(struct wl1271 *wl)
119 return 0; 119 return 0;
120} 120}
121 121
122static inline void
123wlcore_hw_set_tx_desc_csum(struct wl1271 *wl,
124 struct wl1271_tx_hw_descr *desc,
125 struct sk_buff *skb)
126{
127 if (!wl->ops->set_tx_desc_csum)
128 BUG_ON(1);
129
130 wl->ops->set_tx_desc_csum(wl, desc, skb);
131}
132
133static inline void
134wlcore_hw_set_rx_csum(struct wl1271 *wl,
135 struct wl1271_rx_descriptor *desc,
136 struct sk_buff *skb)
137{
138 if (wl->ops->set_rx_csum)
139 wl->ops->set_rx_csum(wl, desc, skb);
140}
141
142static inline u32
143wlcore_hw_ap_get_mimo_wide_rate_mask(struct wl1271 *wl,
144 struct wl12xx_vif *wlvif)
145{
146 if (wl->ops->ap_get_mimo_wide_rate_mask)
147 return wl->ops->ap_get_mimo_wide_rate_mask(wl, wlvif);
148
149 return 0;
150}
151
152static inline int
153wlcore_debugfs_init(struct wl1271 *wl, struct dentry *rootdir)
154{
155 if (wl->ops->debugfs_init)
156 return wl->ops->debugfs_init(wl, rootdir);
157
158 return 0;
159}
160
161static inline int
162wlcore_handle_static_data(struct wl1271 *wl, void *static_data)
163{
164 if (wl->ops->handle_static_data)
165 return wl->ops->handle_static_data(wl, static_data);
166
167 return 0;
168}
169
170static inline int
171wlcore_hw_get_spare_blocks(struct wl1271 *wl, bool is_gem)
172{
173 if (!wl->ops->get_spare_blocks)
174 BUG_ON(1);
175
176 return wl->ops->get_spare_blocks(wl, is_gem);
177}
178
179static inline int
180wlcore_hw_set_key(struct wl1271 *wl, enum set_key_cmd cmd,
181 struct ieee80211_vif *vif,
182 struct ieee80211_sta *sta,
183 struct ieee80211_key_conf *key_conf)
184{
185 if (!wl->ops->set_key)
186 BUG_ON(1);
187
188 return wl->ops->set_key(wl, cmd, vif, sta, key_conf);
189}
190
191static inline u32
192wlcore_hw_pre_pkt_send(struct wl1271 *wl, u32 buf_offset, u32 last_len)
193{
194 if (wl->ops->pre_pkt_send)
195 return wl->ops->pre_pkt_send(wl, buf_offset, last_len);
196
197 return buf_offset;
198}
199
122#endif 200#endif
diff --git a/drivers/net/wireless/ti/wlcore/init.c b/drivers/net/wireless/ti/wlcore/init.c
index 9f89255eb6e6..645abd4b660d 100644
--- a/drivers/net/wireless/ti/wlcore/init.c
+++ b/drivers/net/wireless/ti/wlcore/init.c
@@ -460,6 +460,9 @@ int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
460 /* unconditionally enable HT rates */ 460 /* unconditionally enable HT rates */
461 supported_rates |= CONF_TX_MCS_RATES; 461 supported_rates |= CONF_TX_MCS_RATES;
462 462
463 /* get extra MIMO or wide-chan rates where the HW supports it */
464 supported_rates |= wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
465
463 /* configure unicast TX rate classes */ 466 /* configure unicast TX rate classes */
464 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) { 467 for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
465 rc.enabled_rates = supported_rates; 468 rc.enabled_rates = supported_rates;
diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
index acef93390d3d..1156e3f578c1 100644
--- a/drivers/net/wireless/ti/wlcore/main.c
+++ b/drivers/net/wireless/ti/wlcore/main.c
@@ -320,46 +320,6 @@ static void wlcore_adjust_conf(struct wl1271 *wl)
320 } 320 }
321} 321}
322 322
323static int wl1271_plt_init(struct wl1271 *wl)
324{
325 int ret;
326
327 ret = wl->ops->hw_init(wl);
328 if (ret < 0)
329 return ret;
330
331 ret = wl1271_acx_init_mem_config(wl);
332 if (ret < 0)
333 return ret;
334
335 ret = wl12xx_acx_mem_cfg(wl);
336 if (ret < 0)
337 goto out_free_memmap;
338
339 /* Enable data path */
340 ret = wl1271_cmd_data_path(wl, 1);
341 if (ret < 0)
342 goto out_free_memmap;
343
344 /* Configure for CAM power saving (ie. always active) */
345 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
346 if (ret < 0)
347 goto out_free_memmap;
348
349 /* configure PM */
350 ret = wl1271_acx_pm_config(wl);
351 if (ret < 0)
352 goto out_free_memmap;
353
354 return 0;
355
356 out_free_memmap:
357 kfree(wl->target_mem_map);
358 wl->target_mem_map = NULL;
359
360 return ret;
361}
362
363static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl, 323static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
364 struct wl12xx_vif *wlvif, 324 struct wl12xx_vif *wlvif,
365 u8 hlid, u8 tx_pkts) 325 u8 hlid, u8 tx_pkts)
@@ -387,7 +347,7 @@ static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
387 347
388static void wl12xx_irq_update_links_status(struct wl1271 *wl, 348static void wl12xx_irq_update_links_status(struct wl1271 *wl,
389 struct wl12xx_vif *wlvif, 349 struct wl12xx_vif *wlvif,
390 struct wl_fw_status *status) 350 struct wl_fw_status_2 *status)
391{ 351{
392 struct wl1271_link *lnk; 352 struct wl1271_link *lnk;
393 u32 cur_fw_ps_map; 353 u32 cur_fw_ps_map;
@@ -419,7 +379,8 @@ static void wl12xx_irq_update_links_status(struct wl1271 *wl,
419} 379}
420 380
421static void wl12xx_fw_status(struct wl1271 *wl, 381static void wl12xx_fw_status(struct wl1271 *wl,
422 struct wl_fw_status *status) 382 struct wl_fw_status_1 *status_1,
383 struct wl_fw_status_2 *status_2)
423{ 384{
424 struct wl12xx_vif *wlvif; 385 struct wl12xx_vif *wlvif;
425 struct timespec ts; 386 struct timespec ts;
@@ -428,37 +389,38 @@ static void wl12xx_fw_status(struct wl1271 *wl,
428 int i; 389 int i;
429 size_t status_len; 390 size_t status_len;
430 391
431 status_len = sizeof(*status) + wl->fw_status_priv_len; 392 status_len = WLCORE_FW_STATUS_1_LEN(wl->num_rx_desc) +
393 sizeof(*status_2) + wl->fw_status_priv_len;
432 394
433 wlcore_raw_read_data(wl, REG_RAW_FW_STATUS_ADDR, status, 395 wlcore_raw_read_data(wl, REG_RAW_FW_STATUS_ADDR, status_1,
434 status_len, false); 396 status_len, false);
435 397
436 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, " 398 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
437 "drv_rx_counter = %d, tx_results_counter = %d)", 399 "drv_rx_counter = %d, tx_results_counter = %d)",
438 status->intr, 400 status_1->intr,
439 status->fw_rx_counter, 401 status_1->fw_rx_counter,
440 status->drv_rx_counter, 402 status_1->drv_rx_counter,
441 status->tx_results_counter); 403 status_1->tx_results_counter);
442 404
443 for (i = 0; i < NUM_TX_QUEUES; i++) { 405 for (i = 0; i < NUM_TX_QUEUES; i++) {
444 /* prevent wrap-around in freed-packets counter */ 406 /* prevent wrap-around in freed-packets counter */
445 wl->tx_allocated_pkts[i] -= 407 wl->tx_allocated_pkts[i] -=
446 (status->counters.tx_released_pkts[i] - 408 (status_2->counters.tx_released_pkts[i] -
447 wl->tx_pkts_freed[i]) & 0xff; 409 wl->tx_pkts_freed[i]) & 0xff;
448 410
449 wl->tx_pkts_freed[i] = status->counters.tx_released_pkts[i]; 411 wl->tx_pkts_freed[i] = status_2->counters.tx_released_pkts[i];
450 } 412 }
451 413
452 /* prevent wrap-around in total blocks counter */ 414 /* prevent wrap-around in total blocks counter */
453 if (likely(wl->tx_blocks_freed <= 415 if (likely(wl->tx_blocks_freed <=
454 le32_to_cpu(status->total_released_blks))) 416 le32_to_cpu(status_2->total_released_blks)))
455 freed_blocks = le32_to_cpu(status->total_released_blks) - 417 freed_blocks = le32_to_cpu(status_2->total_released_blks) -
456 wl->tx_blocks_freed; 418 wl->tx_blocks_freed;
457 else 419 else
458 freed_blocks = 0x100000000LL - wl->tx_blocks_freed + 420 freed_blocks = 0x100000000LL - wl->tx_blocks_freed +
459 le32_to_cpu(status->total_released_blks); 421 le32_to_cpu(status_2->total_released_blks);
460 422
461 wl->tx_blocks_freed = le32_to_cpu(status->total_released_blks); 423 wl->tx_blocks_freed = le32_to_cpu(status_2->total_released_blks);
462 424
463 wl->tx_allocated_blocks -= freed_blocks; 425 wl->tx_allocated_blocks -= freed_blocks;
464 426
@@ -474,7 +436,7 @@ static void wl12xx_fw_status(struct wl1271 *wl,
474 cancel_delayed_work(&wl->tx_watchdog_work); 436 cancel_delayed_work(&wl->tx_watchdog_work);
475 } 437 }
476 438
477 avail = le32_to_cpu(status->tx_total) - wl->tx_allocated_blocks; 439 avail = le32_to_cpu(status_2->tx_total) - wl->tx_allocated_blocks;
478 440
479 /* 441 /*
480 * The FW might change the total number of TX memblocks before 442 * The FW might change the total number of TX memblocks before
@@ -493,13 +455,13 @@ static void wl12xx_fw_status(struct wl1271 *wl,
493 455
494 /* for AP update num of allocated TX blocks per link and ps status */ 456 /* for AP update num of allocated TX blocks per link and ps status */
495 wl12xx_for_each_wlvif_ap(wl, wlvif) { 457 wl12xx_for_each_wlvif_ap(wl, wlvif) {
496 wl12xx_irq_update_links_status(wl, wlvif, status); 458 wl12xx_irq_update_links_status(wl, wlvif, status_2);
497 } 459 }
498 460
499 /* update the host-chipset time offset */ 461 /* update the host-chipset time offset */
500 getnstimeofday(&ts); 462 getnstimeofday(&ts);
501 wl->time_offset = (timespec_to_ns(&ts) >> 10) - 463 wl->time_offset = (timespec_to_ns(&ts) >> 10) -
502 (s64)le32_to_cpu(status->fw_localtime); 464 (s64)le32_to_cpu(status_2->fw_localtime);
503} 465}
504 466
505static void wl1271_flush_deferred_work(struct wl1271 *wl) 467static void wl1271_flush_deferred_work(struct wl1271 *wl)
@@ -568,20 +530,30 @@ static irqreturn_t wl1271_irq(int irq, void *cookie)
568 clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags); 530 clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
569 smp_mb__after_clear_bit(); 531 smp_mb__after_clear_bit();
570 532
571 wl12xx_fw_status(wl, wl->fw_status); 533 wl12xx_fw_status(wl, wl->fw_status_1, wl->fw_status_2);
572 534
573 wlcore_hw_tx_immediate_compl(wl); 535 wlcore_hw_tx_immediate_compl(wl);
574 536
575 intr = le32_to_cpu(wl->fw_status->intr); 537 intr = le32_to_cpu(wl->fw_status_1->intr);
576 intr &= WL1271_INTR_MASK; 538 intr &= WLCORE_ALL_INTR_MASK;
577 if (!intr) { 539 if (!intr) {
578 done = true; 540 done = true;
579 continue; 541 continue;
580 } 542 }
581 543
582 if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) { 544 if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
583 wl1271_error("watchdog interrupt received! " 545 wl1271_error("HW watchdog interrupt received! starting recovery.");
546 wl->watchdog_recovery = true;
547 wl12xx_queue_recovery_work(wl);
548
549 /* restarting the chip. ignore any other interrupt. */
550 goto out;
551 }
552
553 if (unlikely(intr & WL1271_ACX_SW_INTR_WATCHDOG)) {
554 wl1271_error("SW watchdog interrupt received! "
584 "starting recovery."); 555 "starting recovery.");
556 wl->watchdog_recovery = true;
585 wl12xx_queue_recovery_work(wl); 557 wl12xx_queue_recovery_work(wl);
586 558
587 /* restarting the chip. ignore any other interrupt. */ 559 /* restarting the chip. ignore any other interrupt. */
@@ -591,7 +563,7 @@ static irqreturn_t wl1271_irq(int irq, void *cookie)
591 if (likely(intr & WL1271_ACX_INTR_DATA)) { 563 if (likely(intr & WL1271_ACX_INTR_DATA)) {
592 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA"); 564 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
593 565
594 wl12xx_rx(wl, wl->fw_status); 566 wl12xx_rx(wl, wl->fw_status_1);
595 567
596 /* Check if any tx blocks were freed */ 568 /* Check if any tx blocks were freed */
597 spin_lock_irqsave(&wl->wl_lock, flags); 569 spin_lock_irqsave(&wl->wl_lock, flags);
@@ -743,7 +715,7 @@ out:
743 return ret; 715 return ret;
744} 716}
745 717
746static int wl1271_fetch_nvs(struct wl1271 *wl) 718static void wl1271_fetch_nvs(struct wl1271 *wl)
747{ 719{
748 const struct firmware *fw; 720 const struct firmware *fw;
749 int ret; 721 int ret;
@@ -751,16 +723,15 @@ static int wl1271_fetch_nvs(struct wl1271 *wl)
751 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev); 723 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev);
752 724
753 if (ret < 0) { 725 if (ret < 0) {
754 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME, 726 wl1271_debug(DEBUG_BOOT, "could not get nvs file %s: %d",
755 ret); 727 WL12XX_NVS_NAME, ret);
756 return ret; 728 return;
757 } 729 }
758 730
759 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL); 731 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
760 732
761 if (!wl->nvs) { 733 if (!wl->nvs) {
762 wl1271_error("could not allocate memory for the nvs file"); 734 wl1271_error("could not allocate memory for the nvs file");
763 ret = -ENOMEM;
764 goto out; 735 goto out;
765 } 736 }
766 737
@@ -768,8 +739,6 @@ static int wl1271_fetch_nvs(struct wl1271 *wl)
768 739
769out: 740out:
770 release_firmware(fw); 741 release_firmware(fw);
771
772 return ret;
773} 742}
774 743
775void wl12xx_queue_recovery_work(struct wl1271 *wl) 744void wl12xx_queue_recovery_work(struct wl1271 *wl)
@@ -820,14 +789,16 @@ static void wl12xx_read_fwlog_panic(struct wl1271 *wl)
820 789
821 /* 790 /*
822 * Make sure the chip is awake and the logger isn't active. 791 * Make sure the chip is awake and the logger isn't active.
823 * This might fail if the firmware hanged. 792 * Do not send a stop fwlog command if the fw is hanged.
824 */ 793 */
825 if (!wl1271_ps_elp_wakeup(wl)) 794 if (!wl1271_ps_elp_wakeup(wl) && !wl->watchdog_recovery)
826 wl12xx_cmd_stop_fwlog(wl); 795 wl12xx_cmd_stop_fwlog(wl);
796 else
797 goto out;
827 798
828 /* Read the first memory block address */ 799 /* Read the first memory block address */
829 wl12xx_fw_status(wl, wl->fw_status); 800 wl12xx_fw_status(wl, wl->fw_status_1, wl->fw_status_2);
830 first_addr = le32_to_cpu(wl->fw_status->log_start_addr); 801 first_addr = le32_to_cpu(wl->fw_status_2->log_start_addr);
831 if (!first_addr) 802 if (!first_addr)
832 goto out; 803 goto out;
833 804
@@ -872,9 +843,14 @@ static void wl1271_recovery_work(struct work_struct *work)
872 843
873 wl12xx_read_fwlog_panic(wl); 844 wl12xx_read_fwlog_panic(wl);
874 845
875 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x", 846 /* change partitions momentarily so we can read the FW pc */
847 wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
848 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x "
849 "hint_sts: 0x%08x",
876 wl->chip.fw_ver_str, 850 wl->chip.fw_ver_str,
877 wlcore_read_reg(wl, REG_PC_ON_RECOVERY)); 851 wlcore_read_reg(wl, REG_PC_ON_RECOVERY),
852 wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR));
853 wlcore_set_partition(wl, &wl->ptable[PART_WORK]);
878 854
879 BUG_ON(bug_on_recovery && 855 BUG_ON(bug_on_recovery &&
880 !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags)); 856 !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags));
@@ -885,8 +861,6 @@ static void wl1271_recovery_work(struct work_struct *work)
885 goto out_unlock; 861 goto out_unlock;
886 } 862 }
887 863
888 BUG_ON(bug_on_recovery);
889
890 /* 864 /*
891 * Advance security sequence number to overcome potential progress 865 * Advance security sequence number to overcome potential progress
892 * in the firmware during recovery. This doens't hurt if the network is 866 * in the firmware during recovery. This doens't hurt if the network is
@@ -900,7 +874,7 @@ static void wl1271_recovery_work(struct work_struct *work)
900 } 874 }
901 875
902 /* Prevent spurious TX during FW restart */ 876 /* Prevent spurious TX during FW restart */
903 ieee80211_stop_queues(wl->hw); 877 wlcore_stop_queues(wl, WLCORE_QUEUE_STOP_REASON_FW_RESTART);
904 878
905 if (wl->sched_scanning) { 879 if (wl->sched_scanning) {
906 ieee80211_sched_scan_stopped(wl->hw); 880 ieee80211_sched_scan_stopped(wl->hw);
@@ -914,6 +888,7 @@ static void wl1271_recovery_work(struct work_struct *work)
914 vif = wl12xx_wlvif_to_vif(wlvif); 888 vif = wl12xx_wlvif_to_vif(wlvif);
915 __wl1271_op_remove_interface(wl, vif, false); 889 __wl1271_op_remove_interface(wl, vif, false);
916 } 890 }
891 wl->watchdog_recovery = false;
917 mutex_unlock(&wl->mutex); 892 mutex_unlock(&wl->mutex);
918 wl1271_op_stop(wl->hw); 893 wl1271_op_stop(wl->hw);
919 894
@@ -925,9 +900,10 @@ static void wl1271_recovery_work(struct work_struct *work)
925 * Its safe to enable TX now - the queues are stopped after a request 900 * Its safe to enable TX now - the queues are stopped after a request
926 * to restart the HW. 901 * to restart the HW.
927 */ 902 */
928 ieee80211_wake_queues(wl->hw); 903 wlcore_wake_queues(wl, WLCORE_QUEUE_STOP_REASON_FW_RESTART);
929 return; 904 return;
930out_unlock: 905out_unlock:
906 wl->watchdog_recovery = false;
931 mutex_unlock(&wl->mutex); 907 mutex_unlock(&wl->mutex);
932} 908}
933 909
@@ -938,13 +914,19 @@ static void wl1271_fw_wakeup(struct wl1271 *wl)
938 914
939static int wl1271_setup(struct wl1271 *wl) 915static int wl1271_setup(struct wl1271 *wl)
940{ 916{
941 wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL); 917 wl->fw_status_1 = kmalloc(WLCORE_FW_STATUS_1_LEN(wl->num_rx_desc) +
942 if (!wl->fw_status) 918 sizeof(*wl->fw_status_2) +
919 wl->fw_status_priv_len, GFP_KERNEL);
920 if (!wl->fw_status_1)
943 return -ENOMEM; 921 return -ENOMEM;
944 922
923 wl->fw_status_2 = (struct wl_fw_status_2 *)
924 (((u8 *) wl->fw_status_1) +
925 WLCORE_FW_STATUS_1_LEN(wl->num_rx_desc));
926
945 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL); 927 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
946 if (!wl->tx_res_if) { 928 if (!wl->tx_res_if) {
947 kfree(wl->fw_status); 929 kfree(wl->fw_status_1);
948 return -ENOMEM; 930 return -ENOMEM;
949 } 931 }
950 932
@@ -987,13 +969,12 @@ static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt)
987 * simplify the code and since the performance impact is 969 * simplify the code and since the performance impact is
988 * negligible, we use the same block size for all different 970 * negligible, we use the same block size for all different
989 * chip types. 971 * chip types.
972 *
973 * Check if the bus supports blocksize alignment and, if it
974 * doesn't, make sure we don't have the quirk.
990 */ 975 */
991 if (wl1271_set_block_size(wl)) 976 if (!wl1271_set_block_size(wl))
992 wl->quirks |= WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN; 977 wl->quirks &= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN;
993
994 ret = wl->ops->identify_chip(wl);
995 if (ret < 0)
996 goto out;
997 978
998 /* TODO: make sure the lower driver has set things up correctly */ 979 /* TODO: make sure the lower driver has set things up correctly */
999 980
@@ -1005,13 +986,6 @@ static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt)
1005 if (ret < 0) 986 if (ret < 0)
1006 goto out; 987 goto out;
1007 988
1008 /* No NVS from netlink, try to get it from the filesystem */
1009 if (wl->nvs == NULL) {
1010 ret = wl1271_fetch_nvs(wl);
1011 if (ret < 0)
1012 goto out;
1013 }
1014
1015out: 989out:
1016 return ret; 990 return ret;
1017} 991}
@@ -1039,14 +1013,10 @@ int wl1271_plt_start(struct wl1271 *wl)
1039 if (ret < 0) 1013 if (ret < 0)
1040 goto power_off; 1014 goto power_off;
1041 1015
1042 ret = wl->ops->boot(wl); 1016 ret = wl->ops->plt_init(wl);
1043 if (ret < 0) 1017 if (ret < 0)
1044 goto power_off; 1018 goto power_off;
1045 1019
1046 ret = wl1271_plt_init(wl);
1047 if (ret < 0)
1048 goto irq_disable;
1049
1050 wl->plt = true; 1020 wl->plt = true;
1051 wl->state = WL1271_STATE_ON; 1021 wl->state = WL1271_STATE_ON;
1052 wl1271_notice("firmware booted in PLT mode (%s)", 1022 wl1271_notice("firmware booted in PLT mode (%s)",
@@ -1059,19 +1029,6 @@ int wl1271_plt_start(struct wl1271 *wl)
1059 1029
1060 goto out; 1030 goto out;
1061 1031
1062irq_disable:
1063 mutex_unlock(&wl->mutex);
1064 /* Unlocking the mutex in the middle of handling is
1065 inherently unsafe. In this case we deem it safe to do,
1066 because we need to let any possibly pending IRQ out of
1067 the system (and while we are WL1271_STATE_OFF the IRQ
1068 work function will not do anything.) Also, any other
1069 possible concurrent operations will fail due to the
1070 current state, hence the wl1271 struct should be safe. */
1071 wlcore_disable_interrupts(wl);
1072 wl1271_flush_deferred_work(wl);
1073 cancel_work_sync(&wl->netstack_work);
1074 mutex_lock(&wl->mutex);
1075power_off: 1032power_off:
1076 wl1271_power_off(wl); 1033 wl1271_power_off(wl);
1077 } 1034 }
@@ -1154,9 +1111,16 @@ static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1154 1111
1155 spin_lock_irqsave(&wl->wl_lock, flags); 1112 spin_lock_irqsave(&wl->wl_lock, flags);
1156 1113
1157 /* queue the packet */ 1114 /*
1115 * drop the packet if the link is invalid or the queue is stopped
1116 * for any reason but watermark. Watermark is a "soft"-stop so we
1117 * allow these packets through.
1118 */
1158 if (hlid == WL12XX_INVALID_LINK_ID || 1119 if (hlid == WL12XX_INVALID_LINK_ID ||
1159 (wlvif && !test_bit(hlid, wlvif->links_map))) { 1120 (wlvif && !test_bit(hlid, wlvif->links_map)) ||
1121 (wlcore_is_queue_stopped(wl, q) &&
1122 !wlcore_is_queue_stopped_by_reason(wl, q,
1123 WLCORE_QUEUE_STOP_REASON_WATERMARK))) {
1160 wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q); 1124 wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q);
1161 ieee80211_free_txskb(hw, skb); 1125 ieee80211_free_txskb(hw, skb);
1162 goto out; 1126 goto out;
@@ -1174,8 +1138,8 @@ static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1174 */ 1138 */
1175 if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) { 1139 if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
1176 wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q); 1140 wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q);
1177 ieee80211_stop_queue(wl->hw, mapping); 1141 wlcore_stop_queue_locked(wl, q,
1178 set_bit(q, &wl->stopped_queues_map); 1142 WLCORE_QUEUE_STOP_REASON_WATERMARK);
1179 } 1143 }
1180 1144
1181 /* 1145 /*
@@ -1758,7 +1722,7 @@ static void wl1271_op_stop(struct ieee80211_hw *hw)
1758 cancel_delayed_work_sync(&wl->connection_loss_work); 1722 cancel_delayed_work_sync(&wl->connection_loss_work);
1759 1723
1760 /* let's notify MAC80211 about the remaining pending TX frames */ 1724 /* let's notify MAC80211 about the remaining pending TX frames */
1761 wl12xx_tx_reset(wl, true); 1725 wl12xx_tx_reset(wl);
1762 mutex_lock(&wl->mutex); 1726 mutex_lock(&wl->mutex);
1763 1727
1764 wl1271_power_off(wl); 1728 wl1271_power_off(wl);
@@ -1767,6 +1731,7 @@ static void wl1271_op_stop(struct ieee80211_hw *hw)
1767 1731
1768 wl->rx_counter = 0; 1732 wl->rx_counter = 0;
1769 wl->power_level = WL1271_DEFAULT_POWER_LEVEL; 1733 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1734 wl->channel_type = NL80211_CHAN_NO_HT;
1770 wl->tx_blocks_available = 0; 1735 wl->tx_blocks_available = 0;
1771 wl->tx_allocated_blocks = 0; 1736 wl->tx_allocated_blocks = 0;
1772 wl->tx_results_count = 0; 1737 wl->tx_results_count = 0;
@@ -1799,8 +1764,9 @@ static void wl1271_op_stop(struct ieee80211_hw *hw)
1799 1764
1800 wl1271_debugfs_reset(wl); 1765 wl1271_debugfs_reset(wl);
1801 1766
1802 kfree(wl->fw_status); 1767 kfree(wl->fw_status_1);
1803 wl->fw_status = NULL; 1768 wl->fw_status_1 = NULL;
1769 wl->fw_status_2 = NULL;
1804 kfree(wl->tx_res_if); 1770 kfree(wl->tx_res_if);
1805 wl->tx_res_if = NULL; 1771 wl->tx_res_if = NULL;
1806 kfree(wl->target_mem_map); 1772 kfree(wl->target_mem_map);
@@ -1894,6 +1860,9 @@ static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1894 wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx); 1860 wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx);
1895 wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx); 1861 wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx);
1896 wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx); 1862 wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
1863 wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
1864 wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
1865 wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
1897 } else { 1866 } else {
1898 /* init ap data */ 1867 /* init ap data */
1899 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID; 1868 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
@@ -1903,13 +1872,19 @@ static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1903 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++) 1872 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
1904 wl12xx_allocate_rate_policy(wl, 1873 wl12xx_allocate_rate_policy(wl,
1905 &wlvif->ap.ucast_rate_idx[i]); 1874 &wlvif->ap.ucast_rate_idx[i]);
1875 wlvif->basic_rate_set = CONF_TX_AP_ENABLED_RATES;
1876 /*
1877 * TODO: check if basic_rate shouldn't be
1878 * wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
1879 * instead (the same thing for STA above).
1880 */
1881 wlvif->basic_rate = CONF_TX_AP_ENABLED_RATES;
1882 /* TODO: this seems to be used only for STA, check it */
1883 wlvif->rate_set = CONF_TX_AP_ENABLED_RATES;
1906 } 1884 }
1907 1885
1908 wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate; 1886 wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
1909 wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5; 1887 wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
1910 wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
1911 wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
1912 wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
1913 wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT; 1888 wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT;
1914 1889
1915 /* 1890 /*
@@ -1919,6 +1894,7 @@ static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1919 wlvif->band = wl->band; 1894 wlvif->band = wl->band;
1920 wlvif->channel = wl->channel; 1895 wlvif->channel = wl->channel;
1921 wlvif->power_level = wl->power_level; 1896 wlvif->power_level = wl->power_level;
1897 wlvif->channel_type = wl->channel_type;
1922 1898
1923 INIT_WORK(&wlvif->rx_streaming_enable_work, 1899 INIT_WORK(&wlvif->rx_streaming_enable_work,
1924 wl1271_rx_streaming_enable_work); 1900 wl1271_rx_streaming_enable_work);
@@ -2444,7 +2420,7 @@ static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2444 } else { 2420 } else {
2445 /* The current firmware only supports sched_scan in idle */ 2421 /* The current firmware only supports sched_scan in idle */
2446 if (wl->sched_scanning) { 2422 if (wl->sched_scanning) {
2447 wl1271_scan_sched_scan_stop(wl); 2423 wl1271_scan_sched_scan_stop(wl, wlvif);
2448 ieee80211_sched_scan_stopped(wl->hw); 2424 ieee80211_sched_scan_stopped(wl->hw);
2449 } 2425 }
2450 2426
@@ -2469,13 +2445,20 @@ static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2469 /* if the channel changes while joined, join again */ 2445 /* if the channel changes while joined, join again */
2470 if (changed & IEEE80211_CONF_CHANGE_CHANNEL && 2446 if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
2471 ((wlvif->band != conf->channel->band) || 2447 ((wlvif->band != conf->channel->band) ||
2472 (wlvif->channel != channel))) { 2448 (wlvif->channel != channel) ||
2449 (wlvif->channel_type != conf->channel_type))) {
2473 /* send all pending packets */ 2450 /* send all pending packets */
2474 wl1271_tx_work_locked(wl); 2451 wl1271_tx_work_locked(wl);
2475 wlvif->band = conf->channel->band; 2452 wlvif->band = conf->channel->band;
2476 wlvif->channel = channel; 2453 wlvif->channel = channel;
2454 wlvif->channel_type = conf->channel_type;
2477 2455
2478 if (!is_ap) { 2456 if (is_ap) {
2457 ret = wl1271_init_ap_rates(wl, wlvif);
2458 if (ret < 0)
2459 wl1271_error("AP rate policy change failed %d",
2460 ret);
2461 } else {
2479 /* 2462 /*
2480 * FIXME: the mac80211 should really provide a fixed 2463 * FIXME: the mac80211 should really provide a fixed
2481 * rate to use here. for now, just use the smallest 2464 * rate to use here. for now, just use the smallest
@@ -2583,8 +2566,9 @@ static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2583 * frames, such as the deauth. To make sure those frames reach the air, 2566 * frames, such as the deauth. To make sure those frames reach the air,
2584 * wait here until the TX queue is fully flushed. 2567 * wait here until the TX queue is fully flushed.
2585 */ 2568 */
2586 if ((changed & IEEE80211_CONF_CHANGE_IDLE) && 2569 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
2587 (conf->flags & IEEE80211_CONF_IDLE)) 2570 ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
2571 (conf->flags & IEEE80211_CONF_IDLE)))
2588 wl1271_tx_flush(wl); 2572 wl1271_tx_flush(wl);
2589 2573
2590 mutex_lock(&wl->mutex); 2574 mutex_lock(&wl->mutex);
@@ -2593,6 +2577,7 @@ static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2593 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { 2577 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2594 wl->band = conf->channel->band; 2578 wl->band = conf->channel->band;
2595 wl->channel = channel; 2579 wl->channel = channel;
2580 wl->channel_type = conf->channel_type;
2596 } 2581 }
2597 2582
2598 if (changed & IEEE80211_CONF_CHANGE_POWER) 2583 if (changed & IEEE80211_CONF_CHANGE_POWER)
@@ -2825,17 +2810,6 @@ static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2825 int ret; 2810 int ret;
2826 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS); 2811 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2827 2812
2828 /*
2829 * A role set to GEM cipher requires different Tx settings (namely
2830 * spare blocks). Note when we are in this mode so the HW can adjust.
2831 */
2832 if (key_type == KEY_GEM) {
2833 if (action == KEY_ADD_OR_REPLACE)
2834 wlvif->is_gem = true;
2835 else if (action == KEY_REMOVE)
2836 wlvif->is_gem = false;
2837 }
2838
2839 if (is_ap) { 2813 if (is_ap) {
2840 struct wl1271_station *wl_sta; 2814 struct wl1271_station *wl_sta;
2841 u8 hlid; 2815 u8 hlid;
@@ -2913,12 +2887,21 @@ static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2913 return 0; 2887 return 0;
2914} 2888}
2915 2889
2916static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 2890static int wlcore_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2917 struct ieee80211_vif *vif, 2891 struct ieee80211_vif *vif,
2918 struct ieee80211_sta *sta, 2892 struct ieee80211_sta *sta,
2919 struct ieee80211_key_conf *key_conf) 2893 struct ieee80211_key_conf *key_conf)
2920{ 2894{
2921 struct wl1271 *wl = hw->priv; 2895 struct wl1271 *wl = hw->priv;
2896
2897 return wlcore_hw_set_key(wl, cmd, vif, sta, key_conf);
2898}
2899
2900int wlcore_set_key(struct wl1271 *wl, enum set_key_cmd cmd,
2901 struct ieee80211_vif *vif,
2902 struct ieee80211_sta *sta,
2903 struct ieee80211_key_conf *key_conf)
2904{
2922 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); 2905 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2923 int ret; 2906 int ret;
2924 u32 tx_seq_32 = 0; 2907 u32 tx_seq_32 = 0;
@@ -3029,6 +3012,7 @@ out_unlock:
3029 3012
3030 return ret; 3013 return ret;
3031} 3014}
3015EXPORT_SYMBOL_GPL(wlcore_set_key);
3032 3016
3033static int wl1271_op_hw_scan(struct ieee80211_hw *hw, 3017static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
3034 struct ieee80211_vif *vif, 3018 struct ieee80211_vif *vif,
@@ -3167,6 +3151,7 @@ static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
3167 struct ieee80211_vif *vif) 3151 struct ieee80211_vif *vif)
3168{ 3152{
3169 struct wl1271 *wl = hw->priv; 3153 struct wl1271 *wl = hw->priv;
3154 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3170 int ret; 3155 int ret;
3171 3156
3172 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop"); 3157 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
@@ -3180,7 +3165,7 @@ static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
3180 if (ret < 0) 3165 if (ret < 0)
3181 goto out; 3166 goto out;
3182 3167
3183 wl1271_scan_sched_scan_stop(wl); 3168 wl1271_scan_sched_scan_stop(wl, wlvif);
3184 3169
3185 wl1271_ps_elp_sleep(wl); 3170 wl1271_ps_elp_sleep(wl);
3186out: 3171out:
@@ -3316,8 +3301,15 @@ static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates,
3316 skb->data, 3301 skb->data,
3317 skb->len, 0, 3302 skb->len, 0,
3318 rates); 3303 rates);
3319
3320 dev_kfree_skb(skb); 3304 dev_kfree_skb(skb);
3305
3306 if (ret < 0)
3307 goto out;
3308
3309 wl1271_debug(DEBUG_AP, "probe response updated");
3310 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
3311
3312out:
3321 return ret; 3313 return ret;
3322} 3314}
3323 3315
@@ -3422,6 +3414,87 @@ out:
3422 return ret; 3414 return ret;
3423} 3415}
3424 3416
3417static int wlcore_set_beacon_template(struct wl1271 *wl,
3418 struct ieee80211_vif *vif,
3419 bool is_ap)
3420{
3421 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3422 struct ieee80211_hdr *hdr;
3423 u32 min_rate;
3424 int ret;
3425 int ieoffset = offsetof(struct ieee80211_mgmt,
3426 u.beacon.variable);
3427 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
3428 u16 tmpl_id;
3429
3430 if (!beacon) {
3431 ret = -EINVAL;
3432 goto out;
3433 }
3434
3435 wl1271_debug(DEBUG_MASTER, "beacon updated");
3436
3437 ret = wl1271_ssid_set(vif, beacon, ieoffset);
3438 if (ret < 0) {
3439 dev_kfree_skb(beacon);
3440 goto out;
3441 }
3442 min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
3443 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
3444 CMD_TEMPL_BEACON;
3445 ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id,
3446 beacon->data,
3447 beacon->len, 0,
3448 min_rate);
3449 if (ret < 0) {
3450 dev_kfree_skb(beacon);
3451 goto out;
3452 }
3453
3454 /*
3455 * In case we already have a probe-resp beacon set explicitly
3456 * by usermode, don't use the beacon data.
3457 */
3458 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
3459 goto end_bcn;
3460
3461 /* remove TIM ie from probe response */
3462 wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
3463
3464 /*
3465 * remove p2p ie from probe response.
3466 * the fw reponds to probe requests that don't include
3467 * the p2p ie. probe requests with p2p ie will be passed,
3468 * and will be responded by the supplicant (the spec
3469 * forbids including the p2p ie when responding to probe
3470 * requests that didn't include it).
3471 */
3472 wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA,
3473 WLAN_OUI_TYPE_WFA_P2P, ieoffset);
3474
3475 hdr = (struct ieee80211_hdr *) beacon->data;
3476 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3477 IEEE80211_STYPE_PROBE_RESP);
3478 if (is_ap)
3479 ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
3480 beacon->data,
3481 beacon->len,
3482 min_rate);
3483 else
3484 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
3485 CMD_TEMPL_PROBE_RESPONSE,
3486 beacon->data,
3487 beacon->len, 0,
3488 min_rate);
3489end_bcn:
3490 dev_kfree_skb(beacon);
3491 if (ret < 0)
3492 goto out;
3493
3494out:
3495 return ret;
3496}
3497
3425static int wl1271_bss_beacon_info_changed(struct wl1271 *wl, 3498static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3426 struct ieee80211_vif *vif, 3499 struct ieee80211_vif *vif,
3427 struct ieee80211_bss_conf *bss_conf, 3500 struct ieee80211_bss_conf *bss_conf,
@@ -3440,81 +3513,12 @@ static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3440 3513
3441 if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) { 3514 if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) {
3442 u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set); 3515 u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
3443 if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) { 3516
3444 wl1271_debug(DEBUG_AP, "probe response updated"); 3517 wl1271_ap_set_probe_resp_tmpl(wl, rate, vif);
3445 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
3446 }
3447 } 3518 }
3448 3519
3449 if ((changed & BSS_CHANGED_BEACON)) { 3520 if ((changed & BSS_CHANGED_BEACON)) {
3450 struct ieee80211_hdr *hdr; 3521 ret = wlcore_set_beacon_template(wl, vif, is_ap);
3451 u32 min_rate;
3452 int ieoffset = offsetof(struct ieee80211_mgmt,
3453 u.beacon.variable);
3454 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
3455 u16 tmpl_id;
3456
3457 if (!beacon) {
3458 ret = -EINVAL;
3459 goto out;
3460 }
3461
3462 wl1271_debug(DEBUG_MASTER, "beacon updated");
3463
3464 ret = wl1271_ssid_set(vif, beacon, ieoffset);
3465 if (ret < 0) {
3466 dev_kfree_skb(beacon);
3467 goto out;
3468 }
3469 min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
3470 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
3471 CMD_TEMPL_BEACON;
3472 ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id,
3473 beacon->data,
3474 beacon->len, 0,
3475 min_rate);
3476 if (ret < 0) {
3477 dev_kfree_skb(beacon);
3478 goto out;
3479 }
3480
3481 /*
3482 * In case we already have a probe-resp beacon set explicitly
3483 * by usermode, don't use the beacon data.
3484 */
3485 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
3486 goto end_bcn;
3487
3488 /* remove TIM ie from probe response */
3489 wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
3490
3491 /*
3492 * remove p2p ie from probe response.
3493 * the fw reponds to probe requests that don't include
3494 * the p2p ie. probe requests with p2p ie will be passed,
3495 * and will be responded by the supplicant (the spec
3496 * forbids including the p2p ie when responding to probe
3497 * requests that didn't include it).
3498 */
3499 wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA,
3500 WLAN_OUI_TYPE_WFA_P2P, ieoffset);
3501
3502 hdr = (struct ieee80211_hdr *) beacon->data;
3503 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3504 IEEE80211_STYPE_PROBE_RESP);
3505 if (is_ap)
3506 ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
3507 beacon->data,
3508 beacon->len,
3509 min_rate);
3510 else
3511 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
3512 CMD_TEMPL_PROBE_RESPONSE,
3513 beacon->data,
3514 beacon->len, 0,
3515 min_rate);
3516end_bcn:
3517 dev_kfree_skb(beacon);
3518 if (ret < 0) 3522 if (ret < 0)
3519 goto out; 3523 goto out;
3520 } 3524 }
@@ -3551,6 +3555,14 @@ static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
3551 ret = wl1271_ap_init_templates(wl, vif); 3555 ret = wl1271_ap_init_templates(wl, vif);
3552 if (ret < 0) 3556 if (ret < 0)
3553 goto out; 3557 goto out;
3558
3559 ret = wl1271_ap_set_probe_resp_tmpl(wl, wlvif->basic_rate, vif);
3560 if (ret < 0)
3561 goto out;
3562
3563 ret = wlcore_set_beacon_template(wl, vif, true);
3564 if (ret < 0)
3565 goto out;
3554 } 3566 }
3555 3567
3556 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed); 3568 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
@@ -3691,7 +3703,8 @@ static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3691 sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band]; 3703 sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
3692 if (sta->ht_cap.ht_supported) 3704 if (sta->ht_cap.ht_supported)
3693 sta_rate_set |= 3705 sta_rate_set |=
3694 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET); 3706 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET) |
3707 (sta->ht_cap.mcs.rx_mask[1] << HW_MIMO_RATES_OFFSET);
3695 sta_ht_cap = sta->ht_cap; 3708 sta_ht_cap = sta->ht_cap;
3696 sta_exists = true; 3709 sta_exists = true;
3697 3710
@@ -3704,13 +3717,11 @@ sta_not_found:
3704 u32 rates; 3717 u32 rates;
3705 int ieoffset; 3718 int ieoffset;
3706 wlvif->aid = bss_conf->aid; 3719 wlvif->aid = bss_conf->aid;
3720 wlvif->channel_type = bss_conf->channel_type;
3707 wlvif->beacon_int = bss_conf->beacon_int; 3721 wlvif->beacon_int = bss_conf->beacon_int;
3708 do_join = true; 3722 do_join = true;
3709 set_assoc = true; 3723 set_assoc = true;
3710 3724
3711 /* Cancel connection_loss_work */
3712 cancel_delayed_work_sync(&wl->connection_loss_work);
3713
3714 /* 3725 /*
3715 * use basic rates from AP, and determine lowest rate 3726 * use basic rates from AP, and determine lowest rate
3716 * to use with control frames. 3727 * to use with control frames.
@@ -3960,6 +3971,17 @@ static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
3960 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x", 3971 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
3961 (int)changed); 3972 (int)changed);
3962 3973
3974 /*
3975 * make sure to cancel pending disconnections if our association
3976 * state changed
3977 */
3978 if (!is_ap && (changed & BSS_CHANGED_ASSOC))
3979 cancel_delayed_work_sync(&wl->connection_loss_work);
3980
3981 if (is_ap && (changed & BSS_CHANGED_BEACON_ENABLED) &&
3982 !bss_conf->enable_beacon)
3983 wl1271_tx_flush(wl);
3984
3963 mutex_lock(&wl->mutex); 3985 mutex_lock(&wl->mutex);
3964 3986
3965 if (unlikely(wl->state == WL1271_STATE_OFF)) 3987 if (unlikely(wl->state == WL1271_STATE_OFF))
@@ -4636,7 +4658,7 @@ static const struct ieee80211_ops wl1271_ops = {
4636 .prepare_multicast = wl1271_op_prepare_multicast, 4658 .prepare_multicast = wl1271_op_prepare_multicast,
4637 .configure_filter = wl1271_op_configure_filter, 4659 .configure_filter = wl1271_op_configure_filter,
4638 .tx = wl1271_op_tx, 4660 .tx = wl1271_op_tx,
4639 .set_key = wl1271_op_set_key, 4661 .set_key = wlcore_op_set_key,
4640 .hw_scan = wl1271_op_hw_scan, 4662 .hw_scan = wl1271_op_hw_scan,
4641 .cancel_hw_scan = wl1271_op_cancel_hw_scan, 4663 .cancel_hw_scan = wl1271_op_cancel_hw_scan,
4642 .sched_scan_start = wl1271_op_sched_scan_start, 4664 .sched_scan_start = wl1271_op_sched_scan_start,
@@ -4905,14 +4927,8 @@ static int wl1271_register_hw(struct wl1271 *wl)
4905 if (wl->mac80211_registered) 4927 if (wl->mac80211_registered)
4906 return 0; 4928 return 0;
4907 4929
4908 ret = wl12xx_get_hw_info(wl); 4930 wl1271_fetch_nvs(wl);
4909 if (ret < 0) { 4931 if (wl->nvs != NULL) {
4910 wl1271_error("couldn't get hw info");
4911 goto out;
4912 }
4913
4914 ret = wl1271_fetch_nvs(wl);
4915 if (ret == 0) {
4916 /* NOTE: The wl->nvs->nvs element must be first, in 4932 /* NOTE: The wl->nvs->nvs element must be first, in
4917 * order to simplify the casting, we assume it is at 4933 * order to simplify the casting, we assume it is at
4918 * the beginning of the wl->nvs structure. 4934 * the beginning of the wl->nvs structure.
@@ -4970,9 +4986,11 @@ static int wl1271_init_ieee80211(struct wl1271 *wl)
4970 WL1271_CIPHER_SUITE_GEM, 4986 WL1271_CIPHER_SUITE_GEM,
4971 }; 4987 };
4972 4988
4973 /* The tx descriptor buffer and the TKIP space. */ 4989 /* The tx descriptor buffer */
4974 wl->hw->extra_tx_headroom = WL1271_EXTRA_SPACE_TKIP + 4990 wl->hw->extra_tx_headroom = sizeof(struct wl1271_tx_hw_descr);
4975 sizeof(struct wl1271_tx_hw_descr); 4991
4992 if (wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE)
4993 wl->hw->extra_tx_headroom += WL1271_EXTRA_SPACE_TKIP;
4976 4994
4977 /* unit us */ 4995 /* unit us */
4978 /* FIXME: find a proper value */ 4996 /* FIXME: find a proper value */
@@ -5025,12 +5043,14 @@ static int wl1271_init_ieee80211(struct wl1271 *wl)
5025 */ 5043 */
5026 memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz, 5044 memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
5027 sizeof(wl1271_band_2ghz)); 5045 sizeof(wl1271_band_2ghz));
5028 memcpy(&wl->bands[IEEE80211_BAND_2GHZ].ht_cap, &wl->ht_cap, 5046 memcpy(&wl->bands[IEEE80211_BAND_2GHZ].ht_cap,
5029 sizeof(wl->ht_cap)); 5047 &wl->ht_cap[IEEE80211_BAND_2GHZ],
5048 sizeof(*wl->ht_cap));
5030 memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz, 5049 memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
5031 sizeof(wl1271_band_5ghz)); 5050 sizeof(wl1271_band_5ghz));
5032 memcpy(&wl->bands[IEEE80211_BAND_5GHZ].ht_cap, &wl->ht_cap, 5051 memcpy(&wl->bands[IEEE80211_BAND_5GHZ].ht_cap,
5033 sizeof(wl->ht_cap)); 5052 &wl->ht_cap[IEEE80211_BAND_5GHZ],
5053 sizeof(*wl->ht_cap));
5034 5054
5035 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = 5055 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5036 &wl->bands[IEEE80211_BAND_2GHZ]; 5056 &wl->bands[IEEE80211_BAND_2GHZ];
@@ -5117,6 +5137,7 @@ struct ieee80211_hw *wlcore_alloc_hw(size_t priv_size)
5117 wl->rx_counter = 0; 5137 wl->rx_counter = 0;
5118 wl->power_level = WL1271_DEFAULT_POWER_LEVEL; 5138 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
5119 wl->band = IEEE80211_BAND_2GHZ; 5139 wl->band = IEEE80211_BAND_2GHZ;
5140 wl->channel_type = NL80211_CHAN_NO_HT;
5120 wl->flags = 0; 5141 wl->flags = 0;
5121 wl->sg_enabled = true; 5142 wl->sg_enabled = true;
5122 wl->hw_pg_ver = -1; 5143 wl->hw_pg_ver = -1;
@@ -5142,6 +5163,7 @@ struct ieee80211_hw *wlcore_alloc_hw(size_t priv_size)
5142 wl->state = WL1271_STATE_OFF; 5163 wl->state = WL1271_STATE_OFF;
5143 wl->fw_type = WL12XX_FW_TYPE_NONE; 5164 wl->fw_type = WL12XX_FW_TYPE_NONE;
5144 mutex_init(&wl->mutex); 5165 mutex_init(&wl->mutex);
5166 mutex_init(&wl->flush_mutex);
5145 5167
5146 order = get_order(WL1271_AGGR_BUFFER_SIZE); 5168 order = get_order(WL1271_AGGR_BUFFER_SIZE);
5147 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order); 5169 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
@@ -5222,7 +5244,7 @@ int wlcore_free_hw(struct wl1271 *wl)
5222 kfree(wl->nvs); 5244 kfree(wl->nvs);
5223 wl->nvs = NULL; 5245 wl->nvs = NULL;
5224 5246
5225 kfree(wl->fw_status); 5247 kfree(wl->fw_status_1);
5226 kfree(wl->tx_res_if); 5248 kfree(wl->tx_res_if);
5227 destroy_workqueue(wl->freezable_wq); 5249 destroy_workqueue(wl->freezable_wq);
5228 5250
@@ -5279,8 +5301,6 @@ int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev)
5279 wlcore_adjust_conf(wl); 5301 wlcore_adjust_conf(wl);
5280 5302
5281 wl->irq = platform_get_irq(pdev, 0); 5303 wl->irq = platform_get_irq(pdev, 0);
5282 wl->ref_clock = pdata->board_ref_clock;
5283 wl->tcxo_clock = pdata->board_tcxo_clock;
5284 wl->platform_quirks = pdata->platform_quirks; 5304 wl->platform_quirks = pdata->platform_quirks;
5285 wl->set_power = pdata->set_power; 5305 wl->set_power = pdata->set_power;
5286 wl->dev = &pdev->dev; 5306 wl->dev = &pdev->dev;
@@ -5316,6 +5336,16 @@ int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev)
5316 } 5336 }
5317 disable_irq(wl->irq); 5337 disable_irq(wl->irq);
5318 5338
5339 ret = wl12xx_get_hw_info(wl);
5340 if (ret < 0) {
5341 wl1271_error("couldn't get hw info");
5342 goto out;
5343 }
5344
5345 ret = wl->ops->identify_chip(wl);
5346 if (ret < 0)
5347 goto out;
5348
5319 ret = wl1271_init_ieee80211(wl); 5349 ret = wl1271_init_ieee80211(wl);
5320 if (ret) 5350 if (ret)
5321 goto out_irq; 5351 goto out_irq;
diff --git a/drivers/net/wireless/ti/wlcore/ps.c b/drivers/net/wireless/ti/wlcore/ps.c
index 756eee2257b4..47e81b32f7da 100644
--- a/drivers/net/wireless/ti/wlcore/ps.c
+++ b/drivers/net/wireless/ti/wlcore/ps.c
@@ -28,6 +28,8 @@
28 28
29#define WL1271_WAKEUP_TIMEOUT 500 29#define WL1271_WAKEUP_TIMEOUT 500
30 30
31#define ELP_ENTRY_DELAY 5
32
31void wl1271_elp_work(struct work_struct *work) 33void wl1271_elp_work(struct work_struct *work)
32{ 34{
33 struct delayed_work *dwork; 35 struct delayed_work *dwork;
@@ -72,6 +74,7 @@ out:
72void wl1271_ps_elp_sleep(struct wl1271 *wl) 74void wl1271_ps_elp_sleep(struct wl1271 *wl)
73{ 75{
74 struct wl12xx_vif *wlvif; 76 struct wl12xx_vif *wlvif;
77 u32 timeout;
75 78
76 if (wl->quirks & WLCORE_QUIRK_NO_ELP) 79 if (wl->quirks & WLCORE_QUIRK_NO_ELP)
77 return; 80 return;
@@ -89,8 +92,13 @@ void wl1271_ps_elp_sleep(struct wl1271 *wl)
89 return; 92 return;
90 } 93 }
91 94
95 if (wl->conf.conn.forced_ps)
96 timeout = ELP_ENTRY_DELAY;
97 else
98 timeout = wl->conf.conn.dynamic_ps_timeout;
99
92 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, 100 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work,
93 msecs_to_jiffies(wl->conf.conn.dynamic_ps_timeout)); 101 msecs_to_jiffies(timeout));
94} 102}
95 103
96int wl1271_ps_elp_wakeup(struct wl1271 *wl) 104int wl1271_ps_elp_wakeup(struct wl1271 *wl)
@@ -185,8 +193,12 @@ int wl1271_ps_set_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
185 193
186 set_bit(WLVIF_FLAG_IN_PS, &wlvif->flags); 194 set_bit(WLVIF_FLAG_IN_PS, &wlvif->flags);
187 195
188 /* enable beacon early termination. Not relevant for 5GHz */ 196 /*
189 if (wlvif->band == IEEE80211_BAND_2GHZ) { 197 * enable beacon early termination.
198 * Not relevant for 5GHz and for high rates.
199 */
200 if ((wlvif->band == IEEE80211_BAND_2GHZ) &&
201 (wlvif->basic_rate < CONF_HW_BIT_RATE_9MBPS)) {
190 ret = wl1271_acx_bet_enable(wl, wlvif, true); 202 ret = wl1271_acx_bet_enable(wl, wlvif, true);
191 if (ret < 0) 203 if (ret < 0)
192 return ret; 204 return ret;
@@ -196,7 +208,8 @@ int wl1271_ps_set_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
196 wl1271_debug(DEBUG_PSM, "leaving psm"); 208 wl1271_debug(DEBUG_PSM, "leaving psm");
197 209
198 /* disable beacon early termination */ 210 /* disable beacon early termination */
199 if (wlvif->band == IEEE80211_BAND_2GHZ) { 211 if ((wlvif->band == IEEE80211_BAND_2GHZ) &&
212 (wlvif->basic_rate < CONF_HW_BIT_RATE_9MBPS)) {
200 ret = wl1271_acx_bet_enable(wl, wlvif, false); 213 ret = wl1271_acx_bet_enable(wl, wlvif, false);
201 if (ret < 0) 214 if (ret < 0)
202 return ret; 215 return ret;
diff --git a/drivers/net/wireless/ti/wlcore/rx.c b/drivers/net/wireless/ti/wlcore/rx.c
index d6a3c6b07827..78200dcacfca 100644
--- a/drivers/net/wireless/ti/wlcore/rx.c
+++ b/drivers/net/wireless/ti/wlcore/rx.c
@@ -186,6 +186,7 @@ static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length,
186 is_data = 1; 186 is_data = 1;
187 187
188 wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon); 188 wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon);
189 wlcore_hw_set_rx_csum(wl, desc, skb);
189 190
190 seq_num = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4; 191 seq_num = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
191 wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s seq %d hlid %d", skb, 192 wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s seq %d hlid %d", skb,
@@ -199,12 +200,12 @@ static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length,
199 return is_data; 200 return is_data;
200} 201}
201 202
202void wl12xx_rx(struct wl1271 *wl, struct wl_fw_status *status) 203void wl12xx_rx(struct wl1271 *wl, struct wl_fw_status_1 *status)
203{ 204{
204 unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0}; 205 unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0};
205 u32 buf_size; 206 u32 buf_size;
206 u32 fw_rx_counter = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK; 207 u32 fw_rx_counter = status->fw_rx_counter % wl->num_rx_desc;
207 u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK; 208 u32 drv_rx_counter = wl->rx_counter % wl->num_rx_desc;
208 u32 rx_counter; 209 u32 rx_counter;
209 u32 pkt_len, align_pkt_len; 210 u32 pkt_len, align_pkt_len;
210 u32 pkt_offset, des; 211 u32 pkt_offset, des;
@@ -223,7 +224,7 @@ void wl12xx_rx(struct wl1271 *wl, struct wl_fw_status *status)
223 break; 224 break;
224 buf_size += align_pkt_len; 225 buf_size += align_pkt_len;
225 rx_counter++; 226 rx_counter++;
226 rx_counter &= NUM_RX_PKT_DESC_MOD_MASK; 227 rx_counter %= wl->num_rx_desc;
227 } 228 }
228 229
229 if (buf_size == 0) { 230 if (buf_size == 0) {
@@ -263,7 +264,7 @@ void wl12xx_rx(struct wl1271 *wl, struct wl_fw_status *status)
263 264
264 wl->rx_counter++; 265 wl->rx_counter++;
265 drv_rx_counter++; 266 drv_rx_counter++;
266 drv_rx_counter &= NUM_RX_PKT_DESC_MOD_MASK; 267 drv_rx_counter %= wl->num_rx_desc;
267 pkt_offset += wlcore_rx_get_align_buf_size(wl, pkt_len); 268 pkt_offset += wlcore_rx_get_align_buf_size(wl, pkt_len);
268 } 269 }
269 } 270 }
diff --git a/drivers/net/wireless/ti/wlcore/rx.h b/drivers/net/wireless/ti/wlcore/rx.h
index e9a162a864ca..9be780179456 100644
--- a/drivers/net/wireless/ti/wlcore/rx.h
+++ b/drivers/net/wireless/ti/wlcore/rx.h
@@ -38,8 +38,6 @@
38#define RX_DESC_PACKETID_SHIFT 11 38#define RX_DESC_PACKETID_SHIFT 11
39#define RX_MAX_PACKET_ID 3 39#define RX_MAX_PACKET_ID 3
40 40
41#define NUM_RX_PKT_DESC_MOD_MASK 7
42
43#define RX_DESC_VALID_FCS 0x0001 41#define RX_DESC_VALID_FCS 0x0001
44#define RX_DESC_MATCH_RXADDR1 0x0002 42#define RX_DESC_MATCH_RXADDR1 0x0002
45#define RX_DESC_MCAST 0x0004 43#define RX_DESC_MCAST 0x0004
@@ -102,6 +100,9 @@
102/* If set, the start of IP payload is not 4 bytes aligned */ 100/* If set, the start of IP payload is not 4 bytes aligned */
103#define RX_BUF_UNALIGNED_PAYLOAD BIT(20) 101#define RX_BUF_UNALIGNED_PAYLOAD BIT(20)
104 102
103/* If set, the buffer was padded by the FW to be 4 bytes aligned */
104#define RX_BUF_PADDED_PAYLOAD BIT(30)
105
105/* Describes the alignment state of a Rx buffer */ 106/* Describes the alignment state of a Rx buffer */
106enum wl_rx_buf_align { 107enum wl_rx_buf_align {
107 WLCORE_RX_BUF_ALIGNED, 108 WLCORE_RX_BUF_ALIGNED,
@@ -136,7 +137,7 @@ struct wl1271_rx_descriptor {
136 u8 reserved; 137 u8 reserved;
137} __packed; 138} __packed;
138 139
139void wl12xx_rx(struct wl1271 *wl, struct wl_fw_status *status); 140void wl12xx_rx(struct wl1271 *wl, struct wl_fw_status_1 *status);
140u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band); 141u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band);
141int wl1271_rx_filter_enable(struct wl1271 *wl, 142int wl1271_rx_filter_enable(struct wl1271 *wl,
142 int index, bool enable, 143 int index, bool enable,
diff --git a/drivers/net/wireless/ti/wlcore/scan.c b/drivers/net/wireless/ti/wlcore/scan.c
index ade21a011c45..d9daed53ceb7 100644
--- a/drivers/net/wireless/ti/wlcore/scan.c
+++ b/drivers/net/wireless/ti/wlcore/scan.c
@@ -411,7 +411,8 @@ wl1271_scan_get_sched_scan_channels(struct wl1271 *wl,
411 struct cfg80211_sched_scan_request *req, 411 struct cfg80211_sched_scan_request *req,
412 struct conn_scan_ch_params *channels, 412 struct conn_scan_ch_params *channels,
413 u32 band, bool radar, bool passive, 413 u32 band, bool radar, bool passive,
414 int start, int max_channels) 414 int start, int max_channels,
415 u8 *n_pactive_ch)
415{ 416{
416 struct conf_sched_scan_settings *c = &wl->conf.sched_scan; 417 struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
417 int i, j; 418 int i, j;
@@ -479,6 +480,23 @@ wl1271_scan_get_sched_scan_channels(struct wl1271 *wl,
479 channels[j].tx_power_att = req->channels[i]->max_power; 480 channels[j].tx_power_att = req->channels[i]->max_power;
480 channels[j].channel = req->channels[i]->hw_value; 481 channels[j].channel = req->channels[i]->hw_value;
481 482
483 if ((band == IEEE80211_BAND_2GHZ) &&
484 (channels[j].channel >= 12) &&
485 (channels[j].channel <= 14) &&
486 (flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
487 !force_passive) {
488 /* pactive channels treated as DFS */
489 channels[j].flags = SCAN_CHANNEL_FLAGS_DFS;
490
491 /*
492 * n_pactive_ch is counted down from the end of
493 * the passive channel list
494 */
495 (*n_pactive_ch)++;
496 wl1271_debug(DEBUG_SCAN, "n_pactive_ch = %d",
497 *n_pactive_ch);
498 }
499
482 j++; 500 j++;
483 } 501 }
484 } 502 }
@@ -491,38 +509,47 @@ wl1271_scan_sched_scan_channels(struct wl1271 *wl,
491 struct cfg80211_sched_scan_request *req, 509 struct cfg80211_sched_scan_request *req,
492 struct wl1271_cmd_sched_scan_config *cfg) 510 struct wl1271_cmd_sched_scan_config *cfg)
493{ 511{
512 u8 n_pactive_ch = 0;
513
494 cfg->passive[0] = 514 cfg->passive[0] =
495 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2, 515 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
496 IEEE80211_BAND_2GHZ, 516 IEEE80211_BAND_2GHZ,
497 false, true, 0, 517 false, true, 0,
498 MAX_CHANNELS_2GHZ); 518 MAX_CHANNELS_2GHZ,
519 &n_pactive_ch);
499 cfg->active[0] = 520 cfg->active[0] =
500 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2, 521 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
501 IEEE80211_BAND_2GHZ, 522 IEEE80211_BAND_2GHZ,
502 false, false, 523 false, false,
503 cfg->passive[0], 524 cfg->passive[0],
504 MAX_CHANNELS_2GHZ); 525 MAX_CHANNELS_2GHZ,
526 &n_pactive_ch);
505 cfg->passive[1] = 527 cfg->passive[1] =
506 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5, 528 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
507 IEEE80211_BAND_5GHZ, 529 IEEE80211_BAND_5GHZ,
508 false, true, 0, 530 false, true, 0,
509 MAX_CHANNELS_5GHZ); 531 MAX_CHANNELS_5GHZ,
532 &n_pactive_ch);
510 cfg->dfs = 533 cfg->dfs =
511 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5, 534 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
512 IEEE80211_BAND_5GHZ, 535 IEEE80211_BAND_5GHZ,
513 true, true, 536 true, true,
514 cfg->passive[1], 537 cfg->passive[1],
515 MAX_CHANNELS_5GHZ); 538 MAX_CHANNELS_5GHZ,
539 &n_pactive_ch);
516 cfg->active[1] = 540 cfg->active[1] =
517 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5, 541 wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
518 IEEE80211_BAND_5GHZ, 542 IEEE80211_BAND_5GHZ,
519 false, false, 543 false, false,
520 cfg->passive[1] + cfg->dfs, 544 cfg->passive[1] + cfg->dfs,
521 MAX_CHANNELS_5GHZ); 545 MAX_CHANNELS_5GHZ,
546 &n_pactive_ch);
522 /* 802.11j channels are not supported yet */ 547 /* 802.11j channels are not supported yet */
523 cfg->passive[2] = 0; 548 cfg->passive[2] = 0;
524 cfg->active[2] = 0; 549 cfg->active[2] = 0;
525 550
551 cfg->n_pactive_ch = n_pactive_ch;
552
526 wl1271_debug(DEBUG_SCAN, " 2.4GHz: active %d passive %d", 553 wl1271_debug(DEBUG_SCAN, " 2.4GHz: active %d passive %d",
527 cfg->active[0], cfg->passive[0]); 554 cfg->active[0], cfg->passive[0]);
528 wl1271_debug(DEBUG_SCAN, " 5GHz: active %d passive %d", 555 wl1271_debug(DEBUG_SCAN, " 5GHz: active %d passive %d",
@@ -537,6 +564,7 @@ wl1271_scan_sched_scan_channels(struct wl1271 *wl,
537/* Returns the scan type to be used or a negative value on error */ 564/* Returns the scan type to be used or a negative value on error */
538static int 565static int
539wl12xx_scan_sched_scan_ssid_list(struct wl1271 *wl, 566wl12xx_scan_sched_scan_ssid_list(struct wl1271 *wl,
567 struct wl12xx_vif *wlvif,
540 struct cfg80211_sched_scan_request *req) 568 struct cfg80211_sched_scan_request *req)
541{ 569{
542 struct wl1271_cmd_sched_scan_ssid_list *cmd = NULL; 570 struct wl1271_cmd_sched_scan_ssid_list *cmd = NULL;
@@ -565,6 +593,7 @@ wl12xx_scan_sched_scan_ssid_list(struct wl1271 *wl,
565 goto out; 593 goto out;
566 } 594 }
567 595
596 cmd->role_id = wlvif->dev_role_id;
568 if (!n_match_ssids) { 597 if (!n_match_ssids) {
569 /* No filter, with ssids */ 598 /* No filter, with ssids */
570 type = SCAN_SSID_FILTER_DISABLED; 599 type = SCAN_SSID_FILTER_DISABLED;
@@ -603,7 +632,9 @@ wl12xx_scan_sched_scan_ssid_list(struct wl1271 *wl,
603 continue; 632 continue;
604 633
605 for (j = 0; j < cmd->n_ssids; j++) 634 for (j = 0; j < cmd->n_ssids; j++)
606 if (!memcmp(req->ssids[i].ssid, 635 if ((req->ssids[i].ssid_len ==
636 req->ssids[j].ssid_len) &&
637 !memcmp(req->ssids[i].ssid,
607 cmd->ssids[j].ssid, 638 cmd->ssids[j].ssid,
608 req->ssids[i].ssid_len)) { 639 req->ssids[i].ssid_len)) {
609 cmd->ssids[j].type = 640 cmd->ssids[j].type =
@@ -652,6 +683,7 @@ int wl1271_scan_sched_scan_config(struct wl1271 *wl,
652 if (!cfg) 683 if (!cfg)
653 return -ENOMEM; 684 return -ENOMEM;
654 685
686 cfg->role_id = wlvif->dev_role_id;
655 cfg->rssi_threshold = c->rssi_threshold; 687 cfg->rssi_threshold = c->rssi_threshold;
656 cfg->snr_threshold = c->snr_threshold; 688 cfg->snr_threshold = c->snr_threshold;
657 cfg->n_probe_reqs = c->num_probe_reqs; 689 cfg->n_probe_reqs = c->num_probe_reqs;
@@ -669,7 +701,7 @@ int wl1271_scan_sched_scan_config(struct wl1271 *wl,
669 cfg->intervals[i] = cpu_to_le32(req->interval); 701 cfg->intervals[i] = cpu_to_le32(req->interval);
670 702
671 cfg->ssid_len = 0; 703 cfg->ssid_len = 0;
672 ret = wl12xx_scan_sched_scan_ssid_list(wl, req); 704 ret = wl12xx_scan_sched_scan_ssid_list(wl, wlvif, req);
673 if (ret < 0) 705 if (ret < 0)
674 goto out; 706 goto out;
675 707
@@ -741,6 +773,7 @@ int wl1271_scan_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif)
741 if (!start) 773 if (!start)
742 return -ENOMEM; 774 return -ENOMEM;
743 775
776 start->role_id = wlvif->dev_role_id;
744 start->tag = WL1271_SCAN_DEFAULT_TAG; 777 start->tag = WL1271_SCAN_DEFAULT_TAG;
745 778
746 ret = wl1271_cmd_send(wl, CMD_START_PERIODIC_SCAN, start, 779 ret = wl1271_cmd_send(wl, CMD_START_PERIODIC_SCAN, start,
@@ -762,7 +795,7 @@ void wl1271_scan_sched_scan_results(struct wl1271 *wl)
762 ieee80211_sched_scan_results(wl->hw); 795 ieee80211_sched_scan_results(wl->hw);
763} 796}
764 797
765void wl1271_scan_sched_scan_stop(struct wl1271 *wl) 798void wl1271_scan_sched_scan_stop(struct wl1271 *wl, struct wl12xx_vif *wlvif)
766{ 799{
767 struct wl1271_cmd_sched_scan_stop *stop; 800 struct wl1271_cmd_sched_scan_stop *stop;
768 int ret = 0; 801 int ret = 0;
@@ -776,6 +809,7 @@ void wl1271_scan_sched_scan_stop(struct wl1271 *wl)
776 return; 809 return;
777 } 810 }
778 811
812 stop->role_id = wlvif->dev_role_id;
779 stop->tag = WL1271_SCAN_DEFAULT_TAG; 813 stop->tag = WL1271_SCAN_DEFAULT_TAG;
780 814
781 ret = wl1271_cmd_send(wl, CMD_STOP_PERIODIC_SCAN, stop, 815 ret = wl1271_cmd_send(wl, CMD_STOP_PERIODIC_SCAN, stop,
diff --git a/drivers/net/wireless/ti/wlcore/scan.h b/drivers/net/wireless/ti/wlcore/scan.h
index 81ee36ac2078..29f3c8d6b046 100644
--- a/drivers/net/wireless/ti/wlcore/scan.h
+++ b/drivers/net/wireless/ti/wlcore/scan.h
@@ -40,7 +40,7 @@ int wl1271_scan_sched_scan_config(struct wl1271 *wl,
40 struct cfg80211_sched_scan_request *req, 40 struct cfg80211_sched_scan_request *req,
41 struct ieee80211_sched_scan_ies *ies); 41 struct ieee80211_sched_scan_ies *ies);
42int wl1271_scan_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif); 42int wl1271_scan_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif);
43void wl1271_scan_sched_scan_stop(struct wl1271 *wl); 43void wl1271_scan_sched_scan_stop(struct wl1271 *wl, struct wl12xx_vif *wlvif);
44void wl1271_scan_sched_scan_results(struct wl1271 *wl); 44void wl1271_scan_sched_scan_results(struct wl1271 *wl);
45 45
46#define WL1271_SCAN_MAX_CHANNELS 24 46#define WL1271_SCAN_MAX_CHANNELS 24
@@ -142,7 +142,8 @@ enum {
142 SCAN_BSS_TYPE_ANY, 142 SCAN_BSS_TYPE_ANY,
143}; 143};
144 144
145#define SCAN_CHANNEL_FLAGS_DFS BIT(0) 145#define SCAN_CHANNEL_FLAGS_DFS BIT(0) /* channel is passive until an
146 activity is detected on it */
146#define SCAN_CHANNEL_FLAGS_DFS_ENABLED BIT(1) 147#define SCAN_CHANNEL_FLAGS_DFS_ENABLED BIT(1)
147 148
148struct conn_scan_ch_params { 149struct conn_scan_ch_params {
@@ -185,7 +186,10 @@ struct wl1271_cmd_sched_scan_config {
185 186
186 u8 dfs; 187 u8 dfs;
187 188
188 u8 padding[3]; 189 u8 n_pactive_ch; /* number of pactive (passive until fw detects energy)
190 channels in BG band */
191 u8 role_id;
192 u8 padding[1];
189 193
190 struct conn_scan_ch_params channels_2[MAX_CHANNELS_2GHZ]; 194 struct conn_scan_ch_params channels_2[MAX_CHANNELS_2GHZ];
191 struct conn_scan_ch_params channels_5[MAX_CHANNELS_5GHZ]; 195 struct conn_scan_ch_params channels_5[MAX_CHANNELS_5GHZ];
@@ -212,21 +216,24 @@ struct wl1271_cmd_sched_scan_ssid_list {
212 216
213 u8 n_ssids; 217 u8 n_ssids;
214 struct wl1271_ssid ssids[SCHED_SCAN_MAX_SSIDS]; 218 struct wl1271_ssid ssids[SCHED_SCAN_MAX_SSIDS];
215 u8 padding[3]; 219 u8 role_id;
220 u8 padding[2];
216} __packed; 221} __packed;
217 222
218struct wl1271_cmd_sched_scan_start { 223struct wl1271_cmd_sched_scan_start {
219 struct wl1271_cmd_header header; 224 struct wl1271_cmd_header header;
220 225
221 u8 tag; 226 u8 tag;
222 u8 padding[3]; 227 u8 role_id;
228 u8 padding[2];
223} __packed; 229} __packed;
224 230
225struct wl1271_cmd_sched_scan_stop { 231struct wl1271_cmd_sched_scan_stop {
226 struct wl1271_cmd_header header; 232 struct wl1271_cmd_header header;
227 233
228 u8 tag; 234 u8 tag;
229 u8 padding[3]; 235 u8 role_id;
236 u8 padding[2];
230} __packed; 237} __packed;
231 238
232 239
diff --git a/drivers/net/wireless/ti/wlcore/sdio.c b/drivers/net/wireless/ti/wlcore/sdio.c
index 0a72347cfc4c..c67ec482e445 100644
--- a/drivers/net/wireless/ti/wlcore/sdio.c
+++ b/drivers/net/wireless/ti/wlcore/sdio.c
@@ -25,6 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/mmc/sdio.h>
28#include <linux/mmc/sdio_func.h> 29#include <linux/mmc/sdio_func.h>
29#include <linux/mmc/sdio_ids.h> 30#include <linux/mmc/sdio_ids.h>
30#include <linux/mmc/card.h> 31#include <linux/mmc/card.h>
@@ -32,6 +33,7 @@
32#include <linux/gpio.h> 33#include <linux/gpio.h>
33#include <linux/wl12xx.h> 34#include <linux/wl12xx.h>
34#include <linux/pm_runtime.h> 35#include <linux/pm_runtime.h>
36#include <linux/printk.h>
35 37
36#include "wlcore.h" 38#include "wlcore.h"
37#include "wl12xx_80211.h" 39#include "wl12xx_80211.h"
@@ -45,6 +47,8 @@
45#define SDIO_DEVICE_ID_TI_WL1271 0x4076 47#define SDIO_DEVICE_ID_TI_WL1271 0x4076
46#endif 48#endif
47 49
50static bool dump = false;
51
48struct wl12xx_sdio_glue { 52struct wl12xx_sdio_glue {
49 struct device *dev; 53 struct device *dev;
50 struct platform_device *core; 54 struct platform_device *core;
@@ -76,6 +80,13 @@ static void wl12xx_sdio_raw_read(struct device *child, int addr, void *buf,
76 80
77 sdio_claim_host(func); 81 sdio_claim_host(func);
78 82
83 if (unlikely(dump)) {
84 printk(KERN_DEBUG "wlcore_sdio: READ from 0x%04x\n", addr);
85 print_hex_dump(KERN_DEBUG, "wlcore_sdio: READ ",
86 DUMP_PREFIX_OFFSET, 16, 1,
87 buf, len, false);
88 }
89
79 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG)) { 90 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG)) {
80 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret); 91 ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
81 dev_dbg(child->parent, "sdio read 52 addr 0x%x, byte 0x%02x\n", 92 dev_dbg(child->parent, "sdio read 52 addr 0x%x, byte 0x%02x\n",
@@ -105,6 +116,13 @@ static void wl12xx_sdio_raw_write(struct device *child, int addr, void *buf,
105 116
106 sdio_claim_host(func); 117 sdio_claim_host(func);
107 118
119 if (unlikely(dump)) {
120 printk(KERN_DEBUG "wlcore_sdio: WRITE to 0x%04x\n", addr);
121 print_hex_dump(KERN_DEBUG, "wlcore_sdio: WRITE ",
122 DUMP_PREFIX_OFFSET, 16, 1,
123 buf, len, false);
124 }
125
108 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG)) { 126 if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG)) {
109 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret); 127 sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
110 dev_dbg(child->parent, "sdio write 52 addr 0x%x, byte 0x%02x\n", 128 dev_dbg(child->parent, "sdio write 52 addr 0x%x, byte 0x%02x\n",
@@ -196,6 +214,7 @@ static int __devinit wl1271_probe(struct sdio_func *func,
196 struct resource res[1]; 214 struct resource res[1];
197 mmc_pm_flag_t mmcflags; 215 mmc_pm_flag_t mmcflags;
198 int ret = -ENOMEM; 216 int ret = -ENOMEM;
217 const char *chip_family;
199 218
200 /* We are only able to handle the wlan function */ 219 /* We are only able to handle the wlan function */
201 if (func->num != 0x02) 220 if (func->num != 0x02)
@@ -236,7 +255,18 @@ static int __devinit wl1271_probe(struct sdio_func *func,
236 /* Tell PM core that we don't need the card to be powered now */ 255 /* Tell PM core that we don't need the card to be powered now */
237 pm_runtime_put_noidle(&func->dev); 256 pm_runtime_put_noidle(&func->dev);
238 257
239 glue->core = platform_device_alloc("wl12xx", -1); 258 /*
259 * Due to a hardware bug, we can't differentiate wl18xx from
260 * wl12xx, because both report the same device ID. The only
261 * way to differentiate is by checking the SDIO revision,
262 * which is 3.00 on the wl18xx chips.
263 */
264 if (func->card->cccr.sdio_vsn == SDIO_SDIO_REV_3_00)
265 chip_family = "wl18xx";
266 else
267 chip_family = "wl12xx";
268
269 glue->core = platform_device_alloc(chip_family, -1);
240 if (!glue->core) { 270 if (!glue->core) {
241 dev_err(glue->dev, "can't allocate platform_device"); 271 dev_err(glue->dev, "can't allocate platform_device");
242 ret = -ENOMEM; 272 ret = -ENOMEM;
@@ -367,6 +397,9 @@ static void __exit wl1271_exit(void)
367module_init(wl1271_init); 397module_init(wl1271_init);
368module_exit(wl1271_exit); 398module_exit(wl1271_exit);
369 399
400module_param(dump, bool, S_IRUSR | S_IWUSR);
401MODULE_PARM_DESC(dump, "Enable sdio read/write dumps.");
402
370MODULE_LICENSE("GPL"); 403MODULE_LICENSE("GPL");
371MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>"); 404MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
372MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>"); 405MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
diff --git a/drivers/net/wireless/ti/wlcore/tx.c b/drivers/net/wireless/ti/wlcore/tx.c
index 6893bc207994..6983e7a829d0 100644
--- a/drivers/net/wireless/ti/wlcore/tx.c
+++ b/drivers/net/wireless/ti/wlcore/tx.c
@@ -72,7 +72,7 @@ static int wl1271_alloc_tx_id(struct wl1271 *wl, struct sk_buff *skb)
72 return id; 72 return id;
73} 73}
74 74
75static void wl1271_free_tx_id(struct wl1271 *wl, int id) 75void wl1271_free_tx_id(struct wl1271 *wl, int id)
76{ 76{
77 if (__test_and_clear_bit(id, wl->tx_frames_map)) { 77 if (__test_and_clear_bit(id, wl->tx_frames_map)) {
78 if (unlikely(wl->tx_frames_cnt == wl->num_tx_desc)) 78 if (unlikely(wl->tx_frames_cnt == wl->num_tx_desc))
@@ -82,6 +82,7 @@ static void wl1271_free_tx_id(struct wl1271 *wl, int id)
82 wl->tx_frames_cnt--; 82 wl->tx_frames_cnt--;
83 } 83 }
84} 84}
85EXPORT_SYMBOL(wl1271_free_tx_id);
85 86
86static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl, 87static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl,
87 struct sk_buff *skb) 88 struct sk_buff *skb)
@@ -127,6 +128,7 @@ bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb)
127{ 128{
128 return wl->dummy_packet == skb; 129 return wl->dummy_packet == skb;
129} 130}
131EXPORT_SYMBOL(wl12xx_is_dummy_packet);
130 132
131u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif, 133u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif,
132 struct sk_buff *skb) 134 struct sk_buff *skb)
@@ -146,10 +148,10 @@ u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif,
146 return wl->system_hlid; 148 return wl->system_hlid;
147 149
148 hdr = (struct ieee80211_hdr *)skb->data; 150 hdr = (struct ieee80211_hdr *)skb->data;
149 if (ieee80211_is_mgmt(hdr->frame_control)) 151 if (is_multicast_ether_addr(ieee80211_get_DA(hdr)))
150 return wlvif->ap.global_hlid;
151 else
152 return wlvif->ap.bcast_hlid; 152 return wlvif->ap.bcast_hlid;
153 else
154 return wlvif->ap.global_hlid;
153 } 155 }
154} 156}
155 157
@@ -176,37 +178,34 @@ u8 wl12xx_tx_get_hlid(struct wl1271 *wl, struct wl12xx_vif *wlvif,
176unsigned int wlcore_calc_packet_alignment(struct wl1271 *wl, 178unsigned int wlcore_calc_packet_alignment(struct wl1271 *wl,
177 unsigned int packet_length) 179 unsigned int packet_length)
178{ 180{
179 if (wl->quirks & WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN) 181 if ((wl->quirks & WLCORE_QUIRK_TX_PAD_LAST_FRAME) ||
180 return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE); 182 !(wl->quirks & WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN))
181 else
182 return ALIGN(packet_length, WL1271_TX_ALIGN_TO); 183 return ALIGN(packet_length, WL1271_TX_ALIGN_TO);
184 else
185 return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE);
183} 186}
184EXPORT_SYMBOL(wlcore_calc_packet_alignment); 187EXPORT_SYMBOL(wlcore_calc_packet_alignment);
185 188
186static int wl1271_tx_allocate(struct wl1271 *wl, struct wl12xx_vif *wlvif, 189static int wl1271_tx_allocate(struct wl1271 *wl, struct wl12xx_vif *wlvif,
187 struct sk_buff *skb, u32 extra, u32 buf_offset, 190 struct sk_buff *skb, u32 extra, u32 buf_offset,
188 u8 hlid) 191 u8 hlid, bool is_gem)
189{ 192{
190 struct wl1271_tx_hw_descr *desc; 193 struct wl1271_tx_hw_descr *desc;
191 u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra; 194 u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
192 u32 total_blocks; 195 u32 total_blocks;
193 int id, ret = -EBUSY, ac; 196 int id, ret = -EBUSY, ac;
194 u32 spare_blocks = wl->normal_tx_spare; 197 u32 spare_blocks;
195 bool is_dummy = false;
196 198
197 if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE) 199 if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE)
198 return -EAGAIN; 200 return -EAGAIN;
199 201
202 spare_blocks = wlcore_hw_get_spare_blocks(wl, is_gem);
203
200 /* allocate free identifier for the packet */ 204 /* allocate free identifier for the packet */
201 id = wl1271_alloc_tx_id(wl, skb); 205 id = wl1271_alloc_tx_id(wl, skb);
202 if (id < 0) 206 if (id < 0)
203 return id; 207 return id;
204 208
205 if (unlikely(wl12xx_is_dummy_packet(wl, skb)))
206 is_dummy = true;
207 else if (wlvif->is_gem)
208 spare_blocks = wl->gem_tx_spare;
209
210 total_blocks = wlcore_hw_calc_tx_blocks(wl, total_len, spare_blocks); 209 total_blocks = wlcore_hw_calc_tx_blocks(wl, total_len, spare_blocks);
211 210
212 if (total_blocks <= wl->tx_blocks_available) { 211 if (total_blocks <= wl->tx_blocks_available) {
@@ -228,7 +227,7 @@ static int wl1271_tx_allocate(struct wl1271 *wl, struct wl12xx_vif *wlvif,
228 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb)); 227 ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
229 wl->tx_allocated_pkts[ac]++; 228 wl->tx_allocated_pkts[ac]++;
230 229
231 if (!is_dummy && wlvif && 230 if (!wl12xx_is_dummy_packet(wl, skb) && wlvif &&
232 wlvif->bss_type == BSS_TYPE_AP_BSS && 231 wlvif->bss_type == BSS_TYPE_AP_BSS &&
233 test_bit(hlid, wlvif->ap.sta_hlid_map)) 232 test_bit(hlid, wlvif->ap.sta_hlid_map))
234 wl->links[hlid].allocated_pkts++; 233 wl->links[hlid].allocated_pkts++;
@@ -268,6 +267,7 @@ static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct wl12xx_vif *wlvif,
268 if (extra) { 267 if (extra) {
269 int hdrlen = ieee80211_hdrlen(frame_control); 268 int hdrlen = ieee80211_hdrlen(frame_control);
270 memmove(frame_start, hdr, hdrlen); 269 memmove(frame_start, hdr, hdrlen);
270 skb_set_network_header(skb, skb_network_offset(skb) + extra);
271 } 271 }
272 272
273 /* configure packet life time */ 273 /* configure packet life time */
@@ -330,9 +330,9 @@ static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct wl12xx_vif *wlvif,
330 ieee80211_has_protected(frame_control)) 330 ieee80211_has_protected(frame_control))
331 tx_attr |= TX_HW_ATTR_HOST_ENCRYPT; 331 tx_attr |= TX_HW_ATTR_HOST_ENCRYPT;
332 332
333 desc->reserved = 0;
334 desc->tx_attr = cpu_to_le16(tx_attr); 333 desc->tx_attr = cpu_to_le16(tx_attr);
335 334
335 wlcore_hw_set_tx_desc_csum(wl, desc, skb);
336 wlcore_hw_set_tx_desc_data_len(wl, desc, skb); 336 wlcore_hw_set_tx_desc_data_len(wl, desc, skb);
337} 337}
338 338
@@ -346,6 +346,7 @@ static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct wl12xx_vif *wlvif,
346 u32 total_len; 346 u32 total_len;
347 u8 hlid; 347 u8 hlid;
348 bool is_dummy; 348 bool is_dummy;
349 bool is_gem = false;
349 350
350 if (!skb) 351 if (!skb)
351 return -EINVAL; 352 return -EINVAL;
@@ -355,7 +356,8 @@ static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct wl12xx_vif *wlvif,
355 /* TODO: handle dummy packets on multi-vifs */ 356 /* TODO: handle dummy packets on multi-vifs */
356 is_dummy = wl12xx_is_dummy_packet(wl, skb); 357 is_dummy = wl12xx_is_dummy_packet(wl, skb);
357 358
358 if (info->control.hw_key && 359 if ((wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) &&
360 info->control.hw_key &&
359 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) 361 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
360 extra = WL1271_EXTRA_SPACE_TKIP; 362 extra = WL1271_EXTRA_SPACE_TKIP;
361 363
@@ -373,6 +375,8 @@ static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct wl12xx_vif *wlvif,
373 return ret; 375 return ret;
374 wlvif->default_key = idx; 376 wlvif->default_key = idx;
375 } 377 }
378
379 is_gem = (cipher == WL1271_CIPHER_SUITE_GEM);
376 } 380 }
377 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb); 381 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
378 if (hlid == WL12XX_INVALID_LINK_ID) { 382 if (hlid == WL12XX_INVALID_LINK_ID) {
@@ -380,7 +384,8 @@ static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct wl12xx_vif *wlvif,
380 return -EINVAL; 384 return -EINVAL;
381 } 385 }
382 386
383 ret = wl1271_tx_allocate(wl, wlvif, skb, extra, buf_offset, hlid); 387 ret = wl1271_tx_allocate(wl, wlvif, skb, extra, buf_offset, hlid,
388 is_gem);
384 if (ret < 0) 389 if (ret < 0)
385 return ret; 390 return ret;
386 391
@@ -425,10 +430,10 @@ u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set,
425 rate_set >>= 1; 430 rate_set >>= 1;
426 } 431 }
427 432
428 /* MCS rates indication are on bits 16 - 23 */ 433 /* MCS rates indication are on bits 16 - 31 */
429 rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates; 434 rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates;
430 435
431 for (bit = 0; bit < 8; bit++) { 436 for (bit = 0; bit < 16; bit++) {
432 if (rate_set & 0x1) 437 if (rate_set & 0x1)
433 enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit); 438 enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit);
434 rate_set >>= 1; 439 rate_set >>= 1;
@@ -439,18 +444,15 @@ u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set,
439 444
440void wl1271_handle_tx_low_watermark(struct wl1271 *wl) 445void wl1271_handle_tx_low_watermark(struct wl1271 *wl)
441{ 446{
442 unsigned long flags;
443 int i; 447 int i;
444 448
445 for (i = 0; i < NUM_TX_QUEUES; i++) { 449 for (i = 0; i < NUM_TX_QUEUES; i++) {
446 if (test_bit(i, &wl->stopped_queues_map) && 450 if (wlcore_is_queue_stopped_by_reason(wl, i,
451 WLCORE_QUEUE_STOP_REASON_WATERMARK) &&
447 wl->tx_queue_count[i] <= WL1271_TX_QUEUE_LOW_WATERMARK) { 452 wl->tx_queue_count[i] <= WL1271_TX_QUEUE_LOW_WATERMARK) {
448 /* firmware buffer has space, restart queues */ 453 /* firmware buffer has space, restart queues */
449 spin_lock_irqsave(&wl->wl_lock, flags); 454 wlcore_wake_queue(wl, i,
450 ieee80211_wake_queue(wl->hw, 455 WLCORE_QUEUE_STOP_REASON_WATERMARK);
451 wl1271_tx_get_mac80211_queue(i));
452 clear_bit(i, &wl->stopped_queues_map);
453 spin_unlock_irqrestore(&wl->wl_lock, flags);
454 } 456 }
455 } 457 }
456} 458}
@@ -661,7 +663,7 @@ void wl1271_tx_work_locked(struct wl1271 *wl)
661 struct wl12xx_vif *wlvif; 663 struct wl12xx_vif *wlvif;
662 struct sk_buff *skb; 664 struct sk_buff *skb;
663 struct wl1271_tx_hw_descr *desc; 665 struct wl1271_tx_hw_descr *desc;
664 u32 buf_offset = 0; 666 u32 buf_offset = 0, last_len = 0;
665 bool sent_packets = false; 667 bool sent_packets = false;
666 unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0}; 668 unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0};
667 int ret; 669 int ret;
@@ -685,6 +687,9 @@ void wl1271_tx_work_locked(struct wl1271 *wl)
685 * Flush buffer and try again. 687 * Flush buffer and try again.
686 */ 688 */
687 wl1271_skb_queue_head(wl, wlvif, skb); 689 wl1271_skb_queue_head(wl, wlvif, skb);
690
691 buf_offset = wlcore_hw_pre_pkt_send(wl, buf_offset,
692 last_len);
688 wlcore_write_data(wl, REG_SLV_MEM_DATA, wl->aggr_buf, 693 wlcore_write_data(wl, REG_SLV_MEM_DATA, wl->aggr_buf,
689 buf_offset, true); 694 buf_offset, true);
690 sent_packets = true; 695 sent_packets = true;
@@ -710,7 +715,8 @@ void wl1271_tx_work_locked(struct wl1271 *wl)
710 ieee80211_free_txskb(wl->hw, skb); 715 ieee80211_free_txskb(wl->hw, skb);
711 goto out_ack; 716 goto out_ack;
712 } 717 }
713 buf_offset += ret; 718 last_len = ret;
719 buf_offset += last_len;
714 wl->tx_packets_count++; 720 wl->tx_packets_count++;
715 if (has_data) { 721 if (has_data) {
716 desc = (struct wl1271_tx_hw_descr *) skb->data; 722 desc = (struct wl1271_tx_hw_descr *) skb->data;
@@ -720,6 +726,7 @@ void wl1271_tx_work_locked(struct wl1271 *wl)
720 726
721out_ack: 727out_ack:
722 if (buf_offset) { 728 if (buf_offset) {
729 buf_offset = wlcore_hw_pre_pkt_send(wl, buf_offset, last_len);
723 wlcore_write_data(wl, REG_SLV_MEM_DATA, wl->aggr_buf, 730 wlcore_write_data(wl, REG_SLV_MEM_DATA, wl->aggr_buf,
724 buf_offset, true); 731 buf_offset, true);
725 sent_packets = true; 732 sent_packets = true;
@@ -849,7 +856,8 @@ static void wl1271_tx_complete_packet(struct wl1271 *wl,
849 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); 856 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
850 857
851 /* remove TKIP header space if present */ 858 /* remove TKIP header space if present */
852 if (info->control.hw_key && 859 if ((wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) &&
860 info->control.hw_key &&
853 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) { 861 info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
854 int hdrlen = ieee80211_get_hdrlen_from_skb(skb); 862 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
855 memmove(skb->data + WL1271_EXTRA_SPACE_TKIP, skb->data, 863 memmove(skb->data + WL1271_EXTRA_SPACE_TKIP, skb->data,
@@ -958,7 +966,7 @@ void wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif)
958 966
959} 967}
960/* caller must hold wl->mutex and TX must be stopped */ 968/* caller must hold wl->mutex and TX must be stopped */
961void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues) 969void wl12xx_tx_reset(struct wl1271 *wl)
962{ 970{
963 int i; 971 int i;
964 struct sk_buff *skb; 972 struct sk_buff *skb;
@@ -973,15 +981,12 @@ void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues)
973 wl->tx_queue_count[i] = 0; 981 wl->tx_queue_count[i] = 0;
974 } 982 }
975 983
976 wl->stopped_queues_map = 0;
977
978 /* 984 /*
979 * Make sure the driver is at a consistent state, in case this 985 * Make sure the driver is at a consistent state, in case this
980 * function is called from a context other than interface removal. 986 * function is called from a context other than interface removal.
981 * This call will always wake the TX queues. 987 * This call will always wake the TX queues.
982 */ 988 */
983 if (reset_tx_queues) 989 wl1271_handle_tx_low_watermark(wl);
984 wl1271_handle_tx_low_watermark(wl);
985 990
986 for (i = 0; i < wl->num_tx_desc; i++) { 991 for (i = 0; i < wl->num_tx_desc; i++) {
987 if (wl->tx_frames[i] == NULL) 992 if (wl->tx_frames[i] == NULL)
@@ -998,7 +1003,8 @@ void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues)
998 */ 1003 */
999 info = IEEE80211_SKB_CB(skb); 1004 info = IEEE80211_SKB_CB(skb);
1000 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr)); 1005 skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
1001 if (info->control.hw_key && 1006 if ((wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) &&
1007 info->control.hw_key &&
1002 info->control.hw_key->cipher == 1008 info->control.hw_key->cipher ==
1003 WLAN_CIPHER_SUITE_TKIP) { 1009 WLAN_CIPHER_SUITE_TKIP) {
1004 int hdrlen = ieee80211_get_hdrlen_from_skb(skb); 1010 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
@@ -1024,6 +1030,11 @@ void wl1271_tx_flush(struct wl1271 *wl)
1024 int i; 1030 int i;
1025 timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT); 1031 timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT);
1026 1032
1033 /* only one flush should be in progress, for consistent queue state */
1034 mutex_lock(&wl->flush_mutex);
1035
1036 wlcore_stop_queues(wl, WLCORE_QUEUE_STOP_REASON_FLUSH);
1037
1027 while (!time_after(jiffies, timeout)) { 1038 while (!time_after(jiffies, timeout)) {
1028 mutex_lock(&wl->mutex); 1039 mutex_lock(&wl->mutex);
1029 wl1271_debug(DEBUG_TX, "flushing tx buffer: %d %d", 1040 wl1271_debug(DEBUG_TX, "flushing tx buffer: %d %d",
@@ -1032,7 +1043,7 @@ void wl1271_tx_flush(struct wl1271 *wl)
1032 if ((wl->tx_frames_cnt == 0) && 1043 if ((wl->tx_frames_cnt == 0) &&
1033 (wl1271_tx_total_queue_count(wl) == 0)) { 1044 (wl1271_tx_total_queue_count(wl) == 0)) {
1034 mutex_unlock(&wl->mutex); 1045 mutex_unlock(&wl->mutex);
1035 return; 1046 goto out;
1036 } 1047 }
1037 mutex_unlock(&wl->mutex); 1048 mutex_unlock(&wl->mutex);
1038 msleep(1); 1049 msleep(1);
@@ -1045,7 +1056,12 @@ void wl1271_tx_flush(struct wl1271 *wl)
1045 for (i = 0; i < WL12XX_MAX_LINKS; i++) 1056 for (i = 0; i < WL12XX_MAX_LINKS; i++)
1046 wl1271_tx_reset_link_queues(wl, i); 1057 wl1271_tx_reset_link_queues(wl, i);
1047 mutex_unlock(&wl->mutex); 1058 mutex_unlock(&wl->mutex);
1059
1060out:
1061 wlcore_wake_queues(wl, WLCORE_QUEUE_STOP_REASON_FLUSH);
1062 mutex_unlock(&wl->flush_mutex);
1048} 1063}
1064EXPORT_SYMBOL_GPL(wl1271_tx_flush);
1049 1065
1050u32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set) 1066u32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set)
1051{ 1067{
@@ -1054,3 +1070,96 @@ u32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set)
1054 1070
1055 return BIT(__ffs(rate_set)); 1071 return BIT(__ffs(rate_set));
1056} 1072}
1073
1074void wlcore_stop_queue_locked(struct wl1271 *wl, u8 queue,
1075 enum wlcore_queue_stop_reason reason)
1076{
1077 bool stopped = !!wl->queue_stop_reasons[queue];
1078
1079 /* queue should not be stopped for this reason */
1080 WARN_ON(test_and_set_bit(reason, &wl->queue_stop_reasons[queue]));
1081
1082 if (stopped)
1083 return;
1084
1085 ieee80211_stop_queue(wl->hw, wl1271_tx_get_mac80211_queue(queue));
1086}
1087
1088void wlcore_stop_queue(struct wl1271 *wl, u8 queue,
1089 enum wlcore_queue_stop_reason reason)
1090{
1091 unsigned long flags;
1092
1093 spin_lock_irqsave(&wl->wl_lock, flags);
1094 wlcore_stop_queue_locked(wl, queue, reason);
1095 spin_unlock_irqrestore(&wl->wl_lock, flags);
1096}
1097
1098void wlcore_wake_queue(struct wl1271 *wl, u8 queue,
1099 enum wlcore_queue_stop_reason reason)
1100{
1101 unsigned long flags;
1102
1103 spin_lock_irqsave(&wl->wl_lock, flags);
1104
1105 /* queue should not be clear for this reason */
1106 WARN_ON(!test_and_clear_bit(reason, &wl->queue_stop_reasons[queue]));
1107
1108 if (wl->queue_stop_reasons[queue])
1109 goto out;
1110
1111 ieee80211_wake_queue(wl->hw, wl1271_tx_get_mac80211_queue(queue));
1112
1113out:
1114 spin_unlock_irqrestore(&wl->wl_lock, flags);
1115}
1116
1117void wlcore_stop_queues(struct wl1271 *wl,
1118 enum wlcore_queue_stop_reason reason)
1119{
1120 int i;
1121
1122 for (i = 0; i < NUM_TX_QUEUES; i++)
1123 wlcore_stop_queue(wl, i, reason);
1124}
1125EXPORT_SYMBOL_GPL(wlcore_stop_queues);
1126
1127void wlcore_wake_queues(struct wl1271 *wl,
1128 enum wlcore_queue_stop_reason reason)
1129{
1130 int i;
1131
1132 for (i = 0; i < NUM_TX_QUEUES; i++)
1133 wlcore_wake_queue(wl, i, reason);
1134}
1135EXPORT_SYMBOL_GPL(wlcore_wake_queues);
1136
1137void wlcore_reset_stopped_queues(struct wl1271 *wl)
1138{
1139 int i;
1140 unsigned long flags;
1141
1142 spin_lock_irqsave(&wl->wl_lock, flags);
1143
1144 for (i = 0; i < NUM_TX_QUEUES; i++) {
1145 if (!wl->queue_stop_reasons[i])
1146 continue;
1147
1148 wl->queue_stop_reasons[i] = 0;
1149 ieee80211_wake_queue(wl->hw,
1150 wl1271_tx_get_mac80211_queue(i));
1151 }
1152
1153 spin_unlock_irqrestore(&wl->wl_lock, flags);
1154}
1155
1156bool wlcore_is_queue_stopped_by_reason(struct wl1271 *wl, u8 queue,
1157 enum wlcore_queue_stop_reason reason)
1158{
1159 return test_bit(reason, &wl->queue_stop_reasons[queue]);
1160}
1161
1162bool wlcore_is_queue_stopped(struct wl1271 *wl, u8 queue)
1163{
1164 return !!wl->queue_stop_reasons[queue];
1165}
diff --git a/drivers/net/wireless/ti/wlcore/tx.h b/drivers/net/wireless/ti/wlcore/tx.h
index 2fd6e5dc6f75..fa4be1b91135 100644
--- a/drivers/net/wireless/ti/wlcore/tx.h
+++ b/drivers/net/wireless/ti/wlcore/tx.h
@@ -85,6 +85,19 @@ struct wl128x_tx_mem {
85 u8 extra_bytes; 85 u8 extra_bytes;
86} __packed; 86} __packed;
87 87
88struct wl18xx_tx_mem {
89 /*
90 * Total number of memory blocks allocated by the host for
91 * this packet.
92 */
93 u8 total_mem_blocks;
94
95 /*
96 * control bits
97 */
98 u8 ctrl;
99} __packed;
100
88/* 101/*
89 * On wl128x based devices, when TX packets are aggregated, each packet 102 * On wl128x based devices, when TX packets are aggregated, each packet
90 * size must be aligned to the SDIO block size. The maximum block size 103 * size must be aligned to the SDIO block size. The maximum block size
@@ -100,6 +113,7 @@ struct wl1271_tx_hw_descr {
100 union { 113 union {
101 struct wl127x_tx_mem wl127x_mem; 114 struct wl127x_tx_mem wl127x_mem;
102 struct wl128x_tx_mem wl128x_mem; 115 struct wl128x_tx_mem wl128x_mem;
116 struct wl18xx_tx_mem wl18xx_mem;
103 } __packed; 117 } __packed;
104 /* Device time (in us) when the packet arrived to the driver */ 118 /* Device time (in us) when the packet arrived to the driver */
105 __le32 start_time; 119 __le32 start_time;
@@ -116,7 +130,16 @@ struct wl1271_tx_hw_descr {
116 u8 tid; 130 u8 tid;
117 /* host link ID (HLID) */ 131 /* host link ID (HLID) */
118 u8 hlid; 132 u8 hlid;
119 u8 reserved; 133
134 union {
135 u8 wl12xx_reserved;
136
137 /*
138 * bit 0 -> 0 = udp, 1 = tcp
139 * bit 1:7 -> IP header offset
140 */
141 u8 wl18xx_checksum_data;
142 } __packed;
120} __packed; 143} __packed;
121 144
122enum wl1271_tx_hw_res_status { 145enum wl1271_tx_hw_res_status {
@@ -161,6 +184,13 @@ struct wl1271_tx_hw_res_if {
161 struct wl1271_tx_hw_res_descr tx_results_queue[TX_HW_RESULT_QUEUE_LEN]; 184 struct wl1271_tx_hw_res_descr tx_results_queue[TX_HW_RESULT_QUEUE_LEN];
162} __packed; 185} __packed;
163 186
187enum wlcore_queue_stop_reason {
188 WLCORE_QUEUE_STOP_REASON_WATERMARK,
189 WLCORE_QUEUE_STOP_REASON_FW_RESTART,
190 WLCORE_QUEUE_STOP_REASON_FLUSH,
191 WLCORE_QUEUE_STOP_REASON_SPARE_BLK, /* 18xx specific */
192};
193
164static inline int wl1271_tx_get_queue(int queue) 194static inline int wl1271_tx_get_queue(int queue)
165{ 195{
166 switch (queue) { 196 switch (queue) {
@@ -207,7 +237,7 @@ void wl1271_tx_work(struct work_struct *work);
207void wl1271_tx_work_locked(struct wl1271 *wl); 237void wl1271_tx_work_locked(struct wl1271 *wl);
208void wl1271_tx_complete(struct wl1271 *wl); 238void wl1271_tx_complete(struct wl1271 *wl);
209void wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif); 239void wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif);
210void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues); 240void wl12xx_tx_reset(struct wl1271 *wl);
211void wl1271_tx_flush(struct wl1271 *wl); 241void wl1271_tx_flush(struct wl1271 *wl);
212u8 wlcore_rate_to_idx(struct wl1271 *wl, u8 rate, enum ieee80211_band band); 242u8 wlcore_rate_to_idx(struct wl1271 *wl, u8 rate, enum ieee80211_band band);
213u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set, 243u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set,
@@ -223,6 +253,21 @@ bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb);
223void wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids); 253void wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids);
224unsigned int wlcore_calc_packet_alignment(struct wl1271 *wl, 254unsigned int wlcore_calc_packet_alignment(struct wl1271 *wl,
225 unsigned int packet_length); 255 unsigned int packet_length);
256void wl1271_free_tx_id(struct wl1271 *wl, int id);
257void wlcore_stop_queue_locked(struct wl1271 *wl, u8 queue,
258 enum wlcore_queue_stop_reason reason);
259void wlcore_stop_queue(struct wl1271 *wl, u8 queue,
260 enum wlcore_queue_stop_reason reason);
261void wlcore_wake_queue(struct wl1271 *wl, u8 queue,
262 enum wlcore_queue_stop_reason reason);
263void wlcore_stop_queues(struct wl1271 *wl,
264 enum wlcore_queue_stop_reason reason);
265void wlcore_wake_queues(struct wl1271 *wl,
266 enum wlcore_queue_stop_reason reason);
267void wlcore_reset_stopped_queues(struct wl1271 *wl);
268bool wlcore_is_queue_stopped_by_reason(struct wl1271 *wl, u8 queue,
269 enum wlcore_queue_stop_reason reason);
270bool wlcore_is_queue_stopped(struct wl1271 *wl, u8 queue);
226 271
227/* from main.c */ 272/* from main.c */
228void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid); 273void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid);
diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
index 0b3f0b586f4b..761a72f4b8d1 100644
--- a/drivers/net/wireless/ti/wlcore/wlcore.h
+++ b/drivers/net/wireless/ti/wlcore/wlcore.h
@@ -24,8 +24,9 @@
24 24
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26 26
27#include "wl12xx.h" 27#include "wlcore_i.h"
28#include "event.h" 28#include "event.h"
29#include "boot.h"
29 30
30/* The maximum number of Tx descriptors in all chip families */ 31/* The maximum number of Tx descriptors in all chip families */
31#define WLCORE_MAX_TX_DESCRIPTORS 32 32#define WLCORE_MAX_TX_DESCRIPTORS 32
@@ -33,11 +34,13 @@
33/* forward declaration */ 34/* forward declaration */
34struct wl1271_tx_hw_descr; 35struct wl1271_tx_hw_descr;
35enum wl_rx_buf_align; 36enum wl_rx_buf_align;
37struct wl1271_rx_descriptor;
36 38
37struct wlcore_ops { 39struct wlcore_ops {
38 int (*identify_chip)(struct wl1271 *wl); 40 int (*identify_chip)(struct wl1271 *wl);
39 int (*identify_fw)(struct wl1271 *wl); 41 int (*identify_fw)(struct wl1271 *wl);
40 int (*boot)(struct wl1271 *wl); 42 int (*boot)(struct wl1271 *wl);
43 int (*plt_init)(struct wl1271 *wl);
41 void (*trigger_cmd)(struct wl1271 *wl, int cmd_box_addr, 44 void (*trigger_cmd)(struct wl1271 *wl, int cmd_box_addr,
42 void *buf, size_t len); 45 void *buf, size_t len);
43 void (*ack_event)(struct wl1271 *wl); 46 void (*ack_event)(struct wl1271 *wl);
@@ -61,6 +64,23 @@ struct wlcore_ops {
61 struct wl12xx_vif *wlvif); 64 struct wl12xx_vif *wlvif);
62 s8 (*get_pg_ver)(struct wl1271 *wl); 65 s8 (*get_pg_ver)(struct wl1271 *wl);
63 void (*get_mac)(struct wl1271 *wl); 66 void (*get_mac)(struct wl1271 *wl);
67 void (*set_tx_desc_csum)(struct wl1271 *wl,
68 struct wl1271_tx_hw_descr *desc,
69 struct sk_buff *skb);
70 void (*set_rx_csum)(struct wl1271 *wl,
71 struct wl1271_rx_descriptor *desc,
72 struct sk_buff *skb);
73 u32 (*ap_get_mimo_wide_rate_mask)(struct wl1271 *wl,
74 struct wl12xx_vif *wlvif);
75 int (*debugfs_init)(struct wl1271 *wl, struct dentry *rootdir);
76 int (*handle_static_data)(struct wl1271 *wl,
77 struct wl1271_static_data *static_data);
78 int (*get_spare_blocks)(struct wl1271 *wl, bool is_gem);
79 int (*set_key)(struct wl1271 *wl, enum set_key_cmd cmd,
80 struct ieee80211_vif *vif,
81 struct ieee80211_sta *sta,
82 struct ieee80211_key_conf *key_conf);
83 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
64}; 84};
65 85
66enum wlcore_partitions { 86enum wlcore_partitions {
@@ -109,6 +129,15 @@ enum wlcore_registers {
109 REG_TABLE_LEN, 129 REG_TABLE_LEN,
110}; 130};
111 131
132struct wl1271_stats {
133 void *fw_stats;
134 unsigned long fw_stats_update;
135 size_t fw_stats_len;
136
137 unsigned int retry_count;
138 unsigned int excessive_retries;
139};
140
112struct wl1271 { 141struct wl1271 {
113 struct ieee80211_hw *hw; 142 struct ieee80211_hw *hw;
114 bool mac80211_registered; 143 bool mac80211_registered;
@@ -121,7 +150,6 @@ struct wl1271 {
121 150
122 void (*set_power)(bool enable); 151 void (*set_power)(bool enable);
123 int irq; 152 int irq;
124 int ref_clock;
125 153
126 spinlock_t wl_lock; 154 spinlock_t wl_lock;
127 155
@@ -186,7 +214,7 @@ struct wl1271 {
186 214
187 /* Frames scheduled for transmission, not handled yet */ 215 /* Frames scheduled for transmission, not handled yet */
188 int tx_queue_count[NUM_TX_QUEUES]; 216 int tx_queue_count[NUM_TX_QUEUES];
189 long stopped_queues_map; 217 unsigned long queue_stop_reasons[NUM_TX_QUEUES];
190 218
191 /* Frames received, not handled yet by mac80211 */ 219 /* Frames received, not handled yet by mac80211 */
192 struct sk_buff_head deferred_rx_queue; 220 struct sk_buff_head deferred_rx_queue;
@@ -205,9 +233,6 @@ struct wl1271 {
205 /* FW Rx counter */ 233 /* FW Rx counter */
206 u32 rx_counter; 234 u32 rx_counter;
207 235
208 /* Rx memory pool address */
209 struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
210
211 /* Intermediate buffer, used for packet aggregation */ 236 /* Intermediate buffer, used for packet aggregation */
212 u8 *aggr_buf; 237 u8 *aggr_buf;
213 238
@@ -228,6 +253,7 @@ struct wl1271 {
228 253
229 /* Hardware recovery work */ 254 /* Hardware recovery work */
230 struct work_struct recovery_work; 255 struct work_struct recovery_work;
256 bool watchdog_recovery;
231 257
232 /* Pointer that holds DMA-friendly block for the mailbox */ 258 /* Pointer that holds DMA-friendly block for the mailbox */
233 struct event_mailbox *mbox; 259 struct event_mailbox *mbox;
@@ -263,7 +289,8 @@ struct wl1271 {
263 u32 buffer_cmd; 289 u32 buffer_cmd;
264 u32 buffer_busyword[WL1271_BUSY_WORD_CNT]; 290 u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
265 291
266 struct wl_fw_status *fw_status; 292 struct wl_fw_status_1 *fw_status_1;
293 struct wl_fw_status_2 *fw_status_2;
267 struct wl1271_tx_hw_res_if *tx_res_if; 294 struct wl1271_tx_hw_res_if *tx_res_if;
268 295
269 /* Current chipset configuration */ 296 /* Current chipset configuration */
@@ -279,8 +306,6 @@ struct wl1271 {
279 /* bands supported by this instance of wl12xx */ 306 /* bands supported by this instance of wl12xx */
280 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS]; 307 struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
281 308
282 int tcxo_clock;
283
284 /* 309 /*
285 * wowlan trigger was configured during suspend. 310 * wowlan trigger was configured during suspend.
286 * (currently, only "ANY" trigger is supported) 311 * (currently, only "ANY" trigger is supported)
@@ -333,10 +358,8 @@ struct wl1271 {
333 358
334 /* number of TX descriptors the HW supports. */ 359 /* number of TX descriptors the HW supports. */
335 u32 num_tx_desc; 360 u32 num_tx_desc;
336 361 /* number of RX descriptors the HW supports. */
337 /* spare Tx blocks for normal/GEM operating modes */ 362 u32 num_rx_desc;
338 u32 normal_tx_spare;
339 u32 gem_tx_spare;
340 363
341 /* translate HW Tx rates to standard rate-indices */ 364 /* translate HW Tx rates to standard rate-indices */
342 const u8 **band_rate_to_idx; 365 const u8 **band_rate_to_idx;
@@ -348,19 +371,32 @@ struct wl1271 {
348 u8 hw_min_ht_rate; 371 u8 hw_min_ht_rate;
349 372
350 /* HW HT (11n) capabilities */ 373 /* HW HT (11n) capabilities */
351 struct ieee80211_sta_ht_cap ht_cap; 374 struct ieee80211_sta_ht_cap ht_cap[IEEE80211_NUM_BANDS];
352 375
353 /* size of the private FW status data */ 376 /* size of the private FW status data */
354 size_t fw_status_priv_len; 377 size_t fw_status_priv_len;
355 378
356 /* RX Data filter rule state - enabled/disabled */ 379 /* RX Data filter rule state - enabled/disabled */
357 bool rx_filter_enabled[WL1271_MAX_RX_FILTERS]; 380 bool rx_filter_enabled[WL1271_MAX_RX_FILTERS];
381
382 /* size of the private static data */
383 size_t static_data_priv_len;
384
385 /* the current channel type */
386 enum nl80211_channel_type channel_type;
387
388 /* mutex for protecting the tx_flush function */
389 struct mutex flush_mutex;
358}; 390};
359 391
360int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev); 392int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev);
361int __devexit wlcore_remove(struct platform_device *pdev); 393int __devexit wlcore_remove(struct platform_device *pdev);
362struct ieee80211_hw *wlcore_alloc_hw(size_t priv_size); 394struct ieee80211_hw *wlcore_alloc_hw(size_t priv_size);
363int wlcore_free_hw(struct wl1271 *wl); 395int wlcore_free_hw(struct wl1271 *wl);
396int wlcore_set_key(struct wl1271 *wl, enum set_key_cmd cmd,
397 struct ieee80211_vif *vif,
398 struct ieee80211_sta *sta,
399 struct ieee80211_key_conf *key_conf);
364 400
365/* Firmware image load chunk size */ 401/* Firmware image load chunk size */
366#define CHUNK_SIZE 16384 402#define CHUNK_SIZE 16384
@@ -385,6 +421,12 @@ int wlcore_free_hw(struct wl1271 *wl);
385/* Some firmwares may not support ELP */ 421/* Some firmwares may not support ELP */
386#define WLCORE_QUIRK_NO_ELP BIT(6) 422#define WLCORE_QUIRK_NO_ELP BIT(6)
387 423
424/* pad only the last frame in the aggregate buffer */
425#define WLCORE_QUIRK_TX_PAD_LAST_FRAME BIT(7)
426
427/* extra header space is required for TKIP */
428#define WLCORE_QUIRK_TKIP_HEADER_SPACE BIT(8)
429
388/* TODO: move to the lower drivers when all usages are abstracted */ 430/* TODO: move to the lower drivers when all usages are abstracted */
389#define CHIP_ID_1271_PG10 (0x4030101) 431#define CHIP_ID_1271_PG10 (0x4030101)
390#define CHIP_ID_1271_PG20 (0x4030111) 432#define CHIP_ID_1271_PG20 (0x4030111)
diff --git a/drivers/net/wireless/ti/wlcore/wl12xx.h b/drivers/net/wireless/ti/wlcore/wlcore_i.h
index f12bdf745180..8260b1e9288a 100644
--- a/drivers/net/wireless/ti/wlcore/wl12xx.h
+++ b/drivers/net/wireless/ti/wlcore/wlcore_i.h
@@ -22,8 +22,8 @@
22 * 22 *
23 */ 23 */
24 24
25#ifndef __WL12XX_H__ 25#ifndef __WLCORE_I_H__
26#define __WL12XX_H__ 26#define __WLCORE_I_H__
27 27
28#include <linux/mutex.h> 28#include <linux/mutex.h>
29#include <linux/completion.h> 29#include <linux/completion.h>
@@ -89,7 +89,7 @@
89#define WL1271_AP_BSS_INDEX 0 89#define WL1271_AP_BSS_INDEX 0
90#define WL1271_AP_DEF_BEACON_EXP 20 90#define WL1271_AP_DEF_BEACON_EXP 20
91 91
92#define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE) 92#define WL1271_AGGR_BUFFER_SIZE (5 * PAGE_SIZE)
93 93
94enum wl1271_state { 94enum wl1271_state {
95 WL1271_STATE_OFF, 95 WL1271_STATE_OFF,
@@ -132,16 +132,7 @@ struct wl1271_chip {
132 unsigned int fw_ver[NUM_FW_VER]; 132 unsigned int fw_ver[NUM_FW_VER];
133}; 133};
134 134
135struct wl1271_stats {
136 struct acx_statistics *fw_stats;
137 unsigned long fw_stats_update;
138
139 unsigned int retry_count;
140 unsigned int excessive_retries;
141};
142
143#define NUM_TX_QUEUES 4 135#define NUM_TX_QUEUES 4
144#define NUM_RX_PKT_DESC 8
145 136
146#define AP_MAX_STATIONS 8 137#define AP_MAX_STATIONS 8
147 138
@@ -159,13 +150,26 @@ struct wl_fw_packet_counters {
159} __packed; 150} __packed;
160 151
161/* FW status registers */ 152/* FW status registers */
162struct wl_fw_status { 153struct wl_fw_status_1 {
163 __le32 intr; 154 __le32 intr;
164 u8 fw_rx_counter; 155 u8 fw_rx_counter;
165 u8 drv_rx_counter; 156 u8 drv_rx_counter;
166 u8 reserved; 157 u8 reserved;
167 u8 tx_results_counter; 158 u8 tx_results_counter;
168 __le32 rx_pkt_descs[NUM_RX_PKT_DESC]; 159 __le32 rx_pkt_descs[0];
160} __packed;
161
162/*
163 * Each HW arch has a different number of Rx descriptors.
164 * The length of the status depends on it, since it holds an array
165 * of descriptors.
166 */
167#define WLCORE_FW_STATUS_1_LEN(num_rx_desc) \
168 (sizeof(struct wl_fw_status_1) + \
169 (sizeof(((struct wl_fw_status_1 *)0)->rx_pkt_descs[0])) * \
170 num_rx_desc)
171
172struct wl_fw_status_2 {
169 __le32 fw_localtime; 173 __le32 fw_localtime;
170 174
171 /* 175 /*
@@ -194,11 +198,6 @@ struct wl_fw_status {
194 u8 priv[0]; 198 u8 priv[0];
195} __packed; 199} __packed;
196 200
197struct wl1271_rx_mem_pool_addr {
198 u32 addr;
199 u32 addr_extra;
200};
201
202#define WL1271_MAX_CHANNELS 64 201#define WL1271_MAX_CHANNELS 64
203struct wl1271_scan { 202struct wl1271_scan {
204 struct cfg80211_scan_request *req; 203 struct cfg80211_scan_request *req;
@@ -367,6 +366,7 @@ struct wl12xx_vif {
367 /* The current band */ 366 /* The current band */
368 enum ieee80211_band band; 367 enum ieee80211_band band;
369 int channel; 368 int channel;
369 enum nl80211_channel_type channel_type;
370 370
371 u32 bitrate_masks[IEEE80211_NUM_BANDS]; 371 u32 bitrate_masks[IEEE80211_NUM_BANDS];
372 u32 basic_rate_set; 372 u32 basic_rate_set;
@@ -417,9 +417,6 @@ struct wl12xx_vif {
417 struct work_struct rx_streaming_disable_work; 417 struct work_struct rx_streaming_disable_work;
418 struct timer_list rx_streaming_timer; 418 struct timer_list rx_streaming_timer;
419 419
420 /* does the current role use GEM for encryption (AP or STA) */
421 bool is_gem;
422
423 /* 420 /*
424 * This struct must be last! 421 * This struct must be last!
425 * data that has to be saved acrossed reconfigs (e.g. recovery) 422 * data that has to be saved acrossed reconfigs (e.g. recovery)
@@ -501,7 +498,8 @@ void wl1271_rx_filter_flatten_fields(struct wl12xx_rx_filter *filter,
501/* Macros to handle wl1271.sta_rate_set */ 498/* Macros to handle wl1271.sta_rate_set */
502#define HW_BG_RATES_MASK 0xffff 499#define HW_BG_RATES_MASK 0xffff
503#define HW_HT_RATES_OFFSET 16 500#define HW_HT_RATES_OFFSET 16
501#define HW_MIMO_RATES_OFFSET 24
504 502
505#define WL12XX_HW_BLOCK_SIZE 256 503#define WL12XX_HW_BLOCK_SIZE 256
506 504
507#endif 505#endif /* __WLCORE_I_H__ */
diff --git a/drivers/nfc/pn533.c b/drivers/nfc/pn533.c
index 19110f0eb15f..9ac829e22e73 100644
--- a/drivers/nfc/pn533.c
+++ b/drivers/nfc/pn533.c
@@ -45,6 +45,9 @@ static const struct usb_device_id pn533_table[] = {
45}; 45};
46MODULE_DEVICE_TABLE(usb, pn533_table); 46MODULE_DEVICE_TABLE(usb, pn533_table);
47 47
48/* How much time we spend listening for initiators */
49#define PN533_LISTEN_TIME 2
50
48/* frame definitions */ 51/* frame definitions */
49#define PN533_FRAME_TAIL_SIZE 2 52#define PN533_FRAME_TAIL_SIZE 2
50#define PN533_FRAME_SIZE(f) (sizeof(struct pn533_frame) + f->datalen + \ 53#define PN533_FRAME_SIZE(f) (sizeof(struct pn533_frame) + f->datalen + \
@@ -74,6 +77,10 @@ MODULE_DEVICE_TABLE(usb, pn533_table);
74#define PN533_CMD_IN_RELEASE 0x52 77#define PN533_CMD_IN_RELEASE 0x52
75#define PN533_CMD_IN_JUMP_FOR_DEP 0x56 78#define PN533_CMD_IN_JUMP_FOR_DEP 0x56
76 79
80#define PN533_CMD_TG_INIT_AS_TARGET 0x8c
81#define PN533_CMD_TG_GET_DATA 0x86
82#define PN533_CMD_TG_SET_DATA 0x8e
83
77#define PN533_CMD_RESPONSE(cmd) (cmd + 1) 84#define PN533_CMD_RESPONSE(cmd) (cmd + 1)
78 85
79/* PN533 Return codes */ 86/* PN533 Return codes */
@@ -81,6 +88,9 @@ MODULE_DEVICE_TABLE(usb, pn533_table);
81#define PN533_CMD_MI_MASK 0x40 88#define PN533_CMD_MI_MASK 0x40
82#define PN533_CMD_RET_SUCCESS 0x00 89#define PN533_CMD_RET_SUCCESS 0x00
83 90
91/* PN533 status codes */
92#define PN533_STATUS_TARGET_RELEASED 0x29
93
84struct pn533; 94struct pn533;
85 95
86typedef int (*pn533_cmd_complete_t) (struct pn533 *dev, void *arg, 96typedef int (*pn533_cmd_complete_t) (struct pn533 *dev, void *arg,
@@ -97,8 +107,14 @@ struct pn533_fw_version {
97}; 107};
98 108
99/* PN533_CMD_RF_CONFIGURATION */ 109/* PN533_CMD_RF_CONFIGURATION */
110#define PN533_CFGITEM_TIMING 0x02
100#define PN533_CFGITEM_MAX_RETRIES 0x05 111#define PN533_CFGITEM_MAX_RETRIES 0x05
101 112
113#define PN533_CONFIG_TIMING_102 0xb
114#define PN533_CONFIG_TIMING_204 0xc
115#define PN533_CONFIG_TIMING_409 0xd
116#define PN533_CONFIG_TIMING_819 0xe
117
102#define PN533_CONFIG_MAX_RETRIES_NO_RETRY 0x00 118#define PN533_CONFIG_MAX_RETRIES_NO_RETRY 0x00
103#define PN533_CONFIG_MAX_RETRIES_ENDLESS 0xFF 119#define PN533_CONFIG_MAX_RETRIES_ENDLESS 0xFF
104 120
@@ -108,6 +124,12 @@ struct pn533_config_max_retries {
108 u8 mx_rty_passive_act; 124 u8 mx_rty_passive_act;
109} __packed; 125} __packed;
110 126
127struct pn533_config_timing {
128 u8 rfu;
129 u8 atr_res_timeout;
130 u8 dep_timeout;
131} __packed;
132
111/* PN533_CMD_IN_LIST_PASSIVE_TARGET */ 133/* PN533_CMD_IN_LIST_PASSIVE_TARGET */
112 134
113/* felica commands opcode */ 135/* felica commands opcode */
@@ -144,6 +166,7 @@ enum {
144 PN533_POLL_MOD_424KBPS_FELICA, 166 PN533_POLL_MOD_424KBPS_FELICA,
145 PN533_POLL_MOD_106KBPS_JEWEL, 167 PN533_POLL_MOD_106KBPS_JEWEL,
146 PN533_POLL_MOD_847KBPS_B, 168 PN533_POLL_MOD_847KBPS_B,
169 PN533_LISTEN_MOD,
147 170
148 __PN533_POLL_MOD_AFTER_LAST, 171 __PN533_POLL_MOD_AFTER_LAST,
149}; 172};
@@ -211,6 +234,9 @@ const struct pn533_poll_modulations poll_mod[] = {
211 }, 234 },
212 .len = 3, 235 .len = 3,
213 }, 236 },
237 [PN533_LISTEN_MOD] = {
238 .len = 0,
239 },
214}; 240};
215 241
216/* PN533_CMD_IN_ATR */ 242/* PN533_CMD_IN_ATR */
@@ -237,7 +263,7 @@ struct pn533_cmd_jump_dep {
237 u8 active; 263 u8 active;
238 u8 baud; 264 u8 baud;
239 u8 next; 265 u8 next;
240 u8 gt[]; 266 u8 data[];
241} __packed; 267} __packed;
242 268
243struct pn533_cmd_jump_dep_response { 269struct pn533_cmd_jump_dep_response {
@@ -253,6 +279,29 @@ struct pn533_cmd_jump_dep_response {
253 u8 gt[]; 279 u8 gt[];
254} __packed; 280} __packed;
255 281
282
283/* PN533_TG_INIT_AS_TARGET */
284#define PN533_INIT_TARGET_PASSIVE 0x1
285#define PN533_INIT_TARGET_DEP 0x2
286
287#define PN533_INIT_TARGET_RESP_FRAME_MASK 0x3
288#define PN533_INIT_TARGET_RESP_ACTIVE 0x1
289#define PN533_INIT_TARGET_RESP_DEP 0x4
290
291struct pn533_cmd_init_target {
292 u8 mode;
293 u8 mifare[6];
294 u8 felica[18];
295 u8 nfcid3[10];
296 u8 gb_len;
297 u8 gb[];
298} __packed;
299
300struct pn533_cmd_init_target_response {
301 u8 mode;
302 u8 cmd[];
303} __packed;
304
256struct pn533 { 305struct pn533 {
257 struct usb_device *udev; 306 struct usb_device *udev;
258 struct usb_interface *interface; 307 struct usb_interface *interface;
@@ -270,22 +319,31 @@ struct pn533 {
270 319
271 struct workqueue_struct *wq; 320 struct workqueue_struct *wq;
272 struct work_struct cmd_work; 321 struct work_struct cmd_work;
322 struct work_struct poll_work;
273 struct work_struct mi_work; 323 struct work_struct mi_work;
324 struct work_struct tg_work;
325 struct timer_list listen_timer;
274 struct pn533_frame *wq_in_frame; 326 struct pn533_frame *wq_in_frame;
275 int wq_in_error; 327 int wq_in_error;
328 int cancel_listen;
276 329
277 pn533_cmd_complete_t cmd_complete; 330 pn533_cmd_complete_t cmd_complete;
278 void *cmd_complete_arg; 331 void *cmd_complete_arg;
279 struct semaphore cmd_lock; 332 struct mutex cmd_lock;
280 u8 cmd; 333 u8 cmd;
281 334
282 struct pn533_poll_modulations *poll_mod_active[PN533_POLL_MOD_MAX + 1]; 335 struct pn533_poll_modulations *poll_mod_active[PN533_POLL_MOD_MAX + 1];
283 u8 poll_mod_count; 336 u8 poll_mod_count;
284 u8 poll_mod_curr; 337 u8 poll_mod_curr;
285 u32 poll_protocols; 338 u32 poll_protocols;
339 u32 listen_protocols;
340
341 u8 *gb;
342 size_t gb_len;
286 343
287 u8 tgt_available_prots; 344 u8 tgt_available_prots;
288 u8 tgt_active_prot; 345 u8 tgt_active_prot;
346 u8 tgt_mode;
289}; 347};
290 348
291struct pn533_frame { 349struct pn533_frame {
@@ -405,7 +463,7 @@ static void pn533_wq_cmd_complete(struct work_struct *work)
405 PN533_FRAME_CMD_PARAMS_LEN(in_frame)); 463 PN533_FRAME_CMD_PARAMS_LEN(in_frame));
406 464
407 if (rc != -EINPROGRESS) 465 if (rc != -EINPROGRESS)
408 up(&dev->cmd_lock); 466 mutex_unlock(&dev->cmd_lock);
409} 467}
410 468
411static void pn533_recv_response(struct urb *urb) 469static void pn533_recv_response(struct urb *urb)
@@ -583,7 +641,7 @@ static int pn533_send_cmd_frame_async(struct pn533 *dev,
583 641
584 nfc_dev_dbg(&dev->interface->dev, "%s", __func__); 642 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
585 643
586 if (down_trylock(&dev->cmd_lock)) 644 if (!mutex_trylock(&dev->cmd_lock))
587 return -EBUSY; 645 return -EBUSY;
588 646
589 rc = __pn533_send_cmd_frame_async(dev, out_frame, in_frame, 647 rc = __pn533_send_cmd_frame_async(dev, out_frame, in_frame,
@@ -593,7 +651,7 @@ static int pn533_send_cmd_frame_async(struct pn533 *dev,
593 651
594 return 0; 652 return 0;
595error: 653error:
596 up(&dev->cmd_lock); 654 mutex_unlock(&dev->cmd_lock);
597 return rc; 655 return rc;
598} 656}
599 657
@@ -963,6 +1021,11 @@ static int pn533_target_found(struct pn533 *dev,
963 return 0; 1021 return 0;
964} 1022}
965 1023
1024static inline void pn533_poll_next_mod(struct pn533 *dev)
1025{
1026 dev->poll_mod_curr = (dev->poll_mod_curr + 1) % dev->poll_mod_count;
1027}
1028
966static void pn533_poll_reset_mod_list(struct pn533 *dev) 1029static void pn533_poll_reset_mod_list(struct pn533 *dev)
967{ 1030{
968 dev->poll_mod_count = 0; 1031 dev->poll_mod_count = 0;
@@ -975,102 +1038,283 @@ static void pn533_poll_add_mod(struct pn533 *dev, u8 mod_index)
975 dev->poll_mod_count++; 1038 dev->poll_mod_count++;
976} 1039}
977 1040
978static void pn533_poll_create_mod_list(struct pn533 *dev, u32 protocols) 1041static void pn533_poll_create_mod_list(struct pn533 *dev,
1042 u32 im_protocols, u32 tm_protocols)
979{ 1043{
980 pn533_poll_reset_mod_list(dev); 1044 pn533_poll_reset_mod_list(dev);
981 1045
982 if (protocols & NFC_PROTO_MIFARE_MASK 1046 if (im_protocols & NFC_PROTO_MIFARE_MASK
983 || protocols & NFC_PROTO_ISO14443_MASK 1047 || im_protocols & NFC_PROTO_ISO14443_MASK
984 || protocols & NFC_PROTO_NFC_DEP_MASK) 1048 || im_protocols & NFC_PROTO_NFC_DEP_MASK)
985 pn533_poll_add_mod(dev, PN533_POLL_MOD_106KBPS_A); 1049 pn533_poll_add_mod(dev, PN533_POLL_MOD_106KBPS_A);
986 1050
987 if (protocols & NFC_PROTO_FELICA_MASK 1051 if (im_protocols & NFC_PROTO_FELICA_MASK
988 || protocols & NFC_PROTO_NFC_DEP_MASK) { 1052 || im_protocols & NFC_PROTO_NFC_DEP_MASK) {
989 pn533_poll_add_mod(dev, PN533_POLL_MOD_212KBPS_FELICA); 1053 pn533_poll_add_mod(dev, PN533_POLL_MOD_212KBPS_FELICA);
990 pn533_poll_add_mod(dev, PN533_POLL_MOD_424KBPS_FELICA); 1054 pn533_poll_add_mod(dev, PN533_POLL_MOD_424KBPS_FELICA);
991 } 1055 }
992 1056
993 if (protocols & NFC_PROTO_JEWEL_MASK) 1057 if (im_protocols & NFC_PROTO_JEWEL_MASK)
994 pn533_poll_add_mod(dev, PN533_POLL_MOD_106KBPS_JEWEL); 1058 pn533_poll_add_mod(dev, PN533_POLL_MOD_106KBPS_JEWEL);
995 1059
996 if (protocols & NFC_PROTO_ISO14443_MASK) 1060 if (im_protocols & NFC_PROTO_ISO14443_MASK)
997 pn533_poll_add_mod(dev, PN533_POLL_MOD_847KBPS_B); 1061 pn533_poll_add_mod(dev, PN533_POLL_MOD_847KBPS_B);
1062
1063 if (tm_protocols)
1064 pn533_poll_add_mod(dev, PN533_LISTEN_MOD);
1065}
1066
1067static int pn533_start_poll_complete(struct pn533 *dev, void *arg,
1068 u8 *params, int params_len)
1069{
1070 struct pn533_poll_response *resp;
1071 int rc;
1072
1073 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1074
1075 resp = (struct pn533_poll_response *) params;
1076 if (resp->nbtg) {
1077 rc = pn533_target_found(dev, resp, params_len);
1078
1079 /* We must stop the poll after a valid target found */
1080 if (rc == 0) {
1081 pn533_poll_reset_mod_list(dev);
1082 return 0;
1083 }
1084 }
1085
1086 return -EAGAIN;
998} 1087}
999 1088
1000static void pn533_start_poll_frame(struct pn533_frame *frame, 1089static int pn533_init_target_frame(struct pn533_frame *frame,
1001 struct pn533_poll_modulations *mod) 1090 u8 *gb, size_t gb_len)
1002{ 1091{
1092 struct pn533_cmd_init_target *cmd;
1093 size_t cmd_len;
1094 u8 felica_params[18] = {0x1, 0xfe, /* DEP */
1095 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, /* random */
1096 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
1097 0xff, 0xff}; /* System code */
1098 u8 mifare_params[6] = {0x1, 0x1, /* SENS_RES */
1099 0x0, 0x0, 0x0,
1100 0x40}; /* SEL_RES for DEP */
1101
1102 cmd_len = sizeof(struct pn533_cmd_init_target) + gb_len + 1;
1103 cmd = kzalloc(cmd_len, GFP_KERNEL);
1104 if (cmd == NULL)
1105 return -ENOMEM;
1106
1107 pn533_tx_frame_init(frame, PN533_CMD_TG_INIT_AS_TARGET);
1108
1109 /* DEP support only */
1110 cmd->mode |= PN533_INIT_TARGET_DEP;
1111
1112 /* Felica params */
1113 memcpy(cmd->felica, felica_params, 18);
1114 get_random_bytes(cmd->felica + 2, 6);
1115
1116 /* NFCID3 */
1117 memset(cmd->nfcid3, 0, 10);
1118 memcpy(cmd->nfcid3, cmd->felica, 8);
1003 1119
1004 pn533_tx_frame_init(frame, PN533_CMD_IN_LIST_PASSIVE_TARGET); 1120 /* MIFARE params */
1121 memcpy(cmd->mifare, mifare_params, 6);
1005 1122
1006 memcpy(PN533_FRAME_CMD_PARAMS_PTR(frame), &mod->data, mod->len); 1123 /* General bytes */
1007 frame->datalen += mod->len; 1124 cmd->gb_len = gb_len;
1125 memcpy(cmd->gb, gb, gb_len);
1126
1127 /* Len Tk */
1128 cmd->gb[gb_len] = 0;
1129
1130 memcpy(PN533_FRAME_CMD_PARAMS_PTR(frame), cmd, cmd_len);
1131
1132 frame->datalen += cmd_len;
1008 1133
1009 pn533_tx_frame_finish(frame); 1134 pn533_tx_frame_finish(frame);
1135
1136 kfree(cmd);
1137
1138 return 0;
1010} 1139}
1011 1140
1012static int pn533_start_poll_complete(struct pn533 *dev, void *arg, 1141#define PN533_CMD_DATAEXCH_HEAD_LEN (sizeof(struct pn533_frame) + 3)
1013 u8 *params, int params_len) 1142#define PN533_CMD_DATAEXCH_DATA_MAXLEN 262
1143static int pn533_tm_get_data_complete(struct pn533 *dev, void *arg,
1144 u8 *params, int params_len)
1014{ 1145{
1015 struct pn533_poll_response *resp; 1146 struct sk_buff *skb_resp = arg;
1016 struct pn533_poll_modulations *next_mod; 1147 struct pn533_frame *in_frame = (struct pn533_frame *) skb_resp->data;
1017 int rc;
1018 1148
1019 nfc_dev_dbg(&dev->interface->dev, "%s", __func__); 1149 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1020 1150
1021 if (params_len == -ENOENT) { 1151 if (params_len < 0) {
1022 nfc_dev_dbg(&dev->interface->dev, "Polling operation has been" 1152 nfc_dev_err(&dev->interface->dev,
1023 " stopped"); 1153 "Error %d when starting as a target",
1024 goto stop_poll; 1154 params_len);
1155
1156 return params_len;
1025 } 1157 }
1026 1158
1159 if (params_len > 0 && params[0] != 0) {
1160 nfc_tm_deactivated(dev->nfc_dev);
1161
1162 dev->tgt_mode = 0;
1163
1164 kfree_skb(skb_resp);
1165 return 0;
1166 }
1167
1168 skb_put(skb_resp, PN533_FRAME_SIZE(in_frame));
1169 skb_pull(skb_resp, PN533_CMD_DATAEXCH_HEAD_LEN);
1170 skb_trim(skb_resp, skb_resp->len - PN533_FRAME_TAIL_SIZE);
1171
1172 return nfc_tm_data_received(dev->nfc_dev, skb_resp);
1173}
1174
1175static void pn533_wq_tg_get_data(struct work_struct *work)
1176{
1177 struct pn533 *dev = container_of(work, struct pn533, tg_work);
1178 struct pn533_frame *in_frame;
1179 struct sk_buff *skb_resp;
1180 size_t skb_resp_len;
1181
1182 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1183
1184 skb_resp_len = PN533_CMD_DATAEXCH_HEAD_LEN +
1185 PN533_CMD_DATAEXCH_DATA_MAXLEN +
1186 PN533_FRAME_TAIL_SIZE;
1187
1188 skb_resp = nfc_alloc_recv_skb(skb_resp_len, GFP_KERNEL);
1189 if (!skb_resp)
1190 return;
1191
1192 in_frame = (struct pn533_frame *)skb_resp->data;
1193
1194 pn533_tx_frame_init(dev->out_frame, PN533_CMD_TG_GET_DATA);
1195 pn533_tx_frame_finish(dev->out_frame);
1196
1197 pn533_send_cmd_frame_async(dev, dev->out_frame, in_frame,
1198 skb_resp_len,
1199 pn533_tm_get_data_complete,
1200 skb_resp, GFP_KERNEL);
1201
1202 return;
1203}
1204
1205#define ATR_REQ_GB_OFFSET 17
1206static int pn533_init_target_complete(struct pn533 *dev, void *arg,
1207 u8 *params, int params_len)
1208{
1209 struct pn533_cmd_init_target_response *resp;
1210 u8 frame, comm_mode = NFC_COMM_PASSIVE, *gb;
1211 size_t gb_len;
1212 int rc;
1213
1214 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1215
1027 if (params_len < 0) { 1216 if (params_len < 0) {
1028 nfc_dev_err(&dev->interface->dev, "Error %d when running poll", 1217 nfc_dev_err(&dev->interface->dev,
1029 params_len); 1218 "Error %d when starting as a target",
1030 goto stop_poll; 1219 params_len);
1220
1221 return params_len;
1031 } 1222 }
1032 1223
1033 resp = (struct pn533_poll_response *) params; 1224 if (params_len < ATR_REQ_GB_OFFSET + 1)
1034 if (resp->nbtg) { 1225 return -EINVAL;
1035 rc = pn533_target_found(dev, resp, params_len);
1036 1226
1037 /* We must stop the poll after a valid target found */ 1227 resp = (struct pn533_cmd_init_target_response *) params;
1038 if (rc == 0) 1228
1039 goto stop_poll; 1229 nfc_dev_dbg(&dev->interface->dev, "Target mode 0x%x param len %d\n",
1230 resp->mode, params_len);
1231
1232 frame = resp->mode & PN533_INIT_TARGET_RESP_FRAME_MASK;
1233 if (frame == PN533_INIT_TARGET_RESP_ACTIVE)
1234 comm_mode = NFC_COMM_ACTIVE;
1040 1235
1041 if (rc != -EAGAIN) 1236 /* Again, only DEP */
1042 nfc_dev_err(&dev->interface->dev, "The target found is" 1237 if ((resp->mode & PN533_INIT_TARGET_RESP_DEP) == 0)
1043 " not valid - continuing to poll"); 1238 return -EOPNOTSUPP;
1239
1240 gb = resp->cmd + ATR_REQ_GB_OFFSET;
1241 gb_len = params_len - (ATR_REQ_GB_OFFSET + 1);
1242
1243 rc = nfc_tm_activated(dev->nfc_dev, NFC_PROTO_NFC_DEP_MASK,
1244 comm_mode, gb, gb_len);
1245 if (rc < 0) {
1246 nfc_dev_err(&dev->interface->dev,
1247 "Error when signaling target activation");
1248 return rc;
1044 } 1249 }
1045 1250
1046 dev->poll_mod_curr = (dev->poll_mod_curr + 1) % dev->poll_mod_count; 1251 dev->tgt_mode = 1;
1047 1252
1048 next_mod = dev->poll_mod_active[dev->poll_mod_curr]; 1253 queue_work(dev->wq, &dev->tg_work);
1049 1254
1050 nfc_dev_dbg(&dev->interface->dev, "Polling next modulation (0x%x)", 1255 return 0;
1051 dev->poll_mod_curr); 1256}
1257
1258static void pn533_listen_mode_timer(unsigned long data)
1259{
1260 struct pn533 *dev = (struct pn533 *) data;
1261
1262 nfc_dev_dbg(&dev->interface->dev, "Listen mode timeout");
1263
1264 /* An ack will cancel the last issued command (poll) */
1265 pn533_send_ack(dev, GFP_ATOMIC);
1266
1267 dev->cancel_listen = 1;
1268
1269 mutex_unlock(&dev->cmd_lock);
1270
1271 pn533_poll_next_mod(dev);
1272
1273 queue_work(dev->wq, &dev->poll_work);
1274}
1052 1275
1053 pn533_start_poll_frame(dev->out_frame, next_mod); 1276static int pn533_poll_complete(struct pn533 *dev, void *arg,
1277 u8 *params, int params_len)
1278{
1279 struct pn533_poll_modulations *cur_mod;
1280 int rc;
1054 1281
1055 /* Don't need to down the semaphore again */ 1282 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1056 rc = __pn533_send_cmd_frame_async(dev, dev->out_frame, dev->in_frame, 1283
1057 dev->in_maxlen, pn533_start_poll_complete, 1284 if (params_len == -ENOENT) {
1058 NULL, GFP_ATOMIC); 1285 if (dev->poll_mod_count != 0)
1286 return 0;
1287
1288 nfc_dev_err(&dev->interface->dev,
1289 "Polling operation has been stopped");
1059 1290
1060 if (rc == -EPERM) {
1061 nfc_dev_dbg(&dev->interface->dev, "Cannot poll next modulation"
1062 " because poll has been stopped");
1063 goto stop_poll; 1291 goto stop_poll;
1064 } 1292 }
1065 1293
1066 if (rc) { 1294 if (params_len < 0) {
1067 nfc_dev_err(&dev->interface->dev, "Error %d when trying to poll" 1295 nfc_dev_err(&dev->interface->dev,
1068 " next modulation", rc); 1296 "Error %d when running poll", params_len);
1297
1069 goto stop_poll; 1298 goto stop_poll;
1070 } 1299 }
1071 1300
1072 /* Inform caller function to do not up the semaphore */ 1301 cur_mod = dev->poll_mod_active[dev->poll_mod_curr];
1073 return -EINPROGRESS; 1302
1303 if (cur_mod->len == 0) {
1304 del_timer(&dev->listen_timer);
1305
1306 return pn533_init_target_complete(dev, arg, params, params_len);
1307 } else {
1308 rc = pn533_start_poll_complete(dev, arg, params, params_len);
1309 if (!rc)
1310 return rc;
1311 }
1312
1313 pn533_poll_next_mod(dev);
1314
1315 queue_work(dev->wq, &dev->poll_work);
1316
1317 return 0;
1074 1318
1075stop_poll: 1319stop_poll:
1076 pn533_poll_reset_mod_list(dev); 1320 pn533_poll_reset_mod_list(dev);
@@ -1078,61 +1322,104 @@ stop_poll:
1078 return 0; 1322 return 0;
1079} 1323}
1080 1324
1081static int pn533_start_poll(struct nfc_dev *nfc_dev, u32 protocols) 1325static void pn533_build_poll_frame(struct pn533 *dev,
1326 struct pn533_frame *frame,
1327 struct pn533_poll_modulations *mod)
1082{ 1328{
1083 struct pn533 *dev = nfc_get_drvdata(nfc_dev); 1329 nfc_dev_dbg(&dev->interface->dev, "mod len %d\n", mod->len);
1084 struct pn533_poll_modulations *start_mod;
1085 int rc;
1086 1330
1087 nfc_dev_dbg(&dev->interface->dev, "%s - protocols=0x%x", __func__, 1331 if (mod->len == 0) {
1088 protocols); 1332 /* Listen mode */
1333 pn533_init_target_frame(frame, dev->gb, dev->gb_len);
1334 } else {
1335 /* Polling mode */
1336 pn533_tx_frame_init(frame, PN533_CMD_IN_LIST_PASSIVE_TARGET);
1089 1337
1090 if (dev->poll_mod_count) { 1338 memcpy(PN533_FRAME_CMD_PARAMS_PTR(frame), &mod->data, mod->len);
1091 nfc_dev_err(&dev->interface->dev, "Polling operation already" 1339 frame->datalen += mod->len;
1092 " active");
1093 return -EBUSY;
1094 }
1095 1340
1096 if (dev->tgt_active_prot) { 1341 pn533_tx_frame_finish(frame);
1097 nfc_dev_err(&dev->interface->dev, "Cannot poll with a target"
1098 " already activated");
1099 return -EBUSY;
1100 } 1342 }
1343}
1101 1344
1102 pn533_poll_create_mod_list(dev, protocols); 1345static int pn533_send_poll_frame(struct pn533 *dev)
1346{
1347 struct pn533_poll_modulations *cur_mod;
1348 int rc;
1103 1349
1104 if (!dev->poll_mod_count) { 1350 cur_mod = dev->poll_mod_active[dev->poll_mod_curr];
1105 nfc_dev_err(&dev->interface->dev, "No valid protocols" 1351
1106 " specified"); 1352 pn533_build_poll_frame(dev, dev->out_frame, cur_mod);
1107 rc = -EINVAL; 1353
1108 goto error; 1354 rc = pn533_send_cmd_frame_async(dev, dev->out_frame, dev->in_frame,
1355 dev->in_maxlen, pn533_poll_complete,
1356 NULL, GFP_KERNEL);
1357 if (rc)
1358 nfc_dev_err(&dev->interface->dev, "Polling loop error %d", rc);
1359
1360 return rc;
1361}
1362
1363static void pn533_wq_poll(struct work_struct *work)
1364{
1365 struct pn533 *dev = container_of(work, struct pn533, poll_work);
1366 struct pn533_poll_modulations *cur_mod;
1367 int rc;
1368
1369 cur_mod = dev->poll_mod_active[dev->poll_mod_curr];
1370
1371 nfc_dev_dbg(&dev->interface->dev,
1372 "%s cancel_listen %d modulation len %d",
1373 __func__, dev->cancel_listen, cur_mod->len);
1374
1375 if (dev->cancel_listen == 1) {
1376 dev->cancel_listen = 0;
1377 usb_kill_urb(dev->in_urb);
1109 } 1378 }
1110 1379
1111 nfc_dev_dbg(&dev->interface->dev, "It will poll %d modulations types", 1380 rc = pn533_send_poll_frame(dev);
1112 dev->poll_mod_count); 1381 if (rc)
1382 return;
1113 1383
1114 dev->poll_mod_curr = 0; 1384 if (cur_mod->len == 0 && dev->poll_mod_count > 1)
1115 start_mod = dev->poll_mod_active[dev->poll_mod_curr]; 1385 mod_timer(&dev->listen_timer, jiffies + PN533_LISTEN_TIME * HZ);
1116 1386
1117 pn533_start_poll_frame(dev->out_frame, start_mod); 1387 return;
1388}
1118 1389
1119 rc = pn533_send_cmd_frame_async(dev, dev->out_frame, dev->in_frame, 1390static int pn533_start_poll(struct nfc_dev *nfc_dev,
1120 dev->in_maxlen, pn533_start_poll_complete, 1391 u32 im_protocols, u32 tm_protocols)
1121 NULL, GFP_KERNEL); 1392{
1393 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1122 1394
1123 if (rc) { 1395 nfc_dev_dbg(&dev->interface->dev,
1124 nfc_dev_err(&dev->interface->dev, "Error %d when trying to" 1396 "%s: im protocols 0x%x tm protocols 0x%x",
1125 " start poll", rc); 1397 __func__, im_protocols, tm_protocols);
1126 goto error; 1398
1399 if (dev->tgt_active_prot) {
1400 nfc_dev_err(&dev->interface->dev,
1401 "Cannot poll with a target already activated");
1402 return -EBUSY;
1127 } 1403 }
1128 1404
1129 dev->poll_protocols = protocols; 1405 if (dev->tgt_mode) {
1406 nfc_dev_err(&dev->interface->dev,
1407 "Cannot poll while already being activated");
1408 return -EBUSY;
1409 }
1130 1410
1131 return 0; 1411 if (tm_protocols) {
1412 dev->gb = nfc_get_local_general_bytes(nfc_dev, &dev->gb_len);
1413 if (dev->gb == NULL)
1414 tm_protocols = 0;
1415 }
1132 1416
1133error: 1417 dev->poll_mod_curr = 0;
1134 pn533_poll_reset_mod_list(dev); 1418 pn533_poll_create_mod_list(dev, im_protocols, tm_protocols);
1135 return rc; 1419 dev->poll_protocols = im_protocols;
1420 dev->listen_protocols = tm_protocols;
1421
1422 return pn533_send_poll_frame(dev);
1136} 1423}
1137 1424
1138static void pn533_stop_poll(struct nfc_dev *nfc_dev) 1425static void pn533_stop_poll(struct nfc_dev *nfc_dev)
@@ -1141,6 +1428,8 @@ static void pn533_stop_poll(struct nfc_dev *nfc_dev)
1141 1428
1142 nfc_dev_dbg(&dev->interface->dev, "%s", __func__); 1429 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1143 1430
1431 del_timer(&dev->listen_timer);
1432
1144 if (!dev->poll_mod_count) { 1433 if (!dev->poll_mod_count) {
1145 nfc_dev_dbg(&dev->interface->dev, "Polling operation was not" 1434 nfc_dev_dbg(&dev->interface->dev, "Polling operation was not"
1146 " running"); 1435 " running");
@@ -1152,6 +1441,8 @@ static void pn533_stop_poll(struct nfc_dev *nfc_dev)
1152 1441
1153 /* prevent pn533_start_poll_complete to issue a new poll meanwhile */ 1442 /* prevent pn533_start_poll_complete to issue a new poll meanwhile */
1154 usb_kill_urb(dev->in_urb); 1443 usb_kill_urb(dev->in_urb);
1444
1445 pn533_poll_reset_mod_list(dev);
1155} 1446}
1156 1447
1157static int pn533_activate_target_nfcdep(struct pn533 *dev) 1448static int pn533_activate_target_nfcdep(struct pn533 *dev)
@@ -1349,13 +1640,29 @@ static int pn533_in_dep_link_up_complete(struct pn533 *dev, void *arg,
1349 return 0; 1640 return 0;
1350} 1641}
1351 1642
1643static int pn533_mod_to_baud(struct pn533 *dev)
1644{
1645 switch (dev->poll_mod_curr) {
1646 case PN533_POLL_MOD_106KBPS_A:
1647 return 0;
1648 case PN533_POLL_MOD_212KBPS_FELICA:
1649 return 1;
1650 case PN533_POLL_MOD_424KBPS_FELICA:
1651 return 2;
1652 default:
1653 return -EINVAL;
1654 }
1655}
1656
1657#define PASSIVE_DATA_LEN 5
1352static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target, 1658static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target,
1353 u8 comm_mode, u8* gb, size_t gb_len) 1659 u8 comm_mode, u8* gb, size_t gb_len)
1354{ 1660{
1355 struct pn533 *dev = nfc_get_drvdata(nfc_dev); 1661 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1356 struct pn533_cmd_jump_dep *cmd; 1662 struct pn533_cmd_jump_dep *cmd;
1357 u8 cmd_len; 1663 u8 cmd_len, *data_ptr;
1358 int rc; 1664 u8 passive_data[PASSIVE_DATA_LEN] = {0x00, 0xff, 0xff, 0x00, 0x3};
1665 int rc, baud;
1359 1666
1360 nfc_dev_dbg(&dev->interface->dev, "%s", __func__); 1667 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1361 1668
@@ -1371,7 +1678,17 @@ static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target,
1371 return -EBUSY; 1678 return -EBUSY;
1372 } 1679 }
1373 1680
1681 baud = pn533_mod_to_baud(dev);
1682 if (baud < 0) {
1683 nfc_dev_err(&dev->interface->dev,
1684 "Invalid curr modulation %d", dev->poll_mod_curr);
1685 return baud;
1686 }
1687
1374 cmd_len = sizeof(struct pn533_cmd_jump_dep) + gb_len; 1688 cmd_len = sizeof(struct pn533_cmd_jump_dep) + gb_len;
1689 if (comm_mode == NFC_COMM_PASSIVE)
1690 cmd_len += PASSIVE_DATA_LEN;
1691
1375 cmd = kzalloc(cmd_len, GFP_KERNEL); 1692 cmd = kzalloc(cmd_len, GFP_KERNEL);
1376 if (cmd == NULL) 1693 if (cmd == NULL)
1377 return -ENOMEM; 1694 return -ENOMEM;
@@ -1379,10 +1696,18 @@ static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target,
1379 pn533_tx_frame_init(dev->out_frame, PN533_CMD_IN_JUMP_FOR_DEP); 1696 pn533_tx_frame_init(dev->out_frame, PN533_CMD_IN_JUMP_FOR_DEP);
1380 1697
1381 cmd->active = !comm_mode; 1698 cmd->active = !comm_mode;
1382 cmd->baud = 0; 1699 cmd->next = 0;
1700 cmd->baud = baud;
1701 data_ptr = cmd->data;
1702 if (comm_mode == NFC_COMM_PASSIVE && cmd->baud > 0) {
1703 memcpy(data_ptr, passive_data, PASSIVE_DATA_LEN);
1704 cmd->next |= 1;
1705 data_ptr += PASSIVE_DATA_LEN;
1706 }
1707
1383 if (gb != NULL && gb_len > 0) { 1708 if (gb != NULL && gb_len > 0) {
1384 cmd->next = 4; /* We have some Gi */ 1709 cmd->next |= 4; /* We have some Gi */
1385 memcpy(cmd->gt, gb, gb_len); 1710 memcpy(data_ptr, gb, gb_len);
1386 } else { 1711 } else {
1387 cmd->next = 0; 1712 cmd->next = 0;
1388 } 1713 }
@@ -1407,15 +1732,25 @@ out:
1407 1732
1408static int pn533_dep_link_down(struct nfc_dev *nfc_dev) 1733static int pn533_dep_link_down(struct nfc_dev *nfc_dev)
1409{ 1734{
1410 pn533_deactivate_target(nfc_dev, 0); 1735 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1736
1737 pn533_poll_reset_mod_list(dev);
1738
1739 if (dev->tgt_mode || dev->tgt_active_prot) {
1740 pn533_send_ack(dev, GFP_KERNEL);
1741 usb_kill_urb(dev->in_urb);
1742 }
1743
1744 dev->tgt_active_prot = 0;
1745 dev->tgt_mode = 0;
1746
1747 skb_queue_purge(&dev->resp_q);
1411 1748
1412 return 0; 1749 return 0;
1413} 1750}
1414 1751
1415#define PN533_CMD_DATAEXCH_HEAD_LEN (sizeof(struct pn533_frame) + 3) 1752static int pn533_build_tx_frame(struct pn533 *dev, struct sk_buff *skb,
1416#define PN533_CMD_DATAEXCH_DATA_MAXLEN 262 1753 bool target)
1417
1418static int pn533_data_exchange_tx_frame(struct pn533 *dev, struct sk_buff *skb)
1419{ 1754{
1420 int payload_len = skb->len; 1755 int payload_len = skb->len;
1421 struct pn533_frame *out_frame; 1756 struct pn533_frame *out_frame;
@@ -1432,14 +1767,20 @@ static int pn533_data_exchange_tx_frame(struct pn533 *dev, struct sk_buff *skb)
1432 return -ENOSYS; 1767 return -ENOSYS;
1433 } 1768 }
1434 1769
1435 skb_push(skb, PN533_CMD_DATAEXCH_HEAD_LEN); 1770 if (target == true) {
1436 out_frame = (struct pn533_frame *) skb->data; 1771 skb_push(skb, PN533_CMD_DATAEXCH_HEAD_LEN);
1772 out_frame = (struct pn533_frame *) skb->data;
1437 1773
1438 pn533_tx_frame_init(out_frame, PN533_CMD_IN_DATA_EXCHANGE); 1774 pn533_tx_frame_init(out_frame, PN533_CMD_IN_DATA_EXCHANGE);
1775 tg = 1;
1776 memcpy(PN533_FRAME_CMD_PARAMS_PTR(out_frame), &tg, sizeof(u8));
1777 out_frame->datalen += sizeof(u8);
1778 } else {
1779 skb_push(skb, PN533_CMD_DATAEXCH_HEAD_LEN - 1);
1780 out_frame = (struct pn533_frame *) skb->data;
1781 pn533_tx_frame_init(out_frame, PN533_CMD_TG_SET_DATA);
1782 }
1439 1783
1440 tg = 1;
1441 memcpy(PN533_FRAME_CMD_PARAMS_PTR(out_frame), &tg, sizeof(u8));
1442 out_frame->datalen += sizeof(u8);
1443 1784
1444 /* The data is already in the out_frame, just update the datalen */ 1785 /* The data is already in the out_frame, just update the datalen */
1445 out_frame->datalen += payload_len; 1786 out_frame->datalen += payload_len;
@@ -1550,9 +1891,9 @@ error:
1550 return 0; 1891 return 0;
1551} 1892}
1552 1893
1553static int pn533_data_exchange(struct nfc_dev *nfc_dev, 1894static int pn533_transceive(struct nfc_dev *nfc_dev,
1554 struct nfc_target *target, struct sk_buff *skb, 1895 struct nfc_target *target, struct sk_buff *skb,
1555 data_exchange_cb_t cb, void *cb_context) 1896 data_exchange_cb_t cb, void *cb_context)
1556{ 1897{
1557 struct pn533 *dev = nfc_get_drvdata(nfc_dev); 1898 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1558 struct pn533_frame *out_frame, *in_frame; 1899 struct pn533_frame *out_frame, *in_frame;
@@ -1570,7 +1911,7 @@ static int pn533_data_exchange(struct nfc_dev *nfc_dev,
1570 goto error; 1911 goto error;
1571 } 1912 }
1572 1913
1573 rc = pn533_data_exchange_tx_frame(dev, skb); 1914 rc = pn533_build_tx_frame(dev, skb, true);
1574 if (rc) 1915 if (rc)
1575 goto error; 1916 goto error;
1576 1917
@@ -1618,6 +1959,63 @@ error:
1618 return rc; 1959 return rc;
1619} 1960}
1620 1961
1962static int pn533_tm_send_complete(struct pn533 *dev, void *arg,
1963 u8 *params, int params_len)
1964{
1965 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1966
1967 if (params_len < 0) {
1968 nfc_dev_err(&dev->interface->dev,
1969 "Error %d when sending data",
1970 params_len);
1971
1972 return params_len;
1973 }
1974
1975 if (params_len > 0 && params[0] != 0) {
1976 nfc_tm_deactivated(dev->nfc_dev);
1977
1978 dev->tgt_mode = 0;
1979
1980 return 0;
1981 }
1982
1983 queue_work(dev->wq, &dev->tg_work);
1984
1985 return 0;
1986}
1987
1988static int pn533_tm_send(struct nfc_dev *nfc_dev, struct sk_buff *skb)
1989{
1990 struct pn533 *dev = nfc_get_drvdata(nfc_dev);
1991 struct pn533_frame *out_frame;
1992 int rc;
1993
1994 nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
1995
1996 rc = pn533_build_tx_frame(dev, skb, false);
1997 if (rc)
1998 goto error;
1999
2000 out_frame = (struct pn533_frame *) skb->data;
2001
2002 rc = pn533_send_cmd_frame_async(dev, out_frame, dev->in_frame,
2003 dev->in_maxlen, pn533_tm_send_complete,
2004 NULL, GFP_KERNEL);
2005 if (rc) {
2006 nfc_dev_err(&dev->interface->dev,
2007 "Error %d when trying to send data", rc);
2008 goto error;
2009 }
2010
2011 return 0;
2012
2013error:
2014 kfree_skb(skb);
2015
2016 return rc;
2017}
2018
1621static void pn533_wq_mi_recv(struct work_struct *work) 2019static void pn533_wq_mi_recv(struct work_struct *work)
1622{ 2020{
1623 struct pn533 *dev = container_of(work, struct pn533, mi_work); 2021 struct pn533 *dev = container_of(work, struct pn533, mi_work);
@@ -1638,7 +2036,7 @@ static void pn533_wq_mi_recv(struct work_struct *work)
1638 2036
1639 skb_reserve(skb_cmd, PN533_CMD_DATAEXCH_HEAD_LEN); 2037 skb_reserve(skb_cmd, PN533_CMD_DATAEXCH_HEAD_LEN);
1640 2038
1641 rc = pn533_data_exchange_tx_frame(dev, skb_cmd); 2039 rc = pn533_build_tx_frame(dev, skb_cmd, true);
1642 if (rc) 2040 if (rc)
1643 goto error_frame; 2041 goto error_frame;
1644 2042
@@ -1677,7 +2075,7 @@ error_cmd:
1677 2075
1678 kfree(arg); 2076 kfree(arg);
1679 2077
1680 up(&dev->cmd_lock); 2078 mutex_unlock(&dev->cmd_lock);
1681} 2079}
1682 2080
1683static int pn533_set_configuration(struct pn533 *dev, u8 cfgitem, u8 *cfgdata, 2081static int pn533_set_configuration(struct pn533 *dev, u8 cfgitem, u8 *cfgdata,
@@ -1712,7 +2110,8 @@ struct nfc_ops pn533_nfc_ops = {
1712 .stop_poll = pn533_stop_poll, 2110 .stop_poll = pn533_stop_poll,
1713 .activate_target = pn533_activate_target, 2111 .activate_target = pn533_activate_target,
1714 .deactivate_target = pn533_deactivate_target, 2112 .deactivate_target = pn533_deactivate_target,
1715 .data_exchange = pn533_data_exchange, 2113 .im_transceive = pn533_transceive,
2114 .tm_send = pn533_tm_send,
1716}; 2115};
1717 2116
1718static int pn533_probe(struct usb_interface *interface, 2117static int pn533_probe(struct usb_interface *interface,
@@ -1723,6 +2122,7 @@ static int pn533_probe(struct usb_interface *interface,
1723 struct usb_host_interface *iface_desc; 2122 struct usb_host_interface *iface_desc;
1724 struct usb_endpoint_descriptor *endpoint; 2123 struct usb_endpoint_descriptor *endpoint;
1725 struct pn533_config_max_retries max_retries; 2124 struct pn533_config_max_retries max_retries;
2125 struct pn533_config_timing timing;
1726 int in_endpoint = 0; 2126 int in_endpoint = 0;
1727 int out_endpoint = 0; 2127 int out_endpoint = 0;
1728 int rc = -ENOMEM; 2128 int rc = -ENOMEM;
@@ -1735,7 +2135,7 @@ static int pn533_probe(struct usb_interface *interface,
1735 2135
1736 dev->udev = usb_get_dev(interface_to_usbdev(interface)); 2136 dev->udev = usb_get_dev(interface_to_usbdev(interface));
1737 dev->interface = interface; 2137 dev->interface = interface;
1738 sema_init(&dev->cmd_lock, 1); 2138 mutex_init(&dev->cmd_lock);
1739 2139
1740 iface_desc = interface->cur_altsetting; 2140 iface_desc = interface->cur_altsetting;
1741 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { 2141 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
@@ -1779,12 +2179,18 @@ static int pn533_probe(struct usb_interface *interface,
1779 2179
1780 INIT_WORK(&dev->cmd_work, pn533_wq_cmd_complete); 2180 INIT_WORK(&dev->cmd_work, pn533_wq_cmd_complete);
1781 INIT_WORK(&dev->mi_work, pn533_wq_mi_recv); 2181 INIT_WORK(&dev->mi_work, pn533_wq_mi_recv);
2182 INIT_WORK(&dev->tg_work, pn533_wq_tg_get_data);
2183 INIT_WORK(&dev->poll_work, pn533_wq_poll);
1782 dev->wq = alloc_workqueue("pn533", 2184 dev->wq = alloc_workqueue("pn533",
1783 WQ_NON_REENTRANT | WQ_UNBOUND | WQ_MEM_RECLAIM, 2185 WQ_NON_REENTRANT | WQ_UNBOUND | WQ_MEM_RECLAIM,
1784 1); 2186 1);
1785 if (dev->wq == NULL) 2187 if (dev->wq == NULL)
1786 goto error; 2188 goto error;
1787 2189
2190 init_timer(&dev->listen_timer);
2191 dev->listen_timer.data = (unsigned long) dev;
2192 dev->listen_timer.function = pn533_listen_mode_timer;
2193
1788 skb_queue_head_init(&dev->resp_q); 2194 skb_queue_head_init(&dev->resp_q);
1789 2195
1790 usb_set_intfdata(interface, dev); 2196 usb_set_intfdata(interface, dev);
@@ -1830,13 +2236,29 @@ static int pn533_probe(struct usb_interface *interface,
1830 if (rc) { 2236 if (rc) {
1831 nfc_dev_err(&dev->interface->dev, "Error on setting MAX_RETRIES" 2237 nfc_dev_err(&dev->interface->dev, "Error on setting MAX_RETRIES"
1832 " config"); 2238 " config");
1833 goto free_nfc_dev; 2239 goto unregister_nfc_dev;
2240 }
2241
2242 timing.rfu = PN533_CONFIG_TIMING_102;
2243 timing.atr_res_timeout = PN533_CONFIG_TIMING_204;
2244 timing.dep_timeout = PN533_CONFIG_TIMING_409;
2245
2246 rc = pn533_set_configuration(dev, PN533_CFGITEM_TIMING,
2247 (u8 *) &timing, sizeof(timing));
2248 if (rc) {
2249 nfc_dev_err(&dev->interface->dev,
2250 "Error on setting RF timings");
2251 goto unregister_nfc_dev;
1834 } 2252 }
1835 2253
1836 return 0; 2254 return 0;
1837 2255
2256unregister_nfc_dev:
2257 nfc_unregister_device(dev->nfc_dev);
2258
1838free_nfc_dev: 2259free_nfc_dev:
1839 nfc_free_device(dev->nfc_dev); 2260 nfc_free_device(dev->nfc_dev);
2261
1840destroy_wq: 2262destroy_wq:
1841 destroy_workqueue(dev->wq); 2263 destroy_workqueue(dev->wq);
1842error: 2264error:
@@ -1865,6 +2287,8 @@ static void pn533_disconnect(struct usb_interface *interface)
1865 2287
1866 skb_queue_purge(&dev->resp_q); 2288 skb_queue_purge(&dev->resp_q);
1867 2289
2290 del_timer(&dev->listen_timer);
2291
1868 kfree(dev->in_frame); 2292 kfree(dev->in_frame);
1869 usb_free_urb(dev->in_urb); 2293 usb_free_urb(dev->in_urb);
1870 kfree(dev->out_frame); 2294 kfree(dev->out_frame);
diff --git a/drivers/nfc/pn544_hci.c b/drivers/nfc/pn544_hci.c
index 281f18c2fb82..457eac35dc74 100644
--- a/drivers/nfc/pn544_hci.c
+++ b/drivers/nfc/pn544_hci.c
@@ -576,7 +576,8 @@ static int pn544_hci_xmit(struct nfc_shdlc *shdlc, struct sk_buff *skb)
576 return pn544_hci_i2c_write(client, skb->data, skb->len); 576 return pn544_hci_i2c_write(client, skb->data, skb->len);
577} 577}
578 578
579static int pn544_hci_start_poll(struct nfc_shdlc *shdlc, u32 protocols) 579static int pn544_hci_start_poll(struct nfc_shdlc *shdlc,
580 u32 im_protocols, u32 tm_protocols)
580{ 581{
581 struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc); 582 struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc);
582 u8 phases = 0; 583 u8 phases = 0;
@@ -584,7 +585,8 @@ static int pn544_hci_start_poll(struct nfc_shdlc *shdlc, u32 protocols)
584 u8 duration[2]; 585 u8 duration[2];
585 u8 activated; 586 u8 activated;
586 587
587 pr_info(DRIVER_DESC ": %s protocols = %d\n", __func__, protocols); 588 pr_info(DRIVER_DESC ": %s protocols 0x%x 0x%x\n",
589 __func__, im_protocols, tm_protocols);
588 590
589 r = nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE, 591 r = nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE,
590 NFC_HCI_EVT_END_OPERATION, NULL, 0); 592 NFC_HCI_EVT_END_OPERATION, NULL, 0);
@@ -604,10 +606,10 @@ static int pn544_hci_start_poll(struct nfc_shdlc *shdlc, u32 protocols)
604 if (r < 0) 606 if (r < 0)
605 return r; 607 return r;
606 608
607 if (protocols & (NFC_PROTO_ISO14443_MASK | NFC_PROTO_MIFARE_MASK | 609 if (im_protocols & (NFC_PROTO_ISO14443_MASK | NFC_PROTO_MIFARE_MASK |
608 NFC_PROTO_JEWEL_MASK)) 610 NFC_PROTO_JEWEL_MASK))
609 phases |= 1; /* Type A */ 611 phases |= 1; /* Type A */
610 if (protocols & NFC_PROTO_FELICA_MASK) { 612 if (im_protocols & NFC_PROTO_FELICA_MASK) {
611 phases |= (1 << 2); /* Type F 212 */ 613 phases |= (1 << 2); /* Type F 212 */
612 phases |= (1 << 3); /* Type F 424 */ 614 phases |= (1 << 3); /* Type F 424 */
613 } 615 }
diff --git a/drivers/ssb/b43_pci_bridge.c b/drivers/ssb/b43_pci_bridge.c
index f551e5376147..266aa1648a02 100644
--- a/drivers/ssb/b43_pci_bridge.c
+++ b/drivers/ssb/b43_pci_bridge.c
@@ -36,6 +36,7 @@ static const struct pci_device_id b43_pci_bridge_tbl[] = {
36 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4328) }, 36 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4328) },
37 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4329) }, 37 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4329) },
38 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x432b) }, 38 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x432b) },
39 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x432c) },
39 { 0, }, 40 { 0, },
40}; 41};
41MODULE_DEVICE_TABLE(pci, b43_pci_bridge_tbl); 42MODULE_DEVICE_TABLE(pci, b43_pci_bridge_tbl);
diff --git a/drivers/ssb/scan.c b/drivers/ssb/scan.c
index 266c7c5c86dc..ab4627cf1114 100644
--- a/drivers/ssb/scan.c
+++ b/drivers/ssb/scan.c
@@ -90,6 +90,8 @@ const char *ssb_core_name(u16 coreid)
90 return "ARM 1176"; 90 return "ARM 1176";
91 case SSB_DEV_ARM_7TDMI: 91 case SSB_DEV_ARM_7TDMI:
92 return "ARM 7TDMI"; 92 return "ARM 7TDMI";
93 case SSB_DEV_ARM_CM3:
94 return "ARM Cortex M3";
93 } 95 }
94 return "UNKNOWN"; 96 return "UNKNOWN";
95} 97}
diff --git a/include/linux/nfc.h b/include/linux/nfc.h
index 0ae9b5857c83..f4e6dd915b1c 100644
--- a/include/linux/nfc.h
+++ b/include/linux/nfc.h
@@ -56,6 +56,10 @@
56 * %NFC_ATTR_PROTOCOLS) 56 * %NFC_ATTR_PROTOCOLS)
57 * @NFC_EVENT_DEVICE_REMOVED: event emitted when a device is removed 57 * @NFC_EVENT_DEVICE_REMOVED: event emitted when a device is removed
58 * (it sends %NFC_ATTR_DEVICE_INDEX) 58 * (it sends %NFC_ATTR_DEVICE_INDEX)
59 * @NFC_EVENT_TM_ACTIVATED: event emitted when the adapter is activated in
60 * target mode.
61 * @NFC_EVENT_DEVICE_DEACTIVATED: event emitted when the adapter is deactivated
62 * from target mode.
59 */ 63 */
60enum nfc_commands { 64enum nfc_commands {
61 NFC_CMD_UNSPEC, 65 NFC_CMD_UNSPEC,
@@ -71,6 +75,8 @@ enum nfc_commands {
71 NFC_EVENT_DEVICE_ADDED, 75 NFC_EVENT_DEVICE_ADDED,
72 NFC_EVENT_DEVICE_REMOVED, 76 NFC_EVENT_DEVICE_REMOVED,
73 NFC_EVENT_TARGET_LOST, 77 NFC_EVENT_TARGET_LOST,
78 NFC_EVENT_TM_ACTIVATED,
79 NFC_EVENT_TM_DEACTIVATED,
74/* private: internal use only */ 80/* private: internal use only */
75 __NFC_CMD_AFTER_LAST 81 __NFC_CMD_AFTER_LAST
76}; 82};
@@ -94,6 +100,8 @@ enum nfc_commands {
94 * @NFC_ATTR_TARGET_SENSF_RES: NFC-F targets extra information, max 18 bytes 100 * @NFC_ATTR_TARGET_SENSF_RES: NFC-F targets extra information, max 18 bytes
95 * @NFC_ATTR_COMM_MODE: Passive or active mode 101 * @NFC_ATTR_COMM_MODE: Passive or active mode
96 * @NFC_ATTR_RF_MODE: Initiator or target 102 * @NFC_ATTR_RF_MODE: Initiator or target
103 * @NFC_ATTR_IM_PROTOCOLS: Initiator mode protocols to poll for
104 * @NFC_ATTR_TM_PROTOCOLS: Target mode protocols to listen for
97 */ 105 */
98enum nfc_attrs { 106enum nfc_attrs {
99 NFC_ATTR_UNSPEC, 107 NFC_ATTR_UNSPEC,
@@ -109,6 +117,8 @@ enum nfc_attrs {
109 NFC_ATTR_COMM_MODE, 117 NFC_ATTR_COMM_MODE,
110 NFC_ATTR_RF_MODE, 118 NFC_ATTR_RF_MODE,
111 NFC_ATTR_DEVICE_POWERED, 119 NFC_ATTR_DEVICE_POWERED,
120 NFC_ATTR_IM_PROTOCOLS,
121 NFC_ATTR_TM_PROTOCOLS,
112/* private: internal use only */ 122/* private: internal use only */
113 __NFC_ATTR_AFTER_LAST 123 __NFC_ATTR_AFTER_LAST
114}; 124};
@@ -118,6 +128,7 @@ enum nfc_attrs {
118#define NFC_NFCID1_MAXSIZE 10 128#define NFC_NFCID1_MAXSIZE 10
119#define NFC_SENSB_RES_MAXSIZE 12 129#define NFC_SENSB_RES_MAXSIZE 12
120#define NFC_SENSF_RES_MAXSIZE 18 130#define NFC_SENSF_RES_MAXSIZE 18
131#define NFC_GB_MAXSIZE 48
121 132
122/* NFC protocols */ 133/* NFC protocols */
123#define NFC_PROTO_JEWEL 1 134#define NFC_PROTO_JEWEL 1
@@ -135,6 +146,7 @@ enum nfc_attrs {
135/* NFC RF modes */ 146/* NFC RF modes */
136#define NFC_RF_INITIATOR 0 147#define NFC_RF_INITIATOR 0
137#define NFC_RF_TARGET 1 148#define NFC_RF_TARGET 1
149#define NFC_RF_NONE 2
138 150
139/* NFC protocols masks used in bitsets */ 151/* NFC protocols masks used in bitsets */
140#define NFC_PROTO_JEWEL_MASK (1 << NFC_PROTO_JEWEL) 152#define NFC_PROTO_JEWEL_MASK (1 << NFC_PROTO_JEWEL)
diff --git a/include/linux/nl80211.h b/include/linux/nl80211.h
index a6959f72745e..970afdf5a605 100644
--- a/include/linux/nl80211.h
+++ b/include/linux/nl80211.h
@@ -170,6 +170,8 @@
170 * %NL80211_ATTR_CIPHER_GROUP, %NL80211_ATTR_WPA_VERSIONS, 170 * %NL80211_ATTR_CIPHER_GROUP, %NL80211_ATTR_WPA_VERSIONS,
171 * %NL80211_ATTR_AKM_SUITES, %NL80211_ATTR_PRIVACY, 171 * %NL80211_ATTR_AKM_SUITES, %NL80211_ATTR_PRIVACY,
172 * %NL80211_ATTR_AUTH_TYPE and %NL80211_ATTR_INACTIVITY_TIMEOUT. 172 * %NL80211_ATTR_AUTH_TYPE and %NL80211_ATTR_INACTIVITY_TIMEOUT.
173 * The channel to use can be set on the interface or be given using the
174 * %NL80211_ATTR_WIPHY_FREQ and %NL80211_ATTR_WIPHY_CHANNEL_TYPE attrs.
173 * @NL80211_CMD_NEW_BEACON: old alias for %NL80211_CMD_START_AP 175 * @NL80211_CMD_NEW_BEACON: old alias for %NL80211_CMD_START_AP
174 * @NL80211_CMD_STOP_AP: Stop AP operation on the given interface 176 * @NL80211_CMD_STOP_AP: Stop AP operation on the given interface
175 * @NL80211_CMD_DEL_BEACON: old alias for %NL80211_CMD_STOP_AP 177 * @NL80211_CMD_DEL_BEACON: old alias for %NL80211_CMD_STOP_AP
@@ -1520,6 +1522,8 @@ enum nl80211_attrs {
1520#define NL80211_MAX_NR_CIPHER_SUITES 5 1522#define NL80211_MAX_NR_CIPHER_SUITES 5
1521#define NL80211_MAX_NR_AKM_SUITES 2 1523#define NL80211_MAX_NR_AKM_SUITES 2
1522 1524
1525#define NL80211_MIN_REMAIN_ON_CHANNEL_TIME 10
1526
1523/** 1527/**
1524 * enum nl80211_iftype - (virtual) interface types 1528 * enum nl80211_iftype - (virtual) interface types
1525 * 1529 *
@@ -2534,10 +2538,14 @@ enum nl80211_attr_cqm {
2534 * configured threshold 2538 * configured threshold
2535 * @NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH: The RSSI is higher than the 2539 * @NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH: The RSSI is higher than the
2536 * configured threshold 2540 * configured threshold
2541 * @NL80211_CQM_RSSI_BEACON_LOSS_EVENT: The device experienced beacon loss.
2542 * (Note that deauth/disassoc will still follow if the AP is not
2543 * available. This event might get used as roaming event, etc.)
2537 */ 2544 */
2538enum nl80211_cqm_rssi_threshold_event { 2545enum nl80211_cqm_rssi_threshold_event {
2539 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, 2546 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
2540 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, 2547 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
2548 NL80211_CQM_RSSI_BEACON_LOSS_EVENT,
2541}; 2549};
2542 2550
2543 2551
diff --git a/include/linux/ssb/ssb.h b/include/linux/ssb/ssb.h
index bc14bd738ade..bb674c02f306 100644
--- a/include/linux/ssb/ssb.h
+++ b/include/linux/ssb/ssb.h
@@ -243,6 +243,7 @@ struct ssb_bus_ops {
243#define SSB_DEV_MINI_MACPHY 0x823 243#define SSB_DEV_MINI_MACPHY 0x823
244#define SSB_DEV_ARM_1176 0x824 244#define SSB_DEV_ARM_1176 0x824
245#define SSB_DEV_ARM_7TDMI 0x825 245#define SSB_DEV_ARM_7TDMI 0x825
246#define SSB_DEV_ARM_CM3 0x82A
246 247
247/* Vendor-ID values */ 248/* Vendor-ID values */
248#define SSB_VENDOR_BROADCOM 0x4243 249#define SSB_VENDOR_BROADCOM 0x4243
diff --git a/include/net/bluetooth/a2mp.h b/include/net/bluetooth/a2mp.h
new file mode 100644
index 000000000000..6a76e0a0705e
--- /dev/null
+++ b/include/net/bluetooth/a2mp.h
@@ -0,0 +1,126 @@
1/*
2 Copyright (c) 2010,2011 Code Aurora Forum. All rights reserved.
3 Copyright (c) 2011,2012 Intel Corp.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 and
7 only version 2 as published by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13*/
14
15#ifndef __A2MP_H
16#define __A2MP_H
17
18#include <net/bluetooth/l2cap.h>
19
20#define A2MP_FEAT_EXT 0x8000
21
22struct amp_mgr {
23 struct l2cap_conn *l2cap_conn;
24 struct l2cap_chan *a2mp_chan;
25 struct kref kref;
26 __u8 ident;
27 __u8 handle;
28 unsigned long flags;
29};
30
31struct a2mp_cmd {
32 __u8 code;
33 __u8 ident;
34 __le16 len;
35 __u8 data[0];
36} __packed;
37
38/* A2MP command codes */
39#define A2MP_COMMAND_REJ 0x01
40struct a2mp_cmd_rej {
41 __le16 reason;
42 __u8 data[0];
43} __packed;
44
45#define A2MP_DISCOVER_REQ 0x02
46struct a2mp_discov_req {
47 __le16 mtu;
48 __le16 ext_feat;
49} __packed;
50
51struct a2mp_cl {
52 __u8 id;
53 __u8 type;
54 __u8 status;
55} __packed;
56
57#define A2MP_DISCOVER_RSP 0x03
58struct a2mp_discov_rsp {
59 __le16 mtu;
60 __le16 ext_feat;
61 struct a2mp_cl cl[0];
62} __packed;
63
64#define A2MP_CHANGE_NOTIFY 0x04
65#define A2MP_CHANGE_RSP 0x05
66
67#define A2MP_GETINFO_REQ 0x06
68struct a2mp_info_req {
69 __u8 id;
70} __packed;
71
72#define A2MP_GETINFO_RSP 0x07
73struct a2mp_info_rsp {
74 __u8 id;
75 __u8 status;
76 __le32 total_bw;
77 __le32 max_bw;
78 __le32 min_latency;
79 __le16 pal_cap;
80 __le16 assoc_size;
81} __packed;
82
83#define A2MP_GETAMPASSOC_REQ 0x08
84struct a2mp_amp_assoc_req {
85 __u8 id;
86} __packed;
87
88#define A2MP_GETAMPASSOC_RSP 0x09
89struct a2mp_amp_assoc_rsp {
90 __u8 id;
91 __u8 status;
92 __u8 amp_assoc[0];
93} __packed;
94
95#define A2MP_CREATEPHYSLINK_REQ 0x0A
96#define A2MP_DISCONNPHYSLINK_REQ 0x0C
97struct a2mp_physlink_req {
98 __u8 local_id;
99 __u8 remote_id;
100 __u8 amp_assoc[0];
101} __packed;
102
103#define A2MP_CREATEPHYSLINK_RSP 0x0B
104#define A2MP_DISCONNPHYSLINK_RSP 0x0D
105struct a2mp_physlink_rsp {
106 __u8 local_id;
107 __u8 remote_id;
108 __u8 status;
109} __packed;
110
111/* A2MP response status */
112#define A2MP_STATUS_SUCCESS 0x00
113#define A2MP_STATUS_INVALID_CTRL_ID 0x01
114#define A2MP_STATUS_UNABLE_START_LINK_CREATION 0x02
115#define A2MP_STATUS_NO_PHYSICAL_LINK_EXISTS 0x02
116#define A2MP_STATUS_COLLISION_OCCURED 0x03
117#define A2MP_STATUS_DISCONN_REQ_RECVD 0x04
118#define A2MP_STATUS_PHYS_LINK_EXISTS 0x05
119#define A2MP_STATUS_SECURITY_VIOLATION 0x06
120
121void amp_mgr_get(struct amp_mgr *mgr);
122int amp_mgr_put(struct amp_mgr *mgr);
123struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn,
124 struct sk_buff *skb);
125
126#endif /* __A2MP_H */
diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 961669b648fd..565d4bee1e49 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -1,4 +1,4 @@
1/* 1/*
2 BlueZ - Bluetooth protocol stack for Linux 2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated 3 Copyright (C) 2000-2001 Qualcomm Incorporated
4 4
@@ -12,22 +12,19 @@
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. 13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY 14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 19
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED. 22 SOFTWARE IS DISCLAIMED.
23*/ 23*/
24 24
25#ifndef __BLUETOOTH_H 25#ifndef __BLUETOOTH_H
26#define __BLUETOOTH_H 26#define __BLUETOOTH_H
27 27
28#include <asm/types.h>
29#include <asm/byteorder.h>
30#include <linux/list.h>
31#include <linux/poll.h> 28#include <linux/poll.h>
32#include <net/sock.h> 29#include <net/sock.h>
33 30
@@ -168,8 +165,8 @@ typedef struct {
168#define BDADDR_LE_PUBLIC 0x01 165#define BDADDR_LE_PUBLIC 0x01
169#define BDADDR_LE_RANDOM 0x02 166#define BDADDR_LE_RANDOM 0x02
170 167
171#define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) 168#define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0} })
172#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff}}) 169#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff} })
173 170
174/* Copy, swap, convert BD Address */ 171/* Copy, swap, convert BD Address */
175static inline int bacmp(bdaddr_t *ba1, bdaddr_t *ba2) 172static inline int bacmp(bdaddr_t *ba1, bdaddr_t *ba2)
@@ -215,7 +212,7 @@ int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
215 struct msghdr *msg, size_t len, int flags); 212 struct msghdr *msg, size_t len, int flags);
216int bt_sock_stream_recvmsg(struct kiocb *iocb, struct socket *sock, 213int bt_sock_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
217 struct msghdr *msg, size_t len, int flags); 214 struct msghdr *msg, size_t len, int flags);
218uint bt_sock_poll(struct file * file, struct socket *sock, poll_table *wait); 215uint bt_sock_poll(struct file *file, struct socket *sock, poll_table *wait);
219int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); 216int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
220int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo); 217int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo);
221 218
@@ -225,12 +222,12 @@ struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock);
225 222
226/* Skb helpers */ 223/* Skb helpers */
227struct l2cap_ctrl { 224struct l2cap_ctrl {
228 unsigned int sframe : 1, 225 unsigned int sframe:1,
229 poll : 1, 226 poll:1,
230 final : 1, 227 final:1,
231 fcs : 1, 228 fcs:1,
232 sar : 2, 229 sar:2,
233 super : 2; 230 super:2;
234 __u16 reqseq; 231 __u16 reqseq;
235 __u16 txseq; 232 __u16 txseq;
236 __u8 retries; 233 __u8 retries;
@@ -249,7 +246,8 @@ static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how)
249{ 246{
250 struct sk_buff *skb; 247 struct sk_buff *skb;
251 248
252 if ((skb = alloc_skb(len + BT_SKB_RESERVE, how))) { 249 skb = alloc_skb(len + BT_SKB_RESERVE, how);
250 if (skb) {
253 skb_reserve(skb, BT_SKB_RESERVE); 251 skb_reserve(skb, BT_SKB_RESERVE);
254 bt_cb(skb)->incoming = 0; 252 bt_cb(skb)->incoming = 0;
255 } 253 }
@@ -261,7 +259,8 @@ static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk,
261{ 259{
262 struct sk_buff *skb; 260 struct sk_buff *skb;
263 261
264 if ((skb = sock_alloc_send_skb(sk, len + BT_SKB_RESERVE, nb, err))) { 262 skb = sock_alloc_send_skb(sk, len + BT_SKB_RESERVE, nb, err);
263 if (skb) {
265 skb_reserve(skb, BT_SKB_RESERVE); 264 skb_reserve(skb, BT_SKB_RESERVE);
266 bt_cb(skb)->incoming = 0; 265 bt_cb(skb)->incoming = 0;
267 } 266 }
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 3def64ba77fa..2a6b0b8b7120 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -30,6 +30,9 @@
30#define HCI_MAX_EVENT_SIZE 260 30#define HCI_MAX_EVENT_SIZE 260
31#define HCI_MAX_FRAME_SIZE (HCI_MAX_ACL_SIZE + 4) 31#define HCI_MAX_FRAME_SIZE (HCI_MAX_ACL_SIZE + 4)
32 32
33#define HCI_LINK_KEY_SIZE 16
34#define HCI_AMP_LINK_KEY_SIZE (2 * HCI_LINK_KEY_SIZE)
35
33/* HCI dev events */ 36/* HCI dev events */
34#define HCI_DEV_REG 1 37#define HCI_DEV_REG 1
35#define HCI_DEV_UNREG 2 38#define HCI_DEV_UNREG 2
@@ -56,9 +59,12 @@
56#define HCI_BREDR 0x00 59#define HCI_BREDR 0x00
57#define HCI_AMP 0x01 60#define HCI_AMP 0x01
58 61
62/* First BR/EDR Controller shall have ID = 0 */
63#define HCI_BREDR_ID 0
64
59/* HCI device quirks */ 65/* HCI device quirks */
60enum { 66enum {
61 HCI_QUIRK_NO_RESET, 67 HCI_QUIRK_RESET_ON_CLOSE,
62 HCI_QUIRK_RAW_DEVICE, 68 HCI_QUIRK_RAW_DEVICE,
63 HCI_QUIRK_FIXUP_BUFFER_SIZE 69 HCI_QUIRK_FIXUP_BUFFER_SIZE
64}; 70};
@@ -133,10 +139,8 @@ enum {
133#define HCIINQUIRY _IOR('H', 240, int) 139#define HCIINQUIRY _IOR('H', 240, int)
134 140
135/* HCI timeouts */ 141/* HCI timeouts */
136#define HCI_CONNECT_TIMEOUT (40000) /* 40 seconds */
137#define HCI_DISCONN_TIMEOUT (2000) /* 2 seconds */ 142#define HCI_DISCONN_TIMEOUT (2000) /* 2 seconds */
138#define HCI_PAIRING_TIMEOUT (60000) /* 60 seconds */ 143#define HCI_PAIRING_TIMEOUT (60000) /* 60 seconds */
139#define HCI_IDLE_TIMEOUT (6000) /* 6 seconds */
140#define HCI_INIT_TIMEOUT (10000) /* 10 seconds */ 144#define HCI_INIT_TIMEOUT (10000) /* 10 seconds */
141#define HCI_CMD_TIMEOUT (1000) /* 1 seconds */ 145#define HCI_CMD_TIMEOUT (1000) /* 1 seconds */
142#define HCI_ACL_TX_TIMEOUT (45000) /* 45 seconds */ 146#define HCI_ACL_TX_TIMEOUT (45000) /* 45 seconds */
@@ -371,7 +375,7 @@ struct hci_cp_reject_conn_req {
371#define HCI_OP_LINK_KEY_REPLY 0x040b 375#define HCI_OP_LINK_KEY_REPLY 0x040b
372struct hci_cp_link_key_reply { 376struct hci_cp_link_key_reply {
373 bdaddr_t bdaddr; 377 bdaddr_t bdaddr;
374 __u8 link_key[16]; 378 __u8 link_key[HCI_LINK_KEY_SIZE];
375} __packed; 379} __packed;
376 380
377#define HCI_OP_LINK_KEY_NEG_REPLY 0x040c 381#define HCI_OP_LINK_KEY_NEG_REPLY 0x040c
@@ -523,6 +527,28 @@ struct hci_cp_io_capability_neg_reply {
523 __u8 reason; 527 __u8 reason;
524} __packed; 528} __packed;
525 529
530#define HCI_OP_CREATE_PHY_LINK 0x0435
531struct hci_cp_create_phy_link {
532 __u8 phy_handle;
533 __u8 key_len;
534 __u8 key_type;
535 __u8 key[HCI_AMP_LINK_KEY_SIZE];
536} __packed;
537
538#define HCI_OP_ACCEPT_PHY_LINK 0x0436
539struct hci_cp_accept_phy_link {
540 __u8 phy_handle;
541 __u8 key_len;
542 __u8 key_type;
543 __u8 key[HCI_AMP_LINK_KEY_SIZE];
544} __packed;
545
546#define HCI_OP_DISCONN_PHY_LINK 0x0437
547struct hci_cp_disconn_phy_link {
548 __u8 phy_handle;
549 __u8 reason;
550} __packed;
551
526#define HCI_OP_SNIFF_MODE 0x0803 552#define HCI_OP_SNIFF_MODE 0x0803
527struct hci_cp_sniff_mode { 553struct hci_cp_sniff_mode {
528 __le16 handle; 554 __le16 handle;
@@ -818,6 +844,31 @@ struct hci_rp_read_local_amp_info {
818 __le32 be_flush_to; 844 __le32 be_flush_to;
819} __packed; 845} __packed;
820 846
847#define HCI_OP_READ_LOCAL_AMP_ASSOC 0x140a
848struct hci_cp_read_local_amp_assoc {
849 __u8 phy_handle;
850 __le16 len_so_far;
851 __le16 max_len;
852} __packed;
853struct hci_rp_read_local_amp_assoc {
854 __u8 status;
855 __u8 phy_handle;
856 __le16 rem_len;
857 __u8 frag[0];
858} __packed;
859
860#define HCI_OP_WRITE_REMOTE_AMP_ASSOC 0x140b
861struct hci_cp_write_remote_amp_assoc {
862 __u8 phy_handle;
863 __le16 len_so_far;
864 __le16 rem_len;
865 __u8 frag[0];
866} __packed;
867struct hci_rp_write_remote_amp_assoc {
868 __u8 status;
869 __u8 phy_handle;
870} __packed;
871
821#define HCI_OP_LE_SET_EVENT_MASK 0x2001 872#define HCI_OP_LE_SET_EVENT_MASK 0x2001
822struct hci_cp_le_set_event_mask { 873struct hci_cp_le_set_event_mask {
823 __u8 mask[8]; 874 __u8 mask[8];
@@ -1048,7 +1099,7 @@ struct hci_ev_link_key_req {
1048#define HCI_EV_LINK_KEY_NOTIFY 0x18 1099#define HCI_EV_LINK_KEY_NOTIFY 0x18
1049struct hci_ev_link_key_notify { 1100struct hci_ev_link_key_notify {
1050 bdaddr_t bdaddr; 1101 bdaddr_t bdaddr;
1051 __u8 link_key[16]; 1102 __u8 link_key[HCI_LINK_KEY_SIZE];
1052 __u8 key_type; 1103 __u8 key_type;
1053} __packed; 1104} __packed;
1054 1105
@@ -1196,6 +1247,39 @@ struct hci_ev_le_meta {
1196 __u8 subevent; 1247 __u8 subevent;
1197} __packed; 1248} __packed;
1198 1249
1250#define HCI_EV_PHY_LINK_COMPLETE 0x40
1251struct hci_ev_phy_link_complete {
1252 __u8 status;
1253 __u8 phy_handle;
1254} __packed;
1255
1256#define HCI_EV_CHANNEL_SELECTED 0x41
1257struct hci_ev_channel_selected {
1258 __u8 phy_handle;
1259} __packed;
1260
1261#define HCI_EV_DISCONN_PHY_LINK_COMPLETE 0x42
1262struct hci_ev_disconn_phy_link_complete {
1263 __u8 status;
1264 __u8 phy_handle;
1265 __u8 reason;
1266} __packed;
1267
1268#define HCI_EV_LOGICAL_LINK_COMPLETE 0x45
1269struct hci_ev_logical_link_complete {
1270 __u8 status;
1271 __le16 handle;
1272 __u8 phy_handle;
1273 __u8 flow_spec_id;
1274} __packed;
1275
1276#define HCI_EV_DISCONN_LOGICAL_LINK_COMPLETE 0x46
1277struct hci_ev_disconn_logical_link_complete {
1278 __u8 status;
1279 __le16 handle;
1280 __u8 reason;
1281} __packed;
1282
1199#define HCI_EV_NUM_COMP_BLOCKS 0x48 1283#define HCI_EV_NUM_COMP_BLOCKS 0x48
1200struct hci_comp_blocks_info { 1284struct hci_comp_blocks_info {
1201 __le16 handle; 1285 __le16 handle;
@@ -1296,7 +1380,6 @@ struct hci_sco_hdr {
1296 __u8 dlen; 1380 __u8 dlen;
1297} __packed; 1381} __packed;
1298 1382
1299#include <linux/skbuff.h>
1300static inline struct hci_event_hdr *hci_event_hdr(const struct sk_buff *skb) 1383static inline struct hci_event_hdr *hci_event_hdr(const struct sk_buff *skb)
1301{ 1384{
1302 return (struct hci_event_hdr *) skb->data; 1385 return (struct hci_event_hdr *) skb->data;
@@ -1313,12 +1396,12 @@ static inline struct hci_sco_hdr *hci_sco_hdr(const struct sk_buff *skb)
1313} 1396}
1314 1397
1315/* Command opcode pack/unpack */ 1398/* Command opcode pack/unpack */
1316#define hci_opcode_pack(ogf, ocf) (__u16) ((ocf & 0x03ff)|(ogf << 10)) 1399#define hci_opcode_pack(ogf, ocf) ((__u16) ((ocf & 0x03ff)|(ogf << 10)))
1317#define hci_opcode_ogf(op) (op >> 10) 1400#define hci_opcode_ogf(op) (op >> 10)
1318#define hci_opcode_ocf(op) (op & 0x03ff) 1401#define hci_opcode_ocf(op) (op & 0x03ff)
1319 1402
1320/* ACL handle and flags pack/unpack */ 1403/* ACL handle and flags pack/unpack */
1321#define hci_handle_pack(h, f) (__u16) ((h & 0x0fff)|(f << 12)) 1404#define hci_handle_pack(h, f) ((__u16) ((h & 0x0fff)|(f << 12)))
1322#define hci_handle(h) (h & 0x0fff) 1405#define hci_handle(h) (h & 0x0fff)
1323#define hci_flags(h) (h >> 12) 1406#define hci_flags(h) (h >> 12)
1324 1407
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 9fc7728f94e4..20fd57367ddc 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -25,7 +25,6 @@
25#ifndef __HCI_CORE_H 25#ifndef __HCI_CORE_H
26#define __HCI_CORE_H 26#define __HCI_CORE_H
27 27
28#include <linux/interrupt.h>
29#include <net/bluetooth/hci.h> 28#include <net/bluetooth/hci.h>
30 29
31/* HCI priority */ 30/* HCI priority */
@@ -65,7 +64,7 @@ struct discovery_state {
65 DISCOVERY_RESOLVING, 64 DISCOVERY_RESOLVING,
66 DISCOVERY_STOPPING, 65 DISCOVERY_STOPPING,
67 } state; 66 } state;
68 struct list_head all; /* All devices found during inquiry */ 67 struct list_head all; /* All devices found during inquiry */
69 struct list_head unknown; /* Name state not known */ 68 struct list_head unknown; /* Name state not known */
70 struct list_head resolve; /* Name needs to be resolved */ 69 struct list_head resolve; /* Name needs to be resolved */
71 __u32 timestamp; 70 __u32 timestamp;
@@ -105,7 +104,7 @@ struct link_key {
105 struct list_head list; 104 struct list_head list;
106 bdaddr_t bdaddr; 105 bdaddr_t bdaddr;
107 u8 type; 106 u8 type;
108 u8 val[16]; 107 u8 val[HCI_LINK_KEY_SIZE];
109 u8 pin_len; 108 u8 pin_len;
110}; 109};
111 110
@@ -333,6 +332,7 @@ struct hci_conn {
333 void *l2cap_data; 332 void *l2cap_data;
334 void *sco_data; 333 void *sco_data;
335 void *smp_conn; 334 void *smp_conn;
335 struct amp_mgr *amp_mgr;
336 336
337 struct hci_conn *link; 337 struct hci_conn *link;
338 338
@@ -360,7 +360,8 @@ extern int l2cap_connect_cfm(struct hci_conn *hcon, u8 status);
360extern int l2cap_disconn_ind(struct hci_conn *hcon); 360extern int l2cap_disconn_ind(struct hci_conn *hcon);
361extern int l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason); 361extern int l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason);
362extern int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt); 362extern int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt);
363extern int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags); 363extern int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb,
364 u16 flags);
364 365
365extern int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr); 366extern int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
366extern int sco_connect_cfm(struct hci_conn *hcon, __u8 status); 367extern int sco_connect_cfm(struct hci_conn *hcon, __u8 status);
@@ -429,8 +430,8 @@ enum {
429static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) 430static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
430{ 431{
431 struct hci_dev *hdev = conn->hdev; 432 struct hci_dev *hdev = conn->hdev;
432 return (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) && 433 return test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) &&
433 test_bit(HCI_CONN_SSP_ENABLED, &conn->flags)); 434 test_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
434} 435}
435 436
436static inline void hci_conn_hash_init(struct hci_dev *hdev) 437static inline void hci_conn_hash_init(struct hci_dev *hdev)
@@ -640,6 +641,19 @@ static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
640 dev_set_drvdata(&hdev->dev, data); 641 dev_set_drvdata(&hdev->dev, data);
641} 642}
642 643
644/* hci_dev_list shall be locked */
645static inline uint8_t __hci_num_ctrl(void)
646{
647 uint8_t count = 0;
648 struct list_head *p;
649
650 list_for_each(p, &hci_dev_list) {
651 count++;
652 }
653
654 return count;
655}
656
643struct hci_dev *hci_dev_get(int index); 657struct hci_dev *hci_dev_get(int index);
644struct hci_dev *hci_get_route(bdaddr_t *src, bdaddr_t *dst); 658struct hci_dev *hci_get_route(bdaddr_t *src, bdaddr_t *dst);
645 659
@@ -661,7 +675,8 @@ int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
661int hci_get_auth_info(struct hci_dev *hdev, void __user *arg); 675int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
662int hci_inquiry(void __user *arg); 676int hci_inquiry(void __user *arg);
663 677
664struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr); 678struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev,
679 bdaddr_t *bdaddr);
665int hci_blacklist_clear(struct hci_dev *hdev); 680int hci_blacklist_clear(struct hci_dev *hdev);
666int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 681int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
667int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 682int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 1c7d1cd5e679..d80e3f0691b4 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -40,11 +40,11 @@
40#define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */ 40#define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */
41#define L2CAP_DEFAULT_MAX_PDU_SIZE 1009 /* Sized for 3-DH5 packet */ 41#define L2CAP_DEFAULT_MAX_PDU_SIZE 1009 /* Sized for 3-DH5 packet */
42#define L2CAP_DEFAULT_ACK_TO 200 42#define L2CAP_DEFAULT_ACK_TO 200
43#define L2CAP_LE_DEFAULT_MTU 23
44#define L2CAP_DEFAULT_MAX_SDU_SIZE 0xFFFF 43#define L2CAP_DEFAULT_MAX_SDU_SIZE 0xFFFF
45#define L2CAP_DEFAULT_SDU_ITIME 0xFFFFFFFF 44#define L2CAP_DEFAULT_SDU_ITIME 0xFFFFFFFF
46#define L2CAP_DEFAULT_ACC_LAT 0xFFFFFFFF 45#define L2CAP_DEFAULT_ACC_LAT 0xFFFFFFFF
47#define L2CAP_BREDR_MAX_PAYLOAD 1019 /* 3-DH5 packet */ 46#define L2CAP_BREDR_MAX_PAYLOAD 1019 /* 3-DH5 packet */
47#define L2CAP_LE_MIN_MTU 23
48 48
49#define L2CAP_DISC_TIMEOUT msecs_to_jiffies(100) 49#define L2CAP_DISC_TIMEOUT msecs_to_jiffies(100)
50#define L2CAP_DISC_REJ_TIMEOUT msecs_to_jiffies(5000) 50#define L2CAP_DISC_REJ_TIMEOUT msecs_to_jiffies(5000)
@@ -52,6 +52,8 @@
52#define L2CAP_CONN_TIMEOUT msecs_to_jiffies(40000) 52#define L2CAP_CONN_TIMEOUT msecs_to_jiffies(40000)
53#define L2CAP_INFO_TIMEOUT msecs_to_jiffies(4000) 53#define L2CAP_INFO_TIMEOUT msecs_to_jiffies(4000)
54 54
55#define L2CAP_A2MP_DEFAULT_MTU 670
56
55/* L2CAP socket address */ 57/* L2CAP socket address */
56struct sockaddr_l2 { 58struct sockaddr_l2 {
57 sa_family_t l2_family; 59 sa_family_t l2_family;
@@ -229,9 +231,14 @@ struct l2cap_conn_rsp {
229 __le16 status; 231 __le16 status;
230} __packed; 232} __packed;
231 233
234/* protocol/service multiplexer (PSM) */
235#define L2CAP_PSM_SDP 0x0001
236#define L2CAP_PSM_RFCOMM 0x0003
237
232/* channel indentifier */ 238/* channel indentifier */
233#define L2CAP_CID_SIGNALING 0x0001 239#define L2CAP_CID_SIGNALING 0x0001
234#define L2CAP_CID_CONN_LESS 0x0002 240#define L2CAP_CID_CONN_LESS 0x0002
241#define L2CAP_CID_A2MP 0x0003
235#define L2CAP_CID_LE_DATA 0x0004 242#define L2CAP_CID_LE_DATA 0x0004
236#define L2CAP_CID_LE_SIGNALING 0x0005 243#define L2CAP_CID_LE_SIGNALING 0x0005
237#define L2CAP_CID_SMP 0x0006 244#define L2CAP_CID_SMP 0x0006
@@ -271,6 +278,9 @@ struct l2cap_conf_rsp {
271#define L2CAP_CONF_PENDING 0x0004 278#define L2CAP_CONF_PENDING 0x0004
272#define L2CAP_CONF_EFS_REJECT 0x0005 279#define L2CAP_CONF_EFS_REJECT 0x0005
273 280
281/* configuration req/rsp continuation flag */
282#define L2CAP_CONF_FLAG_CONTINUATION 0x0001
283
274struct l2cap_conf_opt { 284struct l2cap_conf_opt {
275 __u8 type; 285 __u8 type;
276 __u8 len; 286 __u8 len;
@@ -419,11 +429,6 @@ struct l2cap_seq_list {
419#define L2CAP_SEQ_LIST_CLEAR 0xFFFF 429#define L2CAP_SEQ_LIST_CLEAR 0xFFFF
420#define L2CAP_SEQ_LIST_TAIL 0x8000 430#define L2CAP_SEQ_LIST_TAIL 0x8000
421 431
422struct srej_list {
423 __u16 tx_seq;
424 struct list_head list;
425};
426
427struct l2cap_chan { 432struct l2cap_chan {
428 struct sock *sk; 433 struct sock *sk;
429 434
@@ -475,14 +480,12 @@ struct l2cap_chan {
475 __u16 expected_ack_seq; 480 __u16 expected_ack_seq;
476 __u16 expected_tx_seq; 481 __u16 expected_tx_seq;
477 __u16 buffer_seq; 482 __u16 buffer_seq;
478 __u16 buffer_seq_srej;
479 __u16 srej_save_reqseq; 483 __u16 srej_save_reqseq;
480 __u16 last_acked_seq; 484 __u16 last_acked_seq;
481 __u16 frames_sent; 485 __u16 frames_sent;
482 __u16 unacked_frames; 486 __u16 unacked_frames;
483 __u8 retry_count; 487 __u8 retry_count;
484 __u16 srej_queue_next; 488 __u16 srej_queue_next;
485 __u8 num_acked;
486 __u16 sdu_len; 489 __u16 sdu_len;
487 struct sk_buff *sdu; 490 struct sk_buff *sdu;
488 struct sk_buff *sdu_last_frag; 491 struct sk_buff *sdu_last_frag;
@@ -515,7 +518,6 @@ struct l2cap_chan {
515 struct sk_buff_head srej_q; 518 struct sk_buff_head srej_q;
516 struct l2cap_seq_list srej_list; 519 struct l2cap_seq_list srej_list;
517 struct l2cap_seq_list retrans_list; 520 struct l2cap_seq_list retrans_list;
518 struct list_head srej_l;
519 521
520 struct list_head list; 522 struct list_head list;
521 struct list_head global_l; 523 struct list_head global_l;
@@ -528,10 +530,14 @@ struct l2cap_chan {
528struct l2cap_ops { 530struct l2cap_ops {
529 char *name; 531 char *name;
530 532
531 struct l2cap_chan *(*new_connection) (void *data); 533 struct l2cap_chan *(*new_connection) (struct l2cap_chan *chan);
532 int (*recv) (void *data, struct sk_buff *skb); 534 int (*recv) (struct l2cap_chan * chan,
533 void (*close) (void *data); 535 struct sk_buff *skb);
534 void (*state_change) (void *data, int state); 536 void (*teardown) (struct l2cap_chan *chan, int err);
537 void (*close) (struct l2cap_chan *chan);
538 void (*state_change) (struct l2cap_chan *chan,
539 int state);
540 void (*ready) (struct l2cap_chan *chan);
535 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan, 541 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
536 unsigned long len, int nb); 542 unsigned long len, int nb);
537}; 543};
@@ -575,6 +581,7 @@ struct l2cap_conn {
575#define L2CAP_CHAN_RAW 1 581#define L2CAP_CHAN_RAW 1
576#define L2CAP_CHAN_CONN_LESS 2 582#define L2CAP_CHAN_CONN_LESS 2
577#define L2CAP_CHAN_CONN_ORIENTED 3 583#define L2CAP_CHAN_CONN_ORIENTED 3
584#define L2CAP_CHAN_CONN_FIX_A2MP 4
578 585
579/* ----- L2CAP socket info ----- */ 586/* ----- L2CAP socket info ----- */
580#define l2cap_pi(sk) ((struct l2cap_pinfo *) sk) 587#define l2cap_pi(sk) ((struct l2cap_pinfo *) sk)
@@ -597,6 +604,7 @@ enum {
597 CONF_EWS_RECV, 604 CONF_EWS_RECV,
598 CONF_LOC_CONF_PEND, 605 CONF_LOC_CONF_PEND,
599 CONF_REM_CONF_PEND, 606 CONF_REM_CONF_PEND,
607 CONF_NOT_COMPLETE,
600}; 608};
601 609
602#define L2CAP_CONF_MAX_CONF_REQ 2 610#define L2CAP_CONF_MAX_CONF_REQ 2
@@ -713,11 +721,7 @@ static inline bool l2cap_clear_timer(struct l2cap_chan *chan,
713 721
714#define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t)) 722#define __set_chan_timer(c, t) l2cap_set_timer(c, &c->chan_timer, (t))
715#define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer) 723#define __clear_chan_timer(c) l2cap_clear_timer(c, &c->chan_timer)
716#define __set_retrans_timer(c) l2cap_set_timer(c, &c->retrans_timer, \
717 msecs_to_jiffies(L2CAP_DEFAULT_RETRANS_TO));
718#define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer) 724#define __clear_retrans_timer(c) l2cap_clear_timer(c, &c->retrans_timer)
719#define __set_monitor_timer(c) l2cap_set_timer(c, &c->monitor_timer, \
720 msecs_to_jiffies(L2CAP_DEFAULT_MONITOR_TO));
721#define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer) 725#define __clear_monitor_timer(c) l2cap_clear_timer(c, &c->monitor_timer)
722#define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \ 726#define __set_ack_timer(c) l2cap_set_timer(c, &chan->ack_timer, \
723 msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO)); 727 msecs_to_jiffies(L2CAP_DEFAULT_ACK_TO));
@@ -736,173 +740,17 @@ static inline __u16 __next_seq(struct l2cap_chan *chan, __u16 seq)
736 return (seq + 1) % (chan->tx_win_max + 1); 740 return (seq + 1) % (chan->tx_win_max + 1);
737} 741}
738 742
739static inline int l2cap_tx_window_full(struct l2cap_chan *ch) 743static inline struct l2cap_chan *l2cap_chan_no_new_connection(struct l2cap_chan *chan)
740{
741 int sub;
742
743 sub = (ch->next_tx_seq - ch->expected_ack_seq) % 64;
744
745 if (sub < 0)
746 sub += 64;
747
748 return sub == ch->remote_tx_win;
749}
750
751static inline __u16 __get_reqseq(struct l2cap_chan *chan, __u32 ctrl)
752{
753 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
754 return (ctrl & L2CAP_EXT_CTRL_REQSEQ) >>
755 L2CAP_EXT_CTRL_REQSEQ_SHIFT;
756 else
757 return (ctrl & L2CAP_CTRL_REQSEQ) >> L2CAP_CTRL_REQSEQ_SHIFT;
758}
759
760static inline __u32 __set_reqseq(struct l2cap_chan *chan, __u32 reqseq)
761{ 744{
762 if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 745 return NULL;
763 return (reqseq << L2CAP_EXT_CTRL_REQSEQ_SHIFT) &
764 L2CAP_EXT_CTRL_REQSEQ;
765 else
766 return (reqseq << L2CAP_CTRL_REQSEQ_SHIFT) & L2CAP_CTRL_REQSEQ;
767} 746}
768 747
769static inline __u16 __get_txseq(struct l2cap_chan *chan, __u32 ctrl) 748static inline void l2cap_chan_no_teardown(struct l2cap_chan *chan, int err)
770{ 749{
771 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
772 return (ctrl & L2CAP_EXT_CTRL_TXSEQ) >>
773 L2CAP_EXT_CTRL_TXSEQ_SHIFT;
774 else
775 return (ctrl & L2CAP_CTRL_TXSEQ) >> L2CAP_CTRL_TXSEQ_SHIFT;
776} 750}
777 751
778static inline __u32 __set_txseq(struct l2cap_chan *chan, __u32 txseq) 752static inline void l2cap_chan_no_ready(struct l2cap_chan *chan)
779{ 753{
780 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
781 return (txseq << L2CAP_EXT_CTRL_TXSEQ_SHIFT) &
782 L2CAP_EXT_CTRL_TXSEQ;
783 else
784 return (txseq << L2CAP_CTRL_TXSEQ_SHIFT) & L2CAP_CTRL_TXSEQ;
785}
786
787static inline bool __is_sframe(struct l2cap_chan *chan, __u32 ctrl)
788{
789 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
790 return ctrl & L2CAP_EXT_CTRL_FRAME_TYPE;
791 else
792 return ctrl & L2CAP_CTRL_FRAME_TYPE;
793}
794
795static inline __u32 __set_sframe(struct l2cap_chan *chan)
796{
797 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
798 return L2CAP_EXT_CTRL_FRAME_TYPE;
799 else
800 return L2CAP_CTRL_FRAME_TYPE;
801}
802
803static inline __u8 __get_ctrl_sar(struct l2cap_chan *chan, __u32 ctrl)
804{
805 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
806 return (ctrl & L2CAP_EXT_CTRL_SAR) >> L2CAP_EXT_CTRL_SAR_SHIFT;
807 else
808 return (ctrl & L2CAP_CTRL_SAR) >> L2CAP_CTRL_SAR_SHIFT;
809}
810
811static inline __u32 __set_ctrl_sar(struct l2cap_chan *chan, __u32 sar)
812{
813 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
814 return (sar << L2CAP_EXT_CTRL_SAR_SHIFT) & L2CAP_EXT_CTRL_SAR;
815 else
816 return (sar << L2CAP_CTRL_SAR_SHIFT) & L2CAP_CTRL_SAR;
817}
818
819static inline bool __is_sar_start(struct l2cap_chan *chan, __u32 ctrl)
820{
821 return __get_ctrl_sar(chan, ctrl) == L2CAP_SAR_START;
822}
823
824static inline __u32 __get_sar_mask(struct l2cap_chan *chan)
825{
826 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
827 return L2CAP_EXT_CTRL_SAR;
828 else
829 return L2CAP_CTRL_SAR;
830}
831
832static inline __u8 __get_ctrl_super(struct l2cap_chan *chan, __u32 ctrl)
833{
834 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
835 return (ctrl & L2CAP_EXT_CTRL_SUPERVISE) >>
836 L2CAP_EXT_CTRL_SUPER_SHIFT;
837 else
838 return (ctrl & L2CAP_CTRL_SUPERVISE) >> L2CAP_CTRL_SUPER_SHIFT;
839}
840
841static inline __u32 __set_ctrl_super(struct l2cap_chan *chan, __u32 super)
842{
843 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
844 return (super << L2CAP_EXT_CTRL_SUPER_SHIFT) &
845 L2CAP_EXT_CTRL_SUPERVISE;
846 else
847 return (super << L2CAP_CTRL_SUPER_SHIFT) &
848 L2CAP_CTRL_SUPERVISE;
849}
850
851static inline __u32 __set_ctrl_final(struct l2cap_chan *chan)
852{
853 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
854 return L2CAP_EXT_CTRL_FINAL;
855 else
856 return L2CAP_CTRL_FINAL;
857}
858
859static inline bool __is_ctrl_final(struct l2cap_chan *chan, __u32 ctrl)
860{
861 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
862 return ctrl & L2CAP_EXT_CTRL_FINAL;
863 else
864 return ctrl & L2CAP_CTRL_FINAL;
865}
866
867static inline __u32 __set_ctrl_poll(struct l2cap_chan *chan)
868{
869 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
870 return L2CAP_EXT_CTRL_POLL;
871 else
872 return L2CAP_CTRL_POLL;
873}
874
875static inline bool __is_ctrl_poll(struct l2cap_chan *chan, __u32 ctrl)
876{
877 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
878 return ctrl & L2CAP_EXT_CTRL_POLL;
879 else
880 return ctrl & L2CAP_CTRL_POLL;
881}
882
883static inline __u32 __get_control(struct l2cap_chan *chan, void *p)
884{
885 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
886 return get_unaligned_le32(p);
887 else
888 return get_unaligned_le16(p);
889}
890
891static inline void __put_control(struct l2cap_chan *chan, __u32 control,
892 void *p)
893{
894 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
895 return put_unaligned_le32(control, p);
896 else
897 return put_unaligned_le16(control, p);
898}
899
900static inline __u8 __ctrl_size(struct l2cap_chan *chan)
901{
902 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
903 return L2CAP_EXT_HDR_SIZE - L2CAP_HDR_SIZE;
904 else
905 return L2CAP_ENH_HDR_SIZE - L2CAP_HDR_SIZE;
906} 754}
907 755
908extern bool disable_ertm; 756extern bool disable_ertm;
@@ -926,5 +774,8 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
926void l2cap_chan_busy(struct l2cap_chan *chan, int busy); 774void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
927int l2cap_chan_check_security(struct l2cap_chan *chan); 775int l2cap_chan_check_security(struct l2cap_chan *chan);
928void l2cap_chan_set_defaults(struct l2cap_chan *chan); 776void l2cap_chan_set_defaults(struct l2cap_chan *chan);
777int l2cap_ertm_init(struct l2cap_chan *chan);
778void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan);
779void l2cap_chan_del(struct l2cap_chan *chan, int err);
929 780
930#endif /* __L2CAP_H */ 781#endif /* __L2CAP_H */
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 0289d4ce7070..7319f25250b6 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -404,6 +404,8 @@ struct cfg80211_beacon_data {
404 * 404 *
405 * Used to configure an AP interface. 405 * Used to configure an AP interface.
406 * 406 *
407 * @channel: the channel to start the AP on
408 * @channel_type: the channel type to use
407 * @beacon: beacon data 409 * @beacon: beacon data
408 * @beacon_interval: beacon interval 410 * @beacon_interval: beacon interval
409 * @dtim_period: DTIM period 411 * @dtim_period: DTIM period
@@ -417,6 +419,9 @@ struct cfg80211_beacon_data {
417 * @inactivity_timeout: time in seconds to determine station's inactivity. 419 * @inactivity_timeout: time in seconds to determine station's inactivity.
418 */ 420 */
419struct cfg80211_ap_settings { 421struct cfg80211_ap_settings {
422 struct ieee80211_channel *channel;
423 enum nl80211_channel_type channel_type;
424
420 struct cfg80211_beacon_data beacon; 425 struct cfg80211_beacon_data beacon;
421 426
422 int beacon_interval, dtim_period; 427 int beacon_interval, dtim_period;
@@ -826,6 +831,8 @@ struct mesh_config {
826 831
827/** 832/**
828 * struct mesh_setup - 802.11s mesh setup configuration 833 * struct mesh_setup - 802.11s mesh setup configuration
834 * @channel: the channel to start the mesh network on
835 * @channel_type: the channel type to use
829 * @mesh_id: the mesh ID 836 * @mesh_id: the mesh ID
830 * @mesh_id_len: length of the mesh ID, at least 1 and at most 32 bytes 837 * @mesh_id_len: length of the mesh ID, at least 1 and at most 32 bytes
831 * @sync_method: which synchronization method to use 838 * @sync_method: which synchronization method to use
@@ -840,6 +847,8 @@ struct mesh_config {
840 * These parameters are fixed when the mesh is created. 847 * These parameters are fixed when the mesh is created.
841 */ 848 */
842struct mesh_setup { 849struct mesh_setup {
850 struct ieee80211_channel *channel;
851 enum nl80211_channel_type channel_type;
843 const u8 *mesh_id; 852 const u8 *mesh_id;
844 u8 mesh_id_len; 853 u8 mesh_id_len;
845 u8 sync_method; 854 u8 sync_method;
@@ -1411,11 +1420,14 @@ struct cfg80211_gtk_rekey_data {
1411 * 1420 *
1412 * @set_txq_params: Set TX queue parameters 1421 * @set_txq_params: Set TX queue parameters
1413 * 1422 *
1414 * @set_channel: Set channel for a given wireless interface. Some devices 1423 * @libertas_set_mesh_channel: Only for backward compatibility for libertas,
1415 * may support multi-channel operation (by channel hopping) so cfg80211 1424 * as it doesn't implement join_mesh and needs to set the channel to
1416 * doesn't verify much. Note, however, that the passed netdev may be 1425 * join the mesh instead.
1417 * %NULL as well if the user requested changing the channel for the 1426 *
1418 * device itself, or for a monitor interface. 1427 * @set_monitor_channel: Set the monitor mode channel for the device. If other
1428 * interfaces are active this callback should reject the configuration.
1429 * If no interfaces are active or the device is down, the channel should
1430 * be stored for when a monitor interface becomes active.
1419 * @get_channel: Get the current operating channel, should return %NULL if 1431 * @get_channel: Get the current operating channel, should return %NULL if
1420 * there's no single defined operating channel if for example the 1432 * there's no single defined operating channel if for example the
1421 * device implements channel hopping for multi-channel virtual interfaces. 1433 * device implements channel hopping for multi-channel virtual interfaces.
@@ -1605,9 +1617,13 @@ struct cfg80211_ops {
1605 int (*set_txq_params)(struct wiphy *wiphy, struct net_device *dev, 1617 int (*set_txq_params)(struct wiphy *wiphy, struct net_device *dev,
1606 struct ieee80211_txq_params *params); 1618 struct ieee80211_txq_params *params);
1607 1619
1608 int (*set_channel)(struct wiphy *wiphy, struct net_device *dev, 1620 int (*libertas_set_mesh_channel)(struct wiphy *wiphy,
1609 struct ieee80211_channel *chan, 1621 struct net_device *dev,
1610 enum nl80211_channel_type channel_type); 1622 struct ieee80211_channel *chan);
1623
1624 int (*set_monitor_channel)(struct wiphy *wiphy,
1625 struct ieee80211_channel *chan,
1626 enum nl80211_channel_type channel_type);
1611 1627
1612 int (*scan)(struct wiphy *wiphy, struct net_device *dev, 1628 int (*scan)(struct wiphy *wiphy, struct net_device *dev,
1613 struct cfg80211_scan_request *request); 1629 struct cfg80211_scan_request *request);
@@ -2263,7 +2279,10 @@ struct cfg80211_cached_keys;
2263 * @netdev: (private) Used to reference back to the netdev 2279 * @netdev: (private) Used to reference back to the netdev
2264 * @current_bss: (private) Used by the internal configuration code 2280 * @current_bss: (private) Used by the internal configuration code
2265 * @channel: (private) Used by the internal configuration code to track 2281 * @channel: (private) Used by the internal configuration code to track
2266 * user-set AP, monitor and WDS channels for wireless extensions 2282 * the user-set AP, monitor and WDS channel
2283 * @preset_chan: (private) Used by the internal configuration code to
2284 * track the channel to be used for AP later
2285 * @preset_chantype: (private) the corresponding channel type
2267 * @bssid: (private) Used by the internal configuration code 2286 * @bssid: (private) Used by the internal configuration code
2268 * @ssid: (private) Used by the internal configuration code 2287 * @ssid: (private) Used by the internal configuration code
2269 * @ssid_len: (private) Used by the internal configuration code 2288 * @ssid_len: (private) Used by the internal configuration code
@@ -2313,7 +2332,8 @@ struct wireless_dev {
2313 spinlock_t event_lock; 2332 spinlock_t event_lock;
2314 2333
2315 struct cfg80211_internal_bss *current_bss; /* associated / joined */ 2334 struct cfg80211_internal_bss *current_bss; /* associated / joined */
2316 struct ieee80211_channel *channel; 2335 struct ieee80211_channel *preset_chan;
2336 enum nl80211_channel_type preset_chantype;
2317 2337
2318 bool ps; 2338 bool ps;
2319 int ps_timeout; 2339 int ps_timeout;
@@ -3359,11 +3379,14 @@ void cfg80211_report_obss_beacon(struct wiphy *wiphy,
3359 const u8 *frame, size_t len, 3379 const u8 *frame, size_t len,
3360 int freq, int sig_dbm, gfp_t gfp); 3380 int freq, int sig_dbm, gfp_t gfp);
3361 3381
3362/* 3382/**
3363 * cfg80211_can_beacon_sec_chan - test if ht40 on extension channel can be used 3383 * cfg80211_can_beacon_sec_chan - test if ht40 on extension channel can be used
3364 * @wiphy: the wiphy 3384 * @wiphy: the wiphy
3365 * @chan: main channel 3385 * @chan: main channel
3366 * @channel_type: HT mode 3386 * @channel_type: HT mode
3387 *
3388 * This function returns true if there is no secondary channel or the secondary
3389 * channel can be used for beaconing (i.e. is not a radar channel etc.)
3367 */ 3390 */
3368bool cfg80211_can_beacon_sec_chan(struct wiphy *wiphy, 3391bool cfg80211_can_beacon_sec_chan(struct wiphy *wiphy,
3369 struct ieee80211_channel *chan, 3392 struct ieee80211_channel *chan,
diff --git a/include/net/mac80211.h b/include/net/mac80211.h
index 95e39b6a02ec..6914f9978aea 100644
--- a/include/net/mac80211.h
+++ b/include/net/mac80211.h
@@ -1297,6 +1297,10 @@ enum ieee80211_hw_flags {
1297 * reports, by default it is set to _MCS, _GI and _BW but doesn't 1297 * reports, by default it is set to _MCS, _GI and _BW but doesn't
1298 * include _FMT. Use %IEEE80211_RADIOTAP_MCS_HAVE_* values, only 1298 * include _FMT. Use %IEEE80211_RADIOTAP_MCS_HAVE_* values, only
1299 * adding _BW is supported today. 1299 * adding _BW is supported today.
1300 *
1301 * @netdev_features: netdev features to be set in each netdev created
1302 * from this HW. Note only HW checksum features are currently
1303 * compatible with mac80211. Other feature bits will be rejected.
1300 */ 1304 */
1301struct ieee80211_hw { 1305struct ieee80211_hw {
1302 struct ieee80211_conf conf; 1306 struct ieee80211_conf conf;
@@ -1319,6 +1323,7 @@ struct ieee80211_hw {
1319 u8 max_tx_aggregation_subframes; 1323 u8 max_tx_aggregation_subframes;
1320 u8 offchannel_tx_hw_queue; 1324 u8 offchannel_tx_hw_queue;
1321 u8 radiotap_mcs_details; 1325 u8 radiotap_mcs_details;
1326 netdev_features_t netdev_features;
1322}; 1327};
1323 1328
1324/** 1329/**
@@ -2183,7 +2188,10 @@ enum ieee80211_rate_control_changed {
2183 * offload. Frames to transmit on the off-channel channel are transmitted 2188 * offload. Frames to transmit on the off-channel channel are transmitted
2184 * normally except for the %IEEE80211_TX_CTL_TX_OFFCHAN flag. When the 2189 * normally except for the %IEEE80211_TX_CTL_TX_OFFCHAN flag. When the
2185 * duration (which will always be non-zero) expires, the driver must call 2190 * duration (which will always be non-zero) expires, the driver must call
2186 * ieee80211_remain_on_channel_expired(). This callback may sleep. 2191 * ieee80211_remain_on_channel_expired().
2192 * Note that this callback may be called while the device is in IDLE and
2193 * must be accepted in this case.
2194 * This callback may sleep.
2187 * @cancel_remain_on_channel: Requests that an ongoing off-channel period is 2195 * @cancel_remain_on_channel: Requests that an ongoing off-channel period is
2188 * aborted before it expires. This callback may sleep. 2196 * aborted before it expires. This callback may sleep.
2189 * 2197 *
@@ -3557,16 +3565,6 @@ void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
3557 gfp_t gfp); 3565 gfp_t gfp);
3558 3566
3559/** 3567/**
3560 * ieee80211_get_operstate - get the operstate of the vif
3561 *
3562 * @vif: &struct ieee80211_vif pointer from the add_interface callback.
3563 *
3564 * The driver might need to know the operstate of the net_device
3565 * (specifically, whether the link is IF_OPER_UP after resume)
3566 */
3567unsigned char ieee80211_get_operstate(struct ieee80211_vif *vif);
3568
3569/**
3570 * ieee80211_chswitch_done - Complete channel switch process 3568 * ieee80211_chswitch_done - Complete channel switch process
3571 * @vif: &struct ieee80211_vif pointer from the add_interface callback. 3569 * @vif: &struct ieee80211_vif pointer from the add_interface callback.
3572 * @success: make the channel switch successful or not 3570 * @success: make the channel switch successful or not
@@ -3845,4 +3843,28 @@ int ieee80211_add_ext_srates_ie(struct ieee80211_vif *vif,
3845 */ 3843 */
3846int ieee80211_ave_rssi(struct ieee80211_vif *vif); 3844int ieee80211_ave_rssi(struct ieee80211_vif *vif);
3847 3845
3846/* Extra debugging macros */
3847
3848#ifdef CONFIG_MAC80211_HT_DEBUG
3849#define ht_vdbg(fmt, ...) \
3850 pr_debug(fmt, ##__VA_ARGS__)
3851#else
3852#define ht_vdbg(fmt, ...) \
3853do { \
3854 if (0) \
3855 pr_debug(fmt, ##__VA_ARGS__); \
3856} while (0)
3857#endif
3858
3859#ifdef CONFIG_MAC80211_IBSS_DEBUG
3860#define ibss_vdbg(fmt, ...) \
3861 pr_debug(fmt, ##__VA_ARGS__)
3862#else
3863#define ibss_vdbg(fmt, ...) \
3864do { \
3865 if (0) \
3866 pr_debug(fmt, ##__VA_ARGS__); \
3867} while (0)
3868#endif
3869
3848#endif /* MAC80211_H */ 3870#endif /* MAC80211_H */
diff --git a/include/net/nfc/hci.h b/include/net/nfc/hci.h
index 4467c9460857..e30e6a869714 100644
--- a/include/net/nfc/hci.h
+++ b/include/net/nfc/hci.h
@@ -31,7 +31,8 @@ struct nfc_hci_ops {
31 void (*close) (struct nfc_hci_dev *hdev); 31 void (*close) (struct nfc_hci_dev *hdev);
32 int (*hci_ready) (struct nfc_hci_dev *hdev); 32 int (*hci_ready) (struct nfc_hci_dev *hdev);
33 int (*xmit) (struct nfc_hci_dev *hdev, struct sk_buff *skb); 33 int (*xmit) (struct nfc_hci_dev *hdev, struct sk_buff *skb);
34 int (*start_poll) (struct nfc_hci_dev *hdev, u32 protocols); 34 int (*start_poll) (struct nfc_hci_dev *hdev,
35 u32 im_protocols, u32 tm_protocols);
35 int (*target_from_gate) (struct nfc_hci_dev *hdev, u8 gate, 36 int (*target_from_gate) (struct nfc_hci_dev *hdev, u8 gate,
36 struct nfc_target *target); 37 struct nfc_target *target);
37 int (*complete_target_discovered) (struct nfc_hci_dev *hdev, u8 gate, 38 int (*complete_target_discovered) (struct nfc_hci_dev *hdev, u8 gate,
diff --git a/include/net/nfc/nfc.h b/include/net/nfc/nfc.h
index b7ca4a2a1d72..180964b954ab 100644
--- a/include/net/nfc/nfc.h
+++ b/include/net/nfc/nfc.h
@@ -53,7 +53,8 @@ struct nfc_target;
53struct nfc_ops { 53struct nfc_ops {
54 int (*dev_up)(struct nfc_dev *dev); 54 int (*dev_up)(struct nfc_dev *dev);
55 int (*dev_down)(struct nfc_dev *dev); 55 int (*dev_down)(struct nfc_dev *dev);
56 int (*start_poll)(struct nfc_dev *dev, u32 protocols); 56 int (*start_poll)(struct nfc_dev *dev,
57 u32 im_protocols, u32 tm_protocols);
57 void (*stop_poll)(struct nfc_dev *dev); 58 void (*stop_poll)(struct nfc_dev *dev);
58 int (*dep_link_up)(struct nfc_dev *dev, struct nfc_target *target, 59 int (*dep_link_up)(struct nfc_dev *dev, struct nfc_target *target,
59 u8 comm_mode, u8 *gb, size_t gb_len); 60 u8 comm_mode, u8 *gb, size_t gb_len);
@@ -62,9 +63,10 @@ struct nfc_ops {
62 u32 protocol); 63 u32 protocol);
63 void (*deactivate_target)(struct nfc_dev *dev, 64 void (*deactivate_target)(struct nfc_dev *dev,
64 struct nfc_target *target); 65 struct nfc_target *target);
65 int (*data_exchange)(struct nfc_dev *dev, struct nfc_target *target, 66 int (*im_transceive)(struct nfc_dev *dev, struct nfc_target *target,
66 struct sk_buff *skb, data_exchange_cb_t cb, 67 struct sk_buff *skb, data_exchange_cb_t cb,
67 void *cb_context); 68 void *cb_context);
69 int (*tm_send)(struct nfc_dev *dev, struct sk_buff *skb);
68 int (*check_presence)(struct nfc_dev *dev, struct nfc_target *target); 70 int (*check_presence)(struct nfc_dev *dev, struct nfc_target *target);
69}; 71};
70 72
@@ -99,10 +101,10 @@ struct nfc_dev {
99 int targets_generation; 101 int targets_generation;
100 struct device dev; 102 struct device dev;
101 bool dev_up; 103 bool dev_up;
104 u8 rf_mode;
102 bool polling; 105 bool polling;
103 struct nfc_target *active_target; 106 struct nfc_target *active_target;
104 bool dep_link_up; 107 bool dep_link_up;
105 u32 dep_rf_mode;
106 struct nfc_genl_data genl_data; 108 struct nfc_genl_data genl_data;
107 u32 supported_protocols; 109 u32 supported_protocols;
108 110
@@ -188,6 +190,7 @@ struct sk_buff *nfc_alloc_recv_skb(unsigned int size, gfp_t gfp);
188 190
189int nfc_set_remote_general_bytes(struct nfc_dev *dev, 191int nfc_set_remote_general_bytes(struct nfc_dev *dev,
190 u8 *gt, u8 gt_len); 192 u8 *gt, u8 gt_len);
193u8 *nfc_get_local_general_bytes(struct nfc_dev *dev, size_t *gb_len);
191 194
192int nfc_targets_found(struct nfc_dev *dev, 195int nfc_targets_found(struct nfc_dev *dev,
193 struct nfc_target *targets, int ntargets); 196 struct nfc_target *targets, int ntargets);
@@ -196,4 +199,9 @@ int nfc_target_lost(struct nfc_dev *dev, u32 target_idx);
196int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx, 199int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx,
197 u8 comm_mode, u8 rf_mode); 200 u8 comm_mode, u8 rf_mode);
198 201
202int nfc_tm_activated(struct nfc_dev *dev, u32 protocol, u8 comm_mode,
203 u8 *gb, size_t gb_len);
204int nfc_tm_deactivated(struct nfc_dev *dev);
205int nfc_tm_data_received(struct nfc_dev *dev, struct sk_buff *skb);
206
199#endif /* __NET_NFC_H */ 207#endif /* __NET_NFC_H */
diff --git a/include/net/nfc/shdlc.h b/include/net/nfc/shdlc.h
index ab06afd462da..35e930d2f638 100644
--- a/include/net/nfc/shdlc.h
+++ b/include/net/nfc/shdlc.h
@@ -27,7 +27,8 @@ struct nfc_shdlc_ops {
27 void (*close) (struct nfc_shdlc *shdlc); 27 void (*close) (struct nfc_shdlc *shdlc);
28 int (*hci_ready) (struct nfc_shdlc *shdlc); 28 int (*hci_ready) (struct nfc_shdlc *shdlc);
29 int (*xmit) (struct nfc_shdlc *shdlc, struct sk_buff *skb); 29 int (*xmit) (struct nfc_shdlc *shdlc, struct sk_buff *skb);
30 int (*start_poll) (struct nfc_shdlc *shdlc, u32 protocols); 30 int (*start_poll) (struct nfc_shdlc *shdlc,
31 u32 im_protocols, u32 tm_protocols);
31 int (*target_from_gate) (struct nfc_shdlc *shdlc, u8 gate, 32 int (*target_from_gate) (struct nfc_shdlc *shdlc, u8 gate,
32 struct nfc_target *target); 33 struct nfc_target *target);
33 int (*complete_target_discovered) (struct nfc_shdlc *shdlc, u8 gate, 34 int (*complete_target_discovered) (struct nfc_shdlc *shdlc, u8 gate,
diff --git a/net/bluetooth/Makefile b/net/bluetooth/Makefile
index 2dc5a5700f53..fa6d94a4602a 100644
--- a/net/bluetooth/Makefile
+++ b/net/bluetooth/Makefile
@@ -9,4 +9,5 @@ obj-$(CONFIG_BT_CMTP) += cmtp/
9obj-$(CONFIG_BT_HIDP) += hidp/ 9obj-$(CONFIG_BT_HIDP) += hidp/
10 10
11bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \ 11bluetooth-y := af_bluetooth.o hci_core.o hci_conn.o hci_event.o mgmt.o \
12 hci_sock.o hci_sysfs.o l2cap_core.o l2cap_sock.o smp.o sco.o lib.o 12 hci_sock.o hci_sysfs.o l2cap_core.o l2cap_sock.o smp.o sco.o lib.o \
13 a2mp.o
diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c
new file mode 100644
index 000000000000..fb93250b3938
--- /dev/null
+++ b/net/bluetooth/a2mp.c
@@ -0,0 +1,568 @@
1/*
2 Copyright (c) 2010,2011 Code Aurora Forum. All rights reserved.
3 Copyright (c) 2011,2012 Intel Corp.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 and
7 only version 2 as published by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13*/
14
15#include <net/bluetooth/bluetooth.h>
16#include <net/bluetooth/hci_core.h>
17#include <net/bluetooth/l2cap.h>
18#include <net/bluetooth/a2mp.h>
19
20/* A2MP build & send command helper functions */
21static struct a2mp_cmd *__a2mp_build(u8 code, u8 ident, u16 len, void *data)
22{
23 struct a2mp_cmd *cmd;
24 int plen;
25
26 plen = sizeof(*cmd) + len;
27 cmd = kzalloc(plen, GFP_KERNEL);
28 if (!cmd)
29 return NULL;
30
31 cmd->code = code;
32 cmd->ident = ident;
33 cmd->len = cpu_to_le16(len);
34
35 memcpy(cmd->data, data, len);
36
37 return cmd;
38}
39
40static void a2mp_send(struct amp_mgr *mgr, u8 code, u8 ident, u16 len,
41 void *data)
42{
43 struct l2cap_chan *chan = mgr->a2mp_chan;
44 struct a2mp_cmd *cmd;
45 u16 total_len = len + sizeof(*cmd);
46 struct kvec iv;
47 struct msghdr msg;
48
49 cmd = __a2mp_build(code, ident, len, data);
50 if (!cmd)
51 return;
52
53 iv.iov_base = cmd;
54 iv.iov_len = total_len;
55
56 memset(&msg, 0, sizeof(msg));
57
58 msg.msg_iov = (struct iovec *) &iv;
59 msg.msg_iovlen = 1;
60
61 l2cap_chan_send(chan, &msg, total_len, 0);
62
63 kfree(cmd);
64}
65
66static inline void __a2mp_cl_bredr(struct a2mp_cl *cl)
67{
68 cl->id = 0;
69 cl->type = 0;
70 cl->status = 1;
71}
72
73/* hci_dev_list shall be locked */
74static void __a2mp_add_cl(struct amp_mgr *mgr, struct a2mp_cl *cl, u8 num_ctrl)
75{
76 int i = 0;
77 struct hci_dev *hdev;
78
79 __a2mp_cl_bredr(cl);
80
81 list_for_each_entry(hdev, &hci_dev_list, list) {
82 /* Iterate through AMP controllers */
83 if (hdev->id == HCI_BREDR_ID)
84 continue;
85
86 /* Starting from second entry */
87 if (++i >= num_ctrl)
88 return;
89
90 cl[i].id = hdev->id;
91 cl[i].type = hdev->amp_type;
92 cl[i].status = hdev->amp_status;
93 }
94}
95
96/* Processing A2MP messages */
97static int a2mp_command_rej(struct amp_mgr *mgr, struct sk_buff *skb,
98 struct a2mp_cmd *hdr)
99{
100 struct a2mp_cmd_rej *rej = (void *) skb->data;
101
102 if (le16_to_cpu(hdr->len) < sizeof(*rej))
103 return -EINVAL;
104
105 BT_DBG("ident %d reason %d", hdr->ident, le16_to_cpu(rej->reason));
106
107 skb_pull(skb, sizeof(*rej));
108
109 return 0;
110}
111
112static int a2mp_discover_req(struct amp_mgr *mgr, struct sk_buff *skb,
113 struct a2mp_cmd *hdr)
114{
115 struct a2mp_discov_req *req = (void *) skb->data;
116 u16 len = le16_to_cpu(hdr->len);
117 struct a2mp_discov_rsp *rsp;
118 u16 ext_feat;
119 u8 num_ctrl;
120
121 if (len < sizeof(*req))
122 return -EINVAL;
123
124 skb_pull(skb, sizeof(*req));
125
126 ext_feat = le16_to_cpu(req->ext_feat);
127
128 BT_DBG("mtu %d efm 0x%4.4x", le16_to_cpu(req->mtu), ext_feat);
129
130 /* check that packet is not broken for now */
131 while (ext_feat & A2MP_FEAT_EXT) {
132 if (len < sizeof(ext_feat))
133 return -EINVAL;
134
135 ext_feat = get_unaligned_le16(skb->data);
136 BT_DBG("efm 0x%4.4x", ext_feat);
137 len -= sizeof(ext_feat);
138 skb_pull(skb, sizeof(ext_feat));
139 }
140
141 read_lock(&hci_dev_list_lock);
142
143 num_ctrl = __hci_num_ctrl();
144 len = num_ctrl * sizeof(struct a2mp_cl) + sizeof(*rsp);
145 rsp = kmalloc(len, GFP_ATOMIC);
146 if (!rsp) {
147 read_unlock(&hci_dev_list_lock);
148 return -ENOMEM;
149 }
150
151 rsp->mtu = __constant_cpu_to_le16(L2CAP_A2MP_DEFAULT_MTU);
152 rsp->ext_feat = 0;
153
154 __a2mp_add_cl(mgr, rsp->cl, num_ctrl);
155
156 read_unlock(&hci_dev_list_lock);
157
158 a2mp_send(mgr, A2MP_DISCOVER_RSP, hdr->ident, len, rsp);
159
160 kfree(rsp);
161 return 0;
162}
163
164static int a2mp_change_notify(struct amp_mgr *mgr, struct sk_buff *skb,
165 struct a2mp_cmd *hdr)
166{
167 struct a2mp_cl *cl = (void *) skb->data;
168
169 while (skb->len >= sizeof(*cl)) {
170 BT_DBG("Controller id %d type %d status %d", cl->id, cl->type,
171 cl->status);
172 cl = (struct a2mp_cl *) skb_pull(skb, sizeof(*cl));
173 }
174
175 /* TODO send A2MP_CHANGE_RSP */
176
177 return 0;
178}
179
180static int a2mp_getinfo_req(struct amp_mgr *mgr, struct sk_buff *skb,
181 struct a2mp_cmd *hdr)
182{
183 struct a2mp_info_req *req = (void *) skb->data;
184 struct a2mp_info_rsp rsp;
185 struct hci_dev *hdev;
186
187 if (le16_to_cpu(hdr->len) < sizeof(*req))
188 return -EINVAL;
189
190 BT_DBG("id %d", req->id);
191
192 rsp.id = req->id;
193 rsp.status = A2MP_STATUS_INVALID_CTRL_ID;
194
195 hdev = hci_dev_get(req->id);
196 if (hdev && hdev->amp_type != HCI_BREDR) {
197 rsp.status = 0;
198 rsp.total_bw = cpu_to_le32(hdev->amp_total_bw);
199 rsp.max_bw = cpu_to_le32(hdev->amp_max_bw);
200 rsp.min_latency = cpu_to_le32(hdev->amp_min_latency);
201 rsp.pal_cap = cpu_to_le16(hdev->amp_pal_cap);
202 rsp.assoc_size = cpu_to_le16(hdev->amp_assoc_size);
203 }
204
205 if (hdev)
206 hci_dev_put(hdev);
207
208 a2mp_send(mgr, A2MP_GETINFO_RSP, hdr->ident, sizeof(rsp), &rsp);
209
210 skb_pull(skb, sizeof(*req));
211 return 0;
212}
213
214static int a2mp_getampassoc_req(struct amp_mgr *mgr, struct sk_buff *skb,
215 struct a2mp_cmd *hdr)
216{
217 struct a2mp_amp_assoc_req *req = (void *) skb->data;
218 struct hci_dev *hdev;
219
220 if (le16_to_cpu(hdr->len) < sizeof(*req))
221 return -EINVAL;
222
223 BT_DBG("id %d", req->id);
224
225 hdev = hci_dev_get(req->id);
226 if (!hdev || hdev->amp_type == HCI_BREDR) {
227 struct a2mp_amp_assoc_rsp rsp;
228 rsp.id = req->id;
229 rsp.status = A2MP_STATUS_INVALID_CTRL_ID;
230
231 a2mp_send(mgr, A2MP_GETAMPASSOC_RSP, hdr->ident, sizeof(rsp),
232 &rsp);
233 goto clean;
234 }
235
236 /* Placeholder for HCI Read AMP Assoc */
237
238clean:
239 if (hdev)
240 hci_dev_put(hdev);
241
242 skb_pull(skb, sizeof(*req));
243 return 0;
244}
245
246static int a2mp_createphyslink_req(struct amp_mgr *mgr, struct sk_buff *skb,
247 struct a2mp_cmd *hdr)
248{
249 struct a2mp_physlink_req *req = (void *) skb->data;
250
251 struct a2mp_physlink_rsp rsp;
252 struct hci_dev *hdev;
253
254 if (le16_to_cpu(hdr->len) < sizeof(*req))
255 return -EINVAL;
256
257 BT_DBG("local_id %d, remote_id %d", req->local_id, req->remote_id);
258
259 rsp.local_id = req->remote_id;
260 rsp.remote_id = req->local_id;
261
262 hdev = hci_dev_get(req->remote_id);
263 if (!hdev || hdev->amp_type != HCI_AMP) {
264 rsp.status = A2MP_STATUS_INVALID_CTRL_ID;
265 goto send_rsp;
266 }
267
268 /* TODO process physlink create */
269
270 rsp.status = A2MP_STATUS_SUCCESS;
271
272send_rsp:
273 if (hdev)
274 hci_dev_put(hdev);
275
276 a2mp_send(mgr, A2MP_CREATEPHYSLINK_RSP, hdr->ident, sizeof(rsp),
277 &rsp);
278
279 skb_pull(skb, le16_to_cpu(hdr->len));
280 return 0;
281}
282
283static int a2mp_discphyslink_req(struct amp_mgr *mgr, struct sk_buff *skb,
284 struct a2mp_cmd *hdr)
285{
286 struct a2mp_physlink_req *req = (void *) skb->data;
287 struct a2mp_physlink_rsp rsp;
288 struct hci_dev *hdev;
289
290 if (le16_to_cpu(hdr->len) < sizeof(*req))
291 return -EINVAL;
292
293 BT_DBG("local_id %d remote_id %d", req->local_id, req->remote_id);
294
295 rsp.local_id = req->remote_id;
296 rsp.remote_id = req->local_id;
297 rsp.status = A2MP_STATUS_SUCCESS;
298
299 hdev = hci_dev_get(req->local_id);
300 if (!hdev) {
301 rsp.status = A2MP_STATUS_INVALID_CTRL_ID;
302 goto send_rsp;
303 }
304
305 /* TODO Disconnect Phys Link here */
306
307 hci_dev_put(hdev);
308
309send_rsp:
310 a2mp_send(mgr, A2MP_DISCONNPHYSLINK_RSP, hdr->ident, sizeof(rsp), &rsp);
311
312 skb_pull(skb, sizeof(*req));
313 return 0;
314}
315
316static inline int a2mp_cmd_rsp(struct amp_mgr *mgr, struct sk_buff *skb,
317 struct a2mp_cmd *hdr)
318{
319 BT_DBG("ident %d code %d", hdr->ident, hdr->code);
320
321 skb_pull(skb, le16_to_cpu(hdr->len));
322 return 0;
323}
324
325/* Handle A2MP signalling */
326static int a2mp_chan_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb)
327{
328 struct a2mp_cmd *hdr = (void *) skb->data;
329 struct amp_mgr *mgr = chan->data;
330 int err = 0;
331
332 amp_mgr_get(mgr);
333
334 while (skb->len >= sizeof(*hdr)) {
335 struct a2mp_cmd *hdr = (void *) skb->data;
336 u16 len = le16_to_cpu(hdr->len);
337
338 BT_DBG("code 0x%02x id %d len %d", hdr->code, hdr->ident, len);
339
340 skb_pull(skb, sizeof(*hdr));
341
342 if (len > skb->len || !hdr->ident) {
343 err = -EINVAL;
344 break;
345 }
346
347 mgr->ident = hdr->ident;
348
349 switch (hdr->code) {
350 case A2MP_COMMAND_REJ:
351 a2mp_command_rej(mgr, skb, hdr);
352 break;
353
354 case A2MP_DISCOVER_REQ:
355 err = a2mp_discover_req(mgr, skb, hdr);
356 break;
357
358 case A2MP_CHANGE_NOTIFY:
359 err = a2mp_change_notify(mgr, skb, hdr);
360 break;
361
362 case A2MP_GETINFO_REQ:
363 err = a2mp_getinfo_req(mgr, skb, hdr);
364 break;
365
366 case A2MP_GETAMPASSOC_REQ:
367 err = a2mp_getampassoc_req(mgr, skb, hdr);
368 break;
369
370 case A2MP_CREATEPHYSLINK_REQ:
371 err = a2mp_createphyslink_req(mgr, skb, hdr);
372 break;
373
374 case A2MP_DISCONNPHYSLINK_REQ:
375 err = a2mp_discphyslink_req(mgr, skb, hdr);
376 break;
377
378 case A2MP_CHANGE_RSP:
379 case A2MP_DISCOVER_RSP:
380 case A2MP_GETINFO_RSP:
381 case A2MP_GETAMPASSOC_RSP:
382 case A2MP_CREATEPHYSLINK_RSP:
383 case A2MP_DISCONNPHYSLINK_RSP:
384 err = a2mp_cmd_rsp(mgr, skb, hdr);
385 break;
386
387 default:
388 BT_ERR("Unknown A2MP sig cmd 0x%2.2x", hdr->code);
389 err = -EINVAL;
390 break;
391 }
392 }
393
394 if (err) {
395 struct a2mp_cmd_rej rej;
396 rej.reason = __constant_cpu_to_le16(0);
397
398 BT_DBG("Send A2MP Rej: cmd 0x%2.2x err %d", hdr->code, err);
399
400 a2mp_send(mgr, A2MP_COMMAND_REJ, hdr->ident, sizeof(rej),
401 &rej);
402 }
403
404 /* Always free skb and return success error code to prevent
405 from sending L2CAP Disconnect over A2MP channel */
406 kfree_skb(skb);
407
408 amp_mgr_put(mgr);
409
410 return 0;
411}
412
413static void a2mp_chan_close_cb(struct l2cap_chan *chan)
414{
415 l2cap_chan_destroy(chan);
416}
417
418static void a2mp_chan_state_change_cb(struct l2cap_chan *chan, int state)
419{
420 struct amp_mgr *mgr = chan->data;
421
422 if (!mgr)
423 return;
424
425 BT_DBG("chan %p state %s", chan, state_to_string(state));
426
427 chan->state = state;
428
429 switch (state) {
430 case BT_CLOSED:
431 if (mgr)
432 amp_mgr_put(mgr);
433 break;
434 }
435}
436
437static struct sk_buff *a2mp_chan_alloc_skb_cb(struct l2cap_chan *chan,
438 unsigned long len, int nb)
439{
440 return bt_skb_alloc(len, GFP_KERNEL);
441}
442
443static struct l2cap_ops a2mp_chan_ops = {
444 .name = "L2CAP A2MP channel",
445 .recv = a2mp_chan_recv_cb,
446 .close = a2mp_chan_close_cb,
447 .state_change = a2mp_chan_state_change_cb,
448 .alloc_skb = a2mp_chan_alloc_skb_cb,
449
450 /* Not implemented for A2MP */
451 .new_connection = l2cap_chan_no_new_connection,
452 .teardown = l2cap_chan_no_teardown,
453 .ready = l2cap_chan_no_ready,
454};
455
456static struct l2cap_chan *a2mp_chan_open(struct l2cap_conn *conn)
457{
458 struct l2cap_chan *chan;
459 int err;
460
461 chan = l2cap_chan_create();
462 if (!chan)
463 return NULL;
464
465 BT_DBG("chan %p", chan);
466
467 chan->chan_type = L2CAP_CHAN_CONN_FIX_A2MP;
468 chan->flush_to = L2CAP_DEFAULT_FLUSH_TO;
469
470 chan->ops = &a2mp_chan_ops;
471
472 l2cap_chan_set_defaults(chan);
473 chan->remote_max_tx = chan->max_tx;
474 chan->remote_tx_win = chan->tx_win;
475
476 chan->retrans_timeout = L2CAP_DEFAULT_RETRANS_TO;
477 chan->monitor_timeout = L2CAP_DEFAULT_MONITOR_TO;
478
479 skb_queue_head_init(&chan->tx_q);
480
481 chan->mode = L2CAP_MODE_ERTM;
482
483 err = l2cap_ertm_init(chan);
484 if (err < 0) {
485 l2cap_chan_del(chan, 0);
486 return NULL;
487 }
488
489 chan->conf_state = 0;
490
491 l2cap_chan_add(conn, chan);
492
493 chan->remote_mps = chan->omtu;
494 chan->mps = chan->omtu;
495
496 chan->state = BT_CONNECTED;
497
498 return chan;
499}
500
501/* AMP Manager functions */
502void amp_mgr_get(struct amp_mgr *mgr)
503{
504 BT_DBG("mgr %p", mgr);
505
506 kref_get(&mgr->kref);
507}
508
509static void amp_mgr_destroy(struct kref *kref)
510{
511 struct amp_mgr *mgr = container_of(kref, struct amp_mgr, kref);
512
513 BT_DBG("mgr %p", mgr);
514
515 kfree(mgr);
516}
517
518int amp_mgr_put(struct amp_mgr *mgr)
519{
520 BT_DBG("mgr %p", mgr);
521
522 return kref_put(&mgr->kref, &amp_mgr_destroy);
523}
524
525static struct amp_mgr *amp_mgr_create(struct l2cap_conn *conn)
526{
527 struct amp_mgr *mgr;
528 struct l2cap_chan *chan;
529
530 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
531 if (!mgr)
532 return NULL;
533
534 BT_DBG("conn %p mgr %p", conn, mgr);
535
536 mgr->l2cap_conn = conn;
537
538 chan = a2mp_chan_open(conn);
539 if (!chan) {
540 kfree(mgr);
541 return NULL;
542 }
543
544 mgr->a2mp_chan = chan;
545 chan->data = mgr;
546
547 conn->hcon->amp_mgr = mgr;
548
549 kref_init(&mgr->kref);
550
551 return mgr;
552}
553
554struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn,
555 struct sk_buff *skb)
556{
557 struct amp_mgr *mgr;
558
559 mgr = amp_mgr_create(conn);
560 if (!mgr) {
561 BT_ERR("Could not create AMP manager");
562 return NULL;
563 }
564
565 BT_DBG("mgr: %p chan %p", mgr, mgr->a2mp_chan);
566
567 return mgr->a2mp_chan;
568}
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 3e18af4dadc4..f7db5792ec64 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -25,18 +25,7 @@
25/* Bluetooth address family and sockets. */ 25/* Bluetooth address family and sockets. */
26 26
27#include <linux/module.h> 27#include <linux/module.h>
28
29#include <linux/types.h>
30#include <linux/list.h>
31#include <linux/errno.h>
32#include <linux/kernel.h>
33#include <linux/sched.h>
34#include <linux/skbuff.h>
35#include <linux/init.h>
36#include <linux/poll.h>
37#include <net/sock.h>
38#include <asm/ioctls.h> 28#include <asm/ioctls.h>
39#include <linux/kmod.h>
40 29
41#include <net/bluetooth/bluetooth.h> 30#include <net/bluetooth/bluetooth.h>
42 31
@@ -418,7 +407,8 @@ static inline unsigned int bt_accept_poll(struct sock *parent)
418 return 0; 407 return 0;
419} 408}
420 409
421unsigned int bt_sock_poll(struct file *file, struct socket *sock, poll_table *wait) 410unsigned int bt_sock_poll(struct file *file, struct socket *sock,
411 poll_table *wait)
422{ 412{
423 struct sock *sk = sock->sk; 413 struct sock *sk = sock->sk;
424 unsigned int mask = 0; 414 unsigned int mask = 0;
diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index 031d7d656754..4a6620bc1570 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -26,26 +26,9 @@
26*/ 26*/
27 27
28#include <linux/module.h> 28#include <linux/module.h>
29
30#include <linux/kernel.h>
31#include <linux/sched.h>
32#include <linux/signal.h>
33#include <linux/init.h>
34#include <linux/wait.h>
35#include <linux/freezer.h>
36#include <linux/errno.h>
37#include <linux/net.h>
38#include <linux/slab.h>
39#include <linux/kthread.h> 29#include <linux/kthread.h>
40#include <net/sock.h>
41
42#include <linux/socket.h>
43#include <linux/file.h> 30#include <linux/file.h>
44
45#include <linux/netdevice.h>
46#include <linux/etherdevice.h> 31#include <linux/etherdevice.h>
47#include <linux/skbuff.h>
48
49#include <asm/unaligned.h> 32#include <asm/unaligned.h>
50 33
51#include <net/bluetooth/bluetooth.h> 34#include <net/bluetooth/bluetooth.h>
@@ -306,7 +289,7 @@ static u8 __bnep_rx_hlen[] = {
306 ETH_ALEN + 2 /* BNEP_COMPRESSED_DST_ONLY */ 289 ETH_ALEN + 2 /* BNEP_COMPRESSED_DST_ONLY */
307}; 290};
308 291
309static inline int bnep_rx_frame(struct bnep_session *s, struct sk_buff *skb) 292static int bnep_rx_frame(struct bnep_session *s, struct sk_buff *skb)
310{ 293{
311 struct net_device *dev = s->dev; 294 struct net_device *dev = s->dev;
312 struct sk_buff *nskb; 295 struct sk_buff *nskb;
@@ -404,7 +387,7 @@ static u8 __bnep_tx_types[] = {
404 BNEP_COMPRESSED 387 BNEP_COMPRESSED
405}; 388};
406 389
407static inline int bnep_tx_frame(struct bnep_session *s, struct sk_buff *skb) 390static int bnep_tx_frame(struct bnep_session *s, struct sk_buff *skb)
408{ 391{
409 struct ethhdr *eh = (void *) skb->data; 392 struct ethhdr *eh = (void *) skb->data;
410 struct socket *sock = s->sock; 393 struct socket *sock = s->sock;
diff --git a/net/bluetooth/bnep/netdev.c b/net/bluetooth/bnep/netdev.c
index bc4086480d97..98f86f91d47c 100644
--- a/net/bluetooth/bnep/netdev.c
+++ b/net/bluetooth/bnep/netdev.c
@@ -25,16 +25,8 @@
25 SOFTWARE IS DISCLAIMED. 25 SOFTWARE IS DISCLAIMED.
26*/ 26*/
27 27
28#include <linux/module.h> 28#include <linux/export.h>
29#include <linux/slab.h>
30
31#include <linux/socket.h>
32#include <linux/netdevice.h>
33#include <linux/etherdevice.h> 29#include <linux/etherdevice.h>
34#include <linux/skbuff.h>
35#include <linux/wait.h>
36
37#include <asm/unaligned.h>
38 30
39#include <net/bluetooth/bluetooth.h> 31#include <net/bluetooth/bluetooth.h>
40#include <net/bluetooth/hci_core.h> 32#include <net/bluetooth/hci_core.h>
@@ -128,7 +120,7 @@ static void bnep_net_timeout(struct net_device *dev)
128} 120}
129 121
130#ifdef CONFIG_BT_BNEP_MC_FILTER 122#ifdef CONFIG_BT_BNEP_MC_FILTER
131static inline int bnep_net_mc_filter(struct sk_buff *skb, struct bnep_session *s) 123static int bnep_net_mc_filter(struct sk_buff *skb, struct bnep_session *s)
132{ 124{
133 struct ethhdr *eh = (void *) skb->data; 125 struct ethhdr *eh = (void *) skb->data;
134 126
@@ -140,7 +132,7 @@ static inline int bnep_net_mc_filter(struct sk_buff *skb, struct bnep_session *s
140 132
141#ifdef CONFIG_BT_BNEP_PROTO_FILTER 133#ifdef CONFIG_BT_BNEP_PROTO_FILTER
142/* Determine ether protocol. Based on eth_type_trans. */ 134/* Determine ether protocol. Based on eth_type_trans. */
143static inline u16 bnep_net_eth_proto(struct sk_buff *skb) 135static u16 bnep_net_eth_proto(struct sk_buff *skb)
144{ 136{
145 struct ethhdr *eh = (void *) skb->data; 137 struct ethhdr *eh = (void *) skb->data;
146 u16 proto = ntohs(eh->h_proto); 138 u16 proto = ntohs(eh->h_proto);
@@ -154,7 +146,7 @@ static inline u16 bnep_net_eth_proto(struct sk_buff *skb)
154 return ETH_P_802_2; 146 return ETH_P_802_2;
155} 147}
156 148
157static inline int bnep_net_proto_filter(struct sk_buff *skb, struct bnep_session *s) 149static int bnep_net_proto_filter(struct sk_buff *skb, struct bnep_session *s)
158{ 150{
159 u16 proto = bnep_net_eth_proto(skb); 151 u16 proto = bnep_net_eth_proto(skb);
160 struct bnep_proto_filter *f = s->proto_filter; 152 struct bnep_proto_filter *f = s->proto_filter;
diff --git a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c
index 180bfc45810d..5e5f5b410e0b 100644
--- a/net/bluetooth/bnep/sock.c
+++ b/net/bluetooth/bnep/sock.c
@@ -24,24 +24,8 @@
24 SOFTWARE IS DISCLAIMED. 24 SOFTWARE IS DISCLAIMED.
25*/ 25*/
26 26
27#include <linux/module.h> 27#include <linux/export.h>
28
29#include <linux/types.h>
30#include <linux/capability.h>
31#include <linux/errno.h>
32#include <linux/kernel.h>
33#include <linux/poll.h>
34#include <linux/fcntl.h>
35#include <linux/skbuff.h>
36#include <linux/socket.h>
37#include <linux/ioctl.h>
38#include <linux/file.h> 28#include <linux/file.h>
39#include <linux/init.h>
40#include <linux/compat.h>
41#include <linux/gfp.h>
42#include <linux/uaccess.h>
43#include <net/sock.h>
44
45 29
46#include "bnep.h" 30#include "bnep.h"
47 31
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 3f18a6ed9731..2fcced377e50 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -24,24 +24,11 @@
24 24
25/* Bluetooth HCI connection handling. */ 25/* Bluetooth HCI connection handling. */
26 26
27#include <linux/module.h> 27#include <linux/export.h>
28
29#include <linux/types.h>
30#include <linux/errno.h>
31#include <linux/kernel.h>
32#include <linux/slab.h>
33#include <linux/poll.h>
34#include <linux/fcntl.h>
35#include <linux/init.h>
36#include <linux/skbuff.h>
37#include <linux/interrupt.h>
38#include <net/sock.h>
39
40#include <linux/uaccess.h>
41#include <asm/unaligned.h>
42 28
43#include <net/bluetooth/bluetooth.h> 29#include <net/bluetooth/bluetooth.h>
44#include <net/bluetooth/hci_core.h> 30#include <net/bluetooth/hci_core.h>
31#include <net/bluetooth/a2mp.h>
45 32
46static void hci_le_connect(struct hci_conn *conn) 33static void hci_le_connect(struct hci_conn *conn)
47{ 34{
@@ -54,15 +41,15 @@ static void hci_le_connect(struct hci_conn *conn)
54 conn->sec_level = BT_SECURITY_LOW; 41 conn->sec_level = BT_SECURITY_LOW;
55 42
56 memset(&cp, 0, sizeof(cp)); 43 memset(&cp, 0, sizeof(cp));
57 cp.scan_interval = cpu_to_le16(0x0060); 44 cp.scan_interval = __constant_cpu_to_le16(0x0060);
58 cp.scan_window = cpu_to_le16(0x0030); 45 cp.scan_window = __constant_cpu_to_le16(0x0030);
59 bacpy(&cp.peer_addr, &conn->dst); 46 bacpy(&cp.peer_addr, &conn->dst);
60 cp.peer_addr_type = conn->dst_type; 47 cp.peer_addr_type = conn->dst_type;
61 cp.conn_interval_min = cpu_to_le16(0x0028); 48 cp.conn_interval_min = __constant_cpu_to_le16(0x0028);
62 cp.conn_interval_max = cpu_to_le16(0x0038); 49 cp.conn_interval_max = __constant_cpu_to_le16(0x0038);
63 cp.supervision_timeout = cpu_to_le16(0x002a); 50 cp.supervision_timeout = __constant_cpu_to_le16(0x002a);
64 cp.min_ce_len = cpu_to_le16(0x0000); 51 cp.min_ce_len = __constant_cpu_to_le16(0x0000);
65 cp.max_ce_len = cpu_to_le16(0x0000); 52 cp.max_ce_len = __constant_cpu_to_le16(0x0000);
66 53
67 hci_send_cmd(hdev, HCI_OP_LE_CREATE_CONN, sizeof(cp), &cp); 54 hci_send_cmd(hdev, HCI_OP_LE_CREATE_CONN, sizeof(cp), &cp);
68} 55}
@@ -99,7 +86,7 @@ void hci_acl_connect(struct hci_conn *conn)
99 cp.pscan_rep_mode = ie->data.pscan_rep_mode; 86 cp.pscan_rep_mode = ie->data.pscan_rep_mode;
100 cp.pscan_mode = ie->data.pscan_mode; 87 cp.pscan_mode = ie->data.pscan_mode;
101 cp.clock_offset = ie->data.clock_offset | 88 cp.clock_offset = ie->data.clock_offset |
102 cpu_to_le16(0x8000); 89 __constant_cpu_to_le16(0x8000);
103 } 90 }
104 91
105 memcpy(conn->dev_class, ie->data.dev_class, 3); 92 memcpy(conn->dev_class, ie->data.dev_class, 3);
@@ -175,9 +162,9 @@ void hci_setup_sync(struct hci_conn *conn, __u16 handle)
175 cp.handle = cpu_to_le16(handle); 162 cp.handle = cpu_to_le16(handle);
176 cp.pkt_type = cpu_to_le16(conn->pkt_type); 163 cp.pkt_type = cpu_to_le16(conn->pkt_type);
177 164
178 cp.tx_bandwidth = cpu_to_le32(0x00001f40); 165 cp.tx_bandwidth = __constant_cpu_to_le32(0x00001f40);
179 cp.rx_bandwidth = cpu_to_le32(0x00001f40); 166 cp.rx_bandwidth = __constant_cpu_to_le32(0x00001f40);
180 cp.max_latency = cpu_to_le16(0xffff); 167 cp.max_latency = __constant_cpu_to_le16(0xffff);
181 cp.voice_setting = cpu_to_le16(hdev->voice_setting); 168 cp.voice_setting = cpu_to_le16(hdev->voice_setting);
182 cp.retrans_effort = 0xff; 169 cp.retrans_effort = 0xff;
183 170
@@ -185,7 +172,7 @@ void hci_setup_sync(struct hci_conn *conn, __u16 handle)
185} 172}
186 173
187void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, 174void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
188 u16 latency, u16 to_multiplier) 175 u16 latency, u16 to_multiplier)
189{ 176{
190 struct hci_cp_le_conn_update cp; 177 struct hci_cp_le_conn_update cp;
191 struct hci_dev *hdev = conn->hdev; 178 struct hci_dev *hdev = conn->hdev;
@@ -197,15 +184,14 @@ void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
197 cp.conn_interval_max = cpu_to_le16(max); 184 cp.conn_interval_max = cpu_to_le16(max);
198 cp.conn_latency = cpu_to_le16(latency); 185 cp.conn_latency = cpu_to_le16(latency);
199 cp.supervision_timeout = cpu_to_le16(to_multiplier); 186 cp.supervision_timeout = cpu_to_le16(to_multiplier);
200 cp.min_ce_len = cpu_to_le16(0x0001); 187 cp.min_ce_len = __constant_cpu_to_le16(0x0001);
201 cp.max_ce_len = cpu_to_le16(0x0001); 188 cp.max_ce_len = __constant_cpu_to_le16(0x0001);
202 189
203 hci_send_cmd(hdev, HCI_OP_LE_CONN_UPDATE, sizeof(cp), &cp); 190 hci_send_cmd(hdev, HCI_OP_LE_CONN_UPDATE, sizeof(cp), &cp);
204} 191}
205EXPORT_SYMBOL(hci_le_conn_update);
206 192
207void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8], 193void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
208 __u8 ltk[16]) 194 __u8 ltk[16])
209{ 195{
210 struct hci_dev *hdev = conn->hdev; 196 struct hci_dev *hdev = conn->hdev;
211 struct hci_cp_le_start_enc cp; 197 struct hci_cp_le_start_enc cp;
@@ -221,7 +207,6 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
221 207
222 hci_send_cmd(hdev, HCI_OP_LE_START_ENC, sizeof(cp), &cp); 208 hci_send_cmd(hdev, HCI_OP_LE_START_ENC, sizeof(cp), &cp);
223} 209}
224EXPORT_SYMBOL(hci_le_start_enc);
225 210
226/* Device _must_ be locked */ 211/* Device _must_ be locked */
227void hci_sco_setup(struct hci_conn *conn, __u8 status) 212void hci_sco_setup(struct hci_conn *conn, __u8 status)
@@ -247,7 +232,7 @@ void hci_sco_setup(struct hci_conn *conn, __u8 status)
247static void hci_conn_timeout(struct work_struct *work) 232static void hci_conn_timeout(struct work_struct *work)
248{ 233{
249 struct hci_conn *conn = container_of(work, struct hci_conn, 234 struct hci_conn *conn = container_of(work, struct hci_conn,
250 disc_work.work); 235 disc_work.work);
251 __u8 reason; 236 __u8 reason;
252 237
253 BT_DBG("conn %p state %s", conn, state_to_string(conn->state)); 238 BT_DBG("conn %p state %s", conn, state_to_string(conn->state));
@@ -295,9 +280,9 @@ static void hci_conn_enter_sniff_mode(struct hci_conn *conn)
295 if (lmp_sniffsubr_capable(hdev) && lmp_sniffsubr_capable(conn)) { 280 if (lmp_sniffsubr_capable(hdev) && lmp_sniffsubr_capable(conn)) {
296 struct hci_cp_sniff_subrate cp; 281 struct hci_cp_sniff_subrate cp;
297 cp.handle = cpu_to_le16(conn->handle); 282 cp.handle = cpu_to_le16(conn->handle);
298 cp.max_latency = cpu_to_le16(0); 283 cp.max_latency = __constant_cpu_to_le16(0);
299 cp.min_remote_timeout = cpu_to_le16(0); 284 cp.min_remote_timeout = __constant_cpu_to_le16(0);
300 cp.min_local_timeout = cpu_to_le16(0); 285 cp.min_local_timeout = __constant_cpu_to_le16(0);
301 hci_send_cmd(hdev, HCI_OP_SNIFF_SUBRATE, sizeof(cp), &cp); 286 hci_send_cmd(hdev, HCI_OP_SNIFF_SUBRATE, sizeof(cp), &cp);
302 } 287 }
303 288
@@ -306,8 +291,8 @@ static void hci_conn_enter_sniff_mode(struct hci_conn *conn)
306 cp.handle = cpu_to_le16(conn->handle); 291 cp.handle = cpu_to_le16(conn->handle);
307 cp.max_interval = cpu_to_le16(hdev->sniff_max_interval); 292 cp.max_interval = cpu_to_le16(hdev->sniff_max_interval);
308 cp.min_interval = cpu_to_le16(hdev->sniff_min_interval); 293 cp.min_interval = cpu_to_le16(hdev->sniff_min_interval);
309 cp.attempt = cpu_to_le16(4); 294 cp.attempt = __constant_cpu_to_le16(4);
310 cp.timeout = cpu_to_le16(1); 295 cp.timeout = __constant_cpu_to_le16(1);
311 hci_send_cmd(hdev, HCI_OP_SNIFF_MODE, sizeof(cp), &cp); 296 hci_send_cmd(hdev, HCI_OP_SNIFF_MODE, sizeof(cp), &cp);
312 } 297 }
313} 298}
@@ -327,7 +312,7 @@ static void hci_conn_auto_accept(unsigned long arg)
327 struct hci_dev *hdev = conn->hdev; 312 struct hci_dev *hdev = conn->hdev;
328 313
329 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_REPLY, sizeof(conn->dst), 314 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_REPLY, sizeof(conn->dst),
330 &conn->dst); 315 &conn->dst);
331} 316}
332 317
333struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst) 318struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
@@ -376,7 +361,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
376 INIT_DELAYED_WORK(&conn->disc_work, hci_conn_timeout); 361 INIT_DELAYED_WORK(&conn->disc_work, hci_conn_timeout);
377 setup_timer(&conn->idle_timer, hci_conn_idle, (unsigned long)conn); 362 setup_timer(&conn->idle_timer, hci_conn_idle, (unsigned long)conn);
378 setup_timer(&conn->auto_accept_timer, hci_conn_auto_accept, 363 setup_timer(&conn->auto_accept_timer, hci_conn_auto_accept,
379 (unsigned long) conn); 364 (unsigned long) conn);
380 365
381 atomic_set(&conn->refcnt, 0); 366 atomic_set(&conn->refcnt, 0);
382 367
@@ -425,9 +410,11 @@ int hci_conn_del(struct hci_conn *conn)
425 } 410 }
426 } 411 }
427 412
428
429 hci_chan_list_flush(conn); 413 hci_chan_list_flush(conn);
430 414
415 if (conn->amp_mgr)
416 amp_mgr_put(conn->amp_mgr);
417
431 hci_conn_hash_del(hdev, conn); 418 hci_conn_hash_del(hdev, conn);
432 if (hdev->notify) 419 if (hdev->notify)
433 hdev->notify(hdev, HCI_NOTIFY_CONN_DEL); 420 hdev->notify(hdev, HCI_NOTIFY_CONN_DEL);
@@ -454,7 +441,8 @@ struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src)
454 read_lock(&hci_dev_list_lock); 441 read_lock(&hci_dev_list_lock);
455 442
456 list_for_each_entry(d, &hci_dev_list, list) { 443 list_for_each_entry(d, &hci_dev_list, list) {
457 if (!test_bit(HCI_UP, &d->flags) || test_bit(HCI_RAW, &d->flags)) 444 if (!test_bit(HCI_UP, &d->flags) ||
445 test_bit(HCI_RAW, &d->flags))
458 continue; 446 continue;
459 447
460 /* Simple routing: 448 /* Simple routing:
@@ -495,6 +483,11 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
495 if (type == LE_LINK) { 483 if (type == LE_LINK) {
496 le = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst); 484 le = hci_conn_hash_lookup_ba(hdev, LE_LINK, dst);
497 if (!le) { 485 if (!le) {
486 le = hci_conn_hash_lookup_state(hdev, LE_LINK,
487 BT_CONNECT);
488 if (le)
489 return ERR_PTR(-EBUSY);
490
498 le = hci_conn_add(hdev, LE_LINK, dst); 491 le = hci_conn_add(hdev, LE_LINK, dst);
499 if (!le) 492 if (!le)
500 return ERR_PTR(-ENOMEM); 493 return ERR_PTR(-ENOMEM);
@@ -545,7 +538,7 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
545 hci_conn_hold(sco); 538 hci_conn_hold(sco);
546 539
547 if (acl->state == BT_CONNECTED && 540 if (acl->state == BT_CONNECTED &&
548 (sco->state == BT_OPEN || sco->state == BT_CLOSED)) { 541 (sco->state == BT_OPEN || sco->state == BT_CLOSED)) {
549 set_bit(HCI_CONN_POWER_SAVE, &acl->flags); 542 set_bit(HCI_CONN_POWER_SAVE, &acl->flags);
550 hci_conn_enter_active_mode(acl, BT_POWER_FORCE_ACTIVE_ON); 543 hci_conn_enter_active_mode(acl, BT_POWER_FORCE_ACTIVE_ON);
551 544
@@ -560,7 +553,6 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
560 553
561 return sco; 554 return sco;
562} 555}
563EXPORT_SYMBOL(hci_connect);
564 556
565/* Check link security requirement */ 557/* Check link security requirement */
566int hci_conn_check_link_mode(struct hci_conn *conn) 558int hci_conn_check_link_mode(struct hci_conn *conn)
@@ -572,7 +564,6 @@ int hci_conn_check_link_mode(struct hci_conn *conn)
572 564
573 return 1; 565 return 1;
574} 566}
575EXPORT_SYMBOL(hci_conn_check_link_mode);
576 567
577/* Authenticate remote device */ 568/* Authenticate remote device */
578static int hci_conn_auth(struct hci_conn *conn, __u8 sec_level, __u8 auth_type) 569static int hci_conn_auth(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
@@ -600,7 +591,7 @@ static int hci_conn_auth(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
600 591
601 cp.handle = cpu_to_le16(conn->handle); 592 cp.handle = cpu_to_le16(conn->handle);
602 hci_send_cmd(conn->hdev, HCI_OP_AUTH_REQUESTED, 593 hci_send_cmd(conn->hdev, HCI_OP_AUTH_REQUESTED,
603 sizeof(cp), &cp); 594 sizeof(cp), &cp);
604 if (conn->key_type != 0xff) 595 if (conn->key_type != 0xff)
605 set_bit(HCI_CONN_REAUTH_PEND, &conn->flags); 596 set_bit(HCI_CONN_REAUTH_PEND, &conn->flags);
606 } 597 }
@@ -618,7 +609,7 @@ static void hci_conn_encrypt(struct hci_conn *conn)
618 cp.handle = cpu_to_le16(conn->handle); 609 cp.handle = cpu_to_le16(conn->handle);
619 cp.encrypt = 0x01; 610 cp.encrypt = 0x01;
620 hci_send_cmd(conn->hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), 611 hci_send_cmd(conn->hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp),
621 &cp); 612 &cp);
622 } 613 }
623} 614}
624 615
@@ -648,8 +639,7 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
648 /* An unauthenticated combination key has sufficient security for 639 /* An unauthenticated combination key has sufficient security for
649 security level 1 and 2. */ 640 security level 1 and 2. */
650 if (conn->key_type == HCI_LK_UNAUTH_COMBINATION && 641 if (conn->key_type == HCI_LK_UNAUTH_COMBINATION &&
651 (sec_level == BT_SECURITY_MEDIUM || 642 (sec_level == BT_SECURITY_MEDIUM || sec_level == BT_SECURITY_LOW))
652 sec_level == BT_SECURITY_LOW))
653 goto encrypt; 643 goto encrypt;
654 644
655 /* A combination key has always sufficient security for the security 645 /* A combination key has always sufficient security for the security
@@ -657,8 +647,7 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
657 is generated using maximum PIN code length (16). 647 is generated using maximum PIN code length (16).
658 For pre 2.1 units. */ 648 For pre 2.1 units. */
659 if (conn->key_type == HCI_LK_COMBINATION && 649 if (conn->key_type == HCI_LK_COMBINATION &&
660 (sec_level != BT_SECURITY_HIGH || 650 (sec_level != BT_SECURITY_HIGH || conn->pin_length == 16))
661 conn->pin_length == 16))
662 goto encrypt; 651 goto encrypt;
663 652
664auth: 653auth:
@@ -701,12 +690,11 @@ int hci_conn_change_link_key(struct hci_conn *conn)
701 struct hci_cp_change_conn_link_key cp; 690 struct hci_cp_change_conn_link_key cp;
702 cp.handle = cpu_to_le16(conn->handle); 691 cp.handle = cpu_to_le16(conn->handle);
703 hci_send_cmd(conn->hdev, HCI_OP_CHANGE_CONN_LINK_KEY, 692 hci_send_cmd(conn->hdev, HCI_OP_CHANGE_CONN_LINK_KEY,
704 sizeof(cp), &cp); 693 sizeof(cp), &cp);
705 } 694 }
706 695
707 return 0; 696 return 0;
708} 697}
709EXPORT_SYMBOL(hci_conn_change_link_key);
710 698
711/* Switch role */ 699/* Switch role */
712int hci_conn_switch_role(struct hci_conn *conn, __u8 role) 700int hci_conn_switch_role(struct hci_conn *conn, __u8 role)
@@ -752,7 +740,7 @@ void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active)
752timer: 740timer:
753 if (hdev->idle_timeout > 0) 741 if (hdev->idle_timeout > 0)
754 mod_timer(&conn->idle_timer, 742 mod_timer(&conn->idle_timer,
755 jiffies + msecs_to_jiffies(hdev->idle_timeout)); 743 jiffies + msecs_to_jiffies(hdev->idle_timeout));
756} 744}
757 745
758/* Drop all connection on the device */ 746/* Drop all connection on the device */
@@ -802,7 +790,7 @@ EXPORT_SYMBOL(hci_conn_put_device);
802 790
803int hci_get_conn_list(void __user *arg) 791int hci_get_conn_list(void __user *arg)
804{ 792{
805 register struct hci_conn *c; 793 struct hci_conn *c;
806 struct hci_conn_list_req req, *cl; 794 struct hci_conn_list_req req, *cl;
807 struct hci_conn_info *ci; 795 struct hci_conn_info *ci;
808 struct hci_dev *hdev; 796 struct hci_dev *hdev;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 411ace8e647b..08994ecc3b6a 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -25,28 +25,10 @@
25 25
26/* Bluetooth HCI core. */ 26/* Bluetooth HCI core. */
27 27
28#include <linux/jiffies.h> 28#include <linux/export.h>
29#include <linux/module.h> 29#include <linux/idr.h>
30#include <linux/kmod.h>
31
32#include <linux/types.h>
33#include <linux/errno.h>
34#include <linux/kernel.h>
35#include <linux/sched.h>
36#include <linux/slab.h>
37#include <linux/poll.h>
38#include <linux/fcntl.h>
39#include <linux/init.h>
40#include <linux/skbuff.h>
41#include <linux/workqueue.h>
42#include <linux/interrupt.h>
43#include <linux/rfkill.h>
44#include <linux/timer.h>
45#include <linux/crypto.h>
46#include <net/sock.h>
47 30
48#include <linux/uaccess.h> 31#include <linux/rfkill.h>
49#include <asm/unaligned.h>
50 32
51#include <net/bluetooth/bluetooth.h> 33#include <net/bluetooth/bluetooth.h>
52#include <net/bluetooth/hci_core.h> 34#include <net/bluetooth/hci_core.h>
@@ -65,6 +47,9 @@ DEFINE_RWLOCK(hci_dev_list_lock);
65LIST_HEAD(hci_cb_list); 47LIST_HEAD(hci_cb_list);
66DEFINE_RWLOCK(hci_cb_list_lock); 48DEFINE_RWLOCK(hci_cb_list_lock);
67 49
50/* HCI ID Numbering */
51static DEFINE_IDA(hci_index_ida);
52
68/* ---- HCI notifications ---- */ 53/* ---- HCI notifications ---- */
69 54
70static void hci_notify(struct hci_dev *hdev, int event) 55static void hci_notify(struct hci_dev *hdev, int event)
@@ -124,8 +109,9 @@ static void hci_req_cancel(struct hci_dev *hdev, int err)
124} 109}
125 110
126/* Execute request and wait for completion. */ 111/* Execute request and wait for completion. */
127static int __hci_request(struct hci_dev *hdev, void (*req)(struct hci_dev *hdev, unsigned long opt), 112static int __hci_request(struct hci_dev *hdev,
128 unsigned long opt, __u32 timeout) 113 void (*req)(struct hci_dev *hdev, unsigned long opt),
114 unsigned long opt, __u32 timeout)
129{ 115{
130 DECLARE_WAITQUEUE(wait, current); 116 DECLARE_WAITQUEUE(wait, current);
131 int err = 0; 117 int err = 0;
@@ -166,8 +152,9 @@ static int __hci_request(struct hci_dev *hdev, void (*req)(struct hci_dev *hdev,
166 return err; 152 return err;
167} 153}
168 154
169static inline int hci_request(struct hci_dev *hdev, void (*req)(struct hci_dev *hdev, unsigned long opt), 155static int hci_request(struct hci_dev *hdev,
170 unsigned long opt, __u32 timeout) 156 void (*req)(struct hci_dev *hdev, unsigned long opt),
157 unsigned long opt, __u32 timeout)
171{ 158{
172 int ret; 159 int ret;
173 160
@@ -202,7 +189,7 @@ static void bredr_init(struct hci_dev *hdev)
202 /* Mandatory initialization */ 189 /* Mandatory initialization */
203 190
204 /* Reset */ 191 /* Reset */
205 if (!test_bit(HCI_QUIRK_NO_RESET, &hdev->quirks)) { 192 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) {
206 set_bit(HCI_RESET, &hdev->flags); 193 set_bit(HCI_RESET, &hdev->flags);
207 hci_send_cmd(hdev, HCI_OP_RESET, 0, NULL); 194 hci_send_cmd(hdev, HCI_OP_RESET, 0, NULL);
208 } 195 }
@@ -235,7 +222,7 @@ static void bredr_init(struct hci_dev *hdev)
235 hci_send_cmd(hdev, HCI_OP_SET_EVENT_FLT, 1, &flt_type); 222 hci_send_cmd(hdev, HCI_OP_SET_EVENT_FLT, 1, &flt_type);
236 223
237 /* Connection accept timeout ~20 secs */ 224 /* Connection accept timeout ~20 secs */
238 param = cpu_to_le16(0x7d00); 225 param = __constant_cpu_to_le16(0x7d00);
239 hci_send_cmd(hdev, HCI_OP_WRITE_CA_TIMEOUT, 2, &param); 226 hci_send_cmd(hdev, HCI_OP_WRITE_CA_TIMEOUT, 2, &param);
240 227
241 bacpy(&cp.bdaddr, BDADDR_ANY); 228 bacpy(&cp.bdaddr, BDADDR_ANY);
@@ -417,7 +404,8 @@ static void inquiry_cache_flush(struct hci_dev *hdev)
417 INIT_LIST_HEAD(&cache->resolve); 404 INIT_LIST_HEAD(&cache->resolve);
418} 405}
419 406
420struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr) 407struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
408 bdaddr_t *bdaddr)
421{ 409{
422 struct discovery_state *cache = &hdev->discovery; 410 struct discovery_state *cache = &hdev->discovery;
423 struct inquiry_entry *e; 411 struct inquiry_entry *e;
@@ -478,7 +466,7 @@ void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
478 466
479 list_for_each_entry(p, &cache->resolve, list) { 467 list_for_each_entry(p, &cache->resolve, list) {
480 if (p->name_state != NAME_PENDING && 468 if (p->name_state != NAME_PENDING &&
481 abs(p->data.rssi) >= abs(ie->data.rssi)) 469 abs(p->data.rssi) >= abs(ie->data.rssi))
482 break; 470 break;
483 pos = &p->list; 471 pos = &p->list;
484 } 472 }
@@ -503,7 +491,7 @@ bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
503 *ssp = true; 491 *ssp = true;
504 492
505 if (ie->name_state == NAME_NEEDED && 493 if (ie->name_state == NAME_NEEDED &&
506 data->rssi != ie->data.rssi) { 494 data->rssi != ie->data.rssi) {
507 ie->data.rssi = data->rssi; 495 ie->data.rssi = data->rssi;
508 hci_inquiry_cache_update_resolve(hdev, ie); 496 hci_inquiry_cache_update_resolve(hdev, ie);
509 } 497 }
@@ -527,7 +515,7 @@ bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
527 515
528update: 516update:
529 if (name_known && ie->name_state != NAME_KNOWN && 517 if (name_known && ie->name_state != NAME_KNOWN &&
530 ie->name_state != NAME_PENDING) { 518 ie->name_state != NAME_PENDING) {
531 ie->name_state = NAME_KNOWN; 519 ie->name_state = NAME_KNOWN;
532 list_del(&ie->list); 520 list_del(&ie->list);
533 } 521 }
@@ -605,8 +593,7 @@ int hci_inquiry(void __user *arg)
605 593
606 hci_dev_lock(hdev); 594 hci_dev_lock(hdev);
607 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX || 595 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX ||
608 inquiry_cache_empty(hdev) || 596 inquiry_cache_empty(hdev) || ir.flags & IREQ_CACHE_FLUSH) {
609 ir.flags & IREQ_CACHE_FLUSH) {
610 inquiry_cache_flush(hdev); 597 inquiry_cache_flush(hdev);
611 do_inquiry = 1; 598 do_inquiry = 1;
612 } 599 }
@@ -620,7 +607,9 @@ int hci_inquiry(void __user *arg)
620 goto done; 607 goto done;
621 } 608 }
622 609
623 /* for unlimited number of responses we will use buffer with 255 entries */ 610 /* for unlimited number of responses we will use buffer with
611 * 255 entries
612 */
624 max_rsp = (ir.num_rsp == 0) ? 255 : ir.num_rsp; 613 max_rsp = (ir.num_rsp == 0) ? 255 : ir.num_rsp;
625 614
626 /* cache_dump can't sleep. Therefore we allocate temp buffer and then 615 /* cache_dump can't sleep. Therefore we allocate temp buffer and then
@@ -641,7 +630,7 @@ int hci_inquiry(void __user *arg)
641 if (!copy_to_user(ptr, &ir, sizeof(ir))) { 630 if (!copy_to_user(ptr, &ir, sizeof(ir))) {
642 ptr += sizeof(ir); 631 ptr += sizeof(ir);
643 if (copy_to_user(ptr, buf, sizeof(struct inquiry_info) * 632 if (copy_to_user(ptr, buf, sizeof(struct inquiry_info) *
644 ir.num_rsp)) 633 ir.num_rsp))
645 err = -EFAULT; 634 err = -EFAULT;
646 } else 635 } else
647 err = -EFAULT; 636 err = -EFAULT;
@@ -702,11 +691,11 @@ int hci_dev_open(__u16 dev)
702 hdev->init_last_cmd = 0; 691 hdev->init_last_cmd = 0;
703 692
704 ret = __hci_request(hdev, hci_init_req, 0, 693 ret = __hci_request(hdev, hci_init_req, 0,
705 msecs_to_jiffies(HCI_INIT_TIMEOUT)); 694 msecs_to_jiffies(HCI_INIT_TIMEOUT));
706 695
707 if (lmp_host_le_capable(hdev)) 696 if (lmp_host_le_capable(hdev))
708 ret = __hci_request(hdev, hci_le_init_req, 0, 697 ret = __hci_request(hdev, hci_le_init_req, 0,
709 msecs_to_jiffies(HCI_INIT_TIMEOUT)); 698 msecs_to_jiffies(HCI_INIT_TIMEOUT));
710 699
711 clear_bit(HCI_INIT, &hdev->flags); 700 clear_bit(HCI_INIT, &hdev->flags);
712 } 701 }
@@ -791,10 +780,10 @@ static int hci_dev_do_close(struct hci_dev *hdev)
791 skb_queue_purge(&hdev->cmd_q); 780 skb_queue_purge(&hdev->cmd_q);
792 atomic_set(&hdev->cmd_cnt, 1); 781 atomic_set(&hdev->cmd_cnt, 1);
793 if (!test_bit(HCI_RAW, &hdev->flags) && 782 if (!test_bit(HCI_RAW, &hdev->flags) &&
794 test_bit(HCI_QUIRK_NO_RESET, &hdev->quirks)) { 783 test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) {
795 set_bit(HCI_INIT, &hdev->flags); 784 set_bit(HCI_INIT, &hdev->flags);
796 __hci_request(hdev, hci_reset_req, 0, 785 __hci_request(hdev, hci_reset_req, 0,
797 msecs_to_jiffies(250)); 786 msecs_to_jiffies(250));
798 clear_bit(HCI_INIT, &hdev->flags); 787 clear_bit(HCI_INIT, &hdev->flags);
799 } 788 }
800 789
@@ -884,7 +873,7 @@ int hci_dev_reset(__u16 dev)
884 873
885 if (!test_bit(HCI_RAW, &hdev->flags)) 874 if (!test_bit(HCI_RAW, &hdev->flags))
886 ret = __hci_request(hdev, hci_reset_req, 0, 875 ret = __hci_request(hdev, hci_reset_req, 0,
887 msecs_to_jiffies(HCI_INIT_TIMEOUT)); 876 msecs_to_jiffies(HCI_INIT_TIMEOUT));
888 877
889done: 878done:
890 hci_req_unlock(hdev); 879 hci_req_unlock(hdev);
@@ -924,7 +913,7 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
924 switch (cmd) { 913 switch (cmd) {
925 case HCISETAUTH: 914 case HCISETAUTH:
926 err = hci_request(hdev, hci_auth_req, dr.dev_opt, 915 err = hci_request(hdev, hci_auth_req, dr.dev_opt,
927 msecs_to_jiffies(HCI_INIT_TIMEOUT)); 916 msecs_to_jiffies(HCI_INIT_TIMEOUT));
928 break; 917 break;
929 918
930 case HCISETENCRYPT: 919 case HCISETENCRYPT:
@@ -936,23 +925,23 @@ int hci_dev_cmd(unsigned int cmd, void __user *arg)
936 if (!test_bit(HCI_AUTH, &hdev->flags)) { 925 if (!test_bit(HCI_AUTH, &hdev->flags)) {
937 /* Auth must be enabled first */ 926 /* Auth must be enabled first */
938 err = hci_request(hdev, hci_auth_req, dr.dev_opt, 927 err = hci_request(hdev, hci_auth_req, dr.dev_opt,
939 msecs_to_jiffies(HCI_INIT_TIMEOUT)); 928 msecs_to_jiffies(HCI_INIT_TIMEOUT));
940 if (err) 929 if (err)
941 break; 930 break;
942 } 931 }
943 932
944 err = hci_request(hdev, hci_encrypt_req, dr.dev_opt, 933 err = hci_request(hdev, hci_encrypt_req, dr.dev_opt,
945 msecs_to_jiffies(HCI_INIT_TIMEOUT)); 934 msecs_to_jiffies(HCI_INIT_TIMEOUT));
946 break; 935 break;
947 936
948 case HCISETSCAN: 937 case HCISETSCAN:
949 err = hci_request(hdev, hci_scan_req, dr.dev_opt, 938 err = hci_request(hdev, hci_scan_req, dr.dev_opt,
950 msecs_to_jiffies(HCI_INIT_TIMEOUT)); 939 msecs_to_jiffies(HCI_INIT_TIMEOUT));
951 break; 940 break;
952 941
953 case HCISETLINKPOL: 942 case HCISETLINKPOL:
954 err = hci_request(hdev, hci_linkpol_req, dr.dev_opt, 943 err = hci_request(hdev, hci_linkpol_req, dr.dev_opt,
955 msecs_to_jiffies(HCI_INIT_TIMEOUT)); 944 msecs_to_jiffies(HCI_INIT_TIMEOUT));
956 break; 945 break;
957 946
958 case HCISETLINKMODE: 947 case HCISETLINKMODE:
@@ -1103,7 +1092,7 @@ static void hci_power_on(struct work_struct *work)
1103 1092
1104 if (test_bit(HCI_AUTO_OFF, &hdev->dev_flags)) 1093 if (test_bit(HCI_AUTO_OFF, &hdev->dev_flags))
1105 schedule_delayed_work(&hdev->power_off, 1094 schedule_delayed_work(&hdev->power_off,
1106 msecs_to_jiffies(AUTO_OFF_TIMEOUT)); 1095 msecs_to_jiffies(AUTO_OFF_TIMEOUT));
1107 1096
1108 if (test_and_clear_bit(HCI_SETUP, &hdev->dev_flags)) 1097 if (test_and_clear_bit(HCI_SETUP, &hdev->dev_flags))
1109 mgmt_index_added(hdev); 1098 mgmt_index_added(hdev);
@@ -1112,7 +1101,7 @@ static void hci_power_on(struct work_struct *work)
1112static void hci_power_off(struct work_struct *work) 1101static void hci_power_off(struct work_struct *work)
1113{ 1102{
1114 struct hci_dev *hdev = container_of(work, struct hci_dev, 1103 struct hci_dev *hdev = container_of(work, struct hci_dev,
1115 power_off.work); 1104 power_off.work);
1116 1105
1117 BT_DBG("%s", hdev->name); 1106 BT_DBG("%s", hdev->name);
1118 1107
@@ -1193,7 +1182,7 @@ struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr)
1193} 1182}
1194 1183
1195static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn, 1184static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn,
1196 u8 key_type, u8 old_key_type) 1185 u8 key_type, u8 old_key_type)
1197{ 1186{
1198 /* Legacy key */ 1187 /* Legacy key */
1199 if (key_type < 0x03) 1188 if (key_type < 0x03)
@@ -1234,7 +1223,7 @@ struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8])
1234 1223
1235 list_for_each_entry(k, &hdev->long_term_keys, list) { 1224 list_for_each_entry(k, &hdev->long_term_keys, list) {
1236 if (k->ediv != ediv || 1225 if (k->ediv != ediv ||
1237 memcmp(rand, k->rand, sizeof(k->rand))) 1226 memcmp(rand, k->rand, sizeof(k->rand)))
1238 continue; 1227 continue;
1239 1228
1240 return k; 1229 return k;
@@ -1242,7 +1231,6 @@ struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8])
1242 1231
1243 return NULL; 1232 return NULL;
1244} 1233}
1245EXPORT_SYMBOL(hci_find_ltk);
1246 1234
1247struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, 1235struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
1248 u8 addr_type) 1236 u8 addr_type)
@@ -1251,12 +1239,11 @@ struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
1251 1239
1252 list_for_each_entry(k, &hdev->long_term_keys, list) 1240 list_for_each_entry(k, &hdev->long_term_keys, list)
1253 if (addr_type == k->bdaddr_type && 1241 if (addr_type == k->bdaddr_type &&
1254 bacmp(bdaddr, &k->bdaddr) == 0) 1242 bacmp(bdaddr, &k->bdaddr) == 0)
1255 return k; 1243 return k;
1256 1244
1257 return NULL; 1245 return NULL;
1258} 1246}
1259EXPORT_SYMBOL(hci_find_ltk_by_addr);
1260 1247
1261int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key, 1248int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
1262 bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len) 1249 bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len)
@@ -1283,15 +1270,14 @@ int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
1283 * combination key for legacy pairing even when there's no 1270 * combination key for legacy pairing even when there's no
1284 * previous key */ 1271 * previous key */
1285 if (type == HCI_LK_CHANGED_COMBINATION && 1272 if (type == HCI_LK_CHANGED_COMBINATION &&
1286 (!conn || conn->remote_auth == 0xff) && 1273 (!conn || conn->remote_auth == 0xff) && old_key_type == 0xff) {
1287 old_key_type == 0xff) {
1288 type = HCI_LK_COMBINATION; 1274 type = HCI_LK_COMBINATION;
1289 if (conn) 1275 if (conn)
1290 conn->key_type = type; 1276 conn->key_type = type;
1291 } 1277 }
1292 1278
1293 bacpy(&key->bdaddr, bdaddr); 1279 bacpy(&key->bdaddr, bdaddr);
1294 memcpy(key->val, val, 16); 1280 memcpy(key->val, val, HCI_LINK_KEY_SIZE);
1295 key->pin_len = pin_len; 1281 key->pin_len = pin_len;
1296 1282
1297 if (type == HCI_LK_CHANGED_COMBINATION) 1283 if (type == HCI_LK_CHANGED_COMBINATION)
@@ -1540,6 +1526,7 @@ static void le_scan_enable_req(struct hci_dev *hdev, unsigned long opt)
1540 1526
1541 memset(&cp, 0, sizeof(cp)); 1527 memset(&cp, 0, sizeof(cp));
1542 cp.enable = 1; 1528 cp.enable = 1;
1529 cp.filter_dup = 1;
1543 1530
1544 hci_send_cmd(hdev, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp); 1531 hci_send_cmd(hdev, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
1545} 1532}
@@ -1707,41 +1694,39 @@ EXPORT_SYMBOL(hci_free_dev);
1707/* Register HCI device */ 1694/* Register HCI device */
1708int hci_register_dev(struct hci_dev *hdev) 1695int hci_register_dev(struct hci_dev *hdev)
1709{ 1696{
1710 struct list_head *head, *p;
1711 int id, error; 1697 int id, error;
1712 1698
1713 if (!hdev->open || !hdev->close) 1699 if (!hdev->open || !hdev->close)
1714 return -EINVAL; 1700 return -EINVAL;
1715 1701
1716 write_lock(&hci_dev_list_lock);
1717
1718 /* Do not allow HCI_AMP devices to register at index 0, 1702 /* Do not allow HCI_AMP devices to register at index 0,
1719 * so the index can be used as the AMP controller ID. 1703 * so the index can be used as the AMP controller ID.
1720 */ 1704 */
1721 id = (hdev->dev_type == HCI_BREDR) ? 0 : 1; 1705 switch (hdev->dev_type) {
1722 head = &hci_dev_list; 1706 case HCI_BREDR:
1723 1707 id = ida_simple_get(&hci_index_ida, 0, 0, GFP_KERNEL);
1724 /* Find first available device id */ 1708 break;
1725 list_for_each(p, &hci_dev_list) { 1709 case HCI_AMP:
1726 int nid = list_entry(p, struct hci_dev, list)->id; 1710 id = ida_simple_get(&hci_index_ida, 1, 0, GFP_KERNEL);
1727 if (nid > id) 1711 break;
1728 break; 1712 default:
1729 if (nid == id) 1713 return -EINVAL;
1730 id++;
1731 head = p;
1732 } 1714 }
1733 1715
1716 if (id < 0)
1717 return id;
1718
1734 sprintf(hdev->name, "hci%d", id); 1719 sprintf(hdev->name, "hci%d", id);
1735 hdev->id = id; 1720 hdev->id = id;
1736 1721
1737 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); 1722 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
1738 1723
1739 list_add(&hdev->list, head); 1724 write_lock(&hci_dev_list_lock);
1740 1725 list_add(&hdev->list, &hci_dev_list);
1741 write_unlock(&hci_dev_list_lock); 1726 write_unlock(&hci_dev_list_lock);
1742 1727
1743 hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND | 1728 hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND |
1744 WQ_MEM_RECLAIM, 1); 1729 WQ_MEM_RECLAIM, 1);
1745 if (!hdev->workqueue) { 1730 if (!hdev->workqueue) {
1746 error = -ENOMEM; 1731 error = -ENOMEM;
1747 goto err; 1732 goto err;
@@ -1752,7 +1737,8 @@ int hci_register_dev(struct hci_dev *hdev)
1752 goto err_wqueue; 1737 goto err_wqueue;
1753 1738
1754 hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev, 1739 hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev,
1755 RFKILL_TYPE_BLUETOOTH, &hci_rfkill_ops, hdev); 1740 RFKILL_TYPE_BLUETOOTH, &hci_rfkill_ops,
1741 hdev);
1756 if (hdev->rfkill) { 1742 if (hdev->rfkill) {
1757 if (rfkill_register(hdev->rfkill) < 0) { 1743 if (rfkill_register(hdev->rfkill) < 0) {
1758 rfkill_destroy(hdev->rfkill); 1744 rfkill_destroy(hdev->rfkill);
@@ -1772,6 +1758,7 @@ int hci_register_dev(struct hci_dev *hdev)
1772err_wqueue: 1758err_wqueue:
1773 destroy_workqueue(hdev->workqueue); 1759 destroy_workqueue(hdev->workqueue);
1774err: 1760err:
1761 ida_simple_remove(&hci_index_ida, hdev->id);
1775 write_lock(&hci_dev_list_lock); 1762 write_lock(&hci_dev_list_lock);
1776 list_del(&hdev->list); 1763 list_del(&hdev->list);
1777 write_unlock(&hci_dev_list_lock); 1764 write_unlock(&hci_dev_list_lock);
@@ -1783,12 +1770,14 @@ EXPORT_SYMBOL(hci_register_dev);
1783/* Unregister HCI device */ 1770/* Unregister HCI device */
1784void hci_unregister_dev(struct hci_dev *hdev) 1771void hci_unregister_dev(struct hci_dev *hdev)
1785{ 1772{
1786 int i; 1773 int i, id;
1787 1774
1788 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); 1775 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
1789 1776
1790 set_bit(HCI_UNREGISTER, &hdev->dev_flags); 1777 set_bit(HCI_UNREGISTER, &hdev->dev_flags);
1791 1778
1779 id = hdev->id;
1780
1792 write_lock(&hci_dev_list_lock); 1781 write_lock(&hci_dev_list_lock);
1793 list_del(&hdev->list); 1782 list_del(&hdev->list);
1794 write_unlock(&hci_dev_list_lock); 1783 write_unlock(&hci_dev_list_lock);
@@ -1799,7 +1788,7 @@ void hci_unregister_dev(struct hci_dev *hdev)
1799 kfree_skb(hdev->reassembly[i]); 1788 kfree_skb(hdev->reassembly[i]);
1800 1789
1801 if (!test_bit(HCI_INIT, &hdev->flags) && 1790 if (!test_bit(HCI_INIT, &hdev->flags) &&
1802 !test_bit(HCI_SETUP, &hdev->dev_flags)) { 1791 !test_bit(HCI_SETUP, &hdev->dev_flags)) {
1803 hci_dev_lock(hdev); 1792 hci_dev_lock(hdev);
1804 mgmt_index_removed(hdev); 1793 mgmt_index_removed(hdev);
1805 hci_dev_unlock(hdev); 1794 hci_dev_unlock(hdev);
@@ -1829,6 +1818,8 @@ void hci_unregister_dev(struct hci_dev *hdev)
1829 hci_dev_unlock(hdev); 1818 hci_dev_unlock(hdev);
1830 1819
1831 hci_dev_put(hdev); 1820 hci_dev_put(hdev);
1821
1822 ida_simple_remove(&hci_index_ida, id);
1832} 1823}
1833EXPORT_SYMBOL(hci_unregister_dev); 1824EXPORT_SYMBOL(hci_unregister_dev);
1834 1825
@@ -1853,7 +1844,7 @@ int hci_recv_frame(struct sk_buff *skb)
1853{ 1844{
1854 struct hci_dev *hdev = (struct hci_dev *) skb->dev; 1845 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
1855 if (!hdev || (!test_bit(HCI_UP, &hdev->flags) 1846 if (!hdev || (!test_bit(HCI_UP, &hdev->flags)
1856 && !test_bit(HCI_INIT, &hdev->flags))) { 1847 && !test_bit(HCI_INIT, &hdev->flags))) {
1857 kfree_skb(skb); 1848 kfree_skb(skb);
1858 return -ENXIO; 1849 return -ENXIO;
1859 } 1850 }
@@ -1872,7 +1863,7 @@ int hci_recv_frame(struct sk_buff *skb)
1872EXPORT_SYMBOL(hci_recv_frame); 1863EXPORT_SYMBOL(hci_recv_frame);
1873 1864
1874static int hci_reassembly(struct hci_dev *hdev, int type, void *data, 1865static int hci_reassembly(struct hci_dev *hdev, int type, void *data,
1875 int count, __u8 index) 1866 int count, __u8 index)
1876{ 1867{
1877 int len = 0; 1868 int len = 0;
1878 int hlen = 0; 1869 int hlen = 0;
@@ -1881,7 +1872,7 @@ static int hci_reassembly(struct hci_dev *hdev, int type, void *data,
1881 struct bt_skb_cb *scb; 1872 struct bt_skb_cb *scb;
1882 1873
1883 if ((type < HCI_ACLDATA_PKT || type > HCI_EVENT_PKT) || 1874 if ((type < HCI_ACLDATA_PKT || type > HCI_EVENT_PKT) ||
1884 index >= NUM_REASSEMBLY) 1875 index >= NUM_REASSEMBLY)
1885 return -EILSEQ; 1876 return -EILSEQ;
1886 1877
1887 skb = hdev->reassembly[index]; 1878 skb = hdev->reassembly[index];
@@ -2023,7 +2014,7 @@ int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count)
2023 type = bt_cb(skb)->pkt_type; 2014 type = bt_cb(skb)->pkt_type;
2024 2015
2025 rem = hci_reassembly(hdev, type, data, count, 2016 rem = hci_reassembly(hdev, type, data, count,
2026 STREAM_REASSEMBLY); 2017 STREAM_REASSEMBLY);
2027 if (rem < 0) 2018 if (rem < 0)
2028 return rem; 2019 return rem;
2029 2020
@@ -2157,7 +2148,7 @@ static void hci_add_acl_hdr(struct sk_buff *skb, __u16 handle, __u16 flags)
2157} 2148}
2158 2149
2159static void hci_queue_acl(struct hci_conn *conn, struct sk_buff_head *queue, 2150static void hci_queue_acl(struct hci_conn *conn, struct sk_buff_head *queue,
2160 struct sk_buff *skb, __u16 flags) 2151 struct sk_buff *skb, __u16 flags)
2161{ 2152{
2162 struct hci_dev *hdev = conn->hdev; 2153 struct hci_dev *hdev = conn->hdev;
2163 struct sk_buff *list; 2154 struct sk_buff *list;
@@ -2216,7 +2207,6 @@ void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags)
2216 2207
2217 queue_work(hdev->workqueue, &hdev->tx_work); 2208 queue_work(hdev->workqueue, &hdev->tx_work);
2218} 2209}
2219EXPORT_SYMBOL(hci_send_acl);
2220 2210
2221/* Send SCO data */ 2211/* Send SCO data */
2222void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb) 2212void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb)
@@ -2239,12 +2229,12 @@ void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb)
2239 skb_queue_tail(&conn->data_q, skb); 2229 skb_queue_tail(&conn->data_q, skb);
2240 queue_work(hdev->workqueue, &hdev->tx_work); 2230 queue_work(hdev->workqueue, &hdev->tx_work);
2241} 2231}
2242EXPORT_SYMBOL(hci_send_sco);
2243 2232
2244/* ---- HCI TX task (outgoing data) ---- */ 2233/* ---- HCI TX task (outgoing data) ---- */
2245 2234
2246/* HCI Connection scheduler */ 2235/* HCI Connection scheduler */
2247static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int *quote) 2236static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type,
2237 int *quote)
2248{ 2238{
2249 struct hci_conn_hash *h = &hdev->conn_hash; 2239 struct hci_conn_hash *h = &hdev->conn_hash;
2250 struct hci_conn *conn = NULL, *c; 2240 struct hci_conn *conn = NULL, *c;
@@ -2303,7 +2293,7 @@ static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int
2303 return conn; 2293 return conn;
2304} 2294}
2305 2295
2306static inline void hci_link_tx_to(struct hci_dev *hdev, __u8 type) 2296static void hci_link_tx_to(struct hci_dev *hdev, __u8 type)
2307{ 2297{
2308 struct hci_conn_hash *h = &hdev->conn_hash; 2298 struct hci_conn_hash *h = &hdev->conn_hash;
2309 struct hci_conn *c; 2299 struct hci_conn *c;
@@ -2316,16 +2306,16 @@ static inline void hci_link_tx_to(struct hci_dev *hdev, __u8 type)
2316 list_for_each_entry_rcu(c, &h->list, list) { 2306 list_for_each_entry_rcu(c, &h->list, list) {
2317 if (c->type == type && c->sent) { 2307 if (c->type == type && c->sent) {
2318 BT_ERR("%s killing stalled connection %s", 2308 BT_ERR("%s killing stalled connection %s",
2319 hdev->name, batostr(&c->dst)); 2309 hdev->name, batostr(&c->dst));
2320 hci_acl_disconn(c, 0x13); 2310 hci_acl_disconn(c, HCI_ERROR_REMOTE_USER_TERM);
2321 } 2311 }
2322 } 2312 }
2323 2313
2324 rcu_read_unlock(); 2314 rcu_read_unlock();
2325} 2315}
2326 2316
2327static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type, 2317static struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type,
2328 int *quote) 2318 int *quote)
2329{ 2319{
2330 struct hci_conn_hash *h = &hdev->conn_hash; 2320 struct hci_conn_hash *h = &hdev->conn_hash;
2331 struct hci_chan *chan = NULL; 2321 struct hci_chan *chan = NULL;
@@ -2442,7 +2432,7 @@ static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type)
2442 skb->priority = HCI_PRIO_MAX - 1; 2432 skb->priority = HCI_PRIO_MAX - 1;
2443 2433
2444 BT_DBG("chan %p skb %p promoted to %d", chan, skb, 2434 BT_DBG("chan %p skb %p promoted to %d", chan, skb,
2445 skb->priority); 2435 skb->priority);
2446 } 2436 }
2447 2437
2448 if (hci_conn_num(hdev, type) == num) 2438 if (hci_conn_num(hdev, type) == num)
@@ -2459,18 +2449,18 @@ static inline int __get_blocks(struct hci_dev *hdev, struct sk_buff *skb)
2459 return DIV_ROUND_UP(skb->len - HCI_ACL_HDR_SIZE, hdev->block_len); 2449 return DIV_ROUND_UP(skb->len - HCI_ACL_HDR_SIZE, hdev->block_len);
2460} 2450}
2461 2451
2462static inline void __check_timeout(struct hci_dev *hdev, unsigned int cnt) 2452static void __check_timeout(struct hci_dev *hdev, unsigned int cnt)
2463{ 2453{
2464 if (!test_bit(HCI_RAW, &hdev->flags)) { 2454 if (!test_bit(HCI_RAW, &hdev->flags)) {
2465 /* ACL tx timeout must be longer than maximum 2455 /* ACL tx timeout must be longer than maximum
2466 * link supervision timeout (40.9 seconds) */ 2456 * link supervision timeout (40.9 seconds) */
2467 if (!cnt && time_after(jiffies, hdev->acl_last_tx + 2457 if (!cnt && time_after(jiffies, hdev->acl_last_tx +
2468 msecs_to_jiffies(HCI_ACL_TX_TIMEOUT))) 2458 msecs_to_jiffies(HCI_ACL_TX_TIMEOUT)))
2469 hci_link_tx_to(hdev, ACL_LINK); 2459 hci_link_tx_to(hdev, ACL_LINK);
2470 } 2460 }
2471} 2461}
2472 2462
2473static inline void hci_sched_acl_pkt(struct hci_dev *hdev) 2463static void hci_sched_acl_pkt(struct hci_dev *hdev)
2474{ 2464{
2475 unsigned int cnt = hdev->acl_cnt; 2465 unsigned int cnt = hdev->acl_cnt;
2476 struct hci_chan *chan; 2466 struct hci_chan *chan;
@@ -2480,11 +2470,11 @@ static inline void hci_sched_acl_pkt(struct hci_dev *hdev)
2480 __check_timeout(hdev, cnt); 2470 __check_timeout(hdev, cnt);
2481 2471
2482 while (hdev->acl_cnt && 2472 while (hdev->acl_cnt &&
2483 (chan = hci_chan_sent(hdev, ACL_LINK, &quote))) { 2473 (chan = hci_chan_sent(hdev, ACL_LINK, &quote))) {
2484 u32 priority = (skb_peek(&chan->data_q))->priority; 2474 u32 priority = (skb_peek(&chan->data_q))->priority;
2485 while (quote-- && (skb = skb_peek(&chan->data_q))) { 2475 while (quote-- && (skb = skb_peek(&chan->data_q))) {
2486 BT_DBG("chan %p skb %p len %d priority %u", chan, skb, 2476 BT_DBG("chan %p skb %p len %d priority %u", chan, skb,
2487 skb->len, skb->priority); 2477 skb->len, skb->priority);
2488 2478
2489 /* Stop if priority has changed */ 2479 /* Stop if priority has changed */
2490 if (skb->priority < priority) 2480 if (skb->priority < priority)
@@ -2508,7 +2498,7 @@ static inline void hci_sched_acl_pkt(struct hci_dev *hdev)
2508 hci_prio_recalculate(hdev, ACL_LINK); 2498 hci_prio_recalculate(hdev, ACL_LINK);
2509} 2499}
2510 2500
2511static inline void hci_sched_acl_blk(struct hci_dev *hdev) 2501static void hci_sched_acl_blk(struct hci_dev *hdev)
2512{ 2502{
2513 unsigned int cnt = hdev->block_cnt; 2503 unsigned int cnt = hdev->block_cnt;
2514 struct hci_chan *chan; 2504 struct hci_chan *chan;
@@ -2518,13 +2508,13 @@ static inline void hci_sched_acl_blk(struct hci_dev *hdev)
2518 __check_timeout(hdev, cnt); 2508 __check_timeout(hdev, cnt);
2519 2509
2520 while (hdev->block_cnt > 0 && 2510 while (hdev->block_cnt > 0 &&
2521 (chan = hci_chan_sent(hdev, ACL_LINK, &quote))) { 2511 (chan = hci_chan_sent(hdev, ACL_LINK, &quote))) {
2522 u32 priority = (skb_peek(&chan->data_q))->priority; 2512 u32 priority = (skb_peek(&chan->data_q))->priority;
2523 while (quote > 0 && (skb = skb_peek(&chan->data_q))) { 2513 while (quote > 0 && (skb = skb_peek(&chan->data_q))) {
2524 int blocks; 2514 int blocks;
2525 2515
2526 BT_DBG("chan %p skb %p len %d priority %u", chan, skb, 2516 BT_DBG("chan %p skb %p len %d priority %u", chan, skb,
2527 skb->len, skb->priority); 2517 skb->len, skb->priority);
2528 2518
2529 /* Stop if priority has changed */ 2519 /* Stop if priority has changed */
2530 if (skb->priority < priority) 2520 if (skb->priority < priority)
@@ -2537,7 +2527,7 @@ static inline void hci_sched_acl_blk(struct hci_dev *hdev)
2537 return; 2527 return;
2538 2528
2539 hci_conn_enter_active_mode(chan->conn, 2529 hci_conn_enter_active_mode(chan->conn,
2540 bt_cb(skb)->force_active); 2530 bt_cb(skb)->force_active);
2541 2531
2542 hci_send_frame(skb); 2532 hci_send_frame(skb);
2543 hdev->acl_last_tx = jiffies; 2533 hdev->acl_last_tx = jiffies;
@@ -2554,7 +2544,7 @@ static inline void hci_sched_acl_blk(struct hci_dev *hdev)
2554 hci_prio_recalculate(hdev, ACL_LINK); 2544 hci_prio_recalculate(hdev, ACL_LINK);
2555} 2545}
2556 2546
2557static inline void hci_sched_acl(struct hci_dev *hdev) 2547static void hci_sched_acl(struct hci_dev *hdev)
2558{ 2548{
2559 BT_DBG("%s", hdev->name); 2549 BT_DBG("%s", hdev->name);
2560 2550
@@ -2573,7 +2563,7 @@ static inline void hci_sched_acl(struct hci_dev *hdev)
2573} 2563}
2574 2564
2575/* Schedule SCO */ 2565/* Schedule SCO */
2576static inline void hci_sched_sco(struct hci_dev *hdev) 2566static void hci_sched_sco(struct hci_dev *hdev)
2577{ 2567{
2578 struct hci_conn *conn; 2568 struct hci_conn *conn;
2579 struct sk_buff *skb; 2569 struct sk_buff *skb;
@@ -2596,7 +2586,7 @@ static inline void hci_sched_sco(struct hci_dev *hdev)
2596 } 2586 }
2597} 2587}
2598 2588
2599static inline void hci_sched_esco(struct hci_dev *hdev) 2589static void hci_sched_esco(struct hci_dev *hdev)
2600{ 2590{
2601 struct hci_conn *conn; 2591 struct hci_conn *conn;
2602 struct sk_buff *skb; 2592 struct sk_buff *skb;
@@ -2607,7 +2597,8 @@ static inline void hci_sched_esco(struct hci_dev *hdev)
2607 if (!hci_conn_num(hdev, ESCO_LINK)) 2597 if (!hci_conn_num(hdev, ESCO_LINK))
2608 return; 2598 return;
2609 2599
2610 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK, &quote))) { 2600 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK,
2601 &quote))) {
2611 while (quote-- && (skb = skb_dequeue(&conn->data_q))) { 2602 while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
2612 BT_DBG("skb %p len %d", skb, skb->len); 2603 BT_DBG("skb %p len %d", skb, skb->len);
2613 hci_send_frame(skb); 2604 hci_send_frame(skb);
@@ -2619,7 +2610,7 @@ static inline void hci_sched_esco(struct hci_dev *hdev)
2619 } 2610 }
2620} 2611}
2621 2612
2622static inline void hci_sched_le(struct hci_dev *hdev) 2613static void hci_sched_le(struct hci_dev *hdev)
2623{ 2614{
2624 struct hci_chan *chan; 2615 struct hci_chan *chan;
2625 struct sk_buff *skb; 2616 struct sk_buff *skb;
@@ -2634,7 +2625,7 @@ static inline void hci_sched_le(struct hci_dev *hdev)
2634 /* LE tx timeout must be longer than maximum 2625 /* LE tx timeout must be longer than maximum
2635 * link supervision timeout (40.9 seconds) */ 2626 * link supervision timeout (40.9 seconds) */
2636 if (!hdev->le_cnt && hdev->le_pkts && 2627 if (!hdev->le_cnt && hdev->le_pkts &&
2637 time_after(jiffies, hdev->le_last_tx + HZ * 45)) 2628 time_after(jiffies, hdev->le_last_tx + HZ * 45))
2638 hci_link_tx_to(hdev, LE_LINK); 2629 hci_link_tx_to(hdev, LE_LINK);
2639 } 2630 }
2640 2631
@@ -2644,7 +2635,7 @@ static inline void hci_sched_le(struct hci_dev *hdev)
2644 u32 priority = (skb_peek(&chan->data_q))->priority; 2635 u32 priority = (skb_peek(&chan->data_q))->priority;
2645 while (quote-- && (skb = skb_peek(&chan->data_q))) { 2636 while (quote-- && (skb = skb_peek(&chan->data_q))) {
2646 BT_DBG("chan %p skb %p len %d priority %u", chan, skb, 2637 BT_DBG("chan %p skb %p len %d priority %u", chan, skb,
2647 skb->len, skb->priority); 2638 skb->len, skb->priority);
2648 2639
2649 /* Stop if priority has changed */ 2640 /* Stop if priority has changed */
2650 if (skb->priority < priority) 2641 if (skb->priority < priority)
@@ -2676,7 +2667,7 @@ static void hci_tx_work(struct work_struct *work)
2676 struct sk_buff *skb; 2667 struct sk_buff *skb;
2677 2668
2678 BT_DBG("%s acl %d sco %d le %d", hdev->name, hdev->acl_cnt, 2669 BT_DBG("%s acl %d sco %d le %d", hdev->name, hdev->acl_cnt,
2679 hdev->sco_cnt, hdev->le_cnt); 2670 hdev->sco_cnt, hdev->le_cnt);
2680 2671
2681 /* Schedule queues and send stuff to HCI driver */ 2672 /* Schedule queues and send stuff to HCI driver */
2682 2673
@@ -2696,7 +2687,7 @@ static void hci_tx_work(struct work_struct *work)
2696/* ----- HCI RX task (incoming data processing) ----- */ 2687/* ----- HCI RX task (incoming data processing) ----- */
2697 2688
2698/* ACL data packet */ 2689/* ACL data packet */
2699static inline void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) 2690static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
2700{ 2691{
2701 struct hci_acl_hdr *hdr = (void *) skb->data; 2692 struct hci_acl_hdr *hdr = (void *) skb->data;
2702 struct hci_conn *conn; 2693 struct hci_conn *conn;
@@ -2708,7 +2699,8 @@ static inline void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
2708 flags = hci_flags(handle); 2699 flags = hci_flags(handle);
2709 handle = hci_handle(handle); 2700 handle = hci_handle(handle);
2710 2701
2711 BT_DBG("%s len %d handle 0x%x flags 0x%x", hdev->name, skb->len, handle, flags); 2702 BT_DBG("%s len %d handle 0x%x flags 0x%x", hdev->name, skb->len,
2703 handle, flags);
2712 2704
2713 hdev->stat.acl_rx++; 2705 hdev->stat.acl_rx++;
2714 2706
@@ -2732,14 +2724,14 @@ static inline void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
2732 return; 2724 return;
2733 } else { 2725 } else {
2734 BT_ERR("%s ACL packet for unknown connection handle %d", 2726 BT_ERR("%s ACL packet for unknown connection handle %d",
2735 hdev->name, handle); 2727 hdev->name, handle);
2736 } 2728 }
2737 2729
2738 kfree_skb(skb); 2730 kfree_skb(skb);
2739} 2731}
2740 2732
2741/* SCO data packet */ 2733/* SCO data packet */
2742static inline void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) 2734static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb)
2743{ 2735{
2744 struct hci_sco_hdr *hdr = (void *) skb->data; 2736 struct hci_sco_hdr *hdr = (void *) skb->data;
2745 struct hci_conn *conn; 2737 struct hci_conn *conn;
@@ -2763,7 +2755,7 @@ static inline void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb)
2763 return; 2755 return;
2764 } else { 2756 } else {
2765 BT_ERR("%s SCO packet for unknown connection handle %d", 2757 BT_ERR("%s SCO packet for unknown connection handle %d",
2766 hdev->name, handle); 2758 hdev->name, handle);
2767 } 2759 }
2768 2760
2769 kfree_skb(skb); 2761 kfree_skb(skb);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 94ad124a4ea3..1ba929c05d0d 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -24,20 +24,7 @@
24 24
25/* Bluetooth HCI event handling. */ 25/* Bluetooth HCI event handling. */
26 26
27#include <linux/module.h> 27#include <linux/export.h>
28
29#include <linux/types.h>
30#include <linux/errno.h>
31#include <linux/kernel.h>
32#include <linux/slab.h>
33#include <linux/poll.h>
34#include <linux/fcntl.h>
35#include <linux/init.h>
36#include <linux/skbuff.h>
37#include <linux/interrupt.h>
38#include <net/sock.h>
39
40#include <linux/uaccess.h>
41#include <asm/unaligned.h> 28#include <asm/unaligned.h>
42 29
43#include <net/bluetooth/bluetooth.h> 30#include <net/bluetooth/bluetooth.h>
@@ -95,7 +82,8 @@ static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
95 hci_conn_check_pending(hdev); 82 hci_conn_check_pending(hdev);
96} 83}
97 84
98static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev, struct sk_buff *skb) 85static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev,
86 struct sk_buff *skb)
99{ 87{
100 BT_DBG("%s", hdev->name); 88 BT_DBG("%s", hdev->name);
101} 89}
@@ -166,7 +154,8 @@ static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
166 hci_dev_unlock(hdev); 154 hci_dev_unlock(hdev);
167} 155}
168 156
169static void hci_cc_read_def_link_policy(struct hci_dev *hdev, struct sk_buff *skb) 157static void hci_cc_read_def_link_policy(struct hci_dev *hdev,
158 struct sk_buff *skb)
170{ 159{
171 struct hci_rp_read_def_link_policy *rp = (void *) skb->data; 160 struct hci_rp_read_def_link_policy *rp = (void *) skb->data;
172 161
@@ -178,7 +167,8 @@ static void hci_cc_read_def_link_policy(struct hci_dev *hdev, struct sk_buff *sk
178 hdev->link_policy = __le16_to_cpu(rp->policy); 167 hdev->link_policy = __le16_to_cpu(rp->policy);
179} 168}
180 169
181static void hci_cc_write_def_link_policy(struct hci_dev *hdev, struct sk_buff *skb) 170static void hci_cc_write_def_link_policy(struct hci_dev *hdev,
171 struct sk_buff *skb)
182{ 172{
183 __u8 status = *((__u8 *) skb->data); 173 __u8 status = *((__u8 *) skb->data);
184 void *sent; 174 void *sent;
@@ -329,7 +319,7 @@ static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
329 if (hdev->discov_timeout > 0) { 319 if (hdev->discov_timeout > 0) {
330 int to = msecs_to_jiffies(hdev->discov_timeout * 1000); 320 int to = msecs_to_jiffies(hdev->discov_timeout * 1000);
331 queue_delayed_work(hdev->workqueue, &hdev->discov_off, 321 queue_delayed_work(hdev->workqueue, &hdev->discov_off,
332 to); 322 to);
333 } 323 }
334 } else if (old_iscan) 324 } else if (old_iscan)
335 mgmt_discoverable(hdev, 0); 325 mgmt_discoverable(hdev, 0);
@@ -358,7 +348,7 @@ static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
358 memcpy(hdev->dev_class, rp->dev_class, 3); 348 memcpy(hdev->dev_class, rp->dev_class, 3);
359 349
360 BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name, 350 BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name,
361 hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]); 351 hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
362} 352}
363 353
364static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) 354static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
@@ -406,7 +396,8 @@ static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
406 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); 396 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
407} 397}
408 398
409static void hci_cc_write_voice_setting(struct hci_dev *hdev, struct sk_buff *skb) 399static void hci_cc_write_voice_setting(struct hci_dev *hdev,
400 struct sk_buff *skb)
410{ 401{
411 __u8 status = *((__u8 *) skb->data); 402 __u8 status = *((__u8 *) skb->data);
412 __u16 setting; 403 __u16 setting;
@@ -473,7 +464,7 @@ static u8 hci_get_inquiry_mode(struct hci_dev *hdev)
473 return 1; 464 return 1;
474 465
475 if (hdev->manufacturer == 11 && hdev->hci_rev == 0x00 && 466 if (hdev->manufacturer == 11 && hdev->hci_rev == 0x00 &&
476 hdev->lmp_subver == 0x0757) 467 hdev->lmp_subver == 0x0757)
477 return 1; 468 return 1;
478 469
479 if (hdev->manufacturer == 15) { 470 if (hdev->manufacturer == 15) {
@@ -486,7 +477,7 @@ static u8 hci_get_inquiry_mode(struct hci_dev *hdev)
486 } 477 }
487 478
488 if (hdev->manufacturer == 31 && hdev->hci_rev == 0x2005 && 479 if (hdev->manufacturer == 31 && hdev->hci_rev == 0x2005 &&
489 hdev->lmp_subver == 0x1805) 480 hdev->lmp_subver == 0x1805)
490 return 1; 481 return 1;
491 482
492 return 0; 483 return 0;
@@ -566,7 +557,7 @@ static void hci_setup(struct hci_dev *hdev)
566 if (hdev->hci_ver > BLUETOOTH_VER_1_1) 557 if (hdev->hci_ver > BLUETOOTH_VER_1_1)
567 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_COMMANDS, 0, NULL); 558 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_COMMANDS, 0, NULL);
568 559
569 if (hdev->features[6] & LMP_SIMPLE_PAIR) { 560 if (lmp_ssp_capable(hdev)) {
570 if (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags)) { 561 if (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags)) {
571 u8 mode = 0x01; 562 u8 mode = 0x01;
572 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, 563 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE,
@@ -618,8 +609,7 @@ static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb)
618 hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver); 609 hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver);
619 610
620 BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name, 611 BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name,
621 hdev->manufacturer, 612 hdev->manufacturer, hdev->hci_ver, hdev->hci_rev);
622 hdev->hci_ver, hdev->hci_rev);
623 613
624 if (test_bit(HCI_INIT, &hdev->flags)) 614 if (test_bit(HCI_INIT, &hdev->flags))
625 hci_setup(hdev); 615 hci_setup(hdev);
@@ -646,7 +636,8 @@ static void hci_setup_link_policy(struct hci_dev *hdev)
646 hci_send_cmd(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, sizeof(cp), &cp); 636 hci_send_cmd(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, sizeof(cp), &cp);
647} 637}
648 638
649static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb) 639static void hci_cc_read_local_commands(struct hci_dev *hdev,
640 struct sk_buff *skb)
650{ 641{
651 struct hci_rp_read_local_commands *rp = (void *) skb->data; 642 struct hci_rp_read_local_commands *rp = (void *) skb->data;
652 643
@@ -664,7 +655,8 @@ done:
664 hci_req_complete(hdev, HCI_OP_READ_LOCAL_COMMANDS, rp->status); 655 hci_req_complete(hdev, HCI_OP_READ_LOCAL_COMMANDS, rp->status);
665} 656}
666 657
667static void hci_cc_read_local_features(struct hci_dev *hdev, struct sk_buff *skb) 658static void hci_cc_read_local_features(struct hci_dev *hdev,
659 struct sk_buff *skb)
668{ 660{
669 struct hci_rp_read_local_features *rp = (void *) skb->data; 661 struct hci_rp_read_local_features *rp = (void *) skb->data;
670 662
@@ -713,10 +705,10 @@ static void hci_cc_read_local_features(struct hci_dev *hdev, struct sk_buff *skb
713 hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5); 705 hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5);
714 706
715 BT_DBG("%s features 0x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", hdev->name, 707 BT_DBG("%s features 0x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", hdev->name,
716 hdev->features[0], hdev->features[1], 708 hdev->features[0], hdev->features[1],
717 hdev->features[2], hdev->features[3], 709 hdev->features[2], hdev->features[3],
718 hdev->features[4], hdev->features[5], 710 hdev->features[4], hdev->features[5],
719 hdev->features[6], hdev->features[7]); 711 hdev->features[6], hdev->features[7]);
720} 712}
721 713
722static void hci_set_le_support(struct hci_dev *hdev) 714static void hci_set_le_support(struct hci_dev *hdev)
@@ -736,7 +728,7 @@ static void hci_set_le_support(struct hci_dev *hdev)
736} 728}
737 729
738static void hci_cc_read_local_ext_features(struct hci_dev *hdev, 730static void hci_cc_read_local_ext_features(struct hci_dev *hdev,
739 struct sk_buff *skb) 731 struct sk_buff *skb)
740{ 732{
741 struct hci_rp_read_local_ext_features *rp = (void *) skb->data; 733 struct hci_rp_read_local_ext_features *rp = (void *) skb->data;
742 734
@@ -762,7 +754,7 @@ done:
762} 754}
763 755
764static void hci_cc_read_flow_control_mode(struct hci_dev *hdev, 756static void hci_cc_read_flow_control_mode(struct hci_dev *hdev,
765 struct sk_buff *skb) 757 struct sk_buff *skb)
766{ 758{
767 struct hci_rp_read_flow_control_mode *rp = (void *) skb->data; 759 struct hci_rp_read_flow_control_mode *rp = (void *) skb->data;
768 760
@@ -798,9 +790,8 @@ static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
798 hdev->acl_cnt = hdev->acl_pkts; 790 hdev->acl_cnt = hdev->acl_pkts;
799 hdev->sco_cnt = hdev->sco_pkts; 791 hdev->sco_cnt = hdev->sco_pkts;
800 792
801 BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, 793 BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, hdev->acl_mtu,
802 hdev->acl_mtu, hdev->acl_pkts, 794 hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts);
803 hdev->sco_mtu, hdev->sco_pkts);
804} 795}
805 796
806static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb) 797static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb)
@@ -816,7 +807,7 @@ static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb)
816} 807}
817 808
818static void hci_cc_read_data_block_size(struct hci_dev *hdev, 809static void hci_cc_read_data_block_size(struct hci_dev *hdev,
819 struct sk_buff *skb) 810 struct sk_buff *skb)
820{ 811{
821 struct hci_rp_read_data_block_size *rp = (void *) skb->data; 812 struct hci_rp_read_data_block_size *rp = (void *) skb->data;
822 813
@@ -832,7 +823,7 @@ static void hci_cc_read_data_block_size(struct hci_dev *hdev,
832 hdev->block_cnt = hdev->num_blocks; 823 hdev->block_cnt = hdev->num_blocks;
833 824
834 BT_DBG("%s blk mtu %d cnt %d len %d", hdev->name, hdev->block_mtu, 825 BT_DBG("%s blk mtu %d cnt %d len %d", hdev->name, hdev->block_mtu,
835 hdev->block_cnt, hdev->block_len); 826 hdev->block_cnt, hdev->block_len);
836 827
837 hci_req_complete(hdev, HCI_OP_READ_DATA_BLOCK_SIZE, rp->status); 828 hci_req_complete(hdev, HCI_OP_READ_DATA_BLOCK_SIZE, rp->status);
838} 829}
@@ -847,7 +838,7 @@ static void hci_cc_write_ca_timeout(struct hci_dev *hdev, struct sk_buff *skb)
847} 838}
848 839
849static void hci_cc_read_local_amp_info(struct hci_dev *hdev, 840static void hci_cc_read_local_amp_info(struct hci_dev *hdev,
850 struct sk_buff *skb) 841 struct sk_buff *skb)
851{ 842{
852 struct hci_rp_read_local_amp_info *rp = (void *) skb->data; 843 struct hci_rp_read_local_amp_info *rp = (void *) skb->data;
853 844
@@ -871,7 +862,7 @@ static void hci_cc_read_local_amp_info(struct hci_dev *hdev,
871} 862}
872 863
873static void hci_cc_delete_stored_link_key(struct hci_dev *hdev, 864static void hci_cc_delete_stored_link_key(struct hci_dev *hdev,
874 struct sk_buff *skb) 865 struct sk_buff *skb)
875{ 866{
876 __u8 status = *((__u8 *) skb->data); 867 __u8 status = *((__u8 *) skb->data);
877 868
@@ -890,7 +881,7 @@ static void hci_cc_set_event_mask(struct hci_dev *hdev, struct sk_buff *skb)
890} 881}
891 882
892static void hci_cc_write_inquiry_mode(struct hci_dev *hdev, 883static void hci_cc_write_inquiry_mode(struct hci_dev *hdev,
893 struct sk_buff *skb) 884 struct sk_buff *skb)
894{ 885{
895 __u8 status = *((__u8 *) skb->data); 886 __u8 status = *((__u8 *) skb->data);
896 887
@@ -900,7 +891,7 @@ static void hci_cc_write_inquiry_mode(struct hci_dev *hdev,
900} 891}
901 892
902static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev, 893static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev,
903 struct sk_buff *skb) 894 struct sk_buff *skb)
904{ 895{
905 struct hci_rp_read_inq_rsp_tx_power *rp = (void *) skb->data; 896 struct hci_rp_read_inq_rsp_tx_power *rp = (void *) skb->data;
906 897
@@ -959,7 +950,7 @@ static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
959 950
960 if (test_bit(HCI_MGMT, &hdev->dev_flags)) 951 if (test_bit(HCI_MGMT, &hdev->dev_flags))
961 mgmt_pin_code_neg_reply_complete(hdev, &rp->bdaddr, 952 mgmt_pin_code_neg_reply_complete(hdev, &rp->bdaddr,
962 rp->status); 953 rp->status);
963 954
964 hci_dev_unlock(hdev); 955 hci_dev_unlock(hdev);
965} 956}
@@ -1000,7 +991,7 @@ static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb)
1000} 991}
1001 992
1002static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev, 993static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev,
1003 struct sk_buff *skb) 994 struct sk_buff *skb)
1004{ 995{
1005 struct hci_rp_user_confirm_reply *rp = (void *) skb->data; 996 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
1006 997
@@ -1031,7 +1022,7 @@ static void hci_cc_user_passkey_reply(struct hci_dev *hdev, struct sk_buff *skb)
1031} 1022}
1032 1023
1033static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev, 1024static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev,
1034 struct sk_buff *skb) 1025 struct sk_buff *skb)
1035{ 1026{
1036 struct hci_rp_user_confirm_reply *rp = (void *) skb->data; 1027 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
1037 1028
@@ -1047,7 +1038,7 @@ static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev,
1047} 1038}
1048 1039
1049static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev, 1040static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
1050 struct sk_buff *skb) 1041 struct sk_buff *skb)
1051{ 1042{
1052 struct hci_rp_read_local_oob_data *rp = (void *) skb->data; 1043 struct hci_rp_read_local_oob_data *rp = (void *) skb->data;
1053 1044
@@ -1076,7 +1067,7 @@ static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb)
1076} 1067}
1077 1068
1078static void hci_cc_le_set_scan_enable(struct hci_dev *hdev, 1069static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
1079 struct sk_buff *skb) 1070 struct sk_buff *skb)
1080{ 1071{
1081 struct hci_cp_le_set_scan_enable *cp; 1072 struct hci_cp_le_set_scan_enable *cp;
1082 __u8 status = *((__u8 *) skb->data); 1073 __u8 status = *((__u8 *) skb->data);
@@ -1156,8 +1147,8 @@ static void hci_cc_le_ltk_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
1156 hci_req_complete(hdev, HCI_OP_LE_LTK_NEG_REPLY, rp->status); 1147 hci_req_complete(hdev, HCI_OP_LE_LTK_NEG_REPLY, rp->status);
1157} 1148}
1158 1149
1159static inline void hci_cc_write_le_host_supported(struct hci_dev *hdev, 1150static void hci_cc_write_le_host_supported(struct hci_dev *hdev,
1160 struct sk_buff *skb) 1151 struct sk_buff *skb)
1161{ 1152{
1162 struct hci_cp_write_le_host_supported *sent; 1153 struct hci_cp_write_le_host_supported *sent;
1163 __u8 status = *((__u8 *) skb->data); 1154 __u8 status = *((__u8 *) skb->data);
@@ -1176,13 +1167,13 @@ static inline void hci_cc_write_le_host_supported(struct hci_dev *hdev,
1176 } 1167 }
1177 1168
1178 if (test_bit(HCI_MGMT, &hdev->dev_flags) && 1169 if (test_bit(HCI_MGMT, &hdev->dev_flags) &&
1179 !test_bit(HCI_INIT, &hdev->flags)) 1170 !test_bit(HCI_INIT, &hdev->flags))
1180 mgmt_le_enable_complete(hdev, sent->le, status); 1171 mgmt_le_enable_complete(hdev, sent->le, status);
1181 1172
1182 hci_req_complete(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, status); 1173 hci_req_complete(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, status);
1183} 1174}
1184 1175
1185static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) 1176static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
1186{ 1177{
1187 BT_DBG("%s status 0x%x", hdev->name, status); 1178 BT_DBG("%s status 0x%x", hdev->name, status);
1188 1179
@@ -1203,7 +1194,7 @@ static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
1203 hci_dev_unlock(hdev); 1194 hci_dev_unlock(hdev);
1204} 1195}
1205 1196
1206static inline void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) 1197static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
1207{ 1198{
1208 struct hci_cp_create_conn *cp; 1199 struct hci_cp_create_conn *cp;
1209 struct hci_conn *conn; 1200 struct hci_conn *conn;
@@ -1333,7 +1324,7 @@ static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
1333} 1324}
1334 1325
1335static int hci_outgoing_auth_needed(struct hci_dev *hdev, 1326static int hci_outgoing_auth_needed(struct hci_dev *hdev,
1336 struct hci_conn *conn) 1327 struct hci_conn *conn)
1337{ 1328{
1338 if (conn->state != BT_CONFIG || !conn->out) 1329 if (conn->state != BT_CONFIG || !conn->out)
1339 return 0; 1330 return 0;
@@ -1343,15 +1334,14 @@ static int hci_outgoing_auth_needed(struct hci_dev *hdev,
1343 1334
1344 /* Only request authentication for SSP connections or non-SSP 1335 /* Only request authentication for SSP connections or non-SSP
1345 * devices with sec_level HIGH or if MITM protection is requested */ 1336 * devices with sec_level HIGH or if MITM protection is requested */
1346 if (!hci_conn_ssp_enabled(conn) && 1337 if (!hci_conn_ssp_enabled(conn) && !(conn->auth_type & 0x01) &&
1347 conn->pending_sec_level != BT_SECURITY_HIGH && 1338 conn->pending_sec_level != BT_SECURITY_HIGH)
1348 !(conn->auth_type & 0x01))
1349 return 0; 1339 return 0;
1350 1340
1351 return 1; 1341 return 1;
1352} 1342}
1353 1343
1354static inline int hci_resolve_name(struct hci_dev *hdev, 1344static int hci_resolve_name(struct hci_dev *hdev,
1355 struct inquiry_entry *e) 1345 struct inquiry_entry *e)
1356{ 1346{
1357 struct hci_cp_remote_name_req cp; 1347 struct hci_cp_remote_name_req cp;
@@ -1638,7 +1628,7 @@ static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status)
1638 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->peer_addr); 1628 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->peer_addr);
1639 1629
1640 BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->peer_addr), 1630 BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->peer_addr),
1641 conn); 1631 conn);
1642 1632
1643 if (status) { 1633 if (status) {
1644 if (conn && conn->state == BT_CONNECT) { 1634 if (conn && conn->state == BT_CONNECT) {
@@ -1668,7 +1658,7 @@ static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status)
1668 BT_DBG("%s status 0x%x", hdev->name, status); 1658 BT_DBG("%s status 0x%x", hdev->name, status);
1669} 1659}
1670 1660
1671static inline void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 1661static void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1672{ 1662{
1673 __u8 status = *((__u8 *) skb->data); 1663 __u8 status = *((__u8 *) skb->data);
1674 struct discovery_state *discov = &hdev->discovery; 1664 struct discovery_state *discov = &hdev->discovery;
@@ -1708,7 +1698,7 @@ unlock:
1708 hci_dev_unlock(hdev); 1698 hci_dev_unlock(hdev);
1709} 1699}
1710 1700
1711static inline void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb) 1701static void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
1712{ 1702{
1713 struct inquiry_data data; 1703 struct inquiry_data data;
1714 struct inquiry_info *info = (void *) (skb->data + 1); 1704 struct inquiry_info *info = (void *) (skb->data + 1);
@@ -1745,7 +1735,7 @@ static inline void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *
1745 hci_dev_unlock(hdev); 1735 hci_dev_unlock(hdev);
1746} 1736}
1747 1737
1748static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 1738static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1749{ 1739{
1750 struct hci_ev_conn_complete *ev = (void *) skb->data; 1740 struct hci_ev_conn_complete *ev = (void *) skb->data;
1751 struct hci_conn *conn; 1741 struct hci_conn *conn;
@@ -1823,18 +1813,18 @@ unlock:
1823 hci_conn_check_pending(hdev); 1813 hci_conn_check_pending(hdev);
1824} 1814}
1825 1815
1826static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) 1816static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
1827{ 1817{
1828 struct hci_ev_conn_request *ev = (void *) skb->data; 1818 struct hci_ev_conn_request *ev = (void *) skb->data;
1829 int mask = hdev->link_mode; 1819 int mask = hdev->link_mode;
1830 1820
1831 BT_DBG("%s bdaddr %s type 0x%x", hdev->name, 1821 BT_DBG("%s bdaddr %s type 0x%x", hdev->name, batostr(&ev->bdaddr),
1832 batostr(&ev->bdaddr), ev->link_type); 1822 ev->link_type);
1833 1823
1834 mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type); 1824 mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type);
1835 1825
1836 if ((mask & HCI_LM_ACCEPT) && 1826 if ((mask & HCI_LM_ACCEPT) &&
1837 !hci_blacklist_lookup(hdev, &ev->bdaddr)) { 1827 !hci_blacklist_lookup(hdev, &ev->bdaddr)) {
1838 /* Connection accepted */ 1828 /* Connection accepted */
1839 struct inquiry_entry *ie; 1829 struct inquiry_entry *ie;
1840 struct hci_conn *conn; 1830 struct hci_conn *conn;
@@ -1845,7 +1835,8 @@ static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *sk
1845 if (ie) 1835 if (ie)
1846 memcpy(ie->data.dev_class, ev->dev_class, 3); 1836 memcpy(ie->data.dev_class, ev->dev_class, 3);
1847 1837
1848 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); 1838 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type,
1839 &ev->bdaddr);
1849 if (!conn) { 1840 if (!conn) {
1850 conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr); 1841 conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr);
1851 if (!conn) { 1842 if (!conn) {
@@ -1878,9 +1869,9 @@ static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *sk
1878 bacpy(&cp.bdaddr, &ev->bdaddr); 1869 bacpy(&cp.bdaddr, &ev->bdaddr);
1879 cp.pkt_type = cpu_to_le16(conn->pkt_type); 1870 cp.pkt_type = cpu_to_le16(conn->pkt_type);
1880 1871
1881 cp.tx_bandwidth = cpu_to_le32(0x00001f40); 1872 cp.tx_bandwidth = __constant_cpu_to_le32(0x00001f40);
1882 cp.rx_bandwidth = cpu_to_le32(0x00001f40); 1873 cp.rx_bandwidth = __constant_cpu_to_le32(0x00001f40);
1883 cp.max_latency = cpu_to_le16(0xffff); 1874 cp.max_latency = __constant_cpu_to_le16(0xffff);
1884 cp.content_format = cpu_to_le16(hdev->voice_setting); 1875 cp.content_format = cpu_to_le16(hdev->voice_setting);
1885 cp.retrans_effort = 0xff; 1876 cp.retrans_effort = 0xff;
1886 1877
@@ -1897,7 +1888,7 @@ static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *sk
1897 } 1888 }
1898} 1889}
1899 1890
1900static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 1891static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1901{ 1892{
1902 struct hci_ev_disconn_complete *ev = (void *) skb->data; 1893 struct hci_ev_disconn_complete *ev = (void *) skb->data;
1903 struct hci_conn *conn; 1894 struct hci_conn *conn;
@@ -1914,10 +1905,10 @@ static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff
1914 conn->state = BT_CLOSED; 1905 conn->state = BT_CLOSED;
1915 1906
1916 if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags) && 1907 if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags) &&
1917 (conn->type == ACL_LINK || conn->type == LE_LINK)) { 1908 (conn->type == ACL_LINK || conn->type == LE_LINK)) {
1918 if (ev->status != 0) 1909 if (ev->status != 0)
1919 mgmt_disconnect_failed(hdev, &conn->dst, conn->type, 1910 mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
1920 conn->dst_type, ev->status); 1911 conn->dst_type, ev->status);
1921 else 1912 else
1922 mgmt_device_disconnected(hdev, &conn->dst, conn->type, 1913 mgmt_device_disconnected(hdev, &conn->dst, conn->type,
1923 conn->dst_type); 1914 conn->dst_type);
@@ -1934,7 +1925,7 @@ unlock:
1934 hci_dev_unlock(hdev); 1925 hci_dev_unlock(hdev);
1935} 1926}
1936 1927
1937static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 1928static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1938{ 1929{
1939 struct hci_ev_auth_complete *ev = (void *) skb->data; 1930 struct hci_ev_auth_complete *ev = (void *) skb->data;
1940 struct hci_conn *conn; 1931 struct hci_conn *conn;
@@ -1949,7 +1940,7 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s
1949 1940
1950 if (!ev->status) { 1941 if (!ev->status) {
1951 if (!hci_conn_ssp_enabled(conn) && 1942 if (!hci_conn_ssp_enabled(conn) &&
1952 test_bit(HCI_CONN_REAUTH_PEND, &conn->flags)) { 1943 test_bit(HCI_CONN_REAUTH_PEND, &conn->flags)) {
1953 BT_INFO("re-auth of legacy device is not possible."); 1944 BT_INFO("re-auth of legacy device is not possible.");
1954 } else { 1945 } else {
1955 conn->link_mode |= HCI_LM_AUTH; 1946 conn->link_mode |= HCI_LM_AUTH;
@@ -1969,7 +1960,7 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s
1969 cp.handle = ev->handle; 1960 cp.handle = ev->handle;
1970 cp.encrypt = 0x01; 1961 cp.encrypt = 0x01;
1971 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), 1962 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp),
1972 &cp); 1963 &cp);
1973 } else { 1964 } else {
1974 conn->state = BT_CONNECTED; 1965 conn->state = BT_CONNECTED;
1975 hci_proto_connect_cfm(conn, ev->status); 1966 hci_proto_connect_cfm(conn, ev->status);
@@ -1989,7 +1980,7 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s
1989 cp.handle = ev->handle; 1980 cp.handle = ev->handle;
1990 cp.encrypt = 0x01; 1981 cp.encrypt = 0x01;
1991 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), 1982 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp),
1992 &cp); 1983 &cp);
1993 } else { 1984 } else {
1994 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); 1985 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
1995 hci_encrypt_cfm(conn, ev->status, 0x00); 1986 hci_encrypt_cfm(conn, ev->status, 0x00);
@@ -2000,7 +1991,7 @@ unlock:
2000 hci_dev_unlock(hdev); 1991 hci_dev_unlock(hdev);
2001} 1992}
2002 1993
2003static inline void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb) 1994static void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb)
2004{ 1995{
2005 struct hci_ev_remote_name *ev = (void *) skb->data; 1996 struct hci_ev_remote_name *ev = (void *) skb->data;
2006 struct hci_conn *conn; 1997 struct hci_conn *conn;
@@ -2039,7 +2030,7 @@ unlock:
2039 hci_dev_unlock(hdev); 2030 hci_dev_unlock(hdev);
2040} 2031}
2041 2032
2042static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) 2033static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2043{ 2034{
2044 struct hci_ev_encrypt_change *ev = (void *) skb->data; 2035 struct hci_ev_encrypt_change *ev = (void *) skb->data;
2045 struct hci_conn *conn; 2036 struct hci_conn *conn;
@@ -2082,7 +2073,8 @@ unlock:
2082 hci_dev_unlock(hdev); 2073 hci_dev_unlock(hdev);
2083} 2074}
2084 2075
2085static inline void hci_change_link_key_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 2076static void hci_change_link_key_complete_evt(struct hci_dev *hdev,
2077 struct sk_buff *skb)
2086{ 2078{
2087 struct hci_ev_change_link_key_complete *ev = (void *) skb->data; 2079 struct hci_ev_change_link_key_complete *ev = (void *) skb->data;
2088 struct hci_conn *conn; 2080 struct hci_conn *conn;
@@ -2104,7 +2096,8 @@ static inline void hci_change_link_key_complete_evt(struct hci_dev *hdev, struct
2104 hci_dev_unlock(hdev); 2096 hci_dev_unlock(hdev);
2105} 2097}
2106 2098
2107static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff *skb) 2099static void hci_remote_features_evt(struct hci_dev *hdev,
2100 struct sk_buff *skb)
2108{ 2101{
2109 struct hci_ev_remote_features *ev = (void *) skb->data; 2102 struct hci_ev_remote_features *ev = (void *) skb->data;
2110 struct hci_conn *conn; 2103 struct hci_conn *conn;
@@ -2128,7 +2121,7 @@ static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff
2128 cp.handle = ev->handle; 2121 cp.handle = ev->handle;
2129 cp.page = 0x01; 2122 cp.page = 0x01;
2130 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES, 2123 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES,
2131 sizeof(cp), &cp); 2124 sizeof(cp), &cp);
2132 goto unlock; 2125 goto unlock;
2133 } 2126 }
2134 2127
@@ -2153,17 +2146,18 @@ unlock:
2153 hci_dev_unlock(hdev); 2146 hci_dev_unlock(hdev);
2154} 2147}
2155 2148
2156static inline void hci_remote_version_evt(struct hci_dev *hdev, struct sk_buff *skb) 2149static void hci_remote_version_evt(struct hci_dev *hdev, struct sk_buff *skb)
2157{ 2150{
2158 BT_DBG("%s", hdev->name); 2151 BT_DBG("%s", hdev->name);
2159} 2152}
2160 2153
2161static inline void hci_qos_setup_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 2154static void hci_qos_setup_complete_evt(struct hci_dev *hdev,
2155 struct sk_buff *skb)
2162{ 2156{
2163 BT_DBG("%s", hdev->name); 2157 BT_DBG("%s", hdev->name);
2164} 2158}
2165 2159
2166static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 2160static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2167{ 2161{
2168 struct hci_ev_cmd_complete *ev = (void *) skb->data; 2162 struct hci_ev_cmd_complete *ev = (void *) skb->data;
2169 __u16 opcode; 2163 __u16 opcode;
@@ -2384,7 +2378,7 @@ static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *sk
2384 } 2378 }
2385} 2379}
2386 2380
2387static inline void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb) 2381static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
2388{ 2382{
2389 struct hci_ev_cmd_status *ev = (void *) skb->data; 2383 struct hci_ev_cmd_status *ev = (void *) skb->data;
2390 __u16 opcode; 2384 __u16 opcode;
@@ -2465,7 +2459,7 @@ static inline void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
2465 } 2459 }
2466} 2460}
2467 2461
2468static inline void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb) 2462static void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2469{ 2463{
2470 struct hci_ev_role_change *ev = (void *) skb->data; 2464 struct hci_ev_role_change *ev = (void *) skb->data;
2471 struct hci_conn *conn; 2465 struct hci_conn *conn;
@@ -2491,7 +2485,7 @@ static inline void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb
2491 hci_dev_unlock(hdev); 2485 hci_dev_unlock(hdev);
2492} 2486}
2493 2487
2494static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb) 2488static void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)
2495{ 2489{
2496 struct hci_ev_num_comp_pkts *ev = (void *) skb->data; 2490 struct hci_ev_num_comp_pkts *ev = (void *) skb->data;
2497 int i; 2491 int i;
@@ -2502,7 +2496,7 @@ static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *s
2502 } 2496 }
2503 2497
2504 if (skb->len < sizeof(*ev) || skb->len < sizeof(*ev) + 2498 if (skb->len < sizeof(*ev) || skb->len < sizeof(*ev) +
2505 ev->num_hndl * sizeof(struct hci_comp_pkts_info)) { 2499 ev->num_hndl * sizeof(struct hci_comp_pkts_info)) {
2506 BT_DBG("%s bad parameters", hdev->name); 2500 BT_DBG("%s bad parameters", hdev->name);
2507 return; 2501 return;
2508 } 2502 }
@@ -2557,8 +2551,7 @@ static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *s
2557 queue_work(hdev->workqueue, &hdev->tx_work); 2551 queue_work(hdev->workqueue, &hdev->tx_work);
2558} 2552}
2559 2553
2560static inline void hci_num_comp_blocks_evt(struct hci_dev *hdev, 2554static void hci_num_comp_blocks_evt(struct hci_dev *hdev, struct sk_buff *skb)
2561 struct sk_buff *skb)
2562{ 2555{
2563 struct hci_ev_num_comp_blocks *ev = (void *) skb->data; 2556 struct hci_ev_num_comp_blocks *ev = (void *) skb->data;
2564 int i; 2557 int i;
@@ -2569,13 +2562,13 @@ static inline void hci_num_comp_blocks_evt(struct hci_dev *hdev,
2569 } 2562 }
2570 2563
2571 if (skb->len < sizeof(*ev) || skb->len < sizeof(*ev) + 2564 if (skb->len < sizeof(*ev) || skb->len < sizeof(*ev) +
2572 ev->num_hndl * sizeof(struct hci_comp_blocks_info)) { 2565 ev->num_hndl * sizeof(struct hci_comp_blocks_info)) {
2573 BT_DBG("%s bad parameters", hdev->name); 2566 BT_DBG("%s bad parameters", hdev->name);
2574 return; 2567 return;
2575 } 2568 }
2576 2569
2577 BT_DBG("%s num_blocks %d num_hndl %d", hdev->name, ev->num_blocks, 2570 BT_DBG("%s num_blocks %d num_hndl %d", hdev->name, ev->num_blocks,
2578 ev->num_hndl); 2571 ev->num_hndl);
2579 2572
2580 for (i = 0; i < ev->num_hndl; i++) { 2573 for (i = 0; i < ev->num_hndl; i++) {
2581 struct hci_comp_blocks_info *info = &ev->handles[i]; 2574 struct hci_comp_blocks_info *info = &ev->handles[i];
@@ -2607,7 +2600,7 @@ static inline void hci_num_comp_blocks_evt(struct hci_dev *hdev,
2607 queue_work(hdev->workqueue, &hdev->tx_work); 2600 queue_work(hdev->workqueue, &hdev->tx_work);
2608} 2601}
2609 2602
2610static inline void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb) 2603static void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2611{ 2604{
2612 struct hci_ev_mode_change *ev = (void *) skb->data; 2605 struct hci_ev_mode_change *ev = (void *) skb->data;
2613 struct hci_conn *conn; 2606 struct hci_conn *conn;
@@ -2621,7 +2614,8 @@ static inline void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb
2621 conn->mode = ev->mode; 2614 conn->mode = ev->mode;
2622 conn->interval = __le16_to_cpu(ev->interval); 2615 conn->interval = __le16_to_cpu(ev->interval);
2623 2616
2624 if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) { 2617 if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND,
2618 &conn->flags)) {
2625 if (conn->mode == HCI_CM_ACTIVE) 2619 if (conn->mode == HCI_CM_ACTIVE)
2626 set_bit(HCI_CONN_POWER_SAVE, &conn->flags); 2620 set_bit(HCI_CONN_POWER_SAVE, &conn->flags);
2627 else 2621 else
@@ -2635,7 +2629,7 @@ static inline void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb
2635 hci_dev_unlock(hdev); 2629 hci_dev_unlock(hdev);
2636} 2630}
2637 2631
2638static inline void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb) 2632static void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
2639{ 2633{
2640 struct hci_ev_pin_code_req *ev = (void *) skb->data; 2634 struct hci_ev_pin_code_req *ev = (void *) skb->data;
2641 struct hci_conn *conn; 2635 struct hci_conn *conn;
@@ -2656,7 +2650,7 @@ static inline void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff
2656 2650
2657 if (!test_bit(HCI_PAIRABLE, &hdev->dev_flags)) 2651 if (!test_bit(HCI_PAIRABLE, &hdev->dev_flags))
2658 hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, 2652 hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY,
2659 sizeof(ev->bdaddr), &ev->bdaddr); 2653 sizeof(ev->bdaddr), &ev->bdaddr);
2660 else if (test_bit(HCI_MGMT, &hdev->dev_flags)) { 2654 else if (test_bit(HCI_MGMT, &hdev->dev_flags)) {
2661 u8 secure; 2655 u8 secure;
2662 2656
@@ -2672,7 +2666,7 @@ unlock:
2672 hci_dev_unlock(hdev); 2666 hci_dev_unlock(hdev);
2673} 2667}
2674 2668
2675static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb) 2669static void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
2676{ 2670{
2677 struct hci_ev_link_key_req *ev = (void *) skb->data; 2671 struct hci_ev_link_key_req *ev = (void *) skb->data;
2678 struct hci_cp_link_key_reply cp; 2672 struct hci_cp_link_key_reply cp;
@@ -2689,15 +2683,15 @@ static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff
2689 key = hci_find_link_key(hdev, &ev->bdaddr); 2683 key = hci_find_link_key(hdev, &ev->bdaddr);
2690 if (!key) { 2684 if (!key) {
2691 BT_DBG("%s link key not found for %s", hdev->name, 2685 BT_DBG("%s link key not found for %s", hdev->name,
2692 batostr(&ev->bdaddr)); 2686 batostr(&ev->bdaddr));
2693 goto not_found; 2687 goto not_found;
2694 } 2688 }
2695 2689
2696 BT_DBG("%s found key type %u for %s", hdev->name, key->type, 2690 BT_DBG("%s found key type %u for %s", hdev->name, key->type,
2697 batostr(&ev->bdaddr)); 2691 batostr(&ev->bdaddr));
2698 2692
2699 if (!test_bit(HCI_DEBUG_KEYS, &hdev->dev_flags) && 2693 if (!test_bit(HCI_DEBUG_KEYS, &hdev->dev_flags) &&
2700 key->type == HCI_LK_DEBUG_COMBINATION) { 2694 key->type == HCI_LK_DEBUG_COMBINATION) {
2701 BT_DBG("%s ignoring debug key", hdev->name); 2695 BT_DBG("%s ignoring debug key", hdev->name);
2702 goto not_found; 2696 goto not_found;
2703 } 2697 }
@@ -2705,16 +2699,15 @@ static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff
2705 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); 2699 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2706 if (conn) { 2700 if (conn) {
2707 if (key->type == HCI_LK_UNAUTH_COMBINATION && 2701 if (key->type == HCI_LK_UNAUTH_COMBINATION &&
2708 conn->auth_type != 0xff && 2702 conn->auth_type != 0xff && (conn->auth_type & 0x01)) {
2709 (conn->auth_type & 0x01)) {
2710 BT_DBG("%s ignoring unauthenticated key", hdev->name); 2703 BT_DBG("%s ignoring unauthenticated key", hdev->name);
2711 goto not_found; 2704 goto not_found;
2712 } 2705 }
2713 2706
2714 if (key->type == HCI_LK_COMBINATION && key->pin_len < 16 && 2707 if (key->type == HCI_LK_COMBINATION && key->pin_len < 16 &&
2715 conn->pending_sec_level == BT_SECURITY_HIGH) { 2708 conn->pending_sec_level == BT_SECURITY_HIGH) {
2716 BT_DBG("%s ignoring key unauthenticated for high \ 2709 BT_DBG("%s ignoring key unauthenticated for high security",
2717 security", hdev->name); 2710 hdev->name);
2718 goto not_found; 2711 goto not_found;
2719 } 2712 }
2720 2713
@@ -2723,7 +2716,7 @@ static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff
2723 } 2716 }
2724 2717
2725 bacpy(&cp.bdaddr, &ev->bdaddr); 2718 bacpy(&cp.bdaddr, &ev->bdaddr);
2726 memcpy(cp.link_key, key->val, 16); 2719 memcpy(cp.link_key, key->val, HCI_LINK_KEY_SIZE);
2727 2720
2728 hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp); 2721 hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp);
2729 2722
@@ -2736,7 +2729,7 @@ not_found:
2736 hci_dev_unlock(hdev); 2729 hci_dev_unlock(hdev);
2737} 2730}
2738 2731
2739static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) 2732static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
2740{ 2733{
2741 struct hci_ev_link_key_notify *ev = (void *) skb->data; 2734 struct hci_ev_link_key_notify *ev = (void *) skb->data;
2742 struct hci_conn *conn; 2735 struct hci_conn *conn;
@@ -2760,12 +2753,12 @@ static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff
2760 2753
2761 if (test_bit(HCI_LINK_KEYS, &hdev->dev_flags)) 2754 if (test_bit(HCI_LINK_KEYS, &hdev->dev_flags))
2762 hci_add_link_key(hdev, conn, 1, &ev->bdaddr, ev->link_key, 2755 hci_add_link_key(hdev, conn, 1, &ev->bdaddr, ev->link_key,
2763 ev->key_type, pin_len); 2756 ev->key_type, pin_len);
2764 2757
2765 hci_dev_unlock(hdev); 2758 hci_dev_unlock(hdev);
2766} 2759}
2767 2760
2768static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb) 2761static void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb)
2769{ 2762{
2770 struct hci_ev_clock_offset *ev = (void *) skb->data; 2763 struct hci_ev_clock_offset *ev = (void *) skb->data;
2771 struct hci_conn *conn; 2764 struct hci_conn *conn;
@@ -2788,7 +2781,7 @@ static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *sk
2788 hci_dev_unlock(hdev); 2781 hci_dev_unlock(hdev);
2789} 2782}
2790 2783
2791static inline void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff *skb) 2784static void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2792{ 2785{
2793 struct hci_ev_pkt_type_change *ev = (void *) skb->data; 2786 struct hci_ev_pkt_type_change *ev = (void *) skb->data;
2794 struct hci_conn *conn; 2787 struct hci_conn *conn;
@@ -2804,7 +2797,7 @@ static inline void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff
2804 hci_dev_unlock(hdev); 2797 hci_dev_unlock(hdev);
2805} 2798}
2806 2799
2807static inline void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb) 2800static void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb)
2808{ 2801{
2809 struct hci_ev_pscan_rep_mode *ev = (void *) skb->data; 2802 struct hci_ev_pscan_rep_mode *ev = (void *) skb->data;
2810 struct inquiry_entry *ie; 2803 struct inquiry_entry *ie;
@@ -2822,7 +2815,8 @@ static inline void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *
2822 hci_dev_unlock(hdev); 2815 hci_dev_unlock(hdev);
2823} 2816}
2824 2817
2825static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct sk_buff *skb) 2818static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev,
2819 struct sk_buff *skb)
2826{ 2820{
2827 struct inquiry_data data; 2821 struct inquiry_data data;
2828 int num_rsp = *((__u8 *) skb->data); 2822 int num_rsp = *((__u8 *) skb->data);
@@ -2881,7 +2875,8 @@ static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct
2881 hci_dev_unlock(hdev); 2875 hci_dev_unlock(hdev);
2882} 2876}
2883 2877
2884static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_buff *skb) 2878static void hci_remote_ext_features_evt(struct hci_dev *hdev,
2879 struct sk_buff *skb)
2885{ 2880{
2886 struct hci_ev_remote_ext_features *ev = (void *) skb->data; 2881 struct hci_ev_remote_ext_features *ev = (void *) skb->data;
2887 struct hci_conn *conn; 2882 struct hci_conn *conn;
@@ -2929,7 +2924,8 @@ unlock:
2929 hci_dev_unlock(hdev); 2924 hci_dev_unlock(hdev);
2930} 2925}
2931 2926
2932static inline void hci_sync_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 2927static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
2928 struct sk_buff *skb)
2933{ 2929{
2934 struct hci_ev_sync_conn_complete *ev = (void *) skb->data; 2930 struct hci_ev_sync_conn_complete *ev = (void *) skb->data;
2935 struct hci_conn *conn; 2931 struct hci_conn *conn;
@@ -2984,19 +2980,20 @@ unlock:
2984 hci_dev_unlock(hdev); 2980 hci_dev_unlock(hdev);
2985} 2981}
2986 2982
2987static inline void hci_sync_conn_changed_evt(struct hci_dev *hdev, struct sk_buff *skb) 2983static void hci_sync_conn_changed_evt(struct hci_dev *hdev, struct sk_buff *skb)
2988{ 2984{
2989 BT_DBG("%s", hdev->name); 2985 BT_DBG("%s", hdev->name);
2990} 2986}
2991 2987
2992static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb) 2988static void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb)
2993{ 2989{
2994 struct hci_ev_sniff_subrate *ev = (void *) skb->data; 2990 struct hci_ev_sniff_subrate *ev = (void *) skb->data;
2995 2991
2996 BT_DBG("%s status %d", hdev->name, ev->status); 2992 BT_DBG("%s status %d", hdev->name, ev->status);
2997} 2993}
2998 2994
2999static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb) 2995static void hci_extended_inquiry_result_evt(struct hci_dev *hdev,
2996 struct sk_buff *skb)
3000{ 2997{
3001 struct inquiry_data data; 2998 struct inquiry_data data;
3002 struct extended_inquiry_info *info = (void *) (skb->data + 1); 2999 struct extended_inquiry_info *info = (void *) (skb->data + 1);
@@ -3087,7 +3084,7 @@ unlock:
3087 hci_dev_unlock(hdev); 3084 hci_dev_unlock(hdev);
3088} 3085}
3089 3086
3090static inline u8 hci_get_auth_req(struct hci_conn *conn) 3087static u8 hci_get_auth_req(struct hci_conn *conn)
3091{ 3088{
3092 /* If remote requests dedicated bonding follow that lead */ 3089 /* If remote requests dedicated bonding follow that lead */
3093 if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) { 3090 if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) {
@@ -3106,7 +3103,7 @@ static inline u8 hci_get_auth_req(struct hci_conn *conn)
3106 return conn->auth_type; 3103 return conn->auth_type;
3107} 3104}
3108 3105
3109static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb) 3106static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
3110{ 3107{
3111 struct hci_ev_io_capa_request *ev = (void *) skb->data; 3108 struct hci_ev_io_capa_request *ev = (void *) skb->data;
3112 struct hci_conn *conn; 3109 struct hci_conn *conn;
@@ -3125,7 +3122,7 @@ static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff
3125 goto unlock; 3122 goto unlock;
3126 3123
3127 if (test_bit(HCI_PAIRABLE, &hdev->dev_flags) || 3124 if (test_bit(HCI_PAIRABLE, &hdev->dev_flags) ||
3128 (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) { 3125 (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) {
3129 struct hci_cp_io_capability_reply cp; 3126 struct hci_cp_io_capability_reply cp;
3130 3127
3131 bacpy(&cp.bdaddr, &ev->bdaddr); 3128 bacpy(&cp.bdaddr, &ev->bdaddr);
@@ -3136,14 +3133,14 @@ static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff
3136 conn->auth_type = hci_get_auth_req(conn); 3133 conn->auth_type = hci_get_auth_req(conn);
3137 cp.authentication = conn->auth_type; 3134 cp.authentication = conn->auth_type;
3138 3135
3139 if ((conn->out || test_bit(HCI_CONN_REMOTE_OOB, &conn->flags)) && 3136 if (hci_find_remote_oob_data(hdev, &conn->dst) &&
3140 hci_find_remote_oob_data(hdev, &conn->dst)) 3137 (conn->out || test_bit(HCI_CONN_REMOTE_OOB, &conn->flags)))
3141 cp.oob_data = 0x01; 3138 cp.oob_data = 0x01;
3142 else 3139 else
3143 cp.oob_data = 0x00; 3140 cp.oob_data = 0x00;
3144 3141
3145 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY, 3142 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY,
3146 sizeof(cp), &cp); 3143 sizeof(cp), &cp);
3147 } else { 3144 } else {
3148 struct hci_cp_io_capability_neg_reply cp; 3145 struct hci_cp_io_capability_neg_reply cp;
3149 3146
@@ -3151,14 +3148,14 @@ static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff
3151 cp.reason = HCI_ERROR_PAIRING_NOT_ALLOWED; 3148 cp.reason = HCI_ERROR_PAIRING_NOT_ALLOWED;
3152 3149
3153 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY, 3150 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY,
3154 sizeof(cp), &cp); 3151 sizeof(cp), &cp);
3155 } 3152 }
3156 3153
3157unlock: 3154unlock:
3158 hci_dev_unlock(hdev); 3155 hci_dev_unlock(hdev);
3159} 3156}
3160 3157
3161static inline void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *skb) 3158static void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *skb)
3162{ 3159{
3163 struct hci_ev_io_capa_reply *ev = (void *) skb->data; 3160 struct hci_ev_io_capa_reply *ev = (void *) skb->data;
3164 struct hci_conn *conn; 3161 struct hci_conn *conn;
@@ -3180,8 +3177,8 @@ unlock:
3180 hci_dev_unlock(hdev); 3177 hci_dev_unlock(hdev);
3181} 3178}
3182 3179
3183static inline void hci_user_confirm_request_evt(struct hci_dev *hdev, 3180static void hci_user_confirm_request_evt(struct hci_dev *hdev,
3184 struct sk_buff *skb) 3181 struct sk_buff *skb)
3185{ 3182{
3186 struct hci_ev_user_confirm_req *ev = (void *) skb->data; 3183 struct hci_ev_user_confirm_req *ev = (void *) skb->data;
3187 int loc_mitm, rem_mitm, confirm_hint = 0; 3184 int loc_mitm, rem_mitm, confirm_hint = 0;
@@ -3209,13 +3206,13 @@ static inline void hci_user_confirm_request_evt(struct hci_dev *hdev,
3209 if (!conn->connect_cfm_cb && loc_mitm && conn->remote_cap == 0x03) { 3206 if (!conn->connect_cfm_cb && loc_mitm && conn->remote_cap == 0x03) {
3210 BT_DBG("Rejecting request: remote device can't provide MITM"); 3207 BT_DBG("Rejecting request: remote device can't provide MITM");
3211 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_NEG_REPLY, 3208 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_NEG_REPLY,
3212 sizeof(ev->bdaddr), &ev->bdaddr); 3209 sizeof(ev->bdaddr), &ev->bdaddr);
3213 goto unlock; 3210 goto unlock;
3214 } 3211 }
3215 3212
3216 /* If no side requires MITM protection; auto-accept */ 3213 /* If no side requires MITM protection; auto-accept */
3217 if ((!loc_mitm || conn->remote_cap == 0x03) && 3214 if ((!loc_mitm || conn->remote_cap == 0x03) &&
3218 (!rem_mitm || conn->io_capability == 0x03)) { 3215 (!rem_mitm || conn->io_capability == 0x03)) {
3219 3216
3220 /* If we're not the initiators request authorization to 3217 /* If we're not the initiators request authorization to
3221 * proceed from user space (mgmt_user_confirm with 3218 * proceed from user space (mgmt_user_confirm with
@@ -3227,7 +3224,7 @@ static inline void hci_user_confirm_request_evt(struct hci_dev *hdev,
3227 } 3224 }
3228 3225
3229 BT_DBG("Auto-accept of user confirmation with %ums delay", 3226 BT_DBG("Auto-accept of user confirmation with %ums delay",
3230 hdev->auto_accept_delay); 3227 hdev->auto_accept_delay);
3231 3228
3232 if (hdev->auto_accept_delay > 0) { 3229 if (hdev->auto_accept_delay > 0) {
3233 int delay = msecs_to_jiffies(hdev->auto_accept_delay); 3230 int delay = msecs_to_jiffies(hdev->auto_accept_delay);
@@ -3236,7 +3233,7 @@ static inline void hci_user_confirm_request_evt(struct hci_dev *hdev,
3236 } 3233 }
3237 3234
3238 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_REPLY, 3235 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_REPLY,
3239 sizeof(ev->bdaddr), &ev->bdaddr); 3236 sizeof(ev->bdaddr), &ev->bdaddr);
3240 goto unlock; 3237 goto unlock;
3241 } 3238 }
3242 3239
@@ -3248,8 +3245,8 @@ unlock:
3248 hci_dev_unlock(hdev); 3245 hci_dev_unlock(hdev);
3249} 3246}
3250 3247
3251static inline void hci_user_passkey_request_evt(struct hci_dev *hdev, 3248static void hci_user_passkey_request_evt(struct hci_dev *hdev,
3252 struct sk_buff *skb) 3249 struct sk_buff *skb)
3253{ 3250{
3254 struct hci_ev_user_passkey_req *ev = (void *) skb->data; 3251 struct hci_ev_user_passkey_req *ev = (void *) skb->data;
3255 3252
@@ -3263,7 +3260,8 @@ static inline void hci_user_passkey_request_evt(struct hci_dev *hdev,
3263 hci_dev_unlock(hdev); 3260 hci_dev_unlock(hdev);
3264} 3261}
3265 3262
3266static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 3263static void hci_simple_pair_complete_evt(struct hci_dev *hdev,
3264 struct sk_buff *skb)
3267{ 3265{
3268 struct hci_ev_simple_pair_complete *ev = (void *) skb->data; 3266 struct hci_ev_simple_pair_complete *ev = (void *) skb->data;
3269 struct hci_conn *conn; 3267 struct hci_conn *conn;
@@ -3291,7 +3289,8 @@ unlock:
3291 hci_dev_unlock(hdev); 3289 hci_dev_unlock(hdev);
3292} 3290}
3293 3291
3294static inline void hci_remote_host_features_evt(struct hci_dev *hdev, struct sk_buff *skb) 3292static void hci_remote_host_features_evt(struct hci_dev *hdev,
3293 struct sk_buff *skb)
3295{ 3294{
3296 struct hci_ev_remote_host_features *ev = (void *) skb->data; 3295 struct hci_ev_remote_host_features *ev = (void *) skb->data;
3297 struct inquiry_entry *ie; 3296 struct inquiry_entry *ie;
@@ -3307,8 +3306,8 @@ static inline void hci_remote_host_features_evt(struct hci_dev *hdev, struct sk_
3307 hci_dev_unlock(hdev); 3306 hci_dev_unlock(hdev);
3308} 3307}
3309 3308
3310static inline void hci_remote_oob_data_request_evt(struct hci_dev *hdev, 3309static void hci_remote_oob_data_request_evt(struct hci_dev *hdev,
3311 struct sk_buff *skb) 3310 struct sk_buff *skb)
3312{ 3311{
3313 struct hci_ev_remote_oob_data_request *ev = (void *) skb->data; 3312 struct hci_ev_remote_oob_data_request *ev = (void *) skb->data;
3314 struct oob_data *data; 3313 struct oob_data *data;
@@ -3329,20 +3328,20 @@ static inline void hci_remote_oob_data_request_evt(struct hci_dev *hdev,
3329 memcpy(cp.randomizer, data->randomizer, sizeof(cp.randomizer)); 3328 memcpy(cp.randomizer, data->randomizer, sizeof(cp.randomizer));
3330 3329
3331 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, sizeof(cp), 3330 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, sizeof(cp),
3332 &cp); 3331 &cp);
3333 } else { 3332 } else {
3334 struct hci_cp_remote_oob_data_neg_reply cp; 3333 struct hci_cp_remote_oob_data_neg_reply cp;
3335 3334
3336 bacpy(&cp.bdaddr, &ev->bdaddr); 3335 bacpy(&cp.bdaddr, &ev->bdaddr);
3337 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY, sizeof(cp), 3336 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY, sizeof(cp),
3338 &cp); 3337 &cp);
3339 } 3338 }
3340 3339
3341unlock: 3340unlock:
3342 hci_dev_unlock(hdev); 3341 hci_dev_unlock(hdev);
3343} 3342}
3344 3343
3345static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) 3344static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
3346{ 3345{
3347 struct hci_ev_le_conn_complete *ev = (void *) skb->data; 3346 struct hci_ev_le_conn_complete *ev = (void *) skb->data;
3348 struct hci_conn *conn; 3347 struct hci_conn *conn;
@@ -3351,6 +3350,19 @@ static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff
3351 3350
3352 hci_dev_lock(hdev); 3351 hci_dev_lock(hdev);
3353 3352
3353 if (ev->status) {
3354 conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
3355 if (!conn)
3356 goto unlock;
3357
3358 mgmt_connect_failed(hdev, &conn->dst, conn->type,
3359 conn->dst_type, ev->status);
3360 hci_proto_connect_cfm(conn, ev->status);
3361 conn->state = BT_CLOSED;
3362 hci_conn_del(conn);
3363 goto unlock;
3364 }
3365
3354 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &ev->bdaddr); 3366 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &ev->bdaddr);
3355 if (!conn) { 3367 if (!conn) {
3356 conn = hci_conn_add(hdev, LE_LINK, &ev->bdaddr); 3368 conn = hci_conn_add(hdev, LE_LINK, &ev->bdaddr);
@@ -3363,15 +3375,6 @@ static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff
3363 conn->dst_type = ev->bdaddr_type; 3375 conn->dst_type = ev->bdaddr_type;
3364 } 3376 }
3365 3377
3366 if (ev->status) {
3367 mgmt_connect_failed(hdev, &ev->bdaddr, conn->type,
3368 conn->dst_type, ev->status);
3369 hci_proto_connect_cfm(conn, ev->status);
3370 conn->state = BT_CLOSED;
3371 hci_conn_del(conn);
3372 goto unlock;
3373 }
3374
3375 if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) 3378 if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
3376 mgmt_device_connected(hdev, &ev->bdaddr, conn->type, 3379 mgmt_device_connected(hdev, &ev->bdaddr, conn->type,
3377 conn->dst_type, 0, NULL, 0, NULL); 3380 conn->dst_type, 0, NULL, 0, NULL);
@@ -3389,8 +3392,7 @@ unlock:
3389 hci_dev_unlock(hdev); 3392 hci_dev_unlock(hdev);
3390} 3393}
3391 3394
3392static inline void hci_le_adv_report_evt(struct hci_dev *hdev, 3395static void hci_le_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb)
3393 struct sk_buff *skb)
3394{ 3396{
3395 u8 num_reports = skb->data[0]; 3397 u8 num_reports = skb->data[0];
3396 void *ptr = &skb->data[1]; 3398 void *ptr = &skb->data[1];
@@ -3411,8 +3413,7 @@ static inline void hci_le_adv_report_evt(struct hci_dev *hdev,
3411 hci_dev_unlock(hdev); 3413 hci_dev_unlock(hdev);
3412} 3414}
3413 3415
3414static inline void hci_le_ltk_request_evt(struct hci_dev *hdev, 3416static void hci_le_ltk_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
3415 struct sk_buff *skb)
3416{ 3417{
3417 struct hci_ev_le_ltk_req *ev = (void *) skb->data; 3418 struct hci_ev_le_ltk_req *ev = (void *) skb->data;
3418 struct hci_cp_le_ltk_reply cp; 3419 struct hci_cp_le_ltk_reply cp;
@@ -3455,7 +3456,7 @@ not_found:
3455 hci_dev_unlock(hdev); 3456 hci_dev_unlock(hdev);
3456} 3457}
3457 3458
3458static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb) 3459static void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
3459{ 3460{
3460 struct hci_ev_le_meta *le_ev = (void *) skb->data; 3461 struct hci_ev_le_meta *le_ev = (void *) skb->data;
3461 3462
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 5914623f426a..a7f04de03d79 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -24,25 +24,7 @@
24 24
25/* Bluetooth HCI sockets. */ 25/* Bluetooth HCI sockets. */
26 26
27#include <linux/module.h> 27#include <linux/export.h>
28
29#include <linux/types.h>
30#include <linux/capability.h>
31#include <linux/errno.h>
32#include <linux/kernel.h>
33#include <linux/slab.h>
34#include <linux/poll.h>
35#include <linux/fcntl.h>
36#include <linux/init.h>
37#include <linux/skbuff.h>
38#include <linux/workqueue.h>
39#include <linux/interrupt.h>
40#include <linux/compat.h>
41#include <linux/socket.h>
42#include <linux/ioctl.h>
43#include <net/sock.h>
44
45#include <linux/uaccess.h>
46#include <asm/unaligned.h> 28#include <asm/unaligned.h>
47 29
48#include <net/bluetooth/bluetooth.h> 30#include <net/bluetooth/bluetooth.h>
@@ -113,11 +95,12 @@ void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb)
113 flt = &hci_pi(sk)->filter; 95 flt = &hci_pi(sk)->filter;
114 96
115 if (!test_bit((bt_cb(skb)->pkt_type == HCI_VENDOR_PKT) ? 97 if (!test_bit((bt_cb(skb)->pkt_type == HCI_VENDOR_PKT) ?
116 0 : (bt_cb(skb)->pkt_type & HCI_FLT_TYPE_BITS), &flt->type_mask)) 98 0 : (bt_cb(skb)->pkt_type & HCI_FLT_TYPE_BITS),
99 &flt->type_mask))
117 continue; 100 continue;
118 101
119 if (bt_cb(skb)->pkt_type == HCI_EVENT_PKT) { 102 if (bt_cb(skb)->pkt_type == HCI_EVENT_PKT) {
120 register int evt = (*(__u8 *)skb->data & HCI_FLT_EVENT_BITS); 103 int evt = (*(__u8 *)skb->data & HCI_FLT_EVENT_BITS);
121 104
122 if (!hci_test_bit(evt, &flt->event_mask)) 105 if (!hci_test_bit(evt, &flt->event_mask))
123 continue; 106 continue;
@@ -240,7 +223,8 @@ void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb)
240 struct hci_mon_hdr *hdr; 223 struct hci_mon_hdr *hdr;
241 224
242 /* Create a private copy with headroom */ 225 /* Create a private copy with headroom */
243 skb_copy = __pskb_copy(skb, HCI_MON_HDR_SIZE, GFP_ATOMIC); 226 skb_copy = __pskb_copy(skb, HCI_MON_HDR_SIZE,
227 GFP_ATOMIC);
244 if (!skb_copy) 228 if (!skb_copy)
245 continue; 229 continue;
246 230
@@ -495,7 +479,8 @@ static int hci_sock_blacklist_del(struct hci_dev *hdev, void __user *arg)
495} 479}
496 480
497/* Ioctls that require bound socket */ 481/* Ioctls that require bound socket */
498static inline int hci_sock_bound_ioctl(struct sock *sk, unsigned int cmd, unsigned long arg) 482static int hci_sock_bound_ioctl(struct sock *sk, unsigned int cmd,
483 unsigned long arg)
499{ 484{
500 struct hci_dev *hdev = hci_pi(sk)->hdev; 485 struct hci_dev *hdev = hci_pi(sk)->hdev;
501 486
@@ -540,7 +525,8 @@ static inline int hci_sock_bound_ioctl(struct sock *sk, unsigned int cmd, unsign
540 } 525 }
541} 526}
542 527
543static int hci_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 528static int hci_sock_ioctl(struct socket *sock, unsigned int cmd,
529 unsigned long arg)
544{ 530{
545 struct sock *sk = sock->sk; 531 struct sock *sk = sock->sk;
546 void __user *argp = (void __user *) arg; 532 void __user *argp = (void __user *) arg;
@@ -601,7 +587,8 @@ static int hci_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long a
601 } 587 }
602} 588}
603 589
604static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, int addr_len) 590static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
591 int addr_len)
605{ 592{
606 struct sockaddr_hci haddr; 593 struct sockaddr_hci haddr;
607 struct sock *sk = sock->sk; 594 struct sock *sk = sock->sk;
@@ -690,7 +677,8 @@ done:
690 return err; 677 return err;
691} 678}
692 679
693static int hci_sock_getname(struct socket *sock, struct sockaddr *addr, int *addr_len, int peer) 680static int hci_sock_getname(struct socket *sock, struct sockaddr *addr,
681 int *addr_len, int peer)
694{ 682{
695 struct sockaddr_hci *haddr = (struct sockaddr_hci *) addr; 683 struct sockaddr_hci *haddr = (struct sockaddr_hci *) addr;
696 struct sock *sk = sock->sk; 684 struct sock *sk = sock->sk;
@@ -711,13 +699,15 @@ static int hci_sock_getname(struct socket *sock, struct sockaddr *addr, int *add
711 return 0; 699 return 0;
712} 700}
713 701
714static inline void hci_sock_cmsg(struct sock *sk, struct msghdr *msg, struct sk_buff *skb) 702static void hci_sock_cmsg(struct sock *sk, struct msghdr *msg,
703 struct sk_buff *skb)
715{ 704{
716 __u32 mask = hci_pi(sk)->cmsg_mask; 705 __u32 mask = hci_pi(sk)->cmsg_mask;
717 706
718 if (mask & HCI_CMSG_DIR) { 707 if (mask & HCI_CMSG_DIR) {
719 int incoming = bt_cb(skb)->incoming; 708 int incoming = bt_cb(skb)->incoming;
720 put_cmsg(msg, SOL_HCI, HCI_CMSG_DIR, sizeof(incoming), &incoming); 709 put_cmsg(msg, SOL_HCI, HCI_CMSG_DIR, sizeof(incoming),
710 &incoming);
721 } 711 }
722 712
723 if (mask & HCI_CMSG_TSTAMP) { 713 if (mask & HCI_CMSG_TSTAMP) {
@@ -747,7 +737,7 @@ static inline void hci_sock_cmsg(struct sock *sk, struct msghdr *msg, struct sk_
747} 737}
748 738
749static int hci_sock_recvmsg(struct kiocb *iocb, struct socket *sock, 739static int hci_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
750 struct msghdr *msg, size_t len, int flags) 740 struct msghdr *msg, size_t len, int flags)
751{ 741{
752 int noblock = flags & MSG_DONTWAIT; 742 int noblock = flags & MSG_DONTWAIT;
753 struct sock *sk = sock->sk; 743 struct sock *sk = sock->sk;
@@ -857,8 +847,9 @@ static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
857 u16 ocf = hci_opcode_ocf(opcode); 847 u16 ocf = hci_opcode_ocf(opcode);
858 848
859 if (((ogf > HCI_SFLT_MAX_OGF) || 849 if (((ogf > HCI_SFLT_MAX_OGF) ||
860 !hci_test_bit(ocf & HCI_FLT_OCF_BITS, &hci_sec_filter.ocf_mask[ogf])) && 850 !hci_test_bit(ocf & HCI_FLT_OCF_BITS,
861 !capable(CAP_NET_RAW)) { 851 &hci_sec_filter.ocf_mask[ogf])) &&
852 !capable(CAP_NET_RAW)) {
862 err = -EPERM; 853 err = -EPERM;
863 goto drop; 854 goto drop;
864 } 855 }
@@ -891,7 +882,8 @@ drop:
891 goto done; 882 goto done;
892} 883}
893 884
894static int hci_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int len) 885static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
886 char __user *optval, unsigned int len)
895{ 887{
896 struct hci_ufilter uf = { .opcode = 0 }; 888 struct hci_ufilter uf = { .opcode = 0 };
897 struct sock *sk = sock->sk; 889 struct sock *sk = sock->sk;
@@ -973,7 +965,8 @@ done:
973 return err; 965 return err;
974} 966}
975 967
976static int hci_sock_getsockopt(struct socket *sock, int level, int optname, char __user *optval, int __user *optlen) 968static int hci_sock_getsockopt(struct socket *sock, int level, int optname,
969 char __user *optval, int __user *optlen)
977{ 970{
978 struct hci_ufilter uf; 971 struct hci_ufilter uf;
979 struct sock *sk = sock->sk; 972 struct sock *sk = sock->sk;
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 937f3187eafa..a20e61c3653d 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -1,10 +1,6 @@
1/* Bluetooth HCI driver model support. */ 1/* Bluetooth HCI driver model support. */
2 2
3#include <linux/kernel.h>
4#include <linux/slab.h>
5#include <linux/init.h>
6#include <linux/debugfs.h> 3#include <linux/debugfs.h>
7#include <linux/seq_file.h>
8#include <linux/module.h> 4#include <linux/module.h>
9 5
10#include <net/bluetooth/bluetooth.h> 6#include <net/bluetooth/bluetooth.h>
@@ -31,27 +27,30 @@ static inline char *link_typetostr(int type)
31 } 27 }
32} 28}
33 29
34static ssize_t show_link_type(struct device *dev, struct device_attribute *attr, char *buf) 30static ssize_t show_link_type(struct device *dev,
31 struct device_attribute *attr, char *buf)
35{ 32{
36 struct hci_conn *conn = to_hci_conn(dev); 33 struct hci_conn *conn = to_hci_conn(dev);
37 return sprintf(buf, "%s\n", link_typetostr(conn->type)); 34 return sprintf(buf, "%s\n", link_typetostr(conn->type));
38} 35}
39 36
40static ssize_t show_link_address(struct device *dev, struct device_attribute *attr, char *buf) 37static ssize_t show_link_address(struct device *dev,
38 struct device_attribute *attr, char *buf)
41{ 39{
42 struct hci_conn *conn = to_hci_conn(dev); 40 struct hci_conn *conn = to_hci_conn(dev);
43 return sprintf(buf, "%s\n", batostr(&conn->dst)); 41 return sprintf(buf, "%s\n", batostr(&conn->dst));
44} 42}
45 43
46static ssize_t show_link_features(struct device *dev, struct device_attribute *attr, char *buf) 44static ssize_t show_link_features(struct device *dev,
45 struct device_attribute *attr, char *buf)
47{ 46{
48 struct hci_conn *conn = to_hci_conn(dev); 47 struct hci_conn *conn = to_hci_conn(dev);
49 48
50 return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", 49 return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
51 conn->features[0], conn->features[1], 50 conn->features[0], conn->features[1],
52 conn->features[2], conn->features[3], 51 conn->features[2], conn->features[3],
53 conn->features[4], conn->features[5], 52 conn->features[4], conn->features[5],
54 conn->features[6], conn->features[7]); 53 conn->features[6], conn->features[7]);
55} 54}
56 55
57#define LINK_ATTR(_name, _mode, _show, _store) \ 56#define LINK_ATTR(_name, _mode, _show, _store) \
@@ -185,19 +184,22 @@ static inline char *host_typetostr(int type)
185 } 184 }
186} 185}
187 186
188static ssize_t show_bus(struct device *dev, struct device_attribute *attr, char *buf) 187static ssize_t show_bus(struct device *dev,
188 struct device_attribute *attr, char *buf)
189{ 189{
190 struct hci_dev *hdev = to_hci_dev(dev); 190 struct hci_dev *hdev = to_hci_dev(dev);
191 return sprintf(buf, "%s\n", host_bustostr(hdev->bus)); 191 return sprintf(buf, "%s\n", host_bustostr(hdev->bus));
192} 192}
193 193
194static ssize_t show_type(struct device *dev, struct device_attribute *attr, char *buf) 194static ssize_t show_type(struct device *dev,
195 struct device_attribute *attr, char *buf)
195{ 196{
196 struct hci_dev *hdev = to_hci_dev(dev); 197 struct hci_dev *hdev = to_hci_dev(dev);
197 return sprintf(buf, "%s\n", host_typetostr(hdev->dev_type)); 198 return sprintf(buf, "%s\n", host_typetostr(hdev->dev_type));
198} 199}
199 200
200static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) 201static ssize_t show_name(struct device *dev,
202 struct device_attribute *attr, char *buf)
201{ 203{
202 struct hci_dev *hdev = to_hci_dev(dev); 204 struct hci_dev *hdev = to_hci_dev(dev);
203 char name[HCI_MAX_NAME_LENGTH + 1]; 205 char name[HCI_MAX_NAME_LENGTH + 1];
@@ -210,55 +212,64 @@ static ssize_t show_name(struct device *dev, struct device_attribute *attr, char
210 return sprintf(buf, "%s\n", name); 212 return sprintf(buf, "%s\n", name);
211} 213}
212 214
213static ssize_t show_class(struct device *dev, struct device_attribute *attr, char *buf) 215static ssize_t show_class(struct device *dev,
216 struct device_attribute *attr, char *buf)
214{ 217{
215 struct hci_dev *hdev = to_hci_dev(dev); 218 struct hci_dev *hdev = to_hci_dev(dev);
216 return sprintf(buf, "0x%.2x%.2x%.2x\n", 219 return sprintf(buf, "0x%.2x%.2x%.2x\n", hdev->dev_class[2],
217 hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]); 220 hdev->dev_class[1], hdev->dev_class[0]);
218} 221}
219 222
220static ssize_t show_address(struct device *dev, struct device_attribute *attr, char *buf) 223static ssize_t show_address(struct device *dev,
224 struct device_attribute *attr, char *buf)
221{ 225{
222 struct hci_dev *hdev = to_hci_dev(dev); 226 struct hci_dev *hdev = to_hci_dev(dev);
223 return sprintf(buf, "%s\n", batostr(&hdev->bdaddr)); 227 return sprintf(buf, "%s\n", batostr(&hdev->bdaddr));
224} 228}
225 229
226static ssize_t show_features(struct device *dev, struct device_attribute *attr, char *buf) 230static ssize_t show_features(struct device *dev,
231 struct device_attribute *attr, char *buf)
227{ 232{
228 struct hci_dev *hdev = to_hci_dev(dev); 233 struct hci_dev *hdev = to_hci_dev(dev);
229 234
230 return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n", 235 return sprintf(buf, "0x%02x%02x%02x%02x%02x%02x%02x%02x\n",
231 hdev->features[0], hdev->features[1], 236 hdev->features[0], hdev->features[1],
232 hdev->features[2], hdev->features[3], 237 hdev->features[2], hdev->features[3],
233 hdev->features[4], hdev->features[5], 238 hdev->features[4], hdev->features[5],
234 hdev->features[6], hdev->features[7]); 239 hdev->features[6], hdev->features[7]);
235} 240}
236 241
237static ssize_t show_manufacturer(struct device *dev, struct device_attribute *attr, char *buf) 242static ssize_t show_manufacturer(struct device *dev,
243 struct device_attribute *attr, char *buf)
238{ 244{
239 struct hci_dev *hdev = to_hci_dev(dev); 245 struct hci_dev *hdev = to_hci_dev(dev);
240 return sprintf(buf, "%d\n", hdev->manufacturer); 246 return sprintf(buf, "%d\n", hdev->manufacturer);
241} 247}
242 248
243static ssize_t show_hci_version(struct device *dev, struct device_attribute *attr, char *buf) 249static ssize_t show_hci_version(struct device *dev,
250 struct device_attribute *attr, char *buf)
244{ 251{
245 struct hci_dev *hdev = to_hci_dev(dev); 252 struct hci_dev *hdev = to_hci_dev(dev);
246 return sprintf(buf, "%d\n", hdev->hci_ver); 253 return sprintf(buf, "%d\n", hdev->hci_ver);
247} 254}
248 255
249static ssize_t show_hci_revision(struct device *dev, struct device_attribute *attr, char *buf) 256static ssize_t show_hci_revision(struct device *dev,
257 struct device_attribute *attr, char *buf)
250{ 258{
251 struct hci_dev *hdev = to_hci_dev(dev); 259 struct hci_dev *hdev = to_hci_dev(dev);
252 return sprintf(buf, "%d\n", hdev->hci_rev); 260 return sprintf(buf, "%d\n", hdev->hci_rev);
253} 261}
254 262
255static ssize_t show_idle_timeout(struct device *dev, struct device_attribute *attr, char *buf) 263static ssize_t show_idle_timeout(struct device *dev,
264 struct device_attribute *attr, char *buf)
256{ 265{
257 struct hci_dev *hdev = to_hci_dev(dev); 266 struct hci_dev *hdev = to_hci_dev(dev);
258 return sprintf(buf, "%d\n", hdev->idle_timeout); 267 return sprintf(buf, "%d\n", hdev->idle_timeout);
259} 268}
260 269
261static ssize_t store_idle_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 270static ssize_t store_idle_timeout(struct device *dev,
271 struct device_attribute *attr,
272 const char *buf, size_t count)
262{ 273{
263 struct hci_dev *hdev = to_hci_dev(dev); 274 struct hci_dev *hdev = to_hci_dev(dev);
264 unsigned int val; 275 unsigned int val;
@@ -276,13 +287,16 @@ static ssize_t store_idle_timeout(struct device *dev, struct device_attribute *a
276 return count; 287 return count;
277} 288}
278 289
279static ssize_t show_sniff_max_interval(struct device *dev, struct device_attribute *attr, char *buf) 290static ssize_t show_sniff_max_interval(struct device *dev,
291 struct device_attribute *attr, char *buf)
280{ 292{
281 struct hci_dev *hdev = to_hci_dev(dev); 293 struct hci_dev *hdev = to_hci_dev(dev);
282 return sprintf(buf, "%d\n", hdev->sniff_max_interval); 294 return sprintf(buf, "%d\n", hdev->sniff_max_interval);
283} 295}
284 296
285static ssize_t store_sniff_max_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 297static ssize_t store_sniff_max_interval(struct device *dev,
298 struct device_attribute *attr,
299 const char *buf, size_t count)
286{ 300{
287 struct hci_dev *hdev = to_hci_dev(dev); 301 struct hci_dev *hdev = to_hci_dev(dev);
288 u16 val; 302 u16 val;
@@ -300,13 +314,16 @@ static ssize_t store_sniff_max_interval(struct device *dev, struct device_attrib
300 return count; 314 return count;
301} 315}
302 316
303static ssize_t show_sniff_min_interval(struct device *dev, struct device_attribute *attr, char *buf) 317static ssize_t show_sniff_min_interval(struct device *dev,
318 struct device_attribute *attr, char *buf)
304{ 319{
305 struct hci_dev *hdev = to_hci_dev(dev); 320 struct hci_dev *hdev = to_hci_dev(dev);
306 return sprintf(buf, "%d\n", hdev->sniff_min_interval); 321 return sprintf(buf, "%d\n", hdev->sniff_min_interval);
307} 322}
308 323
309static ssize_t store_sniff_min_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 324static ssize_t store_sniff_min_interval(struct device *dev,
325 struct device_attribute *attr,
326 const char *buf, size_t count)
310{ 327{
311 struct hci_dev *hdev = to_hci_dev(dev); 328 struct hci_dev *hdev = to_hci_dev(dev);
312 u16 val; 329 u16 val;
@@ -335,11 +352,11 @@ static DEVICE_ATTR(hci_version, S_IRUGO, show_hci_version, NULL);
335static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL); 352static DEVICE_ATTR(hci_revision, S_IRUGO, show_hci_revision, NULL);
336 353
337static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR, 354static DEVICE_ATTR(idle_timeout, S_IRUGO | S_IWUSR,
338 show_idle_timeout, store_idle_timeout); 355 show_idle_timeout, store_idle_timeout);
339static DEVICE_ATTR(sniff_max_interval, S_IRUGO | S_IWUSR, 356static DEVICE_ATTR(sniff_max_interval, S_IRUGO | S_IWUSR,
340 show_sniff_max_interval, store_sniff_max_interval); 357 show_sniff_max_interval, store_sniff_max_interval);
341static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR, 358static DEVICE_ATTR(sniff_min_interval, S_IRUGO | S_IWUSR,
342 show_sniff_min_interval, store_sniff_min_interval); 359 show_sniff_min_interval, store_sniff_min_interval);
343 360
344static struct attribute *bt_host_attrs[] = { 361static struct attribute *bt_host_attrs[] = {
345 &dev_attr_bus.attr, 362 &dev_attr_bus.attr,
@@ -455,8 +472,8 @@ static void print_bt_uuid(struct seq_file *f, u8 *uuid)
455 memcpy(&data5, &uuid[14], 2); 472 memcpy(&data5, &uuid[14], 2);
456 473
457 seq_printf(f, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x\n", 474 seq_printf(f, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x\n",
458 ntohl(data0), ntohs(data1), ntohs(data2), 475 ntohl(data0), ntohs(data1), ntohs(data2), ntohs(data3),
459 ntohs(data3), ntohl(data4), ntohs(data5)); 476 ntohl(data4), ntohs(data5));
460} 477}
461 478
462static int uuids_show(struct seq_file *f, void *p) 479static int uuids_show(struct seq_file *f, void *p)
@@ -513,7 +530,7 @@ static int auto_accept_delay_get(void *data, u64 *val)
513} 530}
514 531
515DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get, 532DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
516 auto_accept_delay_set, "%llu\n"); 533 auto_accept_delay_set, "%llu\n");
517 534
518void hci_init_sysfs(struct hci_dev *hdev) 535void hci_init_sysfs(struct hci_dev *hdev)
519{ 536{
@@ -547,15 +564,15 @@ int hci_add_sysfs(struct hci_dev *hdev)
547 return 0; 564 return 0;
548 565
549 debugfs_create_file("inquiry_cache", 0444, hdev->debugfs, 566 debugfs_create_file("inquiry_cache", 0444, hdev->debugfs,
550 hdev, &inquiry_cache_fops); 567 hdev, &inquiry_cache_fops);
551 568
552 debugfs_create_file("blacklist", 0444, hdev->debugfs, 569 debugfs_create_file("blacklist", 0444, hdev->debugfs,
553 hdev, &blacklist_fops); 570 hdev, &blacklist_fops);
554 571
555 debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops); 572 debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops);
556 573
557 debugfs_create_file("auto_accept_delay", 0444, hdev->debugfs, hdev, 574 debugfs_create_file("auto_accept_delay", 0444, hdev->debugfs, hdev,
558 &auto_accept_delay_fops); 575 &auto_accept_delay_fops);
559 return 0; 576 return 0;
560} 577}
561 578
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index 2c20d765b394..ccd985da6518 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -21,27 +21,8 @@
21*/ 21*/
22 22
23#include <linux/module.h> 23#include <linux/module.h>
24
25#include <linux/types.h>
26#include <linux/errno.h>
27#include <linux/kernel.h>
28#include <linux/sched.h>
29#include <linux/slab.h>
30#include <linux/poll.h>
31#include <linux/freezer.h>
32#include <linux/fcntl.h>
33#include <linux/skbuff.h>
34#include <linux/socket.h>
35#include <linux/ioctl.h>
36#include <linux/file.h> 24#include <linux/file.h>
37#include <linux/init.h>
38#include <linux/wait.h>
39#include <linux/mutex.h>
40#include <linux/kthread.h> 25#include <linux/kthread.h>
41#include <net/sock.h>
42
43#include <linux/input.h>
44#include <linux/hid.h>
45#include <linux/hidraw.h> 26#include <linux/hidraw.h>
46 27
47#include <net/bluetooth/bluetooth.h> 28#include <net/bluetooth/bluetooth.h>
@@ -244,7 +225,8 @@ static void hidp_input_report(struct hidp_session *session, struct sk_buff *skb)
244} 225}
245 226
246static int __hidp_send_ctrl_message(struct hidp_session *session, 227static int __hidp_send_ctrl_message(struct hidp_session *session,
247 unsigned char hdr, unsigned char *data, int size) 228 unsigned char hdr, unsigned char *data,
229 int size)
248{ 230{
249 struct sk_buff *skb; 231 struct sk_buff *skb;
250 232
@@ -268,7 +250,7 @@ static int __hidp_send_ctrl_message(struct hidp_session *session,
268 return 0; 250 return 0;
269} 251}
270 252
271static inline int hidp_send_ctrl_message(struct hidp_session *session, 253static int hidp_send_ctrl_message(struct hidp_session *session,
272 unsigned char hdr, unsigned char *data, int size) 254 unsigned char hdr, unsigned char *data, int size)
273{ 255{
274 int err; 256 int err;
@@ -471,7 +453,7 @@ static void hidp_set_timer(struct hidp_session *session)
471 mod_timer(&session->timer, jiffies + HZ * session->idle_to); 453 mod_timer(&session->timer, jiffies + HZ * session->idle_to);
472} 454}
473 455
474static inline void hidp_del_timer(struct hidp_session *session) 456static void hidp_del_timer(struct hidp_session *session)
475{ 457{
476 if (session->idle_to > 0) 458 if (session->idle_to > 0)
477 del_timer(&session->timer); 459 del_timer(&session->timer);
diff --git a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c
index 73a32d705c1f..18b3f6892a36 100644
--- a/net/bluetooth/hidp/sock.c
+++ b/net/bluetooth/hidp/sock.c
@@ -20,22 +20,8 @@
20 SOFTWARE IS DISCLAIMED. 20 SOFTWARE IS DISCLAIMED.
21*/ 21*/
22 22
23#include <linux/module.h> 23#include <linux/export.h>
24
25#include <linux/types.h>
26#include <linux/capability.h>
27#include <linux/errno.h>
28#include <linux/kernel.h>
29#include <linux/poll.h>
30#include <linux/fcntl.h>
31#include <linux/skbuff.h>
32#include <linux/socket.h>
33#include <linux/ioctl.h>
34#include <linux/file.h> 24#include <linux/file.h>
35#include <linux/init.h>
36#include <linux/compat.h>
37#include <linux/gfp.h>
38#include <net/sock.h>
39 25
40#include "hidp.h" 26#include "hidp.h"
41 27
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 8394e3615ef6..4ca88247b7c2 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -30,32 +30,14 @@
30 30
31#include <linux/module.h> 31#include <linux/module.h>
32 32
33#include <linux/types.h>
34#include <linux/capability.h>
35#include <linux/errno.h>
36#include <linux/kernel.h>
37#include <linux/sched.h>
38#include <linux/slab.h>
39#include <linux/poll.h>
40#include <linux/fcntl.h>
41#include <linux/init.h>
42#include <linux/interrupt.h>
43#include <linux/socket.h>
44#include <linux/skbuff.h>
45#include <linux/list.h>
46#include <linux/device.h>
47#include <linux/debugfs.h> 33#include <linux/debugfs.h>
48#include <linux/seq_file.h>
49#include <linux/uaccess.h>
50#include <linux/crc16.h> 34#include <linux/crc16.h>
51#include <net/sock.h>
52
53#include <asm/unaligned.h>
54 35
55#include <net/bluetooth/bluetooth.h> 36#include <net/bluetooth/bluetooth.h>
56#include <net/bluetooth/hci_core.h> 37#include <net/bluetooth/hci_core.h>
57#include <net/bluetooth/l2cap.h> 38#include <net/bluetooth/l2cap.h>
58#include <net/bluetooth/smp.h> 39#include <net/bluetooth/smp.h>
40#include <net/bluetooth/a2mp.h>
59 41
60bool disable_ertm; 42bool disable_ertm;
61 43
@@ -73,6 +55,9 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data);
73static void l2cap_send_disconn_req(struct l2cap_conn *conn, 55static void l2cap_send_disconn_req(struct l2cap_conn *conn,
74 struct l2cap_chan *chan, int err); 56 struct l2cap_chan *chan, int err);
75 57
58static void l2cap_tx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
59 struct sk_buff_head *skbs, u8 event);
60
76/* ---- L2CAP channels ---- */ 61/* ---- L2CAP channels ---- */
77 62
78static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn, u16 cid) 63static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn, u16 cid)
@@ -196,7 +181,7 @@ static void __l2cap_state_change(struct l2cap_chan *chan, int state)
196 state_to_string(state)); 181 state_to_string(state));
197 182
198 chan->state = state; 183 chan->state = state;
199 chan->ops->state_change(chan->data, state); 184 chan->ops->state_change(chan, state);
200} 185}
201 186
202static void l2cap_state_change(struct l2cap_chan *chan, int state) 187static void l2cap_state_change(struct l2cap_chan *chan, int state)
@@ -224,6 +209,37 @@ static inline void l2cap_chan_set_err(struct l2cap_chan *chan, int err)
224 release_sock(sk); 209 release_sock(sk);
225} 210}
226 211
212static void __set_retrans_timer(struct l2cap_chan *chan)
213{
214 if (!delayed_work_pending(&chan->monitor_timer) &&
215 chan->retrans_timeout) {
216 l2cap_set_timer(chan, &chan->retrans_timer,
217 msecs_to_jiffies(chan->retrans_timeout));
218 }
219}
220
221static void __set_monitor_timer(struct l2cap_chan *chan)
222{
223 __clear_retrans_timer(chan);
224 if (chan->monitor_timeout) {
225 l2cap_set_timer(chan, &chan->monitor_timer,
226 msecs_to_jiffies(chan->monitor_timeout));
227 }
228}
229
230static struct sk_buff *l2cap_ertm_seq_in_queue(struct sk_buff_head *head,
231 u16 seq)
232{
233 struct sk_buff *skb;
234
235 skb_queue_walk(head, skb) {
236 if (bt_cb(skb)->control.txseq == seq)
237 return skb;
238 }
239
240 return NULL;
241}
242
227/* ---- L2CAP sequence number lists ---- */ 243/* ---- L2CAP sequence number lists ---- */
228 244
229/* For ERTM, ordered lists of sequence numbers must be tracked for 245/* For ERTM, ordered lists of sequence numbers must be tracked for
@@ -366,7 +382,7 @@ static void l2cap_chan_timeout(struct work_struct *work)
366 382
367 l2cap_chan_unlock(chan); 383 l2cap_chan_unlock(chan);
368 384
369 chan->ops->close(chan->data); 385 chan->ops->close(chan);
370 mutex_unlock(&conn->chan_lock); 386 mutex_unlock(&conn->chan_lock);
371 387
372 l2cap_chan_put(chan); 388 l2cap_chan_put(chan);
@@ -392,6 +408,9 @@ struct l2cap_chan *l2cap_chan_create(void)
392 408
393 atomic_set(&chan->refcnt, 1); 409 atomic_set(&chan->refcnt, 1);
394 410
411 /* This flag is cleared in l2cap_chan_ready() */
412 set_bit(CONF_NOT_COMPLETE, &chan->conf_state);
413
395 BT_DBG("chan %p", chan); 414 BT_DBG("chan %p", chan);
396 415
397 return chan; 416 return chan;
@@ -430,7 +449,7 @@ static void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
430 case L2CAP_CHAN_CONN_ORIENTED: 449 case L2CAP_CHAN_CONN_ORIENTED:
431 if (conn->hcon->type == LE_LINK) { 450 if (conn->hcon->type == LE_LINK) {
432 /* LE connection */ 451 /* LE connection */
433 chan->omtu = L2CAP_LE_DEFAULT_MTU; 452 chan->omtu = L2CAP_DEFAULT_MTU;
434 chan->scid = L2CAP_CID_LE_DATA; 453 chan->scid = L2CAP_CID_LE_DATA;
435 chan->dcid = L2CAP_CID_LE_DATA; 454 chan->dcid = L2CAP_CID_LE_DATA;
436 } else { 455 } else {
@@ -447,6 +466,13 @@ static void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
447 chan->omtu = L2CAP_DEFAULT_MTU; 466 chan->omtu = L2CAP_DEFAULT_MTU;
448 break; 467 break;
449 468
469 case L2CAP_CHAN_CONN_FIX_A2MP:
470 chan->scid = L2CAP_CID_A2MP;
471 chan->dcid = L2CAP_CID_A2MP;
472 chan->omtu = L2CAP_A2MP_DEFAULT_MTU;
473 chan->imtu = L2CAP_A2MP_DEFAULT_MTU;
474 break;
475
450 default: 476 default:
451 /* Raw socket can send/recv signalling messages only */ 477 /* Raw socket can send/recv signalling messages only */
452 chan->scid = L2CAP_CID_SIGNALING; 478 chan->scid = L2CAP_CID_SIGNALING;
@@ -466,18 +492,16 @@ static void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
466 list_add(&chan->list, &conn->chan_l); 492 list_add(&chan->list, &conn->chan_l);
467} 493}
468 494
469static void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) 495void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
470{ 496{
471 mutex_lock(&conn->chan_lock); 497 mutex_lock(&conn->chan_lock);
472 __l2cap_chan_add(conn, chan); 498 __l2cap_chan_add(conn, chan);
473 mutex_unlock(&conn->chan_lock); 499 mutex_unlock(&conn->chan_lock);
474} 500}
475 501
476static void l2cap_chan_del(struct l2cap_chan *chan, int err) 502void l2cap_chan_del(struct l2cap_chan *chan, int err)
477{ 503{
478 struct sock *sk = chan->sk;
479 struct l2cap_conn *conn = chan->conn; 504 struct l2cap_conn *conn = chan->conn;
480 struct sock *parent = bt_sk(sk)->parent;
481 505
482 __clear_chan_timer(chan); 506 __clear_chan_timer(chan);
483 507
@@ -490,34 +514,22 @@ static void l2cap_chan_del(struct l2cap_chan *chan, int err)
490 l2cap_chan_put(chan); 514 l2cap_chan_put(chan);
491 515
492 chan->conn = NULL; 516 chan->conn = NULL;
493 hci_conn_put(conn->hcon);
494 }
495
496 lock_sock(sk);
497
498 __l2cap_state_change(chan, BT_CLOSED);
499 sock_set_flag(sk, SOCK_ZAPPED);
500 517
501 if (err) 518 if (chan->chan_type != L2CAP_CHAN_CONN_FIX_A2MP)
502 __l2cap_chan_set_err(chan, err); 519 hci_conn_put(conn->hcon);
520 }
503 521
504 if (parent) { 522 if (chan->ops->teardown)
505 bt_accept_unlink(sk); 523 chan->ops->teardown(chan, err);
506 parent->sk_data_ready(parent, 0);
507 } else
508 sk->sk_state_change(sk);
509 524
510 release_sock(sk); 525 if (test_bit(CONF_NOT_COMPLETE, &chan->conf_state))
511
512 if (!(test_bit(CONF_OUTPUT_DONE, &chan->conf_state) &&
513 test_bit(CONF_INPUT_DONE, &chan->conf_state)))
514 return; 526 return;
515 527
516 skb_queue_purge(&chan->tx_q); 528 switch(chan->mode) {
517 529 case L2CAP_MODE_BASIC:
518 if (chan->mode == L2CAP_MODE_ERTM) { 530 break;
519 struct srej_list *l, *tmp;
520 531
532 case L2CAP_MODE_ERTM:
521 __clear_retrans_timer(chan); 533 __clear_retrans_timer(chan);
522 __clear_monitor_timer(chan); 534 __clear_monitor_timer(chan);
523 __clear_ack_timer(chan); 535 __clear_ack_timer(chan);
@@ -526,30 +538,15 @@ static void l2cap_chan_del(struct l2cap_chan *chan, int err)
526 538
527 l2cap_seq_list_free(&chan->srej_list); 539 l2cap_seq_list_free(&chan->srej_list);
528 l2cap_seq_list_free(&chan->retrans_list); 540 l2cap_seq_list_free(&chan->retrans_list);
529 list_for_each_entry_safe(l, tmp, &chan->srej_l, list) {
530 list_del(&l->list);
531 kfree(l);
532 }
533 }
534}
535
536static void l2cap_chan_cleanup_listen(struct sock *parent)
537{
538 struct sock *sk;
539
540 BT_DBG("parent %p", parent);
541 541
542 /* Close not yet accepted channels */ 542 /* fall through */
543 while ((sk = bt_accept_dequeue(parent, NULL))) {
544 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
545
546 l2cap_chan_lock(chan);
547 __clear_chan_timer(chan);
548 l2cap_chan_close(chan, ECONNRESET);
549 l2cap_chan_unlock(chan);
550 543
551 chan->ops->close(chan->data); 544 case L2CAP_MODE_STREAMING:
545 skb_queue_purge(&chan->tx_q);
546 break;
552 } 547 }
548
549 return;
553} 550}
554 551
555void l2cap_chan_close(struct l2cap_chan *chan, int reason) 552void l2cap_chan_close(struct l2cap_chan *chan, int reason)
@@ -562,12 +559,8 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason)
562 559
563 switch (chan->state) { 560 switch (chan->state) {
564 case BT_LISTEN: 561 case BT_LISTEN:
565 lock_sock(sk); 562 if (chan->ops->teardown)
566 l2cap_chan_cleanup_listen(sk); 563 chan->ops->teardown(chan, 0);
567
568 __l2cap_state_change(chan, BT_CLOSED);
569 sock_set_flag(sk, SOCK_ZAPPED);
570 release_sock(sk);
571 break; 564 break;
572 565
573 case BT_CONNECTED: 566 case BT_CONNECTED:
@@ -595,7 +588,7 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason)
595 rsp.scid = cpu_to_le16(chan->dcid); 588 rsp.scid = cpu_to_le16(chan->dcid);
596 rsp.dcid = cpu_to_le16(chan->scid); 589 rsp.dcid = cpu_to_le16(chan->scid);
597 rsp.result = cpu_to_le16(result); 590 rsp.result = cpu_to_le16(result);
598 rsp.status = cpu_to_le16(L2CAP_CS_NO_INFO); 591 rsp.status = __constant_cpu_to_le16(L2CAP_CS_NO_INFO);
599 l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP, 592 l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP,
600 sizeof(rsp), &rsp); 593 sizeof(rsp), &rsp);
601 } 594 }
@@ -609,9 +602,8 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason)
609 break; 602 break;
610 603
611 default: 604 default:
612 lock_sock(sk); 605 if (chan->ops->teardown)
613 sock_set_flag(sk, SOCK_ZAPPED); 606 chan->ops->teardown(chan, 0);
614 release_sock(sk);
615 break; 607 break;
616 } 608 }
617} 609}
@@ -627,7 +619,7 @@ static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan)
627 default: 619 default:
628 return HCI_AT_NO_BONDING; 620 return HCI_AT_NO_BONDING;
629 } 621 }
630 } else if (chan->psm == cpu_to_le16(0x0001)) { 622 } else if (chan->psm == __constant_cpu_to_le16(L2CAP_PSM_SDP)) {
631 if (chan->sec_level == BT_SECURITY_LOW) 623 if (chan->sec_level == BT_SECURITY_LOW)
632 chan->sec_level = BT_SECURITY_SDP; 624 chan->sec_level = BT_SECURITY_SDP;
633 625
@@ -773,9 +765,11 @@ static inline void __unpack_control(struct l2cap_chan *chan,
773 if (test_bit(FLAG_EXT_CTRL, &chan->flags)) { 765 if (test_bit(FLAG_EXT_CTRL, &chan->flags)) {
774 __unpack_extended_control(get_unaligned_le32(skb->data), 766 __unpack_extended_control(get_unaligned_le32(skb->data),
775 &bt_cb(skb)->control); 767 &bt_cb(skb)->control);
768 skb_pull(skb, L2CAP_EXT_CTRL_SIZE);
776 } else { 769 } else {
777 __unpack_enhanced_control(get_unaligned_le16(skb->data), 770 __unpack_enhanced_control(get_unaligned_le16(skb->data),
778 &bt_cb(skb)->control); 771 &bt_cb(skb)->control);
772 skb_pull(skb, L2CAP_ENH_CTRL_SIZE);
779 } 773 }
780} 774}
781 775
@@ -830,66 +824,102 @@ static inline void __pack_control(struct l2cap_chan *chan,
830 } 824 }
831} 825}
832 826
833static inline void l2cap_send_sframe(struct l2cap_chan *chan, u32 control) 827static inline unsigned int __ertm_hdr_size(struct l2cap_chan *chan)
834{ 828{
835 struct sk_buff *skb;
836 struct l2cap_hdr *lh;
837 struct l2cap_conn *conn = chan->conn;
838 int count, hlen;
839
840 if (chan->state != BT_CONNECTED)
841 return;
842
843 if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 829 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
844 hlen = L2CAP_EXT_HDR_SIZE; 830 return L2CAP_EXT_HDR_SIZE;
845 else 831 else
846 hlen = L2CAP_ENH_HDR_SIZE; 832 return L2CAP_ENH_HDR_SIZE;
833}
834
835static struct sk_buff *l2cap_create_sframe_pdu(struct l2cap_chan *chan,
836 u32 control)
837{
838 struct sk_buff *skb;
839 struct l2cap_hdr *lh;
840 int hlen = __ertm_hdr_size(chan);
847 841
848 if (chan->fcs == L2CAP_FCS_CRC16) 842 if (chan->fcs == L2CAP_FCS_CRC16)
849 hlen += L2CAP_FCS_SIZE; 843 hlen += L2CAP_FCS_SIZE;
850 844
851 BT_DBG("chan %p, control 0x%8.8x", chan, control); 845 skb = bt_skb_alloc(hlen, GFP_KERNEL);
852
853 count = min_t(unsigned int, conn->mtu, hlen);
854
855 control |= __set_sframe(chan);
856 846
857 if (test_and_clear_bit(CONN_SEND_FBIT, &chan->conn_state))
858 control |= __set_ctrl_final(chan);
859
860 if (test_and_clear_bit(CONN_SEND_PBIT, &chan->conn_state))
861 control |= __set_ctrl_poll(chan);
862
863 skb = bt_skb_alloc(count, GFP_ATOMIC);
864 if (!skb) 847 if (!skb)
865 return; 848 return ERR_PTR(-ENOMEM);
866 849
867 lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE); 850 lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE);
868 lh->len = cpu_to_le16(hlen - L2CAP_HDR_SIZE); 851 lh->len = cpu_to_le16(hlen - L2CAP_HDR_SIZE);
869 lh->cid = cpu_to_le16(chan->dcid); 852 lh->cid = cpu_to_le16(chan->dcid);
870 853
871 __put_control(chan, control, skb_put(skb, __ctrl_size(chan))); 854 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
855 put_unaligned_le32(control, skb_put(skb, L2CAP_EXT_CTRL_SIZE));
856 else
857 put_unaligned_le16(control, skb_put(skb, L2CAP_ENH_CTRL_SIZE));
872 858
873 if (chan->fcs == L2CAP_FCS_CRC16) { 859 if (chan->fcs == L2CAP_FCS_CRC16) {
874 u16 fcs = crc16(0, (u8 *)lh, count - L2CAP_FCS_SIZE); 860 u16 fcs = crc16(0, (u8 *)skb->data, skb->len);
875 put_unaligned_le16(fcs, skb_put(skb, L2CAP_FCS_SIZE)); 861 put_unaligned_le16(fcs, skb_put(skb, L2CAP_FCS_SIZE));
876 } 862 }
877 863
878 skb->priority = HCI_PRIO_MAX; 864 skb->priority = HCI_PRIO_MAX;
879 l2cap_do_send(chan, skb); 865 return skb;
880} 866}
881 867
882static inline void l2cap_send_rr_or_rnr(struct l2cap_chan *chan, u32 control) 868static void l2cap_send_sframe(struct l2cap_chan *chan,
869 struct l2cap_ctrl *control)
883{ 870{
884 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) { 871 struct sk_buff *skb;
885 control |= __set_ctrl_super(chan, L2CAP_SUPER_RNR); 872 u32 control_field;
873
874 BT_DBG("chan %p, control %p", chan, control);
875
876 if (!control->sframe)
877 return;
878
879 if (test_and_clear_bit(CONN_SEND_FBIT, &chan->conn_state) &&
880 !control->poll)
881 control->final = 1;
882
883 if (control->super == L2CAP_SUPER_RR)
884 clear_bit(CONN_RNR_SENT, &chan->conn_state);
885 else if (control->super == L2CAP_SUPER_RNR)
886 set_bit(CONN_RNR_SENT, &chan->conn_state); 886 set_bit(CONN_RNR_SENT, &chan->conn_state);
887 } else
888 control |= __set_ctrl_super(chan, L2CAP_SUPER_RR);
889 887
890 control |= __set_reqseq(chan, chan->buffer_seq); 888 if (control->super != L2CAP_SUPER_SREJ) {
889 chan->last_acked_seq = control->reqseq;
890 __clear_ack_timer(chan);
891 }
891 892
892 l2cap_send_sframe(chan, control); 893 BT_DBG("reqseq %d, final %d, poll %d, super %d", control->reqseq,
894 control->final, control->poll, control->super);
895
896 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
897 control_field = __pack_extended_control(control);
898 else
899 control_field = __pack_enhanced_control(control);
900
901 skb = l2cap_create_sframe_pdu(chan, control_field);
902 if (!IS_ERR(skb))
903 l2cap_do_send(chan, skb);
904}
905
906static void l2cap_send_rr_or_rnr(struct l2cap_chan *chan, bool poll)
907{
908 struct l2cap_ctrl control;
909
910 BT_DBG("chan %p, poll %d", chan, poll);
911
912 memset(&control, 0, sizeof(control));
913 control.sframe = 1;
914 control.poll = poll;
915
916 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state))
917 control.super = L2CAP_SUPER_RNR;
918 else
919 control.super = L2CAP_SUPER_RR;
920
921 control.reqseq = chan->buffer_seq;
922 l2cap_send_sframe(chan, &control);
893} 923}
894 924
895static inline int __l2cap_no_conn_pending(struct l2cap_chan *chan) 925static inline int __l2cap_no_conn_pending(struct l2cap_chan *chan)
@@ -914,25 +944,13 @@ static void l2cap_send_conn_req(struct l2cap_chan *chan)
914 944
915static void l2cap_chan_ready(struct l2cap_chan *chan) 945static void l2cap_chan_ready(struct l2cap_chan *chan)
916{ 946{
917 struct sock *sk = chan->sk; 947 /* This clears all conf flags, including CONF_NOT_COMPLETE */
918 struct sock *parent;
919
920 lock_sock(sk);
921
922 parent = bt_sk(sk)->parent;
923
924 BT_DBG("sk %p, parent %p", sk, parent);
925
926 chan->conf_state = 0; 948 chan->conf_state = 0;
927 __clear_chan_timer(chan); 949 __clear_chan_timer(chan);
928 950
929 __l2cap_state_change(chan, BT_CONNECTED); 951 chan->state = BT_CONNECTED;
930 sk->sk_state_change(sk);
931
932 if (parent)
933 parent->sk_data_ready(parent, 0);
934 952
935 release_sock(sk); 953 chan->ops->ready(chan);
936} 954}
937 955
938static void l2cap_do_start(struct l2cap_chan *chan) 956static void l2cap_do_start(struct l2cap_chan *chan)
@@ -953,7 +971,7 @@ static void l2cap_do_start(struct l2cap_chan *chan)
953 l2cap_send_conn_req(chan); 971 l2cap_send_conn_req(chan);
954 } else { 972 } else {
955 struct l2cap_info_req req; 973 struct l2cap_info_req req;
956 req.type = cpu_to_le16(L2CAP_IT_FEAT_MASK); 974 req.type = __constant_cpu_to_le16(L2CAP_IT_FEAT_MASK);
957 975
958 conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_SENT; 976 conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_SENT;
959 conn->info_ident = l2cap_get_ident(conn); 977 conn->info_ident = l2cap_get_ident(conn);
@@ -995,6 +1013,11 @@ static void l2cap_send_disconn_req(struct l2cap_conn *conn, struct l2cap_chan *c
995 __clear_ack_timer(chan); 1013 __clear_ack_timer(chan);
996 } 1014 }
997 1015
1016 if (chan->chan_type == L2CAP_CHAN_CONN_FIX_A2MP) {
1017 __l2cap_state_change(chan, BT_DISCONN);
1018 return;
1019 }
1020
998 req.dcid = cpu_to_le16(chan->dcid); 1021 req.dcid = cpu_to_le16(chan->dcid);
999 req.scid = cpu_to_le16(chan->scid); 1022 req.scid = cpu_to_le16(chan->scid);
1000 l2cap_send_cmd(conn, l2cap_get_ident(conn), 1023 l2cap_send_cmd(conn, l2cap_get_ident(conn),
@@ -1053,20 +1076,20 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
1053 if (test_bit(BT_SK_DEFER_SETUP, 1076 if (test_bit(BT_SK_DEFER_SETUP,
1054 &bt_sk(sk)->flags)) { 1077 &bt_sk(sk)->flags)) {
1055 struct sock *parent = bt_sk(sk)->parent; 1078 struct sock *parent = bt_sk(sk)->parent;
1056 rsp.result = cpu_to_le16(L2CAP_CR_PEND); 1079 rsp.result = __constant_cpu_to_le16(L2CAP_CR_PEND);
1057 rsp.status = cpu_to_le16(L2CAP_CS_AUTHOR_PEND); 1080 rsp.status = __constant_cpu_to_le16(L2CAP_CS_AUTHOR_PEND);
1058 if (parent) 1081 if (parent)
1059 parent->sk_data_ready(parent, 0); 1082 parent->sk_data_ready(parent, 0);
1060 1083
1061 } else { 1084 } else {
1062 __l2cap_state_change(chan, BT_CONFIG); 1085 __l2cap_state_change(chan, BT_CONFIG);
1063 rsp.result = cpu_to_le16(L2CAP_CR_SUCCESS); 1086 rsp.result = __constant_cpu_to_le16(L2CAP_CR_SUCCESS);
1064 rsp.status = cpu_to_le16(L2CAP_CS_NO_INFO); 1087 rsp.status = __constant_cpu_to_le16(L2CAP_CS_NO_INFO);
1065 } 1088 }
1066 release_sock(sk); 1089 release_sock(sk);
1067 } else { 1090 } else {
1068 rsp.result = cpu_to_le16(L2CAP_CR_PEND); 1091 rsp.result = __constant_cpu_to_le16(L2CAP_CR_PEND);
1069 rsp.status = cpu_to_le16(L2CAP_CS_AUTHEN_PEND); 1092 rsp.status = __constant_cpu_to_le16(L2CAP_CS_AUTHEN_PEND);
1070 } 1093 }
1071 1094
1072 l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP, 1095 l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP,
@@ -1150,13 +1173,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
1150 1173
1151 lock_sock(parent); 1174 lock_sock(parent);
1152 1175
1153 /* Check for backlog size */ 1176 chan = pchan->ops->new_connection(pchan);
1154 if (sk_acceptq_is_full(parent)) {
1155 BT_DBG("backlog full %d", parent->sk_ack_backlog);
1156 goto clean;
1157 }
1158
1159 chan = pchan->ops->new_connection(pchan->data);
1160 if (!chan) 1177 if (!chan)
1161 goto clean; 1178 goto clean;
1162 1179
@@ -1171,10 +1188,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
1171 1188
1172 l2cap_chan_add(conn, chan); 1189 l2cap_chan_add(conn, chan);
1173 1190
1174 __set_chan_timer(chan, sk->sk_sndtimeo); 1191 l2cap_chan_ready(chan);
1175
1176 __l2cap_state_change(chan, BT_CONNECTED);
1177 parent->sk_data_ready(parent, 0);
1178 1192
1179clean: 1193clean:
1180 release_sock(parent); 1194 release_sock(parent);
@@ -1198,6 +1212,11 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
1198 1212
1199 l2cap_chan_lock(chan); 1213 l2cap_chan_lock(chan);
1200 1214
1215 if (chan->chan_type == L2CAP_CHAN_CONN_FIX_A2MP) {
1216 l2cap_chan_unlock(chan);
1217 continue;
1218 }
1219
1201 if (conn->hcon->type == LE_LINK) { 1220 if (conn->hcon->type == LE_LINK) {
1202 if (smp_conn_security(conn, chan->sec_level)) 1221 if (smp_conn_security(conn, chan->sec_level))
1203 l2cap_chan_ready(chan); 1222 l2cap_chan_ready(chan);
@@ -1270,7 +1289,7 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)
1270 1289
1271 l2cap_chan_unlock(chan); 1290 l2cap_chan_unlock(chan);
1272 1291
1273 chan->ops->close(chan->data); 1292 chan->ops->close(chan);
1274 l2cap_chan_put(chan); 1293 l2cap_chan_put(chan);
1275 } 1294 }
1276 1295
@@ -1444,21 +1463,17 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
1444 goto done; 1463 goto done;
1445 } 1464 }
1446 1465
1447 lock_sock(sk); 1466 switch (chan->state) {
1448
1449 switch (sk->sk_state) {
1450 case BT_CONNECT: 1467 case BT_CONNECT:
1451 case BT_CONNECT2: 1468 case BT_CONNECT2:
1452 case BT_CONFIG: 1469 case BT_CONFIG:
1453 /* Already connecting */ 1470 /* Already connecting */
1454 err = 0; 1471 err = 0;
1455 release_sock(sk);
1456 goto done; 1472 goto done;
1457 1473
1458 case BT_CONNECTED: 1474 case BT_CONNECTED:
1459 /* Already connected */ 1475 /* Already connected */
1460 err = -EISCONN; 1476 err = -EISCONN;
1461 release_sock(sk);
1462 goto done; 1477 goto done;
1463 1478
1464 case BT_OPEN: 1479 case BT_OPEN:
@@ -1468,13 +1483,12 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
1468 1483
1469 default: 1484 default:
1470 err = -EBADFD; 1485 err = -EBADFD;
1471 release_sock(sk);
1472 goto done; 1486 goto done;
1473 } 1487 }
1474 1488
1475 /* Set destination address and psm */ 1489 /* Set destination address and psm */
1490 lock_sock(sk);
1476 bacpy(&bt_sk(sk)->dst, dst); 1491 bacpy(&bt_sk(sk)->dst, dst);
1477
1478 release_sock(sk); 1492 release_sock(sk);
1479 1493
1480 chan->psm = psm; 1494 chan->psm = psm;
@@ -1576,23 +1590,20 @@ int __l2cap_wait_ack(struct sock *sk)
1576static void l2cap_monitor_timeout(struct work_struct *work) 1590static void l2cap_monitor_timeout(struct work_struct *work)
1577{ 1591{
1578 struct l2cap_chan *chan = container_of(work, struct l2cap_chan, 1592 struct l2cap_chan *chan = container_of(work, struct l2cap_chan,
1579 monitor_timer.work); 1593 monitor_timer.work);
1580 1594
1581 BT_DBG("chan %p", chan); 1595 BT_DBG("chan %p", chan);
1582 1596
1583 l2cap_chan_lock(chan); 1597 l2cap_chan_lock(chan);
1584 1598
1585 if (chan->retry_count >= chan->remote_max_tx) { 1599 if (!chan->conn) {
1586 l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED);
1587 l2cap_chan_unlock(chan); 1600 l2cap_chan_unlock(chan);
1588 l2cap_chan_put(chan); 1601 l2cap_chan_put(chan);
1589 return; 1602 return;
1590 } 1603 }
1591 1604
1592 chan->retry_count++; 1605 l2cap_tx(chan, NULL, NULL, L2CAP_EV_MONITOR_TO);
1593 __set_monitor_timer(chan);
1594 1606
1595 l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_POLL);
1596 l2cap_chan_unlock(chan); 1607 l2cap_chan_unlock(chan);
1597 l2cap_chan_put(chan); 1608 l2cap_chan_put(chan);
1598} 1609}
@@ -1600,234 +1611,293 @@ static void l2cap_monitor_timeout(struct work_struct *work)
1600static void l2cap_retrans_timeout(struct work_struct *work) 1611static void l2cap_retrans_timeout(struct work_struct *work)
1601{ 1612{
1602 struct l2cap_chan *chan = container_of(work, struct l2cap_chan, 1613 struct l2cap_chan *chan = container_of(work, struct l2cap_chan,
1603 retrans_timer.work); 1614 retrans_timer.work);
1604 1615
1605 BT_DBG("chan %p", chan); 1616 BT_DBG("chan %p", chan);
1606 1617
1607 l2cap_chan_lock(chan); 1618 l2cap_chan_lock(chan);
1608 1619
1609 chan->retry_count = 1; 1620 if (!chan->conn) {
1610 __set_monitor_timer(chan); 1621 l2cap_chan_unlock(chan);
1611 1622 l2cap_chan_put(chan);
1612 set_bit(CONN_WAIT_F, &chan->conn_state); 1623 return;
1613 1624 }
1614 l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_POLL);
1615 1625
1626 l2cap_tx(chan, NULL, NULL, L2CAP_EV_RETRANS_TO);
1616 l2cap_chan_unlock(chan); 1627 l2cap_chan_unlock(chan);
1617 l2cap_chan_put(chan); 1628 l2cap_chan_put(chan);
1618} 1629}
1619 1630
1620static void l2cap_drop_acked_frames(struct l2cap_chan *chan) 1631static void l2cap_streaming_send(struct l2cap_chan *chan,
1632 struct sk_buff_head *skbs)
1621{ 1633{
1622 struct sk_buff *skb; 1634 struct sk_buff *skb;
1635 struct l2cap_ctrl *control;
1623 1636
1624 while ((skb = skb_peek(&chan->tx_q)) && 1637 BT_DBG("chan %p, skbs %p", chan, skbs);
1625 chan->unacked_frames) {
1626 if (bt_cb(skb)->control.txseq == chan->expected_ack_seq)
1627 break;
1628 1638
1629 skb = skb_dequeue(&chan->tx_q); 1639 skb_queue_splice_tail_init(skbs, &chan->tx_q);
1630 kfree_skb(skb);
1631 1640
1632 chan->unacked_frames--; 1641 while (!skb_queue_empty(&chan->tx_q)) {
1633 }
1634 1642
1635 if (!chan->unacked_frames) 1643 skb = skb_dequeue(&chan->tx_q);
1636 __clear_retrans_timer(chan);
1637}
1638 1644
1639static void l2cap_streaming_send(struct l2cap_chan *chan) 1645 bt_cb(skb)->control.retries = 1;
1640{ 1646 control = &bt_cb(skb)->control;
1641 struct sk_buff *skb;
1642 u32 control;
1643 u16 fcs;
1644 1647
1645 while ((skb = skb_dequeue(&chan->tx_q))) { 1648 control->reqseq = 0;
1646 control = __get_control(chan, skb->data + L2CAP_HDR_SIZE); 1649 control->txseq = chan->next_tx_seq;
1647 control |= __set_txseq(chan, chan->next_tx_seq); 1650
1648 control |= __set_ctrl_sar(chan, bt_cb(skb)->control.sar); 1651 __pack_control(chan, control, skb);
1649 __put_control(chan, control, skb->data + L2CAP_HDR_SIZE);
1650 1652
1651 if (chan->fcs == L2CAP_FCS_CRC16) { 1653 if (chan->fcs == L2CAP_FCS_CRC16) {
1652 fcs = crc16(0, (u8 *)skb->data, 1654 u16 fcs = crc16(0, (u8 *) skb->data, skb->len);
1653 skb->len - L2CAP_FCS_SIZE); 1655 put_unaligned_le16(fcs, skb_put(skb, L2CAP_FCS_SIZE));
1654 put_unaligned_le16(fcs,
1655 skb->data + skb->len - L2CAP_FCS_SIZE);
1656 } 1656 }
1657 1657
1658 l2cap_do_send(chan, skb); 1658 l2cap_do_send(chan, skb);
1659 1659
1660 BT_DBG("Sent txseq %d", (int)control->txseq);
1661
1660 chan->next_tx_seq = __next_seq(chan, chan->next_tx_seq); 1662 chan->next_tx_seq = __next_seq(chan, chan->next_tx_seq);
1663 chan->frames_sent++;
1661 } 1664 }
1662} 1665}
1663 1666
1664static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u16 tx_seq) 1667static int l2cap_ertm_send(struct l2cap_chan *chan)
1665{ 1668{
1666 struct sk_buff *skb, *tx_skb; 1669 struct sk_buff *skb, *tx_skb;
1667 u16 fcs; 1670 struct l2cap_ctrl *control;
1668 u32 control; 1671 int sent = 0;
1669 1672
1670 skb = skb_peek(&chan->tx_q); 1673 BT_DBG("chan %p", chan);
1671 if (!skb)
1672 return;
1673 1674
1674 while (bt_cb(skb)->control.txseq != tx_seq) { 1675 if (chan->state != BT_CONNECTED)
1675 if (skb_queue_is_last(&chan->tx_q, skb)) 1676 return -ENOTCONN;
1676 return;
1677 1677
1678 skb = skb_queue_next(&chan->tx_q, skb); 1678 if (test_bit(CONN_REMOTE_BUSY, &chan->conn_state))
1679 } 1679 return 0;
1680 1680
1681 if (bt_cb(skb)->control.retries == chan->remote_max_tx && 1681 while (chan->tx_send_head &&
1682 chan->remote_max_tx) { 1682 chan->unacked_frames < chan->remote_tx_win &&
1683 l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED); 1683 chan->tx_state == L2CAP_TX_STATE_XMIT) {
1684 return;
1685 }
1686 1684
1687 tx_skb = skb_clone(skb, GFP_ATOMIC); 1685 skb = chan->tx_send_head;
1688 bt_cb(skb)->control.retries++;
1689 1686
1690 control = __get_control(chan, tx_skb->data + L2CAP_HDR_SIZE); 1687 bt_cb(skb)->control.retries = 1;
1691 control &= __get_sar_mask(chan); 1688 control = &bt_cb(skb)->control;
1692 1689
1693 if (test_and_clear_bit(CONN_SEND_FBIT, &chan->conn_state)) 1690 if (test_and_clear_bit(CONN_SEND_FBIT, &chan->conn_state))
1694 control |= __set_ctrl_final(chan); 1691 control->final = 1;
1695 1692
1696 control |= __set_reqseq(chan, chan->buffer_seq); 1693 control->reqseq = chan->buffer_seq;
1697 control |= __set_txseq(chan, tx_seq); 1694 chan->last_acked_seq = chan->buffer_seq;
1695 control->txseq = chan->next_tx_seq;
1698 1696
1699 __put_control(chan, control, tx_skb->data + L2CAP_HDR_SIZE); 1697 __pack_control(chan, control, skb);
1700 1698
1701 if (chan->fcs == L2CAP_FCS_CRC16) { 1699 if (chan->fcs == L2CAP_FCS_CRC16) {
1702 fcs = crc16(0, (u8 *)tx_skb->data, 1700 u16 fcs = crc16(0, (u8 *) skb->data, skb->len);
1703 tx_skb->len - L2CAP_FCS_SIZE); 1701 put_unaligned_le16(fcs, skb_put(skb, L2CAP_FCS_SIZE));
1704 put_unaligned_le16(fcs, 1702 }
1705 tx_skb->data + tx_skb->len - L2CAP_FCS_SIZE); 1703
1704 /* Clone after data has been modified. Data is assumed to be
1705 read-only (for locking purposes) on cloned sk_buffs.
1706 */
1707 tx_skb = skb_clone(skb, GFP_KERNEL);
1708
1709 if (!tx_skb)
1710 break;
1711
1712 __set_retrans_timer(chan);
1713
1714 chan->next_tx_seq = __next_seq(chan, chan->next_tx_seq);
1715 chan->unacked_frames++;
1716 chan->frames_sent++;
1717 sent++;
1718
1719 if (skb_queue_is_last(&chan->tx_q, skb))
1720 chan->tx_send_head = NULL;
1721 else
1722 chan->tx_send_head = skb_queue_next(&chan->tx_q, skb);
1723
1724 l2cap_do_send(chan, tx_skb);
1725 BT_DBG("Sent txseq %d", (int)control->txseq);
1706 } 1726 }
1707 1727
1708 l2cap_do_send(chan, tx_skb); 1728 BT_DBG("Sent %d, %d unacked, %d in ERTM queue", sent,
1729 (int) chan->unacked_frames, skb_queue_len(&chan->tx_q));
1730
1731 return sent;
1709} 1732}
1710 1733
1711static int l2cap_ertm_send(struct l2cap_chan *chan) 1734static void l2cap_ertm_resend(struct l2cap_chan *chan)
1712{ 1735{
1713 struct sk_buff *skb, *tx_skb; 1736 struct l2cap_ctrl control;
1714 u16 fcs; 1737 struct sk_buff *skb;
1715 u32 control; 1738 struct sk_buff *tx_skb;
1716 int nsent = 0; 1739 u16 seq;
1717 1740
1718 if (chan->state != BT_CONNECTED) 1741 BT_DBG("chan %p", chan);
1719 return -ENOTCONN;
1720 1742
1721 if (test_bit(CONN_REMOTE_BUSY, &chan->conn_state)) 1743 if (test_bit(CONN_REMOTE_BUSY, &chan->conn_state))
1722 return 0; 1744 return;
1723 1745
1724 while ((skb = chan->tx_send_head) && (!l2cap_tx_window_full(chan))) { 1746 while (chan->retrans_list.head != L2CAP_SEQ_LIST_CLEAR) {
1747 seq = l2cap_seq_list_pop(&chan->retrans_list);
1725 1748
1726 if (bt_cb(skb)->control.retries == chan->remote_max_tx && 1749 skb = l2cap_ertm_seq_in_queue(&chan->tx_q, seq);
1727 chan->remote_max_tx) { 1750 if (!skb) {
1728 l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED); 1751 BT_DBG("Error: Can't retransmit seq %d, frame missing",
1729 break; 1752 seq);
1753 continue;
1730 } 1754 }
1731 1755
1732 tx_skb = skb_clone(skb, GFP_ATOMIC);
1733
1734 bt_cb(skb)->control.retries++; 1756 bt_cb(skb)->control.retries++;
1757 control = bt_cb(skb)->control;
1735 1758
1736 control = __get_control(chan, tx_skb->data + L2CAP_HDR_SIZE); 1759 if (chan->max_tx != 0 &&
1737 control &= __get_sar_mask(chan); 1760 bt_cb(skb)->control.retries > chan->max_tx) {
1761 BT_DBG("Retry limit exceeded (%d)", chan->max_tx);
1762 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
1763 l2cap_seq_list_clear(&chan->retrans_list);
1764 break;
1765 }
1738 1766
1767 control.reqseq = chan->buffer_seq;
1739 if (test_and_clear_bit(CONN_SEND_FBIT, &chan->conn_state)) 1768 if (test_and_clear_bit(CONN_SEND_FBIT, &chan->conn_state))
1740 control |= __set_ctrl_final(chan); 1769 control.final = 1;
1770 else
1771 control.final = 0;
1741 1772
1742 control |= __set_reqseq(chan, chan->buffer_seq); 1773 if (skb_cloned(skb)) {
1743 control |= __set_txseq(chan, chan->next_tx_seq); 1774 /* Cloned sk_buffs are read-only, so we need a
1744 control |= __set_ctrl_sar(chan, bt_cb(skb)->control.sar); 1775 * writeable copy
1776 */
1777 tx_skb = skb_copy(skb, GFP_ATOMIC);
1778 } else {
1779 tx_skb = skb_clone(skb, GFP_ATOMIC);
1780 }
1745 1781
1746 __put_control(chan, control, tx_skb->data + L2CAP_HDR_SIZE); 1782 if (!tx_skb) {
1783 l2cap_seq_list_clear(&chan->retrans_list);
1784 break;
1785 }
1786
1787 /* Update skb contents */
1788 if (test_bit(FLAG_EXT_CTRL, &chan->flags)) {
1789 put_unaligned_le32(__pack_extended_control(&control),
1790 tx_skb->data + L2CAP_HDR_SIZE);
1791 } else {
1792 put_unaligned_le16(__pack_enhanced_control(&control),
1793 tx_skb->data + L2CAP_HDR_SIZE);
1794 }
1747 1795
1748 if (chan->fcs == L2CAP_FCS_CRC16) { 1796 if (chan->fcs == L2CAP_FCS_CRC16) {
1749 fcs = crc16(0, (u8 *)skb->data, 1797 u16 fcs = crc16(0, (u8 *) tx_skb->data, tx_skb->len);
1750 tx_skb->len - L2CAP_FCS_SIZE); 1798 put_unaligned_le16(fcs, skb_put(tx_skb,
1751 put_unaligned_le16(fcs, skb->data + 1799 L2CAP_FCS_SIZE));
1752 tx_skb->len - L2CAP_FCS_SIZE);
1753 } 1800 }
1754 1801
1755 l2cap_do_send(chan, tx_skb); 1802 l2cap_do_send(chan, tx_skb);
1756 1803
1757 __set_retrans_timer(chan); 1804 BT_DBG("Resent txseq %d", control.txseq);
1758
1759 bt_cb(skb)->control.txseq = chan->next_tx_seq;
1760
1761 chan->next_tx_seq = __next_seq(chan, chan->next_tx_seq);
1762
1763 if (bt_cb(skb)->control.retries == 1) {
1764 chan->unacked_frames++;
1765
1766 if (!nsent++)
1767 __clear_ack_timer(chan);
1768 }
1769
1770 chan->frames_sent++;
1771 1805
1772 if (skb_queue_is_last(&chan->tx_q, skb)) 1806 chan->last_acked_seq = chan->buffer_seq;
1773 chan->tx_send_head = NULL;
1774 else
1775 chan->tx_send_head = skb_queue_next(&chan->tx_q, skb);
1776 } 1807 }
1777
1778 return nsent;
1779} 1808}
1780 1809
1781static int l2cap_retransmit_frames(struct l2cap_chan *chan) 1810static void l2cap_retransmit(struct l2cap_chan *chan,
1811 struct l2cap_ctrl *control)
1782{ 1812{
1783 int ret; 1813 BT_DBG("chan %p, control %p", chan, control);
1784
1785 if (!skb_queue_empty(&chan->tx_q))
1786 chan->tx_send_head = chan->tx_q.next;
1787 1814
1788 chan->next_tx_seq = chan->expected_ack_seq; 1815 l2cap_seq_list_append(&chan->retrans_list, control->reqseq);
1789 ret = l2cap_ertm_send(chan); 1816 l2cap_ertm_resend(chan);
1790 return ret;
1791} 1817}
1792 1818
1793static void __l2cap_send_ack(struct l2cap_chan *chan) 1819static void l2cap_retransmit_all(struct l2cap_chan *chan,
1820 struct l2cap_ctrl *control)
1794{ 1821{
1795 u32 control = 0; 1822 struct sk_buff *skb;
1796 1823
1797 control |= __set_reqseq(chan, chan->buffer_seq); 1824 BT_DBG("chan %p, control %p", chan, control);
1798 1825
1799 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) { 1826 if (control->poll)
1800 control |= __set_ctrl_super(chan, L2CAP_SUPER_RNR); 1827 set_bit(CONN_SEND_FBIT, &chan->conn_state);
1801 set_bit(CONN_RNR_SENT, &chan->conn_state);
1802 l2cap_send_sframe(chan, control);
1803 return;
1804 }
1805 1828
1806 if (l2cap_ertm_send(chan) > 0) 1829 l2cap_seq_list_clear(&chan->retrans_list);
1830
1831 if (test_bit(CONN_REMOTE_BUSY, &chan->conn_state))
1807 return; 1832 return;
1808 1833
1809 control |= __set_ctrl_super(chan, L2CAP_SUPER_RR); 1834 if (chan->unacked_frames) {
1810 l2cap_send_sframe(chan, control); 1835 skb_queue_walk(&chan->tx_q, skb) {
1836 if (bt_cb(skb)->control.txseq == control->reqseq ||
1837 skb == chan->tx_send_head)
1838 break;
1839 }
1840
1841 skb_queue_walk_from(&chan->tx_q, skb) {
1842 if (skb == chan->tx_send_head)
1843 break;
1844
1845 l2cap_seq_list_append(&chan->retrans_list,
1846 bt_cb(skb)->control.txseq);
1847 }
1848
1849 l2cap_ertm_resend(chan);
1850 }
1811} 1851}
1812 1852
1813static void l2cap_send_ack(struct l2cap_chan *chan) 1853static void l2cap_send_ack(struct l2cap_chan *chan)
1814{ 1854{
1815 __clear_ack_timer(chan); 1855 struct l2cap_ctrl control;
1816 __l2cap_send_ack(chan); 1856 u16 frames_to_ack = __seq_offset(chan, chan->buffer_seq,
1817} 1857 chan->last_acked_seq);
1858 int threshold;
1818 1859
1819static void l2cap_send_srejtail(struct l2cap_chan *chan) 1860 BT_DBG("chan %p last_acked_seq %d buffer_seq %d",
1820{ 1861 chan, chan->last_acked_seq, chan->buffer_seq);
1821 struct srej_list *tail;
1822 u32 control;
1823 1862
1824 control = __set_ctrl_super(chan, L2CAP_SUPER_SREJ); 1863 memset(&control, 0, sizeof(control));
1825 control |= __set_ctrl_final(chan); 1864 control.sframe = 1;
1826 1865
1827 tail = list_entry((&chan->srej_l)->prev, struct srej_list, list); 1866 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state) &&
1828 control |= __set_reqseq(chan, tail->tx_seq); 1867 chan->rx_state == L2CAP_RX_STATE_RECV) {
1868 __clear_ack_timer(chan);
1869 control.super = L2CAP_SUPER_RNR;
1870 control.reqseq = chan->buffer_seq;
1871 l2cap_send_sframe(chan, &control);
1872 } else {
1873 if (!test_bit(CONN_REMOTE_BUSY, &chan->conn_state)) {
1874 l2cap_ertm_send(chan);
1875 /* If any i-frames were sent, they included an ack */
1876 if (chan->buffer_seq == chan->last_acked_seq)
1877 frames_to_ack = 0;
1878 }
1879
1880 /* Ack now if the tx window is 3/4ths full.
1881 * Calculate without mul or div
1882 */
1883 threshold = chan->tx_win;
1884 threshold += threshold << 1;
1885 threshold >>= 2;
1886
1887 BT_DBG("frames_to_ack %d, threshold %d", (int)frames_to_ack,
1888 threshold);
1889
1890 if (frames_to_ack >= threshold) {
1891 __clear_ack_timer(chan);
1892 control.super = L2CAP_SUPER_RR;
1893 control.reqseq = chan->buffer_seq;
1894 l2cap_send_sframe(chan, &control);
1895 frames_to_ack = 0;
1896 }
1829 1897
1830 l2cap_send_sframe(chan, control); 1898 if (frames_to_ack)
1899 __set_ack_timer(chan);
1900 }
1831} 1901}
1832 1902
1833static inline int l2cap_skbuff_fromiovec(struct l2cap_chan *chan, 1903static inline int l2cap_skbuff_fromiovec(struct l2cap_chan *chan,
@@ -1956,10 +2026,7 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan,
1956 if (!conn) 2026 if (!conn)
1957 return ERR_PTR(-ENOTCONN); 2027 return ERR_PTR(-ENOTCONN);
1958 2028
1959 if (test_bit(FLAG_EXT_CTRL, &chan->flags)) 2029 hlen = __ertm_hdr_size(chan);
1960 hlen = L2CAP_EXT_HDR_SIZE;
1961 else
1962 hlen = L2CAP_ENH_HDR_SIZE;
1963 2030
1964 if (sdulen) 2031 if (sdulen)
1965 hlen += L2CAP_SDULEN_SIZE; 2032 hlen += L2CAP_SDULEN_SIZE;
@@ -1979,7 +2046,11 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan,
1979 lh->cid = cpu_to_le16(chan->dcid); 2046 lh->cid = cpu_to_le16(chan->dcid);
1980 lh->len = cpu_to_le16(len + (hlen - L2CAP_HDR_SIZE)); 2047 lh->len = cpu_to_le16(len + (hlen - L2CAP_HDR_SIZE));
1981 2048
1982 __put_control(chan, 0, skb_put(skb, __ctrl_size(chan))); 2049 /* Control header is populated later */
2050 if (test_bit(FLAG_EXT_CTRL, &chan->flags))
2051 put_unaligned_le32(0, skb_put(skb, L2CAP_EXT_CTRL_SIZE));
2052 else
2053 put_unaligned_le16(0, skb_put(skb, L2CAP_ENH_CTRL_SIZE));
1983 2054
1984 if (sdulen) 2055 if (sdulen)
1985 put_unaligned_le16(sdulen, skb_put(skb, L2CAP_SDULEN_SIZE)); 2056 put_unaligned_le16(sdulen, skb_put(skb, L2CAP_SDULEN_SIZE));
@@ -1990,9 +2061,7 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan,
1990 return ERR_PTR(err); 2061 return ERR_PTR(err);
1991 } 2062 }
1992 2063
1993 if (chan->fcs == L2CAP_FCS_CRC16) 2064 bt_cb(skb)->control.fcs = chan->fcs;
1994 put_unaligned_le16(0, skb_put(skb, L2CAP_FCS_SIZE));
1995
1996 bt_cb(skb)->control.retries = 0; 2065 bt_cb(skb)->control.retries = 0;
1997 return skb; 2066 return skb;
1998} 2067}
@@ -2004,7 +2073,6 @@ static int l2cap_segment_sdu(struct l2cap_chan *chan,
2004 struct sk_buff *skb; 2073 struct sk_buff *skb;
2005 u16 sdu_len; 2074 u16 sdu_len;
2006 size_t pdu_len; 2075 size_t pdu_len;
2007 int err = 0;
2008 u8 sar; 2076 u8 sar;
2009 2077
2010 BT_DBG("chan %p, msg %p, len %d", chan, msg, (int)len); 2078 BT_DBG("chan %p, msg %p, len %d", chan, msg, (int)len);
@@ -2020,7 +2088,10 @@ static int l2cap_segment_sdu(struct l2cap_chan *chan,
2020 pdu_len = min_t(size_t, pdu_len, L2CAP_BREDR_MAX_PAYLOAD); 2088 pdu_len = min_t(size_t, pdu_len, L2CAP_BREDR_MAX_PAYLOAD);
2021 2089
2022 /* Adjust for largest possible L2CAP overhead. */ 2090 /* Adjust for largest possible L2CAP overhead. */
2023 pdu_len -= L2CAP_EXT_HDR_SIZE + L2CAP_FCS_SIZE; 2091 if (chan->fcs)
2092 pdu_len -= L2CAP_FCS_SIZE;
2093
2094 pdu_len -= __ertm_hdr_size(chan);
2024 2095
2025 /* Remote device may have requested smaller PDUs */ 2096 /* Remote device may have requested smaller PDUs */
2026 pdu_len = min_t(size_t, pdu_len, chan->remote_mps); 2097 pdu_len = min_t(size_t, pdu_len, chan->remote_mps);
@@ -2060,7 +2131,7 @@ static int l2cap_segment_sdu(struct l2cap_chan *chan,
2060 } 2131 }
2061 } 2132 }
2062 2133
2063 return err; 2134 return 0;
2064} 2135}
2065 2136
2066int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len, 2137int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
@@ -2122,17 +2193,12 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
2122 if (err) 2193 if (err)
2123 break; 2194 break;
2124 2195
2125 if (chan->mode == L2CAP_MODE_ERTM && chan->tx_send_head == NULL)
2126 chan->tx_send_head = seg_queue.next;
2127 skb_queue_splice_tail_init(&seg_queue, &chan->tx_q);
2128
2129 if (chan->mode == L2CAP_MODE_ERTM) 2196 if (chan->mode == L2CAP_MODE_ERTM)
2130 err = l2cap_ertm_send(chan); 2197 l2cap_tx(chan, NULL, &seg_queue, L2CAP_EV_DATA_REQUEST);
2131 else 2198 else
2132 l2cap_streaming_send(chan); 2199 l2cap_streaming_send(chan, &seg_queue);
2133 2200
2134 if (err >= 0) 2201 err = len;
2135 err = len;
2136 2202
2137 /* If the skbs were not queued for sending, they'll still be in 2203 /* If the skbs were not queued for sending, they'll still be in
2138 * seg_queue and need to be purged. 2204 * seg_queue and need to be purged.
@@ -2148,6 +2214,296 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len,
2148 return err; 2214 return err;
2149} 2215}
2150 2216
2217static void l2cap_send_srej(struct l2cap_chan *chan, u16 txseq)
2218{
2219 struct l2cap_ctrl control;
2220 u16 seq;
2221
2222 BT_DBG("chan %p, txseq %d", chan, txseq);
2223
2224 memset(&control, 0, sizeof(control));
2225 control.sframe = 1;
2226 control.super = L2CAP_SUPER_SREJ;
2227
2228 for (seq = chan->expected_tx_seq; seq != txseq;
2229 seq = __next_seq(chan, seq)) {
2230 if (!l2cap_ertm_seq_in_queue(&chan->srej_q, seq)) {
2231 control.reqseq = seq;
2232 l2cap_send_sframe(chan, &control);
2233 l2cap_seq_list_append(&chan->srej_list, seq);
2234 }
2235 }
2236
2237 chan->expected_tx_seq = __next_seq(chan, txseq);
2238}
2239
2240static void l2cap_send_srej_tail(struct l2cap_chan *chan)
2241{
2242 struct l2cap_ctrl control;
2243
2244 BT_DBG("chan %p", chan);
2245
2246 if (chan->srej_list.tail == L2CAP_SEQ_LIST_CLEAR)
2247 return;
2248
2249 memset(&control, 0, sizeof(control));
2250 control.sframe = 1;
2251 control.super = L2CAP_SUPER_SREJ;
2252 control.reqseq = chan->srej_list.tail;
2253 l2cap_send_sframe(chan, &control);
2254}
2255
2256static void l2cap_send_srej_list(struct l2cap_chan *chan, u16 txseq)
2257{
2258 struct l2cap_ctrl control;
2259 u16 initial_head;
2260 u16 seq;
2261
2262 BT_DBG("chan %p, txseq %d", chan, txseq);
2263
2264 memset(&control, 0, sizeof(control));
2265 control.sframe = 1;
2266 control.super = L2CAP_SUPER_SREJ;
2267
2268 /* Capture initial list head to allow only one pass through the list. */
2269 initial_head = chan->srej_list.head;
2270
2271 do {
2272 seq = l2cap_seq_list_pop(&chan->srej_list);
2273 if (seq == txseq || seq == L2CAP_SEQ_LIST_CLEAR)
2274 break;
2275
2276 control.reqseq = seq;
2277 l2cap_send_sframe(chan, &control);
2278 l2cap_seq_list_append(&chan->srej_list, seq);
2279 } while (chan->srej_list.head != initial_head);
2280}
2281
2282static void l2cap_process_reqseq(struct l2cap_chan *chan, u16 reqseq)
2283{
2284 struct sk_buff *acked_skb;
2285 u16 ackseq;
2286
2287 BT_DBG("chan %p, reqseq %d", chan, reqseq);
2288
2289 if (chan->unacked_frames == 0 || reqseq == chan->expected_ack_seq)
2290 return;
2291
2292 BT_DBG("expected_ack_seq %d, unacked_frames %d",
2293 chan->expected_ack_seq, chan->unacked_frames);
2294
2295 for (ackseq = chan->expected_ack_seq; ackseq != reqseq;
2296 ackseq = __next_seq(chan, ackseq)) {
2297
2298 acked_skb = l2cap_ertm_seq_in_queue(&chan->tx_q, ackseq);
2299 if (acked_skb) {
2300 skb_unlink(acked_skb, &chan->tx_q);
2301 kfree_skb(acked_skb);
2302 chan->unacked_frames--;
2303 }
2304 }
2305
2306 chan->expected_ack_seq = reqseq;
2307
2308 if (chan->unacked_frames == 0)
2309 __clear_retrans_timer(chan);
2310
2311 BT_DBG("unacked_frames %d", (int) chan->unacked_frames);
2312}
2313
2314static void l2cap_abort_rx_srej_sent(struct l2cap_chan *chan)
2315{
2316 BT_DBG("chan %p", chan);
2317
2318 chan->expected_tx_seq = chan->buffer_seq;
2319 l2cap_seq_list_clear(&chan->srej_list);
2320 skb_queue_purge(&chan->srej_q);
2321 chan->rx_state = L2CAP_RX_STATE_RECV;
2322}
2323
2324static void l2cap_tx_state_xmit(struct l2cap_chan *chan,
2325 struct l2cap_ctrl *control,
2326 struct sk_buff_head *skbs, u8 event)
2327{
2328 BT_DBG("chan %p, control %p, skbs %p, event %d", chan, control, skbs,
2329 event);
2330
2331 switch (event) {
2332 case L2CAP_EV_DATA_REQUEST:
2333 if (chan->tx_send_head == NULL)
2334 chan->tx_send_head = skb_peek(skbs);
2335
2336 skb_queue_splice_tail_init(skbs, &chan->tx_q);
2337 l2cap_ertm_send(chan);
2338 break;
2339 case L2CAP_EV_LOCAL_BUSY_DETECTED:
2340 BT_DBG("Enter LOCAL_BUSY");
2341 set_bit(CONN_LOCAL_BUSY, &chan->conn_state);
2342
2343 if (chan->rx_state == L2CAP_RX_STATE_SREJ_SENT) {
2344 /* The SREJ_SENT state must be aborted if we are to
2345 * enter the LOCAL_BUSY state.
2346 */
2347 l2cap_abort_rx_srej_sent(chan);
2348 }
2349
2350 l2cap_send_ack(chan);
2351
2352 break;
2353 case L2CAP_EV_LOCAL_BUSY_CLEAR:
2354 BT_DBG("Exit LOCAL_BUSY");
2355 clear_bit(CONN_LOCAL_BUSY, &chan->conn_state);
2356
2357 if (test_bit(CONN_RNR_SENT, &chan->conn_state)) {
2358 struct l2cap_ctrl local_control;
2359
2360 memset(&local_control, 0, sizeof(local_control));
2361 local_control.sframe = 1;
2362 local_control.super = L2CAP_SUPER_RR;
2363 local_control.poll = 1;
2364 local_control.reqseq = chan->buffer_seq;
2365 l2cap_send_sframe(chan, &local_control);
2366
2367 chan->retry_count = 1;
2368 __set_monitor_timer(chan);
2369 chan->tx_state = L2CAP_TX_STATE_WAIT_F;
2370 }
2371 break;
2372 case L2CAP_EV_RECV_REQSEQ_AND_FBIT:
2373 l2cap_process_reqseq(chan, control->reqseq);
2374 break;
2375 case L2CAP_EV_EXPLICIT_POLL:
2376 l2cap_send_rr_or_rnr(chan, 1);
2377 chan->retry_count = 1;
2378 __set_monitor_timer(chan);
2379 __clear_ack_timer(chan);
2380 chan->tx_state = L2CAP_TX_STATE_WAIT_F;
2381 break;
2382 case L2CAP_EV_RETRANS_TO:
2383 l2cap_send_rr_or_rnr(chan, 1);
2384 chan->retry_count = 1;
2385 __set_monitor_timer(chan);
2386 chan->tx_state = L2CAP_TX_STATE_WAIT_F;
2387 break;
2388 case L2CAP_EV_RECV_FBIT:
2389 /* Nothing to process */
2390 break;
2391 default:
2392 break;
2393 }
2394}
2395
2396static void l2cap_tx_state_wait_f(struct l2cap_chan *chan,
2397 struct l2cap_ctrl *control,
2398 struct sk_buff_head *skbs, u8 event)
2399{
2400 BT_DBG("chan %p, control %p, skbs %p, event %d", chan, control, skbs,
2401 event);
2402
2403 switch (event) {
2404 case L2CAP_EV_DATA_REQUEST:
2405 if (chan->tx_send_head == NULL)
2406 chan->tx_send_head = skb_peek(skbs);
2407 /* Queue data, but don't send. */
2408 skb_queue_splice_tail_init(skbs, &chan->tx_q);
2409 break;
2410 case L2CAP_EV_LOCAL_BUSY_DETECTED:
2411 BT_DBG("Enter LOCAL_BUSY");
2412 set_bit(CONN_LOCAL_BUSY, &chan->conn_state);
2413
2414 if (chan->rx_state == L2CAP_RX_STATE_SREJ_SENT) {
2415 /* The SREJ_SENT state must be aborted if we are to
2416 * enter the LOCAL_BUSY state.
2417 */
2418 l2cap_abort_rx_srej_sent(chan);
2419 }
2420
2421 l2cap_send_ack(chan);
2422
2423 break;
2424 case L2CAP_EV_LOCAL_BUSY_CLEAR:
2425 BT_DBG("Exit LOCAL_BUSY");
2426 clear_bit(CONN_LOCAL_BUSY, &chan->conn_state);
2427
2428 if (test_bit(CONN_RNR_SENT, &chan->conn_state)) {
2429 struct l2cap_ctrl local_control;
2430 memset(&local_control, 0, sizeof(local_control));
2431 local_control.sframe = 1;
2432 local_control.super = L2CAP_SUPER_RR;
2433 local_control.poll = 1;
2434 local_control.reqseq = chan->buffer_seq;
2435 l2cap_send_sframe(chan, &local_control);
2436
2437 chan->retry_count = 1;
2438 __set_monitor_timer(chan);
2439 chan->tx_state = L2CAP_TX_STATE_WAIT_F;
2440 }
2441 break;
2442 case L2CAP_EV_RECV_REQSEQ_AND_FBIT:
2443 l2cap_process_reqseq(chan, control->reqseq);
2444
2445 /* Fall through */
2446
2447 case L2CAP_EV_RECV_FBIT:
2448 if (control && control->final) {
2449 __clear_monitor_timer(chan);
2450 if (chan->unacked_frames > 0)
2451 __set_retrans_timer(chan);
2452 chan->retry_count = 0;
2453 chan->tx_state = L2CAP_TX_STATE_XMIT;
2454 BT_DBG("recv fbit tx_state 0x2.2%x", chan->tx_state);
2455 }
2456 break;
2457 case L2CAP_EV_EXPLICIT_POLL:
2458 /* Ignore */
2459 break;
2460 case L2CAP_EV_MONITOR_TO:
2461 if (chan->max_tx == 0 || chan->retry_count < chan->max_tx) {
2462 l2cap_send_rr_or_rnr(chan, 1);
2463 __set_monitor_timer(chan);
2464 chan->retry_count++;
2465 } else {
2466 l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED);
2467 }
2468 break;
2469 default:
2470 break;
2471 }
2472}
2473
2474static void l2cap_tx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
2475 struct sk_buff_head *skbs, u8 event)
2476{
2477 BT_DBG("chan %p, control %p, skbs %p, event %d, state %d",
2478 chan, control, skbs, event, chan->tx_state);
2479
2480 switch (chan->tx_state) {
2481 case L2CAP_TX_STATE_XMIT:
2482 l2cap_tx_state_xmit(chan, control, skbs, event);
2483 break;
2484 case L2CAP_TX_STATE_WAIT_F:
2485 l2cap_tx_state_wait_f(chan, control, skbs, event);
2486 break;
2487 default:
2488 /* Ignore event */
2489 break;
2490 }
2491}
2492
2493static void l2cap_pass_to_tx(struct l2cap_chan *chan,
2494 struct l2cap_ctrl *control)
2495{
2496 BT_DBG("chan %p, control %p", chan, control);
2497 l2cap_tx(chan, control, NULL, L2CAP_EV_RECV_REQSEQ_AND_FBIT);
2498}
2499
2500static void l2cap_pass_to_tx_fbit(struct l2cap_chan *chan,
2501 struct l2cap_ctrl *control)
2502{
2503 BT_DBG("chan %p, control %p", chan, control);
2504 l2cap_tx(chan, control, NULL, L2CAP_EV_RECV_FBIT);
2505}
2506
2151/* Copy frame to all raw sockets on that connection */ 2507/* Copy frame to all raw sockets on that connection */
2152static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb) 2508static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
2153{ 2509{
@@ -2170,7 +2526,7 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
2170 if (!nskb) 2526 if (!nskb)
2171 continue; 2527 continue;
2172 2528
2173 if (chan->ops->recv(chan->data, nskb)) 2529 if (chan->ops->recv(chan, nskb))
2174 kfree_skb(nskb); 2530 kfree_skb(nskb);
2175 } 2531 }
2176 2532
@@ -2200,9 +2556,9 @@ static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn,
2200 lh->len = cpu_to_le16(L2CAP_CMD_HDR_SIZE + dlen); 2556 lh->len = cpu_to_le16(L2CAP_CMD_HDR_SIZE + dlen);
2201 2557
2202 if (conn->hcon->type == LE_LINK) 2558 if (conn->hcon->type == LE_LINK)
2203 lh->cid = cpu_to_le16(L2CAP_CID_LE_SIGNALING); 2559 lh->cid = __constant_cpu_to_le16(L2CAP_CID_LE_SIGNALING);
2204 else 2560 else
2205 lh->cid = cpu_to_le16(L2CAP_CID_SIGNALING); 2561 lh->cid = __constant_cpu_to_le16(L2CAP_CID_SIGNALING);
2206 2562
2207 cmd = (struct l2cap_cmd_hdr *) skb_put(skb, L2CAP_CMD_HDR_SIZE); 2563 cmd = (struct l2cap_cmd_hdr *) skb_put(skb, L2CAP_CMD_HDR_SIZE);
2208 cmd->code = code; 2564 cmd->code = code;
@@ -2314,8 +2670,8 @@ static void l2cap_add_opt_efs(void **ptr, struct l2cap_chan *chan)
2314 efs.stype = chan->local_stype; 2670 efs.stype = chan->local_stype;
2315 efs.msdu = cpu_to_le16(chan->local_msdu); 2671 efs.msdu = cpu_to_le16(chan->local_msdu);
2316 efs.sdu_itime = cpu_to_le32(chan->local_sdu_itime); 2672 efs.sdu_itime = cpu_to_le32(chan->local_sdu_itime);
2317 efs.acc_lat = cpu_to_le32(L2CAP_DEFAULT_ACC_LAT); 2673 efs.acc_lat = __constant_cpu_to_le32(L2CAP_DEFAULT_ACC_LAT);
2318 efs.flush_to = cpu_to_le32(L2CAP_DEFAULT_FLUSH_TO); 2674 efs.flush_to = __constant_cpu_to_le32(L2CAP_DEFAULT_FLUSH_TO);
2319 break; 2675 break;
2320 2676
2321 case L2CAP_MODE_STREAMING: 2677 case L2CAP_MODE_STREAMING:
@@ -2338,20 +2694,24 @@ static void l2cap_add_opt_efs(void **ptr, struct l2cap_chan *chan)
2338static void l2cap_ack_timeout(struct work_struct *work) 2694static void l2cap_ack_timeout(struct work_struct *work)
2339{ 2695{
2340 struct l2cap_chan *chan = container_of(work, struct l2cap_chan, 2696 struct l2cap_chan *chan = container_of(work, struct l2cap_chan,
2341 ack_timer.work); 2697 ack_timer.work);
2698 u16 frames_to_ack;
2342 2699
2343 BT_DBG("chan %p", chan); 2700 BT_DBG("chan %p", chan);
2344 2701
2345 l2cap_chan_lock(chan); 2702 l2cap_chan_lock(chan);
2346 2703
2347 __l2cap_send_ack(chan); 2704 frames_to_ack = __seq_offset(chan, chan->buffer_seq,
2705 chan->last_acked_seq);
2348 2706
2349 l2cap_chan_unlock(chan); 2707 if (frames_to_ack)
2708 l2cap_send_rr_or_rnr(chan, 0);
2350 2709
2710 l2cap_chan_unlock(chan);
2351 l2cap_chan_put(chan); 2711 l2cap_chan_put(chan);
2352} 2712}
2353 2713
2354static inline int l2cap_ertm_init(struct l2cap_chan *chan) 2714int l2cap_ertm_init(struct l2cap_chan *chan)
2355{ 2715{
2356 int err; 2716 int err;
2357 2717
@@ -2360,7 +2720,6 @@ static inline int l2cap_ertm_init(struct l2cap_chan *chan)
2360 chan->expected_ack_seq = 0; 2720 chan->expected_ack_seq = 0;
2361 chan->unacked_frames = 0; 2721 chan->unacked_frames = 0;
2362 chan->buffer_seq = 0; 2722 chan->buffer_seq = 0;
2363 chan->num_acked = 0;
2364 chan->frames_sent = 0; 2723 chan->frames_sent = 0;
2365 chan->last_acked_seq = 0; 2724 chan->last_acked_seq = 0;
2366 chan->sdu = NULL; 2725 chan->sdu = NULL;
@@ -2381,12 +2740,15 @@ static inline int l2cap_ertm_init(struct l2cap_chan *chan)
2381 2740
2382 skb_queue_head_init(&chan->srej_q); 2741 skb_queue_head_init(&chan->srej_q);
2383 2742
2384 INIT_LIST_HEAD(&chan->srej_l);
2385 err = l2cap_seq_list_init(&chan->srej_list, chan->tx_win); 2743 err = l2cap_seq_list_init(&chan->srej_list, chan->tx_win);
2386 if (err < 0) 2744 if (err < 0)
2387 return err; 2745 return err;
2388 2746
2389 return l2cap_seq_list_init(&chan->retrans_list, chan->remote_tx_win); 2747 err = l2cap_seq_list_init(&chan->retrans_list, chan->remote_tx_win);
2748 if (err < 0)
2749 l2cap_seq_list_free(&chan->srej_list);
2750
2751 return err;
2390} 2752}
2391 2753
2392static inline __u8 l2cap_select_mode(__u8 mode, __u16 remote_feat_mask) 2754static inline __u8 l2cap_select_mode(__u8 mode, __u16 remote_feat_mask)
@@ -2512,6 +2874,7 @@ done:
2512 break; 2874 break;
2513 2875
2514 case L2CAP_MODE_STREAMING: 2876 case L2CAP_MODE_STREAMING:
2877 l2cap_txwin_setup(chan);
2515 rfc.mode = L2CAP_MODE_STREAMING; 2878 rfc.mode = L2CAP_MODE_STREAMING;
2516 rfc.txwin_size = 0; 2879 rfc.txwin_size = 0;
2517 rfc.max_transmit = 0; 2880 rfc.max_transmit = 0;
@@ -2542,7 +2905,7 @@ done:
2542 } 2905 }
2543 2906
2544 req->dcid = cpu_to_le16(chan->dcid); 2907 req->dcid = cpu_to_le16(chan->dcid);
2545 req->flags = cpu_to_le16(0); 2908 req->flags = __constant_cpu_to_le16(0);
2546 2909
2547 return ptr - data; 2910 return ptr - data;
2548} 2911}
@@ -2762,7 +3125,7 @@ done:
2762 } 3125 }
2763 rsp->scid = cpu_to_le16(chan->dcid); 3126 rsp->scid = cpu_to_le16(chan->dcid);
2764 rsp->result = cpu_to_le16(result); 3127 rsp->result = cpu_to_le16(result);
2765 rsp->flags = cpu_to_le16(0x0000); 3128 rsp->flags = __constant_cpu_to_le16(0);
2766 3129
2767 return ptr - data; 3130 return ptr - data;
2768} 3131}
@@ -2861,7 +3224,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
2861 } 3224 }
2862 3225
2863 req->dcid = cpu_to_le16(chan->dcid); 3226 req->dcid = cpu_to_le16(chan->dcid);
2864 req->flags = cpu_to_le16(0x0000); 3227 req->flags = __constant_cpu_to_le16(0);
2865 3228
2866 return ptr - data; 3229 return ptr - data;
2867} 3230}
@@ -2888,8 +3251,8 @@ void __l2cap_connect_rsp_defer(struct l2cap_chan *chan)
2888 3251
2889 rsp.scid = cpu_to_le16(chan->dcid); 3252 rsp.scid = cpu_to_le16(chan->dcid);
2890 rsp.dcid = cpu_to_le16(chan->scid); 3253 rsp.dcid = cpu_to_le16(chan->scid);
2891 rsp.result = cpu_to_le16(L2CAP_CR_SUCCESS); 3254 rsp.result = __constant_cpu_to_le16(L2CAP_CR_SUCCESS);
2892 rsp.status = cpu_to_le16(L2CAP_CS_NO_INFO); 3255 rsp.status = __constant_cpu_to_le16(L2CAP_CS_NO_INFO);
2893 l2cap_send_cmd(conn, chan->ident, 3256 l2cap_send_cmd(conn, chan->ident,
2894 L2CAP_CONN_RSP, sizeof(rsp), &rsp); 3257 L2CAP_CONN_RSP, sizeof(rsp), &rsp);
2895 3258
@@ -2927,8 +3290,8 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
2927 * did not send an RFC option. 3290 * did not send an RFC option.
2928 */ 3291 */
2929 rfc.mode = chan->mode; 3292 rfc.mode = chan->mode;
2930 rfc.retrans_timeout = cpu_to_le16(L2CAP_DEFAULT_RETRANS_TO); 3293 rfc.retrans_timeout = __constant_cpu_to_le16(L2CAP_DEFAULT_RETRANS_TO);
2931 rfc.monitor_timeout = cpu_to_le16(L2CAP_DEFAULT_MONITOR_TO); 3294 rfc.monitor_timeout = __constant_cpu_to_le16(L2CAP_DEFAULT_MONITOR_TO);
2932 rfc.max_pdu_size = cpu_to_le16(chan->imtu); 3295 rfc.max_pdu_size = cpu_to_le16(chan->imtu);
2933 3296
2934 BT_ERR("Expected RFC option was not found, using defaults"); 3297 BT_ERR("Expected RFC option was not found, using defaults");
@@ -2991,7 +3354,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
2991 lock_sock(parent); 3354 lock_sock(parent);
2992 3355
2993 /* Check if the ACL is secure enough (if not SDP) */ 3356 /* Check if the ACL is secure enough (if not SDP) */
2994 if (psm != cpu_to_le16(0x0001) && 3357 if (psm != __constant_cpu_to_le16(L2CAP_PSM_SDP) &&
2995 !hci_conn_check_link_mode(conn->hcon)) { 3358 !hci_conn_check_link_mode(conn->hcon)) {
2996 conn->disc_reason = HCI_ERROR_AUTH_FAILURE; 3359 conn->disc_reason = HCI_ERROR_AUTH_FAILURE;
2997 result = L2CAP_CR_SEC_BLOCK; 3360 result = L2CAP_CR_SEC_BLOCK;
@@ -3000,25 +3363,16 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
3000 3363
3001 result = L2CAP_CR_NO_MEM; 3364 result = L2CAP_CR_NO_MEM;
3002 3365
3003 /* Check for backlog size */ 3366 /* Check if we already have channel with that dcid */
3004 if (sk_acceptq_is_full(parent)) { 3367 if (__l2cap_get_chan_by_dcid(conn, scid))
3005 BT_DBG("backlog full %d", parent->sk_ack_backlog);
3006 goto response; 3368 goto response;
3007 }
3008 3369
3009 chan = pchan->ops->new_connection(pchan->data); 3370 chan = pchan->ops->new_connection(pchan);
3010 if (!chan) 3371 if (!chan)
3011 goto response; 3372 goto response;
3012 3373
3013 sk = chan->sk; 3374 sk = chan->sk;
3014 3375
3015 /* Check if we already have channel with that dcid */
3016 if (__l2cap_get_chan_by_dcid(conn, scid)) {
3017 sock_set_flag(sk, SOCK_ZAPPED);
3018 chan->ops->close(chan->data);
3019 goto response;
3020 }
3021
3022 hci_conn_hold(conn->hcon); 3376 hci_conn_hold(conn->hcon);
3023 3377
3024 bacpy(&bt_sk(sk)->src, conn->src); 3378 bacpy(&bt_sk(sk)->src, conn->src);
@@ -3072,7 +3426,7 @@ sendresp:
3072 3426
3073 if (result == L2CAP_CR_PEND && status == L2CAP_CS_NO_INFO) { 3427 if (result == L2CAP_CR_PEND && status == L2CAP_CS_NO_INFO) {
3074 struct l2cap_info_req info; 3428 struct l2cap_info_req info;
3075 info.type = cpu_to_le16(L2CAP_IT_FEAT_MASK); 3429 info.type = __constant_cpu_to_le16(L2CAP_IT_FEAT_MASK);
3076 3430
3077 conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_SENT; 3431 conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_SENT;
3078 conn->info_ident = l2cap_get_ident(conn); 3432 conn->info_ident = l2cap_get_ident(conn);
@@ -3194,7 +3548,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
3194 if (chan->state != BT_CONFIG && chan->state != BT_CONNECT2) { 3548 if (chan->state != BT_CONFIG && chan->state != BT_CONNECT2) {
3195 struct l2cap_cmd_rej_cid rej; 3549 struct l2cap_cmd_rej_cid rej;
3196 3550
3197 rej.reason = cpu_to_le16(L2CAP_REJ_INVALID_CID); 3551 rej.reason = __constant_cpu_to_le16(L2CAP_REJ_INVALID_CID);
3198 rej.scid = cpu_to_le16(chan->scid); 3552 rej.scid = cpu_to_le16(chan->scid);
3199 rej.dcid = cpu_to_le16(chan->dcid); 3553 rej.dcid = cpu_to_le16(chan->dcid);
3200 3554
@@ -3216,11 +3570,11 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
3216 memcpy(chan->conf_req + chan->conf_len, req->data, len); 3570 memcpy(chan->conf_req + chan->conf_len, req->data, len);
3217 chan->conf_len += len; 3571 chan->conf_len += len;
3218 3572
3219 if (flags & 0x0001) { 3573 if (flags & L2CAP_CONF_FLAG_CONTINUATION) {
3220 /* Incomplete config. Send empty response. */ 3574 /* Incomplete config. Send empty response. */
3221 l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP, 3575 l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
3222 l2cap_build_conf_rsp(chan, rsp, 3576 l2cap_build_conf_rsp(chan, rsp,
3223 L2CAP_CONF_SUCCESS, 0x0001), rsp); 3577 L2CAP_CONF_SUCCESS, flags), rsp);
3224 goto unlock; 3578 goto unlock;
3225 } 3579 }
3226 3580
@@ -3243,8 +3597,6 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
3243 if (test_bit(CONF_INPUT_DONE, &chan->conf_state)) { 3597 if (test_bit(CONF_INPUT_DONE, &chan->conf_state)) {
3244 set_default_fcs(chan); 3598 set_default_fcs(chan);
3245 3599
3246 l2cap_state_change(chan, BT_CONNECTED);
3247
3248 if (chan->mode == L2CAP_MODE_ERTM || 3600 if (chan->mode == L2CAP_MODE_ERTM ||
3249 chan->mode == L2CAP_MODE_STREAMING) 3601 chan->mode == L2CAP_MODE_STREAMING)
3250 err = l2cap_ertm_init(chan); 3602 err = l2cap_ertm_init(chan);
@@ -3276,7 +3628,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
3276 3628
3277 l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP, 3629 l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
3278 l2cap_build_conf_rsp(chan, rsp, 3630 l2cap_build_conf_rsp(chan, rsp,
3279 L2CAP_CONF_SUCCESS, 0x0000), rsp); 3631 L2CAP_CONF_SUCCESS, flags), rsp);
3280 } 3632 }
3281 3633
3282unlock: 3634unlock:
@@ -3367,7 +3719,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr
3367 goto done; 3719 goto done;
3368 } 3720 }
3369 3721
3370 if (flags & 0x01) 3722 if (flags & L2CAP_CONF_FLAG_CONTINUATION)
3371 goto done; 3723 goto done;
3372 3724
3373 set_bit(CONF_INPUT_DONE, &chan->conf_state); 3725 set_bit(CONF_INPUT_DONE, &chan->conf_state);
@@ -3375,7 +3727,6 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr
3375 if (test_bit(CONF_OUTPUT_DONE, &chan->conf_state)) { 3727 if (test_bit(CONF_OUTPUT_DONE, &chan->conf_state)) {
3376 set_default_fcs(chan); 3728 set_default_fcs(chan);
3377 3729
3378 l2cap_state_change(chan, BT_CONNECTED);
3379 if (chan->mode == L2CAP_MODE_ERTM || 3730 if (chan->mode == L2CAP_MODE_ERTM ||
3380 chan->mode == L2CAP_MODE_STREAMING) 3731 chan->mode == L2CAP_MODE_STREAMING)
3381 err = l2cap_ertm_init(chan); 3732 err = l2cap_ertm_init(chan);
@@ -3429,7 +3780,7 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn, struct l2cap_cmd
3429 3780
3430 l2cap_chan_unlock(chan); 3781 l2cap_chan_unlock(chan);
3431 3782
3432 chan->ops->close(chan->data); 3783 chan->ops->close(chan);
3433 l2cap_chan_put(chan); 3784 l2cap_chan_put(chan);
3434 3785
3435 mutex_unlock(&conn->chan_lock); 3786 mutex_unlock(&conn->chan_lock);
@@ -3463,7 +3814,7 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn, struct l2cap_cmd
3463 3814
3464 l2cap_chan_unlock(chan); 3815 l2cap_chan_unlock(chan);
3465 3816
3466 chan->ops->close(chan->data); 3817 chan->ops->close(chan);
3467 l2cap_chan_put(chan); 3818 l2cap_chan_put(chan);
3468 3819
3469 mutex_unlock(&conn->chan_lock); 3820 mutex_unlock(&conn->chan_lock);
@@ -3484,8 +3835,8 @@ static inline int l2cap_information_req(struct l2cap_conn *conn, struct l2cap_cm
3484 u8 buf[8]; 3835 u8 buf[8];
3485 u32 feat_mask = l2cap_feat_mask; 3836 u32 feat_mask = l2cap_feat_mask;
3486 struct l2cap_info_rsp *rsp = (struct l2cap_info_rsp *) buf; 3837 struct l2cap_info_rsp *rsp = (struct l2cap_info_rsp *) buf;
3487 rsp->type = cpu_to_le16(L2CAP_IT_FEAT_MASK); 3838 rsp->type = __constant_cpu_to_le16(L2CAP_IT_FEAT_MASK);
3488 rsp->result = cpu_to_le16(L2CAP_IR_SUCCESS); 3839 rsp->result = __constant_cpu_to_le16(L2CAP_IR_SUCCESS);
3489 if (!disable_ertm) 3840 if (!disable_ertm)
3490 feat_mask |= L2CAP_FEAT_ERTM | L2CAP_FEAT_STREAMING 3841 feat_mask |= L2CAP_FEAT_ERTM | L2CAP_FEAT_STREAMING
3491 | L2CAP_FEAT_FCS; 3842 | L2CAP_FEAT_FCS;
@@ -3505,15 +3856,15 @@ static inline int l2cap_information_req(struct l2cap_conn *conn, struct l2cap_cm
3505 else 3856 else
3506 l2cap_fixed_chan[0] &= ~L2CAP_FC_A2MP; 3857 l2cap_fixed_chan[0] &= ~L2CAP_FC_A2MP;
3507 3858
3508 rsp->type = cpu_to_le16(L2CAP_IT_FIXED_CHAN); 3859 rsp->type = __constant_cpu_to_le16(L2CAP_IT_FIXED_CHAN);
3509 rsp->result = cpu_to_le16(L2CAP_IR_SUCCESS); 3860 rsp->result = __constant_cpu_to_le16(L2CAP_IR_SUCCESS);
3510 memcpy(rsp->data, l2cap_fixed_chan, sizeof(l2cap_fixed_chan)); 3861 memcpy(rsp->data, l2cap_fixed_chan, sizeof(l2cap_fixed_chan));
3511 l2cap_send_cmd(conn, cmd->ident, 3862 l2cap_send_cmd(conn, cmd->ident,
3512 L2CAP_INFO_RSP, sizeof(buf), buf); 3863 L2CAP_INFO_RSP, sizeof(buf), buf);
3513 } else { 3864 } else {
3514 struct l2cap_info_rsp rsp; 3865 struct l2cap_info_rsp rsp;
3515 rsp.type = cpu_to_le16(type); 3866 rsp.type = cpu_to_le16(type);
3516 rsp.result = cpu_to_le16(L2CAP_IR_NOTSUPP); 3867 rsp.result = __constant_cpu_to_le16(L2CAP_IR_NOTSUPP);
3517 l2cap_send_cmd(conn, cmd->ident, 3868 l2cap_send_cmd(conn, cmd->ident,
3518 L2CAP_INFO_RSP, sizeof(rsp), &rsp); 3869 L2CAP_INFO_RSP, sizeof(rsp), &rsp);
3519 } 3870 }
@@ -3553,7 +3904,7 @@ static inline int l2cap_information_rsp(struct l2cap_conn *conn, struct l2cap_cm
3553 3904
3554 if (conn->feat_mask & L2CAP_FEAT_FIXED_CHAN) { 3905 if (conn->feat_mask & L2CAP_FEAT_FIXED_CHAN) {
3555 struct l2cap_info_req req; 3906 struct l2cap_info_req req;
3556 req.type = cpu_to_le16(L2CAP_IT_FIXED_CHAN); 3907 req.type = __constant_cpu_to_le16(L2CAP_IT_FIXED_CHAN);
3557 3908
3558 conn->info_ident = l2cap_get_ident(conn); 3909 conn->info_ident = l2cap_get_ident(conn);
3559 3910
@@ -3788,9 +4139,9 @@ static inline int l2cap_conn_param_update_req(struct l2cap_conn *conn,
3788 4139
3789 err = l2cap_check_conn_param(min, max, latency, to_multiplier); 4140 err = l2cap_check_conn_param(min, max, latency, to_multiplier);
3790 if (err) 4141 if (err)
3791 rsp.result = cpu_to_le16(L2CAP_CONN_PARAM_REJECTED); 4142 rsp.result = __constant_cpu_to_le16(L2CAP_CONN_PARAM_REJECTED);
3792 else 4143 else
3793 rsp.result = cpu_to_le16(L2CAP_CONN_PARAM_ACCEPTED); 4144 rsp.result = __constant_cpu_to_le16(L2CAP_CONN_PARAM_ACCEPTED);
3794 4145
3795 l2cap_send_cmd(conn, cmd->ident, L2CAP_CONN_PARAM_UPDATE_RSP, 4146 l2cap_send_cmd(conn, cmd->ident, L2CAP_CONN_PARAM_UPDATE_RSP,
3796 sizeof(rsp), &rsp); 4147 sizeof(rsp), &rsp);
@@ -3938,7 +4289,7 @@ static inline void l2cap_sig_channel(struct l2cap_conn *conn,
3938 BT_ERR("Wrong link type (%d)", err); 4289 BT_ERR("Wrong link type (%d)", err);
3939 4290
3940 /* FIXME: Map err to a valid reason */ 4291 /* FIXME: Map err to a valid reason */
3941 rej.reason = cpu_to_le16(L2CAP_REJ_NOT_UNDERSTOOD); 4292 rej.reason = __constant_cpu_to_le16(L2CAP_REJ_NOT_UNDERSTOOD);
3942 l2cap_send_cmd(conn, cmd.ident, L2CAP_COMMAND_REJ, sizeof(rej), &rej); 4293 l2cap_send_cmd(conn, cmd.ident, L2CAP_COMMAND_REJ, sizeof(rej), &rej);
3943 } 4294 }
3944 4295
@@ -3970,65 +4321,38 @@ static int l2cap_check_fcs(struct l2cap_chan *chan, struct sk_buff *skb)
3970 return 0; 4321 return 0;
3971} 4322}
3972 4323
3973static inline void l2cap_send_i_or_rr_or_rnr(struct l2cap_chan *chan) 4324static void l2cap_send_i_or_rr_or_rnr(struct l2cap_chan *chan)
3974{ 4325{
3975 u32 control = 0; 4326 struct l2cap_ctrl control;
3976 4327
3977 chan->frames_sent = 0; 4328 BT_DBG("chan %p", chan);
3978 4329
3979 control |= __set_reqseq(chan, chan->buffer_seq); 4330 memset(&control, 0, sizeof(control));
4331 control.sframe = 1;
4332 control.final = 1;
4333 control.reqseq = chan->buffer_seq;
4334 set_bit(CONN_SEND_FBIT, &chan->conn_state);
3980 4335
3981 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) { 4336 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) {
3982 control |= __set_ctrl_super(chan, L2CAP_SUPER_RNR); 4337 control.super = L2CAP_SUPER_RNR;
3983 l2cap_send_sframe(chan, control); 4338 l2cap_send_sframe(chan, &control);
3984 set_bit(CONN_RNR_SENT, &chan->conn_state);
3985 } 4339 }
3986 4340
3987 if (test_bit(CONN_REMOTE_BUSY, &chan->conn_state)) 4341 if (test_and_clear_bit(CONN_REMOTE_BUSY, &chan->conn_state) &&
3988 l2cap_retransmit_frames(chan); 4342 chan->unacked_frames > 0)
4343 __set_retrans_timer(chan);
3989 4344
4345 /* Send pending iframes */
3990 l2cap_ertm_send(chan); 4346 l2cap_ertm_send(chan);
3991 4347
3992 if (!test_bit(CONN_LOCAL_BUSY, &chan->conn_state) && 4348 if (!test_bit(CONN_LOCAL_BUSY, &chan->conn_state) &&
3993 chan->frames_sent == 0) { 4349 test_bit(CONN_SEND_FBIT, &chan->conn_state)) {
3994 control |= __set_ctrl_super(chan, L2CAP_SUPER_RR); 4350 /* F-bit wasn't sent in an s-frame or i-frame yet, so
3995 l2cap_send_sframe(chan, control); 4351 * send it now.
3996 } 4352 */
3997} 4353 control.super = L2CAP_SUPER_RR;
3998 4354 l2cap_send_sframe(chan, &control);
3999static int l2cap_add_to_srej_queue(struct l2cap_chan *chan, struct sk_buff *skb, u16 tx_seq, u8 sar)
4000{
4001 struct sk_buff *next_skb;
4002 int tx_seq_offset, next_tx_seq_offset;
4003
4004 bt_cb(skb)->control.txseq = tx_seq;
4005 bt_cb(skb)->control.sar = sar;
4006
4007 next_skb = skb_peek(&chan->srej_q);
4008
4009 tx_seq_offset = __seq_offset(chan, tx_seq, chan->buffer_seq);
4010
4011 while (next_skb) {
4012 if (bt_cb(next_skb)->control.txseq == tx_seq)
4013 return -EINVAL;
4014
4015 next_tx_seq_offset = __seq_offset(chan,
4016 bt_cb(next_skb)->control.txseq, chan->buffer_seq);
4017
4018 if (next_tx_seq_offset > tx_seq_offset) {
4019 __skb_queue_before(&chan->srej_q, next_skb, skb);
4020 return 0;
4021 }
4022
4023 if (skb_queue_is_last(&chan->srej_q, next_skb))
4024 next_skb = NULL;
4025 else
4026 next_skb = skb_queue_next(&chan->srej_q, next_skb);
4027 } 4355 }
4028
4029 __skb_queue_tail(&chan->srej_q, skb);
4030
4031 return 0;
4032} 4356}
4033 4357
4034static void append_skb_frag(struct sk_buff *skb, 4358static void append_skb_frag(struct sk_buff *skb,
@@ -4050,16 +4374,17 @@ static void append_skb_frag(struct sk_buff *skb,
4050 skb->truesize += new_frag->truesize; 4374 skb->truesize += new_frag->truesize;
4051} 4375}
4052 4376
4053static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb, u32 control) 4377static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb,
4378 struct l2cap_ctrl *control)
4054{ 4379{
4055 int err = -EINVAL; 4380 int err = -EINVAL;
4056 4381
4057 switch (__get_ctrl_sar(chan, control)) { 4382 switch (control->sar) {
4058 case L2CAP_SAR_UNSEGMENTED: 4383 case L2CAP_SAR_UNSEGMENTED:
4059 if (chan->sdu) 4384 if (chan->sdu)
4060 break; 4385 break;
4061 4386
4062 err = chan->ops->recv(chan->data, skb); 4387 err = chan->ops->recv(chan, skb);
4063 break; 4388 break;
4064 4389
4065 case L2CAP_SAR_START: 4390 case L2CAP_SAR_START:
@@ -4109,7 +4434,7 @@ static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb, u3
4109 if (chan->sdu->len != chan->sdu_len) 4434 if (chan->sdu->len != chan->sdu_len)
4110 break; 4435 break;
4111 4436
4112 err = chan->ops->recv(chan->data, chan->sdu); 4437 err = chan->ops->recv(chan, chan->sdu);
4113 4438
4114 if (!err) { 4439 if (!err) {
4115 /* Reassembly complete */ 4440 /* Reassembly complete */
@@ -4131,448 +4456,609 @@ static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb, u3
4131 return err; 4456 return err;
4132} 4457}
4133 4458
4134static void l2cap_ertm_enter_local_busy(struct l2cap_chan *chan) 4459void l2cap_chan_busy(struct l2cap_chan *chan, int busy)
4135{ 4460{
4136 BT_DBG("chan %p, Enter local busy", chan); 4461 u8 event;
4137 4462
4138 set_bit(CONN_LOCAL_BUSY, &chan->conn_state); 4463 if (chan->mode != L2CAP_MODE_ERTM)
4139 l2cap_seq_list_clear(&chan->srej_list); 4464 return;
4140 4465
4141 __set_ack_timer(chan); 4466 event = busy ? L2CAP_EV_LOCAL_BUSY_DETECTED : L2CAP_EV_LOCAL_BUSY_CLEAR;
4467 l2cap_tx(chan, NULL, NULL, event);
4142} 4468}
4143 4469
4144static void l2cap_ertm_exit_local_busy(struct l2cap_chan *chan) 4470static int l2cap_rx_queued_iframes(struct l2cap_chan *chan)
4145{ 4471{
4146 u32 control; 4472 int err = 0;
4147 4473 /* Pass sequential frames to l2cap_reassemble_sdu()
4148 if (!test_bit(CONN_RNR_SENT, &chan->conn_state)) 4474 * until a gap is encountered.
4149 goto done; 4475 */
4150 4476
4151 control = __set_reqseq(chan, chan->buffer_seq); 4477 BT_DBG("chan %p", chan);
4152 control |= __set_ctrl_poll(chan);
4153 control |= __set_ctrl_super(chan, L2CAP_SUPER_RR);
4154 l2cap_send_sframe(chan, control);
4155 chan->retry_count = 1;
4156 4478
4157 __clear_retrans_timer(chan); 4479 while (!test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) {
4158 __set_monitor_timer(chan); 4480 struct sk_buff *skb;
4481 BT_DBG("Searching for skb with txseq %d (queue len %d)",
4482 chan->buffer_seq, skb_queue_len(&chan->srej_q));
4159 4483
4160 set_bit(CONN_WAIT_F, &chan->conn_state); 4484 skb = l2cap_ertm_seq_in_queue(&chan->srej_q, chan->buffer_seq);
4161 4485
4162done: 4486 if (!skb)
4163 clear_bit(CONN_LOCAL_BUSY, &chan->conn_state); 4487 break;
4164 clear_bit(CONN_RNR_SENT, &chan->conn_state);
4165 4488
4166 BT_DBG("chan %p, Exit local busy", chan); 4489 skb_unlink(skb, &chan->srej_q);
4167} 4490 chan->buffer_seq = __next_seq(chan, chan->buffer_seq);
4491 err = l2cap_reassemble_sdu(chan, skb, &bt_cb(skb)->control);
4492 if (err)
4493 break;
4494 }
4168 4495
4169void l2cap_chan_busy(struct l2cap_chan *chan, int busy) 4496 if (skb_queue_empty(&chan->srej_q)) {
4170{ 4497 chan->rx_state = L2CAP_RX_STATE_RECV;
4171 if (chan->mode == L2CAP_MODE_ERTM) { 4498 l2cap_send_ack(chan);
4172 if (busy)
4173 l2cap_ertm_enter_local_busy(chan);
4174 else
4175 l2cap_ertm_exit_local_busy(chan);
4176 } 4499 }
4500
4501 return err;
4177} 4502}
4178 4503
4179static void l2cap_check_srej_gap(struct l2cap_chan *chan, u16 tx_seq) 4504static void l2cap_handle_srej(struct l2cap_chan *chan,
4505 struct l2cap_ctrl *control)
4180{ 4506{
4181 struct sk_buff *skb; 4507 struct sk_buff *skb;
4182 u32 control;
4183 4508
4184 while ((skb = skb_peek(&chan->srej_q)) && 4509 BT_DBG("chan %p, control %p", chan, control);
4185 !test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) {
4186 int err;
4187 4510
4188 if (bt_cb(skb)->control.txseq != tx_seq) 4511 if (control->reqseq == chan->next_tx_seq) {
4189 break; 4512 BT_DBG("Invalid reqseq %d, disconnecting", control->reqseq);
4513 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
4514 return;
4515 }
4190 4516
4191 skb = skb_dequeue(&chan->srej_q); 4517 skb = l2cap_ertm_seq_in_queue(&chan->tx_q, control->reqseq);
4192 control = __set_ctrl_sar(chan, bt_cb(skb)->control.sar);
4193 err = l2cap_reassemble_sdu(chan, skb, control);
4194 4518
4195 if (err < 0) { 4519 if (skb == NULL) {
4196 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); 4520 BT_DBG("Seq %d not available for retransmission",
4197 break; 4521 control->reqseq);
4198 } 4522 return;
4523 }
4199 4524
4200 chan->buffer_seq_srej = __next_seq(chan, chan->buffer_seq_srej); 4525 if (chan->max_tx != 0 && bt_cb(skb)->control.retries >= chan->max_tx) {
4201 tx_seq = __next_seq(chan, tx_seq); 4526 BT_DBG("Retry limit exceeded (%d)", chan->max_tx);
4527 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
4528 return;
4202 } 4529 }
4203}
4204 4530
4205static void l2cap_resend_srejframe(struct l2cap_chan *chan, u16 tx_seq) 4531 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state);
4206{
4207 struct srej_list *l, *tmp;
4208 u32 control;
4209 4532
4210 list_for_each_entry_safe(l, tmp, &chan->srej_l, list) { 4533 if (control->poll) {
4211 if (l->tx_seq == tx_seq) { 4534 l2cap_pass_to_tx(chan, control);
4212 list_del(&l->list); 4535
4213 kfree(l); 4536 set_bit(CONN_SEND_FBIT, &chan->conn_state);
4214 return; 4537 l2cap_retransmit(chan, control);
4538 l2cap_ertm_send(chan);
4539
4540 if (chan->tx_state == L2CAP_TX_STATE_WAIT_F) {
4541 set_bit(CONN_SREJ_ACT, &chan->conn_state);
4542 chan->srej_save_reqseq = control->reqseq;
4543 }
4544 } else {
4545 l2cap_pass_to_tx_fbit(chan, control);
4546
4547 if (control->final) {
4548 if (chan->srej_save_reqseq != control->reqseq ||
4549 !test_and_clear_bit(CONN_SREJ_ACT,
4550 &chan->conn_state))
4551 l2cap_retransmit(chan, control);
4552 } else {
4553 l2cap_retransmit(chan, control);
4554 if (chan->tx_state == L2CAP_TX_STATE_WAIT_F) {
4555 set_bit(CONN_SREJ_ACT, &chan->conn_state);
4556 chan->srej_save_reqseq = control->reqseq;
4557 }
4215 } 4558 }
4216 control = __set_ctrl_super(chan, L2CAP_SUPER_SREJ);
4217 control |= __set_reqseq(chan, l->tx_seq);
4218 l2cap_send_sframe(chan, control);
4219 list_del(&l->list);
4220 list_add_tail(&l->list, &chan->srej_l);
4221 } 4559 }
4222} 4560}
4223 4561
4224static int l2cap_send_srejframe(struct l2cap_chan *chan, u16 tx_seq) 4562static void l2cap_handle_rej(struct l2cap_chan *chan,
4563 struct l2cap_ctrl *control)
4225{ 4564{
4226 struct srej_list *new; 4565 struct sk_buff *skb;
4227 u32 control;
4228
4229 while (tx_seq != chan->expected_tx_seq) {
4230 control = __set_ctrl_super(chan, L2CAP_SUPER_SREJ);
4231 control |= __set_reqseq(chan, chan->expected_tx_seq);
4232 l2cap_seq_list_append(&chan->srej_list, chan->expected_tx_seq);
4233 l2cap_send_sframe(chan, control);
4234 4566
4235 new = kzalloc(sizeof(struct srej_list), GFP_ATOMIC); 4567 BT_DBG("chan %p, control %p", chan, control);
4236 if (!new)
4237 return -ENOMEM;
4238 4568
4239 new->tx_seq = chan->expected_tx_seq; 4569 if (control->reqseq == chan->next_tx_seq) {
4570 BT_DBG("Invalid reqseq %d, disconnecting", control->reqseq);
4571 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
4572 return;
4573 }
4240 4574
4241 chan->expected_tx_seq = __next_seq(chan, chan->expected_tx_seq); 4575 skb = l2cap_ertm_seq_in_queue(&chan->tx_q, control->reqseq);
4242 4576
4243 list_add_tail(&new->list, &chan->srej_l); 4577 if (chan->max_tx && skb &&
4578 bt_cb(skb)->control.retries >= chan->max_tx) {
4579 BT_DBG("Retry limit exceeded (%d)", chan->max_tx);
4580 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
4581 return;
4244 } 4582 }
4245 4583
4246 chan->expected_tx_seq = __next_seq(chan, chan->expected_tx_seq); 4584 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state);
4247 4585
4248 return 0; 4586 l2cap_pass_to_tx(chan, control);
4587
4588 if (control->final) {
4589 if (!test_and_clear_bit(CONN_REJ_ACT, &chan->conn_state))
4590 l2cap_retransmit_all(chan, control);
4591 } else {
4592 l2cap_retransmit_all(chan, control);
4593 l2cap_ertm_send(chan);
4594 if (chan->tx_state == L2CAP_TX_STATE_WAIT_F)
4595 set_bit(CONN_REJ_ACT, &chan->conn_state);
4596 }
4249} 4597}
4250 4598
4251static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u32 rx_control, struct sk_buff *skb) 4599static u8 l2cap_classify_txseq(struct l2cap_chan *chan, u16 txseq)
4252{ 4600{
4253 u16 tx_seq = __get_txseq(chan, rx_control); 4601 BT_DBG("chan %p, txseq %d", chan, txseq);
4254 u16 req_seq = __get_reqseq(chan, rx_control);
4255 u8 sar = __get_ctrl_sar(chan, rx_control);
4256 int tx_seq_offset, expected_tx_seq_offset;
4257 int num_to_ack = (chan->tx_win/6) + 1;
4258 int err = 0;
4259 4602
4260 BT_DBG("chan %p len %d tx_seq %d rx_control 0x%8.8x", chan, skb->len, 4603 BT_DBG("last_acked_seq %d, expected_tx_seq %d", chan->last_acked_seq,
4261 tx_seq, rx_control); 4604 chan->expected_tx_seq);
4262 4605
4263 if (__is_ctrl_final(chan, rx_control) && 4606 if (chan->rx_state == L2CAP_RX_STATE_SREJ_SENT) {
4264 test_bit(CONN_WAIT_F, &chan->conn_state)) { 4607 if (__seq_offset(chan, txseq, chan->last_acked_seq) >=
4265 __clear_monitor_timer(chan); 4608 chan->tx_win) {
4266 if (chan->unacked_frames > 0) 4609 /* See notes below regarding "double poll" and
4267 __set_retrans_timer(chan); 4610 * invalid packets.
4268 clear_bit(CONN_WAIT_F, &chan->conn_state); 4611 */
4269 } 4612 if (chan->tx_win <= ((chan->tx_win_max + 1) >> 1)) {
4613 BT_DBG("Invalid/Ignore - after SREJ");
4614 return L2CAP_TXSEQ_INVALID_IGNORE;
4615 } else {
4616 BT_DBG("Invalid - in window after SREJ sent");
4617 return L2CAP_TXSEQ_INVALID;
4618 }
4619 }
4270 4620
4271 chan->expected_ack_seq = req_seq; 4621 if (chan->srej_list.head == txseq) {
4272 l2cap_drop_acked_frames(chan); 4622 BT_DBG("Expected SREJ");
4623 return L2CAP_TXSEQ_EXPECTED_SREJ;
4624 }
4273 4625
4274 tx_seq_offset = __seq_offset(chan, tx_seq, chan->buffer_seq); 4626 if (l2cap_ertm_seq_in_queue(&chan->srej_q, txseq)) {
4627 BT_DBG("Duplicate SREJ - txseq already stored");
4628 return L2CAP_TXSEQ_DUPLICATE_SREJ;
4629 }
4275 4630
4276 /* invalid tx_seq */ 4631 if (l2cap_seq_list_contains(&chan->srej_list, txseq)) {
4277 if (tx_seq_offset >= chan->tx_win) { 4632 BT_DBG("Unexpected SREJ - not requested");
4278 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); 4633 return L2CAP_TXSEQ_UNEXPECTED_SREJ;
4279 goto drop; 4634 }
4280 } 4635 }
4281 4636
4282 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) { 4637 if (chan->expected_tx_seq == txseq) {
4283 if (!test_bit(CONN_RNR_SENT, &chan->conn_state)) 4638 if (__seq_offset(chan, txseq, chan->last_acked_seq) >=
4284 l2cap_send_ack(chan); 4639 chan->tx_win) {
4285 goto drop; 4640 BT_DBG("Invalid - txseq outside tx window");
4641 return L2CAP_TXSEQ_INVALID;
4642 } else {
4643 BT_DBG("Expected");
4644 return L2CAP_TXSEQ_EXPECTED;
4645 }
4286 } 4646 }
4287 4647
4288 if (tx_seq == chan->expected_tx_seq) 4648 if (__seq_offset(chan, txseq, chan->last_acked_seq) <
4289 goto expected; 4649 __seq_offset(chan, chan->expected_tx_seq,
4650 chan->last_acked_seq)){
4651 BT_DBG("Duplicate - expected_tx_seq later than txseq");
4652 return L2CAP_TXSEQ_DUPLICATE;
4653 }
4654
4655 if (__seq_offset(chan, txseq, chan->last_acked_seq) >= chan->tx_win) {
4656 /* A source of invalid packets is a "double poll" condition,
4657 * where delays cause us to send multiple poll packets. If
4658 * the remote stack receives and processes both polls,
4659 * sequence numbers can wrap around in such a way that a
4660 * resent frame has a sequence number that looks like new data
4661 * with a sequence gap. This would trigger an erroneous SREJ
4662 * request.
4663 *
4664 * Fortunately, this is impossible with a tx window that's
4665 * less than half of the maximum sequence number, which allows
4666 * invalid frames to be safely ignored.
4667 *
4668 * With tx window sizes greater than half of the tx window
4669 * maximum, the frame is invalid and cannot be ignored. This
4670 * causes a disconnect.
4671 */
4290 4672
4291 if (test_bit(CONN_SREJ_SENT, &chan->conn_state)) { 4673 if (chan->tx_win <= ((chan->tx_win_max + 1) >> 1)) {
4292 struct srej_list *first; 4674 BT_DBG("Invalid/Ignore - txseq outside tx window");
4675 return L2CAP_TXSEQ_INVALID_IGNORE;
4676 } else {
4677 BT_DBG("Invalid - txseq outside tx window");
4678 return L2CAP_TXSEQ_INVALID;
4679 }
4680 } else {
4681 BT_DBG("Unexpected - txseq indicates missing frames");
4682 return L2CAP_TXSEQ_UNEXPECTED;
4683 }
4684}
4685
4686static int l2cap_rx_state_recv(struct l2cap_chan *chan,
4687 struct l2cap_ctrl *control,
4688 struct sk_buff *skb, u8 event)
4689{
4690 int err = 0;
4691 bool skb_in_use = 0;
4293 4692
4294 first = list_first_entry(&chan->srej_l, 4693 BT_DBG("chan %p, control %p, skb %p, event %d", chan, control, skb,
4295 struct srej_list, list); 4694 event);
4296 if (tx_seq == first->tx_seq) {
4297 l2cap_add_to_srej_queue(chan, skb, tx_seq, sar);
4298 l2cap_check_srej_gap(chan, tx_seq);
4299 4695
4300 list_del(&first->list); 4696 switch (event) {
4301 kfree(first); 4697 case L2CAP_EV_RECV_IFRAME:
4698 switch (l2cap_classify_txseq(chan, control->txseq)) {
4699 case L2CAP_TXSEQ_EXPECTED:
4700 l2cap_pass_to_tx(chan, control);
4302 4701
4303 if (list_empty(&chan->srej_l)) { 4702 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) {
4304 chan->buffer_seq = chan->buffer_seq_srej; 4703 BT_DBG("Busy, discarding expected seq %d",
4305 clear_bit(CONN_SREJ_SENT, &chan->conn_state); 4704 control->txseq);
4306 l2cap_send_ack(chan); 4705 break;
4307 BT_DBG("chan %p, Exit SREJ_SENT", chan);
4308 } 4706 }
4309 } else {
4310 struct srej_list *l;
4311 4707
4312 /* duplicated tx_seq */ 4708 chan->expected_tx_seq = __next_seq(chan,
4313 if (l2cap_add_to_srej_queue(chan, skb, tx_seq, sar) < 0) 4709 control->txseq);
4314 goto drop; 4710
4711 chan->buffer_seq = chan->expected_tx_seq;
4712 skb_in_use = 1;
4713
4714 err = l2cap_reassemble_sdu(chan, skb, control);
4715 if (err)
4716 break;
4315 4717
4316 list_for_each_entry(l, &chan->srej_l, list) { 4718 if (control->final) {
4317 if (l->tx_seq == tx_seq) { 4719 if (!test_and_clear_bit(CONN_REJ_ACT,
4318 l2cap_resend_srejframe(chan, tx_seq); 4720 &chan->conn_state)) {
4319 return 0; 4721 control->final = 0;
4722 l2cap_retransmit_all(chan, control);
4723 l2cap_ertm_send(chan);
4320 } 4724 }
4321 } 4725 }
4322 4726
4323 err = l2cap_send_srejframe(chan, tx_seq); 4727 if (!test_bit(CONN_LOCAL_BUSY, &chan->conn_state))
4324 if (err < 0) { 4728 l2cap_send_ack(chan);
4325 l2cap_send_disconn_req(chan->conn, chan, -err); 4729 break;
4326 return err; 4730 case L2CAP_TXSEQ_UNEXPECTED:
4731 l2cap_pass_to_tx(chan, control);
4732
4733 /* Can't issue SREJ frames in the local busy state.
4734 * Drop this frame, it will be seen as missing
4735 * when local busy is exited.
4736 */
4737 if (test_bit(CONN_LOCAL_BUSY, &chan->conn_state)) {
4738 BT_DBG("Busy, discarding unexpected seq %d",
4739 control->txseq);
4740 break;
4327 } 4741 }
4328 }
4329 } else {
4330 expected_tx_seq_offset = __seq_offset(chan,
4331 chan->expected_tx_seq, chan->buffer_seq);
4332 4742
4333 /* duplicated tx_seq */ 4743 /* There was a gap in the sequence, so an SREJ
4334 if (tx_seq_offset < expected_tx_seq_offset) 4744 * must be sent for each missing frame. The
4335 goto drop; 4745 * current frame is stored for later use.
4746 */
4747 skb_queue_tail(&chan->srej_q, skb);
4748 skb_in_use = 1;
4749 BT_DBG("Queued %p (queue len %d)", skb,
4750 skb_queue_len(&chan->srej_q));
4336 4751
4337 set_bit(CONN_SREJ_SENT, &chan->conn_state); 4752 clear_bit(CONN_SREJ_ACT, &chan->conn_state);
4338 4753 l2cap_seq_list_clear(&chan->srej_list);
4339 BT_DBG("chan %p, Enter SREJ", chan); 4754 l2cap_send_srej(chan, control->txseq);
4340 4755
4341 INIT_LIST_HEAD(&chan->srej_l); 4756 chan->rx_state = L2CAP_RX_STATE_SREJ_SENT;
4342 chan->buffer_seq_srej = chan->buffer_seq; 4757 break;
4758 case L2CAP_TXSEQ_DUPLICATE:
4759 l2cap_pass_to_tx(chan, control);
4760 break;
4761 case L2CAP_TXSEQ_INVALID_IGNORE:
4762 break;
4763 case L2CAP_TXSEQ_INVALID:
4764 default:
4765 l2cap_send_disconn_req(chan->conn, chan,
4766 ECONNRESET);
4767 break;
4768 }
4769 break;
4770 case L2CAP_EV_RECV_RR:
4771 l2cap_pass_to_tx(chan, control);
4772 if (control->final) {
4773 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state);
4343 4774
4344 __skb_queue_head_init(&chan->srej_q); 4775 if (!test_and_clear_bit(CONN_REJ_ACT,
4345 l2cap_add_to_srej_queue(chan, skb, tx_seq, sar); 4776 &chan->conn_state)) {
4777 control->final = 0;
4778 l2cap_retransmit_all(chan, control);
4779 }
4346 4780
4347 /* Set P-bit only if there are some I-frames to ack. */ 4781 l2cap_ertm_send(chan);
4348 if (__clear_ack_timer(chan)) 4782 } else if (control->poll) {
4349 set_bit(CONN_SEND_PBIT, &chan->conn_state); 4783 l2cap_send_i_or_rr_or_rnr(chan);
4784 } else {
4785 if (test_and_clear_bit(CONN_REMOTE_BUSY,
4786 &chan->conn_state) &&
4787 chan->unacked_frames)
4788 __set_retrans_timer(chan);
4350 4789
4351 err = l2cap_send_srejframe(chan, tx_seq); 4790 l2cap_ertm_send(chan);
4352 if (err < 0) {
4353 l2cap_send_disconn_req(chan->conn, chan, -err);
4354 return err;
4355 } 4791 }
4792 break;
4793 case L2CAP_EV_RECV_RNR:
4794 set_bit(CONN_REMOTE_BUSY, &chan->conn_state);
4795 l2cap_pass_to_tx(chan, control);
4796 if (control && control->poll) {
4797 set_bit(CONN_SEND_FBIT, &chan->conn_state);
4798 l2cap_send_rr_or_rnr(chan, 0);
4799 }
4800 __clear_retrans_timer(chan);
4801 l2cap_seq_list_clear(&chan->retrans_list);
4802 break;
4803 case L2CAP_EV_RECV_REJ:
4804 l2cap_handle_rej(chan, control);
4805 break;
4806 case L2CAP_EV_RECV_SREJ:
4807 l2cap_handle_srej(chan, control);
4808 break;
4809 default:
4810 break;
4356 } 4811 }
4357 return 0;
4358
4359expected:
4360 chan->expected_tx_seq = __next_seq(chan, chan->expected_tx_seq);
4361
4362 if (test_bit(CONN_SREJ_SENT, &chan->conn_state)) {
4363 bt_cb(skb)->control.txseq = tx_seq;
4364 bt_cb(skb)->control.sar = sar;
4365 __skb_queue_tail(&chan->srej_q, skb);
4366 return 0;
4367 }
4368
4369 err = l2cap_reassemble_sdu(chan, skb, rx_control);
4370 chan->buffer_seq = __next_seq(chan, chan->buffer_seq);
4371 4812
4372 if (err < 0) { 4813 if (skb && !skb_in_use) {
4373 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); 4814 BT_DBG("Freeing %p", skb);
4374 return err; 4815 kfree_skb(skb);
4375 } 4816 }
4376 4817
4377 if (__is_ctrl_final(chan, rx_control)) { 4818 return err;
4378 if (!test_and_clear_bit(CONN_REJ_ACT, &chan->conn_state)) 4819}
4379 l2cap_retransmit_frames(chan);
4380 }
4381 4820
4821static int l2cap_rx_state_srej_sent(struct l2cap_chan *chan,
4822 struct l2cap_ctrl *control,
4823 struct sk_buff *skb, u8 event)
4824{
4825 int err = 0;
4826 u16 txseq = control->txseq;
4827 bool skb_in_use = 0;
4828
4829 BT_DBG("chan %p, control %p, skb %p, event %d", chan, control, skb,
4830 event);
4831
4832 switch (event) {
4833 case L2CAP_EV_RECV_IFRAME:
4834 switch (l2cap_classify_txseq(chan, txseq)) {
4835 case L2CAP_TXSEQ_EXPECTED:
4836 /* Keep frame for reassembly later */
4837 l2cap_pass_to_tx(chan, control);
4838 skb_queue_tail(&chan->srej_q, skb);
4839 skb_in_use = 1;
4840 BT_DBG("Queued %p (queue len %d)", skb,
4841 skb_queue_len(&chan->srej_q));
4842
4843 chan->expected_tx_seq = __next_seq(chan, txseq);
4844 break;
4845 case L2CAP_TXSEQ_EXPECTED_SREJ:
4846 l2cap_seq_list_pop(&chan->srej_list);
4382 4847
4383 chan->num_acked = (chan->num_acked + 1) % num_to_ack; 4848 l2cap_pass_to_tx(chan, control);
4384 if (chan->num_acked == num_to_ack - 1) 4849 skb_queue_tail(&chan->srej_q, skb);
4385 l2cap_send_ack(chan); 4850 skb_in_use = 1;
4386 else 4851 BT_DBG("Queued %p (queue len %d)", skb,
4387 __set_ack_timer(chan); 4852 skb_queue_len(&chan->srej_q));
4388 4853
4389 return 0; 4854 err = l2cap_rx_queued_iframes(chan);
4855 if (err)
4856 break;
4390 4857
4391drop: 4858 break;
4392 kfree_skb(skb); 4859 case L2CAP_TXSEQ_UNEXPECTED:
4393 return 0; 4860 /* Got a frame that can't be reassembled yet.
4394} 4861 * Save it for later, and send SREJs to cover
4862 * the missing frames.
4863 */
4864 skb_queue_tail(&chan->srej_q, skb);
4865 skb_in_use = 1;
4866 BT_DBG("Queued %p (queue len %d)", skb,
4867 skb_queue_len(&chan->srej_q));
4868
4869 l2cap_pass_to_tx(chan, control);
4870 l2cap_send_srej(chan, control->txseq);
4871 break;
4872 case L2CAP_TXSEQ_UNEXPECTED_SREJ:
4873 /* This frame was requested with an SREJ, but
4874 * some expected retransmitted frames are
4875 * missing. Request retransmission of missing
4876 * SREJ'd frames.
4877 */
4878 skb_queue_tail(&chan->srej_q, skb);
4879 skb_in_use = 1;
4880 BT_DBG("Queued %p (queue len %d)", skb,
4881 skb_queue_len(&chan->srej_q));
4882
4883 l2cap_pass_to_tx(chan, control);
4884 l2cap_send_srej_list(chan, control->txseq);
4885 break;
4886 case L2CAP_TXSEQ_DUPLICATE_SREJ:
4887 /* We've already queued this frame. Drop this copy. */
4888 l2cap_pass_to_tx(chan, control);
4889 break;
4890 case L2CAP_TXSEQ_DUPLICATE:
4891 /* Expecting a later sequence number, so this frame
4892 * was already received. Ignore it completely.
4893 */
4894 break;
4895 case L2CAP_TXSEQ_INVALID_IGNORE:
4896 break;
4897 case L2CAP_TXSEQ_INVALID:
4898 default:
4899 l2cap_send_disconn_req(chan->conn, chan,
4900 ECONNRESET);
4901 break;
4902 }
4903 break;
4904 case L2CAP_EV_RECV_RR:
4905 l2cap_pass_to_tx(chan, control);
4906 if (control->final) {
4907 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state);
4395 4908
4396static inline void l2cap_data_channel_rrframe(struct l2cap_chan *chan, u32 rx_control) 4909 if (!test_and_clear_bit(CONN_REJ_ACT,
4397{ 4910 &chan->conn_state)) {
4398 BT_DBG("chan %p, req_seq %d ctrl 0x%8.8x", chan, 4911 control->final = 0;
4399 __get_reqseq(chan, rx_control), rx_control); 4912 l2cap_retransmit_all(chan, control);
4913 }
4400 4914
4401 chan->expected_ack_seq = __get_reqseq(chan, rx_control); 4915 l2cap_ertm_send(chan);
4402 l2cap_drop_acked_frames(chan); 4916 } else if (control->poll) {
4917 if (test_and_clear_bit(CONN_REMOTE_BUSY,
4918 &chan->conn_state) &&
4919 chan->unacked_frames) {
4920 __set_retrans_timer(chan);
4921 }
4403 4922
4404 if (__is_ctrl_poll(chan, rx_control)) { 4923 set_bit(CONN_SEND_FBIT, &chan->conn_state);
4405 set_bit(CONN_SEND_FBIT, &chan->conn_state); 4924 l2cap_send_srej_tail(chan);
4406 if (test_bit(CONN_SREJ_SENT, &chan->conn_state)) { 4925 } else {
4407 if (test_bit(CONN_REMOTE_BUSY, &chan->conn_state) && 4926 if (test_and_clear_bit(CONN_REMOTE_BUSY,
4408 (chan->unacked_frames > 0)) 4927 &chan->conn_state) &&
4928 chan->unacked_frames)
4409 __set_retrans_timer(chan); 4929 __set_retrans_timer(chan);
4410 4930
4411 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state); 4931 l2cap_send_ack(chan);
4412 l2cap_send_srejtail(chan); 4932 }
4933 break;
4934 case L2CAP_EV_RECV_RNR:
4935 set_bit(CONN_REMOTE_BUSY, &chan->conn_state);
4936 l2cap_pass_to_tx(chan, control);
4937 if (control->poll) {
4938 l2cap_send_srej_tail(chan);
4413 } else { 4939 } else {
4414 l2cap_send_i_or_rr_or_rnr(chan); 4940 struct l2cap_ctrl rr_control;
4941 memset(&rr_control, 0, sizeof(rr_control));
4942 rr_control.sframe = 1;
4943 rr_control.super = L2CAP_SUPER_RR;
4944 rr_control.reqseq = chan->buffer_seq;
4945 l2cap_send_sframe(chan, &rr_control);
4415 } 4946 }
4416 4947
4417 } else if (__is_ctrl_final(chan, rx_control)) { 4948 break;
4418 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state); 4949 case L2CAP_EV_RECV_REJ:
4419 4950 l2cap_handle_rej(chan, control);
4420 if (!test_and_clear_bit(CONN_REJ_ACT, &chan->conn_state)) 4951 break;
4421 l2cap_retransmit_frames(chan); 4952 case L2CAP_EV_RECV_SREJ:
4422 4953 l2cap_handle_srej(chan, control);
4423 } else { 4954 break;
4424 if (test_bit(CONN_REMOTE_BUSY, &chan->conn_state) && 4955 }
4425 (chan->unacked_frames > 0))
4426 __set_retrans_timer(chan);
4427 4956
4428 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state); 4957 if (skb && !skb_in_use) {
4429 if (test_bit(CONN_SREJ_SENT, &chan->conn_state)) 4958 BT_DBG("Freeing %p", skb);
4430 l2cap_send_ack(chan); 4959 kfree_skb(skb);
4431 else
4432 l2cap_ertm_send(chan);
4433 } 4960 }
4961
4962 return err;
4434} 4963}
4435 4964
4436static inline void l2cap_data_channel_rejframe(struct l2cap_chan *chan, u32 rx_control) 4965static bool __valid_reqseq(struct l2cap_chan *chan, u16 reqseq)
4437{ 4966{
4438 u16 tx_seq = __get_reqseq(chan, rx_control); 4967 /* Make sure reqseq is for a packet that has been sent but not acked */
4439 4968 u16 unacked;
4440 BT_DBG("chan %p, req_seq %d ctrl 0x%8.8x", chan, tx_seq, rx_control);
4441
4442 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state);
4443
4444 chan->expected_ack_seq = tx_seq;
4445 l2cap_drop_acked_frames(chan);
4446
4447 if (__is_ctrl_final(chan, rx_control)) {
4448 if (!test_and_clear_bit(CONN_REJ_ACT, &chan->conn_state))
4449 l2cap_retransmit_frames(chan);
4450 } else {
4451 l2cap_retransmit_frames(chan);
4452 4969
4453 if (test_bit(CONN_WAIT_F, &chan->conn_state)) 4970 unacked = __seq_offset(chan, chan->next_tx_seq, chan->expected_ack_seq);
4454 set_bit(CONN_REJ_ACT, &chan->conn_state); 4971 return __seq_offset(chan, chan->next_tx_seq, reqseq) <= unacked;
4455 }
4456} 4972}
4457static inline void l2cap_data_channel_srejframe(struct l2cap_chan *chan, u32 rx_control)
4458{
4459 u16 tx_seq = __get_reqseq(chan, rx_control);
4460
4461 BT_DBG("chan %p, req_seq %d ctrl 0x%8.8x", chan, tx_seq, rx_control);
4462
4463 clear_bit(CONN_REMOTE_BUSY, &chan->conn_state);
4464 4973
4465 if (__is_ctrl_poll(chan, rx_control)) { 4974static int l2cap_rx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
4466 chan->expected_ack_seq = tx_seq; 4975 struct sk_buff *skb, u8 event)
4467 l2cap_drop_acked_frames(chan); 4976{
4468 4977 int err = 0;
4469 set_bit(CONN_SEND_FBIT, &chan->conn_state);
4470 l2cap_retransmit_one_frame(chan, tx_seq);
4471 4978
4472 l2cap_ertm_send(chan); 4979 BT_DBG("chan %p, control %p, skb %p, event %d, state %d", chan,
4980 control, skb, event, chan->rx_state);
4473 4981
4474 if (test_bit(CONN_WAIT_F, &chan->conn_state)) { 4982 if (__valid_reqseq(chan, control->reqseq)) {
4475 chan->srej_save_reqseq = tx_seq; 4983 switch (chan->rx_state) {
4476 set_bit(CONN_SREJ_ACT, &chan->conn_state); 4984 case L2CAP_RX_STATE_RECV:
4985 err = l2cap_rx_state_recv(chan, control, skb, event);
4986 break;
4987 case L2CAP_RX_STATE_SREJ_SENT:
4988 err = l2cap_rx_state_srej_sent(chan, control, skb,
4989 event);
4990 break;
4991 default:
4992 /* shut it down */
4993 break;
4477 } 4994 }
4478 } else if (__is_ctrl_final(chan, rx_control)) {
4479 if (test_bit(CONN_SREJ_ACT, &chan->conn_state) &&
4480 chan->srej_save_reqseq == tx_seq)
4481 clear_bit(CONN_SREJ_ACT, &chan->conn_state);
4482 else
4483 l2cap_retransmit_one_frame(chan, tx_seq);
4484 } else { 4995 } else {
4485 l2cap_retransmit_one_frame(chan, tx_seq); 4996 BT_DBG("Invalid reqseq %d (next_tx_seq %d, expected_ack_seq %d",
4486 if (test_bit(CONN_WAIT_F, &chan->conn_state)) { 4997 control->reqseq, chan->next_tx_seq,
4487 chan->srej_save_reqseq = tx_seq; 4998 chan->expected_ack_seq);
4488 set_bit(CONN_SREJ_ACT, &chan->conn_state); 4999 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
4489 }
4490 } 5000 }
5001
5002 return err;
4491} 5003}
4492 5004
4493static inline void l2cap_data_channel_rnrframe(struct l2cap_chan *chan, u32 rx_control) 5005static int l2cap_stream_rx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
5006 struct sk_buff *skb)
4494{ 5007{
4495 u16 tx_seq = __get_reqseq(chan, rx_control); 5008 int err = 0;
4496 5009
4497 BT_DBG("chan %p, req_seq %d ctrl 0x%8.8x", chan, tx_seq, rx_control); 5010 BT_DBG("chan %p, control %p, skb %p, state %d", chan, control, skb,
5011 chan->rx_state);
4498 5012
4499 set_bit(CONN_REMOTE_BUSY, &chan->conn_state); 5013 if (l2cap_classify_txseq(chan, control->txseq) ==
4500 chan->expected_ack_seq = tx_seq; 5014 L2CAP_TXSEQ_EXPECTED) {
4501 l2cap_drop_acked_frames(chan); 5015 l2cap_pass_to_tx(chan, control);
4502 5016
4503 if (__is_ctrl_poll(chan, rx_control)) 5017 BT_DBG("buffer_seq %d->%d", chan->buffer_seq,
4504 set_bit(CONN_SEND_FBIT, &chan->conn_state); 5018 __next_seq(chan, chan->buffer_seq));
4505 5019
4506 if (!test_bit(CONN_SREJ_SENT, &chan->conn_state)) { 5020 chan->buffer_seq = __next_seq(chan, chan->buffer_seq);
4507 __clear_retrans_timer(chan);
4508 if (__is_ctrl_poll(chan, rx_control))
4509 l2cap_send_rr_or_rnr(chan, L2CAP_CTRL_FINAL);
4510 return;
4511 }
4512 5021
4513 if (__is_ctrl_poll(chan, rx_control)) { 5022 l2cap_reassemble_sdu(chan, skb, control);
4514 l2cap_send_srejtail(chan);
4515 } else { 5023 } else {
4516 rx_control = __set_ctrl_super(chan, L2CAP_SUPER_RR); 5024 if (chan->sdu) {
4517 l2cap_send_sframe(chan, rx_control); 5025 kfree_skb(chan->sdu);
4518 } 5026 chan->sdu = NULL;
4519} 5027 }
4520 5028 chan->sdu_last_frag = NULL;
4521static inline int l2cap_data_channel_sframe(struct l2cap_chan *chan, u32 rx_control, struct sk_buff *skb) 5029 chan->sdu_len = 0;
4522{
4523 BT_DBG("chan %p rx_control 0x%8.8x len %d", chan, rx_control, skb->len);
4524 5030
4525 if (__is_ctrl_final(chan, rx_control) && 5031 if (skb) {
4526 test_bit(CONN_WAIT_F, &chan->conn_state)) { 5032 BT_DBG("Freeing %p", skb);
4527 __clear_monitor_timer(chan); 5033 kfree_skb(skb);
4528 if (chan->unacked_frames > 0) 5034 }
4529 __set_retrans_timer(chan);
4530 clear_bit(CONN_WAIT_F, &chan->conn_state);
4531 } 5035 }
4532 5036
4533 switch (__get_ctrl_super(chan, rx_control)) { 5037 chan->last_acked_seq = control->txseq;
4534 case L2CAP_SUPER_RR: 5038 chan->expected_tx_seq = __next_seq(chan, control->txseq);
4535 l2cap_data_channel_rrframe(chan, rx_control);
4536 break;
4537 5039
4538 case L2CAP_SUPER_REJ: 5040 return err;
4539 l2cap_data_channel_rejframe(chan, rx_control);
4540 break;
4541
4542 case L2CAP_SUPER_SREJ:
4543 l2cap_data_channel_srejframe(chan, rx_control);
4544 break;
4545
4546 case L2CAP_SUPER_RNR:
4547 l2cap_data_channel_rnrframe(chan, rx_control);
4548 break;
4549 }
4550
4551 kfree_skb(skb);
4552 return 0;
4553} 5041}
4554 5042
4555static int l2cap_ertm_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb) 5043static int l2cap_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
4556{ 5044{
4557 u32 control; 5045 struct l2cap_ctrl *control = &bt_cb(skb)->control;
4558 u16 req_seq; 5046 u16 len;
4559 int len, next_tx_seq_offset, req_seq_offset; 5047 u8 event;
4560 5048
4561 __unpack_control(chan, skb); 5049 __unpack_control(chan, skb);
4562 5050
4563 control = __get_control(chan, skb->data);
4564 skb_pull(skb, __ctrl_size(chan));
4565 len = skb->len; 5051 len = skb->len;
4566 5052
4567 /* 5053 /*
4568 * We can just drop the corrupted I-frame here. 5054 * We can just drop the corrupted I-frame here.
4569 * Receiver will miss it and start proper recovery 5055 * Receiver will miss it and start proper recovery
4570 * procedures and ask retransmission. 5056 * procedures and ask for retransmission.
4571 */ 5057 */
4572 if (l2cap_check_fcs(chan, skb)) 5058 if (l2cap_check_fcs(chan, skb))
4573 goto drop; 5059 goto drop;
4574 5060
4575 if (__is_sar_start(chan, control) && !__is_sframe(chan, control)) 5061 if (!control->sframe && control->sar == L2CAP_SAR_START)
4576 len -= L2CAP_SDULEN_SIZE; 5062 len -= L2CAP_SDULEN_SIZE;
4577 5063
4578 if (chan->fcs == L2CAP_FCS_CRC16) 5064 if (chan->fcs == L2CAP_FCS_CRC16)
@@ -4583,34 +5069,57 @@ static int l2cap_ertm_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
4583 goto drop; 5069 goto drop;
4584 } 5070 }
4585 5071
4586 req_seq = __get_reqseq(chan, control); 5072 if (!control->sframe) {
4587 5073 int err;
4588 req_seq_offset = __seq_offset(chan, req_seq, chan->expected_ack_seq);
4589
4590 next_tx_seq_offset = __seq_offset(chan, chan->next_tx_seq,
4591 chan->expected_ack_seq);
4592 5074
4593 /* check for invalid req-seq */ 5075 BT_DBG("iframe sar %d, reqseq %d, final %d, txseq %d",
4594 if (req_seq_offset > next_tx_seq_offset) { 5076 control->sar, control->reqseq, control->final,
4595 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); 5077 control->txseq);
4596 goto drop;
4597 }
4598 5078
4599 if (!__is_sframe(chan, control)) { 5079 /* Validate F-bit - F=0 always valid, F=1 only
4600 if (len < 0) { 5080 * valid in TX WAIT_F
4601 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); 5081 */
5082 if (control->final && chan->tx_state != L2CAP_TX_STATE_WAIT_F)
4602 goto drop; 5083 goto drop;
5084
5085 if (chan->mode != L2CAP_MODE_STREAMING) {
5086 event = L2CAP_EV_RECV_IFRAME;
5087 err = l2cap_rx(chan, control, skb, event);
5088 } else {
5089 err = l2cap_stream_rx(chan, control, skb);
4603 } 5090 }
4604 5091
4605 l2cap_data_channel_iframe(chan, control, skb); 5092 if (err)
5093 l2cap_send_disconn_req(chan->conn, chan,
5094 ECONNRESET);
4606 } else { 5095 } else {
5096 const u8 rx_func_to_event[4] = {
5097 L2CAP_EV_RECV_RR, L2CAP_EV_RECV_REJ,
5098 L2CAP_EV_RECV_RNR, L2CAP_EV_RECV_SREJ
5099 };
5100
5101 /* Only I-frames are expected in streaming mode */
5102 if (chan->mode == L2CAP_MODE_STREAMING)
5103 goto drop;
5104
5105 BT_DBG("sframe reqseq %d, final %d, poll %d, super %d",
5106 control->reqseq, control->final, control->poll,
5107 control->super);
5108
4607 if (len != 0) { 5109 if (len != 0) {
4608 BT_ERR("%d", len); 5110 BT_ERR("%d", len);
4609 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); 5111 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
4610 goto drop; 5112 goto drop;
4611 } 5113 }
4612 5114
4613 l2cap_data_channel_sframe(chan, control, skb); 5115 /* Validate F and P bits */
5116 if (control->final && (control->poll ||
5117 chan->tx_state != L2CAP_TX_STATE_WAIT_F))
5118 goto drop;
5119
5120 event = rx_func_to_event[control->super];
5121 if (l2cap_rx(chan, control, skb, event))
5122 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
4614 } 5123 }
4615 5124
4616 return 0; 5125 return 0;
@@ -4620,19 +5129,27 @@ drop:
4620 return 0; 5129 return 0;
4621} 5130}
4622 5131
4623static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk_buff *skb) 5132static void l2cap_data_channel(struct l2cap_conn *conn, u16 cid,
5133 struct sk_buff *skb)
4624{ 5134{
4625 struct l2cap_chan *chan; 5135 struct l2cap_chan *chan;
4626 u32 control;
4627 u16 tx_seq;
4628 int len;
4629 5136
4630 chan = l2cap_get_chan_by_scid(conn, cid); 5137 chan = l2cap_get_chan_by_scid(conn, cid);
4631 if (!chan) { 5138 if (!chan) {
4632 BT_DBG("unknown cid 0x%4.4x", cid); 5139 if (cid == L2CAP_CID_A2MP) {
4633 /* Drop packet and return */ 5140 chan = a2mp_channel_create(conn, skb);
4634 kfree_skb(skb); 5141 if (!chan) {
4635 return 0; 5142 kfree_skb(skb);
5143 return;
5144 }
5145
5146 l2cap_chan_lock(chan);
5147 } else {
5148 BT_DBG("unknown cid 0x%4.4x", cid);
5149 /* Drop packet and return */
5150 kfree_skb(skb);
5151 return;
5152 }
4636 } 5153 }
4637 5154
4638 BT_DBG("chan %p, len %d", chan, skb->len); 5155 BT_DBG("chan %p, len %d", chan, skb->len);
@@ -4650,49 +5167,13 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk
4650 if (chan->imtu < skb->len) 5167 if (chan->imtu < skb->len)
4651 goto drop; 5168 goto drop;
4652 5169
4653 if (!chan->ops->recv(chan->data, skb)) 5170 if (!chan->ops->recv(chan, skb))
4654 goto done; 5171 goto done;
4655 break; 5172 break;
4656 5173
4657 case L2CAP_MODE_ERTM: 5174 case L2CAP_MODE_ERTM:
4658 l2cap_ertm_data_rcv(chan, skb);
4659
4660 goto done;
4661
4662 case L2CAP_MODE_STREAMING: 5175 case L2CAP_MODE_STREAMING:
4663 control = __get_control(chan, skb->data); 5176 l2cap_data_rcv(chan, skb);
4664 skb_pull(skb, __ctrl_size(chan));
4665 len = skb->len;
4666
4667 if (l2cap_check_fcs(chan, skb))
4668 goto drop;
4669
4670 if (__is_sar_start(chan, control))
4671 len -= L2CAP_SDULEN_SIZE;
4672
4673 if (chan->fcs == L2CAP_FCS_CRC16)
4674 len -= L2CAP_FCS_SIZE;
4675
4676 if (len > chan->mps || len < 0 || __is_sframe(chan, control))
4677 goto drop;
4678
4679 tx_seq = __get_txseq(chan, control);
4680
4681 if (chan->expected_tx_seq != tx_seq) {
4682 /* Frame(s) missing - must discard partial SDU */
4683 kfree_skb(chan->sdu);
4684 chan->sdu = NULL;
4685 chan->sdu_last_frag = NULL;
4686 chan->sdu_len = 0;
4687
4688 /* TODO: Notify userland of missing data */
4689 }
4690
4691 chan->expected_tx_seq = __next_seq(chan, tx_seq);
4692
4693 if (l2cap_reassemble_sdu(chan, skb, control) == -EMSGSIZE)
4694 l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
4695
4696 goto done; 5177 goto done;
4697 5178
4698 default: 5179 default:
@@ -4705,11 +5186,10 @@ drop:
4705 5186
4706done: 5187done:
4707 l2cap_chan_unlock(chan); 5188 l2cap_chan_unlock(chan);
4708
4709 return 0;
4710} 5189}
4711 5190
4712static inline int l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm, struct sk_buff *skb) 5191static void l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm,
5192 struct sk_buff *skb)
4713{ 5193{
4714 struct l2cap_chan *chan; 5194 struct l2cap_chan *chan;
4715 5195
@@ -4725,17 +5205,15 @@ static inline int l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm, str
4725 if (chan->imtu < skb->len) 5205 if (chan->imtu < skb->len)
4726 goto drop; 5206 goto drop;
4727 5207
4728 if (!chan->ops->recv(chan->data, skb)) 5208 if (!chan->ops->recv(chan, skb))
4729 return 0; 5209 return;
4730 5210
4731drop: 5211drop:
4732 kfree_skb(skb); 5212 kfree_skb(skb);
4733
4734 return 0;
4735} 5213}
4736 5214
4737static inline int l2cap_att_channel(struct l2cap_conn *conn, u16 cid, 5215static void l2cap_att_channel(struct l2cap_conn *conn, u16 cid,
4738 struct sk_buff *skb) 5216 struct sk_buff *skb)
4739{ 5217{
4740 struct l2cap_chan *chan; 5218 struct l2cap_chan *chan;
4741 5219
@@ -4751,13 +5229,11 @@ static inline int l2cap_att_channel(struct l2cap_conn *conn, u16 cid,
4751 if (chan->imtu < skb->len) 5229 if (chan->imtu < skb->len)
4752 goto drop; 5230 goto drop;
4753 5231
4754 if (!chan->ops->recv(chan->data, skb)) 5232 if (!chan->ops->recv(chan, skb))
4755 return 0; 5233 return;
4756 5234
4757drop: 5235drop:
4758 kfree_skb(skb); 5236 kfree_skb(skb);
4759
4760 return 0;
4761} 5237}
4762 5238
4763static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb) 5239static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)
@@ -4785,7 +5261,7 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)
4785 5261
4786 case L2CAP_CID_CONN_LESS: 5262 case L2CAP_CID_CONN_LESS:
4787 psm = get_unaligned((__le16 *) skb->data); 5263 psm = get_unaligned((__le16 *) skb->data);
4788 skb_pull(skb, 2); 5264 skb_pull(skb, L2CAP_PSMLEN_SIZE);
4789 l2cap_conless_channel(conn, psm, skb); 5265 l2cap_conless_channel(conn, psm, skb);
4790 break; 5266 break;
4791 5267
@@ -4979,6 +5455,17 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
4979 rsp.status = cpu_to_le16(stat); 5455 rsp.status = cpu_to_le16(stat);
4980 l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP, 5456 l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP,
4981 sizeof(rsp), &rsp); 5457 sizeof(rsp), &rsp);
5458
5459 if (!test_bit(CONF_REQ_SENT, &chan->conf_state) &&
5460 res == L2CAP_CR_SUCCESS) {
5461 char buf[128];
5462 set_bit(CONF_REQ_SENT, &chan->conf_state);
5463 l2cap_send_cmd(conn, l2cap_get_ident(conn),
5464 L2CAP_CONF_REQ,
5465 l2cap_build_conf_req(chan, buf),
5466 buf);
5467 chan->num_conf_req++;
5468 }
4982 } 5469 }
4983 5470
4984 l2cap_chan_unlock(chan); 5471 l2cap_chan_unlock(chan);
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 3bb1611b9d48..a4bb27e8427e 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -27,7 +27,6 @@
27 27
28/* Bluetooth L2CAP sockets. */ 28/* Bluetooth L2CAP sockets. */
29 29
30#include <linux/security.h>
31#include <linux/export.h> 30#include <linux/export.h>
32 31
33#include <net/bluetooth/bluetooth.h> 32#include <net/bluetooth/bluetooth.h>
@@ -89,8 +88,8 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
89 if (err < 0) 88 if (err < 0)
90 goto done; 89 goto done;
91 90
92 if (__le16_to_cpu(la.l2_psm) == 0x0001 || 91 if (__le16_to_cpu(la.l2_psm) == L2CAP_PSM_SDP ||
93 __le16_to_cpu(la.l2_psm) == 0x0003) 92 __le16_to_cpu(la.l2_psm) == L2CAP_PSM_RFCOMM)
94 chan->sec_level = BT_SECURITY_SDP; 93 chan->sec_level = BT_SECURITY_SDP;
95 94
96 bacpy(&bt_sk(sk)->src, &la.l2_bdaddr); 95 bacpy(&bt_sk(sk)->src, &la.l2_bdaddr);
@@ -446,6 +445,22 @@ static int l2cap_sock_getsockopt(struct socket *sock, int level, int optname, ch
446 return err; 445 return err;
447} 446}
448 447
448static bool l2cap_valid_mtu(struct l2cap_chan *chan, u16 mtu)
449{
450 switch (chan->scid) {
451 case L2CAP_CID_LE_DATA:
452 if (mtu < L2CAP_LE_MIN_MTU)
453 return false;
454 break;
455
456 default:
457 if (mtu < L2CAP_DEFAULT_MIN_MTU)
458 return false;
459 }
460
461 return true;
462}
463
449static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __user *optval, unsigned int optlen) 464static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __user *optval, unsigned int optlen)
450{ 465{
451 struct sock *sk = sock->sk; 466 struct sock *sk = sock->sk;
@@ -484,6 +499,11 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
484 break; 499 break;
485 } 500 }
486 501
502 if (!l2cap_valid_mtu(chan, opts.imtu)) {
503 err = -EINVAL;
504 break;
505 }
506
487 chan->mode = opts.mode; 507 chan->mode = opts.mode;
488 switch (chan->mode) { 508 switch (chan->mode) {
489 case L2CAP_MODE_BASIC: 509 case L2CAP_MODE_BASIC:
@@ -873,9 +893,34 @@ static int l2cap_sock_release(struct socket *sock)
873 return err; 893 return err;
874} 894}
875 895
876static struct l2cap_chan *l2cap_sock_new_connection_cb(void *data) 896static void l2cap_sock_cleanup_listen(struct sock *parent)
877{ 897{
878 struct sock *sk, *parent = data; 898 struct sock *sk;
899
900 BT_DBG("parent %p", parent);
901
902 /* Close not yet accepted channels */
903 while ((sk = bt_accept_dequeue(parent, NULL))) {
904 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
905
906 l2cap_chan_lock(chan);
907 __clear_chan_timer(chan);
908 l2cap_chan_close(chan, ECONNRESET);
909 l2cap_chan_unlock(chan);
910
911 l2cap_sock_kill(sk);
912 }
913}
914
915static struct l2cap_chan *l2cap_sock_new_connection_cb(struct l2cap_chan *chan)
916{
917 struct sock *sk, *parent = chan->data;
918
919 /* Check for backlog size */
920 if (sk_acceptq_is_full(parent)) {
921 BT_DBG("backlog full %d", parent->sk_ack_backlog);
922 return NULL;
923 }
879 924
880 sk = l2cap_sock_alloc(sock_net(parent), NULL, BTPROTO_L2CAP, 925 sk = l2cap_sock_alloc(sock_net(parent), NULL, BTPROTO_L2CAP,
881 GFP_ATOMIC); 926 GFP_ATOMIC);
@@ -889,10 +934,10 @@ static struct l2cap_chan *l2cap_sock_new_connection_cb(void *data)
889 return l2cap_pi(sk)->chan; 934 return l2cap_pi(sk)->chan;
890} 935}
891 936
892static int l2cap_sock_recv_cb(void *data, struct sk_buff *skb) 937static int l2cap_sock_recv_cb(struct l2cap_chan *chan, struct sk_buff *skb)
893{ 938{
894 int err; 939 int err;
895 struct sock *sk = data; 940 struct sock *sk = chan->data;
896 struct l2cap_pinfo *pi = l2cap_pi(sk); 941 struct l2cap_pinfo *pi = l2cap_pi(sk);
897 942
898 lock_sock(sk); 943 lock_sock(sk);
@@ -925,16 +970,57 @@ done:
925 return err; 970 return err;
926} 971}
927 972
928static void l2cap_sock_close_cb(void *data) 973static void l2cap_sock_close_cb(struct l2cap_chan *chan)
929{ 974{
930 struct sock *sk = data; 975 struct sock *sk = chan->data;
931 976
932 l2cap_sock_kill(sk); 977 l2cap_sock_kill(sk);
933} 978}
934 979
935static void l2cap_sock_state_change_cb(void *data, int state) 980static void l2cap_sock_teardown_cb(struct l2cap_chan *chan, int err)
936{ 981{
937 struct sock *sk = data; 982 struct sock *sk = chan->data;
983 struct sock *parent;
984
985 lock_sock(sk);
986
987 parent = bt_sk(sk)->parent;
988
989 sock_set_flag(sk, SOCK_ZAPPED);
990
991 switch (chan->state) {
992 case BT_OPEN:
993 case BT_BOUND:
994 case BT_CLOSED:
995 break;
996 case BT_LISTEN:
997 l2cap_sock_cleanup_listen(sk);
998 sk->sk_state = BT_CLOSED;
999 chan->state = BT_CLOSED;
1000
1001 break;
1002 default:
1003 sk->sk_state = BT_CLOSED;
1004 chan->state = BT_CLOSED;
1005
1006 sk->sk_err = err;
1007
1008 if (parent) {
1009 bt_accept_unlink(sk);
1010 parent->sk_data_ready(parent, 0);
1011 } else {
1012 sk->sk_state_change(sk);
1013 }
1014
1015 break;
1016 }
1017
1018 release_sock(sk);
1019}
1020
1021static void l2cap_sock_state_change_cb(struct l2cap_chan *chan, int state)
1022{
1023 struct sock *sk = chan->data;
938 1024
939 sk->sk_state = state; 1025 sk->sk_state = state;
940} 1026}
@@ -955,12 +1041,34 @@ static struct sk_buff *l2cap_sock_alloc_skb_cb(struct l2cap_chan *chan,
955 return skb; 1041 return skb;
956} 1042}
957 1043
1044static void l2cap_sock_ready_cb(struct l2cap_chan *chan)
1045{
1046 struct sock *sk = chan->data;
1047 struct sock *parent;
1048
1049 lock_sock(sk);
1050
1051 parent = bt_sk(sk)->parent;
1052
1053 BT_DBG("sk %p, parent %p", sk, parent);
1054
1055 sk->sk_state = BT_CONNECTED;
1056 sk->sk_state_change(sk);
1057
1058 if (parent)
1059 parent->sk_data_ready(parent, 0);
1060
1061 release_sock(sk);
1062}
1063
958static struct l2cap_ops l2cap_chan_ops = { 1064static struct l2cap_ops l2cap_chan_ops = {
959 .name = "L2CAP Socket Interface", 1065 .name = "L2CAP Socket Interface",
960 .new_connection = l2cap_sock_new_connection_cb, 1066 .new_connection = l2cap_sock_new_connection_cb,
961 .recv = l2cap_sock_recv_cb, 1067 .recv = l2cap_sock_recv_cb,
962 .close = l2cap_sock_close_cb, 1068 .close = l2cap_sock_close_cb,
1069 .teardown = l2cap_sock_teardown_cb,
963 .state_change = l2cap_sock_state_change_cb, 1070 .state_change = l2cap_sock_state_change_cb,
1071 .ready = l2cap_sock_ready_cb,
964 .alloc_skb = l2cap_sock_alloc_skb_cb, 1072 .alloc_skb = l2cap_sock_alloc_skb_cb,
965}; 1073};
966 1074
diff --git a/net/bluetooth/lib.c b/net/bluetooth/lib.c
index 506628876f36..e1c97527e16c 100644
--- a/net/bluetooth/lib.c
+++ b/net/bluetooth/lib.c
@@ -26,12 +26,7 @@
26 26
27#define pr_fmt(fmt) "Bluetooth: " fmt 27#define pr_fmt(fmt) "Bluetooth: " fmt
28 28
29#include <linux/module.h> 29#include <linux/export.h>
30
31#include <linux/kernel.h>
32#include <linux/stddef.h>
33#include <linux/string.h>
34#include <asm/errno.h>
35 30
36#include <net/bluetooth/bluetooth.h> 31#include <net/bluetooth/bluetooth.h>
37 32
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 991d5b667674..c72307cc25fc 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -24,8 +24,6 @@
24 24
25/* Bluetooth HCI Management interface */ 25/* Bluetooth HCI Management interface */
26 26
27#include <linux/kernel.h>
28#include <linux/uaccess.h>
29#include <linux/module.h> 27#include <linux/module.h>
30#include <asm/unaligned.h> 28#include <asm/unaligned.h>
31 29
@@ -714,7 +712,8 @@ static struct pending_cmd *mgmt_pending_add(struct sock *sk, u16 opcode,
714} 712}
715 713
716static void mgmt_pending_foreach(u16 opcode, struct hci_dev *hdev, 714static void mgmt_pending_foreach(u16 opcode, struct hci_dev *hdev,
717 void (*cb)(struct pending_cmd *cmd, void *data), 715 void (*cb)(struct pending_cmd *cmd,
716 void *data),
718 void *data) 717 void *data)
719{ 718{
720 struct list_head *p, *n; 719 struct list_head *p, *n;
@@ -871,7 +870,7 @@ static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,
871 } 870 }
872 871
873 if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || 872 if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) ||
874 mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { 873 mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) {
875 err = cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE, 874 err = cmd_status(sk, hdev->id, MGMT_OP_SET_DISCOVERABLE,
876 MGMT_STATUS_BUSY); 875 MGMT_STATUS_BUSY);
877 goto failed; 876 goto failed;
@@ -978,7 +977,7 @@ static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
978 } 977 }
979 978
980 if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) || 979 if (mgmt_pending_find(MGMT_OP_SET_DISCOVERABLE, hdev) ||
981 mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) { 980 mgmt_pending_find(MGMT_OP_SET_CONNECTABLE, hdev)) {
982 err = cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE, 981 err = cmd_status(sk, hdev->id, MGMT_OP_SET_CONNECTABLE,
983 MGMT_STATUS_BUSY); 982 MGMT_STATUS_BUSY);
984 goto failed; 983 goto failed;
@@ -1001,7 +1000,7 @@ static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
1001 scan = 0; 1000 scan = 0;
1002 1001
1003 if (test_bit(HCI_ISCAN, &hdev->flags) && 1002 if (test_bit(HCI_ISCAN, &hdev->flags) &&
1004 hdev->discov_timeout > 0) 1003 hdev->discov_timeout > 0)
1005 cancel_delayed_work(&hdev->discov_off); 1004 cancel_delayed_work(&hdev->discov_off);
1006 } 1005 }
1007 1006
@@ -1056,7 +1055,7 @@ static int set_link_security(struct sock *sk, struct hci_dev *hdev, void *data,
1056 bool changed = false; 1055 bool changed = false;
1057 1056
1058 if (!!cp->val != test_bit(HCI_LINK_SECURITY, 1057 if (!!cp->val != test_bit(HCI_LINK_SECURITY,
1059 &hdev->dev_flags)) { 1058 &hdev->dev_flags)) {
1060 change_bit(HCI_LINK_SECURITY, &hdev->dev_flags); 1059 change_bit(HCI_LINK_SECURITY, &hdev->dev_flags);
1061 changed = true; 1060 changed = true;
1062 } 1061 }
@@ -1317,7 +1316,7 @@ static bool enable_service_cache(struct hci_dev *hdev)
1317} 1316}
1318 1317
1319static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data, 1318static int remove_uuid(struct sock *sk, struct hci_dev *hdev, void *data,
1320 u16 len) 1319 u16 len)
1321{ 1320{
1322 struct mgmt_cp_remove_uuid *cp = data; 1321 struct mgmt_cp_remove_uuid *cp = data;
1323 struct pending_cmd *cmd; 1322 struct pending_cmd *cmd;
@@ -1442,7 +1441,7 @@ unlock:
1442} 1441}
1443 1442
1444static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data, 1443static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,
1445 u16 len) 1444 u16 len)
1446{ 1445{
1447 struct mgmt_cp_load_link_keys *cp = data; 1446 struct mgmt_cp_load_link_keys *cp = data;
1448 u16 key_count, expected_len; 1447 u16 key_count, expected_len;
@@ -1454,13 +1453,13 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,
1454 sizeof(struct mgmt_link_key_info); 1453 sizeof(struct mgmt_link_key_info);
1455 if (expected_len != len) { 1454 if (expected_len != len) {
1456 BT_ERR("load_link_keys: expected %u bytes, got %u bytes", 1455 BT_ERR("load_link_keys: expected %u bytes, got %u bytes",
1457 len, expected_len); 1456 len, expected_len);
1458 return cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 1457 return cmd_status(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS,
1459 MGMT_STATUS_INVALID_PARAMS); 1458 MGMT_STATUS_INVALID_PARAMS);
1460 } 1459 }
1461 1460
1462 BT_DBG("%s debug_keys %u key_count %u", hdev->name, cp->debug_keys, 1461 BT_DBG("%s debug_keys %u key_count %u", hdev->name, cp->debug_keys,
1463 key_count); 1462 key_count);
1464 1463
1465 hci_dev_lock(hdev); 1464 hci_dev_lock(hdev);
1466 1465
@@ -1535,10 +1534,10 @@ static int unpair_device(struct sock *sk, struct hci_dev *hdev, void *data,
1535 if (cp->disconnect) { 1534 if (cp->disconnect) {
1536 if (cp->addr.type == BDADDR_BREDR) 1535 if (cp->addr.type == BDADDR_BREDR)
1537 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, 1536 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK,
1538 &cp->addr.bdaddr); 1537 &cp->addr.bdaddr);
1539 else 1538 else
1540 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, 1539 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK,
1541 &cp->addr.bdaddr); 1540 &cp->addr.bdaddr);
1542 } else { 1541 } else {
1543 conn = NULL; 1542 conn = NULL;
1544 } 1543 }
@@ -1594,7 +1593,8 @@ static int disconnect(struct sock *sk, struct hci_dev *hdev, void *data,
1594 } 1593 }
1595 1594
1596 if (cp->addr.type == BDADDR_BREDR) 1595 if (cp->addr.type == BDADDR_BREDR)
1597 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->addr.bdaddr); 1596 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK,
1597 &cp->addr.bdaddr);
1598 else 1598 else
1599 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr); 1599 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->addr.bdaddr);
1600 1600
@@ -1813,7 +1813,7 @@ static int set_io_capability(struct sock *sk, struct hci_dev *hdev, void *data,
1813 hdev->io_capability = cp->io_capability; 1813 hdev->io_capability = cp->io_capability;
1814 1814
1815 BT_DBG("%s IO capability set to 0x%02x", hdev->name, 1815 BT_DBG("%s IO capability set to 0x%02x", hdev->name,
1816 hdev->io_capability); 1816 hdev->io_capability);
1817 1817
1818 hci_dev_unlock(hdev); 1818 hci_dev_unlock(hdev);
1819 1819
@@ -1821,7 +1821,7 @@ static int set_io_capability(struct sock *sk, struct hci_dev *hdev, void *data,
1821 0); 1821 0);
1822} 1822}
1823 1823
1824static inline struct pending_cmd *find_pairing(struct hci_conn *conn) 1824static struct pending_cmd *find_pairing(struct hci_conn *conn)
1825{ 1825{
1826 struct hci_dev *hdev = conn->hdev; 1826 struct hci_dev *hdev = conn->hdev;
1827 struct pending_cmd *cmd; 1827 struct pending_cmd *cmd;
@@ -1927,8 +1927,15 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
1927 rp.addr.type = cp->addr.type; 1927 rp.addr.type = cp->addr.type;
1928 1928
1929 if (IS_ERR(conn)) { 1929 if (IS_ERR(conn)) {
1930 int status;
1931
1932 if (PTR_ERR(conn) == -EBUSY)
1933 status = MGMT_STATUS_BUSY;
1934 else
1935 status = MGMT_STATUS_CONNECT_FAILED;
1936
1930 err = cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE, 1937 err = cmd_complete(sk, hdev->id, MGMT_OP_PAIR_DEVICE,
1931 MGMT_STATUS_CONNECT_FAILED, &rp, 1938 status, &rp,
1932 sizeof(rp)); 1939 sizeof(rp));
1933 goto unlock; 1940 goto unlock;
1934 } 1941 }
@@ -1959,7 +1966,7 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,
1959 cmd->user_data = conn; 1966 cmd->user_data = conn;
1960 1967
1961 if (conn->state == BT_CONNECTED && 1968 if (conn->state == BT_CONNECTED &&
1962 hci_conn_security(conn, sec_level, auth_type)) 1969 hci_conn_security(conn, sec_level, auth_type))
1963 pairing_complete(cmd, 0); 1970 pairing_complete(cmd, 0);
1964 1971
1965 err = 0; 1972 err = 0;
@@ -2256,7 +2263,7 @@ unlock:
2256} 2263}
2257 2264
2258static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev, 2265static int remove_remote_oob_data(struct sock *sk, struct hci_dev *hdev,
2259 void *data, u16 len) 2266 void *data, u16 len)
2260{ 2267{
2261 struct mgmt_cp_remove_remote_oob_data *cp = data; 2268 struct mgmt_cp_remove_remote_oob_data *cp = data;
2262 u8 status; 2269 u8 status;
@@ -2425,7 +2432,7 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
2425 2432
2426 case DISCOVERY_RESOLVING: 2433 case DISCOVERY_RESOLVING:
2427 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, 2434 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY,
2428 NAME_PENDING); 2435 NAME_PENDING);
2429 if (!e) { 2436 if (!e) {
2430 mgmt_pending_remove(cmd); 2437 mgmt_pending_remove(cmd);
2431 err = cmd_complete(sk, hdev->id, 2438 err = cmd_complete(sk, hdev->id,
@@ -2647,7 +2654,7 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
2647 sizeof(struct mgmt_ltk_info); 2654 sizeof(struct mgmt_ltk_info);
2648 if (expected_len != len) { 2655 if (expected_len != len) {
2649 BT_ERR("load_keys: expected %u bytes, got %u bytes", 2656 BT_ERR("load_keys: expected %u bytes, got %u bytes",
2650 len, expected_len); 2657 len, expected_len);
2651 return cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS, 2658 return cmd_status(sk, hdev->id, MGMT_OP_LOAD_LONG_TERM_KEYS,
2652 EINVAL); 2659 EINVAL);
2653 } 2660 }
@@ -2772,7 +2779,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
2772 } 2779 }
2773 2780
2774 if (opcode >= ARRAY_SIZE(mgmt_handlers) || 2781 if (opcode >= ARRAY_SIZE(mgmt_handlers) ||
2775 mgmt_handlers[opcode].func == NULL) { 2782 mgmt_handlers[opcode].func == NULL) {
2776 BT_DBG("Unknown op %u", opcode); 2783 BT_DBG("Unknown op %u", opcode);
2777 err = cmd_status(sk, index, opcode, 2784 err = cmd_status(sk, index, opcode,
2778 MGMT_STATUS_UNKNOWN_COMMAND); 2785 MGMT_STATUS_UNKNOWN_COMMAND);
@@ -2780,7 +2787,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
2780 } 2787 }
2781 2788
2782 if ((hdev && opcode < MGMT_OP_READ_INFO) || 2789 if ((hdev && opcode < MGMT_OP_READ_INFO) ||
2783 (!hdev && opcode >= MGMT_OP_READ_INFO)) { 2790 (!hdev && opcode >= MGMT_OP_READ_INFO)) {
2784 err = cmd_status(sk, index, opcode, 2791 err = cmd_status(sk, index, opcode,
2785 MGMT_STATUS_INVALID_INDEX); 2792 MGMT_STATUS_INVALID_INDEX);
2786 goto done; 2793 goto done;
@@ -2789,7 +2796,7 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
2789 handler = &mgmt_handlers[opcode]; 2796 handler = &mgmt_handlers[opcode];
2790 2797
2791 if ((handler->var_len && len < handler->data_len) || 2798 if ((handler->var_len && len < handler->data_len) ||
2792 (!handler->var_len && len != handler->data_len)) { 2799 (!handler->var_len && len != handler->data_len)) {
2793 err = cmd_status(sk, index, opcode, 2800 err = cmd_status(sk, index, opcode,
2794 MGMT_STATUS_INVALID_PARAMS); 2801 MGMT_STATUS_INVALID_PARAMS);
2795 goto done; 2802 goto done;
@@ -2973,7 +2980,7 @@ int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
2973 bacpy(&ev.key.addr.bdaddr, &key->bdaddr); 2980 bacpy(&ev.key.addr.bdaddr, &key->bdaddr);
2974 ev.key.addr.type = BDADDR_BREDR; 2981 ev.key.addr.type = BDADDR_BREDR;
2975 ev.key.type = key->type; 2982 ev.key.type = key->type;
2976 memcpy(ev.key.val, key->val, 16); 2983 memcpy(ev.key.val, key->val, HCI_LINK_KEY_SIZE);
2977 ev.key.pin_len = key->pin_len; 2984 ev.key.pin_len = key->pin_len;
2978 2985
2979 return mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL); 2986 return mgmt_event(MGMT_EV_NEW_LINK_KEY, hdev, &ev, sizeof(ev), NULL);
@@ -3108,7 +3115,7 @@ int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
3108 mgmt_pending_remove(cmd); 3115 mgmt_pending_remove(cmd);
3109 3116
3110 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp, 3117 mgmt_pending_foreach(MGMT_OP_UNPAIR_DEVICE, hdev, unpair_device_rsp,
3111 hdev); 3118 hdev);
3112 return err; 3119 return err;
3113} 3120}
3114 3121
@@ -3198,7 +3205,7 @@ int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
3198} 3205}
3199 3206
3200int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 3207int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
3201 u8 link_type, u8 addr_type) 3208 u8 link_type, u8 addr_type)
3202{ 3209{
3203 struct mgmt_ev_user_passkey_request ev; 3210 struct mgmt_ev_user_passkey_request ev;
3204 3211
@@ -3212,8 +3219,8 @@ int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
3212} 3219}
3213 3220
3214static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 3221static int user_pairing_resp_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3215 u8 link_type, u8 addr_type, u8 status, 3222 u8 link_type, u8 addr_type, u8 status,
3216 u8 opcode) 3223 u8 opcode)
3217{ 3224{
3218 struct pending_cmd *cmd; 3225 struct pending_cmd *cmd;
3219 struct mgmt_rp_user_confirm_reply rp; 3226 struct mgmt_rp_user_confirm_reply rp;
@@ -3244,7 +3251,8 @@ int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3244 u8 link_type, u8 addr_type, u8 status) 3251 u8 link_type, u8 addr_type, u8 status)
3245{ 3252{
3246 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, 3253 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type,
3247 status, MGMT_OP_USER_CONFIRM_NEG_REPLY); 3254 status,
3255 MGMT_OP_USER_CONFIRM_NEG_REPLY);
3248} 3256}
3249 3257
3250int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 3258int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
@@ -3258,7 +3266,8 @@ int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
3258 u8 link_type, u8 addr_type, u8 status) 3266 u8 link_type, u8 addr_type, u8 status)
3259{ 3267{
3260 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type, 3268 return user_pairing_resp_complete(hdev, bdaddr, link_type, addr_type,
3261 status, MGMT_OP_USER_PASSKEY_NEG_REPLY); 3269 status,
3270 MGMT_OP_USER_PASSKEY_NEG_REPLY);
3262} 3271}
3263 3272
3264int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 3273int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index 8a602388f1e7..c75107ef8920 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -26,22 +26,8 @@
26 */ 26 */
27 27
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/errno.h>
30#include <linux/kernel.h>
31#include <linux/sched.h>
32#include <linux/signal.h>
33#include <linux/init.h>
34#include <linux/wait.h>
35#include <linux/device.h>
36#include <linux/debugfs.h> 29#include <linux/debugfs.h>
37#include <linux/seq_file.h>
38#include <linux/net.h>
39#include <linux/mutex.h>
40#include <linux/kthread.h> 30#include <linux/kthread.h>
41#include <linux/slab.h>
42
43#include <net/sock.h>
44#include <linux/uaccess.h>
45#include <asm/unaligned.h> 31#include <asm/unaligned.h>
46 32
47#include <net/bluetooth/bluetooth.h> 33#include <net/bluetooth/bluetooth.h>
@@ -115,14 +101,14 @@ static void rfcomm_session_del(struct rfcomm_session *s);
115#define __get_rpn_stop_bits(line) (((line) >> 2) & 0x1) 101#define __get_rpn_stop_bits(line) (((line) >> 2) & 0x1)
116#define __get_rpn_parity(line) (((line) >> 3) & 0x7) 102#define __get_rpn_parity(line) (((line) >> 3) & 0x7)
117 103
118static inline void rfcomm_schedule(void) 104static void rfcomm_schedule(void)
119{ 105{
120 if (!rfcomm_thread) 106 if (!rfcomm_thread)
121 return; 107 return;
122 wake_up_process(rfcomm_thread); 108 wake_up_process(rfcomm_thread);
123} 109}
124 110
125static inline void rfcomm_session_put(struct rfcomm_session *s) 111static void rfcomm_session_put(struct rfcomm_session *s)
126{ 112{
127 if (atomic_dec_and_test(&s->refcnt)) 113 if (atomic_dec_and_test(&s->refcnt))
128 rfcomm_session_del(s); 114 rfcomm_session_del(s);
@@ -227,7 +213,7 @@ static int rfcomm_l2sock_create(struct socket **sock)
227 return err; 213 return err;
228} 214}
229 215
230static inline int rfcomm_check_security(struct rfcomm_dlc *d) 216static int rfcomm_check_security(struct rfcomm_dlc *d)
231{ 217{
232 struct sock *sk = d->session->sock->sk; 218 struct sock *sk = d->session->sock->sk;
233 struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn; 219 struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn;
@@ -1750,7 +1736,7 @@ static void rfcomm_process_connect(struct rfcomm_session *s)
1750/* Send data queued for the DLC. 1736/* Send data queued for the DLC.
1751 * Return number of frames left in the queue. 1737 * Return number of frames left in the queue.
1752 */ 1738 */
1753static inline int rfcomm_process_tx(struct rfcomm_dlc *d) 1739static int rfcomm_process_tx(struct rfcomm_dlc *d)
1754{ 1740{
1755 struct sk_buff *skb; 1741 struct sk_buff *skb;
1756 int err; 1742 int err;
@@ -1798,7 +1784,7 @@ static inline int rfcomm_process_tx(struct rfcomm_dlc *d)
1798 return skb_queue_len(&d->tx_queue); 1784 return skb_queue_len(&d->tx_queue);
1799} 1785}
1800 1786
1801static inline void rfcomm_process_dlcs(struct rfcomm_session *s) 1787static void rfcomm_process_dlcs(struct rfcomm_session *s)
1802{ 1788{
1803 struct rfcomm_dlc *d; 1789 struct rfcomm_dlc *d;
1804 struct list_head *p, *n; 1790 struct list_head *p, *n;
@@ -1858,7 +1844,7 @@ static inline void rfcomm_process_dlcs(struct rfcomm_session *s)
1858 } 1844 }
1859} 1845}
1860 1846
1861static inline void rfcomm_process_rx(struct rfcomm_session *s) 1847static void rfcomm_process_rx(struct rfcomm_session *s)
1862{ 1848{
1863 struct socket *sock = s->sock; 1849 struct socket *sock = s->sock;
1864 struct sock *sk = sock->sk; 1850 struct sock *sk = sock->sk;
@@ -1883,7 +1869,7 @@ static inline void rfcomm_process_rx(struct rfcomm_session *s)
1883 } 1869 }
1884} 1870}
1885 1871
1886static inline void rfcomm_accept_connection(struct rfcomm_session *s) 1872static void rfcomm_accept_connection(struct rfcomm_session *s)
1887{ 1873{
1888 struct socket *sock = s->sock, *nsock; 1874 struct socket *sock = s->sock, *nsock;
1889 int err; 1875 int err;
@@ -1917,7 +1903,7 @@ static inline void rfcomm_accept_connection(struct rfcomm_session *s)
1917 sock_release(nsock); 1903 sock_release(nsock);
1918} 1904}
1919 1905
1920static inline void rfcomm_check_connection(struct rfcomm_session *s) 1906static void rfcomm_check_connection(struct rfcomm_session *s)
1921{ 1907{
1922 struct sock *sk = s->sock->sk; 1908 struct sock *sk = s->sock->sk;
1923 1909
@@ -1941,7 +1927,7 @@ static inline void rfcomm_check_connection(struct rfcomm_session *s)
1941 } 1927 }
1942} 1928}
1943 1929
1944static inline void rfcomm_process_sessions(void) 1930static void rfcomm_process_sessions(void)
1945{ 1931{
1946 struct list_head *p, *n; 1932 struct list_head *p, *n;
1947 1933
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index e8707debb864..7e1e59645c05 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -25,27 +25,8 @@
25 * RFCOMM sockets. 25 * RFCOMM sockets.
26 */ 26 */
27 27
28#include <linux/module.h> 28#include <linux/export.h>
29
30#include <linux/types.h>
31#include <linux/errno.h>
32#include <linux/kernel.h>
33#include <linux/sched.h>
34#include <linux/slab.h>
35#include <linux/poll.h>
36#include <linux/fcntl.h>
37#include <linux/init.h>
38#include <linux/interrupt.h>
39#include <linux/socket.h>
40#include <linux/skbuff.h>
41#include <linux/list.h>
42#include <linux/device.h>
43#include <linux/debugfs.h> 29#include <linux/debugfs.h>
44#include <linux/seq_file.h>
45#include <linux/security.h>
46#include <net/sock.h>
47
48#include <linux/uaccess.h>
49 30
50#include <net/bluetooth/bluetooth.h> 31#include <net/bluetooth/bluetooth.h>
51#include <net/bluetooth/hci_core.h> 32#include <net/bluetooth/hci_core.h>
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index d1820ff14aee..cb960773c002 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -31,11 +31,6 @@
31#include <linux/tty_driver.h> 31#include <linux/tty_driver.h>
32#include <linux/tty_flip.h> 32#include <linux/tty_flip.h>
33 33
34#include <linux/capability.h>
35#include <linux/slab.h>
36#include <linux/skbuff.h>
37#include <linux/workqueue.h>
38
39#include <net/bluetooth/bluetooth.h> 34#include <net/bluetooth/bluetooth.h>
40#include <net/bluetooth/hci_core.h> 35#include <net/bluetooth/hci_core.h>
41#include <net/bluetooth/rfcomm.h> 36#include <net/bluetooth/rfcomm.h>
@@ -132,7 +127,7 @@ static struct rfcomm_dev *__rfcomm_dev_get(int id)
132 return NULL; 127 return NULL;
133} 128}
134 129
135static inline struct rfcomm_dev *rfcomm_dev_get(int id) 130static struct rfcomm_dev *rfcomm_dev_get(int id)
136{ 131{
137 struct rfcomm_dev *dev; 132 struct rfcomm_dev *dev;
138 133
@@ -345,7 +340,7 @@ static void rfcomm_wfree(struct sk_buff *skb)
345 tty_port_put(&dev->port); 340 tty_port_put(&dev->port);
346} 341}
347 342
348static inline void rfcomm_set_owner_w(struct sk_buff *skb, struct rfcomm_dev *dev) 343static void rfcomm_set_owner_w(struct sk_buff *skb, struct rfcomm_dev *dev)
349{ 344{
350 tty_port_get(&dev->port); 345 tty_port_get(&dev->port);
351 atomic_add(skb->truesize, &dev->wmem_alloc); 346 atomic_add(skb->truesize, &dev->wmem_alloc);
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index cbdd313659a7..40bbe25dcff7 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -25,26 +25,8 @@
25/* Bluetooth SCO sockets. */ 25/* Bluetooth SCO sockets. */
26 26
27#include <linux/module.h> 27#include <linux/module.h>
28
29#include <linux/types.h>
30#include <linux/errno.h>
31#include <linux/kernel.h>
32#include <linux/sched.h>
33#include <linux/slab.h>
34#include <linux/poll.h>
35#include <linux/fcntl.h>
36#include <linux/init.h>
37#include <linux/interrupt.h>
38#include <linux/socket.h>
39#include <linux/skbuff.h>
40#include <linux/device.h>
41#include <linux/debugfs.h> 28#include <linux/debugfs.h>
42#include <linux/seq_file.h> 29#include <linux/seq_file.h>
43#include <linux/list.h>
44#include <linux/security.h>
45#include <net/sock.h>
46
47#include <linux/uaccess.h>
48 30
49#include <net/bluetooth/bluetooth.h> 31#include <net/bluetooth/bluetooth.h>
50#include <net/bluetooth/hci_core.h> 32#include <net/bluetooth/hci_core.h>
@@ -123,7 +105,7 @@ static struct sco_conn *sco_conn_add(struct hci_conn *hcon)
123 return conn; 105 return conn;
124} 106}
125 107
126static inline struct sock *sco_chan_get(struct sco_conn *conn) 108static struct sock *sco_chan_get(struct sco_conn *conn)
127{ 109{
128 struct sock *sk = NULL; 110 struct sock *sk = NULL;
129 sco_conn_lock(conn); 111 sco_conn_lock(conn);
@@ -157,7 +139,8 @@ static int sco_conn_del(struct hci_conn *hcon, int err)
157 return 0; 139 return 0;
158} 140}
159 141
160static inline int sco_chan_add(struct sco_conn *conn, struct sock *sk, struct sock *parent) 142static int sco_chan_add(struct sco_conn *conn, struct sock *sk,
143 struct sock *parent)
161{ 144{
162 int err = 0; 145 int err = 0;
163 146
@@ -228,7 +211,7 @@ done:
228 return err; 211 return err;
229} 212}
230 213
231static inline int sco_send_frame(struct sock *sk, struct msghdr *msg, int len) 214static int sco_send_frame(struct sock *sk, struct msghdr *msg, int len)
232{ 215{
233 struct sco_conn *conn = sco_pi(sk)->conn; 216 struct sco_conn *conn = sco_pi(sk)->conn;
234 struct sk_buff *skb; 217 struct sk_buff *skb;
@@ -254,7 +237,7 @@ static inline int sco_send_frame(struct sock *sk, struct msghdr *msg, int len)
254 return len; 237 return len;
255} 238}
256 239
257static inline void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb) 240static void sco_recv_frame(struct sco_conn *conn, struct sk_buff *skb)
258{ 241{
259 struct sock *sk = sco_chan_get(conn); 242 struct sock *sk = sco_chan_get(conn);
260 243
@@ -523,7 +506,7 @@ static int sco_sock_connect(struct socket *sock, struct sockaddr *addr, int alen
523 goto done; 506 goto done;
524 507
525 err = bt_sock_wait_state(sk, BT_CONNECTED, 508 err = bt_sock_wait_state(sk, BT_CONNECTED,
526 sock_sndtimeo(sk, flags & O_NONBLOCK)); 509 sock_sndtimeo(sk, flags & O_NONBLOCK));
527 510
528done: 511done:
529 release_sock(sk); 512 release_sock(sk);
@@ -788,7 +771,7 @@ static int sco_sock_shutdown(struct socket *sock, int how)
788 771
789 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime) 772 if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
790 err = bt_sock_wait_state(sk, BT_CLOSED, 773 err = bt_sock_wait_state(sk, BT_CLOSED,
791 sk->sk_lingertime); 774 sk->sk_lingertime);
792 } 775 }
793 release_sock(sk); 776 release_sock(sk);
794 return err; 777 return err;
@@ -878,7 +861,7 @@ static void sco_conn_ready(struct sco_conn *conn)
878 bh_lock_sock(parent); 861 bh_lock_sock(parent);
879 862
880 sk = sco_sock_alloc(sock_net(parent), NULL, 863 sk = sco_sock_alloc(sock_net(parent), NULL,
881 BTPROTO_SCO, GFP_ATOMIC); 864 BTPROTO_SCO, GFP_ATOMIC);
882 if (!sk) { 865 if (!sk) {
883 bh_unlock_sock(parent); 866 bh_unlock_sock(parent);
884 goto done; 867 goto done;
@@ -907,7 +890,7 @@ done:
907/* ----- SCO interface with lower layer (HCI) ----- */ 890/* ----- SCO interface with lower layer (HCI) ----- */
908int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr) 891int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr)
909{ 892{
910 register struct sock *sk; 893 struct sock *sk;
911 struct hlist_node *node; 894 struct hlist_node *node;
912 int lm = 0; 895 int lm = 0;
913 896
@@ -920,7 +903,7 @@ int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr)
920 continue; 903 continue;
921 904
922 if (!bacmp(&bt_sk(sk)->src, &hdev->bdaddr) || 905 if (!bacmp(&bt_sk(sk)->src, &hdev->bdaddr) ||
923 !bacmp(&bt_sk(sk)->src, BDADDR_ANY)) { 906 !bacmp(&bt_sk(sk)->src, BDADDR_ANY)) {
924 lm |= HCI_LM_ACCEPT; 907 lm |= HCI_LM_ACCEPT;
925 break; 908 break;
926 } 909 }
@@ -981,7 +964,7 @@ static int sco_debugfs_show(struct seq_file *f, void *p)
981 964
982 sk_for_each(sk, node, &sco_sk_list.head) { 965 sk_for_each(sk, node, &sco_sk_list.head) {
983 seq_printf(f, "%s %s %d\n", batostr(&bt_sk(sk)->src), 966 seq_printf(f, "%s %s %d\n", batostr(&bt_sk(sk)->src),
984 batostr(&bt_sk(sk)->dst), sk->sk_state); 967 batostr(&bt_sk(sk)->dst), sk->sk_state);
985 } 968 }
986 969
987 read_unlock(&sco_sk_list.lock); 970 read_unlock(&sco_sk_list.lock);
@@ -1044,8 +1027,8 @@ int __init sco_init(void)
1044 } 1027 }
1045 1028
1046 if (bt_debugfs) { 1029 if (bt_debugfs) {
1047 sco_debugfs = debugfs_create_file("sco", 0444, 1030 sco_debugfs = debugfs_create_file("sco", 0444, bt_debugfs,
1048 bt_debugfs, NULL, &sco_debugfs_fops); 1031 NULL, &sco_debugfs_fops);
1049 if (!sco_debugfs) 1032 if (!sco_debugfs)
1050 BT_ERR("Failed to create SCO debug file"); 1033 BT_ERR("Failed to create SCO debug file");
1051 } 1034 }
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 37df4e9b3896..16ef0dc85a0a 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -20,14 +20,15 @@
20 SOFTWARE IS DISCLAIMED. 20 SOFTWARE IS DISCLAIMED.
21*/ 21*/
22 22
23#include <linux/crypto.h>
24#include <linux/scatterlist.h>
25#include <crypto/b128ops.h>
26
23#include <net/bluetooth/bluetooth.h> 27#include <net/bluetooth/bluetooth.h>
24#include <net/bluetooth/hci_core.h> 28#include <net/bluetooth/hci_core.h>
25#include <net/bluetooth/l2cap.h> 29#include <net/bluetooth/l2cap.h>
26#include <net/bluetooth/mgmt.h> 30#include <net/bluetooth/mgmt.h>
27#include <net/bluetooth/smp.h> 31#include <net/bluetooth/smp.h>
28#include <linux/crypto.h>
29#include <linux/scatterlist.h>
30#include <crypto/b128ops.h>
31 32
32#define SMP_TIMEOUT msecs_to_jiffies(30000) 33#define SMP_TIMEOUT msecs_to_jiffies(30000)
33 34
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index fdf9e61d0651..72607174ea5a 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -417,72 +417,6 @@ static struct attribute_group netstat_group = {
417 .name = "statistics", 417 .name = "statistics",
418 .attrs = netstat_attrs, 418 .attrs = netstat_attrs,
419}; 419};
420
421#ifdef CONFIG_WIRELESS_EXT_SYSFS
422/* helper function that does all the locking etc for wireless stats */
423static ssize_t wireless_show(struct device *d, char *buf,
424 ssize_t (*format)(const struct iw_statistics *,
425 char *))
426{
427 struct net_device *dev = to_net_dev(d);
428 const struct iw_statistics *iw;
429 ssize_t ret = -EINVAL;
430
431 if (!rtnl_trylock())
432 return restart_syscall();
433 if (dev_isalive(dev)) {
434 iw = get_wireless_stats(dev);
435 if (iw)
436 ret = (*format)(iw, buf);
437 }
438 rtnl_unlock();
439
440 return ret;
441}
442
443/* show function template for wireless fields */
444#define WIRELESS_SHOW(name, field, format_string) \
445static ssize_t format_iw_##name(const struct iw_statistics *iw, char *buf) \
446{ \
447 return sprintf(buf, format_string, iw->field); \
448} \
449static ssize_t show_iw_##name(struct device *d, \
450 struct device_attribute *attr, char *buf) \
451{ \
452 return wireless_show(d, buf, format_iw_##name); \
453} \
454static DEVICE_ATTR(name, S_IRUGO, show_iw_##name, NULL)
455
456WIRELESS_SHOW(status, status, fmt_hex);
457WIRELESS_SHOW(link, qual.qual, fmt_dec);
458WIRELESS_SHOW(level, qual.level, fmt_dec);
459WIRELESS_SHOW(noise, qual.noise, fmt_dec);
460WIRELESS_SHOW(nwid, discard.nwid, fmt_dec);
461WIRELESS_SHOW(crypt, discard.code, fmt_dec);
462WIRELESS_SHOW(fragment, discard.fragment, fmt_dec);
463WIRELESS_SHOW(misc, discard.misc, fmt_dec);
464WIRELESS_SHOW(retries, discard.retries, fmt_dec);
465WIRELESS_SHOW(beacon, miss.beacon, fmt_dec);
466
467static struct attribute *wireless_attrs[] = {
468 &dev_attr_status.attr,
469 &dev_attr_link.attr,
470 &dev_attr_level.attr,
471 &dev_attr_noise.attr,
472 &dev_attr_nwid.attr,
473 &dev_attr_crypt.attr,
474 &dev_attr_fragment.attr,
475 &dev_attr_retries.attr,
476 &dev_attr_misc.attr,
477 &dev_attr_beacon.attr,
478 NULL
479};
480
481static struct attribute_group wireless_group = {
482 .name = "wireless",
483 .attrs = wireless_attrs,
484};
485#endif
486#endif /* CONFIG_SYSFS */ 420#endif /* CONFIG_SYSFS */
487 421
488#ifdef CONFIG_RPS 422#ifdef CONFIG_RPS
@@ -1463,14 +1397,6 @@ int netdev_register_kobject(struct net_device *net)
1463 groups++; 1397 groups++;
1464 1398
1465 *groups++ = &netstat_group; 1399 *groups++ = &netstat_group;
1466#ifdef CONFIG_WIRELESS_EXT_SYSFS
1467 if (net->ieee80211_ptr)
1468 *groups++ = &wireless_group;
1469#ifdef CONFIG_WIRELESS_EXT
1470 else if (net->wireless_handlers)
1471 *groups++ = &wireless_group;
1472#endif
1473#endif
1474#endif /* CONFIG_SYSFS */ 1400#endif /* CONFIG_SYSFS */
1475 1401
1476 error = device_add(dev); 1402 error = device_add(dev);
diff --git a/net/mac80211/Makefile b/net/mac80211/Makefile
index 3e9d931bba35..2b1470bac178 100644
--- a/net/mac80211/Makefile
+++ b/net/mac80211/Makefile
@@ -9,7 +9,6 @@ mac80211-y := \
9 scan.o offchannel.o \ 9 scan.o offchannel.o \
10 ht.o agg-tx.o agg-rx.o \ 10 ht.o agg-tx.o agg-rx.o \
11 ibss.o \ 11 ibss.o \
12 work.o \
13 iface.o \ 12 iface.o \
14 rate.o \ 13 rate.o \
15 michael.o \ 14 michael.o \
diff --git a/net/mac80211/agg-rx.c b/net/mac80211/agg-rx.c
index c649188314cc..32ef11d69798 100644
--- a/net/mac80211/agg-rx.c
+++ b/net/mac80211/agg-rx.c
@@ -74,18 +74,15 @@ void ___ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
74 74
75 RCU_INIT_POINTER(sta->ampdu_mlme.tid_rx[tid], NULL); 75 RCU_INIT_POINTER(sta->ampdu_mlme.tid_rx[tid], NULL);
76 76
77#ifdef CONFIG_MAC80211_HT_DEBUG 77 ht_vdbg("Rx BA session stop requested for %pM tid %u %s reason: %d\n",
78 printk(KERN_DEBUG 78 sta->sta.addr, tid,
79 "Rx BA session stop requested for %pM tid %u %s reason: %d\n", 79 initiator == WLAN_BACK_RECIPIENT ? "recipient" : "inititator",
80 sta->sta.addr, tid, 80 (int)reason);
81 initiator == WLAN_BACK_RECIPIENT ? "recipient" : "inititator",
82 (int)reason);
83#endif /* CONFIG_MAC80211_HT_DEBUG */
84 81
85 if (drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_STOP, 82 if (drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_STOP,
86 &sta->sta, tid, NULL, 0)) 83 &sta->sta, tid, NULL, 0))
87 printk(KERN_DEBUG "HW problem - can not stop rx " 84 pr_debug("HW problem - can not stop rx aggregation for tid %d\n",
88 "aggregation for tid %d\n", tid); 85 tid);
89 86
90 /* check if this is a self generated aggregation halt */ 87 /* check if this is a self generated aggregation halt */
91 if (initiator == WLAN_BACK_RECIPIENT && tx) 88 if (initiator == WLAN_BACK_RECIPIENT && tx)
@@ -160,9 +157,8 @@ static void sta_rx_agg_session_timer_expired(unsigned long data)
160 } 157 }
161 rcu_read_unlock(); 158 rcu_read_unlock();
162 159
163#ifdef CONFIG_MAC80211_HT_DEBUG 160 ht_vdbg("rx session timer expired on tid %d\n", (u16)*ptid);
164 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid); 161
165#endif
166 set_bit(*ptid, sta->ampdu_mlme.tid_rx_timer_expired); 162 set_bit(*ptid, sta->ampdu_mlme.tid_rx_timer_expired);
167 ieee80211_queue_work(&sta->local->hw, &sta->ampdu_mlme.work); 163 ieee80211_queue_work(&sta->local->hw, &sta->ampdu_mlme.work);
168} 164}
@@ -249,10 +245,7 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
249 status = WLAN_STATUS_REQUEST_DECLINED; 245 status = WLAN_STATUS_REQUEST_DECLINED;
250 246
251 if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) { 247 if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) {
252#ifdef CONFIG_MAC80211_HT_DEBUG 248 ht_vdbg("Suspend in progress - Denying ADDBA request\n");
253 printk(KERN_DEBUG "Suspend in progress. "
254 "Denying ADDBA request\n");
255#endif
256 goto end_no_lock; 249 goto end_no_lock;
257 } 250 }
258 251
@@ -324,10 +317,7 @@ void ieee80211_process_addba_request(struct ieee80211_local *local,
324 317
325 ret = drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_START, 318 ret = drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_START,
326 &sta->sta, tid, &start_seq_num, 0); 319 &sta->sta, tid, &start_seq_num, 0);
327#ifdef CONFIG_MAC80211_HT_DEBUG 320 ht_vdbg("Rx A-MPDU request on tid %d result %d\n", tid, ret);
328 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
329#endif /* CONFIG_MAC80211_HT_DEBUG */
330
331 if (ret) { 321 if (ret) {
332 kfree(tid_agg_rx->reorder_buf); 322 kfree(tid_agg_rx->reorder_buf);
333 kfree(tid_agg_rx->reorder_time); 323 kfree(tid_agg_rx->reorder_time);
diff --git a/net/mac80211/agg-tx.c b/net/mac80211/agg-tx.c
index 7cf07158805c..da07f01cfe4d 100644
--- a/net/mac80211/agg-tx.c
+++ b/net/mac80211/agg-tx.c
@@ -184,10 +184,8 @@ int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
184 184
185 spin_unlock_bh(&sta->lock); 185 spin_unlock_bh(&sta->lock);
186 186
187#ifdef CONFIG_MAC80211_HT_DEBUG 187 ht_vdbg("Tx BA session stop requested for %pM tid %u\n",
188 printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n", 188 sta->sta.addr, tid);
189 sta->sta.addr, tid);
190#endif /* CONFIG_MAC80211_HT_DEBUG */
191 189
192 del_timer_sync(&tid_tx->addba_resp_timer); 190 del_timer_sync(&tid_tx->addba_resp_timer);
193 del_timer_sync(&tid_tx->session_timer); 191 del_timer_sync(&tid_tx->session_timer);
@@ -253,17 +251,12 @@ static void sta_addba_resp_timer_expired(unsigned long data)
253 if (!tid_tx || 251 if (!tid_tx ||
254 test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state)) { 252 test_bit(HT_AGG_STATE_RESPONSE_RECEIVED, &tid_tx->state)) {
255 rcu_read_unlock(); 253 rcu_read_unlock();
256#ifdef CONFIG_MAC80211_HT_DEBUG 254 ht_vdbg("timer expired on tid %d but we are not (or no longer) expecting addBA response there\n",
257 printk(KERN_DEBUG "timer expired on tid %d but we are not "
258 "(or no longer) expecting addBA response there\n",
259 tid); 255 tid);
260#endif
261 return; 256 return;
262 } 257 }
263 258
264#ifdef CONFIG_MAC80211_HT_DEBUG 259 ht_vdbg("addBA response timer expired on tid %d\n", tid);
265 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
266#endif
267 260
268 ieee80211_stop_tx_ba_session(&sta->sta, tid); 261 ieee80211_stop_tx_ba_session(&sta->sta, tid);
269 rcu_read_unlock(); 262 rcu_read_unlock();
@@ -372,10 +365,7 @@ void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
372 ret = drv_ampdu_action(local, sdata, IEEE80211_AMPDU_TX_START, 365 ret = drv_ampdu_action(local, sdata, IEEE80211_AMPDU_TX_START,
373 &sta->sta, tid, &start_seq_num, 0); 366 &sta->sta, tid, &start_seq_num, 0);
374 if (ret) { 367 if (ret) {
375#ifdef CONFIG_MAC80211_HT_DEBUG 368 ht_vdbg("BA request denied - HW unavailable for tid %d\n", tid);
376 printk(KERN_DEBUG "BA request denied - HW unavailable for"
377 " tid %d\n", tid);
378#endif
379 spin_lock_bh(&sta->lock); 369 spin_lock_bh(&sta->lock);
380 ieee80211_agg_splice_packets(sdata, tid_tx, tid); 370 ieee80211_agg_splice_packets(sdata, tid_tx, tid);
381 ieee80211_assign_tid_tx(sta, tid, NULL); 371 ieee80211_assign_tid_tx(sta, tid, NULL);
@@ -388,9 +378,7 @@ void ieee80211_tx_ba_session_handle_start(struct sta_info *sta, int tid)
388 378
389 /* activate the timer for the recipient's addBA response */ 379 /* activate the timer for the recipient's addBA response */
390 mod_timer(&tid_tx->addba_resp_timer, jiffies + ADDBA_RESP_INTERVAL); 380 mod_timer(&tid_tx->addba_resp_timer, jiffies + ADDBA_RESP_INTERVAL);
391#ifdef CONFIG_MAC80211_HT_DEBUG 381 ht_vdbg("activated addBA response timer on tid %d\n", tid);
392 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
393#endif
394 382
395 spin_lock_bh(&sta->lock); 383 spin_lock_bh(&sta->lock);
396 sta->ampdu_mlme.last_addba_req_time[tid] = jiffies; 384 sta->ampdu_mlme.last_addba_req_time[tid] = jiffies;
@@ -437,9 +425,7 @@ static void sta_tx_agg_session_timer_expired(unsigned long data)
437 425
438 rcu_read_unlock(); 426 rcu_read_unlock();
439 427
440#ifdef CONFIG_MAC80211_HT_DEBUG 428 ht_vdbg("tx session timer expired on tid %d\n", (u16)*ptid);
441 printk(KERN_DEBUG "tx session timer expired on tid %d\n", (u16)*ptid);
442#endif
443 429
444 ieee80211_stop_tx_ba_session(&sta->sta, *ptid); 430 ieee80211_stop_tx_ba_session(&sta->sta, *ptid);
445} 431}
@@ -463,10 +449,8 @@ int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
463 (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)) 449 (local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW))
464 return -EINVAL; 450 return -EINVAL;
465 451
466#ifdef CONFIG_MAC80211_HT_DEBUG 452 ht_vdbg("Open BA session requested for %pM tid %u\n",
467 printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n", 453 pubsta->addr, tid);
468 pubsta->addr, tid);
469#endif /* CONFIG_MAC80211_HT_DEBUG */
470 454
471 if (sdata->vif.type != NL80211_IFTYPE_STATION && 455 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
472 sdata->vif.type != NL80211_IFTYPE_MESH_POINT && 456 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
@@ -476,10 +460,7 @@ int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
476 return -EINVAL; 460 return -EINVAL;
477 461
478 if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) { 462 if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) {
479#ifdef CONFIG_MAC80211_HT_DEBUG 463 ht_vdbg("BA sessions blocked - Denying BA session request\n");
480 printk(KERN_DEBUG "BA sessions blocked. "
481 "Denying BA session request\n");
482#endif
483 return -EINVAL; 464 return -EINVAL;
484 } 465 }
485 466
@@ -497,10 +478,8 @@ int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
497 */ 478 */
498 if (sta->sdata->vif.type == NL80211_IFTYPE_ADHOC && 479 if (sta->sdata->vif.type == NL80211_IFTYPE_ADHOC &&
499 !sta->sta.ht_cap.ht_supported) { 480 !sta->sta.ht_cap.ht_supported) {
500#ifdef CONFIG_MAC80211_HT_DEBUG 481 ht_vdbg("BA request denied - IBSS STA %pM does not advertise HT support\n",
501 printk(KERN_DEBUG "BA request denied - IBSS STA %pM" 482 pubsta->addr);
502 "does not advertise HT support\n", pubsta->addr);
503#endif /* CONFIG_MAC80211_HT_DEBUG */
504 return -EINVAL; 483 return -EINVAL;
505 } 484 }
506 485
@@ -520,12 +499,8 @@ int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
520 if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_BURST_RETRIES && 499 if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_BURST_RETRIES &&
521 time_before(jiffies, sta->ampdu_mlme.last_addba_req_time[tid] + 500 time_before(jiffies, sta->ampdu_mlme.last_addba_req_time[tid] +
522 HT_AGG_RETRIES_PERIOD)) { 501 HT_AGG_RETRIES_PERIOD)) {
523#ifdef CONFIG_MAC80211_HT_DEBUG 502 ht_vdbg("BA request denied - waiting a grace period after %d failed requests on tid %u\n",
524 printk(KERN_DEBUG "BA request denied - " 503 sta->ampdu_mlme.addba_req_num[tid], tid);
525 "waiting a grace period after %d failed requests "
526 "on tid %u\n",
527 sta->ampdu_mlme.addba_req_num[tid], tid);
528#endif /* CONFIG_MAC80211_HT_DEBUG */
529 ret = -EBUSY; 504 ret = -EBUSY;
530 goto err_unlock_sta; 505 goto err_unlock_sta;
531 } 506 }
@@ -533,10 +508,8 @@ int ieee80211_start_tx_ba_session(struct ieee80211_sta *pubsta, u16 tid,
533 tid_tx = rcu_dereference_protected_tid_tx(sta, tid); 508 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
534 /* check if the TID is not in aggregation flow already */ 509 /* check if the TID is not in aggregation flow already */
535 if (tid_tx || sta->ampdu_mlme.tid_start_tx[tid]) { 510 if (tid_tx || sta->ampdu_mlme.tid_start_tx[tid]) {
536#ifdef CONFIG_MAC80211_HT_DEBUG 511 ht_vdbg("BA request denied - session is not idle on tid %u\n",
537 printk(KERN_DEBUG "BA request denied - session is not " 512 tid);
538 "idle on tid %u\n", tid);
539#endif /* CONFIG_MAC80211_HT_DEBUG */
540 ret = -EAGAIN; 513 ret = -EAGAIN;
541 goto err_unlock_sta; 514 goto err_unlock_sta;
542 } 515 }
@@ -591,9 +564,7 @@ static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
591 564
592 tid_tx = rcu_dereference_protected_tid_tx(sta, tid); 565 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
593 566
594#ifdef CONFIG_MAC80211_HT_DEBUG 567 ht_vdbg("Aggregation is on for tid %d\n", tid);
595 printk(KERN_DEBUG "Aggregation is on for tid %d\n", tid);
596#endif
597 568
598 drv_ampdu_action(local, sta->sdata, 569 drv_ampdu_action(local, sta->sdata,
599 IEEE80211_AMPDU_TX_OPERATIONAL, 570 IEEE80211_AMPDU_TX_OPERATIONAL,
@@ -627,10 +598,7 @@ void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid)
627 trace_api_start_tx_ba_cb(sdata, ra, tid); 598 trace_api_start_tx_ba_cb(sdata, ra, tid);
628 599
629 if (tid >= STA_TID_NUM) { 600 if (tid >= STA_TID_NUM) {
630#ifdef CONFIG_MAC80211_HT_DEBUG 601 ht_vdbg("Bad TID value: tid = %d (>= %d)\n", tid, STA_TID_NUM);
631 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
632 tid, STA_TID_NUM);
633#endif
634 return; 602 return;
635 } 603 }
636 604
@@ -638,9 +606,7 @@ void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid)
638 sta = sta_info_get_bss(sdata, ra); 606 sta = sta_info_get_bss(sdata, ra);
639 if (!sta) { 607 if (!sta) {
640 mutex_unlock(&local->sta_mtx); 608 mutex_unlock(&local->sta_mtx);
641#ifdef CONFIG_MAC80211_HT_DEBUG 609 ht_vdbg("Could not find station: %pM\n", ra);
642 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
643#endif
644 return; 610 return;
645 } 611 }
646 612
@@ -648,9 +614,7 @@ void ieee80211_start_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u16 tid)
648 tid_tx = rcu_dereference_protected_tid_tx(sta, tid); 614 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
649 615
650 if (WARN_ON(!tid_tx)) { 616 if (WARN_ON(!tid_tx)) {
651#ifdef CONFIG_MAC80211_HT_DEBUG 617 ht_vdbg("addBA was not requested!\n");
652 printk(KERN_DEBUG "addBA was not requested!\n");
653#endif
654 goto unlock; 618 goto unlock;
655 } 619 }
656 620
@@ -750,25 +714,17 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid)
750 trace_api_stop_tx_ba_cb(sdata, ra, tid); 714 trace_api_stop_tx_ba_cb(sdata, ra, tid);
751 715
752 if (tid >= STA_TID_NUM) { 716 if (tid >= STA_TID_NUM) {
753#ifdef CONFIG_MAC80211_HT_DEBUG 717 ht_vdbg("Bad TID value: tid = %d (>= %d)\n", tid, STA_TID_NUM);
754 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
755 tid, STA_TID_NUM);
756#endif
757 return; 718 return;
758 } 719 }
759 720
760#ifdef CONFIG_MAC80211_HT_DEBUG 721 ht_vdbg("Stopping Tx BA session for %pM tid %d\n", ra, tid);
761 printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n",
762 ra, tid);
763#endif /* CONFIG_MAC80211_HT_DEBUG */
764 722
765 mutex_lock(&local->sta_mtx); 723 mutex_lock(&local->sta_mtx);
766 724
767 sta = sta_info_get_bss(sdata, ra); 725 sta = sta_info_get_bss(sdata, ra);
768 if (!sta) { 726 if (!sta) {
769#ifdef CONFIG_MAC80211_HT_DEBUG 727 ht_vdbg("Could not find station: %pM\n", ra);
770 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
771#endif
772 goto unlock; 728 goto unlock;
773 } 729 }
774 730
@@ -777,9 +733,7 @@ void ieee80211_stop_tx_ba_cb(struct ieee80211_vif *vif, u8 *ra, u8 tid)
777 tid_tx = rcu_dereference_protected_tid_tx(sta, tid); 733 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
778 734
779 if (!tid_tx || !test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) { 735 if (!tid_tx || !test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
780#ifdef CONFIG_MAC80211_HT_DEBUG 736 ht_vdbg("unexpected callback to A-MPDU stop\n");
781 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
782#endif
783 goto unlock_sta; 737 goto unlock_sta;
784 } 738 }
785 739
@@ -855,17 +809,13 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local,
855 goto out; 809 goto out;
856 810
857 if (mgmt->u.action.u.addba_resp.dialog_token != tid_tx->dialog_token) { 811 if (mgmt->u.action.u.addba_resp.dialog_token != tid_tx->dialog_token) {
858#ifdef CONFIG_MAC80211_HT_DEBUG 812 ht_vdbg("wrong addBA response token, tid %d\n", tid);
859 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
860#endif
861 goto out; 813 goto out;
862 } 814 }
863 815
864 del_timer_sync(&tid_tx->addba_resp_timer); 816 del_timer_sync(&tid_tx->addba_resp_timer);
865 817
866#ifdef CONFIG_MAC80211_HT_DEBUG 818 ht_vdbg("switched off addBA timer for tid %d\n", tid);
867 printk(KERN_DEBUG "switched off addBA timer for tid %d\n", tid);
868#endif
869 819
870 /* 820 /*
871 * addba_resp_timer may have fired before we got here, and 821 * addba_resp_timer may have fired before we got here, and
@@ -874,11 +824,8 @@ void ieee80211_process_addba_resp(struct ieee80211_local *local,
874 */ 824 */
875 if (test_bit(HT_AGG_STATE_WANT_STOP, &tid_tx->state) || 825 if (test_bit(HT_AGG_STATE_WANT_STOP, &tid_tx->state) ||
876 test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) { 826 test_bit(HT_AGG_STATE_STOPPING, &tid_tx->state)) {
877#ifdef CONFIG_MAC80211_HT_DEBUG 827 ht_vdbg("got addBA resp for tid %d but we already gave up\n",
878 printk(KERN_DEBUG 828 tid);
879 "got addBA resp for tid %d but we already gave up\n",
880 tid);
881#endif
882 goto out; 829 goto out;
883 } 830 }
884 831
diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 7d5108a867ad..85ac364f4636 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -674,6 +674,48 @@ static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
674 return ret; 674 return ret;
675} 675}
676 676
677static int ieee80211_set_channel(struct wiphy *wiphy,
678 struct net_device *netdev,
679 struct ieee80211_channel *chan,
680 enum nl80211_channel_type channel_type)
681{
682 struct ieee80211_local *local = wiphy_priv(wiphy);
683 struct ieee80211_sub_if_data *sdata = NULL;
684
685 if (netdev)
686 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
687
688 switch (ieee80211_get_channel_mode(local, NULL)) {
689 case CHAN_MODE_HOPPING:
690 return -EBUSY;
691 case CHAN_MODE_FIXED:
692 if (local->oper_channel != chan)
693 return -EBUSY;
694 if (!sdata && local->_oper_channel_type == channel_type)
695 return 0;
696 break;
697 case CHAN_MODE_UNDEFINED:
698 break;
699 }
700
701 if (!ieee80211_set_channel_type(local, sdata, channel_type))
702 return -EBUSY;
703
704 local->oper_channel = chan;
705
706 /* auto-detects changes */
707 ieee80211_hw_config(local, 0);
708
709 return 0;
710}
711
712static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
713 struct ieee80211_channel *chan,
714 enum nl80211_channel_type channel_type)
715{
716 return ieee80211_set_channel(wiphy, NULL, chan, channel_type);
717}
718
677static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata, 719static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
678 const u8 *resp, size_t resp_len) 720 const u8 *resp, size_t resp_len)
679{ 721{
@@ -788,6 +830,11 @@ static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
788 if (old) 830 if (old)
789 return -EALREADY; 831 return -EALREADY;
790 832
833 err = ieee80211_set_channel(wiphy, dev, params->channel,
834 params->channel_type);
835 if (err)
836 return err;
837
791 /* 838 /*
792 * Apply control port protocol, this allows us to 839 * Apply control port protocol, this allows us to
793 * not encrypt dynamic WEP control frames. 840 * not encrypt dynamic WEP control frames.
@@ -1558,6 +1605,12 @@ static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1558 err = copy_mesh_setup(ifmsh, setup); 1605 err = copy_mesh_setup(ifmsh, setup);
1559 if (err) 1606 if (err)
1560 return err; 1607 return err;
1608
1609 err = ieee80211_set_channel(wiphy, dev, setup->channel,
1610 setup->channel_type);
1611 if (err)
1612 return err;
1613
1561 ieee80211_start_mesh(sdata); 1614 ieee80211_start_mesh(sdata);
1562 1615
1563 return 0; 1616 return 0;
@@ -1677,55 +1730,6 @@ static int ieee80211_set_txq_params(struct wiphy *wiphy,
1677 return 0; 1730 return 0;
1678} 1731}
1679 1732
1680static int ieee80211_set_channel(struct wiphy *wiphy,
1681 struct net_device *netdev,
1682 struct ieee80211_channel *chan,
1683 enum nl80211_channel_type channel_type)
1684{
1685 struct ieee80211_local *local = wiphy_priv(wiphy);
1686 struct ieee80211_sub_if_data *sdata = NULL;
1687 struct ieee80211_channel *old_oper;
1688 enum nl80211_channel_type old_oper_type;
1689 enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
1690
1691 if (netdev)
1692 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
1693
1694 switch (ieee80211_get_channel_mode(local, NULL)) {
1695 case CHAN_MODE_HOPPING:
1696 return -EBUSY;
1697 case CHAN_MODE_FIXED:
1698 if (local->oper_channel != chan)
1699 return -EBUSY;
1700 if (!sdata && local->_oper_channel_type == channel_type)
1701 return 0;
1702 break;
1703 case CHAN_MODE_UNDEFINED:
1704 break;
1705 }
1706
1707 if (sdata)
1708 old_vif_oper_type = sdata->vif.bss_conf.channel_type;
1709 old_oper_type = local->_oper_channel_type;
1710
1711 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1712 return -EBUSY;
1713
1714 old_oper = local->oper_channel;
1715 local->oper_channel = chan;
1716
1717 /* Update driver if changes were actually made. */
1718 if ((old_oper != local->oper_channel) ||
1719 (old_oper_type != local->_oper_channel_type))
1720 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1721
1722 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR &&
1723 old_vif_oper_type != sdata->vif.bss_conf.channel_type)
1724 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1725
1726 return 0;
1727}
1728
1729#ifdef CONFIG_PM 1733#ifdef CONFIG_PM
1730static int ieee80211_suspend(struct wiphy *wiphy, 1734static int ieee80211_suspend(struct wiphy *wiphy,
1731 struct cfg80211_wowlan *wowlan) 1735 struct cfg80211_wowlan *wowlan)
@@ -2111,35 +2115,171 @@ static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2111 return 0; 2115 return 0;
2112} 2116}
2113 2117
2114static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local, 2118static int ieee80211_start_roc_work(struct ieee80211_local *local,
2115 struct net_device *dev, 2119 struct ieee80211_sub_if_data *sdata,
2116 struct ieee80211_channel *chan, 2120 struct ieee80211_channel *channel,
2117 enum nl80211_channel_type chantype, 2121 enum nl80211_channel_type channel_type,
2118 unsigned int duration, u64 *cookie) 2122 unsigned int duration, u64 *cookie,
2123 struct sk_buff *txskb)
2119{ 2124{
2125 struct ieee80211_roc_work *roc, *tmp;
2126 bool queued = false;
2120 int ret; 2127 int ret;
2121 u32 random_cookie;
2122 2128
2123 lockdep_assert_held(&local->mtx); 2129 lockdep_assert_held(&local->mtx);
2124 2130
2125 if (local->hw_roc_cookie) 2131 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2126 return -EBUSY; 2132 if (!roc)
2127 /* must be nonzero */ 2133 return -ENOMEM;
2128 random_cookie = random32() | 1; 2134
2129 2135 roc->chan = channel;
2130 *cookie = random_cookie; 2136 roc->chan_type = channel_type;
2131 local->hw_roc_dev = dev; 2137 roc->duration = duration;
2132 local->hw_roc_cookie = random_cookie; 2138 roc->req_duration = duration;
2133 local->hw_roc_channel = chan; 2139 roc->frame = txskb;
2134 local->hw_roc_channel_type = chantype; 2140 roc->mgmt_tx_cookie = (unsigned long)txskb;
2135 local->hw_roc_duration = duration; 2141 roc->sdata = sdata;
2136 ret = drv_remain_on_channel(local, chan, chantype, duration); 2142 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2143 INIT_LIST_HEAD(&roc->dependents);
2144
2145 /* if there's one pending or we're scanning, queue this one */
2146 if (!list_empty(&local->roc_list) || local->scanning)
2147 goto out_check_combine;
2148
2149 /* if not HW assist, just queue & schedule work */
2150 if (!local->ops->remain_on_channel) {
2151 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2152 goto out_queue;
2153 }
2154
2155 /* otherwise actually kick it off here (for error handling) */
2156
2157 /*
2158 * If the duration is zero, then the driver
2159 * wouldn't actually do anything. Set it to
2160 * 10 for now.
2161 *
2162 * TODO: cancel the off-channel operation
2163 * when we get the SKB's TX status and
2164 * the wait time was zero before.
2165 */
2166 if (!duration)
2167 duration = 10;
2168
2169 ret = drv_remain_on_channel(local, channel, channel_type, duration);
2137 if (ret) { 2170 if (ret) {
2138 local->hw_roc_channel = NULL; 2171 kfree(roc);
2139 local->hw_roc_cookie = 0; 2172 return ret;
2140 } 2173 }
2141 2174
2142 return ret; 2175 roc->started = true;
2176 goto out_queue;
2177
2178 out_check_combine:
2179 list_for_each_entry(tmp, &local->roc_list, list) {
2180 if (tmp->chan != channel || tmp->chan_type != channel_type)
2181 continue;
2182
2183 /*
2184 * Extend this ROC if possible:
2185 *
2186 * If it hasn't started yet, just increase the duration
2187 * and add the new one to the list of dependents.
2188 */
2189 if (!tmp->started) {
2190 list_add_tail(&roc->list, &tmp->dependents);
2191 tmp->duration = max(tmp->duration, roc->duration);
2192 queued = true;
2193 break;
2194 }
2195
2196 /* If it has already started, it's more difficult ... */
2197 if (local->ops->remain_on_channel) {
2198 unsigned long j = jiffies;
2199
2200 /*
2201 * In the offloaded ROC case, if it hasn't begun, add
2202 * this new one to the dependent list to be handled
2203 * when the the master one begins. If it has begun,
2204 * check that there's still a minimum time left and
2205 * if so, start this one, transmitting the frame, but
2206 * add it to the list directly after this one with a
2207 * a reduced time so we'll ask the driver to execute
2208 * it right after finishing the previous one, in the
2209 * hope that it'll also be executed right afterwards,
2210 * effectively extending the old one.
2211 * If there's no minimum time left, just add it to the
2212 * normal list.
2213 */
2214 if (!tmp->hw_begun) {
2215 list_add_tail(&roc->list, &tmp->dependents);
2216 queued = true;
2217 break;
2218 }
2219
2220 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2221 tmp->hw_start_time +
2222 msecs_to_jiffies(tmp->duration))) {
2223 int new_dur;
2224
2225 ieee80211_handle_roc_started(roc);
2226
2227 new_dur = roc->duration -
2228 jiffies_to_msecs(tmp->hw_start_time +
2229 msecs_to_jiffies(
2230 tmp->duration) -
2231 j);
2232
2233 if (new_dur > 0) {
2234 /* add right after tmp */
2235 list_add(&roc->list, &tmp->list);
2236 } else {
2237 list_add_tail(&roc->list,
2238 &tmp->dependents);
2239 }
2240 queued = true;
2241 }
2242 } else if (del_timer_sync(&tmp->work.timer)) {
2243 unsigned long new_end;
2244
2245 /*
2246 * In the software ROC case, cancel the timer, if
2247 * that fails then the finish work is already
2248 * queued/pending and thus we queue the new ROC
2249 * normally, if that succeeds then we can extend
2250 * the timer duration and TX the frame (if any.)
2251 */
2252
2253 list_add_tail(&roc->list, &tmp->dependents);
2254 queued = true;
2255
2256 new_end = jiffies + msecs_to_jiffies(roc->duration);
2257
2258 /* ok, it was started & we canceled timer */
2259 if (time_after(new_end, tmp->work.timer.expires))
2260 mod_timer(&tmp->work.timer, new_end);
2261 else
2262 add_timer(&tmp->work.timer);
2263
2264 ieee80211_handle_roc_started(roc);
2265 }
2266 break;
2267 }
2268
2269 out_queue:
2270 if (!queued)
2271 list_add_tail(&roc->list, &local->roc_list);
2272
2273 /*
2274 * cookie is either the roc (for normal roc)
2275 * or the SKB (for mgmt TX)
2276 */
2277 if (txskb)
2278 *cookie = (unsigned long)txskb;
2279 else
2280 *cookie = (unsigned long)roc;
2281
2282 return 0;
2143} 2283}
2144 2284
2145static int ieee80211_remain_on_channel(struct wiphy *wiphy, 2285static int ieee80211_remain_on_channel(struct wiphy *wiphy,
@@ -2151,42 +2291,64 @@ static int ieee80211_remain_on_channel(struct wiphy *wiphy,
2151{ 2291{
2152 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2292 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2153 struct ieee80211_local *local = sdata->local; 2293 struct ieee80211_local *local = sdata->local;
2294 int ret;
2154 2295
2155 if (local->ops->remain_on_channel) { 2296 mutex_lock(&local->mtx);
2156 int ret; 2297 ret = ieee80211_start_roc_work(local, sdata, chan, channel_type,
2157 2298 duration, cookie, NULL);
2158 mutex_lock(&local->mtx); 2299 mutex_unlock(&local->mtx);
2159 ret = ieee80211_remain_on_channel_hw(local, dev,
2160 chan, channel_type,
2161 duration, cookie);
2162 local->hw_roc_for_tx = false;
2163 mutex_unlock(&local->mtx);
2164
2165 return ret;
2166 }
2167 2300
2168 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type, 2301 return ret;
2169 duration, cookie);
2170} 2302}
2171 2303
2172static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local, 2304static int ieee80211_cancel_roc(struct ieee80211_local *local,
2173 u64 cookie) 2305 u64 cookie, bool mgmt_tx)
2174{ 2306{
2307 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2175 int ret; 2308 int ret;
2176 2309
2177 lockdep_assert_held(&local->mtx); 2310 mutex_lock(&local->mtx);
2311 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
2312 if (!mgmt_tx && (unsigned long)roc != cookie)
2313 continue;
2314 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2315 continue;
2316
2317 found = roc;
2318 break;
2319 }
2178 2320
2179 if (local->hw_roc_cookie != cookie) 2321 if (!found) {
2322 mutex_unlock(&local->mtx);
2180 return -ENOENT; 2323 return -ENOENT;
2324 }
2181 2325
2182 ret = drv_cancel_remain_on_channel(local); 2326 if (local->ops->remain_on_channel) {
2183 if (ret) 2327 if (found->started) {
2184 return ret; 2328 ret = drv_cancel_remain_on_channel(local);
2329 if (WARN_ON_ONCE(ret)) {
2330 mutex_unlock(&local->mtx);
2331 return ret;
2332 }
2333 }
2185 2334
2186 local->hw_roc_cookie = 0; 2335 list_del(&found->list);
2187 local->hw_roc_channel = NULL;
2188 2336
2189 ieee80211_recalc_idle(local); 2337 ieee80211_run_deferred_scan(local);
2338 ieee80211_start_next_roc(local);
2339 mutex_unlock(&local->mtx);
2340
2341 ieee80211_roc_notify_destroy(found);
2342 } else {
2343 /* work may be pending so use it all the time */
2344 found->abort = true;
2345 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2346
2347 mutex_unlock(&local->mtx);
2348
2349 /* work will clean up etc */
2350 flush_delayed_work(&found->work);
2351 }
2190 2352
2191 return 0; 2353 return 0;
2192} 2354}
@@ -2198,39 +2360,7 @@ static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
2198 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2360 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2199 struct ieee80211_local *local = sdata->local; 2361 struct ieee80211_local *local = sdata->local;
2200 2362
2201 if (local->ops->cancel_remain_on_channel) { 2363 return ieee80211_cancel_roc(local, cookie, false);
2202 int ret;
2203
2204 mutex_lock(&local->mtx);
2205 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
2206 mutex_unlock(&local->mtx);
2207
2208 return ret;
2209 }
2210
2211 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
2212}
2213
2214static enum work_done_result
2215ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
2216{
2217 /*
2218 * Use the data embedded in the work struct for reporting
2219 * here so if the driver mangled the SKB before dropping
2220 * it (which is the only way we really should get here)
2221 * then we don't report mangled data.
2222 *
2223 * If there was no wait time, then by the time we get here
2224 * the driver will likely not have reported the status yet,
2225 * so in that case userspace will have to deal with it.
2226 */
2227
2228 if (wk->offchan_tx.wait && !wk->offchan_tx.status)
2229 cfg80211_mgmt_tx_status(wk->sdata->dev,
2230 (unsigned long) wk->offchan_tx.frame,
2231 wk->data, wk->data_len, false, GFP_KERNEL);
2232
2233 return WORK_DONE_DESTROY;
2234} 2364}
2235 2365
2236static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev, 2366static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
@@ -2244,10 +2374,10 @@ static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
2244 struct ieee80211_local *local = sdata->local; 2374 struct ieee80211_local *local = sdata->local;
2245 struct sk_buff *skb; 2375 struct sk_buff *skb;
2246 struct sta_info *sta; 2376 struct sta_info *sta;
2247 struct ieee80211_work *wk;
2248 const struct ieee80211_mgmt *mgmt = (void *)buf; 2377 const struct ieee80211_mgmt *mgmt = (void *)buf;
2378 bool need_offchan = false;
2249 u32 flags; 2379 u32 flags;
2250 bool is_offchan = false; 2380 int ret;
2251 2381
2252 if (dont_wait_for_ack) 2382 if (dont_wait_for_ack)
2253 flags = IEEE80211_TX_CTL_NO_ACK; 2383 flags = IEEE80211_TX_CTL_NO_ACK;
@@ -2255,33 +2385,28 @@ static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
2255 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX | 2385 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2256 IEEE80211_TX_CTL_REQ_TX_STATUS; 2386 IEEE80211_TX_CTL_REQ_TX_STATUS;
2257 2387
2258 /* Check that we are on the requested channel for transmission */
2259 if (chan != local->tmp_channel &&
2260 chan != local->oper_channel)
2261 is_offchan = true;
2262 if (channel_type_valid &&
2263 (channel_type != local->tmp_channel_type &&
2264 channel_type != local->_oper_channel_type))
2265 is_offchan = true;
2266
2267 if (chan == local->hw_roc_channel) {
2268 /* TODO: check channel type? */
2269 is_offchan = false;
2270 flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2271 }
2272
2273 if (no_cck) 2388 if (no_cck)
2274 flags |= IEEE80211_TX_CTL_NO_CCK_RATE; 2389 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2275 2390
2276 if (is_offchan && !offchan)
2277 return -EBUSY;
2278
2279 switch (sdata->vif.type) { 2391 switch (sdata->vif.type) {
2280 case NL80211_IFTYPE_ADHOC: 2392 case NL80211_IFTYPE_ADHOC:
2393 if (!sdata->vif.bss_conf.ibss_joined)
2394 need_offchan = true;
2395 /* fall through */
2396#ifdef CONFIG_MAC80211_MESH
2397 case NL80211_IFTYPE_MESH_POINT:
2398 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2399 !sdata->u.mesh.mesh_id_len)
2400 need_offchan = true;
2401 /* fall through */
2402#endif
2281 case NL80211_IFTYPE_AP: 2403 case NL80211_IFTYPE_AP:
2282 case NL80211_IFTYPE_AP_VLAN: 2404 case NL80211_IFTYPE_AP_VLAN:
2283 case NL80211_IFTYPE_P2P_GO: 2405 case NL80211_IFTYPE_P2P_GO:
2284 case NL80211_IFTYPE_MESH_POINT: 2406 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2407 !ieee80211_vif_is_mesh(&sdata->vif) &&
2408 !rcu_access_pointer(sdata->bss->beacon))
2409 need_offchan = true;
2285 if (!ieee80211_is_action(mgmt->frame_control) || 2410 if (!ieee80211_is_action(mgmt->frame_control) ||
2286 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) 2411 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
2287 break; 2412 break;
@@ -2293,103 +2418,60 @@ static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
2293 break; 2418 break;
2294 case NL80211_IFTYPE_STATION: 2419 case NL80211_IFTYPE_STATION:
2295 case NL80211_IFTYPE_P2P_CLIENT: 2420 case NL80211_IFTYPE_P2P_CLIENT:
2421 if (!sdata->u.mgd.associated)
2422 need_offchan = true;
2296 break; 2423 break;
2297 default: 2424 default:
2298 return -EOPNOTSUPP; 2425 return -EOPNOTSUPP;
2299 } 2426 }
2300 2427
2428 mutex_lock(&local->mtx);
2429
2430 /* Check if the operating channel is the requested channel */
2431 if (!need_offchan) {
2432 need_offchan = chan != local->oper_channel;
2433 if (channel_type_valid &&
2434 channel_type != local->_oper_channel_type)
2435 need_offchan = true;
2436 }
2437
2438 if (need_offchan && !offchan) {
2439 ret = -EBUSY;
2440 goto out_unlock;
2441 }
2442
2301 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len); 2443 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2302 if (!skb) 2444 if (!skb) {
2303 return -ENOMEM; 2445 ret = -ENOMEM;
2446 goto out_unlock;
2447 }
2304 skb_reserve(skb, local->hw.extra_tx_headroom); 2448 skb_reserve(skb, local->hw.extra_tx_headroom);
2305 2449
2306 memcpy(skb_put(skb, len), buf, len); 2450 memcpy(skb_put(skb, len), buf, len);
2307 2451
2308 IEEE80211_SKB_CB(skb)->flags = flags; 2452 IEEE80211_SKB_CB(skb)->flags = flags;
2309 2453
2310 if (flags & IEEE80211_TX_CTL_TX_OFFCHAN)
2311 IEEE80211_SKB_CB(skb)->hw_queue =
2312 local->hw.offchannel_tx_hw_queue;
2313
2314 skb->dev = sdata->dev; 2454 skb->dev = sdata->dev;
2315 2455
2316 *cookie = (unsigned long) skb; 2456 if (!need_offchan) {
2317 2457 ieee80211_tx_skb(sdata, skb);
2318 if (is_offchan && local->ops->remain_on_channel) { 2458 ret = 0;
2319 unsigned int duration; 2459 goto out_unlock;
2320 int ret; 2460 }
2321
2322 mutex_lock(&local->mtx);
2323 /*
2324 * If the duration is zero, then the driver
2325 * wouldn't actually do anything. Set it to
2326 * 100 for now.
2327 *
2328 * TODO: cancel the off-channel operation
2329 * when we get the SKB's TX status and
2330 * the wait time was zero before.
2331 */
2332 duration = 100;
2333 if (wait)
2334 duration = wait;
2335 ret = ieee80211_remain_on_channel_hw(local, dev, chan,
2336 channel_type,
2337 duration, cookie);
2338 if (ret) {
2339 kfree_skb(skb);
2340 mutex_unlock(&local->mtx);
2341 return ret;
2342 }
2343
2344 local->hw_roc_for_tx = true;
2345 local->hw_roc_duration = wait;
2346
2347 /*
2348 * queue up frame for transmission after
2349 * ieee80211_ready_on_channel call
2350 */
2351 2461
2352 /* modify cookie to prevent API mismatches */ 2462 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2353 *cookie ^= 2; 2463 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
2354 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2355 IEEE80211_SKB_CB(skb)->hw_queue = 2464 IEEE80211_SKB_CB(skb)->hw_queue =
2356 local->hw.offchannel_tx_hw_queue; 2465 local->hw.offchannel_tx_hw_queue;
2357 local->hw_roc_skb = skb;
2358 local->hw_roc_skb_for_status = skb;
2359 mutex_unlock(&local->mtx);
2360
2361 return 0;
2362 }
2363
2364 /*
2365 * Can transmit right away if the channel was the
2366 * right one and there's no wait involved... If a
2367 * wait is involved, we might otherwise not be on
2368 * the right channel for long enough!
2369 */
2370 if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
2371 ieee80211_tx_skb(sdata, skb);
2372 return 0;
2373 }
2374 2466
2375 wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL); 2467 /* This will handle all kinds of coalescing and immediate TX */
2376 if (!wk) { 2468 ret = ieee80211_start_roc_work(local, sdata, chan, channel_type,
2469 wait, cookie, skb);
2470 if (ret)
2377 kfree_skb(skb); 2471 kfree_skb(skb);
2378 return -ENOMEM; 2472 out_unlock:
2379 } 2473 mutex_unlock(&local->mtx);
2380 2474 return ret;
2381 wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
2382 wk->chan = chan;
2383 wk->chan_type = channel_type;
2384 wk->sdata = sdata;
2385 wk->done = ieee80211_offchan_tx_done;
2386 wk->offchan_tx.frame = skb;
2387 wk->offchan_tx.wait = wait;
2388 wk->data_len = len;
2389 memcpy(wk->data, buf, len);
2390
2391 ieee80211_add_work(wk);
2392 return 0;
2393} 2475}
2394 2476
2395static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy, 2477static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
@@ -2398,45 +2480,8 @@ static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
2398{ 2480{
2399 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); 2481 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2400 struct ieee80211_local *local = sdata->local; 2482 struct ieee80211_local *local = sdata->local;
2401 struct ieee80211_work *wk;
2402 int ret = -ENOENT;
2403
2404 mutex_lock(&local->mtx);
2405
2406 if (local->ops->cancel_remain_on_channel) {
2407 cookie ^= 2;
2408 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
2409
2410 if (ret == 0) {
2411 kfree_skb(local->hw_roc_skb);
2412 local->hw_roc_skb = NULL;
2413 local->hw_roc_skb_for_status = NULL;
2414 }
2415
2416 mutex_unlock(&local->mtx);
2417 2483
2418 return ret; 2484 return ieee80211_cancel_roc(local, cookie, true);
2419 }
2420
2421 list_for_each_entry(wk, &local->work_list, list) {
2422 if (wk->sdata != sdata)
2423 continue;
2424
2425 if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
2426 continue;
2427
2428 if (cookie != (unsigned long) wk->offchan_tx.frame)
2429 continue;
2430
2431 wk->timeout = jiffies;
2432
2433 ieee80211_queue_work(&local->hw, &local->work_work);
2434 ret = 0;
2435 break;
2436 }
2437 mutex_unlock(&local->mtx);
2438
2439 return ret;
2440} 2485}
2441 2486
2442static void ieee80211_mgmt_frame_register(struct wiphy *wiphy, 2487static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
@@ -2680,7 +2725,7 @@ static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2680 return -EINVAL; 2725 return -EINVAL;
2681 2726
2682#ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG 2727#ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2683 printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer); 2728 pr_debug("TDLS mgmt action %d peer %pM\n", action_code, peer);
2684#endif 2729#endif
2685 2730
2686 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 2731 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
@@ -2791,7 +2836,7 @@ static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2791 return -EINVAL; 2836 return -EINVAL;
2792 2837
2793#ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG 2838#ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2794 printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer); 2839 pr_debug("TDLS oper %d peer %pM\n", oper, peer);
2795#endif 2840#endif
2796 2841
2797 switch (oper) { 2842 switch (oper) {
@@ -2936,7 +2981,7 @@ struct cfg80211_ops mac80211_config_ops = {
2936#endif 2981#endif
2937 .change_bss = ieee80211_change_bss, 2982 .change_bss = ieee80211_change_bss,
2938 .set_txq_params = ieee80211_set_txq_params, 2983 .set_txq_params = ieee80211_set_txq_params,
2939 .set_channel = ieee80211_set_channel, 2984 .set_monitor_channel = ieee80211_set_monitor_channel,
2940 .suspend = ieee80211_suspend, 2985 .suspend = ieee80211_suspend,
2941 .resume = ieee80211_resume, 2986 .resume = ieee80211_resume,
2942 .scan = ieee80211_scan, 2987 .scan = ieee80211_scan,
diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
index c76cf7230c7d..f0f87e5a1d35 100644
--- a/net/mac80211/chan.c
+++ b/net/mac80211/chan.c
@@ -41,6 +41,10 @@ __ieee80211_get_channel_mode(struct ieee80211_local *local,
41 if (!sdata->u.ap.beacon) 41 if (!sdata->u.ap.beacon)
42 continue; 42 continue;
43 break; 43 break;
44 case NL80211_IFTYPE_MESH_POINT:
45 if (!sdata->wdev.mesh_id_len)
46 continue;
47 break;
44 default: 48 default:
45 break; 49 break;
46 } 50 }
diff --git a/net/mac80211/debugfs_netdev.c b/net/mac80211/debugfs_netdev.c
index 7ed433c66d68..d4272ff43f71 100644
--- a/net/mac80211/debugfs_netdev.c
+++ b/net/mac80211/debugfs_netdev.c
@@ -607,6 +607,7 @@ static void add_mesh_config(struct ieee80211_sub_if_data *sdata)
607 MESHPARAMS_ADD(min_discovery_timeout); 607 MESHPARAMS_ADD(min_discovery_timeout);
608 MESHPARAMS_ADD(dot11MeshHWMPRootMode); 608 MESHPARAMS_ADD(dot11MeshHWMPRootMode);
609 MESHPARAMS_ADD(dot11MeshHWMPRannInterval); 609 MESHPARAMS_ADD(dot11MeshHWMPRannInterval);
610 MESHPARAMS_ADD(dot11MeshForwarding);
610 MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol); 611 MESHPARAMS_ADD(dot11MeshGateAnnouncementProtocol);
611 MESHPARAMS_ADD(rssi_threshold); 612 MESHPARAMS_ADD(rssi_threshold);
612 MESHPARAMS_ADD(ht_opmode); 613 MESHPARAMS_ADD(ht_opmode);
@@ -685,6 +686,6 @@ void ieee80211_debugfs_rename_netdev(struct ieee80211_sub_if_data *sdata)
685 686
686 sprintf(buf, "netdev:%s", sdata->name); 687 sprintf(buf, "netdev:%s", sdata->name);
687 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf)) 688 if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
688 printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs " 689 pr_err("mac80211: debugfs: failed to rename debugfs "
689 "dir to %s\n", buf); 690 "dir to %s\n", buf);
690} 691}
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 33d9d0c3e3d0..725cb4be229d 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -82,8 +82,7 @@ static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
82 82
83 local->oper_channel = chan; 83 local->oper_channel = chan;
84 channel_type = ifibss->channel_type; 84 channel_type = ifibss->channel_type;
85 if (channel_type > NL80211_CHAN_HT20 && 85 if (!cfg80211_can_beacon_sec_chan(local->hw.wiphy, chan, channel_type))
86 !cfg80211_can_beacon_sec_chan(local->hw.wiphy, chan, channel_type))
87 channel_type = NL80211_CHAN_HT20; 86 channel_type = NL80211_CHAN_HT20;
88 if (!ieee80211_set_channel_type(local, sdata, channel_type)) { 87 if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
89 /* can only fail due to HT40+/- mismatch */ 88 /* can only fail due to HT40+/- mismatch */
@@ -281,11 +280,8 @@ static struct sta_info *ieee80211_ibss_finish_sta(struct sta_info *sta,
281 if (sta_info_insert_rcu(sta)) 280 if (sta_info_insert_rcu(sta))
282 return sta_info_get(sdata, addr); 281 return sta_info_get(sdata, addr);
283 if (auth) { 282 if (auth) {
284#ifdef CONFIG_MAC80211_IBSS_DEBUG 283 ibss_vdbg("TX Auth SA=%pM DA=%pM BSSID=%pM (auth_transaction=1)\n",
285 printk(KERN_DEBUG "TX Auth SA=%pM DA=%pM BSSID=%pM" 284 sdata->vif.addr, sdata->u.ibss.bssid, addr);
286 "(auth_transaction=1)\n", sdata->vif.addr,
287 sdata->u.ibss.bssid, addr);
288#endif
289 ieee80211_send_auth(sdata, 1, WLAN_AUTH_OPEN, NULL, 0, 285 ieee80211_send_auth(sdata, 1, WLAN_AUTH_OPEN, NULL, 0,
290 addr, sdata->u.ibss.bssid, NULL, 0, 0); 286 addr, sdata->u.ibss.bssid, NULL, 0, 0);
291 } 287 }
@@ -355,11 +351,9 @@ static void ieee80211_rx_mgmt_auth_ibss(struct ieee80211_sub_if_data *sdata,
355 351
356 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) 352 if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1)
357 return; 353 return;
358#ifdef CONFIG_MAC80211_IBSS_DEBUG 354 ibss_vdbg("%s: RX Auth SA=%pM DA=%pM BSSID=%pM (auth_transaction=%d)\n",
359 printk(KERN_DEBUG "%s: RX Auth SA=%pM DA=%pM BSSID=%pM." 355 sdata->name, mgmt->sa, mgmt->da, mgmt->bssid,
360 "(auth_transaction=%d)\n", 356 auth_transaction);
361 sdata->name, mgmt->sa, mgmt->da, mgmt->bssid, auth_transaction);
362#endif
363 sta_info_destroy_addr(sdata, mgmt->sa); 357 sta_info_destroy_addr(sdata, mgmt->sa);
364 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, 0, false); 358 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, 0, false);
365 rcu_read_unlock(); 359 rcu_read_unlock();
@@ -422,15 +416,10 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
422 ieee80211_mandatory_rates(local, band); 416 ieee80211_mandatory_rates(local, band);
423 417
424 if (sta->sta.supp_rates[band] != prev_rates) { 418 if (sta->sta.supp_rates[band] != prev_rates) {
425#ifdef CONFIG_MAC80211_IBSS_DEBUG 419 ibss_vdbg("%s: updated supp_rates set for %pM based on beacon/probe_resp (0x%x -> 0x%x)\n",
426 printk(KERN_DEBUG 420 sdata->name, sta->sta.addr,
427 "%s: updated supp_rates set " 421 prev_rates,
428 "for %pM based on beacon" 422 sta->sta.supp_rates[band]);
429 "/probe_resp (0x%x -> 0x%x)\n",
430 sdata->name, sta->sta.addr,
431 prev_rates,
432 sta->sta.supp_rates[band]);
433#endif
434 rates_updated = true; 423 rates_updated = true;
435 } 424 }
436 } else { 425 } else {
@@ -545,22 +534,16 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
545 rx_timestamp = drv_get_tsf(local, sdata); 534 rx_timestamp = drv_get_tsf(local, sdata);
546 } 535 }
547 536
548#ifdef CONFIG_MAC80211_IBSS_DEBUG 537 ibss_vdbg("RX beacon SA=%pM BSSID=%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n",
549 printk(KERN_DEBUG "RX beacon SA=%pM BSSID=" 538 mgmt->sa, mgmt->bssid,
550 "%pM TSF=0x%llx BCN=0x%llx diff=%lld @%lu\n", 539 (unsigned long long)rx_timestamp,
551 mgmt->sa, mgmt->bssid, 540 (unsigned long long)beacon_timestamp,
552 (unsigned long long)rx_timestamp, 541 (unsigned long long)(rx_timestamp - beacon_timestamp),
553 (unsigned long long)beacon_timestamp, 542 jiffies);
554 (unsigned long long)(rx_timestamp - beacon_timestamp),
555 jiffies);
556#endif
557 543
558 if (beacon_timestamp > rx_timestamp) { 544 if (beacon_timestamp > rx_timestamp) {
559#ifdef CONFIG_MAC80211_IBSS_DEBUG 545 ibss_vdbg("%s: beacon TSF higher than local TSF - IBSS merge with BSSID %pM\n",
560 printk(KERN_DEBUG "%s: beacon TSF higher than " 546 sdata->name, mgmt->bssid);
561 "local TSF - IBSS merge with BSSID %pM\n",
562 sdata->name, mgmt->bssid);
563#endif
564 ieee80211_sta_join_ibss(sdata, bss); 547 ieee80211_sta_join_ibss(sdata, bss);
565 supp_rates = ieee80211_sta_get_rates(local, elems, band, NULL); 548 supp_rates = ieee80211_sta_get_rates(local, elems, band, NULL);
566 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa, 549 ieee80211_ibss_add_sta(sdata, mgmt->bssid, mgmt->sa,
@@ -662,8 +645,8 @@ static void ieee80211_sta_merge_ibss(struct ieee80211_sub_if_data *sdata)
662 if (ifibss->fixed_channel) 645 if (ifibss->fixed_channel)
663 return; 646 return;
664 647
665 printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other " 648 pr_debug("%s: No active IBSS STAs - trying to scan for other IBSS networks with same SSID (merge)\n",
666 "IBSS networks with same SSID (merge)\n", sdata->name); 649 sdata->name);
667 650
668 ieee80211_request_internal_scan(sdata, 651 ieee80211_request_internal_scan(sdata,
669 ifibss->ssid, ifibss->ssid_len, NULL); 652 ifibss->ssid, ifibss->ssid_len, NULL);
@@ -691,8 +674,8 @@ static void ieee80211_sta_create_ibss(struct ieee80211_sub_if_data *sdata)
691 bssid[0] |= 0x02; 674 bssid[0] |= 0x02;
692 } 675 }
693 676
694 printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID %pM\n", 677 pr_debug("%s: Creating new IBSS network, BSSID %pM\n",
695 sdata->name, bssid); 678 sdata->name, bssid);
696 679
697 capability = WLAN_CAPABILITY_IBSS; 680 capability = WLAN_CAPABILITY_IBSS;
698 681
@@ -723,10 +706,8 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
723 lockdep_assert_held(&ifibss->mtx); 706 lockdep_assert_held(&ifibss->mtx);
724 707
725 active_ibss = ieee80211_sta_active_ibss(sdata); 708 active_ibss = ieee80211_sta_active_ibss(sdata);
726#ifdef CONFIG_MAC80211_IBSS_DEBUG 709 ibss_vdbg("%s: sta_find_ibss (active_ibss=%d)\n",
727 printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n", 710 sdata->name, active_ibss);
728 sdata->name, active_ibss);
729#endif /* CONFIG_MAC80211_IBSS_DEBUG */
730 711
731 if (active_ibss) 712 if (active_ibss)
732 return; 713 return;
@@ -749,29 +730,23 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
749 struct ieee80211_bss *bss; 730 struct ieee80211_bss *bss;
750 731
751 bss = (void *)cbss->priv; 732 bss = (void *)cbss->priv;
752#ifdef CONFIG_MAC80211_IBSS_DEBUG 733 ibss_vdbg(" sta_find_ibss: selected %pM current %pM\n",
753 printk(KERN_DEBUG " sta_find_ibss: selected %pM current " 734 cbss->bssid, ifibss->bssid);
754 "%pM\n", cbss->bssid, ifibss->bssid); 735 pr_debug("%s: Selected IBSS BSSID %pM based on configured SSID\n",
755#endif /* CONFIG_MAC80211_IBSS_DEBUG */ 736 sdata->name, cbss->bssid);
756
757 printk(KERN_DEBUG "%s: Selected IBSS BSSID %pM"
758 " based on configured SSID\n",
759 sdata->name, cbss->bssid);
760 737
761 ieee80211_sta_join_ibss(sdata, bss); 738 ieee80211_sta_join_ibss(sdata, bss);
762 ieee80211_rx_bss_put(local, bss); 739 ieee80211_rx_bss_put(local, bss);
763 return; 740 return;
764 } 741 }
765 742
766#ifdef CONFIG_MAC80211_IBSS_DEBUG 743 ibss_vdbg(" did not try to join ibss\n");
767 printk(KERN_DEBUG " did not try to join ibss\n");
768#endif /* CONFIG_MAC80211_IBSS_DEBUG */
769 744
770 /* Selected IBSS not found in current scan results - try to scan */ 745 /* Selected IBSS not found in current scan results - try to scan */
771 if (time_after(jiffies, ifibss->last_scan_completed + 746 if (time_after(jiffies, ifibss->last_scan_completed +
772 IEEE80211_SCAN_INTERVAL)) { 747 IEEE80211_SCAN_INTERVAL)) {
773 printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to " 748 pr_debug("%s: Trigger new scan to find an IBSS to join\n",
774 "join\n", sdata->name); 749 sdata->name);
775 750
776 ieee80211_request_internal_scan(sdata, 751 ieee80211_request_internal_scan(sdata,
777 ifibss->ssid, ifibss->ssid_len, 752 ifibss->ssid, ifibss->ssid_len,
@@ -785,9 +760,9 @@ static void ieee80211_sta_find_ibss(struct ieee80211_sub_if_data *sdata)
785 ieee80211_sta_create_ibss(sdata); 760 ieee80211_sta_create_ibss(sdata);
786 return; 761 return;
787 } 762 }
788 printk(KERN_DEBUG "%s: IBSS not allowed on" 763 pr_debug("%s: IBSS not allowed on %d MHz\n",
789 " %d MHz\n", sdata->name, 764 sdata->name,
790 local->hw.conf.channel->center_freq); 765 local->hw.conf.channel->center_freq);
791 766
792 /* No IBSS found - decrease scan interval and continue 767 /* No IBSS found - decrease scan interval and continue
793 * scanning. */ 768 * scanning. */
@@ -822,12 +797,9 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
822 797
823 tx_last_beacon = drv_tx_last_beacon(local); 798 tx_last_beacon = drv_tx_last_beacon(local);
824 799
825#ifdef CONFIG_MAC80211_IBSS_DEBUG 800 ibss_vdbg("%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM (tx_last_beacon=%d)\n",
826 printk(KERN_DEBUG "%s: RX ProbeReq SA=%pM DA=%pM BSSID=%pM" 801 sdata->name, mgmt->sa, mgmt->da,
827 " (tx_last_beacon=%d)\n", 802 mgmt->bssid, tx_last_beacon);
828 sdata->name, mgmt->sa, mgmt->da,
829 mgmt->bssid, tx_last_beacon);
830#endif /* CONFIG_MAC80211_IBSS_DEBUG */
831 803
832 if (!tx_last_beacon && is_multicast_ether_addr(mgmt->da)) 804 if (!tx_last_beacon && is_multicast_ether_addr(mgmt->da))
833 return; 805 return;
@@ -840,11 +812,8 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
840 pos = mgmt->u.probe_req.variable; 812 pos = mgmt->u.probe_req.variable;
841 if (pos[0] != WLAN_EID_SSID || 813 if (pos[0] != WLAN_EID_SSID ||
842 pos + 2 + pos[1] > end) { 814 pos + 2 + pos[1] > end) {
843#ifdef CONFIG_MAC80211_IBSS_DEBUG 815 ibss_vdbg("%s: Invalid SSID IE in ProbeReq from %pM\n",
844 printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq " 816 sdata->name, mgmt->sa);
845 "from %pM\n",
846 sdata->name, mgmt->sa);
847#endif
848 return; 817 return;
849 } 818 }
850 if (pos[1] != 0 && 819 if (pos[1] != 0 &&
@@ -861,10 +830,7 @@ static void ieee80211_rx_mgmt_probe_req(struct ieee80211_sub_if_data *sdata,
861 830
862 resp = (struct ieee80211_mgmt *) skb->data; 831 resp = (struct ieee80211_mgmt *) skb->data;
863 memcpy(resp->da, mgmt->sa, ETH_ALEN); 832 memcpy(resp->da, mgmt->sa, ETH_ALEN);
864#ifdef CONFIG_MAC80211_IBSS_DEBUG 833 ibss_vdbg("%s: Sending ProbeResp to %pM\n", sdata->name, resp->da);
865 printk(KERN_DEBUG "%s: Sending ProbeResp to %pM\n",
866 sdata->name, resp->da);
867#endif /* CONFIG_MAC80211_IBSS_DEBUG */
868 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 834 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
869 ieee80211_tx_skb(sdata, skb); 835 ieee80211_tx_skb(sdata, skb);
870} 836}
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 3f3cd50fff16..e6cbf5b68c89 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -317,55 +317,30 @@ struct mesh_preq_queue {
317 u8 flags; 317 u8 flags;
318}; 318};
319 319
320enum ieee80211_work_type { 320#if HZ/100 == 0
321 IEEE80211_WORK_ABORT, 321#define IEEE80211_ROC_MIN_LEFT 1
322 IEEE80211_WORK_REMAIN_ON_CHANNEL, 322#else
323 IEEE80211_WORK_OFFCHANNEL_TX, 323#define IEEE80211_ROC_MIN_LEFT (HZ/100)
324}; 324#endif
325
326/**
327 * enum work_done_result - indicates what to do after work was done
328 *
329 * @WORK_DONE_DESTROY: This work item is no longer needed, destroy.
330 * @WORK_DONE_REQUEUE: This work item was reset to be reused, and
331 * should be requeued.
332 */
333enum work_done_result {
334 WORK_DONE_DESTROY,
335 WORK_DONE_REQUEUE,
336};
337 325
338struct ieee80211_work { 326struct ieee80211_roc_work {
339 struct list_head list; 327 struct list_head list;
328 struct list_head dependents;
340 329
341 struct rcu_head rcu_head; 330 struct delayed_work work;
342 331
343 struct ieee80211_sub_if_data *sdata; 332 struct ieee80211_sub_if_data *sdata;
344 333
345 enum work_done_result (*done)(struct ieee80211_work *wk,
346 struct sk_buff *skb);
347
348 struct ieee80211_channel *chan; 334 struct ieee80211_channel *chan;
349 enum nl80211_channel_type chan_type; 335 enum nl80211_channel_type chan_type;
350 336
351 unsigned long timeout; 337 bool started, abort, hw_begun, notified;
352 enum ieee80211_work_type type;
353 338
354 bool started; 339 unsigned long hw_start_time;
355 340
356 union { 341 u32 duration, req_duration;
357 struct { 342 struct sk_buff *frame;
358 u32 duration; 343 u64 mgmt_tx_cookie;
359 } remain;
360 struct {
361 struct sk_buff *frame;
362 u32 wait;
363 bool status;
364 } offchan_tx;
365 };
366
367 size_t data_len;
368 u8 data[];
369}; 344};
370 345
371/* flags used in struct ieee80211_if_managed.flags */ 346/* flags used in struct ieee80211_if_managed.flags */
@@ -399,7 +374,6 @@ struct ieee80211_mgd_auth_data {
399struct ieee80211_mgd_assoc_data { 374struct ieee80211_mgd_assoc_data {
400 struct cfg80211_bss *bss; 375 struct cfg80211_bss *bss;
401 const u8 *supp_rates; 376 const u8 *supp_rates;
402 const u8 *ht_operation_ie;
403 377
404 unsigned long timeout; 378 unsigned long timeout;
405 int tries; 379 int tries;
@@ -414,6 +388,8 @@ struct ieee80211_mgd_assoc_data {
414 bool sent_assoc; 388 bool sent_assoc;
415 bool synced; 389 bool synced;
416 390
391 u8 ap_ht_param;
392
417 size_t ie_len; 393 size_t ie_len;
418 u8 ie[]; 394 u8 ie[];
419}; 395};
@@ -847,13 +823,6 @@ struct ieee80211_local {
847 const struct ieee80211_ops *ops; 823 const struct ieee80211_ops *ops;
848 824
849 /* 825 /*
850 * work stuff, potentially off-channel (in the future)
851 */
852 struct list_head work_list;
853 struct timer_list work_timer;
854 struct work_struct work_work;
855
856 /*
857 * private workqueue to mac80211. mac80211 makes this accessible 826 * private workqueue to mac80211. mac80211 makes this accessible
858 * via ieee80211_queue_work() 827 * via ieee80211_queue_work()
859 */ 828 */
@@ -1087,14 +1056,12 @@ struct ieee80211_local {
1087 } debugfs; 1056 } debugfs;
1088#endif 1057#endif
1089 1058
1090 struct ieee80211_channel *hw_roc_channel; 1059 /*
1091 struct net_device *hw_roc_dev; 1060 * Remain-on-channel support
1092 struct sk_buff *hw_roc_skb, *hw_roc_skb_for_status; 1061 */
1062 struct list_head roc_list;
1093 struct work_struct hw_roc_start, hw_roc_done; 1063 struct work_struct hw_roc_start, hw_roc_done;
1094 enum nl80211_channel_type hw_roc_channel_type; 1064 unsigned long hw_roc_start_time;
1095 unsigned int hw_roc_duration;
1096 u32 hw_roc_cookie;
1097 bool hw_roc_for_tx;
1098 1065
1099 struct idr ack_status_frames; 1066 struct idr ack_status_frames;
1100 spinlock_t ack_status_lock; 1067 spinlock_t ack_status_lock;
@@ -1290,7 +1257,12 @@ void ieee80211_offchannel_stop_vifs(struct ieee80211_local *local,
1290 bool offchannel_ps_enable); 1257 bool offchannel_ps_enable);
1291void ieee80211_offchannel_return(struct ieee80211_local *local, 1258void ieee80211_offchannel_return(struct ieee80211_local *local,
1292 bool offchannel_ps_disable); 1259 bool offchannel_ps_disable);
1293void ieee80211_hw_roc_setup(struct ieee80211_local *local); 1260void ieee80211_roc_setup(struct ieee80211_local *local);
1261void ieee80211_start_next_roc(struct ieee80211_local *local);
1262void ieee80211_roc_purge(struct ieee80211_sub_if_data *sdata);
1263void ieee80211_roc_notify_destroy(struct ieee80211_roc_work *roc);
1264void ieee80211_sw_roc_work(struct work_struct *work);
1265void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc);
1294 1266
1295/* interface handling */ 1267/* interface handling */
1296int ieee80211_iface_init(void); 1268int ieee80211_iface_init(void);
@@ -1500,18 +1472,6 @@ u8 *ieee80211_ie_build_ht_oper(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
1500 enum nl80211_channel_type channel_type, 1472 enum nl80211_channel_type channel_type,
1501 u16 prot_mode); 1473 u16 prot_mode);
1502 1474
1503/* internal work items */
1504void ieee80211_work_init(struct ieee80211_local *local);
1505void ieee80211_add_work(struct ieee80211_work *wk);
1506void free_work(struct ieee80211_work *wk);
1507void ieee80211_work_purge(struct ieee80211_sub_if_data *sdata);
1508int ieee80211_wk_remain_on_channel(struct ieee80211_sub_if_data *sdata,
1509 struct ieee80211_channel *chan,
1510 enum nl80211_channel_type channel_type,
1511 unsigned int duration, u64 *cookie);
1512int ieee80211_wk_cancel_remain_on_channel(
1513 struct ieee80211_sub_if_data *sdata, u64 cookie);
1514
1515/* channel management */ 1475/* channel management */
1516enum ieee80211_chan_mode { 1476enum ieee80211_chan_mode {
1517 CHAN_MODE_UNDEFINED, 1477 CHAN_MODE_UNDEFINED,
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index 8664111d0566..87aeb4f21ffd 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -58,7 +58,7 @@ static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
58 } 58 }
59 59
60#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 60#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
61 printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu); 61 pr_debug("%s: setting MTU %d\n", dev->name, new_mtu);
62#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 62#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
63 dev->mtu = new_mtu; 63 dev->mtu = new_mtu;
64 return 0; 64 return 0;
@@ -528,10 +528,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
528 */ 528 */
529 netif_tx_stop_all_queues(sdata->dev); 529 netif_tx_stop_all_queues(sdata->dev);
530 530
531 /* 531 ieee80211_roc_purge(sdata);
532 * Purge work for this interface.
533 */
534 ieee80211_work_purge(sdata);
535 532
536 /* 533 /*
537 * Remove all stations associated with this interface. 534 * Remove all stations associated with this interface.
@@ -637,18 +634,6 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
637 ieee80211_configure_filter(local); 634 ieee80211_configure_filter(local);
638 break; 635 break;
639 default: 636 default:
640 mutex_lock(&local->mtx);
641 if (local->hw_roc_dev == sdata->dev &&
642 local->hw_roc_channel) {
643 /* ignore return value since this is racy */
644 drv_cancel_remain_on_channel(local);
645 ieee80211_queue_work(&local->hw, &local->hw_roc_done);
646 }
647 mutex_unlock(&local->mtx);
648
649 flush_work(&local->hw_roc_start);
650 flush_work(&local->hw_roc_done);
651
652 flush_work(&sdata->work); 637 flush_work(&sdata->work);
653 /* 638 /*
654 * When we get here, the interface is marked down. 639 * When we get here, the interface is marked down.
@@ -1238,7 +1223,7 @@ static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
1238 1223
1239 if (__ffs64(mask) + hweight64(mask) != fls64(mask)) { 1224 if (__ffs64(mask) + hweight64(mask) != fls64(mask)) {
1240 /* not a contiguous mask ... not handled now! */ 1225 /* not a contiguous mask ... not handled now! */
1241 printk(KERN_DEBUG "not contiguous\n"); 1226 pr_debug("not contiguous\n");
1242 break; 1227 break;
1243 } 1228 }
1244 1229
@@ -1364,6 +1349,8 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
1364 sdata->u.mgd.use_4addr = params->use_4addr; 1349 sdata->u.mgd.use_4addr = params->use_4addr;
1365 } 1350 }
1366 1351
1352 ndev->features |= local->hw.netdev_features;
1353
1367 ret = register_netdevice(ndev); 1354 ret = register_netdevice(ndev);
1368 if (ret) 1355 if (ret)
1369 goto fail; 1356 goto fail;
@@ -1454,9 +1441,9 @@ u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
1454{ 1441{
1455 struct ieee80211_sub_if_data *sdata; 1442 struct ieee80211_sub_if_data *sdata;
1456 int count = 0; 1443 int count = 0;
1457 bool working = false, scanning = false, hw_roc = false; 1444 bool working = false, scanning = false;
1458 struct ieee80211_work *wk;
1459 unsigned int led_trig_start = 0, led_trig_stop = 0; 1445 unsigned int led_trig_start = 0, led_trig_stop = 0;
1446 struct ieee80211_roc_work *roc;
1460 1447
1461#ifdef CONFIG_PROVE_LOCKING 1448#ifdef CONFIG_PROVE_LOCKING
1462 WARN_ON(debug_locks && !lockdep_rtnl_is_held() && 1449 WARN_ON(debug_locks && !lockdep_rtnl_is_held() &&
@@ -1491,9 +1478,11 @@ u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
1491 count++; 1478 count++;
1492 } 1479 }
1493 1480
1494 list_for_each_entry(wk, &local->work_list, list) { 1481 if (!local->ops->remain_on_channel) {
1495 working = true; 1482 list_for_each_entry(roc, &local->roc_list, list) {
1496 wk->sdata->vif.bss_conf.idle = false; 1483 working = true;
1484 roc->sdata->vif.bss_conf.idle = false;
1485 }
1497 } 1486 }
1498 1487
1499 if (local->scan_sdata && 1488 if (local->scan_sdata &&
@@ -1502,9 +1491,6 @@ u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
1502 local->scan_sdata->vif.bss_conf.idle = false; 1491 local->scan_sdata->vif.bss_conf.idle = false;
1503 } 1492 }
1504 1493
1505 if (local->hw_roc_channel)
1506 hw_roc = true;
1507
1508 list_for_each_entry(sdata, &local->interfaces, list) { 1494 list_for_each_entry(sdata, &local->interfaces, list) {
1509 if (sdata->vif.type == NL80211_IFTYPE_MONITOR || 1495 if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
1510 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) 1496 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
@@ -1516,7 +1502,7 @@ u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
1516 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IDLE); 1502 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_IDLE);
1517 } 1503 }
1518 1504
1519 if (working || scanning || hw_roc) 1505 if (working || scanning)
1520 led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_WORK; 1506 led_trig_start |= IEEE80211_TPT_LEDTRIG_FL_WORK;
1521 else 1507 else
1522 led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_WORK; 1508 led_trig_stop |= IEEE80211_TPT_LEDTRIG_FL_WORK;
@@ -1528,8 +1514,6 @@ u32 __ieee80211_recalc_idle(struct ieee80211_local *local)
1528 1514
1529 ieee80211_mod_tpt_led_trig(local, led_trig_start, led_trig_stop); 1515 ieee80211_mod_tpt_led_trig(local, led_trig_start, led_trig_stop);
1530 1516
1531 if (hw_roc)
1532 return ieee80211_idle_off(local, "hw remain-on-channel");
1533 if (working) 1517 if (working)
1534 return ieee80211_idle_off(local, "working"); 1518 return ieee80211_idle_off(local, "working");
1535 if (scanning) 1519 if (scanning)
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index f5548e953259..d81c178c7712 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -625,8 +625,6 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
625 625
626 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work); 626 INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
627 627
628 ieee80211_work_init(local);
629
630 INIT_WORK(&local->restart_work, ieee80211_restart_work); 628 INIT_WORK(&local->restart_work, ieee80211_restart_work);
631 629
632 INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter); 630 INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
@@ -669,7 +667,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
669 667
670 ieee80211_led_names(local); 668 ieee80211_led_names(local);
671 669
672 ieee80211_hw_roc_setup(local); 670 ieee80211_roc_setup(local);
673 671
674 return &local->hw; 672 return &local->hw;
675} 673}
@@ -682,6 +680,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
682 enum ieee80211_band band; 680 enum ieee80211_band band;
683 int channels, max_bitrates; 681 int channels, max_bitrates;
684 bool supp_ht; 682 bool supp_ht;
683 netdev_features_t feature_whitelist;
685 static const u32 cipher_suites[] = { 684 static const u32 cipher_suites[] = {
686 /* keep WEP first, it may be removed below */ 685 /* keep WEP first, it may be removed below */
687 WLAN_CIPHER_SUITE_WEP40, 686 WLAN_CIPHER_SUITE_WEP40,
@@ -708,6 +707,12 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
708 if ((hw->flags & IEEE80211_HW_SCAN_WHILE_IDLE) && !local->ops->hw_scan) 707 if ((hw->flags & IEEE80211_HW_SCAN_WHILE_IDLE) && !local->ops->hw_scan)
709 return -EINVAL; 708 return -EINVAL;
710 709
710 /* Only HW csum features are currently compatible with mac80211 */
711 feature_whitelist = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
712 NETIF_F_HW_CSUM;
713 if (WARN_ON(hw->netdev_features & ~feature_whitelist))
714 return -EINVAL;
715
711 if (hw->max_report_rates == 0) 716 if (hw->max_report_rates == 0)
712 hw->max_report_rates = hw->max_rates; 717 hw->max_report_rates = hw->max_rates;
713 718
@@ -1009,12 +1014,6 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
1009 1014
1010 rtnl_unlock(); 1015 rtnl_unlock();
1011 1016
1012 /*
1013 * Now all work items will be gone, but the
1014 * timer might still be armed, so delete it
1015 */
1016 del_timer_sync(&local->work_timer);
1017
1018 cancel_work_sync(&local->restart_work); 1017 cancel_work_sync(&local->restart_work);
1019 cancel_work_sync(&local->reconfig_filter); 1018 cancel_work_sync(&local->reconfig_filter);
1020 1019
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 2913113c5833..7cf19509fb68 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -524,8 +524,7 @@ static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata,
524 bool free_plinks; 524 bool free_plinks;
525 525
526#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 526#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
527 printk(KERN_DEBUG "%s: running mesh housekeeping\n", 527 pr_debug("%s: running mesh housekeeping\n", sdata->name);
528 sdata->name);
529#endif 528#endif
530 529
531 ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT); 530 ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT);
diff --git a/net/mac80211/mesh_hwmp.c b/net/mac80211/mesh_hwmp.c
index 9b59658e8650..fa7c58035246 100644
--- a/net/mac80211/mesh_hwmp.c
+++ b/net/mac80211/mesh_hwmp.c
@@ -15,7 +15,7 @@
15 15
16#ifdef CONFIG_MAC80211_VERBOSE_MHWMP_DEBUG 16#ifdef CONFIG_MAC80211_VERBOSE_MHWMP_DEBUG
17#define mhwmp_dbg(fmt, args...) \ 17#define mhwmp_dbg(fmt, args...) \
18 printk(KERN_DEBUG "Mesh HWMP (%s): " fmt "\n", sdata->name, ##args) 18 pr_debug("Mesh HWMP (%s): " fmt "\n", sdata->name, ##args)
19#else 19#else
20#define mhwmp_dbg(fmt, args...) do { (void)(0); } while (0) 20#define mhwmp_dbg(fmt, args...) do { (void)(0); } while (0)
21#endif 21#endif
diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c
index b39224d8255c..572f706fd65b 100644
--- a/net/mac80211/mesh_pathtbl.c
+++ b/net/mac80211/mesh_pathtbl.c
@@ -19,7 +19,7 @@
19#include "mesh.h" 19#include "mesh.h"
20 20
21#ifdef CONFIG_MAC80211_VERBOSE_MPATH_DEBUG 21#ifdef CONFIG_MAC80211_VERBOSE_MPATH_DEBUG
22#define mpath_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args) 22#define mpath_dbg(fmt, args...) pr_debug(fmt, ##args)
23#else 23#else
24#define mpath_dbg(fmt, args...) do { (void)(0); } while (0) 24#define mpath_dbg(fmt, args...) do { (void)(0); } while (0)
25#endif 25#endif
diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
index 60ef235c9d9b..be4fad128c34 100644
--- a/net/mac80211/mesh_plink.c
+++ b/net/mac80211/mesh_plink.c
@@ -14,7 +14,7 @@
14#include "mesh.h" 14#include "mesh.h"
15 15
16#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG 16#ifdef CONFIG_MAC80211_VERBOSE_MPL_DEBUG
17#define mpl_dbg(fmt, args...) printk(KERN_DEBUG fmt, ##args) 17#define mpl_dbg(fmt, args...) pr_debug(fmt, ##args)
18#else 18#else
19#define mpl_dbg(fmt, args...) do { (void)(0); } while (0) 19#define mpl_dbg(fmt, args...) do { (void)(0); } while (0)
20#endif 20#endif
diff --git a/net/mac80211/mesh_sync.c b/net/mac80211/mesh_sync.c
index 38d30e8ce6dc..0ccdad49f987 100644
--- a/net/mac80211/mesh_sync.c
+++ b/net/mac80211/mesh_sync.c
@@ -14,7 +14,7 @@
14 14
15#ifdef CONFIG_MAC80211_VERBOSE_MESH_SYNC_DEBUG 15#ifdef CONFIG_MAC80211_VERBOSE_MESH_SYNC_DEBUG
16#define msync_dbg(fmt, args...) \ 16#define msync_dbg(fmt, args...) \
17 printk(KERN_DEBUG "Mesh sync (%s): " fmt "\n", sdata->name, ##args) 17 pr_debug("Mesh sync (%s): " fmt "\n", sdata->name, ##args)
18#else 18#else
19#define msync_dbg(fmt, args...) do { (void)(0); } while (0) 19#define msync_dbg(fmt, args...) do { (void)(0); } while (0)
20#endif 20#endif
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 66e4fcdd1c6b..079038d26a14 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -258,12 +258,11 @@ static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len,
258} 258}
259 259
260static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata, 260static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
261 struct sk_buff *skb, const u8 *ht_oper_ie, 261 struct sk_buff *skb, u8 ap_ht_param,
262 struct ieee80211_supported_band *sband, 262 struct ieee80211_supported_band *sband,
263 struct ieee80211_channel *channel, 263 struct ieee80211_channel *channel,
264 enum ieee80211_smps_mode smps) 264 enum ieee80211_smps_mode smps)
265{ 265{
266 struct ieee80211_ht_operation *ht_oper;
267 u8 *pos; 266 u8 *pos;
268 u32 flags = channel->flags; 267 u32 flags = channel->flags;
269 u16 cap; 268 u16 cap;
@@ -271,21 +270,13 @@ static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
271 270
272 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap)); 271 BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
273 272
274 if (!ht_oper_ie)
275 return;
276
277 if (ht_oper_ie[1] < sizeof(struct ieee80211_ht_operation))
278 return;
279
280 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap)); 273 memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
281 ieee80211_apply_htcap_overrides(sdata, &ht_cap); 274 ieee80211_apply_htcap_overrides(sdata, &ht_cap);
282 275
283 ht_oper = (struct ieee80211_ht_operation *)(ht_oper_ie + 2);
284
285 /* determine capability flags */ 276 /* determine capability flags */
286 cap = ht_cap.cap; 277 cap = ht_cap.cap;
287 278
288 switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { 279 switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
289 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: 280 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
290 if (flags & IEEE80211_CHAN_NO_HT40PLUS) { 281 if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
291 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; 282 cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
@@ -509,7 +500,7 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
509 } 500 }
510 501
511 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) 502 if (!(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
512 ieee80211_add_ht_ie(sdata, skb, assoc_data->ht_operation_ie, 503 ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
513 sband, local->oper_channel, ifmgd->ap_smps); 504 sband, local->oper_channel, ifmgd->ap_smps);
514 505
515 /* if present, add any custom non-vendor IEs that go after HT */ 506 /* if present, add any custom non-vendor IEs that go after HT */
@@ -939,11 +930,6 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
939 return; 930 return;
940 } 931 }
941 932
942 if (!list_empty(&local->work_list)) {
943 local->ps_sdata = NULL;
944 goto change;
945 }
946
947 list_for_each_entry(sdata, &local->interfaces, list) { 933 list_for_each_entry(sdata, &local->interfaces, list) {
948 if (!ieee80211_sdata_running(sdata)) 934 if (!ieee80211_sdata_running(sdata))
949 continue; 935 continue;
@@ -1016,7 +1002,6 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
1016 local->ps_sdata = NULL; 1002 local->ps_sdata = NULL;
1017 } 1003 }
1018 1004
1019 change:
1020 ieee80211_change_ps(local); 1005 ieee80211_change_ps(local);
1021} 1006}
1022 1007
@@ -1587,6 +1572,8 @@ static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
1587 net_dbg_ratelimited("%s: detected beacon loss from AP - sending probe request\n", 1572 net_dbg_ratelimited("%s: detected beacon loss from AP - sending probe request\n",
1588 sdata->name); 1573 sdata->name);
1589#endif 1574#endif
1575 ieee80211_cqm_rssi_notify(&sdata->vif,
1576 NL80211_CQM_RSSI_BEACON_LOSS_EVENT, GFP_KERNEL);
1590 1577
1591 /* 1578 /*
1592 * The driver/our work has already reported this event or the 1579 * The driver/our work has already reported this event or the
@@ -1669,8 +1656,7 @@ static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata)
1669 1656
1670 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); 1657 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
1671 1658
1672 printk(KERN_DEBUG "%s: Connection to AP %pM lost.\n", 1659 pr_debug("%s: Connection to AP %pM lost\n", sdata->name, bssid);
1673 sdata->name, bssid);
1674 1660
1675 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, 1661 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
1676 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, 1662 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
@@ -1804,9 +1790,10 @@ ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1804 return RX_MGMT_NONE; 1790 return RX_MGMT_NONE;
1805 1791
1806 if (status_code != WLAN_STATUS_SUCCESS) { 1792 if (status_code != WLAN_STATUS_SUCCESS) {
1807 printk(KERN_DEBUG "%s: %pM denied authentication (status %d)\n", 1793 pr_debug("%s: %pM denied authentication (status %d)\n",
1808 sdata->name, mgmt->sa, status_code); 1794 sdata->name, mgmt->sa, status_code);
1809 goto out; 1795 ieee80211_destroy_auth_data(sdata, false);
1796 return RX_MGMT_CFG80211_RX_AUTH;
1810 } 1797 }
1811 1798
1812 switch (ifmgd->auth_data->algorithm) { 1799 switch (ifmgd->auth_data->algorithm) {
@@ -1827,8 +1814,7 @@ ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1827 return RX_MGMT_NONE; 1814 return RX_MGMT_NONE;
1828 } 1815 }
1829 1816
1830 printk(KERN_DEBUG "%s: authenticated\n", sdata->name); 1817 pr_debug("%s: authenticated\n", sdata->name);
1831 out:
1832 ifmgd->auth_data->done = true; 1818 ifmgd->auth_data->done = true;
1833 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC; 1819 ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
1834 run_again(ifmgd, ifmgd->auth_data->timeout); 1820 run_again(ifmgd, ifmgd->auth_data->timeout);
@@ -1841,8 +1827,7 @@ ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
1841 goto out_err; 1827 goto out_err;
1842 } 1828 }
1843 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) { 1829 if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
1844 printk(KERN_DEBUG "%s: failed moving %pM to auth\n", 1830 pr_debug("%s: failed moving %pM to auth\n", sdata->name, bssid);
1845 sdata->name, bssid);
1846 goto out_err; 1831 goto out_err;
1847 } 1832 }
1848 mutex_unlock(&sdata->local->sta_mtx); 1833 mutex_unlock(&sdata->local->sta_mtx);
@@ -1876,8 +1861,8 @@ ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
1876 1861
1877 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); 1862 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
1878 1863
1879 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n", 1864 pr_debug("%s: deauthenticated from %pM (Reason: %u)\n",
1880 sdata->name, bssid, reason_code); 1865 sdata->name, bssid, reason_code);
1881 1866
1882 ieee80211_set_disassoc(sdata, 0, 0, false, NULL); 1867 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
1883 1868
@@ -1907,8 +1892,8 @@ ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
1907 1892
1908 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); 1893 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
1909 1894
1910 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n", 1895 pr_debug("%s: disassociated from %pM (Reason: %u)\n",
1911 sdata->name, mgmt->sa, reason_code); 1896 sdata->name, mgmt->sa, reason_code);
1912 1897
1913 ieee80211_set_disassoc(sdata, 0, 0, false, NULL); 1898 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
1914 1899
@@ -2000,17 +1985,15 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2000 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); 1985 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
2001 1986
2002 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) 1987 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
2003 printk(KERN_DEBUG 1988 pr_debug("%s: invalid AID value 0x%x; bits 15:14 not set\n",
2004 "%s: invalid AID value 0x%x; bits 15:14 not set\n", 1989 sdata->name, aid);
2005 sdata->name, aid);
2006 aid &= ~(BIT(15) | BIT(14)); 1990 aid &= ~(BIT(15) | BIT(14));
2007 1991
2008 ifmgd->broken_ap = false; 1992 ifmgd->broken_ap = false;
2009 1993
2010 if (aid == 0 || aid > IEEE80211_MAX_AID) { 1994 if (aid == 0 || aid > IEEE80211_MAX_AID) {
2011 printk(KERN_DEBUG 1995 pr_debug("%s: invalid AID value %d (out of range), turn off PS\n",
2012 "%s: invalid AID value %d (out of range), turn off PS\n", 1996 sdata->name, aid);
2013 sdata->name, aid);
2014 aid = 0; 1997 aid = 0;
2015 ifmgd->broken_ap = true; 1998 ifmgd->broken_ap = true;
2016 } 1999 }
@@ -2019,8 +2002,8 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2019 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); 2002 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
2020 2003
2021 if (!elems.supp_rates) { 2004 if (!elems.supp_rates) {
2022 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", 2005 pr_debug("%s: no SuppRates element in AssocResp\n",
2023 sdata->name); 2006 sdata->name);
2024 return false; 2007 return false;
2025 } 2008 }
2026 2009
@@ -2060,9 +2043,8 @@ static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
2060 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) 2043 if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
2061 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); 2044 err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
2062 if (err) { 2045 if (err) {
2063 printk(KERN_DEBUG 2046 pr_debug("%s: failed to move station %pM to desired state\n",
2064 "%s: failed to move station %pM to desired state\n", 2047 sdata->name, sta->sta.addr);
2065 sdata->name, sta->sta.addr);
2066 WARN_ON(__sta_info_destroy(sta)); 2048 WARN_ON(__sta_info_destroy(sta));
2067 mutex_unlock(&sdata->local->sta_mtx); 2049 mutex_unlock(&sdata->local->sta_mtx);
2068 return false; 2050 return false;
@@ -2145,10 +2127,9 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
2145 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); 2127 status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
2146 aid = le16_to_cpu(mgmt->u.assoc_resp.aid); 2128 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
2147 2129
2148 printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x " 2130 pr_debug("%s: RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
2149 "status=%d aid=%d)\n", 2131 sdata->name, reassoc ? "Rea" : "A", mgmt->sa,
2150 sdata->name, reassoc ? "Rea" : "A", mgmt->sa, 2132 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
2151 capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
2152 2133
2153 pos = mgmt->u.assoc_resp.variable; 2134 pos = mgmt->u.assoc_resp.variable;
2154 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); 2135 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
@@ -2159,9 +2140,8 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
2159 u32 tu, ms; 2140 u32 tu, ms;
2160 tu = get_unaligned_le32(elems.timeout_int + 1); 2141 tu = get_unaligned_le32(elems.timeout_int + 1);
2161 ms = tu * 1024 / 1000; 2142 ms = tu * 1024 / 1000;
2162 printk(KERN_DEBUG "%s: %pM rejected association temporarily; " 2143 pr_debug("%s: %pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
2163 "comeback duration %u TU (%u ms)\n", 2144 sdata->name, mgmt->sa, tu, ms);
2164 sdata->name, mgmt->sa, tu, ms);
2165 assoc_data->timeout = jiffies + msecs_to_jiffies(ms); 2145 assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
2166 if (ms > IEEE80211_ASSOC_TIMEOUT) 2146 if (ms > IEEE80211_ASSOC_TIMEOUT)
2167 run_again(ifmgd, assoc_data->timeout); 2147 run_again(ifmgd, assoc_data->timeout);
@@ -2171,11 +2151,11 @@ ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
2171 *bss = assoc_data->bss; 2151 *bss = assoc_data->bss;
2172 2152
2173 if (status_code != WLAN_STATUS_SUCCESS) { 2153 if (status_code != WLAN_STATUS_SUCCESS) {
2174 printk(KERN_DEBUG "%s: %pM denied association (code=%d)\n", 2154 pr_debug("%s: %pM denied association (code=%d)\n",
2175 sdata->name, mgmt->sa, status_code); 2155 sdata->name, mgmt->sa, status_code);
2176 ieee80211_destroy_assoc_data(sdata, false); 2156 ieee80211_destroy_assoc_data(sdata, false);
2177 } else { 2157 } else {
2178 printk(KERN_DEBUG "%s: associated\n", sdata->name); 2158 pr_debug("%s: associated\n", sdata->name);
2179 2159
2180 if (!ieee80211_assoc_success(sdata, *bss, mgmt, len)) { 2160 if (!ieee80211_assoc_success(sdata, *bss, mgmt, len)) {
2181 /* oops -- internal error -- send timeout for now */ 2161 /* oops -- internal error -- send timeout for now */
@@ -2283,7 +2263,7 @@ static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
2283 if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies && 2263 if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies &&
2284 ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) { 2264 ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) {
2285 /* got probe response, continue with auth */ 2265 /* got probe response, continue with auth */
2286 printk(KERN_DEBUG "%s: direct probe responded\n", sdata->name); 2266 pr_debug("%s: direct probe responded\n", sdata->name);
2287 ifmgd->auth_data->tries = 0; 2267 ifmgd->auth_data->tries = 0;
2288 ifmgd->auth_data->timeout = jiffies; 2268 ifmgd->auth_data->timeout = jiffies;
2289 run_again(ifmgd, ifmgd->auth_data->timeout); 2269 run_again(ifmgd, ifmgd->auth_data->timeout);
@@ -2645,8 +2625,8 @@ static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
2645 auth_data->tries++; 2625 auth_data->tries++;
2646 2626
2647 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) { 2627 if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
2648 printk(KERN_DEBUG "%s: authentication with %pM timed out\n", 2628 pr_debug("%s: authentication with %pM timed out\n",
2649 sdata->name, auth_data->bss->bssid); 2629 sdata->name, auth_data->bss->bssid);
2650 2630
2651 /* 2631 /*
2652 * Most likely AP is not in the range so remove the 2632 * Most likely AP is not in the range so remove the
@@ -2658,9 +2638,9 @@ static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
2658 } 2638 }
2659 2639
2660 if (auth_data->bss->proberesp_ies) { 2640 if (auth_data->bss->proberesp_ies) {
2661 printk(KERN_DEBUG "%s: send auth to %pM (try %d/%d)\n", 2641 pr_debug("%s: send auth to %pM (try %d/%d)\n",
2662 sdata->name, auth_data->bss->bssid, auth_data->tries, 2642 sdata->name, auth_data->bss->bssid, auth_data->tries,
2663 IEEE80211_AUTH_MAX_TRIES); 2643 IEEE80211_AUTH_MAX_TRIES);
2664 2644
2665 auth_data->expected_transaction = 2; 2645 auth_data->expected_transaction = 2;
2666 ieee80211_send_auth(sdata, 1, auth_data->algorithm, 2646 ieee80211_send_auth(sdata, 1, auth_data->algorithm,
@@ -2670,9 +2650,9 @@ static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata)
2670 } else { 2650 } else {
2671 const u8 *ssidie; 2651 const u8 *ssidie;
2672 2652
2673 printk(KERN_DEBUG "%s: direct probe to %pM (try %d/%i)\n", 2653 pr_debug("%s: direct probe to %pM (try %d/%i)\n",
2674 sdata->name, auth_data->bss->bssid, auth_data->tries, 2654 sdata->name, auth_data->bss->bssid, auth_data->tries,
2675 IEEE80211_AUTH_MAX_TRIES); 2655 IEEE80211_AUTH_MAX_TRIES);
2676 2656
2677 ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID); 2657 ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID);
2678 if (!ssidie) 2658 if (!ssidie)
@@ -2700,8 +2680,8 @@ static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
2700 2680
2701 assoc_data->tries++; 2681 assoc_data->tries++;
2702 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) { 2682 if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
2703 printk(KERN_DEBUG "%s: association with %pM timed out\n", 2683 pr_debug("%s: association with %pM timed out\n",
2704 sdata->name, assoc_data->bss->bssid); 2684 sdata->name, assoc_data->bss->bssid);
2705 2685
2706 /* 2686 /*
2707 * Most likely AP is not in the range so remove the 2687 * Most likely AP is not in the range so remove the
@@ -2712,9 +2692,9 @@ static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
2712 return -ETIMEDOUT; 2692 return -ETIMEDOUT;
2713 } 2693 }
2714 2694
2715 printk(KERN_DEBUG "%s: associate with %pM (try %d/%d)\n", 2695 pr_debug("%s: associate with %pM (try %d/%d)\n",
2716 sdata->name, assoc_data->bss->bssid, assoc_data->tries, 2696 sdata->name, assoc_data->bss->bssid, assoc_data->tries,
2717 IEEE80211_ASSOC_MAX_TRIES); 2697 IEEE80211_ASSOC_MAX_TRIES);
2718 ieee80211_send_assoc(sdata); 2698 ieee80211_send_assoc(sdata);
2719 2699
2720 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT; 2700 assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
@@ -3085,13 +3065,10 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3085 * since we look at probe response/beacon data here 3065 * since we look at probe response/beacon data here
3086 * it should be OK. 3066 * it should be OK.
3087 */ 3067 */
3088 printk(KERN_DEBUG 3068 pr_debug("%s: Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
3089 "%s: Wrong control channel: center-freq: %d" 3069 sdata->name, cbss->channel->center_freq,
3090 " ht-cfreq: %d ht->primary_chan: %d" 3070 ht_cfreq, ht_oper->primary_chan,
3091 " band: %d. Disabling HT.\n", 3071 cbss->channel->band);
3092 sdata->name, cbss->channel->center_freq,
3093 ht_cfreq, ht_oper->primary_chan,
3094 cbss->channel->band);
3095 ht_oper = NULL; 3072 ht_oper = NULL;
3096 } 3073 }
3097 } 3074 }
@@ -3115,9 +3092,8 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3115 if (!ieee80211_set_channel_type(local, sdata, channel_type)) { 3092 if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
3116 /* can only fail due to HT40+/- mismatch */ 3093 /* can only fail due to HT40+/- mismatch */
3117 channel_type = NL80211_CHAN_HT20; 3094 channel_type = NL80211_CHAN_HT20;
3118 printk(KERN_DEBUG 3095 pr_debug("%s: disabling 40 MHz due to multi-vif mismatch\n",
3119 "%s: disabling 40 MHz due to multi-vif mismatch\n", 3096 sdata->name);
3120 sdata->name);
3121 ifmgd->flags |= IEEE80211_STA_DISABLE_40MHZ; 3097 ifmgd->flags |= IEEE80211_STA_DISABLE_40MHZ;
3122 WARN_ON(!ieee80211_set_channel_type(local, sdata, 3098 WARN_ON(!ieee80211_set_channel_type(local, sdata,
3123 channel_type)); 3099 channel_type));
@@ -3146,9 +3122,8 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3146 * we can connect -- with a warning. 3122 * we can connect -- with a warning.
3147 */ 3123 */
3148 if (!basic_rates && min_rate_index >= 0) { 3124 if (!basic_rates && min_rate_index >= 0) {
3149 printk(KERN_DEBUG 3125 pr_debug("%s: No basic rates, using min rate instead\n",
3150 "%s: No basic rates, using min rate instead.\n", 3126 sdata->name);
3151 sdata->name);
3152 basic_rates = BIT(min_rate_index); 3127 basic_rates = BIT(min_rate_index);
3153 } 3128 }
3154 3129
@@ -3174,9 +3149,8 @@ static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
3174 err = sta_info_insert(sta); 3149 err = sta_info_insert(sta);
3175 sta = NULL; 3150 sta = NULL;
3176 if (err) { 3151 if (err) {
3177 printk(KERN_DEBUG 3152 pr_debug("%s: failed to insert STA entry for the AP (error %d)\n",
3178 "%s: failed to insert STA entry for the AP (error %d)\n", 3153 sdata->name, err);
3179 sdata->name, err);
3180 return err; 3154 return err;
3181 } 3155 }
3182 } else 3156 } else
@@ -3254,8 +3228,7 @@ int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
3254 if (ifmgd->associated) 3228 if (ifmgd->associated)
3255 ieee80211_set_disassoc(sdata, 0, 0, false, NULL); 3229 ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
3256 3230
3257 printk(KERN_DEBUG "%s: authenticate with %pM\n", 3231 pr_debug("%s: authenticate with %pM\n", sdata->name, req->bss->bssid);
3258 sdata->name, req->bss->bssid);
3259 3232
3260 err = ieee80211_prep_connection(sdata, req->bss, false); 3233 err = ieee80211_prep_connection(sdata, req->bss, false);
3261 if (err) 3234 if (err)
@@ -3290,7 +3263,7 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3290 struct ieee80211_bss *bss = (void *)req->bss->priv; 3263 struct ieee80211_bss *bss = (void *)req->bss->priv;
3291 struct ieee80211_mgd_assoc_data *assoc_data; 3264 struct ieee80211_mgd_assoc_data *assoc_data;
3292 struct ieee80211_supported_band *sband; 3265 struct ieee80211_supported_band *sband;
3293 const u8 *ssidie; 3266 const u8 *ssidie, *ht_ie;
3294 int i, err; 3267 int i, err;
3295 3268
3296 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); 3269 ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
@@ -3338,11 +3311,15 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3338 * We can set this to true for non-11n hardware, that'll be checked 3311 * We can set this to true for non-11n hardware, that'll be checked
3339 * separately along with the peer capabilities. 3312 * separately along with the peer capabilities.
3340 */ 3313 */
3341 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) 3314 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
3342 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || 3315 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
3343 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP || 3316 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
3344 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) 3317 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
3345 ifmgd->flags |= IEEE80211_STA_DISABLE_11N; 3318 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
3319 netdev_info(sdata->dev,
3320 "disabling HT due to WEP/TKIP use\n");
3321 }
3322 }
3346 3323
3347 if (req->flags & ASSOC_REQ_DISABLE_HT) 3324 if (req->flags & ASSOC_REQ_DISABLE_HT)
3348 ifmgd->flags |= IEEE80211_STA_DISABLE_11N; 3325 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
@@ -3350,8 +3327,11 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3350 /* Also disable HT if we don't support it or the AP doesn't use WMM */ 3327 /* Also disable HT if we don't support it or the AP doesn't use WMM */
3351 sband = local->hw.wiphy->bands[req->bss->channel->band]; 3328 sband = local->hw.wiphy->bands[req->bss->channel->band];
3352 if (!sband->ht_cap.ht_supported || 3329 if (!sband->ht_cap.ht_supported ||
3353 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) 3330 local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) {
3354 ifmgd->flags |= IEEE80211_STA_DISABLE_11N; 3331 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
3332 netdev_info(sdata->dev,
3333 "disabling HT as WMM/QoS is not supported\n");
3334 }
3355 3335
3356 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa)); 3336 memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
3357 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask, 3337 memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
@@ -3377,8 +3357,13 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3377 (local->hw.queues >= IEEE80211_NUM_ACS); 3357 (local->hw.queues >= IEEE80211_NUM_ACS);
3378 assoc_data->supp_rates = bss->supp_rates; 3358 assoc_data->supp_rates = bss->supp_rates;
3379 assoc_data->supp_rates_len = bss->supp_rates_len; 3359 assoc_data->supp_rates_len = bss->supp_rates_len;
3380 assoc_data->ht_operation_ie = 3360
3381 ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION); 3361 ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
3362 if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
3363 assoc_data->ap_ht_param =
3364 ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
3365 else
3366 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
3382 3367
3383 if (bss->wmm_used && bss->uapsd_supported && 3368 if (bss->wmm_used && bss->uapsd_supported &&
3384 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) { 3369 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
@@ -3425,8 +3410,8 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3425 * Wait up to one beacon interval ... 3410 * Wait up to one beacon interval ...
3426 * should this be more if we miss one? 3411 * should this be more if we miss one?
3427 */ 3412 */
3428 printk(KERN_DEBUG "%s: waiting for beacon from %pM\n", 3413 pr_debug("%s: waiting for beacon from %pM\n",
3429 sdata->name, ifmgd->bssid); 3414 sdata->name, ifmgd->bssid);
3430 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval); 3415 assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
3431 } else { 3416 } else {
3432 assoc_data->have_beacon = true; 3417 assoc_data->have_beacon = true;
@@ -3445,8 +3430,8 @@ int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
3445 corrupt_type = "beacon"; 3430 corrupt_type = "beacon";
3446 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) 3431 } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
3447 corrupt_type = "probe response"; 3432 corrupt_type = "probe response";
3448 printk(KERN_DEBUG "%s: associating with AP with corrupt %s\n", 3433 pr_debug("%s: associating with AP with corrupt %s\n",
3449 sdata->name, corrupt_type); 3434 sdata->name, corrupt_type);
3450 } 3435 }
3451 3436
3452 err = 0; 3437 err = 0;
@@ -3475,9 +3460,8 @@ int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
3475 return 0; 3460 return 0;
3476 } 3461 }
3477 3462
3478 printk(KERN_DEBUG 3463 pr_debug("%s: deauthenticating from %pM by local choice (reason=%d)\n",
3479 "%s: deauthenticating from %pM by local choice (reason=%d)\n", 3464 sdata->name, req->bssid, req->reason_code);
3480 sdata->name, req->bssid, req->reason_code);
3481 3465
3482 if (ifmgd->associated && 3466 if (ifmgd->associated &&
3483 ether_addr_equal(ifmgd->associated->bssid, req->bssid)) 3467 ether_addr_equal(ifmgd->associated->bssid, req->bssid))
@@ -3519,8 +3503,8 @@ int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
3519 return -ENOLINK; 3503 return -ENOLINK;
3520 } 3504 }
3521 3505
3522 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n", 3506 pr_debug("%s: disassociating from %pM by local choice (reason=%d)\n",
3523 sdata->name, req->bss->bssid, req->reason_code); 3507 sdata->name, req->bss->bssid, req->reason_code);
3524 3508
3525 memcpy(bssid, req->bss->bssid, ETH_ALEN); 3509 memcpy(bssid, req->bss->bssid, ETH_ALEN);
3526 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC, 3510 ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
@@ -3561,10 +3545,3 @@ void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
3561 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp); 3545 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
3562} 3546}
3563EXPORT_SYMBOL(ieee80211_cqm_rssi_notify); 3547EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
3564
3565unsigned char ieee80211_get_operstate(struct ieee80211_vif *vif)
3566{
3567 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3568 return sdata->dev->operstate;
3569}
3570EXPORT_SYMBOL(ieee80211_get_operstate);
diff --git a/net/mac80211/offchannel.c b/net/mac80211/offchannel.c
index 935aa4b6deee..abb226dc4753 100644
--- a/net/mac80211/offchannel.c
+++ b/net/mac80211/offchannel.c
@@ -16,6 +16,7 @@
16#include <net/mac80211.h> 16#include <net/mac80211.h>
17#include "ieee80211_i.h" 17#include "ieee80211_i.h"
18#include "driver-trace.h" 18#include "driver-trace.h"
19#include "driver-ops.h"
19 20
20/* 21/*
21 * Tell our hardware to disable PS. 22 * Tell our hardware to disable PS.
@@ -181,34 +182,58 @@ void ieee80211_offchannel_return(struct ieee80211_local *local,
181 mutex_unlock(&local->iflist_mtx); 182 mutex_unlock(&local->iflist_mtx);
182} 183}
183 184
185void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc)
186{
187 if (roc->notified)
188 return;
189
190 if (roc->mgmt_tx_cookie) {
191 if (!WARN_ON(!roc->frame)) {
192 ieee80211_tx_skb(roc->sdata, roc->frame);
193 roc->frame = NULL;
194 }
195 } else {
196 cfg80211_ready_on_channel(roc->sdata->dev, (unsigned long)roc,
197 roc->chan, roc->chan_type,
198 roc->req_duration, GFP_KERNEL);
199 }
200
201 roc->notified = true;
202}
203
184static void ieee80211_hw_roc_start(struct work_struct *work) 204static void ieee80211_hw_roc_start(struct work_struct *work)
185{ 205{
186 struct ieee80211_local *local = 206 struct ieee80211_local *local =
187 container_of(work, struct ieee80211_local, hw_roc_start); 207 container_of(work, struct ieee80211_local, hw_roc_start);
188 struct ieee80211_sub_if_data *sdata; 208 struct ieee80211_roc_work *roc, *dep, *tmp;
189 209
190 mutex_lock(&local->mtx); 210 mutex_lock(&local->mtx);
191 211
192 if (!local->hw_roc_channel) { 212 if (list_empty(&local->roc_list))
193 mutex_unlock(&local->mtx); 213 goto out_unlock;
194 return;
195 }
196 214
197 if (local->hw_roc_skb) { 215 roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work,
198 sdata = IEEE80211_DEV_TO_SUB_IF(local->hw_roc_dev); 216 list);
199 ieee80211_tx_skb(sdata, local->hw_roc_skb); 217
200 local->hw_roc_skb = NULL; 218 if (!roc->started)
201 } else { 219 goto out_unlock;
202 cfg80211_ready_on_channel(local->hw_roc_dev,
203 local->hw_roc_cookie,
204 local->hw_roc_channel,
205 local->hw_roc_channel_type,
206 local->hw_roc_duration,
207 GFP_KERNEL);
208 }
209 220
210 ieee80211_recalc_idle(local); 221 roc->hw_begun = true;
222 roc->hw_start_time = local->hw_roc_start_time;
211 223
224 ieee80211_handle_roc_started(roc);
225 list_for_each_entry_safe(dep, tmp, &roc->dependents, list) {
226 ieee80211_handle_roc_started(dep);
227
228 if (dep->duration > roc->duration) {
229 u32 dur = dep->duration;
230 dep->duration = dur - roc->duration;
231 roc->duration = dur;
232 list_del(&dep->list);
233 list_add(&dep->list, &roc->list);
234 }
235 }
236 out_unlock:
212 mutex_unlock(&local->mtx); 237 mutex_unlock(&local->mtx);
213} 238}
214 239
@@ -216,52 +241,179 @@ void ieee80211_ready_on_channel(struct ieee80211_hw *hw)
216{ 241{
217 struct ieee80211_local *local = hw_to_local(hw); 242 struct ieee80211_local *local = hw_to_local(hw);
218 243
244 local->hw_roc_start_time = jiffies;
245
219 trace_api_ready_on_channel(local); 246 trace_api_ready_on_channel(local);
220 247
221 ieee80211_queue_work(hw, &local->hw_roc_start); 248 ieee80211_queue_work(hw, &local->hw_roc_start);
222} 249}
223EXPORT_SYMBOL_GPL(ieee80211_ready_on_channel); 250EXPORT_SYMBOL_GPL(ieee80211_ready_on_channel);
224 251
225static void ieee80211_hw_roc_done(struct work_struct *work) 252void ieee80211_start_next_roc(struct ieee80211_local *local)
226{ 253{
227 struct ieee80211_local *local = 254 struct ieee80211_roc_work *roc;
228 container_of(work, struct ieee80211_local, hw_roc_done);
229 255
230 mutex_lock(&local->mtx); 256 lockdep_assert_held(&local->mtx);
231 257
232 if (!local->hw_roc_channel) { 258 if (list_empty(&local->roc_list)) {
233 mutex_unlock(&local->mtx); 259 ieee80211_run_deferred_scan(local);
234 return; 260 return;
235 } 261 }
236 262
237 /* was never transmitted */ 263 roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work,
238 if (local->hw_roc_skb) { 264 list);
239 u64 cookie;
240 265
241 cookie = local->hw_roc_cookie ^ 2; 266 if (local->ops->remain_on_channel) {
267 int ret, duration = roc->duration;
242 268
243 cfg80211_mgmt_tx_status(local->hw_roc_dev, cookie, 269 /* XXX: duplicated, see ieee80211_start_roc_work() */
244 local->hw_roc_skb->data, 270 if (!duration)
245 local->hw_roc_skb->len, false, 271 duration = 10;
246 GFP_KERNEL);
247 272
248 kfree_skb(local->hw_roc_skb); 273 ret = drv_remain_on_channel(local, roc->chan,
249 local->hw_roc_skb = NULL; 274 roc->chan_type,
250 local->hw_roc_skb_for_status = NULL; 275 duration);
276
277 roc->started = true;
278
279 if (ret) {
280 wiphy_warn(local->hw.wiphy,
281 "failed to start next HW ROC (%d)\n", ret);
282 /*
283 * queue the work struct again to avoid recursion
284 * when multiple failures occur
285 */
286 ieee80211_remain_on_channel_expired(&local->hw);
287 }
288 } else {
289 /* delay it a bit */
290 ieee80211_queue_delayed_work(&local->hw, &roc->work,
291 round_jiffies_relative(HZ/2));
292 }
293}
294
295void ieee80211_roc_notify_destroy(struct ieee80211_roc_work *roc)
296{
297 struct ieee80211_roc_work *dep, *tmp;
298
299 /* was never transmitted */
300 if (roc->frame) {
301 cfg80211_mgmt_tx_status(roc->sdata->dev,
302 (unsigned long)roc->frame,
303 roc->frame->data, roc->frame->len,
304 false, GFP_KERNEL);
305 kfree_skb(roc->frame);
251 } 306 }
252 307
253 if (!local->hw_roc_for_tx) 308 if (!roc->mgmt_tx_cookie)
254 cfg80211_remain_on_channel_expired(local->hw_roc_dev, 309 cfg80211_remain_on_channel_expired(roc->sdata->dev,
255 local->hw_roc_cookie, 310 (unsigned long)roc,
256 local->hw_roc_channel, 311 roc->chan, roc->chan_type,
257 local->hw_roc_channel_type,
258 GFP_KERNEL); 312 GFP_KERNEL);
259 313
260 local->hw_roc_channel = NULL; 314 list_for_each_entry_safe(dep, tmp, &roc->dependents, list)
261 local->hw_roc_cookie = 0; 315 ieee80211_roc_notify_destroy(dep);
316
317 kfree(roc);
318}
319
320void ieee80211_sw_roc_work(struct work_struct *work)
321{
322 struct ieee80211_roc_work *roc =
323 container_of(work, struct ieee80211_roc_work, work.work);
324 struct ieee80211_sub_if_data *sdata = roc->sdata;
325 struct ieee80211_local *local = sdata->local;
326
327 mutex_lock(&local->mtx);
328
329 if (roc->abort)
330 goto finish;
331
332 if (WARN_ON(list_empty(&local->roc_list)))
333 goto out_unlock;
334
335 if (WARN_ON(roc != list_first_entry(&local->roc_list,
336 struct ieee80211_roc_work,
337 list)))
338 goto out_unlock;
339
340 if (!roc->started) {
341 struct ieee80211_roc_work *dep;
342
343 /* start this ROC */
262 344
263 ieee80211_recalc_idle(local); 345 /* switch channel etc */
346 ieee80211_recalc_idle(local);
264 347
348 local->tmp_channel = roc->chan;
349 local->tmp_channel_type = roc->chan_type;
350 ieee80211_hw_config(local, 0);
351
352 /* tell userspace or send frame */
353 ieee80211_handle_roc_started(roc);
354 list_for_each_entry(dep, &roc->dependents, list)
355 ieee80211_handle_roc_started(dep);
356
357 /* if it was pure TX, just finish right away */
358 if (!roc->duration)
359 goto finish;
360
361 roc->started = true;
362 ieee80211_queue_delayed_work(&local->hw, &roc->work,
363 msecs_to_jiffies(roc->duration));
364 } else {
365 /* finish this ROC */
366 finish:
367 list_del(&roc->list);
368 ieee80211_roc_notify_destroy(roc);
369
370 if (roc->started) {
371 drv_flush(local, false);
372
373 local->tmp_channel = NULL;
374 ieee80211_hw_config(local, 0);
375
376 ieee80211_offchannel_return(local, true);
377 }
378
379 ieee80211_recalc_idle(local);
380
381 ieee80211_start_next_roc(local);
382 ieee80211_run_deferred_scan(local);
383 }
384
385 out_unlock:
386 mutex_unlock(&local->mtx);
387}
388
389static void ieee80211_hw_roc_done(struct work_struct *work)
390{
391 struct ieee80211_local *local =
392 container_of(work, struct ieee80211_local, hw_roc_done);
393 struct ieee80211_roc_work *roc;
394
395 mutex_lock(&local->mtx);
396
397 if (list_empty(&local->roc_list))
398 goto out_unlock;
399
400 roc = list_first_entry(&local->roc_list, struct ieee80211_roc_work,
401 list);
402
403 if (!roc->started)
404 goto out_unlock;
405
406 list_del(&roc->list);
407
408 ieee80211_roc_notify_destroy(roc);
409
410 /* if there's another roc, start it now */
411 ieee80211_start_next_roc(local);
412
413 /* or scan maybe */
414 ieee80211_run_deferred_scan(local);
415
416 out_unlock:
265 mutex_unlock(&local->mtx); 417 mutex_unlock(&local->mtx);
266} 418}
267 419
@@ -275,8 +427,48 @@ void ieee80211_remain_on_channel_expired(struct ieee80211_hw *hw)
275} 427}
276EXPORT_SYMBOL_GPL(ieee80211_remain_on_channel_expired); 428EXPORT_SYMBOL_GPL(ieee80211_remain_on_channel_expired);
277 429
278void ieee80211_hw_roc_setup(struct ieee80211_local *local) 430void ieee80211_roc_setup(struct ieee80211_local *local)
279{ 431{
280 INIT_WORK(&local->hw_roc_start, ieee80211_hw_roc_start); 432 INIT_WORK(&local->hw_roc_start, ieee80211_hw_roc_start);
281 INIT_WORK(&local->hw_roc_done, ieee80211_hw_roc_done); 433 INIT_WORK(&local->hw_roc_done, ieee80211_hw_roc_done);
434 INIT_LIST_HEAD(&local->roc_list);
435}
436
437void ieee80211_roc_purge(struct ieee80211_sub_if_data *sdata)
438{
439 struct ieee80211_local *local = sdata->local;
440 struct ieee80211_roc_work *roc, *tmp;
441 LIST_HEAD(tmp_list);
442
443 mutex_lock(&local->mtx);
444 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
445 if (roc->sdata != sdata)
446 continue;
447
448 if (roc->started && local->ops->remain_on_channel) {
449 /* can race, so ignore return value */
450 drv_cancel_remain_on_channel(local);
451 }
452
453 list_move_tail(&roc->list, &tmp_list);
454 roc->abort = true;
455 }
456
457 ieee80211_start_next_roc(local);
458 ieee80211_run_deferred_scan(local);
459 mutex_unlock(&local->mtx);
460
461 list_for_each_entry_safe(roc, tmp, &tmp_list, list) {
462 if (local->ops->remain_on_channel) {
463 list_del(&roc->list);
464 ieee80211_roc_notify_destroy(roc);
465 } else {
466 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
467
468 /* work will clean up etc */
469 flush_delayed_work(&roc->work);
470 }
471 }
472
473 WARN_ON_ONCE(!list_empty(&tmp_list));
282} 474}
diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
index af1c4e26e965..98c128be3827 100644
--- a/net/mac80211/pm.c
+++ b/net/mac80211/pm.c
@@ -77,6 +77,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77 int err = drv_suspend(local, wowlan); 77 int err = drv_suspend(local, wowlan);
78 if (err < 0) { 78 if (err < 0) {
79 local->quiescing = false; 79 local->quiescing = false;
80 local->wowlan = false;
80 return err; 81 return err;
81 } else if (err > 0) { 82 } else if (err > 0) {
82 WARN_ON(err != 1); 83 WARN_ON(err != 1);
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 7bcecf73aafb..6fd2cb0838c4 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -1137,22 +1137,22 @@ static void ap_sta_ps_start(struct sta_info *sta)
1137 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS)) 1137 if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
1138 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta); 1138 drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
1139#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 1139#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1140 printk(KERN_DEBUG "%s: STA %pM aid %d enters power save mode\n", 1140 pr_debug("%s: STA %pM aid %d enters power save mode\n",
1141 sdata->name, sta->sta.addr, sta->sta.aid); 1141 sdata->name, sta->sta.addr, sta->sta.aid);
1142#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 1142#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1143} 1143}
1144 1144
1145static void ap_sta_ps_end(struct sta_info *sta) 1145static void ap_sta_ps_end(struct sta_info *sta)
1146{ 1146{
1147#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 1147#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1148 printk(KERN_DEBUG "%s: STA %pM aid %d exits power save mode\n", 1148 pr_debug("%s: STA %pM aid %d exits power save mode\n",
1149 sta->sdata->name, sta->sta.addr, sta->sta.aid); 1149 sta->sdata->name, sta->sta.addr, sta->sta.aid);
1150#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 1150#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1151 1151
1152 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) { 1152 if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
1153#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 1153#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
1154 printk(KERN_DEBUG "%s: STA %pM aid %d driver-ps-blocked\n", 1154 pr_debug("%s: STA %pM aid %d driver-ps-blocked\n",
1155 sta->sdata->name, sta->sta.addr, sta->sta.aid); 1155 sta->sdata->name, sta->sta.addr, sta->sta.aid);
1156#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 1156#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
1157 return; 1157 return;
1158 } 1158 }
@@ -1387,12 +1387,10 @@ ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
1387#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1387#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1388 struct ieee80211_hdr *hdr = 1388 struct ieee80211_hdr *hdr =
1389 (struct ieee80211_hdr *) entry->skb_list.next->data; 1389 (struct ieee80211_hdr *) entry->skb_list.next->data;
1390 printk(KERN_DEBUG "%s: RX reassembly removed oldest " 1390 pr_debug("%s: RX reassembly removed oldest fragment entry (idx=%d age=%lu seq=%d last_frag=%d addr1=%pM addr2=%pM\n",
1391 "fragment entry (idx=%d age=%lu seq=%d last_frag=%d " 1391 sdata->name, idx,
1392 "addr1=%pM addr2=%pM\n", 1392 jiffies - entry->first_frag_time, entry->seq,
1393 sdata->name, idx, 1393 entry->last_frag, hdr->addr1, hdr->addr2);
1394 jiffies - entry->first_frag_time, entry->seq,
1395 entry->last_frag, hdr->addr1, hdr->addr2);
1396#endif 1394#endif
1397 __skb_queue_purge(&entry->skb_list); 1395 __skb_queue_purge(&entry->skb_list);
1398 } 1396 }
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index 169da0742c81..379f178eab5f 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -323,7 +323,7 @@ static void __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted,
323 ieee80211_mlme_notify_scan_completed(local); 323 ieee80211_mlme_notify_scan_completed(local);
324 ieee80211_ibss_notify_scan_completed(local); 324 ieee80211_ibss_notify_scan_completed(local);
325 ieee80211_mesh_notify_scan_completed(local); 325 ieee80211_mesh_notify_scan_completed(local);
326 ieee80211_queue_work(&local->hw, &local->work_work); 326 ieee80211_start_next_roc(local);
327} 327}
328 328
329void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted) 329void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
@@ -376,7 +376,7 @@ static int ieee80211_start_sw_scan(struct ieee80211_local *local)
376static bool ieee80211_can_scan(struct ieee80211_local *local, 376static bool ieee80211_can_scan(struct ieee80211_local *local,
377 struct ieee80211_sub_if_data *sdata) 377 struct ieee80211_sub_if_data *sdata)
378{ 378{
379 if (!list_empty(&local->work_list)) 379 if (!list_empty(&local->roc_list))
380 return false; 380 return false;
381 381
382 if (sdata->vif.type == NL80211_IFTYPE_STATION && 382 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c
index de455f8bbb91..77dcf2f89d42 100644
--- a/net/mac80211/sta_info.c
+++ b/net/mac80211/sta_info.c
@@ -333,9 +333,8 @@ static int sta_info_insert_drv_state(struct ieee80211_local *local,
333 } 333 }
334 334
335 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { 335 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
336 printk(KERN_DEBUG 336 pr_debug("%s: failed to move IBSS STA %pM to state %d (%d) - keeping it anyway\n",
337 "%s: failed to move IBSS STA %pM to state %d (%d) - keeping it anyway.\n", 337 sdata->name, sta->sta.addr, state + 1, err);
338 sdata->name, sta->sta.addr, state + 1, err);
339 err = 0; 338 err = 0;
340 } 339 }
341 340
@@ -619,8 +618,7 @@ static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
619 618
620 local->total_ps_buffered--; 619 local->total_ps_buffered--;
621#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 620#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
622 printk(KERN_DEBUG "Buffered frame expired (STA %pM)\n", 621 pr_debug("Buffered frame expired (STA %pM)\n", sta->sta.addr);
623 sta->sta.addr);
624#endif 622#endif
625 dev_kfree_skb(skb); 623 dev_kfree_skb(skb);
626 } 624 }
@@ -889,10 +887,8 @@ void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
889 continue; 887 continue;
890 888
891 if (time_after(jiffies, sta->last_rx + exp_time)) { 889 if (time_after(jiffies, sta->last_rx + exp_time)) {
892#ifdef CONFIG_MAC80211_IBSS_DEBUG 890 ibss_vdbg("%s: expiring inactive STA %pM\n",
893 printk(KERN_DEBUG "%s: expiring inactive STA %pM\n", 891 sdata->name, sta->sta.addr);
894 sdata->name, sta->sta.addr);
895#endif
896 WARN_ON(__sta_info_destroy(sta)); 892 WARN_ON(__sta_info_destroy(sta));
897 } 893 }
898 } 894 }
@@ -991,9 +987,8 @@ void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
991 sta_info_recalc_tim(sta); 987 sta_info_recalc_tim(sta);
992 988
993#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 989#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
994 printk(KERN_DEBUG "%s: STA %pM aid %d sending %d filtered/%d PS frames " 990 pr_debug("%s: STA %pM aid %d sending %d filtered/%d PS frames since STA not sleeping anymore\n",
995 "since STA not sleeping anymore\n", sdata->name, 991 sdata->name, sta->sta.addr, sta->sta.aid, filtered, buffered);
996 sta->sta.addr, sta->sta.aid, filtered, buffered);
997#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 992#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
998} 993}
999 994
@@ -1385,8 +1380,8 @@ int sta_info_move_state(struct sta_info *sta,
1385 } 1380 }
1386 1381
1387#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 1382#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1388 printk(KERN_DEBUG "%s: moving STA %pM to state %d\n", 1383 pr_debug("%s: moving STA %pM to state %d\n",
1389 sta->sdata->name, sta->sta.addr, new_state); 1384 sta->sdata->name, sta->sta.addr, new_state);
1390#endif 1385#endif
1391 1386
1392 /* 1387 /*
diff --git a/net/mac80211/status.c b/net/mac80211/status.c
index 28cfa981cfb1..6b4f42527887 100644
--- a/net/mac80211/status.c
+++ b/net/mac80211/status.c
@@ -520,36 +520,16 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
520 520
521 if (info->flags & IEEE80211_TX_INTFL_NL80211_FRAME_TX) { 521 if (info->flags & IEEE80211_TX_INTFL_NL80211_FRAME_TX) {
522 u64 cookie = (unsigned long)skb; 522 u64 cookie = (unsigned long)skb;
523 acked = info->flags & IEEE80211_TX_STAT_ACK;
523 524
524 if (ieee80211_is_nullfunc(hdr->frame_control) || 525 if (ieee80211_is_nullfunc(hdr->frame_control) ||
525 ieee80211_is_qos_nullfunc(hdr->frame_control)) { 526 ieee80211_is_qos_nullfunc(hdr->frame_control))
526 acked = info->flags & IEEE80211_TX_STAT_ACK;
527
528 cfg80211_probe_status(skb->dev, hdr->addr1, 527 cfg80211_probe_status(skb->dev, hdr->addr1,
529 cookie, acked, GFP_ATOMIC); 528 cookie, acked, GFP_ATOMIC);
530 } else { 529 else
531 struct ieee80211_work *wk;
532
533 rcu_read_lock();
534 list_for_each_entry_rcu(wk, &local->work_list, list) {
535 if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
536 continue;
537 if (wk->offchan_tx.frame != skb)
538 continue;
539 wk->offchan_tx.status = true;
540 break;
541 }
542 rcu_read_unlock();
543 if (local->hw_roc_skb_for_status == skb) {
544 cookie = local->hw_roc_cookie ^ 2;
545 local->hw_roc_skb_for_status = NULL;
546 }
547
548 cfg80211_mgmt_tx_status( 530 cfg80211_mgmt_tx_status(
549 skb->dev, cookie, skb->data, skb->len, 531 skb->dev, cookie, skb->data, skb->len,
550 !!(info->flags & IEEE80211_TX_STAT_ACK), 532 acked, GFP_ATOMIC);
551 GFP_ATOMIC);
552 }
553 } 533 }
554 534
555 if (unlikely(info->ack_frame_id)) { 535 if (unlikely(info->ack_frame_id)) {
@@ -589,7 +569,7 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
589 /* send frame to monitor interfaces now */ 569 /* send frame to monitor interfaces now */
590 rtap_len = ieee80211_tx_radiotap_len(info); 570 rtap_len = ieee80211_tx_radiotap_len(info);
591 if (WARN_ON_ONCE(skb_headroom(skb) < rtap_len)) { 571 if (WARN_ON_ONCE(skb_headroom(skb) < rtap_len)) {
592 printk(KERN_ERR "ieee80211_tx_status: headroom too small\n"); 572 pr_err("ieee80211_tx_status: headroom too small\n");
593 dev_kfree_skb(skb); 573 dev_kfree_skb(skb);
594 return; 574 return;
595 } 575 }
diff --git a/net/mac80211/tkip.c b/net/mac80211/tkip.c
index 51077a956a83..68be47ca208f 100644
--- a/net/mac80211/tkip.c
+++ b/net/mac80211/tkip.c
@@ -263,12 +263,11 @@ int ieee80211_tkip_decrypt_data(struct crypto_cipher *tfm,
263#ifdef CONFIG_MAC80211_TKIP_DEBUG 263#ifdef CONFIG_MAC80211_TKIP_DEBUG
264 { 264 {
265 int i; 265 int i;
266 printk(KERN_DEBUG "TKIP decrypt: data(len=%zd)", payload_len); 266 pr_debug("TKIP decrypt: data(len=%zd)", payload_len);
267 for (i = 0; i < payload_len; i++) 267 for (i = 0; i < payload_len; i++)
268 printk(" %02x", payload[i]); 268 printk(" %02x", payload[i]);
269 printk("\n"); 269 printk("\n");
270 printk(KERN_DEBUG "TKIP decrypt: iv16=%04x iv32=%08x\n", 270 pr_debug("TKIP decrypt: iv16=%04x iv32=%08x\n", iv16, iv32);
271 iv16, iv32);
272 } 271 }
273#endif 272#endif
274 273
@@ -283,11 +282,10 @@ int ieee80211_tkip_decrypt_data(struct crypto_cipher *tfm,
283 (iv32 == key->u.tkip.rx[queue].iv32 && 282 (iv32 == key->u.tkip.rx[queue].iv32 &&
284 iv16 <= key->u.tkip.rx[queue].iv16))) { 283 iv16 <= key->u.tkip.rx[queue].iv16))) {
285#ifdef CONFIG_MAC80211_TKIP_DEBUG 284#ifdef CONFIG_MAC80211_TKIP_DEBUG
286 printk(KERN_DEBUG "TKIP replay detected for RX frame from " 285 pr_debug("TKIP replay detected for RX frame from %pM (RX IV (%04x,%02x) <= prev. IV (%04x,%02x)\n",
287 "%pM (RX IV (%04x,%02x) <= prev. IV (%04x,%02x)\n", 286 ta, iv32, iv16,
288 ta, 287 key->u.tkip.rx[queue].iv32,
289 iv32, iv16, key->u.tkip.rx[queue].iv32, 288 key->u.tkip.rx[queue].iv16);
290 key->u.tkip.rx[queue].iv16);
291#endif 289#endif
292 return TKIP_DECRYPT_REPLAY; 290 return TKIP_DECRYPT_REPLAY;
293 } 291 }
@@ -306,13 +304,12 @@ int ieee80211_tkip_decrypt_data(struct crypto_cipher *tfm,
306 { 304 {
307 int i; 305 int i;
308 u8 key_offset = NL80211_TKIP_DATA_OFFSET_ENCR_KEY; 306 u8 key_offset = NL80211_TKIP_DATA_OFFSET_ENCR_KEY;
309 printk(KERN_DEBUG "TKIP decrypt: Phase1 TA=%pM" 307 pr_debug("TKIP decrypt: Phase1 TA=%pM TK=", ta);
310 " TK=", ta);
311 for (i = 0; i < 16; i++) 308 for (i = 0; i < 16; i++)
312 printk("%02x ", 309 printk("%02x ",
313 key->conf.key[key_offset + i]); 310 key->conf.key[key_offset + i]);
314 printk("\n"); 311 printk("\n");
315 printk(KERN_DEBUG "TKIP decrypt: P1K="); 312 pr_debug("TKIP decrypt: P1K=");
316 for (i = 0; i < 5; i++) 313 for (i = 0; i < 5; i++)
317 printk("%04x ", key->u.tkip.rx[queue].p1k[i]); 314 printk("%04x ", key->u.tkip.rx[queue].p1k[i]);
318 printk("\n"); 315 printk("\n");
@@ -336,7 +333,7 @@ int ieee80211_tkip_decrypt_data(struct crypto_cipher *tfm,
336#ifdef CONFIG_MAC80211_TKIP_DEBUG 333#ifdef CONFIG_MAC80211_TKIP_DEBUG
337 { 334 {
338 int i; 335 int i;
339 printk(KERN_DEBUG "TKIP decrypt: Phase2 rc4key="); 336 pr_debug("TKIP decrypt: Phase2 rc4key=");
340 for (i = 0; i < 16; i++) 337 for (i = 0; i < 16; i++)
341 printk("%02x ", rc4key[i]); 338 printk("%02x ", rc4key[i]);
342 printk("\n"); 339 printk("\n");
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c
index e453212fa17f..af25c4e7ec5c 100644
--- a/net/mac80211/tx.c
+++ b/net/mac80211/tx.c
@@ -297,9 +297,8 @@ ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
297 if (unlikely(!assoc && 297 if (unlikely(!assoc &&
298 ieee80211_is_data(hdr->frame_control))) { 298 ieee80211_is_data(hdr->frame_control))) {
299#ifdef CONFIG_MAC80211_VERBOSE_DEBUG 299#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
300 printk(KERN_DEBUG "%s: dropped data frame to not " 300 pr_debug("%s: dropped data frame to not associated station %pM\n",
301 "associated station %pM\n", 301 tx->sdata->name, hdr->addr1);
302 tx->sdata->name, hdr->addr1);
303#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ 302#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
304 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc); 303 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
305 return TX_DROP; 304 return TX_DROP;
@@ -467,8 +466,8 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
467 } 466 }
468 467
469#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 468#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
470 printk(KERN_DEBUG "STA %pM aid %d: PS buffer for AC %d\n", 469 pr_debug("STA %pM aid %d: PS buffer for AC %d\n",
471 sta->sta.addr, sta->sta.aid, ac); 470 sta->sta.addr, sta->sta.aid, ac);
472#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 471#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
473 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) 472 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
474 purge_old_ps_buffers(tx->local); 473 purge_old_ps_buffers(tx->local);
@@ -502,9 +501,8 @@ ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
502 } 501 }
503#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG 502#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
504 else if (unlikely(test_sta_flag(sta, WLAN_STA_PS_STA))) { 503 else if (unlikely(test_sta_flag(sta, WLAN_STA_PS_STA))) {
505 printk(KERN_DEBUG 504 pr_debug("%s: STA %pM in PS mode, but polling/in SP -> send frame\n",
506 "%s: STA %pM in PS mode, but polling/in SP -> send frame\n", 505 tx->sdata->name, sta->sta.addr);
507 tx->sdata->name, sta->sta.addr);
508 } 506 }
509#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ 507#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
510 508
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 8dd4712620ff..1df4019f294b 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -804,7 +804,7 @@ void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
804 struct ieee80211_local *local = sdata->local; 804 struct ieee80211_local *local = sdata->local;
805 struct ieee80211_tx_queue_params qparam; 805 struct ieee80211_tx_queue_params qparam;
806 int ac; 806 int ac;
807 bool use_11b; 807 bool use_11b, enable_qos;
808 int aCWmin, aCWmax; 808 int aCWmin, aCWmax;
809 809
810 if (!local->ops->conf_tx) 810 if (!local->ops->conf_tx)
@@ -818,6 +818,13 @@ void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
818 use_11b = (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) && 818 use_11b = (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) &&
819 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE); 819 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE);
820 820
821 /*
822 * By default disable QoS in STA mode for old access points, which do
823 * not support 802.11e. New APs will provide proper queue parameters,
824 * that we will configure later.
825 */
826 enable_qos = (sdata->vif.type != NL80211_IFTYPE_STATION);
827
821 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 828 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
822 /* Set defaults according to 802.11-2007 Table 7-37 */ 829 /* Set defaults according to 802.11-2007 Table 7-37 */
823 aCWmax = 1023; 830 aCWmax = 1023;
@@ -826,38 +833,47 @@ void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
826 else 833 else
827 aCWmin = 15; 834 aCWmin = 15;
828 835
829 switch (ac) { 836 if (enable_qos) {
830 case IEEE80211_AC_BK: 837 switch (ac) {
831 qparam.cw_max = aCWmax; 838 case IEEE80211_AC_BK:
832 qparam.cw_min = aCWmin; 839 qparam.cw_max = aCWmax;
833 qparam.txop = 0; 840 qparam.cw_min = aCWmin;
834 qparam.aifs = 7; 841 qparam.txop = 0;
835 break; 842 qparam.aifs = 7;
836 default: /* never happens but let's not leave undefined */ 843 break;
837 case IEEE80211_AC_BE: 844 /* never happens but let's not leave undefined */
845 default:
846 case IEEE80211_AC_BE:
847 qparam.cw_max = aCWmax;
848 qparam.cw_min = aCWmin;
849 qparam.txop = 0;
850 qparam.aifs = 3;
851 break;
852 case IEEE80211_AC_VI:
853 qparam.cw_max = aCWmin;
854 qparam.cw_min = (aCWmin + 1) / 2 - 1;
855 if (use_11b)
856 qparam.txop = 6016/32;
857 else
858 qparam.txop = 3008/32;
859 qparam.aifs = 2;
860 break;
861 case IEEE80211_AC_VO:
862 qparam.cw_max = (aCWmin + 1) / 2 - 1;
863 qparam.cw_min = (aCWmin + 1) / 4 - 1;
864 if (use_11b)
865 qparam.txop = 3264/32;
866 else
867 qparam.txop = 1504/32;
868 qparam.aifs = 2;
869 break;
870 }
871 } else {
872 /* Confiure old 802.11b/g medium access rules. */
838 qparam.cw_max = aCWmax; 873 qparam.cw_max = aCWmax;
839 qparam.cw_min = aCWmin; 874 qparam.cw_min = aCWmin;
840 qparam.txop = 0; 875 qparam.txop = 0;
841 qparam.aifs = 3;
842 break;
843 case IEEE80211_AC_VI:
844 qparam.cw_max = aCWmin;
845 qparam.cw_min = (aCWmin + 1) / 2 - 1;
846 if (use_11b)
847 qparam.txop = 6016/32;
848 else
849 qparam.txop = 3008/32;
850 qparam.aifs = 2;
851 break;
852 case IEEE80211_AC_VO:
853 qparam.cw_max = (aCWmin + 1) / 2 - 1;
854 qparam.cw_min = (aCWmin + 1) / 4 - 1;
855 if (use_11b)
856 qparam.txop = 3264/32;
857 else
858 qparam.txop = 1504/32;
859 qparam.aifs = 2; 876 qparam.aifs = 2;
860 break;
861 } 877 }
862 878
863 qparam.uapsd = false; 879 qparam.uapsd = false;
@@ -866,12 +882,8 @@ void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
866 drv_conf_tx(local, sdata, ac, &qparam); 882 drv_conf_tx(local, sdata, ac, &qparam);
867 } 883 }
868 884
869 /* after reinitialize QoS TX queues setting to default,
870 * disable QoS at all */
871
872 if (sdata->vif.type != NL80211_IFTYPE_MONITOR) { 885 if (sdata->vif.type != NL80211_IFTYPE_MONITOR) {
873 sdata->vif.bss_conf.qos = 886 sdata->vif.bss_conf.qos = enable_qos;
874 sdata->vif.type != NL80211_IFTYPE_STATION;
875 if (bss_notify) 887 if (bss_notify)
876 ieee80211_bss_info_change_notify(sdata, 888 ieee80211_bss_info_change_notify(sdata,
877 BSS_CHANGED_QOS); 889 BSS_CHANGED_QOS);
@@ -1267,14 +1279,19 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1267 /* add STAs back */ 1279 /* add STAs back */
1268 mutex_lock(&local->sta_mtx); 1280 mutex_lock(&local->sta_mtx);
1269 list_for_each_entry(sta, &local->sta_list, list) { 1281 list_for_each_entry(sta, &local->sta_list, list) {
1270 if (sta->uploaded) { 1282 enum ieee80211_sta_state state;
1271 enum ieee80211_sta_state state;
1272 1283
1273 for (state = IEEE80211_STA_NOTEXIST; 1284 if (!sta->uploaded)
1274 state < sta->sta_state; state++) 1285 continue;
1275 WARN_ON(drv_sta_state(local, sta->sdata, sta, 1286
1276 state, state + 1)); 1287 /* AP-mode stations will be added later */
1277 } 1288 if (sta->sdata->vif.type == NL80211_IFTYPE_AP)
1289 continue;
1290
1291 for (state = IEEE80211_STA_NOTEXIST;
1292 state < sta->sta_state; state++)
1293 WARN_ON(drv_sta_state(local, sta->sdata, sta, state,
1294 state + 1));
1278 } 1295 }
1279 mutex_unlock(&local->sta_mtx); 1296 mutex_unlock(&local->sta_mtx);
1280 1297
@@ -1371,6 +1388,24 @@ int ieee80211_reconfig(struct ieee80211_local *local)
1371 } 1388 }
1372 } 1389 }
1373 1390
1391 /* APs are now beaconing, add back stations */
1392 mutex_lock(&local->sta_mtx);
1393 list_for_each_entry(sta, &local->sta_list, list) {
1394 enum ieee80211_sta_state state;
1395
1396 if (!sta->uploaded)
1397 continue;
1398
1399 if (sta->sdata->vif.type != NL80211_IFTYPE_AP)
1400 continue;
1401
1402 for (state = IEEE80211_STA_NOTEXIST;
1403 state < sta->sta_state; state++)
1404 WARN_ON(drv_sta_state(local, sta->sdata, sta, state,
1405 state + 1));
1406 }
1407 mutex_unlock(&local->sta_mtx);
1408
1374 /* add back keys */ 1409 /* add back keys */
1375 list_for_each_entry(sdata, &local->interfaces, list) 1410 list_for_each_entry(sdata, &local->interfaces, list)
1376 if (ieee80211_sdata_running(sdata)) 1411 if (ieee80211_sdata_running(sdata))
diff --git a/net/mac80211/work.c b/net/mac80211/work.c
deleted file mode 100644
index b2650a9d45ff..000000000000
--- a/net/mac80211/work.c
+++ /dev/null
@@ -1,370 +0,0 @@
1/*
2 * mac80211 work implementation
3 *
4 * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
5 * Copyright 2004, Instant802 Networks, Inc.
6 * Copyright 2005, Devicescape Software, Inc.
7 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
9 * Copyright 2009, Johannes Berg <johannes@sipsolutions.net>
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#include <linux/delay.h>
17#include <linux/if_ether.h>
18#include <linux/skbuff.h>
19#include <linux/if_arp.h>
20#include <linux/etherdevice.h>
21#include <linux/crc32.h>
22#include <linux/slab.h>
23#include <net/mac80211.h>
24#include <asm/unaligned.h>
25
26#include "ieee80211_i.h"
27#include "rate.h"
28#include "driver-ops.h"
29
30enum work_action {
31 WORK_ACT_NONE,
32 WORK_ACT_TIMEOUT,
33};
34
35
36/* utils */
37static inline void ASSERT_WORK_MTX(struct ieee80211_local *local)
38{
39 lockdep_assert_held(&local->mtx);
40}
41
42/*
43 * We can have multiple work items (and connection probing)
44 * scheduling this timer, but we need to take care to only
45 * reschedule it when it should fire _earlier_ than it was
46 * asked for before, or if it's not pending right now. This
47 * function ensures that. Note that it then is required to
48 * run this function for all timeouts after the first one
49 * has happened -- the work that runs from this timer will
50 * do that.
51 */
52static void run_again(struct ieee80211_local *local,
53 unsigned long timeout)
54{
55 ASSERT_WORK_MTX(local);
56
57 if (!timer_pending(&local->work_timer) ||
58 time_before(timeout, local->work_timer.expires))
59 mod_timer(&local->work_timer, timeout);
60}
61
62void free_work(struct ieee80211_work *wk)
63{
64 kfree_rcu(wk, rcu_head);
65}
66
67static enum work_action __must_check
68ieee80211_remain_on_channel_timeout(struct ieee80211_work *wk)
69{
70 /*
71 * First time we run, do nothing -- the generic code will
72 * have switched to the right channel etc.
73 */
74 if (!wk->started) {
75 wk->timeout = jiffies + msecs_to_jiffies(wk->remain.duration);
76
77 cfg80211_ready_on_channel(wk->sdata->dev, (unsigned long) wk,
78 wk->chan, wk->chan_type,
79 wk->remain.duration, GFP_KERNEL);
80
81 return WORK_ACT_NONE;
82 }
83
84 return WORK_ACT_TIMEOUT;
85}
86
87static enum work_action __must_check
88ieee80211_offchannel_tx(struct ieee80211_work *wk)
89{
90 if (!wk->started) {
91 wk->timeout = jiffies + msecs_to_jiffies(wk->offchan_tx.wait);
92
93 /*
94 * After this, offchan_tx.frame remains but now is no
95 * longer a valid pointer -- we still need it as the
96 * cookie for canceling this work/status matching.
97 */
98 ieee80211_tx_skb(wk->sdata, wk->offchan_tx.frame);
99
100 return WORK_ACT_NONE;
101 }
102
103 return WORK_ACT_TIMEOUT;
104}
105
106static void ieee80211_work_timer(unsigned long data)
107{
108 struct ieee80211_local *local = (void *) data;
109
110 if (local->quiescing)
111 return;
112
113 ieee80211_queue_work(&local->hw, &local->work_work);
114}
115
116static void ieee80211_work_work(struct work_struct *work)
117{
118 struct ieee80211_local *local =
119 container_of(work, struct ieee80211_local, work_work);
120 struct ieee80211_work *wk, *tmp;
121 LIST_HEAD(free_work);
122 enum work_action rma;
123 bool remain_off_channel = false;
124
125 /*
126 * ieee80211_queue_work() should have picked up most cases,
127 * here we'll pick the rest.
128 */
129 if (WARN(local->suspended, "work scheduled while going to suspend\n"))
130 return;
131
132 mutex_lock(&local->mtx);
133
134 if (local->scanning) {
135 mutex_unlock(&local->mtx);
136 return;
137 }
138
139 ieee80211_recalc_idle(local);
140
141 list_for_each_entry_safe(wk, tmp, &local->work_list, list) {
142 bool started = wk->started;
143
144 /* mark work as started if it's on the current off-channel */
145 if (!started && local->tmp_channel &&
146 wk->chan == local->tmp_channel &&
147 wk->chan_type == local->tmp_channel_type) {
148 started = true;
149 wk->timeout = jiffies;
150 }
151
152 if (!started && !local->tmp_channel) {
153 ieee80211_offchannel_stop_vifs(local, true);
154
155 local->tmp_channel = wk->chan;
156 local->tmp_channel_type = wk->chan_type;
157
158 ieee80211_hw_config(local, 0);
159
160 started = true;
161 wk->timeout = jiffies;
162 }
163
164 /* don't try to work with items that aren't started */
165 if (!started)
166 continue;
167
168 if (time_is_after_jiffies(wk->timeout)) {
169 /*
170 * This work item isn't supposed to be worked on
171 * right now, but take care to adjust the timer
172 * properly.
173 */
174 run_again(local, wk->timeout);
175 continue;
176 }
177
178 switch (wk->type) {
179 default:
180 WARN_ON(1);
181 /* nothing */
182 rma = WORK_ACT_NONE;
183 break;
184 case IEEE80211_WORK_ABORT:
185 rma = WORK_ACT_TIMEOUT;
186 break;
187 case IEEE80211_WORK_REMAIN_ON_CHANNEL:
188 rma = ieee80211_remain_on_channel_timeout(wk);
189 break;
190 case IEEE80211_WORK_OFFCHANNEL_TX:
191 rma = ieee80211_offchannel_tx(wk);
192 break;
193 }
194
195 wk->started = started;
196
197 switch (rma) {
198 case WORK_ACT_NONE:
199 /* might have changed the timeout */
200 run_again(local, wk->timeout);
201 break;
202 case WORK_ACT_TIMEOUT:
203 list_del_rcu(&wk->list);
204 synchronize_rcu();
205 list_add(&wk->list, &free_work);
206 break;
207 default:
208 WARN(1, "unexpected: %d", rma);
209 }
210 }
211
212 list_for_each_entry(wk, &local->work_list, list) {
213 if (!wk->started)
214 continue;
215 if (wk->chan != local->tmp_channel ||
216 wk->chan_type != local->tmp_channel_type)
217 continue;
218 remain_off_channel = true;
219 }
220
221 if (!remain_off_channel && local->tmp_channel) {
222 local->tmp_channel = NULL;
223 ieee80211_hw_config(local, 0);
224
225 ieee80211_offchannel_return(local, true);
226
227 /* give connection some time to breathe */
228 run_again(local, jiffies + HZ/2);
229 }
230
231 ieee80211_recalc_idle(local);
232 ieee80211_run_deferred_scan(local);
233
234 mutex_unlock(&local->mtx);
235
236 list_for_each_entry_safe(wk, tmp, &free_work, list) {
237 wk->done(wk, NULL);
238 list_del(&wk->list);
239 kfree(wk);
240 }
241}
242
243void ieee80211_add_work(struct ieee80211_work *wk)
244{
245 struct ieee80211_local *local;
246
247 if (WARN_ON(!wk->chan))
248 return;
249
250 if (WARN_ON(!wk->sdata))
251 return;
252
253 if (WARN_ON(!wk->done))
254 return;
255
256 if (WARN_ON(!ieee80211_sdata_running(wk->sdata)))
257 return;
258
259 wk->started = false;
260
261 local = wk->sdata->local;
262 mutex_lock(&local->mtx);
263 list_add_tail(&wk->list, &local->work_list);
264 mutex_unlock(&local->mtx);
265
266 ieee80211_queue_work(&local->hw, &local->work_work);
267}
268
269void ieee80211_work_init(struct ieee80211_local *local)
270{
271 INIT_LIST_HEAD(&local->work_list);
272 setup_timer(&local->work_timer, ieee80211_work_timer,
273 (unsigned long)local);
274 INIT_WORK(&local->work_work, ieee80211_work_work);
275}
276
277void ieee80211_work_purge(struct ieee80211_sub_if_data *sdata)
278{
279 struct ieee80211_local *local = sdata->local;
280 struct ieee80211_work *wk;
281 bool cleanup = false;
282
283 mutex_lock(&local->mtx);
284 list_for_each_entry(wk, &local->work_list, list) {
285 if (wk->sdata != sdata)
286 continue;
287 cleanup = true;
288 wk->type = IEEE80211_WORK_ABORT;
289 wk->started = true;
290 wk->timeout = jiffies;
291 }
292 mutex_unlock(&local->mtx);
293
294 /* run cleanups etc. */
295 if (cleanup)
296 ieee80211_work_work(&local->work_work);
297
298 mutex_lock(&local->mtx);
299 list_for_each_entry(wk, &local->work_list, list) {
300 if (wk->sdata != sdata)
301 continue;
302 WARN_ON(1);
303 break;
304 }
305 mutex_unlock(&local->mtx);
306}
307
308static enum work_done_result ieee80211_remain_done(struct ieee80211_work *wk,
309 struct sk_buff *skb)
310{
311 /*
312 * We are done serving the remain-on-channel command.
313 */
314 cfg80211_remain_on_channel_expired(wk->sdata->dev, (unsigned long) wk,
315 wk->chan, wk->chan_type,
316 GFP_KERNEL);
317
318 return WORK_DONE_DESTROY;
319}
320
321int ieee80211_wk_remain_on_channel(struct ieee80211_sub_if_data *sdata,
322 struct ieee80211_channel *chan,
323 enum nl80211_channel_type channel_type,
324 unsigned int duration, u64 *cookie)
325{
326 struct ieee80211_work *wk;
327
328 wk = kzalloc(sizeof(*wk), GFP_KERNEL);
329 if (!wk)
330 return -ENOMEM;
331
332 wk->type = IEEE80211_WORK_REMAIN_ON_CHANNEL;
333 wk->chan = chan;
334 wk->chan_type = channel_type;
335 wk->sdata = sdata;
336 wk->done = ieee80211_remain_done;
337
338 wk->remain.duration = duration;
339
340 *cookie = (unsigned long) wk;
341
342 ieee80211_add_work(wk);
343
344 return 0;
345}
346
347int ieee80211_wk_cancel_remain_on_channel(struct ieee80211_sub_if_data *sdata,
348 u64 cookie)
349{
350 struct ieee80211_local *local = sdata->local;
351 struct ieee80211_work *wk, *tmp;
352 bool found = false;
353
354 mutex_lock(&local->mtx);
355 list_for_each_entry_safe(wk, tmp, &local->work_list, list) {
356 if ((unsigned long) wk == cookie) {
357 wk->timeout = jiffies;
358 found = true;
359 break;
360 }
361 }
362 mutex_unlock(&local->mtx);
363
364 if (!found)
365 return -ENOENT;
366
367 ieee80211_queue_work(&local->hw, &local->work_work);
368
369 return 0;
370}
diff --git a/net/nfc/core.c b/net/nfc/core.c
index 9f6ce011d35d..4177bb5104b9 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -121,14 +121,14 @@ error:
121 * The device remains polling for targets until a target is found or 121 * The device remains polling for targets until a target is found or
122 * the nfc_stop_poll function is called. 122 * the nfc_stop_poll function is called.
123 */ 123 */
124int nfc_start_poll(struct nfc_dev *dev, u32 protocols) 124int nfc_start_poll(struct nfc_dev *dev, u32 im_protocols, u32 tm_protocols)
125{ 125{
126 int rc; 126 int rc;
127 127
128 pr_debug("dev_name=%s protocols=0x%x\n", 128 pr_debug("dev_name %s initiator protocols 0x%x target protocols 0x%x\n",
129 dev_name(&dev->dev), protocols); 129 dev_name(&dev->dev), im_protocols, tm_protocols);
130 130
131 if (!protocols) 131 if (!im_protocols && !tm_protocols)
132 return -EINVAL; 132 return -EINVAL;
133 133
134 device_lock(&dev->dev); 134 device_lock(&dev->dev);
@@ -143,9 +143,11 @@ int nfc_start_poll(struct nfc_dev *dev, u32 protocols)
143 goto error; 143 goto error;
144 } 144 }
145 145
146 rc = dev->ops->start_poll(dev, protocols); 146 rc = dev->ops->start_poll(dev, im_protocols, tm_protocols);
147 if (!rc) 147 if (!rc) {
148 dev->polling = true; 148 dev->polling = true;
149 dev->rf_mode = NFC_RF_NONE;
150 }
149 151
150error: 152error:
151 device_unlock(&dev->dev); 153 device_unlock(&dev->dev);
@@ -235,8 +237,10 @@ int nfc_dep_link_up(struct nfc_dev *dev, int target_index, u8 comm_mode)
235 } 237 }
236 238
237 rc = dev->ops->dep_link_up(dev, target, comm_mode, gb, gb_len); 239 rc = dev->ops->dep_link_up(dev, target, comm_mode, gb, gb_len);
238 if (!rc) 240 if (!rc) {
239 dev->active_target = target; 241 dev->active_target = target;
242 dev->rf_mode = NFC_RF_INITIATOR;
243 }
240 244
241error: 245error:
242 device_unlock(&dev->dev); 246 device_unlock(&dev->dev);
@@ -264,11 +268,6 @@ int nfc_dep_link_down(struct nfc_dev *dev)
264 goto error; 268 goto error;
265 } 269 }
266 270
267 if (dev->dep_rf_mode == NFC_RF_TARGET) {
268 rc = -EOPNOTSUPP;
269 goto error;
270 }
271
272 rc = dev->ops->dep_link_down(dev); 271 rc = dev->ops->dep_link_down(dev);
273 if (!rc) { 272 if (!rc) {
274 dev->dep_link_up = false; 273 dev->dep_link_up = false;
@@ -286,7 +285,6 @@ int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx,
286 u8 comm_mode, u8 rf_mode) 285 u8 comm_mode, u8 rf_mode)
287{ 286{
288 dev->dep_link_up = true; 287 dev->dep_link_up = true;
289 dev->dep_rf_mode = rf_mode;
290 288
291 nfc_llcp_mac_is_up(dev, target_idx, comm_mode, rf_mode); 289 nfc_llcp_mac_is_up(dev, target_idx, comm_mode, rf_mode);
292 290
@@ -330,6 +328,7 @@ int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol)
330 rc = dev->ops->activate_target(dev, target, protocol); 328 rc = dev->ops->activate_target(dev, target, protocol);
331 if (!rc) { 329 if (!rc) {
332 dev->active_target = target; 330 dev->active_target = target;
331 dev->rf_mode = NFC_RF_INITIATOR;
333 332
334 if (dev->ops->check_presence) 333 if (dev->ops->check_presence)
335 mod_timer(&dev->check_pres_timer, jiffies + 334 mod_timer(&dev->check_pres_timer, jiffies +
@@ -409,27 +408,30 @@ int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb,
409 goto error; 408 goto error;
410 } 409 }
411 410
412 if (dev->active_target == NULL) { 411 if (dev->rf_mode == NFC_RF_INITIATOR && dev->active_target != NULL) {
413 rc = -ENOTCONN; 412 if (dev->active_target->idx != target_idx) {
414 kfree_skb(skb); 413 rc = -EADDRNOTAVAIL;
415 goto error; 414 kfree_skb(skb);
416 } 415 goto error;
416 }
417 417
418 if (dev->active_target->idx != target_idx) { 418 if (dev->ops->check_presence)
419 rc = -EADDRNOTAVAIL; 419 del_timer_sync(&dev->check_pres_timer);
420
421 rc = dev->ops->im_transceive(dev, dev->active_target, skb, cb,
422 cb_context);
423
424 if (!rc && dev->ops->check_presence)
425 mod_timer(&dev->check_pres_timer, jiffies +
426 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
427 } else if (dev->rf_mode == NFC_RF_TARGET && dev->ops->tm_send != NULL) {
428 rc = dev->ops->tm_send(dev, skb);
429 } else {
430 rc = -ENOTCONN;
420 kfree_skb(skb); 431 kfree_skb(skb);
421 goto error; 432 goto error;
422 } 433 }
423 434
424 if (dev->ops->check_presence)
425 del_timer_sync(&dev->check_pres_timer);
426
427 rc = dev->ops->data_exchange(dev, dev->active_target, skb, cb,
428 cb_context);
429
430 if (!rc && dev->ops->check_presence)
431 mod_timer(&dev->check_pres_timer, jiffies +
432 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
433 435
434error: 436error:
435 device_unlock(&dev->dev); 437 device_unlock(&dev->dev);
@@ -447,6 +449,63 @@ int nfc_set_remote_general_bytes(struct nfc_dev *dev, u8 *gb, u8 gb_len)
447} 449}
448EXPORT_SYMBOL(nfc_set_remote_general_bytes); 450EXPORT_SYMBOL(nfc_set_remote_general_bytes);
449 451
452u8 *nfc_get_local_general_bytes(struct nfc_dev *dev, size_t *gb_len)
453{
454 pr_debug("dev_name=%s\n", dev_name(&dev->dev));
455
456 return nfc_llcp_general_bytes(dev, gb_len);
457}
458EXPORT_SYMBOL(nfc_get_local_general_bytes);
459
460int nfc_tm_data_received(struct nfc_dev *dev, struct sk_buff *skb)
461{
462 /* Only LLCP target mode for now */
463 if (dev->dep_link_up == false) {
464 kfree_skb(skb);
465 return -ENOLINK;
466 }
467
468 return nfc_llcp_data_received(dev, skb);
469}
470EXPORT_SYMBOL(nfc_tm_data_received);
471
472int nfc_tm_activated(struct nfc_dev *dev, u32 protocol, u8 comm_mode,
473 u8 *gb, size_t gb_len)
474{
475 int rc;
476
477 device_lock(&dev->dev);
478
479 dev->polling = false;
480
481 if (gb != NULL) {
482 rc = nfc_set_remote_general_bytes(dev, gb, gb_len);
483 if (rc < 0)
484 goto out;
485 }
486
487 dev->rf_mode = NFC_RF_TARGET;
488
489 if (protocol == NFC_PROTO_NFC_DEP_MASK)
490 nfc_dep_link_is_up(dev, 0, comm_mode, NFC_RF_TARGET);
491
492 rc = nfc_genl_tm_activated(dev, protocol);
493
494out:
495 device_unlock(&dev->dev);
496
497 return rc;
498}
499EXPORT_SYMBOL(nfc_tm_activated);
500
501int nfc_tm_deactivated(struct nfc_dev *dev)
502{
503 dev->dep_link_up = false;
504
505 return nfc_genl_tm_deactivated(dev);
506}
507EXPORT_SYMBOL(nfc_tm_deactivated);
508
450/** 509/**
451 * nfc_alloc_send_skb - allocate a skb for data exchange responses 510 * nfc_alloc_send_skb - allocate a skb for data exchange responses
452 * 511 *
@@ -678,7 +737,7 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
678 struct nfc_dev *dev; 737 struct nfc_dev *dev;
679 738
680 if (!ops->start_poll || !ops->stop_poll || !ops->activate_target || 739 if (!ops->start_poll || !ops->stop_poll || !ops->activate_target ||
681 !ops->deactivate_target || !ops->data_exchange) 740 !ops->deactivate_target || !ops->im_transceive)
682 return NULL; 741 return NULL;
683 742
684 if (!supported_protocols) 743 if (!supported_protocols)
diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c
index e1a640d2b588..a8b0b71e8f86 100644
--- a/net/nfc/hci/core.c
+++ b/net/nfc/hci/core.c
@@ -481,12 +481,13 @@ static int hci_dev_down(struct nfc_dev *nfc_dev)
481 return 0; 481 return 0;
482} 482}
483 483
484static int hci_start_poll(struct nfc_dev *nfc_dev, u32 protocols) 484static int hci_start_poll(struct nfc_dev *nfc_dev,
485 u32 im_protocols, u32 tm_protocols)
485{ 486{
486 struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev); 487 struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
487 488
488 if (hdev->ops->start_poll) 489 if (hdev->ops->start_poll)
489 return hdev->ops->start_poll(hdev, protocols); 490 return hdev->ops->start_poll(hdev, im_protocols, tm_protocols);
490 else 491 else
491 return nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE, 492 return nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE,
492 NFC_HCI_EVT_READER_REQUESTED, NULL, 0); 493 NFC_HCI_EVT_READER_REQUESTED, NULL, 0);
@@ -511,9 +512,9 @@ static void hci_deactivate_target(struct nfc_dev *nfc_dev,
511{ 512{
512} 513}
513 514
514static int hci_data_exchange(struct nfc_dev *nfc_dev, struct nfc_target *target, 515static int hci_transceive(struct nfc_dev *nfc_dev, struct nfc_target *target,
515 struct sk_buff *skb, data_exchange_cb_t cb, 516 struct sk_buff *skb, data_exchange_cb_t cb,
516 void *cb_context) 517 void *cb_context)
517{ 518{
518 struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev); 519 struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
519 int r; 520 int r;
@@ -579,7 +580,7 @@ static struct nfc_ops hci_nfc_ops = {
579 .stop_poll = hci_stop_poll, 580 .stop_poll = hci_stop_poll,
580 .activate_target = hci_activate_target, 581 .activate_target = hci_activate_target,
581 .deactivate_target = hci_deactivate_target, 582 .deactivate_target = hci_deactivate_target,
582 .data_exchange = hci_data_exchange, 583 .im_transceive = hci_transceive,
583 .check_presence = hci_check_presence, 584 .check_presence = hci_check_presence,
584}; 585};
585 586
diff --git a/net/nfc/hci/shdlc.c b/net/nfc/hci/shdlc.c
index 5665dc6d893a..6b836e6242b7 100644
--- a/net/nfc/hci/shdlc.c
+++ b/net/nfc/hci/shdlc.c
@@ -765,14 +765,16 @@ static int nfc_shdlc_xmit(struct nfc_hci_dev *hdev, struct sk_buff *skb)
765 return 0; 765 return 0;
766} 766}
767 767
768static int nfc_shdlc_start_poll(struct nfc_hci_dev *hdev, u32 protocols) 768static int nfc_shdlc_start_poll(struct nfc_hci_dev *hdev,
769 u32 im_protocols, u32 tm_protocols)
769{ 770{
770 struct nfc_shdlc *shdlc = nfc_hci_get_clientdata(hdev); 771 struct nfc_shdlc *shdlc = nfc_hci_get_clientdata(hdev);
771 772
772 pr_debug("\n"); 773 pr_debug("\n");
773 774
774 if (shdlc->ops->start_poll) 775 if (shdlc->ops->start_poll)
775 return shdlc->ops->start_poll(shdlc, protocols); 776 return shdlc->ops->start_poll(shdlc,
777 im_protocols, tm_protocols);
776 778
777 return 0; 779 return 0;
778} 780}
diff --git a/net/nfc/llcp/commands.c b/net/nfc/llcp/commands.c
index bf8ae4f0b90c..b982b5b890d7 100644
--- a/net/nfc/llcp/commands.c
+++ b/net/nfc/llcp/commands.c
@@ -51,7 +51,7 @@ static u8 llcp_tlv8(u8 *tlv, u8 type)
51 return tlv[2]; 51 return tlv[2];
52} 52}
53 53
54static u8 llcp_tlv16(u8 *tlv, u8 type) 54static u16 llcp_tlv16(u8 *tlv, u8 type)
55{ 55{
56 if (tlv[0] != type || tlv[1] != llcp_tlv_length[tlv[0]]) 56 if (tlv[0] != type || tlv[1] != llcp_tlv_length[tlv[0]])
57 return 0; 57 return 0;
@@ -67,7 +67,7 @@ static u8 llcp_tlv_version(u8 *tlv)
67 67
68static u16 llcp_tlv_miux(u8 *tlv) 68static u16 llcp_tlv_miux(u8 *tlv)
69{ 69{
70 return llcp_tlv16(tlv, LLCP_TLV_MIUX) & 0x7f; 70 return llcp_tlv16(tlv, LLCP_TLV_MIUX) & 0x7ff;
71} 71}
72 72
73static u16 llcp_tlv_wks(u8 *tlv) 73static u16 llcp_tlv_wks(u8 *tlv)
@@ -117,8 +117,8 @@ u8 *nfc_llcp_build_tlv(u8 type, u8 *value, u8 value_length, u8 *tlv_length)
117 return tlv; 117 return tlv;
118} 118}
119 119
120int nfc_llcp_parse_tlv(struct nfc_llcp_local *local, 120int nfc_llcp_parse_gb_tlv(struct nfc_llcp_local *local,
121 u8 *tlv_array, u16 tlv_array_len) 121 u8 *tlv_array, u16 tlv_array_len)
122{ 122{
123 u8 *tlv = tlv_array, type, length, offset = 0; 123 u8 *tlv = tlv_array, type, length, offset = 0;
124 124
@@ -149,8 +149,45 @@ int nfc_llcp_parse_tlv(struct nfc_llcp_local *local,
149 case LLCP_TLV_OPT: 149 case LLCP_TLV_OPT:
150 local->remote_opt = llcp_tlv_opt(tlv); 150 local->remote_opt = llcp_tlv_opt(tlv);
151 break; 151 break;
152 default:
153 pr_err("Invalid gt tlv value 0x%x\n", type);
154 break;
155 }
156
157 offset += length + 2;
158 tlv += length + 2;
159 }
160
161 pr_debug("version 0x%x miu %d lto %d opt 0x%x wks 0x%x\n",
162 local->remote_version, local->remote_miu,
163 local->remote_lto, local->remote_opt,
164 local->remote_wks);
165
166 return 0;
167}
168
169int nfc_llcp_parse_connection_tlv(struct nfc_llcp_sock *sock,
170 u8 *tlv_array, u16 tlv_array_len)
171{
172 u8 *tlv = tlv_array, type, length, offset = 0;
173
174 pr_debug("TLV array length %d\n", tlv_array_len);
175
176 if (sock == NULL)
177 return -ENOTCONN;
178
179 while (offset < tlv_array_len) {
180 type = tlv[0];
181 length = tlv[1];
182
183 pr_debug("type 0x%x length %d\n", type, length);
184
185 switch (type) {
186 case LLCP_TLV_MIUX:
187 sock->miu = llcp_tlv_miux(tlv) + 128;
188 break;
152 case LLCP_TLV_RW: 189 case LLCP_TLV_RW:
153 local->remote_rw = llcp_tlv_rw(tlv); 190 sock->rw = llcp_tlv_rw(tlv);
154 break; 191 break;
155 case LLCP_TLV_SN: 192 case LLCP_TLV_SN:
156 break; 193 break;
@@ -163,10 +200,7 @@ int nfc_llcp_parse_tlv(struct nfc_llcp_local *local,
163 tlv += length + 2; 200 tlv += length + 2;
164 } 201 }
165 202
166 pr_debug("version 0x%x miu %d lto %d opt 0x%x wks 0x%x rw %d\n", 203 pr_debug("sock %p rw %d miu %d\n", sock, sock->rw, sock->miu);
167 local->remote_version, local->remote_miu,
168 local->remote_lto, local->remote_opt,
169 local->remote_wks, local->remote_rw);
170 204
171 return 0; 205 return 0;
172} 206}
@@ -474,7 +508,7 @@ int nfc_llcp_send_i_frame(struct nfc_llcp_sock *sock,
474 508
475 while (remaining_len > 0) { 509 while (remaining_len > 0) {
476 510
477 frag_len = min_t(size_t, local->remote_miu, remaining_len); 511 frag_len = min_t(size_t, sock->miu, remaining_len);
478 512
479 pr_debug("Fragment %zd bytes remaining %zd", 513 pr_debug("Fragment %zd bytes remaining %zd",
480 frag_len, remaining_len); 514 frag_len, remaining_len);
diff --git a/net/nfc/llcp/llcp.c b/net/nfc/llcp/llcp.c
index 42994fac26d6..5d503eeb15a1 100644
--- a/net/nfc/llcp/llcp.c
+++ b/net/nfc/llcp/llcp.c
@@ -31,47 +31,41 @@ static u8 llcp_magic[3] = {0x46, 0x66, 0x6d};
31 31
32static struct list_head llcp_devices; 32static struct list_head llcp_devices;
33 33
34static void nfc_llcp_socket_release(struct nfc_llcp_local *local) 34void nfc_llcp_sock_link(struct llcp_sock_list *l, struct sock *sk)
35{ 35{
36 struct nfc_llcp_sock *parent, *s, *n; 36 write_lock(&l->lock);
37 struct sock *sk, *parent_sk; 37 sk_add_node(sk, &l->head);
38 int i; 38 write_unlock(&l->lock);
39 39}
40 mutex_lock(&local->socket_lock);
41
42 for (i = 0; i < LLCP_MAX_SAP; i++) {
43 parent = local->sockets[i];
44 if (parent == NULL)
45 continue;
46
47 /* Release all child sockets */
48 list_for_each_entry_safe(s, n, &parent->list, list) {
49 list_del_init(&s->list);
50 sk = &s->sk;
51
52 lock_sock(sk);
53
54 if (sk->sk_state == LLCP_CONNECTED)
55 nfc_put_device(s->dev);
56 40
57 sk->sk_state = LLCP_CLOSED; 41void nfc_llcp_sock_unlink(struct llcp_sock_list *l, struct sock *sk)
42{
43 write_lock(&l->lock);
44 sk_del_node_init(sk);
45 write_unlock(&l->lock);
46}
58 47
59 release_sock(sk); 48static void nfc_llcp_socket_release(struct nfc_llcp_local *local)
49{
50 struct sock *sk;
51 struct hlist_node *node, *tmp;
52 struct nfc_llcp_sock *llcp_sock;
60 53
61 sock_orphan(sk); 54 write_lock(&local->sockets.lock);
62 55
63 s->local = NULL; 56 sk_for_each_safe(sk, node, tmp, &local->sockets.head) {
64 } 57 llcp_sock = nfc_llcp_sock(sk);
65 58
66 parent_sk = &parent->sk; 59 lock_sock(sk);
67 60
68 lock_sock(parent_sk); 61 if (sk->sk_state == LLCP_CONNECTED)
62 nfc_put_device(llcp_sock->dev);
69 63
70 if (parent_sk->sk_state == LLCP_LISTEN) { 64 if (sk->sk_state == LLCP_LISTEN) {
71 struct nfc_llcp_sock *lsk, *n; 65 struct nfc_llcp_sock *lsk, *n;
72 struct sock *accept_sk; 66 struct sock *accept_sk;
73 67
74 list_for_each_entry_safe(lsk, n, &parent->accept_queue, 68 list_for_each_entry_safe(lsk, n, &llcp_sock->accept_queue,
75 accept_queue) { 69 accept_queue) {
76 accept_sk = &lsk->sk; 70 accept_sk = &lsk->sk;
77 lock_sock(accept_sk); 71 lock_sock(accept_sk);
@@ -83,24 +77,53 @@ static void nfc_llcp_socket_release(struct nfc_llcp_local *local)
83 release_sock(accept_sk); 77 release_sock(accept_sk);
84 78
85 sock_orphan(accept_sk); 79 sock_orphan(accept_sk);
86
87 lsk->local = NULL;
88 } 80 }
89 } 81 }
90 82
91 if (parent_sk->sk_state == LLCP_CONNECTED) 83 sk->sk_state = LLCP_CLOSED;
92 nfc_put_device(parent->dev);
93
94 parent_sk->sk_state = LLCP_CLOSED;
95 84
96 release_sock(parent_sk); 85 release_sock(sk);
97 86
98 sock_orphan(parent_sk); 87 sock_orphan(sk);
99 88
100 parent->local = NULL; 89 sk_del_node_init(sk);
101 } 90 }
102 91
103 mutex_unlock(&local->socket_lock); 92 write_unlock(&local->sockets.lock);
93}
94
95struct nfc_llcp_local *nfc_llcp_local_get(struct nfc_llcp_local *local)
96{
97 kref_get(&local->ref);
98
99 return local;
100}
101
102static void local_release(struct kref *ref)
103{
104 struct nfc_llcp_local *local;
105
106 local = container_of(ref, struct nfc_llcp_local, ref);
107
108 list_del(&local->list);
109 nfc_llcp_socket_release(local);
110 del_timer_sync(&local->link_timer);
111 skb_queue_purge(&local->tx_queue);
112 destroy_workqueue(local->tx_wq);
113 destroy_workqueue(local->rx_wq);
114 destroy_workqueue(local->timeout_wq);
115 kfree_skb(local->rx_pending);
116 kfree(local);
117}
118
119int nfc_llcp_local_put(struct nfc_llcp_local *local)
120{
121 WARN_ON(local == NULL);
122
123 if (local == NULL)
124 return 0;
125
126 return kref_put(&local->ref, local_release);
104} 127}
105 128
106static void nfc_llcp_clear_sdp(struct nfc_llcp_local *local) 129static void nfc_llcp_clear_sdp(struct nfc_llcp_local *local)
@@ -384,31 +407,9 @@ int nfc_llcp_set_remote_gb(struct nfc_dev *dev, u8 *gb, u8 gb_len)
384 return -EINVAL; 407 return -EINVAL;
385 } 408 }
386 409
387 return nfc_llcp_parse_tlv(local, 410 return nfc_llcp_parse_gb_tlv(local,
388 &local->remote_gb[3], 411 &local->remote_gb[3],
389 local->remote_gb_len - 3); 412 local->remote_gb_len - 3);
390}
391
392static void nfc_llcp_tx_work(struct work_struct *work)
393{
394 struct nfc_llcp_local *local = container_of(work, struct nfc_llcp_local,
395 tx_work);
396 struct sk_buff *skb;
397
398 skb = skb_dequeue(&local->tx_queue);
399 if (skb != NULL) {
400 pr_debug("Sending pending skb\n");
401 print_hex_dump(KERN_DEBUG, "LLCP Tx: ", DUMP_PREFIX_OFFSET,
402 16, 1, skb->data, skb->len, true);
403
404 nfc_data_exchange(local->dev, local->target_idx,
405 skb, nfc_llcp_recv, local);
406 } else {
407 nfc_llcp_send_symm(local->dev);
408 }
409
410 mod_timer(&local->link_timer,
411 jiffies + msecs_to_jiffies(local->remote_lto));
412} 413}
413 414
414static u8 nfc_llcp_dsap(struct sk_buff *pdu) 415static u8 nfc_llcp_dsap(struct sk_buff *pdu)
@@ -443,46 +444,146 @@ static void nfc_llcp_set_nrns(struct nfc_llcp_sock *sock, struct sk_buff *pdu)
443 sock->recv_ack_n = (sock->recv_n - 1) % 16; 444 sock->recv_ack_n = (sock->recv_n - 1) % 16;
444} 445}
445 446
447static void nfc_llcp_tx_work(struct work_struct *work)
448{
449 struct nfc_llcp_local *local = container_of(work, struct nfc_llcp_local,
450 tx_work);
451 struct sk_buff *skb;
452 struct sock *sk;
453 struct nfc_llcp_sock *llcp_sock;
454
455 skb = skb_dequeue(&local->tx_queue);
456 if (skb != NULL) {
457 sk = skb->sk;
458 llcp_sock = nfc_llcp_sock(sk);
459 if (llcp_sock != NULL) {
460 int ret;
461
462 pr_debug("Sending pending skb\n");
463 print_hex_dump(KERN_DEBUG, "LLCP Tx: ",
464 DUMP_PREFIX_OFFSET, 16, 1,
465 skb->data, skb->len, true);
466
467 ret = nfc_data_exchange(local->dev, local->target_idx,
468 skb, nfc_llcp_recv, local);
469
470 if (!ret && nfc_llcp_ptype(skb) == LLCP_PDU_I) {
471 skb = skb_get(skb);
472 skb_queue_tail(&llcp_sock->tx_pending_queue,
473 skb);
474 }
475 } else {
476 nfc_llcp_send_symm(local->dev);
477 }
478 } else {
479 nfc_llcp_send_symm(local->dev);
480 }
481
482 mod_timer(&local->link_timer,
483 jiffies + msecs_to_jiffies(2 * local->remote_lto));
484}
485
486static struct nfc_llcp_sock *nfc_llcp_connecting_sock_get(struct nfc_llcp_local *local,
487 u8 ssap)
488{
489 struct sock *sk;
490 struct nfc_llcp_sock *llcp_sock;
491 struct hlist_node *node;
492
493 read_lock(&local->connecting_sockets.lock);
494
495 sk_for_each(sk, node, &local->connecting_sockets.head) {
496 llcp_sock = nfc_llcp_sock(sk);
497
498 if (llcp_sock->ssap == ssap) {
499 sock_hold(&llcp_sock->sk);
500 goto out;
501 }
502 }
503
504 llcp_sock = NULL;
505
506out:
507 read_unlock(&local->connecting_sockets.lock);
508
509 return llcp_sock;
510}
511
446static struct nfc_llcp_sock *nfc_llcp_sock_get(struct nfc_llcp_local *local, 512static struct nfc_llcp_sock *nfc_llcp_sock_get(struct nfc_llcp_local *local,
447 u8 ssap, u8 dsap) 513 u8 ssap, u8 dsap)
448{ 514{
449 struct nfc_llcp_sock *sock, *llcp_sock, *n; 515 struct sock *sk;
516 struct hlist_node *node;
517 struct nfc_llcp_sock *llcp_sock;
450 518
451 pr_debug("ssap dsap %d %d\n", ssap, dsap); 519 pr_debug("ssap dsap %d %d\n", ssap, dsap);
452 520
453 if (ssap == 0 && dsap == 0) 521 if (ssap == 0 && dsap == 0)
454 return NULL; 522 return NULL;
455 523
456 mutex_lock(&local->socket_lock); 524 read_lock(&local->sockets.lock);
457 sock = local->sockets[ssap];
458 if (sock == NULL) {
459 mutex_unlock(&local->socket_lock);
460 return NULL;
461 }
462 525
463 pr_debug("root dsap %d (%d)\n", sock->dsap, dsap); 526 llcp_sock = NULL;
464 527
465 if (sock->dsap == dsap) { 528 sk_for_each(sk, node, &local->sockets.head) {
466 sock_hold(&sock->sk); 529 llcp_sock = nfc_llcp_sock(sk);
467 mutex_unlock(&local->socket_lock); 530
468 return sock; 531 if (llcp_sock->ssap == ssap &&
532 llcp_sock->dsap == dsap)
533 break;
469 } 534 }
470 535
471 list_for_each_entry_safe(llcp_sock, n, &sock->list, list) { 536 read_unlock(&local->sockets.lock);
472 pr_debug("llcp_sock %p sk %p dsap %d\n", llcp_sock, 537
473 &llcp_sock->sk, llcp_sock->dsap); 538 if (llcp_sock == NULL)
474 if (llcp_sock->dsap == dsap) { 539 return NULL;
475 sock_hold(&llcp_sock->sk); 540
476 mutex_unlock(&local->socket_lock); 541 sock_hold(&llcp_sock->sk);
477 return llcp_sock; 542
478 } 543 return llcp_sock;
544}
545
546static struct nfc_llcp_sock *nfc_llcp_sock_get_sn(struct nfc_llcp_local *local,
547 u8 *sn, size_t sn_len)
548{
549 struct sock *sk;
550 struct hlist_node *node;
551 struct nfc_llcp_sock *llcp_sock;
552
553 pr_debug("sn %zd\n", sn_len);
554
555 if (sn == NULL || sn_len == 0)
556 return NULL;
557
558 read_lock(&local->sockets.lock);
559
560 llcp_sock = NULL;
561
562 sk_for_each(sk, node, &local->sockets.head) {
563 llcp_sock = nfc_llcp_sock(sk);
564
565 if (llcp_sock->sk.sk_state != LLCP_LISTEN)
566 continue;
567
568 if (llcp_sock->service_name == NULL ||
569 llcp_sock->service_name_len == 0)
570 continue;
571
572 if (llcp_sock->service_name_len != sn_len)
573 continue;
574
575 if (memcmp(sn, llcp_sock->service_name, sn_len) == 0)
576 break;
479 } 577 }
480 578
481 pr_err("Could not find socket for %d %d\n", ssap, dsap); 579 read_unlock(&local->sockets.lock);
482 580
483 mutex_unlock(&local->socket_lock); 581 if (llcp_sock == NULL)
582 return NULL;
484 583
485 return NULL; 584 sock_hold(&llcp_sock->sk);
585
586 return llcp_sock;
486} 587}
487 588
488static void nfc_llcp_sock_put(struct nfc_llcp_sock *sock) 589static void nfc_llcp_sock_put(struct nfc_llcp_sock *sock)
@@ -518,35 +619,19 @@ static void nfc_llcp_recv_connect(struct nfc_llcp_local *local,
518{ 619{
519 struct sock *new_sk, *parent; 620 struct sock *new_sk, *parent;
520 struct nfc_llcp_sock *sock, *new_sock; 621 struct nfc_llcp_sock *sock, *new_sock;
521 u8 dsap, ssap, bound_sap, reason; 622 u8 dsap, ssap, reason;
522 623
523 dsap = nfc_llcp_dsap(skb); 624 dsap = nfc_llcp_dsap(skb);
524 ssap = nfc_llcp_ssap(skb); 625 ssap = nfc_llcp_ssap(skb);
525 626
526 pr_debug("%d %d\n", dsap, ssap); 627 pr_debug("%d %d\n", dsap, ssap);
527 628
528 nfc_llcp_parse_tlv(local, &skb->data[LLCP_HEADER_SIZE],
529 skb->len - LLCP_HEADER_SIZE);
530
531 if (dsap != LLCP_SAP_SDP) { 629 if (dsap != LLCP_SAP_SDP) {
532 bound_sap = dsap; 630 sock = nfc_llcp_sock_get(local, dsap, LLCP_SAP_SDP);
533 631 if (sock == NULL || sock->sk.sk_state != LLCP_LISTEN) {
534 mutex_lock(&local->socket_lock);
535 sock = local->sockets[dsap];
536 if (sock == NULL) {
537 mutex_unlock(&local->socket_lock);
538 reason = LLCP_DM_NOBOUND; 632 reason = LLCP_DM_NOBOUND;
539 goto fail; 633 goto fail;
540 } 634 }
541
542 sock_hold(&sock->sk);
543 mutex_unlock(&local->socket_lock);
544
545 lock_sock(&sock->sk);
546
547 if (sock->dsap == LLCP_SAP_SDP &&
548 sock->sk.sk_state == LLCP_LISTEN)
549 goto enqueue;
550 } else { 635 } else {
551 u8 *sn; 636 u8 *sn;
552 size_t sn_len; 637 size_t sn_len;
@@ -559,40 +644,15 @@ static void nfc_llcp_recv_connect(struct nfc_llcp_local *local,
559 644
560 pr_debug("Service name length %zu\n", sn_len); 645 pr_debug("Service name length %zu\n", sn_len);
561 646
562 mutex_lock(&local->socket_lock); 647 sock = nfc_llcp_sock_get_sn(local, sn, sn_len);
563 for (bound_sap = 0; bound_sap < LLCP_LOCAL_SAP_OFFSET; 648 if (sock == NULL) {
564 bound_sap++) { 649 reason = LLCP_DM_NOBOUND;
565 sock = local->sockets[bound_sap]; 650 goto fail;
566 if (sock == NULL)
567 continue;
568
569 if (sock->service_name == NULL ||
570 sock->service_name_len == 0)
571 continue;
572
573 if (sock->service_name_len != sn_len)
574 continue;
575
576 if (sock->dsap == LLCP_SAP_SDP &&
577 sock->sk.sk_state == LLCP_LISTEN &&
578 !memcmp(sn, sock->service_name, sn_len)) {
579 pr_debug("Found service name at SAP %d\n",
580 bound_sap);
581 sock_hold(&sock->sk);
582 mutex_unlock(&local->socket_lock);
583
584 lock_sock(&sock->sk);
585
586 goto enqueue;
587 }
588 } 651 }
589 mutex_unlock(&local->socket_lock);
590 } 652 }
591 653
592 reason = LLCP_DM_NOBOUND; 654 lock_sock(&sock->sk);
593 goto fail;
594 655
595enqueue:
596 parent = &sock->sk; 656 parent = &sock->sk;
597 657
598 if (sk_acceptq_is_full(parent)) { 658 if (sk_acceptq_is_full(parent)) {
@@ -612,15 +672,19 @@ enqueue:
612 672
613 new_sock = nfc_llcp_sock(new_sk); 673 new_sock = nfc_llcp_sock(new_sk);
614 new_sock->dev = local->dev; 674 new_sock->dev = local->dev;
615 new_sock->local = local; 675 new_sock->local = nfc_llcp_local_get(local);
676 new_sock->miu = local->remote_miu;
616 new_sock->nfc_protocol = sock->nfc_protocol; 677 new_sock->nfc_protocol = sock->nfc_protocol;
617 new_sock->ssap = bound_sap; 678 new_sock->ssap = sock->ssap;
618 new_sock->dsap = ssap; 679 new_sock->dsap = ssap;
619 new_sock->parent = parent; 680 new_sock->parent = parent;
620 681
682 nfc_llcp_parse_connection_tlv(new_sock, &skb->data[LLCP_HEADER_SIZE],
683 skb->len - LLCP_HEADER_SIZE);
684
621 pr_debug("new sock %p sk %p\n", new_sock, &new_sock->sk); 685 pr_debug("new sock %p sk %p\n", new_sock, &new_sock->sk);
622 686
623 list_add_tail(&new_sock->list, &sock->list); 687 nfc_llcp_sock_link(&local->sockets, new_sk);
624 688
625 nfc_llcp_accept_enqueue(&sock->sk, new_sk); 689 nfc_llcp_accept_enqueue(&sock->sk, new_sk);
626 690
@@ -654,12 +718,12 @@ int nfc_llcp_queue_i_frames(struct nfc_llcp_sock *sock)
654 718
655 pr_debug("Remote ready %d tx queue len %d remote rw %d", 719 pr_debug("Remote ready %d tx queue len %d remote rw %d",
656 sock->remote_ready, skb_queue_len(&sock->tx_pending_queue), 720 sock->remote_ready, skb_queue_len(&sock->tx_pending_queue),
657 local->remote_rw); 721 sock->rw);
658 722
659 /* Try to queue some I frames for transmission */ 723 /* Try to queue some I frames for transmission */
660 while (sock->remote_ready && 724 while (sock->remote_ready &&
661 skb_queue_len(&sock->tx_pending_queue) < local->remote_rw) { 725 skb_queue_len(&sock->tx_pending_queue) < sock->rw) {
662 struct sk_buff *pdu, *pending_pdu; 726 struct sk_buff *pdu;
663 727
664 pdu = skb_dequeue(&sock->tx_queue); 728 pdu = skb_dequeue(&sock->tx_queue);
665 if (pdu == NULL) 729 if (pdu == NULL)
@@ -668,10 +732,7 @@ int nfc_llcp_queue_i_frames(struct nfc_llcp_sock *sock)
668 /* Update N(S)/N(R) */ 732 /* Update N(S)/N(R) */
669 nfc_llcp_set_nrns(sock, pdu); 733 nfc_llcp_set_nrns(sock, pdu);
670 734
671 pending_pdu = skb_clone(pdu, GFP_KERNEL);
672
673 skb_queue_tail(&local->tx_queue, pdu); 735 skb_queue_tail(&local->tx_queue, pdu);
674 skb_queue_tail(&sock->tx_pending_queue, pending_pdu);
675 nr_frames++; 736 nr_frames++;
676 } 737 }
677 738
@@ -728,11 +789,21 @@ static void nfc_llcp_recv_hdlc(struct nfc_llcp_local *local,
728 789
729 llcp_sock->send_ack_n = nr; 790 llcp_sock->send_ack_n = nr;
730 791
731 skb_queue_walk_safe(&llcp_sock->tx_pending_queue, s, tmp) 792 /* Remove and free all skbs until ns == nr */
732 if (nfc_llcp_ns(s) <= nr) { 793 skb_queue_walk_safe(&llcp_sock->tx_pending_queue, s, tmp) {
733 skb_unlink(s, &llcp_sock->tx_pending_queue); 794 skb_unlink(s, &llcp_sock->tx_pending_queue);
734 kfree_skb(s); 795 kfree_skb(s);
735 } 796
797 if (nfc_llcp_ns(s) == nr)
798 break;
799 }
800
801 /* Re-queue the remaining skbs for transmission */
802 skb_queue_reverse_walk_safe(&llcp_sock->tx_pending_queue,
803 s, tmp) {
804 skb_unlink(s, &llcp_sock->tx_pending_queue);
805 skb_queue_head(&local->tx_queue, s);
806 }
736 } 807 }
737 808
738 if (ptype == LLCP_PDU_RR) 809 if (ptype == LLCP_PDU_RR)
@@ -740,7 +811,7 @@ static void nfc_llcp_recv_hdlc(struct nfc_llcp_local *local,
740 else if (ptype == LLCP_PDU_RNR) 811 else if (ptype == LLCP_PDU_RNR)
741 llcp_sock->remote_ready = false; 812 llcp_sock->remote_ready = false;
742 813
743 if (nfc_llcp_queue_i_frames(llcp_sock) == 0) 814 if (nfc_llcp_queue_i_frames(llcp_sock) == 0 && ptype == LLCP_PDU_I)
744 nfc_llcp_send_rr(llcp_sock); 815 nfc_llcp_send_rr(llcp_sock);
745 816
746 release_sock(sk); 817 release_sock(sk);
@@ -791,11 +862,7 @@ static void nfc_llcp_recv_cc(struct nfc_llcp_local *local, struct sk_buff *skb)
791 dsap = nfc_llcp_dsap(skb); 862 dsap = nfc_llcp_dsap(skb);
792 ssap = nfc_llcp_ssap(skb); 863 ssap = nfc_llcp_ssap(skb);
793 864
794 llcp_sock = nfc_llcp_sock_get(local, dsap, ssap); 865 llcp_sock = nfc_llcp_connecting_sock_get(local, dsap);
795
796 if (llcp_sock == NULL)
797 llcp_sock = nfc_llcp_sock_get(local, dsap, LLCP_SAP_SDP);
798
799 if (llcp_sock == NULL) { 866 if (llcp_sock == NULL) {
800 pr_err("Invalid CC\n"); 867 pr_err("Invalid CC\n");
801 nfc_llcp_send_dm(local, dsap, ssap, LLCP_DM_NOCONN); 868 nfc_llcp_send_dm(local, dsap, ssap, LLCP_DM_NOCONN);
@@ -803,11 +870,15 @@ static void nfc_llcp_recv_cc(struct nfc_llcp_local *local, struct sk_buff *skb)
803 return; 870 return;
804 } 871 }
805 872
806 llcp_sock->dsap = ssap;
807 sk = &llcp_sock->sk; 873 sk = &llcp_sock->sk;
808 874
809 nfc_llcp_parse_tlv(local, &skb->data[LLCP_HEADER_SIZE], 875 /* Unlink from connecting and link to the client array */
810 skb->len - LLCP_HEADER_SIZE); 876 nfc_llcp_sock_unlink(&local->connecting_sockets, sk);
877 nfc_llcp_sock_link(&local->sockets, sk);
878 llcp_sock->dsap = ssap;
879
880 nfc_llcp_parse_connection_tlv(llcp_sock, &skb->data[LLCP_HEADER_SIZE],
881 skb->len - LLCP_HEADER_SIZE);
811 882
812 sk->sk_state = LLCP_CONNECTED; 883 sk->sk_state = LLCP_CONNECTED;
813 sk->sk_state_change(sk); 884 sk->sk_state_change(sk);
@@ -891,6 +962,21 @@ void nfc_llcp_recv(void *data, struct sk_buff *skb, int err)
891 return; 962 return;
892} 963}
893 964
965int nfc_llcp_data_received(struct nfc_dev *dev, struct sk_buff *skb)
966{
967 struct nfc_llcp_local *local;
968
969 local = nfc_llcp_find_local(dev);
970 if (local == NULL)
971 return -ENODEV;
972
973 local->rx_pending = skb_get(skb);
974 del_timer(&local->link_timer);
975 queue_work(local->rx_wq, &local->rx_work);
976
977 return 0;
978}
979
894void nfc_llcp_mac_is_down(struct nfc_dev *dev) 980void nfc_llcp_mac_is_down(struct nfc_dev *dev)
895{ 981{
896 struct nfc_llcp_local *local; 982 struct nfc_llcp_local *local;
@@ -943,8 +1029,8 @@ int nfc_llcp_register_device(struct nfc_dev *ndev)
943 1029
944 local->dev = ndev; 1030 local->dev = ndev;
945 INIT_LIST_HEAD(&local->list); 1031 INIT_LIST_HEAD(&local->list);
1032 kref_init(&local->ref);
946 mutex_init(&local->sdp_lock); 1033 mutex_init(&local->sdp_lock);
947 mutex_init(&local->socket_lock);
948 init_timer(&local->link_timer); 1034 init_timer(&local->link_timer);
949 local->link_timer.data = (unsigned long) local; 1035 local->link_timer.data = (unsigned long) local;
950 local->link_timer.function = nfc_llcp_symm_timer; 1036 local->link_timer.function = nfc_llcp_symm_timer;
@@ -984,11 +1070,13 @@ int nfc_llcp_register_device(struct nfc_dev *ndev)
984 goto err_rx_wq; 1070 goto err_rx_wq;
985 } 1071 }
986 1072
1073 local->sockets.lock = __RW_LOCK_UNLOCKED(local->sockets.lock);
1074 local->connecting_sockets.lock = __RW_LOCK_UNLOCKED(local->connecting_sockets.lock);
1075
987 nfc_llcp_build_gb(local); 1076 nfc_llcp_build_gb(local);
988 1077
989 local->remote_miu = LLCP_DEFAULT_MIU; 1078 local->remote_miu = LLCP_DEFAULT_MIU;
990 local->remote_lto = LLCP_DEFAULT_LTO; 1079 local->remote_lto = LLCP_DEFAULT_LTO;
991 local->remote_rw = LLCP_DEFAULT_RW;
992 1080
993 list_add(&llcp_devices, &local->list); 1081 list_add(&llcp_devices, &local->list);
994 1082
@@ -1015,14 +1103,7 @@ void nfc_llcp_unregister_device(struct nfc_dev *dev)
1015 return; 1103 return;
1016 } 1104 }
1017 1105
1018 list_del(&local->list); 1106 nfc_llcp_local_put(local);
1019 nfc_llcp_socket_release(local);
1020 del_timer_sync(&local->link_timer);
1021 skb_queue_purge(&local->tx_queue);
1022 destroy_workqueue(local->tx_wq);
1023 destroy_workqueue(local->rx_wq);
1024 kfree_skb(local->rx_pending);
1025 kfree(local);
1026} 1107}
1027 1108
1028int __init nfc_llcp_init(void) 1109int __init nfc_llcp_init(void)
diff --git a/net/nfc/llcp/llcp.h b/net/nfc/llcp/llcp.h
index 50680ce5ae43..7286c86982ff 100644
--- a/net/nfc/llcp/llcp.h
+++ b/net/nfc/llcp/llcp.h
@@ -40,12 +40,18 @@ enum llcp_state {
40 40
41struct nfc_llcp_sock; 41struct nfc_llcp_sock;
42 42
43struct llcp_sock_list {
44 struct hlist_head head;
45 rwlock_t lock;
46};
47
43struct nfc_llcp_local { 48struct nfc_llcp_local {
44 struct list_head list; 49 struct list_head list;
45 struct nfc_dev *dev; 50 struct nfc_dev *dev;
46 51
52 struct kref ref;
53
47 struct mutex sdp_lock; 54 struct mutex sdp_lock;
48 struct mutex socket_lock;
49 55
50 struct timer_list link_timer; 56 struct timer_list link_timer;
51 struct sk_buff_head tx_queue; 57 struct sk_buff_head tx_queue;
@@ -77,24 +83,26 @@ struct nfc_llcp_local {
77 u16 remote_lto; 83 u16 remote_lto;
78 u8 remote_opt; 84 u8 remote_opt;
79 u16 remote_wks; 85 u16 remote_wks;
80 u8 remote_rw;
81 86
82 /* sockets array */ 87 /* sockets array */
83 struct nfc_llcp_sock *sockets[LLCP_MAX_SAP]; 88 struct llcp_sock_list sockets;
89 struct llcp_sock_list connecting_sockets;
84}; 90};
85 91
86struct nfc_llcp_sock { 92struct nfc_llcp_sock {
87 struct sock sk; 93 struct sock sk;
88 struct list_head list;
89 struct nfc_dev *dev; 94 struct nfc_dev *dev;
90 struct nfc_llcp_local *local; 95 struct nfc_llcp_local *local;
91 u32 target_idx; 96 u32 target_idx;
92 u32 nfc_protocol; 97 u32 nfc_protocol;
93 98
99 /* Link parameters */
94 u8 ssap; 100 u8 ssap;
95 u8 dsap; 101 u8 dsap;
96 char *service_name; 102 char *service_name;
97 size_t service_name_len; 103 size_t service_name_len;
104 u8 rw;
105 u16 miu;
98 106
99 /* Link variables */ 107 /* Link variables */
100 u8 send_n; 108 u8 send_n;
@@ -164,7 +172,11 @@ struct nfc_llcp_sock {
164#define LLCP_DM_REJ 0x03 172#define LLCP_DM_REJ 0x03
165 173
166 174
175void nfc_llcp_sock_link(struct llcp_sock_list *l, struct sock *s);
176void nfc_llcp_sock_unlink(struct llcp_sock_list *l, struct sock *s);
167struct nfc_llcp_local *nfc_llcp_find_local(struct nfc_dev *dev); 177struct nfc_llcp_local *nfc_llcp_find_local(struct nfc_dev *dev);
178struct nfc_llcp_local *nfc_llcp_local_get(struct nfc_llcp_local *local);
179int nfc_llcp_local_put(struct nfc_llcp_local *local);
168u8 nfc_llcp_get_sdp_ssap(struct nfc_llcp_local *local, 180u8 nfc_llcp_get_sdp_ssap(struct nfc_llcp_local *local,
169 struct nfc_llcp_sock *sock); 181 struct nfc_llcp_sock *sock);
170u8 nfc_llcp_get_local_ssap(struct nfc_llcp_local *local); 182u8 nfc_llcp_get_local_ssap(struct nfc_llcp_local *local);
@@ -179,8 +191,10 @@ void nfc_llcp_accept_enqueue(struct sock *parent, struct sock *sk);
179struct sock *nfc_llcp_accept_dequeue(struct sock *sk, struct socket *newsock); 191struct sock *nfc_llcp_accept_dequeue(struct sock *sk, struct socket *newsock);
180 192
181/* TLV API */ 193/* TLV API */
182int nfc_llcp_parse_tlv(struct nfc_llcp_local *local, 194int nfc_llcp_parse_gb_tlv(struct nfc_llcp_local *local,
183 u8 *tlv_array, u16 tlv_array_len); 195 u8 *tlv_array, u16 tlv_array_len);
196int nfc_llcp_parse_connection_tlv(struct nfc_llcp_sock *sock,
197 u8 *tlv_array, u16 tlv_array_len);
184 198
185/* Commands API */ 199/* Commands API */
186void nfc_llcp_recv(void *data, struct sk_buff *skb, int err); 200void nfc_llcp_recv(void *data, struct sk_buff *skb, int err);
diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
index 17a707db40eb..2c0b317344b7 100644
--- a/net/nfc/llcp/sock.c
+++ b/net/nfc/llcp/sock.c
@@ -111,7 +111,7 @@ static int llcp_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
111 } 111 }
112 112
113 llcp_sock->dev = dev; 113 llcp_sock->dev = dev;
114 llcp_sock->local = local; 114 llcp_sock->local = nfc_llcp_local_get(local);
115 llcp_sock->nfc_protocol = llcp_addr.nfc_protocol; 115 llcp_sock->nfc_protocol = llcp_addr.nfc_protocol;
116 llcp_sock->service_name_len = min_t(unsigned int, 116 llcp_sock->service_name_len = min_t(unsigned int,
117 llcp_addr.service_name_len, 117 llcp_addr.service_name_len,
@@ -124,7 +124,7 @@ static int llcp_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
124 if (llcp_sock->ssap == LLCP_MAX_SAP) 124 if (llcp_sock->ssap == LLCP_MAX_SAP)
125 goto put_dev; 125 goto put_dev;
126 126
127 local->sockets[llcp_sock->ssap] = llcp_sock; 127 nfc_llcp_sock_link(&local->sockets, sk);
128 128
129 pr_debug("Socket bound to SAP %d\n", llcp_sock->ssap); 129 pr_debug("Socket bound to SAP %d\n", llcp_sock->ssap);
130 130
@@ -382,15 +382,6 @@ static int llcp_sock_release(struct socket *sock)
382 goto out; 382 goto out;
383 } 383 }
384 384
385 mutex_lock(&local->socket_lock);
386
387 if (llcp_sock == local->sockets[llcp_sock->ssap])
388 local->sockets[llcp_sock->ssap] = NULL;
389 else
390 list_del_init(&llcp_sock->list);
391
392 mutex_unlock(&local->socket_lock);
393
394 lock_sock(sk); 385 lock_sock(sk);
395 386
396 /* Send a DISC */ 387 /* Send a DISC */
@@ -415,14 +406,12 @@ static int llcp_sock_release(struct socket *sock)
415 } 406 }
416 } 407 }
417 408
418 /* Freeing the SAP */ 409 nfc_llcp_put_ssap(llcp_sock->local, llcp_sock->ssap);
419 if ((sk->sk_state == LLCP_CONNECTED
420 && llcp_sock->ssap > LLCP_LOCAL_SAP_OFFSET) ||
421 sk->sk_state == LLCP_BOUND || sk->sk_state == LLCP_LISTEN)
422 nfc_llcp_put_ssap(llcp_sock->local, llcp_sock->ssap);
423 410
424 release_sock(sk); 411 release_sock(sk);
425 412
413 nfc_llcp_sock_unlink(&local->sockets, sk);
414
426out: 415out:
427 sock_orphan(sk); 416 sock_orphan(sk);
428 sock_put(sk); 417 sock_put(sk);
@@ -490,7 +479,8 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
490 } 479 }
491 480
492 llcp_sock->dev = dev; 481 llcp_sock->dev = dev;
493 llcp_sock->local = local; 482 llcp_sock->local = nfc_llcp_local_get(local);
483 llcp_sock->miu = llcp_sock->local->remote_miu;
494 llcp_sock->ssap = nfc_llcp_get_local_ssap(local); 484 llcp_sock->ssap = nfc_llcp_get_local_ssap(local);
495 if (llcp_sock->ssap == LLCP_SAP_MAX) { 485 if (llcp_sock->ssap == LLCP_SAP_MAX) {
496 ret = -ENOMEM; 486 ret = -ENOMEM;
@@ -508,21 +498,26 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
508 llcp_sock->service_name_len, 498 llcp_sock->service_name_len,
509 GFP_KERNEL); 499 GFP_KERNEL);
510 500
511 local->sockets[llcp_sock->ssap] = llcp_sock; 501 nfc_llcp_sock_link(&local->connecting_sockets, sk);
512 502
513 ret = nfc_llcp_send_connect(llcp_sock); 503 ret = nfc_llcp_send_connect(llcp_sock);
514 if (ret) 504 if (ret)
515 goto put_dev; 505 goto sock_unlink;
516 506
517 ret = sock_wait_state(sk, LLCP_CONNECTED, 507 ret = sock_wait_state(sk, LLCP_CONNECTED,
518 sock_sndtimeo(sk, flags & O_NONBLOCK)); 508 sock_sndtimeo(sk, flags & O_NONBLOCK));
519 if (ret) 509 if (ret)
520 goto put_dev; 510 goto sock_unlink;
521 511
522 release_sock(sk); 512 release_sock(sk);
523 513
524 return 0; 514 return 0;
525 515
516sock_unlink:
517 nfc_llcp_put_ssap(local, llcp_sock->ssap);
518
519 nfc_llcp_sock_unlink(&local->connecting_sockets, sk);
520
526put_dev: 521put_dev:
527 nfc_put_device(dev); 522 nfc_put_device(dev);
528 523
@@ -687,13 +682,14 @@ struct sock *nfc_llcp_sock_alloc(struct socket *sock, int type, gfp_t gfp)
687 682
688 llcp_sock->ssap = 0; 683 llcp_sock->ssap = 0;
689 llcp_sock->dsap = LLCP_SAP_SDP; 684 llcp_sock->dsap = LLCP_SAP_SDP;
685 llcp_sock->rw = LLCP_DEFAULT_RW;
686 llcp_sock->miu = LLCP_DEFAULT_MIU;
690 llcp_sock->send_n = llcp_sock->send_ack_n = 0; 687 llcp_sock->send_n = llcp_sock->send_ack_n = 0;
691 llcp_sock->recv_n = llcp_sock->recv_ack_n = 0; 688 llcp_sock->recv_n = llcp_sock->recv_ack_n = 0;
692 llcp_sock->remote_ready = 1; 689 llcp_sock->remote_ready = 1;
693 skb_queue_head_init(&llcp_sock->tx_queue); 690 skb_queue_head_init(&llcp_sock->tx_queue);
694 skb_queue_head_init(&llcp_sock->tx_pending_queue); 691 skb_queue_head_init(&llcp_sock->tx_pending_queue);
695 skb_queue_head_init(&llcp_sock->tx_backlog_queue); 692 skb_queue_head_init(&llcp_sock->tx_backlog_queue);
696 INIT_LIST_HEAD(&llcp_sock->list);
697 INIT_LIST_HEAD(&llcp_sock->accept_queue); 693 INIT_LIST_HEAD(&llcp_sock->accept_queue);
698 694
699 if (sock != NULL) 695 if (sock != NULL)
@@ -704,8 +700,6 @@ struct sock *nfc_llcp_sock_alloc(struct socket *sock, int type, gfp_t gfp)
704 700
705void nfc_llcp_sock_free(struct nfc_llcp_sock *sock) 701void nfc_llcp_sock_free(struct nfc_llcp_sock *sock)
706{ 702{
707 struct nfc_llcp_local *local = sock->local;
708
709 kfree(sock->service_name); 703 kfree(sock->service_name);
710 704
711 skb_queue_purge(&sock->tx_queue); 705 skb_queue_purge(&sock->tx_queue);
@@ -714,12 +708,9 @@ void nfc_llcp_sock_free(struct nfc_llcp_sock *sock)
714 708
715 list_del_init(&sock->accept_queue); 709 list_del_init(&sock->accept_queue);
716 710
717 if (local != NULL && sock == local->sockets[sock->ssap])
718 local->sockets[sock->ssap] = NULL;
719 else
720 list_del_init(&sock->list);
721
722 sock->parent = NULL; 711 sock->parent = NULL;
712
713 nfc_llcp_local_put(sock->local);
723} 714}
724 715
725static int llcp_sock_create(struct net *net, struct socket *sock, 716static int llcp_sock_create(struct net *net, struct socket *sock,
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index d560e6f13072..766a02b1dfa1 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -387,7 +387,8 @@ static int nci_dev_down(struct nfc_dev *nfc_dev)
387 return nci_close_device(ndev); 387 return nci_close_device(ndev);
388} 388}
389 389
390static int nci_start_poll(struct nfc_dev *nfc_dev, __u32 protocols) 390static int nci_start_poll(struct nfc_dev *nfc_dev,
391 __u32 im_protocols, __u32 tm_protocols)
391{ 392{
392 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); 393 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
393 int rc; 394 int rc;
@@ -413,11 +414,11 @@ static int nci_start_poll(struct nfc_dev *nfc_dev, __u32 protocols)
413 return -EBUSY; 414 return -EBUSY;
414 } 415 }
415 416
416 rc = nci_request(ndev, nci_rf_discover_req, protocols, 417 rc = nci_request(ndev, nci_rf_discover_req, im_protocols,
417 msecs_to_jiffies(NCI_RF_DISC_TIMEOUT)); 418 msecs_to_jiffies(NCI_RF_DISC_TIMEOUT));
418 419
419 if (!rc) 420 if (!rc)
420 ndev->poll_prots = protocols; 421 ndev->poll_prots = im_protocols;
421 422
422 return rc; 423 return rc;
423} 424}
@@ -521,9 +522,9 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev,
521 } 522 }
522} 523}
523 524
524static int nci_data_exchange(struct nfc_dev *nfc_dev, struct nfc_target *target, 525static int nci_transceive(struct nfc_dev *nfc_dev, struct nfc_target *target,
525 struct sk_buff *skb, 526 struct sk_buff *skb,
526 data_exchange_cb_t cb, void *cb_context) 527 data_exchange_cb_t cb, void *cb_context)
527{ 528{
528 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); 529 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
529 int rc; 530 int rc;
@@ -556,7 +557,7 @@ static struct nfc_ops nci_nfc_ops = {
556 .stop_poll = nci_stop_poll, 557 .stop_poll = nci_stop_poll,
557 .activate_target = nci_activate_target, 558 .activate_target = nci_activate_target,
558 .deactivate_target = nci_deactivate_target, 559 .deactivate_target = nci_deactivate_target,
559 .data_exchange = nci_data_exchange, 560 .im_transceive = nci_transceive,
560}; 561};
561 562
562/* ---- Interface to NCI drivers ---- */ 563/* ---- Interface to NCI drivers ---- */
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 581d419083aa..03c31db38f12 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -49,6 +49,8 @@ static const struct nla_policy nfc_genl_policy[NFC_ATTR_MAX + 1] = {
49 [NFC_ATTR_COMM_MODE] = { .type = NLA_U8 }, 49 [NFC_ATTR_COMM_MODE] = { .type = NLA_U8 },
50 [NFC_ATTR_RF_MODE] = { .type = NLA_U8 }, 50 [NFC_ATTR_RF_MODE] = { .type = NLA_U8 },
51 [NFC_ATTR_DEVICE_POWERED] = { .type = NLA_U8 }, 51 [NFC_ATTR_DEVICE_POWERED] = { .type = NLA_U8 },
52 [NFC_ATTR_IM_PROTOCOLS] = { .type = NLA_U32 },
53 [NFC_ATTR_TM_PROTOCOLS] = { .type = NLA_U32 },
52}; 54};
53 55
54static int nfc_genl_send_target(struct sk_buff *msg, struct nfc_target *target, 56static int nfc_genl_send_target(struct sk_buff *msg, struct nfc_target *target,
@@ -219,6 +221,68 @@ free_msg:
219 return -EMSGSIZE; 221 return -EMSGSIZE;
220} 222}
221 223
224int nfc_genl_tm_activated(struct nfc_dev *dev, u32 protocol)
225{
226 struct sk_buff *msg;
227 void *hdr;
228
229 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
230 if (!msg)
231 return -ENOMEM;
232
233 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
234 NFC_EVENT_TM_ACTIVATED);
235 if (!hdr)
236 goto free_msg;
237
238 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
239 goto nla_put_failure;
240 if (nla_put_u32(msg, NFC_ATTR_TM_PROTOCOLS, protocol))
241 goto nla_put_failure;
242
243 genlmsg_end(msg, hdr);
244
245 genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
246
247 return 0;
248
249nla_put_failure:
250 genlmsg_cancel(msg, hdr);
251free_msg:
252 nlmsg_free(msg);
253 return -EMSGSIZE;
254}
255
256int nfc_genl_tm_deactivated(struct nfc_dev *dev)
257{
258 struct sk_buff *msg;
259 void *hdr;
260
261 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
262 if (!msg)
263 return -ENOMEM;
264
265 hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
266 NFC_EVENT_TM_DEACTIVATED);
267 if (!hdr)
268 goto free_msg;
269
270 if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx))
271 goto nla_put_failure;
272
273 genlmsg_end(msg, hdr);
274
275 genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
276
277 return 0;
278
279nla_put_failure:
280 genlmsg_cancel(msg, hdr);
281free_msg:
282 nlmsg_free(msg);
283 return -EMSGSIZE;
284}
285
222int nfc_genl_device_added(struct nfc_dev *dev) 286int nfc_genl_device_added(struct nfc_dev *dev)
223{ 287{
224 struct sk_buff *msg; 288 struct sk_buff *msg;
@@ -519,16 +583,25 @@ static int nfc_genl_start_poll(struct sk_buff *skb, struct genl_info *info)
519 struct nfc_dev *dev; 583 struct nfc_dev *dev;
520 int rc; 584 int rc;
521 u32 idx; 585 u32 idx;
522 u32 protocols; 586 u32 im_protocols = 0, tm_protocols = 0;
523 587
524 pr_debug("Poll start\n"); 588 pr_debug("Poll start\n");
525 589
526 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] || 590 if (!info->attrs[NFC_ATTR_DEVICE_INDEX] ||
527 !info->attrs[NFC_ATTR_PROTOCOLS]) 591 ((!info->attrs[NFC_ATTR_IM_PROTOCOLS] &&
592 !info->attrs[NFC_ATTR_PROTOCOLS]) &&
593 !info->attrs[NFC_ATTR_TM_PROTOCOLS]))
528 return -EINVAL; 594 return -EINVAL;
529 595
530 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]); 596 idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
531 protocols = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]); 597
598 if (info->attrs[NFC_ATTR_TM_PROTOCOLS])
599 tm_protocols = nla_get_u32(info->attrs[NFC_ATTR_TM_PROTOCOLS]);
600
601 if (info->attrs[NFC_ATTR_IM_PROTOCOLS])
602 im_protocols = nla_get_u32(info->attrs[NFC_ATTR_IM_PROTOCOLS]);
603 else if (info->attrs[NFC_ATTR_PROTOCOLS])
604 im_protocols = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]);
532 605
533 dev = nfc_get_device(idx); 606 dev = nfc_get_device(idx);
534 if (!dev) 607 if (!dev)
@@ -536,7 +609,7 @@ static int nfc_genl_start_poll(struct sk_buff *skb, struct genl_info *info)
536 609
537 mutex_lock(&dev->genl_data.genl_data_mutex); 610 mutex_lock(&dev->genl_data.genl_data_mutex);
538 611
539 rc = nfc_start_poll(dev, protocols); 612 rc = nfc_start_poll(dev, im_protocols, tm_protocols);
540 if (!rc) 613 if (!rc)
541 dev->genl_data.poll_req_pid = info->snd_pid; 614 dev->genl_data.poll_req_pid = info->snd_pid;
542 615
diff --git a/net/nfc/nfc.h b/net/nfc/nfc.h
index 3dd4232ae664..c5e42b79a418 100644
--- a/net/nfc/nfc.h
+++ b/net/nfc/nfc.h
@@ -55,6 +55,7 @@ int nfc_llcp_register_device(struct nfc_dev *dev);
55void nfc_llcp_unregister_device(struct nfc_dev *dev); 55void nfc_llcp_unregister_device(struct nfc_dev *dev);
56int nfc_llcp_set_remote_gb(struct nfc_dev *dev, u8 *gb, u8 gb_len); 56int nfc_llcp_set_remote_gb(struct nfc_dev *dev, u8 *gb, u8 gb_len);
57u8 *nfc_llcp_general_bytes(struct nfc_dev *dev, size_t *general_bytes_len); 57u8 *nfc_llcp_general_bytes(struct nfc_dev *dev, size_t *general_bytes_len);
58int nfc_llcp_data_received(struct nfc_dev *dev, struct sk_buff *skb);
58int __init nfc_llcp_init(void); 59int __init nfc_llcp_init(void);
59void nfc_llcp_exit(void); 60void nfc_llcp_exit(void);
60 61
@@ -90,6 +91,12 @@ static inline u8 *nfc_llcp_general_bytes(struct nfc_dev *dev, size_t *gb_len)
90 return NULL; 91 return NULL;
91} 92}
92 93
94static inline int nfc_llcp_data_received(struct nfc_dev *dev,
95 struct sk_buff *skb)
96{
97 return 0;
98}
99
93static inline int nfc_llcp_init(void) 100static inline int nfc_llcp_init(void)
94{ 101{
95 return 0; 102 return 0;
@@ -128,6 +135,9 @@ int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,
128 u8 comm_mode, u8 rf_mode); 135 u8 comm_mode, u8 rf_mode);
129int nfc_genl_dep_link_down_event(struct nfc_dev *dev); 136int nfc_genl_dep_link_down_event(struct nfc_dev *dev);
130 137
138int nfc_genl_tm_activated(struct nfc_dev *dev, u32 protocol);
139int nfc_genl_tm_deactivated(struct nfc_dev *dev);
140
131struct nfc_dev *nfc_get_device(unsigned int idx); 141struct nfc_dev *nfc_get_device(unsigned int idx);
132 142
133static inline void nfc_put_device(struct nfc_dev *dev) 143static inline void nfc_put_device(struct nfc_dev *dev)
@@ -158,7 +168,7 @@ int nfc_dev_up(struct nfc_dev *dev);
158 168
159int nfc_dev_down(struct nfc_dev *dev); 169int nfc_dev_down(struct nfc_dev *dev);
160 170
161int nfc_start_poll(struct nfc_dev *dev, u32 protocols); 171int nfc_start_poll(struct nfc_dev *dev, u32 im_protocols, u32 tm_protocols);
162 172
163int nfc_stop_poll(struct nfc_dev *dev); 173int nfc_stop_poll(struct nfc_dev *dev);
164 174
diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index f974961754ca..752b72360ebc 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -325,7 +325,7 @@ static void __rfkill_switch_all(const enum rfkill_type type, bool blocked)
325 325
326 rfkill_global_states[type].cur = blocked; 326 rfkill_global_states[type].cur = blocked;
327 list_for_each_entry(rfkill, &rfkill_list, node) { 327 list_for_each_entry(rfkill, &rfkill_list, node) {
328 if (rfkill->type != type) 328 if (rfkill->type != type && type != RFKILL_TYPE_ALL)
329 continue; 329 continue;
330 330
331 rfkill_set_block(rfkill, blocked); 331 rfkill_set_block(rfkill, blocked);
diff --git a/net/wireless/Kconfig b/net/wireless/Kconfig
index 2e4444fedbe0..4d2b1ec6516f 100644
--- a/net/wireless/Kconfig
+++ b/net/wireless/Kconfig
@@ -114,24 +114,10 @@ config CFG80211_WEXT
114 bool "cfg80211 wireless extensions compatibility" 114 bool "cfg80211 wireless extensions compatibility"
115 depends on CFG80211 115 depends on CFG80211
116 select WEXT_CORE 116 select WEXT_CORE
117 default y
118 help 117 help
119 Enable this option if you need old userspace for wireless 118 Enable this option if you need old userspace for wireless
120 extensions with cfg80211-based drivers. 119 extensions with cfg80211-based drivers.
121 120
122config WIRELESS_EXT_SYSFS
123 bool "Wireless extensions sysfs files"
124 depends on WEXT_CORE && SYSFS
125 help
126 This option enables the deprecated wireless statistics
127 files in /sys/class/net/*/wireless/. The same information
128 is available via the ioctls as well.
129
130 Say N. If you know you have ancient tools requiring it,
131 like very old versions of hal (prior to 0.5.12 release),
132 say Y and update the tools as soon as possible as this
133 option will be removed soon.
134
135config LIB80211 121config LIB80211
136 tristate "Common routines for IEEE802.11 drivers" 122 tristate "Common routines for IEEE802.11 drivers"
137 default n 123 default n
diff --git a/net/wireless/chan.c b/net/wireless/chan.c
index 884801ac4dd0..c1999e45a07c 100644
--- a/net/wireless/chan.c
+++ b/net/wireless/chan.c
@@ -60,7 +60,7 @@ bool cfg80211_can_beacon_sec_chan(struct wiphy *wiphy,
60 diff = -20; 60 diff = -20;
61 break; 61 break;
62 default: 62 default:
63 return false; 63 return true;
64 } 64 }
65 65
66 sec_chan = ieee80211_get_channel(wiphy, chan->center_freq + diff); 66 sec_chan = ieee80211_get_channel(wiphy, chan->center_freq + diff);
@@ -78,60 +78,17 @@ bool cfg80211_can_beacon_sec_chan(struct wiphy *wiphy,
78} 78}
79EXPORT_SYMBOL(cfg80211_can_beacon_sec_chan); 79EXPORT_SYMBOL(cfg80211_can_beacon_sec_chan);
80 80
81int cfg80211_set_freq(struct cfg80211_registered_device *rdev, 81int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev,
82 struct wireless_dev *wdev, int freq, 82 int freq, enum nl80211_channel_type chantype)
83 enum nl80211_channel_type channel_type)
84{ 83{
85 struct ieee80211_channel *chan; 84 struct ieee80211_channel *chan;
86 int result;
87
88 if (wdev && wdev->iftype == NL80211_IFTYPE_MONITOR)
89 wdev = NULL;
90
91 if (wdev) {
92 ASSERT_WDEV_LOCK(wdev);
93
94 if (!netif_running(wdev->netdev))
95 return -ENETDOWN;
96 }
97 85
98 if (!rdev->ops->set_channel) 86 if (!rdev->ops->set_monitor_channel)
99 return -EOPNOTSUPP; 87 return -EOPNOTSUPP;
100 88
101 chan = rdev_freq_to_chan(rdev, freq, channel_type); 89 chan = rdev_freq_to_chan(rdev, freq, chantype);
102 if (!chan) 90 if (!chan)
103 return -EINVAL; 91 return -EINVAL;
104 92
105 /* Both channels should be able to initiate communication */ 93 return rdev->ops->set_monitor_channel(&rdev->wiphy, chan, chantype);
106 if (wdev && (wdev->iftype == NL80211_IFTYPE_ADHOC ||
107 wdev->iftype == NL80211_IFTYPE_AP ||
108 wdev->iftype == NL80211_IFTYPE_AP_VLAN ||
109 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
110 wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
111 switch (channel_type) {
112 case NL80211_CHAN_HT40PLUS:
113 case NL80211_CHAN_HT40MINUS:
114 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, chan,
115 channel_type)) {
116 printk(KERN_DEBUG
117 "cfg80211: Secondary channel not "
118 "allowed to initiate communication\n");
119 return -EINVAL;
120 }
121 break;
122 default:
123 break;
124 }
125 }
126
127 result = rdev->ops->set_channel(&rdev->wiphy,
128 wdev ? wdev->netdev : NULL,
129 chan, channel_type);
130 if (result)
131 return result;
132
133 if (wdev)
134 wdev->channel = chan;
135
136 return 0;
137} 94}
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 8523f3878677..9348a47562a4 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -303,14 +303,17 @@ extern const struct mesh_config default_mesh_config;
303extern const struct mesh_setup default_mesh_setup; 303extern const struct mesh_setup default_mesh_setup;
304int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev, 304int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
305 struct net_device *dev, 305 struct net_device *dev,
306 const struct mesh_setup *setup, 306 struct mesh_setup *setup,
307 const struct mesh_config *conf); 307 const struct mesh_config *conf);
308int cfg80211_join_mesh(struct cfg80211_registered_device *rdev, 308int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
309 struct net_device *dev, 309 struct net_device *dev,
310 const struct mesh_setup *setup, 310 struct mesh_setup *setup,
311 const struct mesh_config *conf); 311 const struct mesh_config *conf);
312int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev, 312int cfg80211_leave_mesh(struct cfg80211_registered_device *rdev,
313 struct net_device *dev); 313 struct net_device *dev);
314int cfg80211_set_mesh_freq(struct cfg80211_registered_device *rdev,
315 struct wireless_dev *wdev, int freq,
316 enum nl80211_channel_type channel_type);
314 317
315/* MLME */ 318/* MLME */
316int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev, 319int __cfg80211_mlme_auth(struct cfg80211_registered_device *rdev,
@@ -441,9 +444,8 @@ cfg80211_can_add_interface(struct cfg80211_registered_device *rdev,
441struct ieee80211_channel * 444struct ieee80211_channel *
442rdev_freq_to_chan(struct cfg80211_registered_device *rdev, 445rdev_freq_to_chan(struct cfg80211_registered_device *rdev,
443 int freq, enum nl80211_channel_type channel_type); 446 int freq, enum nl80211_channel_type channel_type);
444int cfg80211_set_freq(struct cfg80211_registered_device *rdev, 447int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev,
445 struct wireless_dev *wdev, int freq, 448 int freq, enum nl80211_channel_type chantype);
446 enum nl80211_channel_type channel_type);
447 449
448int ieee80211_get_ratemask(struct ieee80211_supported_band *sband, 450int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
449 const u8 *rates, unsigned int n_rates, 451 const u8 *rates, unsigned int n_rates,
diff --git a/net/wireless/mesh.c b/net/wireless/mesh.c
index 2749cb86b462..b44c736bf9cf 100644
--- a/net/wireless/mesh.c
+++ b/net/wireless/mesh.c
@@ -65,6 +65,9 @@ const struct mesh_config default_mesh_config = {
65}; 65};
66 66
67const struct mesh_setup default_mesh_setup = { 67const struct mesh_setup default_mesh_setup = {
68 /* cfg80211_join_mesh() will pick a channel if needed */
69 .channel = NULL,
70 .channel_type = NL80211_CHAN_NO_HT,
68 .sync_method = IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET, 71 .sync_method = IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET,
69 .path_sel_proto = IEEE80211_PATH_PROTOCOL_HWMP, 72 .path_sel_proto = IEEE80211_PATH_PROTOCOL_HWMP,
70 .path_metric = IEEE80211_PATH_METRIC_AIRTIME, 73 .path_metric = IEEE80211_PATH_METRIC_AIRTIME,
@@ -75,7 +78,7 @@ const struct mesh_setup default_mesh_setup = {
75 78
76int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev, 79int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
77 struct net_device *dev, 80 struct net_device *dev,
78 const struct mesh_setup *setup, 81 struct mesh_setup *setup,
79 const struct mesh_config *conf) 82 const struct mesh_config *conf)
80{ 83{
81 struct wireless_dev *wdev = dev->ieee80211_ptr; 84 struct wireless_dev *wdev = dev->ieee80211_ptr;
@@ -101,6 +104,51 @@ int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
101 if (!rdev->ops->join_mesh) 104 if (!rdev->ops->join_mesh)
102 return -EOPNOTSUPP; 105 return -EOPNOTSUPP;
103 106
107 if (!setup->channel) {
108 /* if no channel explicitly given, use preset channel */
109 setup->channel = wdev->preset_chan;
110 setup->channel_type = wdev->preset_chantype;
111 }
112
113 if (!setup->channel) {
114 /* if we don't have that either, use the first usable channel */
115 enum ieee80211_band band;
116
117 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
118 struct ieee80211_supported_band *sband;
119 struct ieee80211_channel *chan;
120 int i;
121
122 sband = rdev->wiphy.bands[band];
123 if (!sband)
124 continue;
125
126 for (i = 0; i < sband->n_channels; i++) {
127 chan = &sband->channels[i];
128 if (chan->flags & (IEEE80211_CHAN_NO_IBSS |
129 IEEE80211_CHAN_PASSIVE_SCAN |
130 IEEE80211_CHAN_DISABLED |
131 IEEE80211_CHAN_RADAR))
132 continue;
133 setup->channel = chan;
134 break;
135 }
136
137 if (setup->channel)
138 break;
139 }
140
141 /* no usable channel ... */
142 if (!setup->channel)
143 return -EINVAL;
144
145 setup->channel_type = NL80211_CHAN_NO_HT;
146 }
147
148 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, setup->channel,
149 setup->channel_type))
150 return -EINVAL;
151
104 err = rdev->ops->join_mesh(&rdev->wiphy, dev, conf, setup); 152 err = rdev->ops->join_mesh(&rdev->wiphy, dev, conf, setup);
105 if (!err) { 153 if (!err) {
106 memcpy(wdev->ssid, setup->mesh_id, setup->mesh_id_len); 154 memcpy(wdev->ssid, setup->mesh_id, setup->mesh_id_len);
@@ -112,7 +160,7 @@ int __cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
112 160
113int cfg80211_join_mesh(struct cfg80211_registered_device *rdev, 161int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
114 struct net_device *dev, 162 struct net_device *dev,
115 const struct mesh_setup *setup, 163 struct mesh_setup *setup,
116 const struct mesh_config *conf) 164 const struct mesh_config *conf)
117{ 165{
118 struct wireless_dev *wdev = dev->ieee80211_ptr; 166 struct wireless_dev *wdev = dev->ieee80211_ptr;
@@ -125,6 +173,45 @@ int cfg80211_join_mesh(struct cfg80211_registered_device *rdev,
125 return err; 173 return err;
126} 174}
127 175
176int cfg80211_set_mesh_freq(struct cfg80211_registered_device *rdev,
177 struct wireless_dev *wdev, int freq,
178 enum nl80211_channel_type channel_type)
179{
180 struct ieee80211_channel *channel;
181
182 channel = rdev_freq_to_chan(rdev, freq, channel_type);
183 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
184 channel,
185 channel_type)) {
186 return -EINVAL;
187 }
188
189 /*
190 * Workaround for libertas (only!), it puts the interface
191 * into mesh mode but doesn't implement join_mesh. Instead,
192 * it is configured via sysfs and then joins the mesh when
193 * you set the channel. Note that the libertas mesh isn't
194 * compatible with 802.11 mesh.
195 */
196 if (rdev->ops->libertas_set_mesh_channel) {
197 if (channel_type != NL80211_CHAN_NO_HT)
198 return -EINVAL;
199
200 if (!netif_running(wdev->netdev))
201 return -ENETDOWN;
202 return rdev->ops->libertas_set_mesh_channel(&rdev->wiphy,
203 wdev->netdev,
204 channel);
205 }
206
207 if (wdev->mesh_id_len)
208 return -EBUSY;
209
210 wdev->preset_chan = channel;
211 wdev->preset_chantype = channel_type;
212 return 0;
213}
214
128void cfg80211_notify_new_peer_candidate(struct net_device *dev, 215void cfg80211_notify_new_peer_candidate(struct net_device *dev,
129 const u8 *macaddr, const u8* ie, u8 ie_len, gfp_t gfp) 216 const u8 *macaddr, const u8* ie, u8 ie_len, gfp_t gfp)
130{ 217{
diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c
index eb90988bbd36..da4406f11929 100644
--- a/net/wireless/mlme.c
+++ b/net/wireless/mlme.c
@@ -947,8 +947,6 @@ void cfg80211_ch_switch_notify(struct net_device *dev, int freq,
947 if (WARN_ON(!chan)) 947 if (WARN_ON(!chan))
948 goto out; 948 goto out;
949 949
950 wdev->channel = chan;
951
952 nl80211_ch_switch_notify(rdev, dev, freq, type, GFP_KERNEL); 950 nl80211_ch_switch_notify(rdev, dev, freq, type, GFP_KERNEL);
953out: 951out:
954 wdev_unlock(wdev); 952 wdev_unlock(wdev);
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 206465dc0cab..7ae54b82291f 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -921,7 +921,12 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
921 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) 921 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
922 goto nla_put_failure; 922 goto nla_put_failure;
923 } 923 }
924 CMD(set_channel, SET_CHANNEL); 924 if (dev->ops->set_monitor_channel || dev->ops->start_ap ||
925 dev->ops->join_mesh) {
926 i++;
927 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
928 goto nla_put_failure;
929 }
925 CMD(set_wds_peer, SET_WDS_PEER); 930 CMD(set_wds_peer, SET_WDS_PEER);
926 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { 931 if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
927 CMD(tdls_mgmt, TDLS_MGMT); 932 CMD(tdls_mgmt, TDLS_MGMT);
@@ -1162,18 +1167,22 @@ static int parse_txq_params(struct nlattr *tb[],
1162static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) 1167static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1163{ 1168{
1164 /* 1169 /*
1165 * You can only set the channel explicitly for AP, mesh 1170 * You can only set the channel explicitly for WDS interfaces,
1166 * and WDS type interfaces; all others have their channel 1171 * all others have their channel managed via their respective
1167 * managed via their respective "establish a connection" 1172 * "establish a connection" command (connect, join, ...)
1168 * command (connect, join, ...) 1173 *
1174 * For AP/GO and mesh mode, the channel can be set with the
1175 * channel userspace API, but is only stored and passed to the
1176 * low-level driver when the AP starts or the mesh is joined.
1177 * This is for backward compatibility, userspace can also give
1178 * the channel in the start-ap or join-mesh commands instead.
1169 * 1179 *
1170 * Monitors are special as they are normally slaved to 1180 * Monitors are special as they are normally slaved to
1171 * whatever else is going on, so they behave as though 1181 * whatever else is going on, so they have their own special
1172 * you tried setting the wiphy channel itself. 1182 * operation to set the monitor channel if possible.
1173 */ 1183 */
1174 return !wdev || 1184 return !wdev ||
1175 wdev->iftype == NL80211_IFTYPE_AP || 1185 wdev->iftype == NL80211_IFTYPE_AP ||
1176 wdev->iftype == NL80211_IFTYPE_WDS ||
1177 wdev->iftype == NL80211_IFTYPE_MESH_POINT || 1186 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
1178 wdev->iftype == NL80211_IFTYPE_MONITOR || 1187 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1179 wdev->iftype == NL80211_IFTYPE_P2P_GO; 1188 wdev->iftype == NL80211_IFTYPE_P2P_GO;
@@ -1204,9 +1213,14 @@ static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1204 struct wireless_dev *wdev, 1213 struct wireless_dev *wdev,
1205 struct genl_info *info) 1214 struct genl_info *info)
1206{ 1215{
1216 struct ieee80211_channel *channel;
1207 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; 1217 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
1208 u32 freq; 1218 u32 freq;
1209 int result; 1219 int result;
1220 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
1221
1222 if (wdev)
1223 iftype = wdev->iftype;
1210 1224
1211 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) 1225 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1212 return -EINVAL; 1226 return -EINVAL;
@@ -1221,12 +1235,32 @@ static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
1221 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); 1235 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1222 1236
1223 mutex_lock(&rdev->devlist_mtx); 1237 mutex_lock(&rdev->devlist_mtx);
1224 if (wdev) { 1238 switch (iftype) {
1225 wdev_lock(wdev); 1239 case NL80211_IFTYPE_AP:
1226 result = cfg80211_set_freq(rdev, wdev, freq, channel_type); 1240 case NL80211_IFTYPE_P2P_GO:
1227 wdev_unlock(wdev); 1241 if (wdev->beacon_interval) {
1228 } else { 1242 result = -EBUSY;
1229 result = cfg80211_set_freq(rdev, NULL, freq, channel_type); 1243 break;
1244 }
1245 channel = rdev_freq_to_chan(rdev, freq, channel_type);
1246 if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy,
1247 channel,
1248 channel_type)) {
1249 result = -EINVAL;
1250 break;
1251 }
1252 wdev->preset_chan = channel;
1253 wdev->preset_chantype = channel_type;
1254 result = 0;
1255 break;
1256 case NL80211_IFTYPE_MESH_POINT:
1257 result = cfg80211_set_mesh_freq(rdev, wdev, freq, channel_type);
1258 break;
1259 case NL80211_IFTYPE_MONITOR:
1260 result = cfg80211_set_monitor_channel(rdev, freq, channel_type);
1261 break;
1262 default:
1263 result = -EINVAL;
1230 } 1264 }
1231 mutex_unlock(&rdev->devlist_mtx); 1265 mutex_unlock(&rdev->devlist_mtx);
1232 1266
@@ -1310,8 +1344,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
1310 result = 0; 1344 result = 0;
1311 1345
1312 mutex_lock(&rdev->mtx); 1346 mutex_lock(&rdev->mtx);
1313 } else if (netif_running(netdev) && 1347 } else if (nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
1314 nl80211_can_set_dev_channel(netdev->ieee80211_ptr))
1315 wdev = netdev->ieee80211_ptr; 1348 wdev = netdev->ieee80211_ptr;
1316 else 1349 else
1317 wdev = NULL; 1350 wdev = NULL;
@@ -2299,6 +2332,29 @@ static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
2299 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); 2332 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
2300 } 2333 }
2301 2334
2335 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2336 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
2337
2338 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
2339 !nl80211_valid_channel_type(info, &channel_type))
2340 return -EINVAL;
2341
2342 params.channel = rdev_freq_to_chan(rdev,
2343 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
2344 channel_type);
2345 if (!params.channel)
2346 return -EINVAL;
2347 params.channel_type = channel_type;
2348 } else if (wdev->preset_chan) {
2349 params.channel = wdev->preset_chan;
2350 params.channel_type = wdev->preset_chantype;
2351 } else
2352 return -EINVAL;
2353
2354 if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel,
2355 params.channel_type))
2356 return -EINVAL;
2357
2302 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params); 2358 err = rdev->ops->start_ap(&rdev->wiphy, dev, &params);
2303 if (!err) 2359 if (!err)
2304 wdev->beacon_interval = params.beacon_interval; 2360 wdev->beacon_interval = params.beacon_interval;
@@ -5489,18 +5545,18 @@ static int nl80211_remain_on_channel(struct sk_buff *skb,
5489 5545
5490 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 5546 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5491 5547
5548 if (!rdev->ops->remain_on_channel ||
5549 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
5550 return -EOPNOTSUPP;
5551
5492 /* 5552 /*
5493 * We should be on that channel for at least one jiffie, 5553 * We should be on that channel for at least a minimum amount of
5494 * and more than 5 seconds seems excessive. 5554 * time (10ms) but no longer than the driver supports.
5495 */ 5555 */
5496 if (!duration || !msecs_to_jiffies(duration) || 5556 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5497 duration > rdev->wiphy.max_remain_on_channel_duration) 5557 duration > rdev->wiphy.max_remain_on_channel_duration)
5498 return -EINVAL; 5558 return -EINVAL;
5499 5559
5500 if (!rdev->ops->remain_on_channel ||
5501 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
5502 return -EOPNOTSUPP;
5503
5504 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && 5560 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
5505 !nl80211_valid_channel_type(info, &channel_type)) 5561 !nl80211_valid_channel_type(info, &channel_type))
5506 return -EINVAL; 5562 return -EINVAL;
@@ -5771,6 +5827,15 @@ static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
5771 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) 5827 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
5772 return -EINVAL; 5828 return -EINVAL;
5773 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); 5829 wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
5830
5831 /*
5832 * We should wait on the channel for at least a minimum amount
5833 * of time (10ms) but no longer than the driver supports.
5834 */
5835 if (wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
5836 wait > rdev->wiphy.max_remain_on_channel_duration)
5837 return -EINVAL;
5838
5774 } 5839 }
5775 5840
5776 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { 5841 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
@@ -6032,6 +6097,24 @@ static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
6032 return err; 6097 return err;
6033 } 6098 }
6034 6099
6100 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
6101 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
6102
6103 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] &&
6104 !nl80211_valid_channel_type(info, &channel_type))
6105 return -EINVAL;
6106
6107 setup.channel = rdev_freq_to_chan(rdev,
6108 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]),
6109 channel_type);
6110 if (!setup.channel)
6111 return -EINVAL;
6112 setup.channel_type = channel_type;
6113 } else {
6114 /* cfg80211_join_mesh() will sort it out */
6115 setup.channel = NULL;
6116 }
6117
6035 return cfg80211_join_mesh(rdev, dev, &setup, &cfg); 6118 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
6036} 6119}
6037 6120
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
index 6a6181a673ca..bc879833b21f 100644
--- a/net/wireless/wext-compat.c
+++ b/net/wireless/wext-compat.c
@@ -796,7 +796,15 @@ static int cfg80211_wext_siwfreq(struct net_device *dev,
796 case NL80211_IFTYPE_ADHOC: 796 case NL80211_IFTYPE_ADHOC:
797 return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra); 797 return cfg80211_ibss_wext_siwfreq(dev, info, wextfreq, extra);
798 case NL80211_IFTYPE_MONITOR: 798 case NL80211_IFTYPE_MONITOR:
799 case NL80211_IFTYPE_WDS: 799 freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
800 if (freq < 0)
801 return freq;
802 if (freq == 0)
803 return -EINVAL;
804 mutex_lock(&rdev->devlist_mtx);
805 err = cfg80211_set_monitor_channel(rdev, freq, NL80211_CHAN_NO_HT);
806 mutex_unlock(&rdev->devlist_mtx);
807 return err;
800 case NL80211_IFTYPE_MESH_POINT: 808 case NL80211_IFTYPE_MESH_POINT:
801 freq = cfg80211_wext_freq(wdev->wiphy, wextfreq); 809 freq = cfg80211_wext_freq(wdev->wiphy, wextfreq);
802 if (freq < 0) 810 if (freq < 0)
@@ -804,9 +812,8 @@ static int cfg80211_wext_siwfreq(struct net_device *dev,
804 if (freq == 0) 812 if (freq == 0)
805 return -EINVAL; 813 return -EINVAL;
806 mutex_lock(&rdev->devlist_mtx); 814 mutex_lock(&rdev->devlist_mtx);
807 wdev_lock(wdev); 815 err = cfg80211_set_mesh_freq(rdev, wdev, freq,
808 err = cfg80211_set_freq(rdev, wdev, freq, NL80211_CHAN_NO_HT); 816 NL80211_CHAN_NO_HT);
809 wdev_unlock(wdev);
810 mutex_unlock(&rdev->devlist_mtx); 817 mutex_unlock(&rdev->devlist_mtx);
811 return err; 818 return err;
812 default: 819 default:
@@ -839,11 +846,7 @@ static int cfg80211_wext_giwfreq(struct net_device *dev,
839 freq->e = 6; 846 freq->e = 6;
840 return 0; 847 return 0;
841 default: 848 default:
842 if (!wdev->channel) 849 return -EINVAL;
843 return -EINVAL;
844 freq->m = wdev->channel->center_freq;
845 freq->e = 6;
846 return 0;
847 } 850 }
848} 851}
849 852
diff --git a/net/wireless/wext-sme.c b/net/wireless/wext-sme.c
index 7decbd357d51..1f773f668d1a 100644
--- a/net/wireless/wext-sme.c
+++ b/net/wireless/wext-sme.c
@@ -111,9 +111,15 @@ int cfg80211_mgd_wext_siwfreq(struct net_device *dev,
111 111
112 wdev->wext.connect.channel = chan; 112 wdev->wext.connect.channel = chan;
113 113
114 /* SSID is not set, we just want to switch channel */ 114 /*
115 * SSID is not set, we just want to switch monitor channel,
116 * this is really just backward compatibility, if the SSID
117 * is set then we use the channel to select the BSS to use
118 * to connect to instead. If we were connected on another
119 * channel we disconnected above and reconnect below.
120 */
115 if (chan && !wdev->wext.connect.ssid_len) { 121 if (chan && !wdev->wext.connect.ssid_len) {
116 err = cfg80211_set_freq(rdev, wdev, freq, NL80211_CHAN_NO_HT); 122 err = cfg80211_set_monitor_channel(rdev, freq, NL80211_CHAN_NO_HT);
117 goto out; 123 goto out;
118 } 124 }
119 125