Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
authorJohn W. Linville <linville@tuxdriver.com>
Wed, 18 Apr 2012 18:17:13 +0000 (14:17 -0400)
committerJohn W. Linville <linville@tuxdriver.com>
Wed, 18 Apr 2012 18:27:48 +0000 (14:27 -0400)
Conflicts:
drivers/net/wireless/iwlwifi/iwl-testmode.c
include/net/nfc/nfc.h
net/nfc/netlink.c
net/wireless/nl80211.c

352 files changed:
Documentation/nfc/nfc-hci.txt [new file with mode: 0644]
MAINTAINERS
drivers/net/wireless/Kconfig
drivers/net/wireless/Makefile
drivers/net/wireless/adm8211.c
drivers/net/wireless/at76c50x-usb.c
drivers/net/wireless/ath/ath5k/ath5k.h
drivers/net/wireless/ath/ath5k/base.c
drivers/net/wireless/ath/ath5k/pci.c
drivers/net/wireless/ath/ath5k/pcu.c
drivers/net/wireless/ath/ath5k/qcu.c
drivers/net/wireless/ath/ath6kl/Makefile
drivers/net/wireless/ath/ath6kl/cfg80211.c
drivers/net/wireless/ath/ath6kl/common.h
drivers/net/wireless/ath/ath6kl/core.c
drivers/net/wireless/ath/ath6kl/core.h
drivers/net/wireless/ath/ath6kl/debug.c
drivers/net/wireless/ath/ath6kl/debug.h
drivers/net/wireless/ath/ath6kl/hif-ops.h
drivers/net/wireless/ath/ath6kl/hif.h
drivers/net/wireless/ath/ath6kl/htc-ops.h [new file with mode: 0644]
drivers/net/wireless/ath/ath6kl/htc.c [deleted file]
drivers/net/wireless/ath/ath6kl/htc.h
drivers/net/wireless/ath/ath6kl/htc_mbox.c [new file with mode: 0644]
drivers/net/wireless/ath/ath6kl/htc_pipe.c [new file with mode: 0644]
drivers/net/wireless/ath/ath6kl/init.c
drivers/net/wireless/ath/ath6kl/main.c
drivers/net/wireless/ath/ath6kl/sdio.c
drivers/net/wireless/ath/ath6kl/txrx.c
drivers/net/wireless/ath/ath6kl/usb.c
drivers/net/wireless/ath/ath6kl/wmi.c
drivers/net/wireless/ath/ath6kl/wmi.h
drivers/net/wireless/ath/ath9k/ani.c
drivers/net/wireless/ath/ath9k/ar5008_phy.c
drivers/net/wireless/ath/ath9k/ar9002_mac.c
drivers/net/wireless/ath/ath9k/ar9002_phy.c
drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
drivers/net/wireless/ath/ath9k/ar9003_eeprom.h
drivers/net/wireless/ath/ath9k/ar9003_hw.c
drivers/net/wireless/ath/ath9k/ar9003_mac.c
drivers/net/wireless/ath/ath9k/ar9003_phy.c
drivers/net/wireless/ath/ath9k/ar9462_2p0_initvals.h
drivers/net/wireless/ath/ath9k/ath9k.h
drivers/net/wireless/ath/ath9k/beacon.c
drivers/net/wireless/ath/ath9k/debug.c
drivers/net/wireless/ath/ath9k/debug.h
drivers/net/wireless/ath/ath9k/eeprom.c
drivers/net/wireless/ath/ath9k/eeprom.h
drivers/net/wireless/ath/ath9k/eeprom_9287.c
drivers/net/wireless/ath/ath9k/eeprom_def.c
drivers/net/wireless/ath/ath9k/gpio.c
drivers/net/wireless/ath/ath9k/hif_usb.c
drivers/net/wireless/ath/ath9k/hw.c
drivers/net/wireless/ath/ath9k/hw.h
drivers/net/wireless/ath/ath9k/main.c
drivers/net/wireless/atmel.c
drivers/net/wireless/atmel_pci.c
drivers/net/wireless/b43/xmit.c
drivers/net/wireless/b43legacy/main.c
drivers/net/wireless/b43legacy/xmit.c
drivers/net/wireless/brcm80211/brcmfmac/dhd.h
drivers/net/wireless/brcm80211/brcmfmac/dhd_cdc.c
drivers/net/wireless/brcm80211/brcmfmac/dhd_common.c
drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c
drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
drivers/net/wireless/brcm80211/brcmfmac/usb.c
drivers/net/wireless/brcm80211/brcmsmac/channel.c
drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c
drivers/net/wireless/brcm80211/brcmsmac/phy/phy_lcn.c
drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c
drivers/net/wireless/brcm80211/include/brcm_hw_ids.h
drivers/net/wireless/hostap/hostap_main.c
drivers/net/wireless/hostap/hostap_pci.c
drivers/net/wireless/hostap/hostap_plx.c
drivers/net/wireless/ipw2x00/ipw.h [new file with mode: 0644]
drivers/net/wireless/ipw2x00/ipw2100.c
drivers/net/wireless/ipw2x00/ipw2200.c
drivers/net/wireless/iwlwifi/Kconfig
drivers/net/wireless/iwlwifi/Makefile
drivers/net/wireless/iwlwifi/iwl-1000.c
drivers/net/wireless/iwlwifi/iwl-2000.c
drivers/net/wireless/iwlwifi/iwl-5000.c
drivers/net/wireless/iwlwifi/iwl-6000.c
drivers/net/wireless/iwlwifi/iwl-agn-calib.c
drivers/net/wireless/iwlwifi/iwl-agn-devices.c [new file with mode: 0644]
drivers/net/wireless/iwlwifi/iwl-agn-lib.c
drivers/net/wireless/iwlwifi/iwl-agn-rs.c
drivers/net/wireless/iwlwifi/iwl-agn-rx.c
drivers/net/wireless/iwlwifi/iwl-agn-rxon.c
drivers/net/wireless/iwlwifi/iwl-agn-sta.c
drivers/net/wireless/iwlwifi/iwl-agn-tx.c
drivers/net/wireless/iwlwifi/iwl-agn.c
drivers/net/wireless/iwlwifi/iwl-agn.h
drivers/net/wireless/iwlwifi/iwl-commands.h
drivers/net/wireless/iwlwifi/iwl-config.h [new file with mode: 0644]
drivers/net/wireless/iwlwifi/iwl-core.c
drivers/net/wireless/iwlwifi/iwl-core.h
drivers/net/wireless/iwlwifi/iwl-csr.h
drivers/net/wireless/iwlwifi/iwl-debugfs.c
drivers/net/wireless/iwlwifi/iwl-dev.h
drivers/net/wireless/iwlwifi/iwl-drv.c
drivers/net/wireless/iwlwifi/iwl-eeprom.c
drivers/net/wireless/iwlwifi/iwl-eeprom.h
drivers/net/wireless/iwlwifi/iwl-fw-file.h
drivers/net/wireless/iwlwifi/iwl-mac80211.c
drivers/net/wireless/iwlwifi/iwl-op-mode.h
drivers/net/wireless/iwlwifi/iwl-pci.c
drivers/net/wireless/iwlwifi/iwl-phy-db.c
drivers/net/wireless/iwlwifi/iwl-phy-db.h
drivers/net/wireless/iwlwifi/iwl-power.c
drivers/net/wireless/iwlwifi/iwl-scan.c
drivers/net/wireless/iwlwifi/iwl-shared.h
drivers/net/wireless/iwlwifi/iwl-testmode.c
drivers/net/wireless/iwlwifi/iwl-trans-pcie-int.h
drivers/net/wireless/iwlwifi/iwl-trans-pcie-rx.c
drivers/net/wireless/iwlwifi/iwl-trans-pcie-tx.c
drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
drivers/net/wireless/iwlwifi/iwl-trans.h
drivers/net/wireless/iwlwifi/iwl-ucode.c
drivers/net/wireless/libertas/Makefile
drivers/net/wireless/libertas/decl.h
drivers/net/wireless/libertas/dev.h
drivers/net/wireless/libertas/firmware.c [new file with mode: 0644]
drivers/net/wireless/libertas/if_cs.c
drivers/net/wireless/libertas/if_sdio.c
drivers/net/wireless/libertas/if_spi.c
drivers/net/wireless/libertas/if_usb.c
drivers/net/wireless/libertas/main.c
drivers/net/wireless/mac80211_hwsim.c
drivers/net/wireless/mwifiex/cfg80211.c
drivers/net/wireless/mwifiex/cfp.c
drivers/net/wireless/mwifiex/debugfs.c
drivers/net/wireless/mwifiex/fw.h
drivers/net/wireless/mwifiex/init.c
drivers/net/wireless/mwifiex/ioctl.h
drivers/net/wireless/mwifiex/join.c
drivers/net/wireless/mwifiex/main.c
drivers/net/wireless/mwifiex/main.h
drivers/net/wireless/mwifiex/pcie.c
drivers/net/wireless/mwifiex/scan.c
drivers/net/wireless/mwifiex/sdio.c
drivers/net/wireless/mwifiex/sta_cmd.c
drivers/net/wireless/mwifiex/sta_ioctl.c
drivers/net/wireless/mwl8k.c
drivers/net/wireless/orinoco/fw.c
drivers/net/wireless/p54/p54pci.c
drivers/net/wireless/prism54/oid_mgt.c
drivers/net/wireless/rt2x00/rt2400pci.c
drivers/net/wireless/rt2x00/rt2500pci.c
drivers/net/wireless/rt2x00/rt2500usb.c
drivers/net/wireless/rt2x00/rt2800lib.c
drivers/net/wireless/rt2x00/rt2800lib.h
drivers/net/wireless/rt2x00/rt2800pci.c
drivers/net/wireless/rt2x00/rt2x00dev.c
drivers/net/wireless/rt2x00/rt61pci.c
drivers/net/wireless/rt2x00/rt73usb.c
drivers/net/wireless/rtl818x/rtl8180/dev.c
drivers/net/wireless/rtl818x/rtl8187/dev.c
drivers/net/wireless/rtlwifi/pci.c
drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c
drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
drivers/net/wireless/rtlwifi/rtl8192de/def.h
drivers/net/wireless/rtlwifi/rtl8192de/hw.c
drivers/net/wireless/rtlwifi/rtl8192se/sw.c
drivers/net/wireless/ti/Kconfig [new file with mode: 0644]
drivers/net/wireless/ti/Makefile [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/Kconfig [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/Makefile [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/acx.c [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/acx.h [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/boot.c [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/boot.h [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/cmd.c [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/cmd.h [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/debugfs.c [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/debugfs.h [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/event.c [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/event.h [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/init.c [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/init.h [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/io.c [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/io.h [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/main.c [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/ps.c [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/ps.h [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/reg.h [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/rx.c [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/rx.h [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/sdio.c [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/spi.c [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/spi.h [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/tx.c [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/tx.h [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/wl1251.h [new file with mode: 0644]
drivers/net/wireless/ti/wl1251/wl12xx_80211.h [new file with mode: 0644]
drivers/net/wireless/ti/wl12xx/Kconfig [new file with mode: 0644]
drivers/net/wireless/ti/wl12xx/Makefile [new file with mode: 0644]
drivers/net/wireless/ti/wl12xx/acx.c [new file with mode: 0644]
drivers/net/wireless/ti/wl12xx/acx.h [new file with mode: 0644]
drivers/net/wireless/ti/wl12xx/cmd.c [new file with mode: 0644]
drivers/net/wireless/ti/wl12xx/cmd.h [new file with mode: 0644]
drivers/net/wireless/ti/wl12xx/conf.h [new file with mode: 0644]
drivers/net/wireless/ti/wl12xx/main.c [new file with mode: 0644]
drivers/net/wireless/ti/wl12xx/reg.h [new file with mode: 0644]
drivers/net/wireless/ti/wl12xx/wl12xx.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/Kconfig [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/Makefile [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/acx.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/acx.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/boot.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/boot.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/cmd.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/cmd.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/conf.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/debug.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/debugfs.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/debugfs.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/event.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/event.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/hw_ops.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/ini.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/init.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/init.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/io.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/io.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/main.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/ps.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/ps.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/rx.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/rx.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/scan.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/scan.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/sdio.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/spi.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/testmode.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/testmode.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/tx.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/tx.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/wl12xx.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/wl12xx_80211.h [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/wl12xx_platform_data.c [new file with mode: 0644]
drivers/net/wireless/ti/wlcore/wlcore.h [new file with mode: 0644]
drivers/net/wireless/wl1251/Kconfig [deleted file]
drivers/net/wireless/wl1251/Makefile [deleted file]
drivers/net/wireless/wl1251/acx.c [deleted file]
drivers/net/wireless/wl1251/acx.h [deleted file]
drivers/net/wireless/wl1251/boot.c [deleted file]
drivers/net/wireless/wl1251/boot.h [deleted file]
drivers/net/wireless/wl1251/cmd.c [deleted file]
drivers/net/wireless/wl1251/cmd.h [deleted file]
drivers/net/wireless/wl1251/debugfs.c [deleted file]
drivers/net/wireless/wl1251/debugfs.h [deleted file]
drivers/net/wireless/wl1251/event.c [deleted file]
drivers/net/wireless/wl1251/event.h [deleted file]
drivers/net/wireless/wl1251/init.c [deleted file]
drivers/net/wireless/wl1251/init.h [deleted file]
drivers/net/wireless/wl1251/io.c [deleted file]
drivers/net/wireless/wl1251/io.h [deleted file]
drivers/net/wireless/wl1251/main.c [deleted file]
drivers/net/wireless/wl1251/ps.c [deleted file]
drivers/net/wireless/wl1251/ps.h [deleted file]
drivers/net/wireless/wl1251/reg.h [deleted file]
drivers/net/wireless/wl1251/rx.c [deleted file]
drivers/net/wireless/wl1251/rx.h [deleted file]
drivers/net/wireless/wl1251/sdio.c [deleted file]
drivers/net/wireless/wl1251/spi.c [deleted file]
drivers/net/wireless/wl1251/spi.h [deleted file]
drivers/net/wireless/wl1251/tx.c [deleted file]
drivers/net/wireless/wl1251/tx.h [deleted file]
drivers/net/wireless/wl1251/wl1251.h [deleted file]
drivers/net/wireless/wl1251/wl12xx_80211.h [deleted file]
drivers/net/wireless/wl12xx/Kconfig [deleted file]
drivers/net/wireless/wl12xx/Makefile [deleted file]
drivers/net/wireless/wl12xx/acx.c [deleted file]
drivers/net/wireless/wl12xx/acx.h [deleted file]
drivers/net/wireless/wl12xx/boot.c [deleted file]
drivers/net/wireless/wl12xx/boot.h [deleted file]
drivers/net/wireless/wl12xx/cmd.c [deleted file]
drivers/net/wireless/wl12xx/cmd.h [deleted file]
drivers/net/wireless/wl12xx/conf.h [deleted file]
drivers/net/wireless/wl12xx/debug.h [deleted file]
drivers/net/wireless/wl12xx/debugfs.c [deleted file]
drivers/net/wireless/wl12xx/debugfs.h [deleted file]
drivers/net/wireless/wl12xx/event.c [deleted file]
drivers/net/wireless/wl12xx/event.h [deleted file]
drivers/net/wireless/wl12xx/ini.h [deleted file]
drivers/net/wireless/wl12xx/init.c [deleted file]
drivers/net/wireless/wl12xx/init.h [deleted file]
drivers/net/wireless/wl12xx/io.c [deleted file]
drivers/net/wireless/wl12xx/io.h [deleted file]
drivers/net/wireless/wl12xx/main.c [deleted file]
drivers/net/wireless/wl12xx/ps.c [deleted file]
drivers/net/wireless/wl12xx/ps.h [deleted file]
drivers/net/wireless/wl12xx/reg.h [deleted file]
drivers/net/wireless/wl12xx/rx.c [deleted file]
drivers/net/wireless/wl12xx/rx.h [deleted file]
drivers/net/wireless/wl12xx/scan.c [deleted file]
drivers/net/wireless/wl12xx/scan.h [deleted file]
drivers/net/wireless/wl12xx/sdio.c [deleted file]
drivers/net/wireless/wl12xx/spi.c [deleted file]
drivers/net/wireless/wl12xx/testmode.c [deleted file]
drivers/net/wireless/wl12xx/testmode.h [deleted file]
drivers/net/wireless/wl12xx/tx.c [deleted file]
drivers/net/wireless/wl12xx/tx.h [deleted file]
drivers/net/wireless/wl12xx/wl12xx.h [deleted file]
drivers/net/wireless/wl12xx/wl12xx_80211.h [deleted file]
drivers/net/wireless/wl12xx/wl12xx_platform_data.c [deleted file]
drivers/nfc/pn533.c
include/linux/ieee80211.h
include/linux/nfc.h
include/net/cfg80211.h
include/net/mac80211.h
include/net/nfc/hci.h [new file with mode: 0644]
include/net/nfc/nfc.h
include/net/nfc/shdlc.h [new file with mode: 0644]
net/mac80211/cfg.c
net/mac80211/ieee80211_i.h
net/mac80211/iface.c
net/mac80211/mesh_hwmp.c
net/mac80211/mesh_pathtbl.c
net/mac80211/mesh_sync.c
net/mac80211/mlme.c
net/mac80211/rc80211_minstrel.c
net/mac80211/rc80211_minstrel_ht.c
net/mac80211/scan.c
net/mac80211/status.c
net/mac80211/tx.c
net/mac80211/util.c
net/mac80211/work.c
net/nfc/Kconfig
net/nfc/Makefile
net/nfc/core.c
net/nfc/hci/Kconfig [new file with mode: 0644]
net/nfc/hci/Makefile [new file with mode: 0644]
net/nfc/hci/command.c [new file with mode: 0644]
net/nfc/hci/core.c [new file with mode: 0644]
net/nfc/hci/hci.h [new file with mode: 0644]
net/nfc/hci/hcp.c [new file with mode: 0644]
net/nfc/hci/shdlc.c [new file with mode: 0644]
net/nfc/llcp/commands.c
net/nfc/llcp/llcp.c
net/nfc/nci/core.c
net/nfc/nci/ntf.c
net/nfc/netlink.c
net/nfc/nfc.h
net/nfc/rawsock.c
net/wireless/core.c
net/wireless/nl80211.c
net/wireless/scan.c
net/wireless/util.c
net/wireless/wext-compat.c

diff --git a/Documentation/nfc/nfc-hci.txt b/Documentation/nfc/nfc-hci.txt
new file mode 100644 (file)
index 0000000..216b725
--- /dev/null
@@ -0,0 +1,155 @@
+HCI backend for NFC Core
+
+Author: Eric Lapuyade, Samuel Ortiz
+Contact: eric.lapuyade@intel.com, samuel.ortiz@intel.com
+
+General
+-------
+
+The HCI layer implements much of the ETSI TS 102 622 V10.2.0 specification. It
+enables easy writing of HCI-based NFC drivers. The HCI layer runs as an NFC Core
+backend, implementing an abstract nfc device and translating NFC Core API
+to HCI commands and events.
+
+HCI
+---
+
+HCI registers as an nfc device with NFC Core. Requests coming from userspace are
+routed through netlink sockets to NFC Core and then to HCI. From this point,
+they are translated in a sequence of HCI commands sent to the HCI layer in the
+host controller (the chip). The sending context blocks while waiting for the
+response to arrive.
+HCI events can also be received from the host controller. They will be handled
+and a translation will be forwarded to NFC Core as needed.
+HCI uses 2 execution contexts:
+- one if for executing commands : nfc_hci_msg_tx_work(). Only one command
+can be executing at any given moment.
+- one if for dispatching received events and responses : nfc_hci_msg_rx_work()
+
+HCI Session initialization:
+---------------------------
+
+The Session initialization is an HCI standard which must unfortunately
+support proprietary gates. This is the reason why the driver will pass a list
+of proprietary gates that must be part of the session. HCI will ensure all
+those gates have pipes connected when the hci device is set up.
+
+HCI Gates and Pipes
+-------------------
+
+A gate defines the 'port' where some service can be found. In order to access
+a service, one must create a pipe to that gate and open it. In this
+implementation, pipes are totally hidden. The public API only knows gates.
+This is consistent with the driver need to send commands to proprietary gates
+without knowing the pipe connected to it.
+
+Driver interface
+----------------
+
+A driver would normally register itself with HCI and provide the following
+entry points:
+
+struct nfc_hci_ops {
+       int (*open)(struct nfc_hci_dev *hdev);
+       void (*close)(struct nfc_hci_dev *hdev);
+       int (*xmit)(struct nfc_hci_dev *hdev, struct sk_buff *skb);
+       int (*start_poll)(struct nfc_hci_dev *hdev, u32 protocols);
+       int (*target_from_gate)(struct nfc_hci_dev *hdev, u8 gate,
+                               struct nfc_target *target);
+};
+
+open() and close() shall turn the hardware on and off. xmit() shall simply
+write a frame to the chip. start_poll() is an optional entrypoint that shall
+set the hardware in polling mode. This must be implemented only if the hardware
+uses proprietary gates or a mechanism slightly different from the HCI standard.
+target_from_gate() is another optional entrypoint to return the protocols
+corresponding to a proprietary gate.
+
+On the rx path, the driver is responsible to push incoming HCP frames to HCI
+using nfc_hci_recv_frame(). HCI will take care of re-aggregation and handling
+This must be done from a context that can sleep.
+
+SHDLC
+-----
+
+Most chips use shdlc to ensure integrity and delivery ordering of the HCP
+frames between the host controller (the chip) and hosts (entities connected
+to the chip, like the cpu). In order to simplify writing the driver, an shdlc
+layer is available for use by the driver.
+When used, the driver actually registers with shdlc, and shdlc will register
+with HCI. HCI sees shdlc as the driver and thus send its HCP frames
+through shdlc->xmit.
+SHDLC adds a new execution context (nfc_shdlc_sm_work()) to run its state
+machine and handle both its rx and tx path.
+
+Included Drivers
+----------------
+
+An HCI based driver for an NXP PN544, connected through I2C bus, and using
+shdlc is included.
+
+Execution Contexts
+------------------
+
+The execution contexts are the following:
+- IRQ handler (IRQH):
+fast, cannot sleep. stores incoming frames into an shdlc rx queue
+
+- SHDLC State Machine worker (SMW)
+handles shdlc rx & tx queues. Dispatches HCI cmd responses.
+
+- HCI Tx Cmd worker (MSGTXWQ)
+Serialize execution of HCI commands. Complete execution in case of resp timeout.
+
+- HCI Rx worker (MSGRXWQ)
+Dispatches incoming HCI commands or events.
+
+- Syscall context from a userspace call (SYSCALL)
+Any entrypoint in HCI called from NFC Core
+
+Workflow executing an HCI command (using shdlc)
+-----------------------------------------------
+
+Executing an HCI command can easily be performed synchronously using the
+following API:
+
+int nfc_hci_send_cmd (struct nfc_hci_dev *hdev, u8 gate, u8 cmd,
+                       const u8 *param, size_t param_len, struct sk_buff **skb)
+
+The API must be invoked from a context that can sleep. Most of the time, this
+will be the syscall context. skb will return the result that was received in
+the response.
+
+Internally, execution is asynchronous. So all this API does is to enqueue the
+HCI command, setup a local wait queue on stack, and wait_event() for completion.
+The wait is not interruptible because it is guaranteed that the command will
+complete after some short timeout anyway.
+
+MSGTXWQ context will then be scheduled and invoke nfc_hci_msg_tx_work().
+This function will dequeue the next pending command and send its HCP fragments
+to the lower layer which happens to be shdlc. It will then start a timer to be
+able to complete the command with a timeout error if no response arrive.
+
+SMW context gets scheduled and invokes nfc_shdlc_sm_work(). This function
+handles shdlc framing in and out. It uses the driver xmit to send frames and
+receives incoming frames in an skb queue filled from the driver IRQ handler.
+SHDLC I(nformation) frames payload are HCP fragments. They are agregated to
+form complete HCI frames, which can be a response, command, or event.
+
+HCI Responses are dispatched immediately from this context to unblock
+waiting command execution. Reponse processing involves invoking the completion
+callback that was provided by nfc_hci_msg_tx_work() when it sent the command.
+The completion callback will then wake the syscall context.
+
+Workflow receiving an HCI event or command
+------------------------------------------
+
+HCI commands or events are not dispatched from SMW context. Instead, they are
+queued to HCI rx_queue and will be dispatched from HCI rx worker
+context (MSGRXWQ). This is done this way to allow a cmd or event handler
+to also execute other commands (for example, handling the
+NFC_HCI_EVT_TARGET_DISCOVERED event from PN544 requires to issue an
+ANY_GET_PARAMETER to the reader A gate to get information on the target
+that was discovered).
+
+Typically, such an event will be propagated to NFC Core from MSGRXWQ context.
index f1b5694340f4ff655c774db5c66116ed3a1bb3b3..250f59cc9d3cc2484d63d63c015b710de63c0cc7 100644 (file)
@@ -6669,6 +6669,16 @@ L:       alsa-devel@alsa-project.org (moderated for non-subscribers)
 S:     Maintained
 F:     sound/soc/codecs/twl4030*
 
+TI WILINK WIRELESS DRIVERS
+M:     Luciano Coelho <coelho@ti.com>
+L:     linux-wireless@vger.kernel.org
+W:     http://wireless.kernel.org/en/users/Drivers/wl12xx
+W:     http://wireless.kernel.org/en/users/Drivers/wl1251
+T:     git git://git.kernel.org/pub/scm/linux/kernel/git/luca/wl12xx.git
+S:     Maintained
+F:     drivers/net/wireless/ti/
+F:     include/linux/wl12xx.h
+
 TIPC NETWORK LAYER
 M:     Jon Maloy <jon.maloy@ericsson.com>
 M:     Allan Stephens <allan.stephens@windriver.com>
@@ -7425,23 +7435,6 @@ M:       Miloslav Trmac <mitr@volny.cz>
 S:     Maintained
 F:     drivers/input/misc/wistron_btns.c
 
-WL1251 WIRELESS DRIVER
-M:     Luciano Coelho <coelho@ti.com>
-L:     linux-wireless@vger.kernel.org
-W:     http://wireless.kernel.org/en/users/Drivers/wl1251
-T:     git git://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless-testing.git
-S:     Maintained
-F:     drivers/net/wireless/wl1251/*
-
-WL1271 WIRELESS DRIVER
-M:     Luciano Coelho <coelho@ti.com>
-L:     linux-wireless@vger.kernel.org
-W:     http://wireless.kernel.org/en/users/Drivers/wl12xx
-T:     git git://git.kernel.org/pub/scm/linux/kernel/git/luca/wl12xx.git
-S:     Maintained
-F:     drivers/net/wireless/wl12xx/
-F:     include/linux/wl12xx.h
-
 WL3501 WIRELESS PCMCIA CARD DRIVER
 M:     Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
 L:     linux-wireless@vger.kernel.org
index abd3b71cd4abf8535ee33c1239a0c15ddf9a0f5f..5f58fa53238cc2496eb9658e6d83f87559b11d66 100644 (file)
@@ -282,8 +282,7 @@ source "drivers/net/wireless/orinoco/Kconfig"
 source "drivers/net/wireless/p54/Kconfig"
 source "drivers/net/wireless/rt2x00/Kconfig"
 source "drivers/net/wireless/rtlwifi/Kconfig"
-source "drivers/net/wireless/wl1251/Kconfig"
-source "drivers/net/wireless/wl12xx/Kconfig"
+source "drivers/net/wireless/ti/Kconfig"
 source "drivers/net/wireless/zd1211rw/Kconfig"
 source "drivers/net/wireless/mwifiex/Kconfig"
 
index 98db76196b59d448ae7d11ba33e46cc8f9339d74..0ce218b931d4091a7f377cbb7866c603b8ede36f 100644 (file)
@@ -51,9 +51,7 @@ obj-$(CONFIG_ATH_COMMON)      += ath/
 
 obj-$(CONFIG_MAC80211_HWSIM)   += mac80211_hwsim.o
 
-obj-$(CONFIG_WL1251)   += wl1251/
-obj-$(CONFIG_WL12XX)   += wl12xx/
-obj-$(CONFIG_WL12XX_PLATFORM_DATA)     += wl12xx/
+obj-$(CONFIG_WL_TI)    += ti/
 
 obj-$(CONFIG_IWM)      += iwmc3200wifi/
 
index f5ce5623da990db9941699cae0bbba8ec74d238d..0ac09a2bd144049091e19ad9a56240cf62b7e64c 100644 (file)
@@ -1991,19 +1991,4 @@ static struct pci_driver adm8211_driver = {
 #endif /* CONFIG_PM */
 };
 
-
-
-static int __init adm8211_init(void)
-{
-       return pci_register_driver(&adm8211_driver);
-}
-
-
-static void __exit adm8211_exit(void)
-{
-       pci_unregister_driver(&adm8211_driver);
-}
-
-
-module_init(adm8211_init);
-module_exit(adm8211_exit);
+module_pci_driver(adm8211_driver);
index 4045e5ab0555a3cbd2f55b1aa0e413a137f6f7f0..faa8bcb4aac1efe6bd9d62242176b71f4544a254 100644 (file)
@@ -2512,10 +2512,8 @@ static void __exit at76_mod_exit(void)
 
        printk(KERN_INFO DRIVER_DESC " " DRIVER_VERSION " unloading\n");
        usb_deregister(&at76_driver);
-       for (i = 0; i < ARRAY_SIZE(firmwares); i++) {
-               if (firmwares[i].fw)
-                       release_firmware(firmwares[i].fw);
-       }
+       for (i = 0; i < ARRAY_SIZE(firmwares); i++)
+               release_firmware(firmwares[i].fw);
        led_trigger_unregister_simple(ledtrig_tx);
 }
 
index 55ef93dd743847dd77f2b4c66fd78f07bd351a21..64a453a6dfe442d22c533435787df147b86101fe 100644 (file)
@@ -1527,7 +1527,7 @@ void ath5k_eeprom_detach(struct ath5k_hw *ah);
 
 /* Protocol Control Unit Functions */
 /* Helpers */
-int ath5k_hw_get_frame_duration(struct ath5k_hw *ah,
+int ath5k_hw_get_frame_duration(struct ath5k_hw *ah, enum ieee80211_band band,
                int len, struct ieee80211_rate *rate, bool shortpre);
 unsigned int ath5k_hw_get_default_slottime(struct ath5k_hw *ah);
 unsigned int ath5k_hw_get_default_sifs(struct ath5k_hw *ah);
index 3007bba12d9434cc21b25c6ca69c02b08ca22791..49e3b19cf781bbe123e8f7837ed1fe99ae97a2de 100644 (file)
@@ -1170,7 +1170,7 @@ ath5k_check_ibss_tsf(struct ath5k_hw *ah, struct sk_buff *skb,
 
        if (ieee80211_is_beacon(mgmt->frame_control) &&
            le16_to_cpu(mgmt->u.beacon.capab_info) & WLAN_CAPABILITY_IBSS &&
-           memcmp(mgmt->bssid, common->curbssid, ETH_ALEN) == 0) {
+           compare_ether_addr(mgmt->bssid, common->curbssid) == 0) {
                /*
                 * Received an IBSS beacon with the same BSSID. Hardware *must*
                 * have updated the local TSF. We have to work around various
@@ -1234,7 +1234,7 @@ ath5k_update_beacon_rssi(struct ath5k_hw *ah, struct sk_buff *skb, int rssi)
 
        /* only beacons from our BSSID */
        if (!ieee80211_is_beacon(mgmt->frame_control) ||
-           memcmp(mgmt->bssid, common->curbssid, ETH_ALEN) != 0)
+           compare_ether_addr(mgmt->bssid, common->curbssid) != 0)
                return;
 
        ewma_add(&ah->ah_beacon_rssi_avg, rssi);
index 53424e8e6d8275892345e96dde7577864e962f9e..dff48fbc63bfd1d7a4cc5aed6c2632c6128c77e9 100644 (file)
@@ -47,6 +47,7 @@ static DEFINE_PCI_DEVICE_TABLE(ath5k_pci_id_table) = {
        { PCI_VDEVICE(ATHEROS, 0x001b) }, /* 5413 Eagle */
        { PCI_VDEVICE(ATHEROS, 0x001c) }, /* PCI-E cards */
        { PCI_VDEVICE(ATHEROS, 0x001d) }, /* 2417 Nala */
+       { PCI_VDEVICE(ATHEROS, 0xff1b) }, /* AR5BXB63 */
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, ath5k_pci_id_table);
@@ -339,28 +340,4 @@ static struct pci_driver ath5k_pci_driver = {
        .driver.pm      = ATH5K_PM_OPS,
 };
 
-/*
- * Module init/exit functions
- */
-static int __init
-init_ath5k_pci(void)
-{
-       int ret;
-
-       ret = pci_register_driver(&ath5k_pci_driver);
-       if (ret) {
-               pr_err("pci: can't register pci driver\n");
-               return ret;
-       }
-
-       return 0;
-}
-
-static void __exit
-exit_ath5k_pci(void)
-{
-       pci_unregister_driver(&ath5k_pci_driver);
-}
-
-module_init(init_ath5k_pci);
-module_exit(exit_ath5k_pci);
+module_pci_driver(ath5k_pci_driver);
index cebfd6fd31d3a1212ed3568c3572dcc800e52e12..1f16b4227d8f0b1cfc11af7a2cafdda6169f9720 100644 (file)
@@ -110,7 +110,7 @@ static const unsigned int ack_rates_high[] =
  * bwmodes.
  */
 int
-ath5k_hw_get_frame_duration(struct ath5k_hw *ah,
+ath5k_hw_get_frame_duration(struct ath5k_hw *ah, enum ieee80211_band band,
                int len, struct ieee80211_rate *rate, bool shortpre)
 {
        int sifs, preamble, plcp_bits, sym_time;
@@ -120,7 +120,7 @@ ath5k_hw_get_frame_duration(struct ath5k_hw *ah,
        /* Fallback */
        if (!ah->ah_bwmode) {
                __le16 raw_dur = ieee80211_generic_frame_duration(ah->hw,
-                                       NULL, len, rate);
+                                       NULL, band, len, rate);
 
                /* subtract difference between long and short preamble */
                dur = le16_to_cpu(raw_dur);
@@ -302,14 +302,15 @@ ath5k_hw_write_rate_duration(struct ath5k_hw *ah)
                 * actual rate for this rate. See mac80211 tx.c
                 * ieee80211_duration() for a brief description of
                 * what rate we should choose to TX ACKs. */
-               tx_time = ath5k_hw_get_frame_duration(ah, 10, rate, false);
+               tx_time = ath5k_hw_get_frame_duration(ah, band, 10,
+                                       rate, false);
 
                ath5k_hw_reg_write(ah, tx_time, reg);
 
                if (!(rate->flags & IEEE80211_RATE_SHORT_PREAMBLE))
                        continue;
 
-               tx_time = ath5k_hw_get_frame_duration(ah, 10, rate, true);
+               tx_time = ath5k_hw_get_frame_duration(ah, band, 10, rate, true);
                ath5k_hw_reg_write(ah, tx_time,
                        reg + (AR5K_SET_SHORT_PREAMBLE << 2));
        }
index a6de200538c322f11b30b2063dcebc3ff8c7ba33..65fe929529a8f9b303858a329b7892d9f9c1cc27 100644 (file)
@@ -565,6 +565,7 @@ ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
 int ath5k_hw_set_ifs_intervals(struct ath5k_hw *ah, unsigned int slot_time)
 {
        struct ieee80211_channel *channel = ah->ah_current_channel;
+       enum ieee80211_band band;
        struct ieee80211_rate *rate;
        u32 ack_tx_time, eifs, eifs_clock, sifs, sifs_clock;
        u32 slot_time_clock = ath5k_hw_htoclock(ah, slot_time);
@@ -600,11 +601,12 @@ int ath5k_hw_set_ifs_intervals(struct ath5k_hw *ah, unsigned int slot_time)
         * Also we have different lowest rate for 802.11a
         */
        if (channel->band == IEEE80211_BAND_5GHZ)
-               rate = &ah->sbands[IEEE80211_BAND_5GHZ].bitrates[0];
+               band = IEEE80211_BAND_5GHZ;
        else
-               rate = &ah->sbands[IEEE80211_BAND_2GHZ].bitrates[0];
+               band = IEEE80211_BAND_2GHZ;
 
-       ack_tx_time = ath5k_hw_get_frame_duration(ah, 10, rate, false);
+       rate = &ah->sbands[band].bitrates[0];
+       ack_tx_time = ath5k_hw_get_frame_duration(ah, band, 10, rate, false);
 
        /* ack_tx_time includes an SIFS already */
        eifs = ack_tx_time + sifs + 2 * slot_time;
index 85746c3eb02788c9109b07bbfda905d98b5a1daf..8cae8886f17dc4eb667f107b49ef4af5c674369b 100644 (file)
@@ -25,7 +25,8 @@
 obj-$(CONFIG_ATH6KL) += ath6kl_core.o
 ath6kl_core-y += debug.o
 ath6kl_core-y += hif.o
-ath6kl_core-y += htc.o
+ath6kl_core-y += htc_mbox.o
+ath6kl_core-y += htc_pipe.o
 ath6kl_core-y += bmi.o
 ath6kl_core-y += cfg80211.o
 ath6kl_core-y += init.o
index bdcc68fb1e37b98a2f1edb14e0eba789491c4863..28a65d3a03d0df49af91e92668b8099c966e5191 100644 (file)
@@ -51,6 +51,8 @@
        .max_power      = 30,                       \
 }
 
+#define DEFAULT_BG_SCAN_PERIOD 60
+
 static struct ieee80211_rate ath6kl_rates[] = {
        RATETAB_ENT(10, 0x1, 0),
        RATETAB_ENT(20, 0x2, 0),
@@ -71,7 +73,8 @@ static struct ieee80211_rate ath6kl_rates[] = {
 #define ath6kl_g_rates     (ath6kl_rates + 0)
 #define ath6kl_g_rates_size    12
 
-#define ath6kl_g_htcap (IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \
+#define ath6kl_g_htcap IEEE80211_HT_CAP_SGI_20
+#define ath6kl_a_htcap (IEEE80211_HT_CAP_SUP_WIDTH_20_40 | \
                        IEEE80211_HT_CAP_SGI_20          | \
                        IEEE80211_HT_CAP_SGI_40)
 
@@ -128,7 +131,7 @@ static struct ieee80211_supported_band ath6kl_band_5ghz = {
        .channels = ath6kl_5ghz_a_channels,
        .n_bitrates = ath6kl_a_rates_size,
        .bitrates = ath6kl_a_rates,
-       .ht_cap.cap = ath6kl_g_htcap,
+       .ht_cap.cap = ath6kl_a_htcap,
        .ht_cap.ht_supported = true,
 };
 
@@ -609,6 +612,17 @@ static int ath6kl_cfg80211_connect(struct wiphy *wiphy, struct net_device *dev,
                                        vif->req_bssid, vif->ch_hint,
                                        ar->connect_ctrl_flags, nw_subtype);
 
+       /* disable background scan if period is 0 */
+       if (sme->bg_scan_period == 0)
+               sme->bg_scan_period = 0xffff;
+
+       /* configure default value if not specified */
+       if (sme->bg_scan_period == -1)
+               sme->bg_scan_period = DEFAULT_BG_SCAN_PERIOD;
+
+       ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx, 0, 0,
+                                 sme->bg_scan_period, 0, 0, 0, 3, 0, 0, 0);
+
        up(&ar->sem);
 
        if (status == -EINVAL) {
@@ -943,6 +957,8 @@ static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
        if (test_bit(CONNECTED, &vif->flags))
                force_fg_scan = 1;
 
+       vif->scan_req = request;
+
        if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
                     ar->fw_capabilities)) {
                /*
@@ -965,10 +981,10 @@ static int ath6kl_cfg80211_scan(struct wiphy *wiphy, struct net_device *ndev,
                                                ATH6KL_FG_SCAN_INTERVAL,
                                                n_channels, channels);
        }
-       if (ret)
+       if (ret) {
                ath6kl_err("wmi_startscan_cmd failed\n");
-       else
-               vif->scan_req = request;
+               vif->scan_req = NULL;
+       }
 
        kfree(channels);
 
@@ -1438,9 +1454,38 @@ static int ath6kl_cfg80211_change_iface(struct wiphy *wiphy,
                                        struct vif_params *params)
 {
        struct ath6kl_vif *vif = netdev_priv(ndev);
+       int i;
 
        ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: type %u\n", __func__, type);
 
+       /*
+        * Don't bring up p2p on an interface which is not initialized
+        * for p2p operation where fw does not have capability to switch
+        * dynamically between non-p2p and p2p type interface.
+        */
+       if (!test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
+                     vif->ar->fw_capabilities) &&
+           (type == NL80211_IFTYPE_P2P_CLIENT ||
+            type == NL80211_IFTYPE_P2P_GO)) {
+               if (vif->ar->vif_max == 1) {
+                       if (vif->fw_vif_idx != 0)
+                               return -EINVAL;
+                       else
+                               goto set_iface_type;
+               }
+
+               for (i = vif->ar->max_norm_iface; i < vif->ar->vif_max; i++) {
+                       if (i == vif->fw_vif_idx)
+                               break;
+               }
+
+               if (i == vif->ar->vif_max) {
+                       ath6kl_err("Invalid interface to bring up P2P\n");
+                       return -EINVAL;
+               }
+       }
+
+set_iface_type:
        switch (type) {
        case NL80211_IFTYPE_STATION:
                vif->next_mode = INFRA_NETWORK;
@@ -1926,12 +1971,61 @@ static int ath6kl_wow_sta(struct ath6kl *ar, struct ath6kl_vif *vif)
        return 0;
 }
 
+static int is_hsleep_mode_procsed(struct ath6kl_vif *vif)
+{
+       return test_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
+}
+
+static bool is_ctrl_ep_empty(struct ath6kl *ar)
+{
+       return !ar->tx_pending[ar->ctrl_ep];
+}
+
+static int ath6kl_cfg80211_host_sleep(struct ath6kl *ar, struct ath6kl_vif *vif)
+{
+       int ret, left;
+
+       clear_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
+
+       ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
+                                                ATH6KL_HOST_MODE_ASLEEP);
+       if (ret)
+               return ret;
+
+       left = wait_event_interruptible_timeout(ar->event_wq,
+                                               is_hsleep_mode_procsed(vif),
+                                               WMI_TIMEOUT);
+       if (left == 0) {
+               ath6kl_warn("timeout, didn't get host sleep cmd processed event\n");
+               ret = -ETIMEDOUT;
+       } else if (left < 0) {
+               ath6kl_warn("error while waiting for host sleep cmd processed event %d\n",
+                           left);
+               ret = left;
+       }
+
+       if (ar->tx_pending[ar->ctrl_ep]) {
+               left = wait_event_interruptible_timeout(ar->event_wq,
+                                                       is_ctrl_ep_empty(ar),
+                                                       WMI_TIMEOUT);
+               if (left == 0) {
+                       ath6kl_warn("clear wmi ctrl data timeout\n");
+                       ret = -ETIMEDOUT;
+               } else if (left < 0) {
+                       ath6kl_warn("clear wmi ctrl data failed: %d\n", left);
+                       ret = left;
+               }
+       }
+
+       return ret;
+}
+
 static int ath6kl_wow_suspend(struct ath6kl *ar, struct cfg80211_wowlan *wow)
 {
        struct in_device *in_dev;
        struct in_ifaddr *ifa;
        struct ath6kl_vif *vif;
-       int ret, left;
+       int ret;
        u32 filter = 0;
        u16 i, bmiss_time;
        u8 index = 0;
@@ -2032,39 +2126,11 @@ skip_arp:
        if (ret)
                return ret;
 
-       clear_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
-
-       ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
-                                                ATH6KL_HOST_MODE_ASLEEP);
+       ret = ath6kl_cfg80211_host_sleep(ar, vif);
        if (ret)
                return ret;
 
-       left = wait_event_interruptible_timeout(ar->event_wq,
-                       test_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags),
-                       WMI_TIMEOUT);
-       if (left == 0) {
-               ath6kl_warn("timeout, didn't get host sleep cmd "
-                           "processed event\n");
-               ret = -ETIMEDOUT;
-       } else if (left < 0) {
-               ath6kl_warn("error while waiting for host sleep cmd "
-                           "processed event %d\n", left);
-               ret = left;
-       }
-
-       if (ar->tx_pending[ar->ctrl_ep]) {
-               left = wait_event_interruptible_timeout(ar->event_wq,
-                               ar->tx_pending[ar->ctrl_ep] == 0, WMI_TIMEOUT);
-               if (left == 0) {
-                       ath6kl_warn("clear wmi ctrl data timeout\n");
-                       ret = -ETIMEDOUT;
-               } else if (left < 0) {
-                       ath6kl_warn("clear wmi ctrl data failed: %d\n", left);
-                       ret = left;
-               }
-       }
-
-       return ret;
+       return 0;
 }
 
 static int ath6kl_wow_resume(struct ath6kl *ar)
@@ -2111,10 +2177,82 @@ static int ath6kl_wow_resume(struct ath6kl *ar)
        return 0;
 }
 
+static int ath6kl_cfg80211_deepsleep_suspend(struct ath6kl *ar)
+{
+       struct ath6kl_vif *vif;
+       int ret;
+
+       vif = ath6kl_vif_first(ar);
+       if (!vif)
+               return -EIO;
+
+       if (!ath6kl_cfg80211_ready(vif))
+               return -EIO;
+
+       ath6kl_cfg80211_stop_all(ar);
+
+       /* Save the current power mode before enabling power save */
+       ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
+
+       ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER);
+       if (ret)
+               return ret;
+
+       /* Disable WOW mode */
+       ret = ath6kl_wmi_set_wow_mode_cmd(ar->wmi, vif->fw_vif_idx,
+                                         ATH6KL_WOW_MODE_DISABLE,
+                                         0, 0);
+       if (ret)
+               return ret;
+
+       /* Flush all non control pkts in TX path */
+       ath6kl_tx_data_cleanup(ar);
+
+       ret = ath6kl_cfg80211_host_sleep(ar, vif);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
+static int ath6kl_cfg80211_deepsleep_resume(struct ath6kl *ar)
+{
+       struct ath6kl_vif *vif;
+       int ret;
+
+       vif = ath6kl_vif_first(ar);
+
+       if (!vif)
+               return -EIO;
+
+       if (ar->wmi->pwr_mode != ar->wmi->saved_pwr_mode) {
+               ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0,
+                                              ar->wmi->saved_pwr_mode);
+               if (ret)
+                       return ret;
+       }
+
+       ret = ath6kl_wmi_set_host_sleep_mode_cmd(ar->wmi, vif->fw_vif_idx,
+                                                ATH6KL_HOST_MODE_AWAKE);
+       if (ret)
+               return ret;
+
+       ar->state = ATH6KL_STATE_ON;
+
+       /* Reset scan parameter to default values */
+       ret = ath6kl_wmi_scanparams_cmd(ar->wmi, vif->fw_vif_idx,
+                                       0, 0, 0, 0, 0, 0, 3, 0, 0, 0);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
 int ath6kl_cfg80211_suspend(struct ath6kl *ar,
                            enum ath6kl_cfg_suspend_mode mode,
                            struct cfg80211_wowlan *wow)
 {
+       struct ath6kl_vif *vif;
        enum ath6kl_state prev_state;
        int ret;
 
@@ -2139,15 +2277,12 @@ int ath6kl_cfg80211_suspend(struct ath6kl *ar,
 
        case ATH6KL_CFG_SUSPEND_DEEPSLEEP:
 
-               ath6kl_cfg80211_stop_all(ar);
-
-               /* save the current power mode before enabling power save */
-               ar->wmi->saved_pwr_mode = ar->wmi->pwr_mode;
+               ath6kl_dbg(ATH6KL_DBG_SUSPEND, "deep sleep suspend\n");
 
-               ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0, REC_POWER);
+               ret = ath6kl_cfg80211_deepsleep_suspend(ar);
                if (ret) {
-                       ath6kl_warn("wmi powermode command failed during suspend: %d\n",
-                                   ret);
+                       ath6kl_err("deepsleep suspend failed: %d\n", ret);
+                       return ret;
                }
 
                ar->state = ATH6KL_STATE_DEEPSLEEP;
@@ -2187,6 +2322,9 @@ int ath6kl_cfg80211_suspend(struct ath6kl *ar,
                break;
        }
 
+       list_for_each_entry(vif, &ar->vif_list, list)
+               ath6kl_cfg80211_scan_complete_event(vif, true);
+
        return 0;
 }
 EXPORT_SYMBOL(ath6kl_cfg80211_suspend);
@@ -2208,17 +2346,13 @@ int ath6kl_cfg80211_resume(struct ath6kl *ar)
                break;
 
        case ATH6KL_STATE_DEEPSLEEP:
-               if (ar->wmi->pwr_mode != ar->wmi->saved_pwr_mode) {
-                       ret = ath6kl_wmi_powermode_cmd(ar->wmi, 0,
-                                                      ar->wmi->saved_pwr_mode);
-                       if (ret) {
-                               ath6kl_warn("wmi powermode command failed during resume: %d\n",
-                                           ret);
-                       }
-               }
-
-               ar->state = ATH6KL_STATE_ON;
+               ath6kl_dbg(ATH6KL_DBG_SUSPEND, "deep sleep resume\n");
 
+               ret = ath6kl_cfg80211_deepsleep_resume(ar);
+               if (ret) {
+                       ath6kl_warn("deep sleep resume failed: %d\n", ret);
+                       return ret;
+               }
                break;
 
        case ATH6KL_STATE_CUTPOWER:
@@ -2292,31 +2426,25 @@ void ath6kl_check_wow_status(struct ath6kl *ar)
 }
 #endif
 
-static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
-                             struct ieee80211_channel *chan,
-                             enum nl80211_channel_type channel_type)
+static int ath6kl_set_htcap(struct ath6kl_vif *vif, enum ieee80211_band band,
+                           bool ht_enable)
 {
-       struct ath6kl_vif *vif;
-
-       /*
-        * 'dev' could be NULL if a channel change is required for the hardware
-        * device itself, instead of a particular VIF.
-        *
-        * FIXME: To be handled properly when monitor mode is supported.
-        */
-       if (!dev)
-               return -EBUSY;
-
-       vif = netdev_priv(dev);
+       struct ath6kl_htcap *htcap = &vif->htcap;
 
-       if (!ath6kl_cfg80211_ready(vif))
-               return -EIO;
+       if (htcap->ht_enable == ht_enable)
+               return 0;
 
-       ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
-                  __func__, chan->center_freq, chan->hw_value);
-       vif->next_chan = chan->center_freq;
+       if (ht_enable) {
+               /* Set default ht capabilities */
+               htcap->ht_enable = true;
+               htcap->cap_info = (band == IEEE80211_BAND_2GHZ) ?
+                                  ath6kl_g_htcap : ath6kl_a_htcap;
+               htcap->ampdu_factor = IEEE80211_HT_MAX_AMPDU_16K;
+       } else /* Disable ht */
+               memset(htcap, 0, sizeof(*htcap));
 
-       return 0;
+       return ath6kl_wmi_set_htcap_cmd(vif->ar->wmi, vif->fw_vif_idx,
+                                       band, htcap);
 }
 
 static bool ath6kl_is_p2p_ie(const u8 *pos)
@@ -2393,6 +2521,81 @@ static int ath6kl_set_ies(struct ath6kl_vif *vif,
        return 0;
 }
 
+static int ath6kl_set_channel(struct wiphy *wiphy, struct net_device *dev,
+                             struct ieee80211_channel *chan,
+                             enum nl80211_channel_type channel_type)
+{
+       struct ath6kl_vif *vif;
+
+       /*
+        * 'dev' could be NULL if a channel change is required for the hardware
+        * device itself, instead of a particular VIF.
+        *
+        * FIXME: To be handled properly when monitor mode is supported.
+        */
+       if (!dev)
+               return -EBUSY;
+
+       vif = netdev_priv(dev);
+
+       if (!ath6kl_cfg80211_ready(vif))
+               return -EIO;
+
+       ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s: center_freq=%u hw_value=%u\n",
+                  __func__, chan->center_freq, chan->hw_value);
+       vif->next_chan = chan->center_freq;
+       vif->next_ch_type = channel_type;
+       vif->next_ch_band = chan->band;
+
+       return 0;
+}
+
+static int ath6kl_get_rsn_capab(struct cfg80211_beacon_data *beacon,
+                               u8 *rsn_capab)
+{
+       const u8 *rsn_ie;
+       size_t rsn_ie_len;
+       u16 cnt;
+
+       if (!beacon->tail)
+               return -EINVAL;
+
+       rsn_ie = cfg80211_find_ie(WLAN_EID_RSN, beacon->tail, beacon->tail_len);
+       if (!rsn_ie)
+               return -EINVAL;
+
+       rsn_ie_len = *(rsn_ie + 1);
+       /* skip element id and length */
+       rsn_ie += 2;
+
+       /* skip version, group cipher */
+       if (rsn_ie_len < 6)
+               return -EINVAL;
+       rsn_ie +=  6;
+       rsn_ie_len -= 6;
+
+       /* skip pairwise cipher suite */
+       if (rsn_ie_len < 2)
+               return -EINVAL;
+       cnt = *((u16 *) rsn_ie);
+       rsn_ie += (2 + cnt * 4);
+       rsn_ie_len -= (2 + cnt * 4);
+
+       /* skip akm suite */
+       if (rsn_ie_len < 2)
+               return -EINVAL;
+       cnt = *((u16 *) rsn_ie);
+       rsn_ie += (2 + cnt * 4);
+       rsn_ie_len -= (2 + cnt * 4);
+
+       if (rsn_ie_len < 2)
+               return -EINVAL;
+
+       memcpy(rsn_capab, rsn_ie, 2);
+
+       return 0;
+}
+
 static int ath6kl_start_ap(struct wiphy *wiphy, struct net_device *dev,
                           struct cfg80211_ap_settings *info)
 {
@@ -2405,6 +2608,7 @@ static int ath6kl_start_ap(struct wiphy *wiphy, struct net_device *dev,
        struct wmi_connect_cmd p;
        int res;
        int i, ret;
+       u16 rsn_capab = 0;
 
        ath6kl_dbg(ATH6KL_DBG_WLAN_CFG, "%s:\n", __func__);
 
@@ -2534,6 +2738,34 @@ static int ath6kl_start_ap(struct wiphy *wiphy, struct net_device *dev,
                p.nw_subtype = SUBTYPE_NONE;
        }
 
+       if (info->inactivity_timeout) {
+               res = ath6kl_wmi_set_inact_period(ar->wmi, vif->fw_vif_idx,
+                                                 info->inactivity_timeout);
+               if (res < 0)
+                       return res;
+       }
+
+       if (ath6kl_set_htcap(vif, vif->next_ch_band,
+                            vif->next_ch_type != NL80211_CHAN_NO_HT))
+               return -EIO;
+
+       /*
+        * Get the PTKSA replay counter in the RSN IE. Supplicant
+        * will use the RSN IE in M3 message and firmware has to
+        * advertise the same in beacon/probe response. Send
+        * the complete RSN IE capability field to firmware
+        */
+       if (!ath6kl_get_rsn_capab(&info->beacon, (u8 *) &rsn_capab) &&
+           test_bit(ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE,
+                    ar->fw_capabilities)) {
+               res = ath6kl_wmi_set_ie_cmd(ar->wmi, vif->fw_vif_idx,
+                                           WLAN_EID_RSN, WMI_RSN_IE_CAPB,
+                                           (const u8 *) &rsn_capab,
+                                           sizeof(rsn_capab));
+               if (res < 0)
+                       return res;
+       }
+
        res = ath6kl_wmi_ap_profile_commit(ar->wmi, vif->fw_vif_idx, &p);
        if (res < 0)
                return res;
@@ -2568,6 +2800,13 @@ static int ath6kl_stop_ap(struct wiphy *wiphy, struct net_device *dev)
        ath6kl_wmi_disconnect_cmd(ar->wmi, vif->fw_vif_idx);
        clear_bit(CONNECTED, &vif->flags);
 
+       /* Restore ht setting in firmware */
+       if (ath6kl_set_htcap(vif, IEEE80211_BAND_2GHZ, true))
+               return -EIO;
+
+       if (ath6kl_set_htcap(vif, IEEE80211_BAND_5GHZ, true))
+               return -EIO;
+
        return 0;
 }
 
@@ -2749,6 +2988,21 @@ static bool ath6kl_mgmt_powersave_ap(struct ath6kl_vif *vif,
        return false;
 }
 
+/* Check if SSID length is greater than DIRECT- */
+static bool ath6kl_is_p2p_go_ssid(const u8 *buf, size_t len)
+{
+       const struct ieee80211_mgmt *mgmt;
+       mgmt = (const struct ieee80211_mgmt *) buf;
+
+       /* variable[1] contains the SSID tag length */
+       if (buf + len >= &mgmt->u.probe_resp.variable[1] &&
+           (mgmt->u.probe_resp.variable[1] > P2P_WILDCARD_SSID_LEN)) {
+               return true;
+       }
+
+       return false;
+}
+
 static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
                          struct ieee80211_channel *chan, bool offchan,
                          enum nl80211_channel_type channel_type,
@@ -2763,11 +3017,11 @@ static int ath6kl_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
        bool more_data, queued;
 
        mgmt = (const struct ieee80211_mgmt *) buf;
-       if (buf + len >= mgmt->u.probe_resp.variable &&
-           vif->nw_type == AP_NETWORK && test_bit(CONNECTED, &vif->flags) &&
-           ieee80211_is_probe_resp(mgmt->frame_control)) {
+       if (vif->nw_type == AP_NETWORK && test_bit(CONNECTED, &vif->flags) &&
+           ieee80211_is_probe_resp(mgmt->frame_control) &&
+           ath6kl_is_p2p_go_ssid(buf, len)) {
                /*
-                * Send Probe Response frame in AP mode using a separate WMI
+                * Send Probe Response frame in GO mode using a separate WMI
                 * command to allow the target to fill in the generic IEs.
                 */
                *cookie = 0; /* TX status not supported */
@@ -2835,6 +3089,8 @@ static int ath6kl_cfg80211_sscan_start(struct wiphy *wiphy,
        if (vif->sme_state != SME_DISCONNECTED)
                return -EBUSY;
 
+       ath6kl_cfg80211_scan_complete_event(vif, true);
+
        for (i = 0; i < ar->wiphy->max_sched_scan_ssids; i++) {
                ath6kl_wmi_probedssid_cmd(ar->wmi, vif->fw_vif_idx,
                                          i, DISABLE_SSID_FLAG,
@@ -3096,6 +3352,7 @@ struct net_device *ath6kl_interface_add(struct ath6kl *ar, char *name,
        vif->next_mode = nw_type;
        vif->listen_intvl_t = ATH6KL_DEFAULT_LISTEN_INTVAL;
        vif->bmiss_time_t = ATH6KL_DEFAULT_BMISS_TIME;
+       vif->htcap.ht_enable = true;
 
        memcpy(ndev->dev_addr, ar->mac_addr, ETH_ALEN);
        if (fw_vif_idx != 0)
@@ -3183,6 +3440,10 @@ int ath6kl_cfg80211_init(struct ath6kl *ar)
        if (test_bit(ATH6KL_FW_CAPABILITY_SCHED_SCAN, ar->fw_capabilities))
                ar->wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
 
+       if (test_bit(ATH6KL_FW_CAPABILITY_INACTIVITY_TIMEOUT,
+                    ar->fw_capabilities))
+               ar->wiphy->features = NL80211_FEATURE_INACTIVITY_TIMER;
+
        ar->wiphy->probe_resp_offload =
                NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
                NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
index a60e78c0472ff0287714b8e114edb4c0d4fb0a3d..98a886154d9cc59775eaa0c17c74305452e52e8e 100644 (file)
@@ -22,7 +22,8 @@
 
 #define ATH6KL_MAX_IE                  256
 
-extern int ath6kl_printk(const char *level, const char *fmt, ...);
+extern __printf(2, 3)
+int ath6kl_printk(const char *level, const char *fmt, ...);
 
 /*
  * Reflects the version of binary interface exposed by ATH6KL target
@@ -77,6 +78,7 @@ enum crypto_type {
 
 struct htc_endpoint_credit_dist;
 struct ath6kl;
+struct ath6kl_htcap;
 enum htc_credit_dist_reason;
 struct ath6kl_htc_credit_info;
 
index 45e641f3a41bb5d0630f41474cf57c2874efa932..fdb3b1decc76716c4c4f41004bb4f7a7bf3bfcc1 100644 (file)
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/export.h>
+#include <linux/vmalloc.h>
 
 #include "debug.h"
 #include "hif-ops.h"
+#include "htc-ops.h"
 #include "cfg80211.h"
 
 unsigned int debug_mask;
@@ -39,12 +41,36 @@ module_param(uart_debug, uint, 0644);
 module_param(ath6kl_p2p, uint, 0644);
 module_param(testmode, uint, 0644);
 
-int ath6kl_core_init(struct ath6kl *ar)
+void ath6kl_core_tx_complete(struct ath6kl *ar, struct sk_buff *skb)
+{
+       ath6kl_htc_tx_complete(ar, skb);
+}
+EXPORT_SYMBOL(ath6kl_core_tx_complete);
+
+void ath6kl_core_rx_complete(struct ath6kl *ar, struct sk_buff *skb, u8 pipe)
+{
+       ath6kl_htc_rx_complete(ar, skb, pipe);
+}
+EXPORT_SYMBOL(ath6kl_core_rx_complete);
+
+int ath6kl_core_init(struct ath6kl *ar, enum ath6kl_htc_type htc_type)
 {
        struct ath6kl_bmi_target_info targ_info;
        struct net_device *ndev;
        int ret = 0, i;
 
+       switch (htc_type) {
+       case ATH6KL_HTC_TYPE_MBOX:
+               ath6kl_htc_mbox_attach(ar);
+               break;
+       case ATH6KL_HTC_TYPE_PIPE:
+               ath6kl_htc_pipe_attach(ar);
+               break;
+       default:
+               WARN_ON(1);
+               return -ENOMEM;
+       }
+
        ar->ath6kl_wq = create_singlethread_workqueue("ath6kl");
        if (!ar->ath6kl_wq)
                return -ENOMEM;
@@ -280,7 +306,7 @@ void ath6kl_core_cleanup(struct ath6kl *ar)
 
        kfree(ar->fw_board);
        kfree(ar->fw_otp);
-       kfree(ar->fw);
+       vfree(ar->fw);
        kfree(ar->fw_patch);
        kfree(ar->fw_testscript);
 
index f1dd8906be45df680c9743c626010aa37cd1f72d..9d67964a51ddde14fc231076b9c122554479f49b 100644 (file)
@@ -91,6 +91,15 @@ enum ath6kl_fw_capability {
         */
        ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
 
+       /*
+        * Firmware has support to cleanup inactive stations
+        * in AP mode.
+        */
+       ATH6KL_FW_CAPABILITY_INACTIVITY_TIMEOUT,
+
+       /* Firmware has support to override rsn cap of rsn ie */
+       ATH6KL_FW_CAPABILITY_RSN_CAP_OVERRIDE,
+
        /* this needs to be last */
        ATH6KL_FW_CAPABILITY_MAX,
 };
@@ -205,6 +214,8 @@ struct ath6kl_fw_ie {
 #define ATH6KL_CONF_ENABLE_TX_BURST            BIT(3)
 #define ATH6KL_CONF_UART_DEBUG                 BIT(4)
 
+#define P2P_WILDCARD_SSID_LEN                  7 /* DIRECT- */
+
 enum wlan_low_pwr_state {
        WLAN_POWER_STATE_ON,
        WLAN_POWER_STATE_CUT_PWR,
@@ -454,6 +465,11 @@ enum ath6kl_hif_type {
        ATH6KL_HIF_TYPE_USB,
 };
 
+enum ath6kl_htc_type {
+       ATH6KL_HTC_TYPE_MBOX,
+       ATH6KL_HTC_TYPE_PIPE,
+};
+
 /* Max number of filters that hw supports */
 #define ATH6K_MAX_MC_FILTERS_PER_LIST 7
 struct ath6kl_mc_filter {
@@ -461,6 +477,12 @@ struct ath6kl_mc_filter {
        char hw_addr[ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE];
 };
 
+struct ath6kl_htcap {
+       bool ht_enable;
+       u8 ampdu_factor;
+       unsigned short cap_info;
+};
+
 /*
  * Driver's maximum limit, note that some firmwares support only one vif
  * and the runtime (current) limit must be checked from ar->vif_max.
@@ -509,6 +531,7 @@ struct ath6kl_vif {
        struct ath6kl_wep_key wep_key_list[WMI_MAX_KEY_INDEX + 1];
        struct ath6kl_key keys[WMI_MAX_KEY_INDEX + 1];
        struct aggr_info *aggr_cntxt;
+       struct ath6kl_htcap htcap;
 
        struct timer_list disconnect_timer;
        struct timer_list sched_scan_timer;
@@ -521,6 +544,8 @@ struct ath6kl_vif {
        u32 send_action_id;
        bool probe_req_report;
        u16 next_chan;
+       enum nl80211_channel_type next_ch_type;
+       enum ieee80211_band next_ch_band;
        u16 assoc_bss_beacon_int;
        u16 listen_intvl_t;
        u16 bmiss_time_t;
@@ -568,6 +593,7 @@ struct ath6kl {
 
        struct ath6kl_bmi bmi;
        const struct ath6kl_hif_ops *hif_ops;
+       const struct ath6kl_htc_ops *htc_ops;
        struct wmi *wmi;
        int tx_pending[ENDPOINT_MAX];
        int total_tx_data_pend;
@@ -746,7 +772,8 @@ void init_netdev(struct net_device *dev);
 void ath6kl_cookie_init(struct ath6kl *ar);
 void ath6kl_cookie_cleanup(struct ath6kl *ar);
 void ath6kl_rx(struct htc_target *target, struct htc_packet *packet);
-void ath6kl_tx_complete(void *context, struct list_head *packet_queue);
+void ath6kl_tx_complete(struct htc_target *context,
+                       struct list_head *packet_queue);
 enum htc_send_full_action ath6kl_tx_queue_full(struct htc_target *target,
                                               struct htc_packet *packet);
 void ath6kl_stop_txrx(struct ath6kl *ar);
@@ -821,8 +848,11 @@ int ath6kl_init_hw_params(struct ath6kl *ar);
 
 void ath6kl_check_wow_status(struct ath6kl *ar);
 
+void ath6kl_core_tx_complete(struct ath6kl *ar, struct sk_buff *skb);
+void ath6kl_core_rx_complete(struct ath6kl *ar, struct sk_buff *skb, u8 pipe);
+
 struct ath6kl *ath6kl_core_create(struct device *dev);
-int ath6kl_core_init(struct ath6kl *ar);
+int ath6kl_core_init(struct ath6kl *ar, enum ath6kl_htc_type htc_type);
 void ath6kl_core_cleanup(struct ath6kl *ar);
 void ath6kl_core_destroy(struct ath6kl *ar);
 
index d01403a263ff66b935e70fcc04f23d2f971b0a10..1b76aff7850834a4be33f284c76395e21334e7f4 100644 (file)
@@ -616,6 +616,12 @@ static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
                         "Num disconnects", tgt_stats->cs_discon_cnt);
        len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
                         "Beacon avg rssi", tgt_stats->cs_ave_beacon_rssi);
+       len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
+                        "ARP pkt received", tgt_stats->arp_received);
+       len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
+                        "ARP pkt matched", tgt_stats->arp_matched);
+       len += scnprintf(buf + len, buf_len - len, "%20s %10d\n",
+                        "ARP pkt replied", tgt_stats->arp_replied);
 
        if (len > buf_len)
                len = buf_len;
index 1803a0baae823d676c56a7ec629d1e8bd52dcf2a..49639d8266c28a25a186cfe148c70a5ef0c3535f 100644 (file)
@@ -43,6 +43,7 @@ enum ATH6K_DEBUG_MASK {
        ATH6KL_DBG_WMI_DUMP     = BIT(19),
        ATH6KL_DBG_SUSPEND      = BIT(20),
        ATH6KL_DBG_USB          = BIT(21),
+       ATH6KL_DBG_USB_BULK     = BIT(22),
        ATH6KL_DBG_ANY          = 0xffffffff  /* enable all logs */
 };
 
index fd84086638e35163e990b74dad6ec8cbb355208e..8c9e72d5250d9a2d012f8885de0451a780ca2b63 100644 (file)
@@ -150,4 +150,38 @@ static inline void ath6kl_hif_stop(struct ath6kl *ar)
        ar->hif_ops->stop(ar);
 }
 
+static inline int ath6kl_hif_pipe_send(struct ath6kl *ar,
+                                      u8 pipe, struct sk_buff *hdr_buf,
+                                      struct sk_buff *buf)
+{
+       ath6kl_dbg(ATH6KL_DBG_HIF, "hif pipe send\n");
+
+       return ar->hif_ops->pipe_send(ar, pipe, hdr_buf, buf);
+}
+
+static inline void ath6kl_hif_pipe_get_default(struct ath6kl *ar,
+                                              u8 *ul_pipe, u8 *dl_pipe)
+{
+       ath6kl_dbg(ATH6KL_DBG_HIF, "hif pipe get default\n");
+
+       ar->hif_ops->pipe_get_default(ar, ul_pipe, dl_pipe);
+}
+
+static inline int ath6kl_hif_pipe_map_service(struct ath6kl *ar,
+                                             u16 service_id, u8 *ul_pipe,
+                                             u8 *dl_pipe)
+{
+       ath6kl_dbg(ATH6KL_DBG_HIF, "hif pipe get default\n");
+
+       return ar->hif_ops->pipe_map_service(ar, service_id, ul_pipe, dl_pipe);
+}
+
+static inline u16 ath6kl_hif_pipe_get_free_queue_number(struct ath6kl *ar,
+                                                       u8 pipe)
+{
+       ath6kl_dbg(ATH6KL_DBG_HIF, "hif pipe get free queue number\n");
+
+       return ar->hif_ops->pipe_get_free_queue_number(ar, pipe);
+}
+
 #endif
index 20ed6b73517be7cf2760db6bc992b95f751edd56..61f6b21fb0aeeaa4e6ef20dfca3baddf6ad638cd 100644 (file)
@@ -256,6 +256,12 @@ struct ath6kl_hif_ops {
        int (*power_on)(struct ath6kl *ar);
        int (*power_off)(struct ath6kl *ar);
        void (*stop)(struct ath6kl *ar);
+       int (*pipe_send)(struct ath6kl *ar, u8 pipe, struct sk_buff *hdr_buf,
+                        struct sk_buff *buf);
+       void (*pipe_get_default)(struct ath6kl *ar, u8 *pipe_ul, u8 *pipe_dl);
+       int (*pipe_map_service)(struct ath6kl *ar, u16 service_id, u8 *pipe_ul,
+                               u8 *pipe_dl);
+       u16 (*pipe_get_free_queue_number)(struct ath6kl *ar, u8 pipe);
 };
 
 int ath6kl_hif_setup(struct ath6kl_device *dev);
diff --git a/drivers/net/wireless/ath/ath6kl/htc-ops.h b/drivers/net/wireless/ath/ath6kl/htc-ops.h
new file mode 100644 (file)
index 0000000..2d4eed5
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2004-2011 Atheros Communications Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef HTC_OPS_H
+#define HTC_OPS_H
+
+#include "htc.h"
+#include "debug.h"
+
+static inline void *ath6kl_htc_create(struct ath6kl *ar)
+{
+       return ar->htc_ops->create(ar);
+}
+
+static inline int ath6kl_htc_wait_target(struct htc_target *target)
+{
+       return target->dev->ar->htc_ops->wait_target(target);
+}
+
+static inline int ath6kl_htc_start(struct htc_target *target)
+{
+       return target->dev->ar->htc_ops->start(target);
+}
+
+static inline int ath6kl_htc_conn_service(struct htc_target *target,
+                                         struct htc_service_connect_req *req,
+                                         struct htc_service_connect_resp *resp)
+{
+       return target->dev->ar->htc_ops->conn_service(target, req, resp);
+}
+
+static inline int ath6kl_htc_tx(struct htc_target *target,
+                               struct htc_packet *packet)
+{
+       return target->dev->ar->htc_ops->tx(target, packet);
+}
+
+static inline void ath6kl_htc_stop(struct htc_target *target)
+{
+       return target->dev->ar->htc_ops->stop(target);
+}
+
+static inline void ath6kl_htc_cleanup(struct htc_target *target)
+{
+       return target->dev->ar->htc_ops->cleanup(target);
+}
+
+static inline void ath6kl_htc_flush_txep(struct htc_target *target,
+                                        enum htc_endpoint_id endpoint,
+                                        u16 tag)
+{
+       return target->dev->ar->htc_ops->flush_txep(target, endpoint, tag);
+}
+
+static inline void ath6kl_htc_flush_rx_buf(struct htc_target *target)
+{
+       return target->dev->ar->htc_ops->flush_rx_buf(target);
+}
+
+static inline void ath6kl_htc_activity_changed(struct htc_target *target,
+                                              enum htc_endpoint_id endpoint,
+                                              bool active)
+{
+       return target->dev->ar->htc_ops->activity_changed(target, endpoint,
+                                                         active);
+}
+
+static inline int ath6kl_htc_get_rxbuf_num(struct htc_target *target,
+                                          enum htc_endpoint_id endpoint)
+{
+       return target->dev->ar->htc_ops->get_rxbuf_num(target, endpoint);
+}
+
+static inline int ath6kl_htc_add_rxbuf_multiple(struct htc_target *target,
+                                               struct list_head *pktq)
+{
+       return target->dev->ar->htc_ops->add_rxbuf_multiple(target, pktq);
+}
+
+static inline int ath6kl_htc_credit_setup(struct htc_target *target,
+                                         struct ath6kl_htc_credit_info *info)
+{
+       return target->dev->ar->htc_ops->credit_setup(target, info);
+}
+
+static inline void ath6kl_htc_tx_complete(struct ath6kl *ar,
+                                         struct sk_buff *skb)
+{
+       ar->htc_ops->tx_complete(ar, skb);
+}
+
+
+static inline void ath6kl_htc_rx_complete(struct ath6kl *ar,
+                                         struct sk_buff *skb, u8 pipe)
+{
+       ar->htc_ops->rx_complete(ar, skb, pipe);
+}
+
+
+#endif
diff --git a/drivers/net/wireless/ath/ath6kl/htc.c b/drivers/net/wireless/ath/ath6kl/htc.c
deleted file mode 100644 (file)
index 4849d99..0000000
+++ /dev/null
@@ -1,2890 +0,0 @@
-/*
- * Copyright (c) 2007-2011 Atheros Communications Inc.
- * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include "core.h"
-#include "hif.h"
-#include "debug.h"
-#include "hif-ops.h"
-#include <asm/unaligned.h>
-
-#define CALC_TXRX_PADDED_LEN(dev, len)  (__ALIGN_MASK((len), (dev)->block_mask))
-
-/* threshold to re-enable Tx bundling for an AC*/
-#define TX_RESUME_BUNDLE_THRESHOLD     1500
-
-/* Functions for Tx credit handling */
-static void ath6kl_credit_deposit(struct ath6kl_htc_credit_info *cred_info,
-                                 struct htc_endpoint_credit_dist *ep_dist,
-                                 int credits)
-{
-       ath6kl_dbg(ATH6KL_DBG_CREDIT, "credit deposit ep %d credits %d\n",
-                  ep_dist->endpoint, credits);
-
-       ep_dist->credits += credits;
-       ep_dist->cred_assngd += credits;
-       cred_info->cur_free_credits -= credits;
-}
-
-static void ath6kl_credit_init(struct ath6kl_htc_credit_info *cred_info,
-                              struct list_head *ep_list,
-                              int tot_credits)
-{
-       struct htc_endpoint_credit_dist *cur_ep_dist;
-       int count;
-
-       ath6kl_dbg(ATH6KL_DBG_CREDIT, "credit init total %d\n", tot_credits);
-
-       cred_info->cur_free_credits = tot_credits;
-       cred_info->total_avail_credits = tot_credits;
-
-       list_for_each_entry(cur_ep_dist, ep_list, list) {
-               if (cur_ep_dist->endpoint == ENDPOINT_0)
-                       continue;
-
-               cur_ep_dist->cred_min = cur_ep_dist->cred_per_msg;
-
-               if (tot_credits > 4) {
-                       if ((cur_ep_dist->svc_id == WMI_DATA_BK_SVC) ||
-                           (cur_ep_dist->svc_id == WMI_DATA_BE_SVC)) {
-                               ath6kl_credit_deposit(cred_info,
-                                                     cur_ep_dist,
-                                                     cur_ep_dist->cred_min);
-                               cur_ep_dist->dist_flags |= HTC_EP_ACTIVE;
-                       }
-               }
-
-               if (cur_ep_dist->svc_id == WMI_CONTROL_SVC) {
-                       ath6kl_credit_deposit(cred_info, cur_ep_dist,
-                                             cur_ep_dist->cred_min);
-                       /*
-                        * Control service is always marked active, it
-                        * never goes inactive EVER.
-                        */
-                       cur_ep_dist->dist_flags |= HTC_EP_ACTIVE;
-               } else if (cur_ep_dist->svc_id == WMI_DATA_BK_SVC)
-                       /* this is the lowest priority data endpoint */
-                       /* FIXME: this looks fishy, check */
-                       cred_info->lowestpri_ep_dist = cur_ep_dist->list;
-
-               /*
-                * Streams have to be created (explicit | implicit) for all
-                * kinds of traffic. BE endpoints are also inactive in the
-                * beginning. When BE traffic starts it creates implicit
-                * streams that redistributes credits.
-                *
-                * Note: all other endpoints have minimums set but are
-                * initially given NO credits. credits will be distributed
-                * as traffic activity demands
-                */
-       }
-
-       WARN_ON(cred_info->cur_free_credits <= 0);
-
-       list_for_each_entry(cur_ep_dist, ep_list, list) {
-               if (cur_ep_dist->endpoint == ENDPOINT_0)
-                       continue;
-
-               if (cur_ep_dist->svc_id == WMI_CONTROL_SVC)
-                       cur_ep_dist->cred_norm = cur_ep_dist->cred_per_msg;
-               else {
-                       /*
-                        * For the remaining data endpoints, we assume that
-                        * each cred_per_msg are the same. We use a simple
-                        * calculation here, we take the remaining credits
-                        * and determine how many max messages this can
-                        * cover and then set each endpoint's normal value
-                        * equal to 3/4 this amount.
-                        */
-                       count = (cred_info->cur_free_credits /
-                                cur_ep_dist->cred_per_msg)
-                               * cur_ep_dist->cred_per_msg;
-                       count = (count * 3) >> 2;
-                       count = max(count, cur_ep_dist->cred_per_msg);
-                       cur_ep_dist->cred_norm = count;
-
-               }
-
-               ath6kl_dbg(ATH6KL_DBG_CREDIT,
-                          "credit ep %d svc_id %d credits %d per_msg %d norm %d min %d\n",
-                          cur_ep_dist->endpoint,
-                          cur_ep_dist->svc_id,
-                          cur_ep_dist->credits,
-                          cur_ep_dist->cred_per_msg,
-                          cur_ep_dist->cred_norm,
-                          cur_ep_dist->cred_min);
-       }
-}
-
-/* initialize and setup credit distribution */
-int ath6kl_credit_setup(void *htc_handle,
-                       struct ath6kl_htc_credit_info *cred_info)
-{
-       u16 servicepriority[5];
-
-       memset(cred_info, 0, sizeof(struct ath6kl_htc_credit_info));
-
-       servicepriority[0] = WMI_CONTROL_SVC;  /* highest */
-       servicepriority[1] = WMI_DATA_VO_SVC;
-       servicepriority[2] = WMI_DATA_VI_SVC;
-       servicepriority[3] = WMI_DATA_BE_SVC;
-       servicepriority[4] = WMI_DATA_BK_SVC; /* lowest */
-
-       /* set priority list */
-       ath6kl_htc_set_credit_dist(htc_handle, cred_info, servicepriority, 5);
-
-       return 0;
-}
-
-/* reduce an ep's credits back to a set limit */
-static void ath6kl_credit_reduce(struct ath6kl_htc_credit_info *cred_info,
-                                struct htc_endpoint_credit_dist *ep_dist,
-                                int limit)
-{
-       int credits;
-
-       ath6kl_dbg(ATH6KL_DBG_CREDIT, "credit reduce ep %d limit %d\n",
-                  ep_dist->endpoint, limit);
-
-       ep_dist->cred_assngd = limit;
-
-       if (ep_dist->credits <= limit)
-               return;
-
-       credits = ep_dist->credits - limit;
-       ep_dist->credits -= credits;
-       cred_info->cur_free_credits += credits;
-}
-
-static void ath6kl_credit_update(struct ath6kl_htc_credit_info *cred_info,
-                                struct list_head *epdist_list)
-{
-       struct htc_endpoint_credit_dist *cur_list;
-
-       list_for_each_entry(cur_list, epdist_list, list) {
-               if (cur_list->endpoint == ENDPOINT_0)
-                       continue;
-
-               if (cur_list->cred_to_dist > 0) {
-                       cur_list->credits += cur_list->cred_to_dist;
-                       cur_list->cred_to_dist = 0;
-
-                       if (cur_list->credits > cur_list->cred_assngd)
-                               ath6kl_credit_reduce(cred_info,
-                                                    cur_list,
-                                                    cur_list->cred_assngd);
-
-                       if (cur_list->credits > cur_list->cred_norm)
-                               ath6kl_credit_reduce(cred_info, cur_list,
-                                                    cur_list->cred_norm);
-
-                       if (!(cur_list->dist_flags & HTC_EP_ACTIVE)) {
-                               if (cur_list->txq_depth == 0)
-                                       ath6kl_credit_reduce(cred_info,
-                                                            cur_list, 0);
-                       }
-               }
-       }
-}
-
-/*
- * HTC has an endpoint that needs credits, ep_dist is the endpoint in
- * question.
- */
-static void ath6kl_credit_seek(struct ath6kl_htc_credit_info *cred_info,
-                               struct htc_endpoint_credit_dist *ep_dist)
-{
-       struct htc_endpoint_credit_dist *curdist_list;
-       int credits = 0;
-       int need;
-
-       if (ep_dist->svc_id == WMI_CONTROL_SVC)
-               goto out;
-
-       if ((ep_dist->svc_id == WMI_DATA_VI_SVC) ||
-           (ep_dist->svc_id == WMI_DATA_VO_SVC))
-               if ((ep_dist->cred_assngd >= ep_dist->cred_norm))
-                       goto out;
-
-       /*
-        * For all other services, we follow a simple algorithm of:
-        *
-        * 1. checking the free pool for credits
-        * 2. checking lower priority endpoints for credits to take
-        */
-
-       credits = min(cred_info->cur_free_credits, ep_dist->seek_cred);
-
-       if (credits >= ep_dist->seek_cred)
-               goto out;
-
-       /*
-        * We don't have enough in the free pool, try taking away from
-        * lower priority services The rule for taking away credits:
-        *
-        *   1. Only take from lower priority endpoints
-        *   2. Only take what is allocated above the minimum (never
-        *      starve an endpoint completely)
-        *   3. Only take what you need.
-        */
-
-       list_for_each_entry_reverse(curdist_list,
-                                   &cred_info->lowestpri_ep_dist,
-                                   list) {
-               if (curdist_list == ep_dist)
-                       break;
-
-               need = ep_dist->seek_cred - cred_info->cur_free_credits;
-
-               if ((curdist_list->cred_assngd - need) >=
-                    curdist_list->cred_min) {
-                       /*
-                        * The current one has been allocated more than
-                        * it's minimum and it has enough credits assigned
-                        * above it's minimum to fulfill our need try to
-                        * take away just enough to fulfill our need.
-                        */
-                       ath6kl_credit_reduce(cred_info, curdist_list,
-                                            curdist_list->cred_assngd - need);
-
-                       if (cred_info->cur_free_credits >=
-                           ep_dist->seek_cred)
-                               break;
-               }
-
-               if (curdist_list->endpoint == ENDPOINT_0)
-                       break;
-       }
-
-       credits = min(cred_info->cur_free_credits, ep_dist->seek_cred);
-
-out:
-       /* did we find some credits? */
-       if (credits)
-               ath6kl_credit_deposit(cred_info, ep_dist, credits);
-
-       ep_dist->seek_cred = 0;
-}
-
-/* redistribute credits based on activity change */
-static void ath6kl_credit_redistribute(struct ath6kl_htc_credit_info *info,
-                                      struct list_head *ep_dist_list)
-{
-       struct htc_endpoint_credit_dist *curdist_list;
-
-       list_for_each_entry(curdist_list, ep_dist_list, list) {
-               if (curdist_list->endpoint == ENDPOINT_0)
-                       continue;
-
-               if ((curdist_list->svc_id == WMI_DATA_BK_SVC)  ||
-                   (curdist_list->svc_id == WMI_DATA_BE_SVC))
-                       curdist_list->dist_flags |= HTC_EP_ACTIVE;
-
-               if ((curdist_list->svc_id != WMI_CONTROL_SVC) &&
-                   !(curdist_list->dist_flags & HTC_EP_ACTIVE)) {
-                       if (curdist_list->txq_depth == 0)
-                               ath6kl_credit_reduce(info, curdist_list, 0);
-                       else
-                               ath6kl_credit_reduce(info,
-                                                    curdist_list,
-                                                    curdist_list->cred_min);
-               }
-       }
-}
-
-/*
- *
- * This function is invoked whenever endpoints require credit
- * distributions. A lock is held while this function is invoked, this
- * function shall NOT block. The ep_dist_list is a list of distribution
- * structures in prioritized order as defined by the call to the
- * htc_set_credit_dist() api.
- */
-static void ath6kl_credit_distribute(struct ath6kl_htc_credit_info *cred_info,
-                                    struct list_head *ep_dist_list,
-                             enum htc_credit_dist_reason reason)
-{
-       switch (reason) {
-       case HTC_CREDIT_DIST_SEND_COMPLETE:
-               ath6kl_credit_update(cred_info, ep_dist_list);
-               break;
-       case HTC_CREDIT_DIST_ACTIVITY_CHANGE:
-               ath6kl_credit_redistribute(cred_info, ep_dist_list);
-               break;
-       default:
-               break;
-       }
-
-       WARN_ON(cred_info->cur_free_credits > cred_info->total_avail_credits);
-       WARN_ON(cred_info->cur_free_credits < 0);
-}
-
-static void ath6kl_htc_tx_buf_align(u8 **buf, unsigned long len)
-{
-       u8 *align_addr;
-
-       if (!IS_ALIGNED((unsigned long) *buf, 4)) {
-               align_addr = PTR_ALIGN(*buf - 4, 4);
-               memmove(align_addr, *buf, len);
-               *buf = align_addr;
-       }
-}
-
-static void ath6kl_htc_tx_prep_pkt(struct htc_packet *packet, u8 flags,
-                                  int ctrl0, int ctrl1)
-{
-       struct htc_frame_hdr *hdr;
-
-       packet->buf -= HTC_HDR_LENGTH;
-       hdr =  (struct htc_frame_hdr *)packet->buf;
-
-       /* Endianess? */
-       put_unaligned((u16)packet->act_len, &hdr->payld_len);
-       hdr->flags = flags;
-       hdr->eid = packet->endpoint;
-       hdr->ctrl[0] = ctrl0;
-       hdr->ctrl[1] = ctrl1;
-}
-
-static void htc_reclaim_txctrl_buf(struct htc_target *target,
-                                  struct htc_packet *pkt)
-{
-       spin_lock_bh(&target->htc_lock);
-       list_add_tail(&pkt->list, &target->free_ctrl_txbuf);
-       spin_unlock_bh(&target->htc_lock);
-}
-
-static struct htc_packet *htc_get_control_buf(struct htc_target *target,
-                                             bool tx)
-{
-       struct htc_packet *packet = NULL;
-       struct list_head *buf_list;
-
-       buf_list = tx ? &target->free_ctrl_txbuf : &target->free_ctrl_rxbuf;
-
-       spin_lock_bh(&target->htc_lock);
-
-       if (list_empty(buf_list)) {
-               spin_unlock_bh(&target->htc_lock);
-               return NULL;
-       }
-
-       packet = list_first_entry(buf_list, struct htc_packet, list);
-       list_del(&packet->list);
-       spin_unlock_bh(&target->htc_lock);
-
-       if (tx)
-               packet->buf = packet->buf_start + HTC_HDR_LENGTH;
-
-       return packet;
-}
-
-static void htc_tx_comp_update(struct htc_target *target,
-                              struct htc_endpoint *endpoint,
-                              struct htc_packet *packet)
-{
-       packet->completion = NULL;
-       packet->buf += HTC_HDR_LENGTH;
-
-       if (!packet->status)
-               return;
-
-       ath6kl_err("req failed (status:%d, ep:%d, len:%d creds:%d)\n",
-                  packet->status, packet->endpoint, packet->act_len,
-                  packet->info.tx.cred_used);
-
-       /* on failure to submit, reclaim credits for this packet */
-       spin_lock_bh(&target->tx_lock);
-       endpoint->cred_dist.cred_to_dist +=
-                               packet->info.tx.cred_used;
-       endpoint->cred_dist.txq_depth = get_queue_depth(&endpoint->txq);
-
-       ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx ctxt 0x%p dist 0x%p\n",
-                  target->credit_info, &target->cred_dist_list);
-
-       ath6kl_credit_distribute(target->credit_info,
-                                &target->cred_dist_list,
-                                HTC_CREDIT_DIST_SEND_COMPLETE);
-
-       spin_unlock_bh(&target->tx_lock);
-}
-
-static void htc_tx_complete(struct htc_endpoint *endpoint,
-                           struct list_head *txq)
-{
-       if (list_empty(txq))
-               return;
-
-       ath6kl_dbg(ATH6KL_DBG_HTC,
-                  "htc tx complete ep %d pkts %d\n",
-                  endpoint->eid, get_queue_depth(txq));
-
-       ath6kl_tx_complete(endpoint->target->dev->ar, txq);
-}
-
-static void htc_tx_comp_handler(struct htc_target *target,
-                               struct htc_packet *packet)
-{
-       struct htc_endpoint *endpoint = &target->endpoint[packet->endpoint];
-       struct list_head container;
-
-       ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx complete seqno %d\n",
-                  packet->info.tx.seqno);
-
-       htc_tx_comp_update(target, endpoint, packet);
-       INIT_LIST_HEAD(&container);
-       list_add_tail(&packet->list, &container);
-       /* do completion */
-       htc_tx_complete(endpoint, &container);
-}
-
-static void htc_async_tx_scat_complete(struct htc_target *target,
-                                      struct hif_scatter_req *scat_req)
-{
-       struct htc_endpoint *endpoint;
-       struct htc_packet *packet;
-       struct list_head tx_compq;
-       int i;
-
-       INIT_LIST_HEAD(&tx_compq);
-
-       ath6kl_dbg(ATH6KL_DBG_HTC,
-                  "htc tx scat complete len %d entries %d\n",
-                  scat_req->len, scat_req->scat_entries);
-
-       if (scat_req->status)
-               ath6kl_err("send scatter req failed: %d\n", scat_req->status);
-
-       packet = scat_req->scat_list[0].packet;
-       endpoint = &target->endpoint[packet->endpoint];
-
-       /* walk through the scatter list and process */
-       for (i = 0; i < scat_req->scat_entries; i++) {
-               packet = scat_req->scat_list[i].packet;
-               if (!packet) {
-                       WARN_ON(1);
-                       return;
-               }
-
-               packet->status = scat_req->status;
-               htc_tx_comp_update(target, endpoint, packet);
-               list_add_tail(&packet->list, &tx_compq);
-       }
-
-       /* free scatter request */
-       hif_scatter_req_add(target->dev->ar, scat_req);
-
-       /* complete all packets */
-       htc_tx_complete(endpoint, &tx_compq);
-}
-
-static int ath6kl_htc_tx_issue(struct htc_target *target,
-                              struct htc_packet *packet)
-{
-       int status;
-       bool sync = false;
-       u32 padded_len, send_len;
-
-       if (!packet->completion)
-               sync = true;
-
-       send_len = packet->act_len + HTC_HDR_LENGTH;
-
-       padded_len = CALC_TXRX_PADDED_LEN(target, send_len);
-
-       ath6kl_dbg(ATH6KL_DBG_HTC,
-                  "htc tx issue len %d seqno %d padded_len %d mbox 0x%X %s\n",
-                  send_len, packet->info.tx.seqno, padded_len,
-                  target->dev->ar->mbox_info.htc_addr,
-                  sync ? "sync" : "async");
-
-       if (sync) {
-               status = hif_read_write_sync(target->dev->ar,
-                               target->dev->ar->mbox_info.htc_addr,
-                                packet->buf, padded_len,
-                                HIF_WR_SYNC_BLOCK_INC);
-
-               packet->status = status;
-               packet->buf += HTC_HDR_LENGTH;
-       } else
-               status = hif_write_async(target->dev->ar,
-                               target->dev->ar->mbox_info.htc_addr,
-                               packet->buf, padded_len,
-                               HIF_WR_ASYNC_BLOCK_INC, packet);
-
-       return status;
-}
-
-static int htc_check_credits(struct htc_target *target,
-                            struct htc_endpoint *ep, u8 *flags,
-                            enum htc_endpoint_id eid, unsigned int len,
-                            int *req_cred)
-{
-
-       *req_cred = (len > target->tgt_cred_sz) ?
-                    DIV_ROUND_UP(len, target->tgt_cred_sz) : 1;
-
-       ath6kl_dbg(ATH6KL_DBG_CREDIT, "credit check need %d got %d\n",
-                  *req_cred, ep->cred_dist.credits);
-
-       if (ep->cred_dist.credits < *req_cred) {
-               if (eid == ENDPOINT_0)
-                       return -EINVAL;
-
-               /* Seek more credits */
-               ep->cred_dist.seek_cred = *req_cred - ep->cred_dist.credits;
-
-               ath6kl_credit_seek(target->credit_info, &ep->cred_dist);
-
-               ep->cred_dist.seek_cred = 0;
-
-               if (ep->cred_dist.credits < *req_cred) {
-                       ath6kl_dbg(ATH6KL_DBG_CREDIT,
-                                  "credit not found for ep %d\n",
-                                  eid);
-                       return -EINVAL;
-               }
-       }
-
-       ep->cred_dist.credits -= *req_cred;
-       ep->ep_st.cred_cosumd += *req_cred;
-
-        /* When we are getting low on credits, ask for more */
-       if (ep->cred_dist.credits < ep->cred_dist.cred_per_msg) {
-               ep->cred_dist.seek_cred =
-               ep->cred_dist.cred_per_msg - ep->cred_dist.credits;
-
-               ath6kl_credit_seek(target->credit_info, &ep->cred_dist);
-
-               /* see if we were successful in getting more */
-               if (ep->cred_dist.credits < ep->cred_dist.cred_per_msg) {
-                       /* tell the target we need credits ASAP! */
-                       *flags |= HTC_FLAGS_NEED_CREDIT_UPDATE;
-                       ep->ep_st.cred_low_indicate += 1;
-                       ath6kl_dbg(ATH6KL_DBG_CREDIT,
-                                  "credit we need credits asap\n");
-               }
-       }
-
-       return 0;
-}
-
-static void ath6kl_htc_tx_pkts_get(struct htc_target *target,
-                                  struct htc_endpoint *endpoint,
-                                  struct list_head *queue)
-{
-       int req_cred;
-       u8 flags;
-       struct htc_packet *packet;
-       unsigned int len;
-
-       while (true) {
-
-               flags = 0;
-
-               if (list_empty(&endpoint->txq))
-                       break;
-               packet = list_first_entry(&endpoint->txq, struct htc_packet,
-                                         list);
-
-               ath6kl_dbg(ATH6KL_DBG_HTC,
-                          "htc tx got packet 0x%p queue depth %d\n",
-                          packet, get_queue_depth(&endpoint->txq));
-
-               len = CALC_TXRX_PADDED_LEN(target,
-                                          packet->act_len + HTC_HDR_LENGTH);
-
-               if (htc_check_credits(target, endpoint, &flags,
-                                     packet->endpoint, len, &req_cred))
-                       break;
-
-               /* now we can fully move onto caller's queue */
-               packet = list_first_entry(&endpoint->txq, struct htc_packet,
-                                         list);
-               list_move_tail(&packet->list, queue);
-
-               /* save the number of credits this packet consumed */
-               packet->info.tx.cred_used = req_cred;
-
-               /* all TX packets are handled asynchronously */
-               packet->completion = htc_tx_comp_handler;
-               packet->context = target;
-               endpoint->ep_st.tx_issued += 1;
-
-               /* save send flags */
-               packet->info.tx.flags = flags;
-               packet->info.tx.seqno = endpoint->seqno;
-               endpoint->seqno++;
-       }
-}
-
-/* See if the padded tx length falls on a credit boundary */
-static int htc_get_credit_padding(unsigned int cred_sz, int *len,
-                                 struct htc_endpoint *ep)
-{
-       int rem_cred, cred_pad;
-
-       rem_cred = *len % cred_sz;
-
-       /* No padding needed */
-       if  (!rem_cred)
-               return 0;
-
-       if (!(ep->conn_flags & HTC_FLGS_TX_BNDL_PAD_EN))
-               return -1;
-
-       /*
-        * The transfer consumes a "partial" credit, this
-        * packet cannot be bundled unless we add
-        * additional "dummy" padding (max 255 bytes) to
-        * consume the entire credit.
-        */
-       cred_pad = *len < cred_sz ? (cred_sz - *len) : rem_cred;
-
-       if ((cred_pad > 0) && (cred_pad <= 255))
-               *len += cred_pad;
-       else
-               /* The amount of padding is too large, send as non-bundled */
-               return -1;
-
-       return cred_pad;
-}
-
-static int ath6kl_htc_tx_setup_scat_list(struct htc_target *target,
-                                        struct htc_endpoint *endpoint,
-                                        struct hif_scatter_req *scat_req,
-                                        int n_scat,
-                                        struct list_head *queue)
-{
-       struct htc_packet *packet;
-       int i, len, rem_scat, cred_pad;
-       int status = 0;
-       u8 flags;
-
-       rem_scat = target->max_tx_bndl_sz;
-
-       for (i = 0; i < n_scat; i++) {
-               scat_req->scat_list[i].packet = NULL;
-
-               if (list_empty(queue))
-                       break;
-
-               packet = list_first_entry(queue, struct htc_packet, list);
-               len = CALC_TXRX_PADDED_LEN(target,
-                                          packet->act_len + HTC_HDR_LENGTH);
-
-               cred_pad = htc_get_credit_padding(target->tgt_cred_sz,
-                                                 &len, endpoint);
-               if (cred_pad < 0 || rem_scat < len) {
-                       status = -ENOSPC;
-                       break;
-               }
-
-               rem_scat -= len;
-               /* now remove it from the queue */
-               list_del(&packet->list);
-
-               scat_req->scat_list[i].packet = packet;
-               /* prepare packet and flag message as part of a send bundle */
-               flags = packet->info.tx.flags | HTC_FLAGS_SEND_BUNDLE;
-               ath6kl_htc_tx_prep_pkt(packet, flags,
-                                      cred_pad, packet->info.tx.seqno);
-               /* Make sure the buffer is 4-byte aligned */
-               ath6kl_htc_tx_buf_align(&packet->buf,
-                                       packet->act_len + HTC_HDR_LENGTH);
-               scat_req->scat_list[i].buf = packet->buf;
-               scat_req->scat_list[i].len = len;
-
-               scat_req->len += len;
-               scat_req->scat_entries++;
-               ath6kl_dbg(ATH6KL_DBG_HTC,
-                          "htc tx adding (%d) pkt 0x%p seqno %d len %d remaining %d\n",
-                          i, packet, packet->info.tx.seqno, len, rem_scat);
-       }
-
-       /* Roll back scatter setup in case of any failure */
-       if (scat_req->scat_entries < HTC_MIN_HTC_MSGS_TO_BUNDLE) {
-               for (i = scat_req->scat_entries - 1; i >= 0; i--) {
-                       packet = scat_req->scat_list[i].packet;
-                       if (packet) {
-                               packet->buf += HTC_HDR_LENGTH;
-                               list_add(&packet->list, queue);
-                       }
-               }
-               return -EAGAIN;
-       }
-
-       return status;
-}
-
-/*
- * Drain a queue and send as bundles this function may return without fully
- * draining the queue when
- *
- *    1. scatter resources are exhausted
- *    2. a message that will consume a partial credit will stop the
- *    bundling process early
- *    3. we drop below the minimum number of messages for a bundle
- */
-static void ath6kl_htc_tx_bundle(struct htc_endpoint *endpoint,
-                                struct list_head *queue,
-                                int *sent_bundle, int *n_bundle_pkts)
-{
-       struct htc_target *target = endpoint->target;
-       struct hif_scatter_req *scat_req = NULL;
-       int n_scat, n_sent_bundle = 0, tot_pkts_bundle = 0;
-       int status;
-       u32 txb_mask;
-       u8 ac = WMM_NUM_AC;
-
-       if ((HTC_CTRL_RSVD_SVC != endpoint->svc_id) ||
-           (WMI_CONTROL_SVC != endpoint->svc_id))
-               ac = target->dev->ar->ep2ac_map[endpoint->eid];
-
-       while (true) {
-               status = 0;
-               n_scat = get_queue_depth(queue);
-               n_scat = min(n_scat, target->msg_per_bndl_max);
-
-               if (n_scat < HTC_MIN_HTC_MSGS_TO_BUNDLE)
-                       /* not enough to bundle */
-                       break;
-
-               scat_req = hif_scatter_req_get(target->dev->ar);
-
-               if (!scat_req) {
-                       /* no scatter resources  */
-                       ath6kl_dbg(ATH6KL_DBG_HTC,
-                                  "htc tx no more scatter resources\n");
-                       break;
-               }
-
-               if ((ac < WMM_NUM_AC) && (ac != WMM_AC_BK)) {
-                       if (WMM_AC_BE == ac)
-                               /*
-                                * BE, BK have priorities and bit
-                                * positions reversed
-                                */
-                               txb_mask = (1 << WMM_AC_BK);
-                       else
-                               /*
-                                * any AC with priority lower than
-                                * itself
-                                */
-                               txb_mask = ((1 << ac) - 1);
-               /*
-                * when the scatter request resources drop below a
-                * certain threshold, disable Tx bundling for all
-                * AC's with priority lower than the current requesting
-                * AC. Otherwise re-enable Tx bundling for them
-                */
-               if (scat_req->scat_q_depth < ATH6KL_SCATTER_REQS)
-                       target->tx_bndl_mask &= ~txb_mask;
-               else
-                       target->tx_bndl_mask |= txb_mask;
-               }
-
-               ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx pkts to scatter: %d\n",
-                          n_scat);
-
-               scat_req->len = 0;
-               scat_req->scat_entries = 0;
-
-               status = ath6kl_htc_tx_setup_scat_list(target, endpoint,
-                                                      scat_req, n_scat,
-                                                      queue);
-               if (status == -EAGAIN) {
-                       hif_scatter_req_add(target->dev->ar, scat_req);
-                       break;
-               }
-
-               /* send path is always asynchronous */
-               scat_req->complete = htc_async_tx_scat_complete;
-               n_sent_bundle++;
-               tot_pkts_bundle += scat_req->scat_entries;
-
-               ath6kl_dbg(ATH6KL_DBG_HTC,
-                          "htc tx scatter bytes %d entries %d\n",
-                          scat_req->len, scat_req->scat_entries);
-               ath6kl_hif_submit_scat_req(target->dev, scat_req, false);
-
-               if (status)
-                       break;
-       }
-
-       *sent_bundle = n_sent_bundle;
-       *n_bundle_pkts = tot_pkts_bundle;
-       ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx bundle sent %d pkts\n",
-                  n_sent_bundle);
-
-       return;
-}
-
-static void ath6kl_htc_tx_from_queue(struct htc_target *target,
-                                    struct htc_endpoint *endpoint)
-{
-       struct list_head txq;
-       struct htc_packet *packet;
-       int bundle_sent;
-       int n_pkts_bundle;
-       u8 ac = WMM_NUM_AC;
-
-       spin_lock_bh(&target->tx_lock);
-
-       endpoint->tx_proc_cnt++;
-       if (endpoint->tx_proc_cnt > 1) {
-               endpoint->tx_proc_cnt--;
-               spin_unlock_bh(&target->tx_lock);
-               ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx busy\n");
-               return;
-       }
-
-       /*
-        * drain the endpoint TX queue for transmission as long
-        * as we have enough credits.
-        */
-       INIT_LIST_HEAD(&txq);
-
-       if ((HTC_CTRL_RSVD_SVC != endpoint->svc_id) ||
-           (WMI_CONTROL_SVC != endpoint->svc_id))
-               ac = target->dev->ar->ep2ac_map[endpoint->eid];
-
-       while (true) {
-
-               if (list_empty(&endpoint->txq))
-                       break;
-
-               ath6kl_htc_tx_pkts_get(target, endpoint, &txq);
-
-               if (list_empty(&txq))
-                       break;
-
-               spin_unlock_bh(&target->tx_lock);
-
-               bundle_sent = 0;
-               n_pkts_bundle = 0;
-
-               while (true) {
-                       /* try to send a bundle on each pass */
-                       if ((target->tx_bndl_mask) &&
-                           (get_queue_depth(&txq) >=
-                           HTC_MIN_HTC_MSGS_TO_BUNDLE)) {
-                               int temp1 = 0, temp2 = 0;
-
-                               /* check if bundling is enabled for an AC */
-                               if (target->tx_bndl_mask & (1 << ac)) {
-                                       ath6kl_htc_tx_bundle(endpoint, &txq,
-                                                            &temp1, &temp2);
-                                       bundle_sent += temp1;
-                                       n_pkts_bundle += temp2;
-                               }
-                       }
-
-                       if (list_empty(&txq))
-                               break;
-
-                       packet = list_first_entry(&txq, struct htc_packet,
-                                                 list);
-                       list_del(&packet->list);
-
-                       ath6kl_htc_tx_prep_pkt(packet, packet->info.tx.flags,
-                                              0, packet->info.tx.seqno);
-                       ath6kl_htc_tx_issue(target, packet);
-               }
-
-               spin_lock_bh(&target->tx_lock);
-
-               endpoint->ep_st.tx_bundles += bundle_sent;
-               endpoint->ep_st.tx_pkt_bundled += n_pkts_bundle;
-
-               /*
-                * if an AC has bundling disabled and no tx bundling
-                * has occured continously for a certain number of TX,
-                * enable tx bundling for this AC
-                */
-               if (!bundle_sent) {
-                       if (!(target->tx_bndl_mask & (1 << ac)) &&
-                           (ac < WMM_NUM_AC)) {
-                               if (++target->ac_tx_count[ac] >=
-                                       TX_RESUME_BUNDLE_THRESHOLD) {
-                                       target->ac_tx_count[ac] = 0;
-                                       target->tx_bndl_mask |= (1 << ac);
-                               }
-                       }
-               } else {
-                       /* tx bundling will reset the counter */
-                       if (ac < WMM_NUM_AC)
-                               target->ac_tx_count[ac] = 0;
-               }
-       }
-
-       endpoint->tx_proc_cnt = 0;
-       spin_unlock_bh(&target->tx_lock);
-}
-
-static bool ath6kl_htc_tx_try(struct htc_target *target,
-                             struct htc_endpoint *endpoint,
-                             struct htc_packet *tx_pkt)
-{
-       struct htc_ep_callbacks ep_cb;
-       int txq_depth;
-       bool overflow = false;
-
-       ep_cb = endpoint->ep_cb;
-
-       spin_lock_bh(&target->tx_lock);
-       txq_depth = get_queue_depth(&endpoint->txq);
-       spin_unlock_bh(&target->tx_lock);
-
-       if (txq_depth >= endpoint->max_txq_depth)
-               overflow = true;
-
-       if (overflow)
-               ath6kl_dbg(ATH6KL_DBG_HTC,
-                          "htc tx overflow ep %d depth %d max %d\n",
-                          endpoint->eid, txq_depth,
-                          endpoint->max_txq_depth);
-
-       if (overflow && ep_cb.tx_full) {
-               if (ep_cb.tx_full(endpoint->target, tx_pkt) ==
-                   HTC_SEND_FULL_DROP) {
-                       endpoint->ep_st.tx_dropped += 1;
-                       return false;
-               }
-       }
-
-       spin_lock_bh(&target->tx_lock);
-       list_add_tail(&tx_pkt->list, &endpoint->txq);
-       spin_unlock_bh(&target->tx_lock);
-
-       ath6kl_htc_tx_from_queue(target, endpoint);
-
-       return true;
-}
-
-static void htc_chk_ep_txq(struct htc_target *target)
-{
-       struct htc_endpoint *endpoint;
-       struct htc_endpoint_credit_dist *cred_dist;
-
-       /*
-        * Run through the credit distribution list to see if there are
-        * packets queued. NOTE: no locks need to be taken since the
-        * distribution list is not dynamic (cannot be re-ordered) and we
-        * are not modifying any state.
-        */
-       list_for_each_entry(cred_dist, &target->cred_dist_list, list) {
-               endpoint = cred_dist->htc_ep;
-
-               spin_lock_bh(&target->tx_lock);
-               if (!list_empty(&endpoint->txq)) {
-                       ath6kl_dbg(ATH6KL_DBG_HTC,
-                                  "htc creds ep %d credits %d pkts %d\n",
-                                  cred_dist->endpoint,
-                                  endpoint->cred_dist.credits,
-                                  get_queue_depth(&endpoint->txq));
-                       spin_unlock_bh(&target->tx_lock);
-                       /*
-                        * Try to start the stalled queue, this list is
-                        * ordered by priority. If there are credits
-                        * available the highest priority queue will get a
-                        * chance to reclaim credits from lower priority
-                        * ones.
-                        */
-                       ath6kl_htc_tx_from_queue(target, endpoint);
-                       spin_lock_bh(&target->tx_lock);
-               }
-               spin_unlock_bh(&target->tx_lock);
-       }
-}
-
-static int htc_setup_tx_complete(struct htc_target *target)
-{
-       struct htc_packet *send_pkt = NULL;
-       int status;
-
-       send_pkt = htc_get_control_buf(target, true);
-
-       if (!send_pkt)
-               return -ENOMEM;
-
-       if (target->htc_tgt_ver >= HTC_VERSION_2P1) {
-               struct htc_setup_comp_ext_msg *setup_comp_ext;
-               u32 flags = 0;
-
-               setup_comp_ext =
-                   (struct htc_setup_comp_ext_msg *)send_pkt->buf;
-               memset(setup_comp_ext, 0, sizeof(*setup_comp_ext));
-               setup_comp_ext->msg_id =
-                       cpu_to_le16(HTC_MSG_SETUP_COMPLETE_EX_ID);
-
-               if (target->msg_per_bndl_max > 0) {
-                       /* Indicate HTC bundling to the target */
-                       flags |= HTC_SETUP_COMP_FLG_RX_BNDL_EN;
-                       setup_comp_ext->msg_per_rxbndl =
-                                               target->msg_per_bndl_max;
-               }
-
-               memcpy(&setup_comp_ext->flags, &flags,
-                      sizeof(setup_comp_ext->flags));
-               set_htc_pkt_info(send_pkt, NULL, (u8 *) setup_comp_ext,
-                                sizeof(struct htc_setup_comp_ext_msg),
-                                ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
-
-       } else {
-               struct htc_setup_comp_msg *setup_comp;
-               setup_comp = (struct htc_setup_comp_msg *)send_pkt->buf;
-               memset(setup_comp, 0, sizeof(struct htc_setup_comp_msg));
-               setup_comp->msg_id = cpu_to_le16(HTC_MSG_SETUP_COMPLETE_ID);
-               set_htc_pkt_info(send_pkt, NULL, (u8 *) setup_comp,
-                                sizeof(struct htc_setup_comp_msg),
-                                ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
-       }
-
-       /* we want synchronous operation */
-       send_pkt->completion = NULL;
-       ath6kl_htc_tx_prep_pkt(send_pkt, 0, 0, 0);
-       status = ath6kl_htc_tx_issue(target, send_pkt);
-
-       if (send_pkt != NULL)
-               htc_reclaim_txctrl_buf(target, send_pkt);
-
-       return status;
-}
-
-void ath6kl_htc_set_credit_dist(struct htc_target *target,
-                               struct ath6kl_htc_credit_info *credit_info,
-                               u16 srvc_pri_order[], int list_len)
-{
-       struct htc_endpoint *endpoint;
-       int i, ep;
-
-       target->credit_info = credit_info;
-
-       list_add_tail(&target->endpoint[ENDPOINT_0].cred_dist.list,
-                     &target->cred_dist_list);
-
-       for (i = 0; i < list_len; i++) {
-               for (ep = ENDPOINT_1; ep < ENDPOINT_MAX; ep++) {
-                       endpoint = &target->endpoint[ep];
-                       if (endpoint->svc_id == srvc_pri_order[i]) {
-                               list_add_tail(&endpoint->cred_dist.list,
-                                             &target->cred_dist_list);
-                               break;
-                       }
-               }
-               if (ep >= ENDPOINT_MAX) {
-                       WARN_ON(1);
-                       return;
-               }
-       }
-}
-
-int ath6kl_htc_tx(struct htc_target *target, struct htc_packet *packet)
-{
-       struct htc_endpoint *endpoint;
-       struct list_head queue;
-
-       ath6kl_dbg(ATH6KL_DBG_HTC,
-                  "htc tx ep id %d buf 0x%p len %d\n",
-                  packet->endpoint, packet->buf, packet->act_len);
-
-       if (packet->endpoint >= ENDPOINT_MAX) {
-               WARN_ON(1);
-               return -EINVAL;
-       }
-
-       endpoint = &target->endpoint[packet->endpoint];
-
-       if (!ath6kl_htc_tx_try(target, endpoint, packet)) {
-               packet->status = (target->htc_flags & HTC_OP_STATE_STOPPING) ?
-                                -ECANCELED : -ENOSPC;
-               INIT_LIST_HEAD(&queue);
-               list_add(&packet->list, &queue);
-               htc_tx_complete(endpoint, &queue);
-       }
-
-       return 0;
-}
-
-/* flush endpoint TX queue */
-void ath6kl_htc_flush_txep(struct htc_target *target,
-                          enum htc_endpoint_id eid, u16 tag)
-{
-       struct htc_packet *packet, *tmp_pkt;
-       struct list_head discard_q, container;
-       struct htc_endpoint *endpoint = &target->endpoint[eid];
-
-       if (!endpoint->svc_id) {
-               WARN_ON(1);
-               return;
-       }
-
-       /* initialize the discard queue */
-       INIT_LIST_HEAD(&discard_q);
-
-       spin_lock_bh(&target->tx_lock);
-
-       list_for_each_entry_safe(packet, tmp_pkt, &endpoint->txq, list) {
-               if ((tag == HTC_TX_PACKET_TAG_ALL) ||
-                   (tag == packet->info.tx.tag))
-                       list_move_tail(&packet->list, &discard_q);
-       }
-
-       spin_unlock_bh(&target->tx_lock);
-
-       list_for_each_entry_safe(packet, tmp_pkt, &discard_q, list) {
-               packet->status = -ECANCELED;
-               list_del(&packet->list);
-               ath6kl_dbg(ATH6KL_DBG_HTC,
-                          "htc tx flushing pkt 0x%p len %d  ep %d tag 0x%x\n",
-                          packet, packet->act_len,
-                          packet->endpoint, packet->info.tx.tag);
-
-               INIT_LIST_HEAD(&container);
-               list_add_tail(&packet->list, &container);
-               htc_tx_complete(endpoint, &container);
-       }
-
-}
-
-static void ath6kl_htc_flush_txep_all(struct htc_target *target)
-{
-       struct htc_endpoint *endpoint;
-       int i;
-
-       dump_cred_dist_stats(target);
-
-       for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
-               endpoint = &target->endpoint[i];
-               if (endpoint->svc_id == 0)
-                       /* not in use.. */
-                       continue;
-               ath6kl_htc_flush_txep(target, i, HTC_TX_PACKET_TAG_ALL);
-       }
-}
-
-void ath6kl_htc_indicate_activity_change(struct htc_target *target,
-                                        enum htc_endpoint_id eid, bool active)
-{
-       struct htc_endpoint *endpoint = &target->endpoint[eid];
-       bool dist = false;
-
-       if (endpoint->svc_id == 0) {
-               WARN_ON(1);
-               return;
-       }
-
-       spin_lock_bh(&target->tx_lock);
-
-       if (active) {
-               if (!(endpoint->cred_dist.dist_flags & HTC_EP_ACTIVE)) {
-                       endpoint->cred_dist.dist_flags |= HTC_EP_ACTIVE;
-                       dist = true;
-               }
-       } else {
-               if (endpoint->cred_dist.dist_flags & HTC_EP_ACTIVE) {
-                       endpoint->cred_dist.dist_flags &= ~HTC_EP_ACTIVE;
-                       dist = true;
-               }
-       }
-
-       if (dist) {
-               endpoint->cred_dist.txq_depth =
-                       get_queue_depth(&endpoint->txq);
-
-               ath6kl_dbg(ATH6KL_DBG_HTC,
-                          "htc tx activity ctxt 0x%p dist 0x%p\n",
-                          target->credit_info, &target->cred_dist_list);
-
-               ath6kl_credit_distribute(target->credit_info,
-                                        &target->cred_dist_list,
-                                        HTC_CREDIT_DIST_ACTIVITY_CHANGE);
-       }
-
-       spin_unlock_bh(&target->tx_lock);
-
-       if (dist && !active)
-               htc_chk_ep_txq(target);
-}
-
-/* HTC Rx */
-
-static inline void ath6kl_htc_rx_update_stats(struct htc_endpoint *endpoint,
-                                             int n_look_ahds)
-{
-       endpoint->ep_st.rx_pkts++;
-       if (n_look_ahds == 1)
-               endpoint->ep_st.rx_lkahds++;
-       else if (n_look_ahds > 1)
-               endpoint->ep_st.rx_bundle_lkahd++;
-}
-
-static inline bool htc_valid_rx_frame_len(struct htc_target *target,
-                                         enum htc_endpoint_id eid, int len)
-{
-       return (eid == target->dev->ar->ctrl_ep) ?
-               len <= ATH6KL_BUFFER_SIZE : len <= ATH6KL_AMSDU_BUFFER_SIZE;
-}
-
-static int htc_add_rxbuf(struct htc_target *target, struct htc_packet *packet)
-{
-       struct list_head queue;
-
-       INIT_LIST_HEAD(&queue);
-       list_add_tail(&packet->list, &queue);
-       return ath6kl_htc_add_rxbuf_multiple(target, &queue);
-}
-
-static void htc_reclaim_rxbuf(struct htc_target *target,
-                             struct htc_packet *packet,
-                             struct htc_endpoint *ep)
-{
-       if (packet->info.rx.rx_flags & HTC_RX_PKT_NO_RECYCLE) {
-               htc_rxpkt_reset(packet);
-               packet->status = -ECANCELED;
-               ep->ep_cb.rx(ep->target, packet);
-       } else {
-               htc_rxpkt_reset(packet);
-               htc_add_rxbuf((void *)(target), packet);
-       }
-}
-
-static void reclaim_rx_ctrl_buf(struct htc_target *target,
-                               struct htc_packet *packet)
-{
-       spin_lock_bh(&target->htc_lock);
-       list_add_tail(&packet->list, &target->free_ctrl_rxbuf);
-       spin_unlock_bh(&target->htc_lock);
-}
-
-static int ath6kl_htc_rx_packet(struct htc_target *target,
-                               struct htc_packet *packet,
-                               u32 rx_len)
-{
-       struct ath6kl_device *dev = target->dev;
-       u32 padded_len;
-       int status;
-
-       padded_len = CALC_TXRX_PADDED_LEN(target, rx_len);
-
-       if (padded_len > packet->buf_len) {
-               ath6kl_err("not enough receive space for packet - padlen %d recvlen %d bufferlen %d\n",
-                          padded_len, rx_len, packet->buf_len);
-               return -ENOMEM;
-       }
-
-       ath6kl_dbg(ATH6KL_DBG_HTC,
-                  "htc rx 0x%p hdr x%x len %d mbox 0x%x\n",
-                  packet, packet->info.rx.exp_hdr,
-                  padded_len, dev->ar->mbox_info.htc_addr);
-
-       status = hif_read_write_sync(dev->ar,
-                                    dev->ar->mbox_info.htc_addr,
-                                    packet->buf, padded_len,
-                                    HIF_RD_SYNC_BLOCK_FIX);
-
-       packet->status = status;
-
-       return status;
-}
-
-/*
- * optimization for recv packets, we can indicate a
- * "hint" that there are more  single-packets to fetch
- * on this endpoint.
- */
-static void ath6kl_htc_rx_set_indicate(u32 lk_ahd,
-                                      struct htc_endpoint *endpoint,
-                                      struct htc_packet *packet)
-{
-       struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)&lk_ahd;
-
-       if (htc_hdr->eid == packet->endpoint) {
-               if (!list_empty(&endpoint->rx_bufq))
-                       packet->info.rx.indicat_flags |=
-                                       HTC_RX_FLAGS_INDICATE_MORE_PKTS;
-       }
-}
-
-static void ath6kl_htc_rx_chk_water_mark(struct htc_endpoint *endpoint)
-{
-       struct htc_ep_callbacks ep_cb = endpoint->ep_cb;
-
-       if (ep_cb.rx_refill_thresh > 0) {
-               spin_lock_bh(&endpoint->target->rx_lock);
-               if (get_queue_depth(&endpoint->rx_bufq)
-                   < ep_cb.rx_refill_thresh) {
-                       spin_unlock_bh(&endpoint->target->rx_lock);
-                       ep_cb.rx_refill(endpoint->target, endpoint->eid);
-                       return;
-               }
-               spin_unlock_bh(&endpoint->target->rx_lock);
-       }
-}
-
-/* This function is called with rx_lock held */
-static int ath6kl_htc_rx_setup(struct htc_target *target,
-                              struct htc_endpoint *ep,
-                              u32 *lk_ahds, struct list_head *queue, int n_msg)
-{
-       struct htc_packet *packet;
-       /* FIXME: type of lk_ahds can't be right */
-       struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)lk_ahds;
-       struct htc_ep_callbacks ep_cb;
-       int status = 0, j, full_len;
-       bool no_recycle;
-
-       full_len = CALC_TXRX_PADDED_LEN(target,
-                                       le16_to_cpu(htc_hdr->payld_len) +
-                                       sizeof(*htc_hdr));
-
-       if (!htc_valid_rx_frame_len(target, ep->eid, full_len)) {
-               ath6kl_warn("Rx buffer requested with invalid length\n");
-               return -EINVAL;
-       }
-
-       ep_cb = ep->ep_cb;
-       for (j = 0; j < n_msg; j++) {
-
-               /*
-                * Reset flag, any packets allocated using the
-                * rx_alloc() API cannot be recycled on
-                * cleanup,they must be explicitly returned.
-                */
-               no_recycle = false;
-
-               if (ep_cb.rx_allocthresh &&
-                   (full_len > ep_cb.rx_alloc_thresh)) {
-                       ep->ep_st.rx_alloc_thresh_hit += 1;
-                       ep->ep_st.rxalloc_thresh_byte +=
-                               le16_to_cpu(htc_hdr->payld_len);
-
-                       spin_unlock_bh(&target->rx_lock);
-                       no_recycle = true;
-
-                       packet = ep_cb.rx_allocthresh(ep->target, ep->eid,
-                                                     full_len);
-                       spin_lock_bh(&target->rx_lock);
-               } else {
-                       /* refill handler is being used */
-                       if (list_empty(&ep->rx_bufq)) {
-                               if (ep_cb.rx_refill) {
-                                       spin_unlock_bh(&target->rx_lock);
-                                       ep_cb.rx_refill(ep->target, ep->eid);
-                                       spin_lock_bh(&target->rx_lock);
-                               }
-                       }
-
-                       if (list_empty(&ep->rx_bufq))
-                               packet = NULL;
-                       else {
-                               packet = list_first_entry(&ep->rx_bufq,
-                                               struct htc_packet, list);
-                               list_del(&packet->list);
-                       }
-               }
-
-               if (!packet) {
-                       target->rx_st_flags |= HTC_RECV_WAIT_BUFFERS;
-                       target->ep_waiting = ep->eid;
-                       return -ENOSPC;
-               }
-
-               /* clear flags */
-               packet->info.rx.rx_flags = 0;
-               packet->info.rx.indicat_flags = 0;
-               packet->status = 0;
-
-               if (no_recycle)
-                       /*
-                        * flag that these packets cannot be
-                        * recycled, they have to be returned to
-                        * the user
-                        */
-                       packet->info.rx.rx_flags |= HTC_RX_PKT_NO_RECYCLE;
-
-               /* Caller needs to free this upon any failure */
-               list_add_tail(&packet->list, queue);
-
-               if (target->htc_flags & HTC_OP_STATE_STOPPING) {
-                       status = -ECANCELED;
-                       break;
-               }
-
-               if (j) {
-                       packet->info.rx.rx_flags |= HTC_RX_PKT_REFRESH_HDR;
-                       packet->info.rx.exp_hdr = 0xFFFFFFFF;
-               } else
-                       /* set expected look ahead */
-                       packet->info.rx.exp_hdr = *lk_ahds;
-
-               packet->act_len = le16_to_cpu(htc_hdr->payld_len) +
-                       HTC_HDR_LENGTH;
-       }
-
-       return status;
-}
-
-static int ath6kl_htc_rx_alloc(struct htc_target *target,
-                              u32 lk_ahds[], int msg,
-                              struct htc_endpoint *endpoint,
-                              struct list_head *queue)
-{
-       int status = 0;
-       struct htc_packet *packet, *tmp_pkt;
-       struct htc_frame_hdr *htc_hdr;
-       int i, n_msg;
-
-       spin_lock_bh(&target->rx_lock);
-
-       for (i = 0; i < msg; i++) {
-
-               htc_hdr = (struct htc_frame_hdr *)&lk_ahds[i];
-
-               if (htc_hdr->eid >= ENDPOINT_MAX) {
-                       ath6kl_err("invalid ep in look-ahead: %d\n",
-                                  htc_hdr->eid);
-                       status = -ENOMEM;
-                       break;
-               }
-
-               if (htc_hdr->eid != endpoint->eid) {
-                       ath6kl_err("invalid ep in look-ahead: %d should be : %d (index:%d)\n",
-                                  htc_hdr->eid, endpoint->eid, i);
-                       status = -ENOMEM;
-                       break;
-               }
-
-               if (le16_to_cpu(htc_hdr->payld_len) > HTC_MAX_PAYLOAD_LENGTH) {
-                       ath6kl_err("payload len %d exceeds max htc : %d !\n",
-                                  htc_hdr->payld_len,
-                                  (u32) HTC_MAX_PAYLOAD_LENGTH);
-                       status = -ENOMEM;
-                       break;
-               }
-
-               if (endpoint->svc_id == 0) {
-                       ath6kl_err("ep %d is not connected !\n", htc_hdr->eid);
-                       status = -ENOMEM;
-                       break;
-               }
-
-               if (htc_hdr->flags & HTC_FLG_RX_BNDL_CNT) {
-                       /*
-                        * HTC header indicates that every packet to follow
-                        * has the same padded length so that it can be
-                        * optimally fetched as a full bundle.
-                        */
-                       n_msg = (htc_hdr->flags & HTC_FLG_RX_BNDL_CNT) >>
-                               HTC_FLG_RX_BNDL_CNT_S;
-
-                       /* the count doesn't include the starter frame */
-                       n_msg++;
-                       if (n_msg > target->msg_per_bndl_max) {
-                               status = -ENOMEM;
-                               break;
-                       }
-
-                       endpoint->ep_st.rx_bundle_from_hdr += 1;
-                       ath6kl_dbg(ATH6KL_DBG_HTC,
-                                  "htc rx bundle pkts %d\n",
-                                  n_msg);
-               } else
-                       /* HTC header only indicates 1 message to fetch */
-                       n_msg = 1;
-
-               /* Setup packet buffers for each message */
-               status = ath6kl_htc_rx_setup(target, endpoint, &lk_ahds[i],
-                                            queue, n_msg);
-
-               /*
-                * This is due to unavailabilty of buffers to rx entire data.
-                * Return no error so that free buffers from queue can be used
-                * to receive partial data.
-                */
-               if (status == -ENOSPC) {
-                       spin_unlock_bh(&target->rx_lock);
-                       return 0;
-               }
-
-               if (status)
-                       break;
-       }
-
-       spin_unlock_bh(&target->rx_lock);
-
-       if (status) {
-               list_for_each_entry_safe(packet, tmp_pkt, queue, list) {
-                       list_del(&packet->list);
-                       htc_reclaim_rxbuf(target, packet,
-                                         &target->endpoint[packet->endpoint]);
-               }
-       }
-
-       return status;
-}
-
-static void htc_ctrl_rx(struct htc_target *context, struct htc_packet *packets)
-{
-       if (packets->endpoint != ENDPOINT_0) {
-               WARN_ON(1);
-               return;
-       }
-
-       if (packets->status == -ECANCELED) {
-               reclaim_rx_ctrl_buf(context, packets);
-               return;
-       }
-
-       if (packets->act_len > 0) {
-               ath6kl_err("htc_ctrl_rx, got message with len:%zu\n",
-                          packets->act_len + HTC_HDR_LENGTH);
-
-               ath6kl_dbg_dump(ATH6KL_DBG_HTC,
-                               "htc rx unexpected endpoint 0 message", "",
-                               packets->buf - HTC_HDR_LENGTH,
-                               packets->act_len + HTC_HDR_LENGTH);
-       }
-
-       htc_reclaim_rxbuf(context, packets, &context->endpoint[0]);
-}
-
-static void htc_proc_cred_rpt(struct htc_target *target,
-                             struct htc_credit_report *rpt,
-                             int n_entries,
-                             enum htc_endpoint_id from_ep)
-{
-       struct htc_endpoint *endpoint;
-       int tot_credits = 0, i;
-       bool dist = false;
-
-       spin_lock_bh(&target->tx_lock);
-
-       for (i = 0; i < n_entries; i++, rpt++) {
-               if (rpt->eid >= ENDPOINT_MAX) {
-                       WARN_ON(1);
-                       spin_unlock_bh(&target->tx_lock);
-                       return;
-               }
-
-               endpoint = &target->endpoint[rpt->eid];
-
-               ath6kl_dbg(ATH6KL_DBG_CREDIT,
-                          "credit report ep %d credits %d\n",
-                          rpt->eid, rpt->credits);
-
-               endpoint->ep_st.tx_cred_rpt += 1;
-               endpoint->ep_st.cred_retnd += rpt->credits;
-
-               if (from_ep == rpt->eid) {
-                       /*
-                        * This credit report arrived on the same endpoint
-                        * indicating it arrived in an RX packet.
-                        */
-                       endpoint->ep_st.cred_from_rx += rpt->credits;
-                       endpoint->ep_st.cred_rpt_from_rx += 1;
-               } else if (from_ep == ENDPOINT_0) {
-                       /* credit arrived on endpoint 0 as a NULL message */
-                       endpoint->ep_st.cred_from_ep0 += rpt->credits;
-                       endpoint->ep_st.cred_rpt_ep0 += 1;
-               } else {
-                       endpoint->ep_st.cred_from_other += rpt->credits;
-                       endpoint->ep_st.cred_rpt_from_other += 1;
-               }
-
-               if (rpt->eid == ENDPOINT_0)
-                       /* always give endpoint 0 credits back */
-                       endpoint->cred_dist.credits += rpt->credits;
-               else {
-                       endpoint->cred_dist.cred_to_dist += rpt->credits;
-                       dist = true;
-               }
-
-               /*
-                * Refresh tx depth for distribution function that will
-                * recover these credits NOTE: this is only valid when
-                * there are credits to recover!
-                */
-               endpoint->cred_dist.txq_depth =
-                       get_queue_depth(&endpoint->txq);
-
-               tot_credits += rpt->credits;
-       }
-
-       if (dist) {
-               /*
-                * This was a credit return based on a completed send
-                * operations note, this is done with the lock held
-                */
-               ath6kl_credit_distribute(target->credit_info,
-                                        &target->cred_dist_list,
-                                        HTC_CREDIT_DIST_SEND_COMPLETE);
-       }
-
-       spin_unlock_bh(&target->tx_lock);
-
-       if (tot_credits)
-               htc_chk_ep_txq(target);
-}
-
-static int htc_parse_trailer(struct htc_target *target,
-                            struct htc_record_hdr *record,
-                            u8 *record_buf, u32 *next_lk_ahds,
-                            enum htc_endpoint_id endpoint,
-                            int *n_lk_ahds)
-{
-       struct htc_bundle_lkahd_rpt *bundle_lkahd_rpt;
-       struct htc_lookahead_report *lk_ahd;
-       int len;
-
-       switch (record->rec_id) {
-       case HTC_RECORD_CREDITS:
-               len = record->len / sizeof(struct htc_credit_report);
-               if (!len) {
-                       WARN_ON(1);
-                       return -EINVAL;
-               }
-
-               htc_proc_cred_rpt(target,
-                                 (struct htc_credit_report *) record_buf,
-                                 len, endpoint);
-               break;
-       case HTC_RECORD_LOOKAHEAD:
-               len = record->len / sizeof(*lk_ahd);
-               if (!len) {
-                       WARN_ON(1);
-                       return -EINVAL;
-               }
-
-               lk_ahd = (struct htc_lookahead_report *) record_buf;
-               if ((lk_ahd->pre_valid == ((~lk_ahd->post_valid) & 0xFF)) &&
-                   next_lk_ahds) {
-
-                       ath6kl_dbg(ATH6KL_DBG_HTC,
-                                  "htc rx lk_ahd found pre_valid 0x%x post_valid 0x%x\n",
-                                  lk_ahd->pre_valid, lk_ahd->post_valid);
-
-                       /* look ahead bytes are valid, copy them over */
-                       memcpy((u8 *)&next_lk_ahds[0], lk_ahd->lk_ahd, 4);
-
-                       ath6kl_dbg_dump(ATH6KL_DBG_HTC,
-                                       "htc rx next look ahead",
-                                       "", next_lk_ahds, 4);
-
-                       *n_lk_ahds = 1;
-               }
-               break;
-       case HTC_RECORD_LOOKAHEAD_BUNDLE:
-               len = record->len / sizeof(*bundle_lkahd_rpt);
-               if (!len || (len > HTC_HOST_MAX_MSG_PER_BUNDLE)) {
-                       WARN_ON(1);
-                       return -EINVAL;
-               }
-
-               if (next_lk_ahds) {
-                       int i;
-
-                       bundle_lkahd_rpt =
-                               (struct htc_bundle_lkahd_rpt *) record_buf;
-
-                       ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx bundle lk_ahd",
-                                       "", record_buf, record->len);
-
-                       for (i = 0; i < len; i++) {
-                               memcpy((u8 *)&next_lk_ahds[i],
-                                      bundle_lkahd_rpt->lk_ahd, 4);
-                               bundle_lkahd_rpt++;
-                       }
-
-                       *n_lk_ahds = i;
-               }
-               break;
-       default:
-               ath6kl_err("unhandled record: id:%d len:%d\n",
-                          record->rec_id, record->len);
-               break;
-       }
-
-       return 0;
-
-}
-
-static int htc_proc_trailer(struct htc_target *target,
-                           u8 *buf, int len, u32 *next_lk_ahds,
-                           int *n_lk_ahds, enum htc_endpoint_id endpoint)
-{
-       struct htc_record_hdr *record;
-       int orig_len;
-       int status;
-       u8 *record_buf;
-       u8 *orig_buf;
-
-       ath6kl_dbg(ATH6KL_DBG_HTC, "htc rx trailer len %d\n", len);
-       ath6kl_dbg_dump(ATH6KL_DBG_HTC, NULL, "", buf, len);
-
-       orig_buf = buf;
-       orig_len = len;
-       status = 0;
-
-       while (len > 0) {
-
-               if (len < sizeof(struct htc_record_hdr)) {
-                       status = -ENOMEM;
-                       break;
-               }
-               /* these are byte aligned structs */
-               record = (struct htc_record_hdr *) buf;
-               len -= sizeof(struct htc_record_hdr);
-               buf += sizeof(struct htc_record_hdr);
-
-               if (record->len > len) {
-                       ath6kl_err("invalid record len: %d (id:%d) buf has: %d bytes left\n",
-                                  record->len, record->rec_id, len);
-                       status = -ENOMEM;
-                       break;
-               }
-               record_buf = buf;
-
-               status = htc_parse_trailer(target, record, record_buf,
-                                          next_lk_ahds, endpoint, n_lk_ahds);
-
-               if (status)
-                       break;
-
-               /* advance buffer past this record for next time around */
-               buf += record->len;
-               len -= record->len;
-       }
-
-       if (status)
-               ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx bad trailer",
-                               "", orig_buf, orig_len);
-
-       return status;
-}
-
-static int ath6kl_htc_rx_process_hdr(struct htc_target *target,
-                                    struct htc_packet *packet,
-                                    u32 *next_lkahds, int *n_lkahds)
-{
-       int status = 0;
-       u16 payload_len;
-       u32 lk_ahd;
-       struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)packet->buf;
-
-       if (n_lkahds != NULL)
-               *n_lkahds = 0;
-
-       /*
-        * NOTE: we cannot assume the alignment of buf, so we use the safe
-        * macros to retrieve 16 bit fields.
-        */
-       payload_len = le16_to_cpu(get_unaligned(&htc_hdr->payld_len));
-
-       memcpy((u8 *)&lk_ahd, packet->buf, sizeof(lk_ahd));
-
-       if (packet->info.rx.rx_flags & HTC_RX_PKT_REFRESH_HDR) {
-               /*
-                * Refresh the expected header and the actual length as it
-                * was unknown when this packet was grabbed as part of the
-                * bundle.
-                */
-               packet->info.rx.exp_hdr = lk_ahd;
-               packet->act_len = payload_len + HTC_HDR_LENGTH;
-
-               /* validate the actual header that was refreshed  */
-               if (packet->act_len > packet->buf_len) {
-                       ath6kl_err("refreshed hdr payload len (%d) in bundled recv is invalid (hdr: 0x%X)\n",
-                                  payload_len, lk_ahd);
-                       /*
-                        * Limit this to max buffer just to print out some
-                        * of the buffer.
-                        */
-                       packet->act_len = min(packet->act_len, packet->buf_len);
-                       status = -ENOMEM;
-                       goto fail_rx;
-               }
-
-               if (packet->endpoint != htc_hdr->eid) {
-                       ath6kl_err("refreshed hdr ep (%d) does not match expected ep (%d)\n",
-                                  htc_hdr->eid, packet->endpoint);
-                       status = -ENOMEM;
-                       goto fail_rx;
-               }
-       }
-
-       if (lk_ahd != packet->info.rx.exp_hdr) {
-               ath6kl_err("%s(): lk_ahd mismatch! (pPkt:0x%p flags:0x%X)\n",
-                          __func__, packet, packet->info.rx.rx_flags);
-               ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx expected lk_ahd",
-                               "", &packet->info.rx.exp_hdr, 4);
-               ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx current header",
-                               "", (u8 *)&lk_ahd, sizeof(lk_ahd));
-               status = -ENOMEM;
-               goto fail_rx;
-       }
-
-       if (htc_hdr->flags & HTC_FLG_RX_TRAILER) {
-               if (htc_hdr->ctrl[0] < sizeof(struct htc_record_hdr) ||
-                   htc_hdr->ctrl[0] > payload_len) {
-                       ath6kl_err("%s(): invalid hdr (payload len should be :%d, CB[0] is:%d)\n",
-                                  __func__, payload_len, htc_hdr->ctrl[0]);
-                       status = -ENOMEM;
-                       goto fail_rx;
-               }
-
-               if (packet->info.rx.rx_flags & HTC_RX_PKT_IGNORE_LOOKAHEAD) {
-                       next_lkahds = NULL;
-                       n_lkahds = NULL;
-               }
-
-               status = htc_proc_trailer(target, packet->buf + HTC_HDR_LENGTH
-                                         + payload_len - htc_hdr->ctrl[0],
-                                         htc_hdr->ctrl[0], next_lkahds,
-                                          n_lkahds, packet->endpoint);
-
-               if (status)
-                       goto fail_rx;
-
-               packet->act_len -= htc_hdr->ctrl[0];
-       }
-
-       packet->buf += HTC_HDR_LENGTH;
-       packet->act_len -= HTC_HDR_LENGTH;
-
-fail_rx:
-       if (status)
-               ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx bad packet",
-                               "", packet->buf, packet->act_len);
-
-       return status;
-}
-
-static void ath6kl_htc_rx_complete(struct htc_endpoint *endpoint,
-                                  struct htc_packet *packet)
-{
-               ath6kl_dbg(ATH6KL_DBG_HTC,
-                          "htc rx complete ep %d packet 0x%p\n",
-                          endpoint->eid, packet);
-               endpoint->ep_cb.rx(endpoint->target, packet);
-}
-
-static int ath6kl_htc_rx_bundle(struct htc_target *target,
-                               struct list_head *rxq,
-                               struct list_head *sync_compq,
-                               int *n_pkt_fetched, bool part_bundle)
-{
-       struct hif_scatter_req *scat_req;
-       struct htc_packet *packet;
-       int rem_space = target->max_rx_bndl_sz;
-       int n_scat_pkt, status = 0, i, len;
-
-       n_scat_pkt = get_queue_depth(rxq);
-       n_scat_pkt = min(n_scat_pkt, target->msg_per_bndl_max);
-
-       if ((get_queue_depth(rxq) - n_scat_pkt) > 0) {
-               /*
-                * We were forced to split this bundle receive operation
-                * all packets in this partial bundle must have their
-                * lookaheads ignored.
-                */
-               part_bundle = true;
-
-               /*
-                * This would only happen if the target ignored our max
-                * bundle limit.
-                */
-               ath6kl_warn("%s(): partial bundle detected num:%d , %d\n",
-                           __func__, get_queue_depth(rxq), n_scat_pkt);
-       }
-
-       len = 0;
-
-       ath6kl_dbg(ATH6KL_DBG_HTC,
-                  "htc rx bundle depth %d pkts %d\n",
-                  get_queue_depth(rxq), n_scat_pkt);
-
-       scat_req = hif_scatter_req_get(target->dev->ar);
-
-       if (scat_req == NULL)
-               goto fail_rx_pkt;
-
-       for (i = 0; i < n_scat_pkt; i++) {
-               int pad_len;
-
-               packet = list_first_entry(rxq, struct htc_packet, list);
-               list_del(&packet->list);
-
-               pad_len = CALC_TXRX_PADDED_LEN(target,
-                                                  packet->act_len);
-
-               if ((rem_space - pad_len) < 0) {
-                       list_add(&packet->list, rxq);
-                       break;
-               }
-
-               rem_space -= pad_len;
-
-               if (part_bundle || (i < (n_scat_pkt - 1)))
-                       /*
-                        * Packet 0..n-1 cannot be checked for look-aheads
-                        * since we are fetching a bundle the last packet
-                        * however can have it's lookahead used
-                        */
-                       packet->info.rx.rx_flags |=
-                           HTC_RX_PKT_IGNORE_LOOKAHEAD;
-
-               /* NOTE: 1 HTC packet per scatter entry */
-               scat_req->scat_list[i].buf = packet->buf;
-               scat_req->scat_list[i].len = pad_len;
-
-               packet->info.rx.rx_flags |= HTC_RX_PKT_PART_OF_BUNDLE;
-
-               list_add_tail(&packet->list, sync_compq);
-
-               WARN_ON(!scat_req->scat_list[i].len);
-               len += scat_req->scat_list[i].len;
-       }
-
-       scat_req->len = len;
-       scat_req->scat_entries = i;
-
-       status = ath6kl_hif_submit_scat_req(target->dev, scat_req, true);
-
-       if (!status)
-               *n_pkt_fetched = i;
-
-       /* free scatter request */
-       hif_scatter_req_add(target->dev->ar, scat_req);
-
-fail_rx_pkt:
-
-       return status;
-}
-
-static int ath6kl_htc_rx_process_packets(struct htc_target *target,
-                                        struct list_head *comp_pktq,
-                                        u32 lk_ahds[],
-                                        int *n_lk_ahd)
-{
-       struct htc_packet *packet, *tmp_pkt;
-       struct htc_endpoint *ep;
-       int status = 0;
-
-       list_for_each_entry_safe(packet, tmp_pkt, comp_pktq, list) {
-               ep = &target->endpoint[packet->endpoint];
-
-               /* process header for each of the recv packet */
-               status = ath6kl_htc_rx_process_hdr(target, packet, lk_ahds,
-                                                  n_lk_ahd);
-               if (status)
-                       return status;
-
-               list_del(&packet->list);
-
-               if (list_empty(comp_pktq)) {
-                       /*
-                        * Last packet's more packet flag is set
-                        * based on the lookahead.
-                        */
-                       if (*n_lk_ahd > 0)
-                               ath6kl_htc_rx_set_indicate(lk_ahds[0],
-                                                          ep, packet);
-               } else
-                       /*
-                        * Packets in a bundle automatically have
-                        * this flag set.
-                        */
-                       packet->info.rx.indicat_flags |=
-                               HTC_RX_FLAGS_INDICATE_MORE_PKTS;
-
-               ath6kl_htc_rx_update_stats(ep, *n_lk_ahd);
-
-               if (packet->info.rx.rx_flags & HTC_RX_PKT_PART_OF_BUNDLE)
-                       ep->ep_st.rx_bundl += 1;
-
-               ath6kl_htc_rx_complete(ep, packet);
-       }
-
-       return status;
-}
-
-static int ath6kl_htc_rx_fetch(struct htc_target *target,
-                              struct list_head *rx_pktq,
-                              struct list_head *comp_pktq)
-{
-       int fetched_pkts;
-       bool part_bundle = false;
-       int status = 0;
-       struct list_head tmp_rxq;
-       struct htc_packet *packet, *tmp_pkt;
-
-       /* now go fetch the list of HTC packets */
-       while (!list_empty(rx_pktq)) {
-               fetched_pkts = 0;
-
-               INIT_LIST_HEAD(&tmp_rxq);
-
-               if (target->rx_bndl_enable && (get_queue_depth(rx_pktq) > 1)) {
-                       /*
-                        * There are enough packets to attempt a
-                        * bundle transfer and recv bundling is
-                        * allowed.
-                        */
-                       status = ath6kl_htc_rx_bundle(target, rx_pktq,
-                                                     &tmp_rxq,
-                                                     &fetched_pkts,
-                                                     part_bundle);
-                       if (status)
-                               goto fail_rx;
-
-                       if (!list_empty(rx_pktq))
-                               part_bundle = true;
-
-                       list_splice_tail_init(&tmp_rxq, comp_pktq);
-               }
-
-               if (!fetched_pkts) {
-
-                       packet = list_first_entry(rx_pktq, struct htc_packet,
-                                                  list);
-
-                       /* fully synchronous */
-                       packet->completion = NULL;
-
-                       if (!list_is_singular(rx_pktq))
-                               /*
-                                * look_aheads in all packet
-                                * except the last one in the
-                                * bundle must be ignored
-                                */
-                               packet->info.rx.rx_flags |=
-                                       HTC_RX_PKT_IGNORE_LOOKAHEAD;
-
-                       /* go fetch the packet */
-                       status = ath6kl_htc_rx_packet(target, packet,
-                                                     packet->act_len);
-
-                       list_move_tail(&packet->list, &tmp_rxq);
-
-                       if (status)
-                               goto fail_rx;
-
-                       list_splice_tail_init(&tmp_rxq, comp_pktq);
-               }
-       }
-
-       return 0;
-
-fail_rx:
-
-       /*
-        * Cleanup any packets we allocated but didn't use to
-        * actually fetch any packets.
-        */
-
-       list_for_each_entry_safe(packet, tmp_pkt, rx_pktq, list) {
-               list_del(&packet->list);
-               htc_reclaim_rxbuf(target, packet,
-                                 &target->endpoint[packet->endpoint]);
-       }
-
-       list_for_each_entry_safe(packet, tmp_pkt, &tmp_rxq, list) {
-               list_del(&packet->list);
-               htc_reclaim_rxbuf(target, packet,
-                                 &target->endpoint[packet->endpoint]);
-       }
-
-       return status;
-}
-
-int ath6kl_htc_rxmsg_pending_handler(struct htc_target *target,
-                                    u32 msg_look_ahead, int *num_pkts)
-{
-       struct htc_packet *packets, *tmp_pkt;
-       struct htc_endpoint *endpoint;
-       struct list_head rx_pktq, comp_pktq;
-       int status = 0;
-       u32 look_aheads[HTC_HOST_MAX_MSG_PER_BUNDLE];
-       int num_look_ahead = 1;
-       enum htc_endpoint_id id;
-       int n_fetched = 0;
-
-       INIT_LIST_HEAD(&comp_pktq);
-       *num_pkts = 0;
-
-       /*
-        * On first entry copy the look_aheads into our temp array for
-        * processing
-        */
-       look_aheads[0] = msg_look_ahead;
-
-       while (true) {
-
-               /*
-                * First lookahead sets the expected endpoint IDs for all
-                * packets in a bundle.
-                */
-               id = ((struct htc_frame_hdr *)&look_aheads[0])->eid;
-               endpoint = &target->endpoint[id];
-
-               if (id >= ENDPOINT_MAX) {
-                       ath6kl_err("MsgPend, invalid endpoint in look-ahead: %d\n",
-                                  id);
-                       status = -ENOMEM;
-                       break;
-               }
-
-               INIT_LIST_HEAD(&rx_pktq);
-               INIT_LIST_HEAD(&comp_pktq);
-
-               /*
-                * Try to allocate as many HTC RX packets indicated by the
-                * look_aheads.
-                */
-               status = ath6kl_htc_rx_alloc(target, look_aheads,
-                                            num_look_ahead, endpoint,
-                                            &rx_pktq);
-               if (status)
-                       break;
-
-               if (get_queue_depth(&rx_pktq) >= 2)
-                       /*
-                        * A recv bundle was detected, force IRQ status
-                        * re-check again
-                        */
-                       target->chk_irq_status_cnt = 1;
-
-               n_fetched += get_queue_depth(&rx_pktq);
-
-               num_look_ahead = 0;
-
-               status = ath6kl_htc_rx_fetch(target, &rx_pktq, &comp_pktq);
-
-               if (!status)
-                       ath6kl_htc_rx_chk_water_mark(endpoint);
-
-               /* Process fetched packets */
-               status = ath6kl_htc_rx_process_packets(target, &comp_pktq,
-                                                      look_aheads,
-                                                      &num_look_ahead);
-
-               if (!num_look_ahead || status)
-                       break;
-
-               /*
-                * For SYNCH processing, if we get here, we are running
-                * through the loop again due to a detected lookahead. Set
-                * flag that we should re-check IRQ status registers again
-                * before leaving IRQ processing, this can net better
-                * performance in high throughput situations.
-                */
-               target->chk_irq_status_cnt = 1;
-       }
-
-       if (status) {
-               ath6kl_err("failed to get pending recv messages: %d\n",
-                          status);
-
-               /* cleanup any packets in sync completion queue */
-               list_for_each_entry_safe(packets, tmp_pkt, &comp_pktq, list) {
-                       list_del(&packets->list);
-                       htc_reclaim_rxbuf(target, packets,
-                                         &target->endpoint[packets->endpoint]);
-               }
-
-               if (target->htc_flags & HTC_OP_STATE_STOPPING) {
-                       ath6kl_warn("host is going to stop blocking receiver for htc_stop\n");
-                       ath6kl_hif_rx_control(target->dev, false);
-               }
-       }
-
-       /*
-        * Before leaving, check to see if host ran out of buffers and
-        * needs to stop the receiver.
-        */
-       if (target->rx_st_flags & HTC_RECV_WAIT_BUFFERS) {
-               ath6kl_warn("host has no rx buffers blocking receiver to prevent overrun\n");
-               ath6kl_hif_rx_control(target->dev, false);
-       }
-       *num_pkts = n_fetched;
-
-       return status;
-}
-
-/*
- * Synchronously wait for a control message from the target,
- * This function is used at initialization time ONLY.  At init messages
- * on ENDPOINT 0 are expected.
- */
-static struct htc_packet *htc_wait_for_ctrl_msg(struct htc_target *target)
-{
-       struct htc_packet *packet = NULL;
-       struct htc_frame_hdr *htc_hdr;
-       u32 look_ahead;
-
-       if (ath6kl_hif_poll_mboxmsg_rx(target->dev, &look_ahead,
-                                      HTC_TARGET_RESPONSE_TIMEOUT))
-               return NULL;
-
-       ath6kl_dbg(ATH6KL_DBG_HTC,
-                  "htc rx wait ctrl look_ahead 0x%X\n", look_ahead);
-
-       htc_hdr = (struct htc_frame_hdr *)&look_ahead;
-
-       if (htc_hdr->eid != ENDPOINT_0)
-               return NULL;
-
-       packet = htc_get_control_buf(target, false);
-
-       if (!packet)
-               return NULL;
-
-       packet->info.rx.rx_flags = 0;
-       packet->info.rx.exp_hdr = look_ahead;
-       packet->act_len = le16_to_cpu(htc_hdr->payld_len) + HTC_HDR_LENGTH;
-
-       if (packet->act_len > packet->buf_len)
-               goto fail_ctrl_rx;
-
-       /* we want synchronous operation */
-       packet->completion = NULL;
-
-       /* get the message from the device, this will block */
-       if (ath6kl_htc_rx_packet(target, packet, packet->act_len))
-               goto fail_ctrl_rx;
-
-       /* process receive header */
-       packet->status = ath6kl_htc_rx_process_hdr(target, packet, NULL, NULL);
-
-       if (packet->status) {
-               ath6kl_err("htc_wait_for_ctrl_msg, ath6kl_htc_rx_process_hdr failed (status = %d)\n",
-                          packet->status);
-               goto fail_ctrl_rx;
-       }
-
-       return packet;
-
-fail_ctrl_rx:
-       if (packet != NULL) {
-               htc_rxpkt_reset(packet);
-               reclaim_rx_ctrl_buf(target, packet);
-       }
-
-       return NULL;
-}
-
-int ath6kl_htc_add_rxbuf_multiple(struct htc_target *target,
-                                 struct list_head *pkt_queue)
-{
-       struct htc_endpoint *endpoint;
-       struct htc_packet *first_pkt;
-       bool rx_unblock = false;
-       int status = 0, depth;
-
-       if (list_empty(pkt_queue))
-               return -ENOMEM;
-
-       first_pkt = list_first_entry(pkt_queue, struct htc_packet, list);
-
-       if (first_pkt->endpoint >= ENDPOINT_MAX)
-               return status;
-
-       depth = get_queue_depth(pkt_queue);
-
-       ath6kl_dbg(ATH6KL_DBG_HTC,
-                  "htc rx add multiple ep id %d cnt %d len %d\n",
-               first_pkt->endpoint, depth, first_pkt->buf_len);
-
-       endpoint = &target->endpoint[first_pkt->endpoint];
-
-       if (target->htc_flags & HTC_OP_STATE_STOPPING) {
-               struct htc_packet *packet, *tmp_pkt;
-
-               /* walk through queue and mark each one canceled */
-               list_for_each_entry_safe(packet, tmp_pkt, pkt_queue, list) {
-                       packet->status = -ECANCELED;
-                       list_del(&packet->list);
-                       ath6kl_htc_rx_complete(endpoint, packet);
-               }
-
-               return status;
-       }
-
-       spin_lock_bh(&target->rx_lock);
-
-       list_splice_tail_init(pkt_queue, &endpoint->rx_bufq);
-
-       /* check if we are blocked waiting for a new buffer */
-       if (target->rx_st_flags & HTC_RECV_WAIT_BUFFERS) {
-               if (target->ep_waiting == first_pkt->endpoint) {
-                       ath6kl_dbg(ATH6KL_DBG_HTC,
-                                  "htc rx blocked on ep %d, unblocking\n",
-                                  target->ep_waiting);
-                       target->rx_st_flags &= ~HTC_RECV_WAIT_BUFFERS;
-                       target->ep_waiting = ENDPOINT_MAX;
-                       rx_unblock = true;
-               }
-       }
-
-       spin_unlock_bh(&target->rx_lock);
-
-       if (rx_unblock && !(target->htc_flags & HTC_OP_STATE_STOPPING))
-               /* TODO : implement a buffer threshold count? */
-               ath6kl_hif_rx_control(target->dev, true);
-
-       return status;
-}
-
-void ath6kl_htc_flush_rx_buf(struct htc_target *target)
-{
-       struct htc_endpoint *endpoint;
-       struct htc_packet *packet, *tmp_pkt;
-       int i;
-
-       for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
-               endpoint = &target->endpoint[i];
-               if (!endpoint->svc_id)
-                       /* not in use.. */
-                       continue;
-
-               spin_lock_bh(&target->rx_lock);
-               list_for_each_entry_safe(packet, tmp_pkt,
-                                        &endpoint->rx_bufq, list) {
-                       list_del(&packet->list);
-                       spin_unlock_bh(&target->rx_lock);
-                       ath6kl_dbg(ATH6KL_DBG_HTC,
-                                  "htc rx flush pkt 0x%p  len %d  ep %d\n",
-                                  packet, packet->buf_len,
-                                  packet->endpoint);
-                       /*
-                        * packets in rx_bufq of endpoint 0 have originally
-                        * been queued from target->free_ctrl_rxbuf where
-                        * packet and packet->buf_start are allocated
-                        * separately using kmalloc(). For other endpoint
-                        * rx_bufq, it is allocated as skb where packet is
-                        * skb->head. Take care of this difference while freeing
-                        * the memory.
-                        */
-                       if (packet->endpoint == ENDPOINT_0) {
-                               kfree(packet->buf_start);
-                               kfree(packet);
-                       } else {
-                               dev_kfree_skb(packet->pkt_cntxt);
-                       }
-                       spin_lock_bh(&target->rx_lock);
-               }
-               spin_unlock_bh(&target->rx_lock);
-       }
-}
-
-int ath6kl_htc_conn_service(struct htc_target *target,
-                           struct htc_service_connect_req *conn_req,
-                           struct htc_service_connect_resp *conn_resp)
-{
-       struct htc_packet *rx_pkt = NULL;
-       struct htc_packet *tx_pkt = NULL;
-       struct htc_conn_service_resp *resp_msg;
-       struct htc_conn_service_msg *conn_msg;
-       struct htc_endpoint *endpoint;
-       enum htc_endpoint_id assigned_ep = ENDPOINT_MAX;
-       unsigned int max_msg_sz = 0;
-       int status = 0;
-       u16 msg_id;
-
-       ath6kl_dbg(ATH6KL_DBG_HTC,
-                  "htc connect service target 0x%p service id 0x%x\n",
-                  target, conn_req->svc_id);
-
-       if (conn_req->svc_id == HTC_CTRL_RSVD_SVC) {
-               /* special case for pseudo control service */
-               assigned_ep = ENDPOINT_0;
-               max_msg_sz = HTC_MAX_CTRL_MSG_LEN;
-       } else {
-               /* allocate a packet to send to the target */
-               tx_pkt = htc_get_control_buf(target, true);
-
-               if (!tx_pkt)
-                       return -ENOMEM;
-
-               conn_msg = (struct htc_conn_service_msg *)tx_pkt->buf;
-               memset(conn_msg, 0, sizeof(*conn_msg));
-               conn_msg->msg_id = cpu_to_le16(HTC_MSG_CONN_SVC_ID);
-               conn_msg->svc_id = cpu_to_le16(conn_req->svc_id);
-               conn_msg->conn_flags = cpu_to_le16(conn_req->conn_flags);
-
-               set_htc_pkt_info(tx_pkt, NULL, (u8 *) conn_msg,
-                                sizeof(*conn_msg) + conn_msg->svc_meta_len,
-                                ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
-
-               /* we want synchronous operation */
-               tx_pkt->completion = NULL;
-               ath6kl_htc_tx_prep_pkt(tx_pkt, 0, 0, 0);
-               status = ath6kl_htc_tx_issue(target, tx_pkt);
-
-               if (status)
-                       goto fail_tx;
-
-               /* wait for response */
-               rx_pkt = htc_wait_for_ctrl_msg(target);
-
-               if (!rx_pkt) {
-                       status = -ENOMEM;
-                       goto fail_tx;
-               }
-
-               resp_msg = (struct htc_conn_service_resp *)rx_pkt->buf;
-               msg_id = le16_to_cpu(resp_msg->msg_id);
-
-               if ((msg_id != HTC_MSG_CONN_SVC_RESP_ID) ||
-                   (rx_pkt->act_len < sizeof(*resp_msg))) {
-                       status = -ENOMEM;
-                       goto fail_tx;
-               }
-
-               conn_resp->resp_code = resp_msg->status;
-               /* check response status */
-               if (resp_msg->status != HTC_SERVICE_SUCCESS) {
-                       ath6kl_err("target failed service 0x%X connect request (status:%d)\n",
-                                  resp_msg->svc_id, resp_msg->status);
-                       status = -ENOMEM;
-                       goto fail_tx;
-               }
-
-               assigned_ep = (enum htc_endpoint_id)resp_msg->eid;
-               max_msg_sz = le16_to_cpu(resp_msg->max_msg_sz);
-       }
-
-       if (assigned_ep >= ENDPOINT_MAX || !max_msg_sz) {
-               status = -ENOMEM;
-               goto fail_tx;
-       }
-
-       endpoint = &target->endpoint[assigned_ep];
-       endpoint->eid = assigned_ep;
-       if (endpoint->svc_id) {
-               status = -ENOMEM;
-               goto fail_tx;
-       }
-
-       /* return assigned endpoint to caller */
-       conn_resp->endpoint = assigned_ep;
-       conn_resp->len_max = max_msg_sz;
-
-       /* setup the endpoint */
-
-       /* this marks the endpoint in use */
-       endpoint->svc_id = conn_req->svc_id;
-
-       endpoint->max_txq_depth = conn_req->max_txq_depth;
-       endpoint->len_max = max_msg_sz;
-       endpoint->ep_cb = conn_req->ep_cb;
-       endpoint->cred_dist.svc_id = conn_req->svc_id;
-       endpoint->cred_dist.htc_ep = endpoint;
-       endpoint->cred_dist.endpoint = assigned_ep;
-       endpoint->cred_dist.cred_sz = target->tgt_cred_sz;
-
-       switch (endpoint->svc_id) {
-       case WMI_DATA_BK_SVC:
-               endpoint->tx_drop_packet_threshold = MAX_DEF_COOKIE_NUM / 3;
-               break;
-       default:
-               endpoint->tx_drop_packet_threshold = MAX_HI_COOKIE_NUM;
-               break;
-       }
-
-       if (conn_req->max_rxmsg_sz) {
-               /*
-                * Override cred_per_msg calculation, this optimizes
-                * the credit-low indications since the host will actually
-                * issue smaller messages in the Send path.
-                */
-               if (conn_req->max_rxmsg_sz > max_msg_sz) {
-                       status = -ENOMEM;
-                       goto fail_tx;
-               }
-               endpoint->cred_dist.cred_per_msg =
-                   conn_req->max_rxmsg_sz / target->tgt_cred_sz;
-       } else
-               endpoint->cred_dist.cred_per_msg =
-                   max_msg_sz / target->tgt_cred_sz;
-
-       if (!endpoint->cred_dist.cred_per_msg)
-               endpoint->cred_dist.cred_per_msg = 1;
-
-       /* save local connection flags */
-       endpoint->conn_flags = conn_req->flags;
-
-fail_tx:
-       if (tx_pkt)
-               htc_reclaim_txctrl_buf(target, tx_pkt);
-
-       if (rx_pkt) {
-               htc_rxpkt_reset(rx_pkt);
-               reclaim_rx_ctrl_buf(target, rx_pkt);
-       }
-
-       return status;
-}
-
-static void reset_ep_state(struct htc_target *target)
-{
-       struct htc_endpoint *endpoint;
-       int i;
-
-       for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
-               endpoint = &target->endpoint[i];
-               memset(&endpoint->cred_dist, 0, sizeof(endpoint->cred_dist));
-               endpoint->svc_id = 0;
-               endpoint->len_max = 0;
-               endpoint->max_txq_depth = 0;
-               memset(&endpoint->ep_st, 0,
-                      sizeof(endpoint->ep_st));
-               INIT_LIST_HEAD(&endpoint->rx_bufq);
-               INIT_LIST_HEAD(&endpoint->txq);
-               endpoint->target = target;
-       }
-
-       /* reset distribution list */
-       /* FIXME: free existing entries */
-       INIT_LIST_HEAD(&target->cred_dist_list);
-}
-
-int ath6kl_htc_get_rxbuf_num(struct htc_target *target,
-                            enum htc_endpoint_id endpoint)
-{
-       int num;
-
-       spin_lock_bh(&target->rx_lock);
-       num = get_queue_depth(&(target->endpoint[endpoint].rx_bufq));
-       spin_unlock_bh(&target->rx_lock);
-       return num;
-}
-
-static void htc_setup_msg_bndl(struct htc_target *target)
-{
-       /* limit what HTC can handle */
-       target->msg_per_bndl_max = min(HTC_HOST_MAX_MSG_PER_BUNDLE,
-                                      target->msg_per_bndl_max);
-
-       if (ath6kl_hif_enable_scatter(target->dev->ar)) {
-               target->msg_per_bndl_max = 0;
-               return;
-       }
-
-       /* limit bundle what the device layer can handle */
-       target->msg_per_bndl_max = min(target->max_scat_entries,
-                                      target->msg_per_bndl_max);
-
-       ath6kl_dbg(ATH6KL_DBG_BOOT,
-                  "htc bundling allowed msg_per_bndl_max %d\n",
-                  target->msg_per_bndl_max);
-
-       /* Max rx bundle size is limited by the max tx bundle size */
-       target->max_rx_bndl_sz = target->max_xfer_szper_scatreq;
-       /* Max tx bundle size if limited by the extended mbox address range */
-       target->max_tx_bndl_sz = min(HIF_MBOX0_EXT_WIDTH,
-                                    target->max_xfer_szper_scatreq);
-
-       ath6kl_dbg(ATH6KL_DBG_BOOT, "htc max_rx_bndl_sz %d max_tx_bndl_sz %d\n",
-                  target->max_rx_bndl_sz, target->max_tx_bndl_sz);
-
-       if (target->max_tx_bndl_sz)
-               /* tx_bndl_mask is enabled per AC, each has 1 bit */
-               target->tx_bndl_mask = (1 << WMM_NUM_AC) - 1;
-
-       if (target->max_rx_bndl_sz)
-               target->rx_bndl_enable = true;
-
-       if ((target->tgt_cred_sz % target->block_sz) != 0) {
-               ath6kl_warn("credit size: %d is not block aligned! Disabling send bundling\n",
-                           target->tgt_cred_sz);
-
-               /*
-                * Disallow send bundling since the credit size is
-                * not aligned to a block size the I/O block
-                * padding will spill into the next credit buffer
-                * which is fatal.
-                */
-               target->tx_bndl_mask = 0;
-       }
-}
-
-int ath6kl_htc_wait_target(struct htc_target *target)
-{
-       struct htc_packet *packet = NULL;
-       struct htc_ready_ext_msg *rdy_msg;
-       struct htc_service_connect_req connect;
-       struct htc_service_connect_resp resp;
-       int status;
-
-       /* FIXME: remove once USB support is implemented */
-       if (target->dev->ar->hif_type == ATH6KL_HIF_TYPE_USB) {
-               ath6kl_err("HTC doesn't support USB yet. Patience!\n");
-               return -EOPNOTSUPP;
-       }
-
-       /* we should be getting 1 control message that the target is ready */
-       packet = htc_wait_for_ctrl_msg(target);
-
-       if (!packet)
-               return -ENOMEM;
-
-       /* we controlled the buffer creation so it's properly aligned */
-       rdy_msg = (struct htc_ready_ext_msg *)packet->buf;
-
-       if ((le16_to_cpu(rdy_msg->ver2_0_info.msg_id) != HTC_MSG_READY_ID) ||
-           (packet->act_len < sizeof(struct htc_ready_msg))) {
-               status = -ENOMEM;
-               goto fail_wait_target;
-       }
-
-       if (!rdy_msg->ver2_0_info.cred_cnt || !rdy_msg->ver2_0_info.cred_sz) {
-               status = -ENOMEM;
-               goto fail_wait_target;
-       }
-
-       target->tgt_creds = le16_to_cpu(rdy_msg->ver2_0_info.cred_cnt);
-       target->tgt_cred_sz = le16_to_cpu(rdy_msg->ver2_0_info.cred_sz);
-
-       ath6kl_dbg(ATH6KL_DBG_BOOT,
-                  "htc target ready credits %d size %d\n",
-                  target->tgt_creds, target->tgt_cred_sz);
-
-       /* check if this is an extended ready message */
-       if (packet->act_len >= sizeof(struct htc_ready_ext_msg)) {
-               /* this is an extended message */
-               target->htc_tgt_ver = rdy_msg->htc_ver;
-               target->msg_per_bndl_max = rdy_msg->msg_per_htc_bndl;
-       } else {
-               /* legacy */
-               target->htc_tgt_ver = HTC_VERSION_2P0;
-               target->msg_per_bndl_max = 0;
-       }
-
-       ath6kl_dbg(ATH6KL_DBG_BOOT, "htc using protocol %s (%d)\n",
-                  (target->htc_tgt_ver == HTC_VERSION_2P0) ? "2.0" : ">= 2.1",
-                  target->htc_tgt_ver);
-
-       if (target->msg_per_bndl_max > 0)
-               htc_setup_msg_bndl(target);
-
-       /* setup our pseudo HTC control endpoint connection */
-       memset(&connect, 0, sizeof(connect));
-       memset(&resp, 0, sizeof(resp));
-       connect.ep_cb.rx = htc_ctrl_rx;
-       connect.ep_cb.rx_refill = NULL;
-       connect.ep_cb.tx_full = NULL;
-       connect.max_txq_depth = NUM_CONTROL_BUFFERS;
-       connect.svc_id = HTC_CTRL_RSVD_SVC;
-
-       /* connect fake service */
-       status = ath6kl_htc_conn_service((void *)target, &connect, &resp);
-
-       if (status)
-               /*
-                * FIXME: this call doesn't make sense, the caller should
-                * call ath6kl_htc_cleanup() when it wants remove htc
-                */
-               ath6kl_hif_cleanup_scatter(target->dev->ar);
-
-fail_wait_target:
-       if (packet) {
-               htc_rxpkt_reset(packet);
-               reclaim_rx_ctrl_buf(target, packet);
-       }
-
-       return status;
-}
-
-/*
- * Start HTC, enable interrupts and let the target know
- * host has finished setup.
- */
-int ath6kl_htc_start(struct htc_target *target)
-{
-       struct htc_packet *packet;
-       int status;
-
-       memset(&target->dev->irq_proc_reg, 0,
-              sizeof(target->dev->irq_proc_reg));
-
-       /* Disable interrupts at the chip level */
-       ath6kl_hif_disable_intrs(target->dev);
-
-       target->htc_flags = 0;
-       target->rx_st_flags = 0;
-
-       /* Push control receive buffers into htc control endpoint */
-       while ((packet = htc_get_control_buf(target, false)) != NULL) {
-               status = htc_add_rxbuf(target, packet);
-               if (status)
-                       return status;
-       }
-
-       /* NOTE: the first entry in the distribution list is ENDPOINT_0 */
-       ath6kl_credit_init(target->credit_info, &target->cred_dist_list,
-                          target->tgt_creds);
-
-       dump_cred_dist_stats(target);
-
-       /* Indicate to the target of the setup completion */
-       status = htc_setup_tx_complete(target);
-
-       if (status)
-               return status;
-
-       /* unmask interrupts */
-       status = ath6kl_hif_unmask_intrs(target->dev);
-
-       if (status)
-               ath6kl_htc_stop(target);
-
-       return status;
-}
-
-static int ath6kl_htc_reset(struct htc_target *target)
-{
-       u32 block_size, ctrl_bufsz;
-       struct htc_packet *packet;
-       int i;
-
-       reset_ep_state(target);
-
-       block_size = target->dev->ar->mbox_info.block_size;
-
-       ctrl_bufsz = (block_size > HTC_MAX_CTRL_MSG_LEN) ?
-                     (block_size + HTC_HDR_LENGTH) :
-                     (HTC_MAX_CTRL_MSG_LEN + HTC_HDR_LENGTH);
-
-       for (i = 0; i < NUM_CONTROL_BUFFERS; i++) {
-               packet = kzalloc(sizeof(*packet), GFP_KERNEL);
-               if (!packet)
-                       return -ENOMEM;
-
-               packet->buf_start = kzalloc(ctrl_bufsz, GFP_KERNEL);
-               if (!packet->buf_start) {
-                       kfree(packet);
-                       return -ENOMEM;
-               }
-
-               packet->buf_len = ctrl_bufsz;
-               if (i < NUM_CONTROL_RX_BUFFERS) {
-                       packet->act_len = 0;
-                       packet->buf = packet->buf_start;
-                       packet->endpoint = ENDPOINT_0;
-                       list_add_tail(&packet->list, &target->free_ctrl_rxbuf);
-               } else
-                       list_add_tail(&packet->list, &target->free_ctrl_txbuf);
-       }
-
-       return 0;
-}
-
-/* htc_stop: stop interrupt reception, and flush all queued buffers */
-void ath6kl_htc_stop(struct htc_target *target)
-{
-       spin_lock_bh(&target->htc_lock);
-       target->htc_flags |= HTC_OP_STATE_STOPPING;
-       spin_unlock_bh(&target->htc_lock);
-
-       /*
-        * Masking interrupts is a synchronous operation, when this
-        * function returns all pending HIF I/O has completed, we can
-        * safely flush the queues.
-        */
-       ath6kl_hif_mask_intrs(target->dev);
-
-       ath6kl_htc_flush_txep_all(target);
-
-       ath6kl_htc_flush_rx_buf(target);
-
-       ath6kl_htc_reset(target);
-}
-
-void *ath6kl_htc_create(struct ath6kl *ar)
-{
-       struct htc_target *target = NULL;
-       int status = 0;
-
-       target = kzalloc(sizeof(*target), GFP_KERNEL);
-       if (!target) {
-               ath6kl_err("unable to allocate memory\n");
-               return NULL;
-       }
-
-       target->dev = kzalloc(sizeof(*target->dev), GFP_KERNEL);
-       if (!target->dev) {
-               ath6kl_err("unable to allocate memory\n");
-               status = -ENOMEM;
-               goto err_htc_cleanup;
-       }
-
-       spin_lock_init(&target->htc_lock);
-       spin_lock_init(&target->rx_lock);
-       spin_lock_init(&target->tx_lock);
-
-       INIT_LIST_HEAD(&target->free_ctrl_txbuf);
-       INIT_LIST_HEAD(&target->free_ctrl_rxbuf);
-       INIT_LIST_HEAD(&target->cred_dist_list);
-
-       target->dev->ar = ar;
-       target->dev->htc_cnxt = target;
-       target->ep_waiting = ENDPOINT_MAX;
-
-       status = ath6kl_hif_setup(target->dev);
-       if (status)
-               goto err_htc_cleanup;
-
-       status = ath6kl_htc_reset(target);
-       if (status)
-               goto err_htc_cleanup;
-
-       return target;
-
-err_htc_cleanup:
-       ath6kl_htc_cleanup(target);
-
-       return NULL;
-}
-
-/* cleanup the HTC instance */
-void ath6kl_htc_cleanup(struct htc_target *target)
-{
-       struct htc_packet *packet, *tmp_packet;
-
-       /* FIXME: remove check once USB support is implemented */
-       if (target->dev->ar->hif_type != ATH6KL_HIF_TYPE_USB)
-               ath6kl_hif_cleanup_scatter(target->dev->ar);
-
-       list_for_each_entry_safe(packet, tmp_packet,
-                                &target->free_ctrl_txbuf, list) {
-               list_del(&packet->list);
-               kfree(packet->buf_start);
-               kfree(packet);
-       }
-
-       list_for_each_entry_safe(packet, tmp_packet,
-                                &target->free_ctrl_rxbuf, list) {
-               list_del(&packet->list);
-               kfree(packet->buf_start);
-               kfree(packet);
-       }
-
-       kfree(target->dev);
-       kfree(target);
-}
index 5027ccc36b6249549b5db9e410819ec620a64582..a2c8ff8097939240f4fecc4e238203b6a5c7de73 100644 (file)
@@ -25,6 +25,7 @@
 /* send direction */
 #define HTC_FLAGS_NEED_CREDIT_UPDATE (1 << 0)
 #define HTC_FLAGS_SEND_BUNDLE        (1 << 1)
+#define HTC_FLAGS_TX_FIXUP_NETBUF    (1 << 2)
 
 /* receive direction */
 #define HTC_FLG_RX_UNUSED        (1 << 0)
 #define HTC_CONN_FLGS_THRESH_LVL_THREE_QUAT    0x2
 #define HTC_CONN_FLGS_REDUCE_CRED_DRIB         0x4
 #define HTC_CONN_FLGS_THRESH_MASK              0x3
+/* disable credit flow control on a specific service */
+#define HTC_CONN_FLGS_DISABLE_CRED_FLOW_CTRL          (1 << 3)
+#define HTC_CONN_FLGS_SET_RECV_ALLOC_SHIFT    8
+#define HTC_CONN_FLGS_SET_RECV_ALLOC_MASK     0xFF00
 
 /* connect response status codes */
 #define HTC_SERVICE_SUCCESS      0
@@ -75,6 +80,7 @@
 #define HTC_RECORD_LOOKAHEAD_BUNDLE 3
 
 #define HTC_SETUP_COMP_FLG_RX_BNDL_EN     (1 << 0)
+#define HTC_SETUP_COMP_FLG_DISABLE_TX_CREDIT_FLOW (1 << 1)
 
 #define MAKE_SERVICE_ID(group, index) \
        (int)(((int)group << 8) | (int)(index))
 
 /* HTC operational parameters */
 #define HTC_TARGET_RESPONSE_TIMEOUT        2000        /* in ms */
+#define HTC_TARGET_RESPONSE_POLL_WAIT      10
+#define HTC_TARGET_RESPONSE_POLL_COUNT     200
 #define HTC_TARGET_DEBUG_INTR_MASK         0x01
 #define HTC_TARGET_CREDIT_INTR_MASK        0xF0
 
 
 #define HTC_RECV_WAIT_BUFFERS        (1 << 0)
 #define HTC_OP_STATE_STOPPING        (1 << 0)
+#define HTC_OP_STATE_SETUP_COMPLETE  (1 << 1)
 
 /*
  * The frame header length and message formats defined herein were selected
@@ -311,6 +320,14 @@ struct htc_packet {
 
        void (*completion) (struct htc_target *, struct htc_packet *);
        struct htc_target *context;
+
+       /*
+        * optimization for network-oriented data, the HTC packet
+        * can pass the network buffer corresponding to the HTC packet
+        * lower layers may optimized the transfer knowing this is
+        * a network buffer
+        */
+       struct sk_buff *skb;
 };
 
 enum htc_send_full_action {
@@ -319,12 +336,14 @@ enum htc_send_full_action {
 };
 
 struct htc_ep_callbacks {
+       void (*tx_complete) (struct htc_target *, struct htc_packet *);
        void (*rx) (struct htc_target *, struct htc_packet *);
        void (*rx_refill) (struct htc_target *, enum htc_endpoint_id endpoint);
        enum htc_send_full_action (*tx_full) (struct htc_target *,
                                              struct htc_packet *);
        struct htc_packet *(*rx_allocthresh) (struct htc_target *,
                                              enum htc_endpoint_id, int);
+       void (*tx_comp_multi) (struct htc_target *, struct list_head *);
        int rx_alloc_thresh;
        int rx_refill_thresh;
 };
@@ -502,6 +521,13 @@ struct htc_endpoint {
        u32 conn_flags;
        struct htc_endpoint_stats ep_st;
        u16 tx_drop_packet_threshold;
+
+       struct {
+               u8 pipeid_ul;
+               u8 pipeid_dl;
+               struct list_head tx_lookup_queue;
+               bool tx_credit_flow_enabled;
+       } pipe;
 };
 
 struct htc_control_buffer {
@@ -509,6 +535,42 @@ struct htc_control_buffer {
        u8 *buf;
 };
 
+struct htc_pipe_txcredit_alloc {
+       u16 service_id;
+       u8 credit_alloc;
+};
+
+enum htc_send_queue_result {
+       HTC_SEND_QUEUE_OK = 0,  /* packet was queued */
+       HTC_SEND_QUEUE_DROP = 1,        /* this packet should be dropped */
+};
+
+struct ath6kl_htc_ops {
+       void* (*create)(struct ath6kl *ar);
+       int (*wait_target)(struct htc_target *target);
+       int (*start)(struct htc_target *target);
+       int (*conn_service)(struct htc_target *target,
+                           struct htc_service_connect_req *req,
+                           struct htc_service_connect_resp *resp);
+       int  (*tx)(struct htc_target *target, struct htc_packet *packet);
+       void (*stop)(struct htc_target *target);
+       void (*cleanup)(struct htc_target *target);
+       void (*flush_txep)(struct htc_target *target,
+                          enum htc_endpoint_id endpoint, u16 tag);
+       void (*flush_rx_buf)(struct htc_target *target);
+       void (*activity_changed)(struct htc_target *target,
+                                enum htc_endpoint_id endpoint,
+                                bool active);
+       int (*get_rxbuf_num)(struct htc_target *target,
+                            enum htc_endpoint_id endpoint);
+       int (*add_rxbuf_multiple)(struct htc_target *target,
+                                 struct list_head *pktq);
+       int (*credit_setup)(struct htc_target *target,
+                           struct ath6kl_htc_credit_info *cred_info);
+       int (*tx_complete)(struct ath6kl *ar, struct sk_buff *skb);
+       int (*rx_complete)(struct ath6kl *ar, struct sk_buff *skb, u8 pipe);
+};
+
 struct ath6kl_device;
 
 /* our HTC target state */
@@ -557,36 +619,19 @@ struct htc_target {
 
        /* counts the number of Tx without bundling continously per AC */
        u32 ac_tx_count[WMM_NUM_AC];
+
+       struct {
+               struct htc_packet *htc_packet_pool;
+               u8 ctrl_response_buf[HTC_MAX_CTRL_MSG_LEN];
+               int ctrl_response_len;
+               bool ctrl_response_valid;
+               struct htc_pipe_txcredit_alloc txcredit_alloc[ENDPOINT_MAX];
+       } pipe;
 };
 
-void *ath6kl_htc_create(struct ath6kl *ar);
-void ath6kl_htc_set_credit_dist(struct htc_target *target,
-                               struct ath6kl_htc_credit_info *cred_info,
-                               u16 svc_pri_order[], int len);
-int ath6kl_htc_wait_target(struct htc_target *target);
-int ath6kl_htc_start(struct htc_target *target);
-int ath6kl_htc_conn_service(struct htc_target *target,
-                           struct htc_service_connect_req *req,
-                           struct htc_service_connect_resp *resp);
-int ath6kl_htc_tx(struct htc_target *target, struct htc_packet *packet);
-void ath6kl_htc_stop(struct htc_target *target);
-void ath6kl_htc_cleanup(struct htc_target *target);
-void ath6kl_htc_flush_txep(struct htc_target *target,
-                          enum htc_endpoint_id endpoint, u16 tag);
-void ath6kl_htc_flush_rx_buf(struct htc_target *target);
-void ath6kl_htc_indicate_activity_change(struct htc_target *target,
-                                        enum htc_endpoint_id endpoint,
-                                        bool active);
-int ath6kl_htc_get_rxbuf_num(struct htc_target *target,
-                            enum htc_endpoint_id endpoint);
-int ath6kl_htc_add_rxbuf_multiple(struct htc_target *target,
-                                 struct list_head *pktq);
 int ath6kl_htc_rxmsg_pending_handler(struct htc_target *target,
                                     u32 msg_look_ahead, int *n_pkts);
 
-int ath6kl_credit_setup(void *htc_handle,
-                       struct ath6kl_htc_credit_info *cred_info);
-
 static inline void set_htc_pkt_info(struct htc_packet *packet, void *context,
                                    u8 *buf, unsigned int len,
                                    enum htc_endpoint_id eid, u16 tag)
@@ -626,4 +671,7 @@ static inline int get_queue_depth(struct list_head *queue)
        return depth;
 }
 
+void ath6kl_htc_pipe_attach(struct ath6kl *ar);
+void ath6kl_htc_mbox_attach(struct ath6kl *ar);
+
 #endif
diff --git a/drivers/net/wireless/ath/ath6kl/htc_mbox.c b/drivers/net/wireless/ath/ath6kl/htc_mbox.c
new file mode 100644 (file)
index 0000000..065e615
--- /dev/null
@@ -0,0 +1,2923 @@
+/*
+ * Copyright (c) 2007-2011 Atheros Communications Inc.
+ * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "core.h"
+#include "hif.h"
+#include "debug.h"
+#include "hif-ops.h"
+#include <asm/unaligned.h>
+
+#define CALC_TXRX_PADDED_LEN(dev, len)  (__ALIGN_MASK((len), (dev)->block_mask))
+
+static void ath6kl_htc_mbox_cleanup(struct htc_target *target);
+static void ath6kl_htc_mbox_stop(struct htc_target *target);
+static int ath6kl_htc_mbox_add_rxbuf_multiple(struct htc_target *target,
+                                             struct list_head *pkt_queue);
+static void ath6kl_htc_set_credit_dist(struct htc_target *target,
+                                      struct ath6kl_htc_credit_info *cred_info,
+                                      u16 svc_pri_order[], int len);
+
+/* threshold to re-enable Tx bundling for an AC*/
+#define TX_RESUME_BUNDLE_THRESHOLD     1500
+
+/* Functions for Tx credit handling */
+static void ath6kl_credit_deposit(struct ath6kl_htc_credit_info *cred_info,
+                                 struct htc_endpoint_credit_dist *ep_dist,
+                                 int credits)
+{
+       ath6kl_dbg(ATH6KL_DBG_CREDIT, "credit deposit ep %d credits %d\n",
+                  ep_dist->endpoint, credits);
+
+       ep_dist->credits += credits;
+       ep_dist->cred_assngd += credits;
+       cred_info->cur_free_credits -= credits;
+}
+
+static void ath6kl_credit_init(struct ath6kl_htc_credit_info *cred_info,
+                              struct list_head *ep_list,
+                              int tot_credits)
+{
+       struct htc_endpoint_credit_dist *cur_ep_dist;
+       int count;
+
+       ath6kl_dbg(ATH6KL_DBG_CREDIT, "credit init total %d\n", tot_credits);
+
+       cred_info->cur_free_credits = tot_credits;
+       cred_info->total_avail_credits = tot_credits;
+
+       list_for_each_entry(cur_ep_dist, ep_list, list) {
+               if (cur_ep_dist->endpoint == ENDPOINT_0)
+                       continue;
+
+               cur_ep_dist->cred_min = cur_ep_dist->cred_per_msg;
+
+               if (tot_credits > 4) {
+                       if ((cur_ep_dist->svc_id == WMI_DATA_BK_SVC) ||
+                           (cur_ep_dist->svc_id == WMI_DATA_BE_SVC)) {
+                               ath6kl_credit_deposit(cred_info,
+                                                     cur_ep_dist,
+                                                     cur_ep_dist->cred_min);
+                               cur_ep_dist->dist_flags |= HTC_EP_ACTIVE;
+                       }
+               }
+
+               if (cur_ep_dist->svc_id == WMI_CONTROL_SVC) {
+                       ath6kl_credit_deposit(cred_info, cur_ep_dist,
+                                             cur_ep_dist->cred_min);
+                       /*
+                        * Control service is always marked active, it
+                        * never goes inactive EVER.
+                        */
+                       cur_ep_dist->dist_flags |= HTC_EP_ACTIVE;
+               } else if (cur_ep_dist->svc_id == WMI_DATA_BK_SVC)
+                       /* this is the lowest priority data endpoint */
+                       /* FIXME: this looks fishy, check */
+                       cred_info->lowestpri_ep_dist = cur_ep_dist->list;
+
+               /*
+                * Streams have to be created (explicit | implicit) for all
+                * kinds of traffic. BE endpoints are also inactive in the
+                * beginning. When BE traffic starts it creates implicit
+                * streams that redistributes credits.
+                *
+                * Note: all other endpoints have minimums set but are
+                * initially given NO credits. credits will be distributed
+                * as traffic activity demands
+                */
+       }
+
+       WARN_ON(cred_info->cur_free_credits <= 0);
+
+       list_for_each_entry(cur_ep_dist, ep_list, list) {
+               if (cur_ep_dist->endpoint == ENDPOINT_0)
+                       continue;
+
+               if (cur_ep_dist->svc_id == WMI_CONTROL_SVC)
+                       cur_ep_dist->cred_norm = cur_ep_dist->cred_per_msg;
+               else {
+                       /*
+                        * For the remaining data endpoints, we assume that
+                        * each cred_per_msg are the same. We use a simple
+                        * calculation here, we take the remaining credits
+                        * and determine how many max messages this can
+                        * cover and then set each endpoint's normal value
+                        * equal to 3/4 this amount.
+                        */
+                       count = (cred_info->cur_free_credits /
+                                cur_ep_dist->cred_per_msg)
+                               * cur_ep_dist->cred_per_msg;
+                       count = (count * 3) >> 2;
+                       count = max(count, cur_ep_dist->cred_per_msg);
+                       cur_ep_dist->cred_norm = count;
+
+               }
+
+               ath6kl_dbg(ATH6KL_DBG_CREDIT,
+                          "credit ep %d svc_id %d credits %d per_msg %d norm %d min %d\n",
+                          cur_ep_dist->endpoint,
+                          cur_ep_dist->svc_id,
+                          cur_ep_dist->credits,
+                          cur_ep_dist->cred_per_msg,
+                          cur_ep_dist->cred_norm,
+                          cur_ep_dist->cred_min);
+       }
+}
+
+/* initialize and setup credit distribution */
+static int ath6kl_htc_mbox_credit_setup(struct htc_target *htc_target,
+                              struct ath6kl_htc_credit_info *cred_info)
+{
+       u16 servicepriority[5];
+
+       memset(cred_info, 0, sizeof(struct ath6kl_htc_credit_info));
+
+       servicepriority[0] = WMI_CONTROL_SVC;  /* highest */
+       servicepriority[1] = WMI_DATA_VO_SVC;
+       servicepriority[2] = WMI_DATA_VI_SVC;
+       servicepriority[3] = WMI_DATA_BE_SVC;
+       servicepriority[4] = WMI_DATA_BK_SVC; /* lowest */
+
+       /* set priority list */
+       ath6kl_htc_set_credit_dist(htc_target, cred_info, servicepriority, 5);
+
+       return 0;
+}
+
+/* reduce an ep's credits back to a set limit */
+static void ath6kl_credit_reduce(struct ath6kl_htc_credit_info *cred_info,
+                                struct htc_endpoint_credit_dist *ep_dist,
+                                int limit)
+{
+       int credits;
+
+       ath6kl_dbg(ATH6KL_DBG_CREDIT, "credit reduce ep %d limit %d\n",
+                  ep_dist->endpoint, limit);
+
+       ep_dist->cred_assngd = limit;
+
+       if (ep_dist->credits <= limit)
+               return;
+
+       credits = ep_dist->credits - limit;
+       ep_dist->credits -= credits;
+       cred_info->cur_free_credits += credits;
+}
+
+static void ath6kl_credit_update(struct ath6kl_htc_credit_info *cred_info,
+                                struct list_head *epdist_list)
+{
+       struct htc_endpoint_credit_dist *cur_list;
+
+       list_for_each_entry(cur_list, epdist_list, list) {
+               if (cur_list->endpoint == ENDPOINT_0)
+                       continue;
+
+               if (cur_list->cred_to_dist > 0) {
+                       cur_list->credits += cur_list->cred_to_dist;
+                       cur_list->cred_to_dist = 0;
+
+                       if (cur_list->credits > cur_list->cred_assngd)
+                               ath6kl_credit_reduce(cred_info,
+                                                    cur_list,
+                                                    cur_list->cred_assngd);
+
+                       if (cur_list->credits > cur_list->cred_norm)
+                               ath6kl_credit_reduce(cred_info, cur_list,
+                                                    cur_list->cred_norm);
+
+                       if (!(cur_list->dist_flags & HTC_EP_ACTIVE)) {
+                               if (cur_list->txq_depth == 0)
+                                       ath6kl_credit_reduce(cred_info,
+                                                            cur_list, 0);
+                       }
+               }
+       }
+}
+
+/*
+ * HTC has an endpoint that needs credits, ep_dist is the endpoint in
+ * question.
+ */
+static void ath6kl_credit_seek(struct ath6kl_htc_credit_info *cred_info,
+                               struct htc_endpoint_credit_dist *ep_dist)
+{
+       struct htc_endpoint_credit_dist *curdist_list;
+       int credits = 0;
+       int need;
+
+       if (ep_dist->svc_id == WMI_CONTROL_SVC)
+               goto out;
+
+       if ((ep_dist->svc_id == WMI_DATA_VI_SVC) ||
+           (ep_dist->svc_id == WMI_DATA_VO_SVC))
+               if ((ep_dist->cred_assngd >= ep_dist->cred_norm))
+                       goto out;
+
+       /*
+        * For all other services, we follow a simple algorithm of:
+        *
+        * 1. checking the free pool for credits
+        * 2. checking lower priority endpoints for credits to take
+        */
+
+       credits = min(cred_info->cur_free_credits, ep_dist->seek_cred);
+
+       if (credits >= ep_dist->seek_cred)
+               goto out;
+
+       /*
+        * We don't have enough in the free pool, try taking away from
+        * lower priority services The rule for taking away credits:
+        *
+        *   1. Only take from lower priority endpoints
+        *   2. Only take what is allocated above the minimum (never
+        *      starve an endpoint completely)
+        *   3. Only take what you need.
+        */
+
+       list_for_each_entry_reverse(curdist_list,
+                                   &cred_info->lowestpri_ep_dist,
+                                   list) {
+               if (curdist_list == ep_dist)
+                       break;
+
+               need = ep_dist->seek_cred - cred_info->cur_free_credits;
+
+               if ((curdist_list->cred_assngd - need) >=
+                    curdist_list->cred_min) {
+                       /*
+                        * The current one has been allocated more than
+                        * it's minimum and it has enough credits assigned
+                        * above it's minimum to fulfill our need try to
+                        * take away just enough to fulfill our need.
+                        */
+                       ath6kl_credit_reduce(cred_info, curdist_list,
+                                            curdist_list->cred_assngd - need);
+
+                       if (cred_info->cur_free_credits >=
+                           ep_dist->seek_cred)
+                               break;
+               }
+
+               if (curdist_list->endpoint == ENDPOINT_0)
+                       break;
+       }
+
+       credits = min(cred_info->cur_free_credits, ep_dist->seek_cred);
+
+out:
+       /* did we find some credits? */
+       if (credits)
+               ath6kl_credit_deposit(cred_info, ep_dist, credits);
+
+       ep_dist->seek_cred = 0;
+}
+
+/* redistribute credits based on activity change */
+static void ath6kl_credit_redistribute(struct ath6kl_htc_credit_info *info,
+                                      struct list_head *ep_dist_list)
+{
+       struct htc_endpoint_credit_dist *curdist_list;
+
+       list_for_each_entry(curdist_list, ep_dist_list, list) {
+               if (curdist_list->endpoint == ENDPOINT_0)
+                       continue;
+
+               if ((curdist_list->svc_id == WMI_DATA_BK_SVC)  ||
+                   (curdist_list->svc_id == WMI_DATA_BE_SVC))
+                       curdist_list->dist_flags |= HTC_EP_ACTIVE;
+
+               if ((curdist_list->svc_id != WMI_CONTROL_SVC) &&
+                   !(curdist_list->dist_flags & HTC_EP_ACTIVE)) {
+                       if (curdist_list->txq_depth == 0)
+                               ath6kl_credit_reduce(info, curdist_list, 0);
+                       else
+                               ath6kl_credit_reduce(info,
+                                                    curdist_list,
+                                                    curdist_list->cred_min);
+               }
+       }
+}
+
+/*
+ *
+ * This function is invoked whenever endpoints require credit
+ * distributions. A lock is held while this function is invoked, this
+ * function shall NOT block. The ep_dist_list is a list of distribution
+ * structures in prioritized order as defined by the call to the
+ * htc_set_credit_dist() api.
+ */
+static void ath6kl_credit_distribute(struct ath6kl_htc_credit_info *cred_info,
+                                    struct list_head *ep_dist_list,
+                             enum htc_credit_dist_reason reason)
+{
+       switch (reason) {
+       case HTC_CREDIT_DIST_SEND_COMPLETE:
+               ath6kl_credit_update(cred_info, ep_dist_list);
+               break;
+       case HTC_CREDIT_DIST_ACTIVITY_CHANGE:
+               ath6kl_credit_redistribute(cred_info, ep_dist_list);
+               break;
+       default:
+               break;
+       }
+
+       WARN_ON(cred_info->cur_free_credits > cred_info->total_avail_credits);
+       WARN_ON(cred_info->cur_free_credits < 0);
+}
+
+static void ath6kl_htc_tx_buf_align(u8 **buf, unsigned long len)
+{
+       u8 *align_addr;
+
+       if (!IS_ALIGNED((unsigned long) *buf, 4)) {
+               align_addr = PTR_ALIGN(*buf - 4, 4);
+               memmove(align_addr, *buf, len);
+               *buf = align_addr;
+       }
+}
+
+static void ath6kl_htc_tx_prep_pkt(struct htc_packet *packet, u8 flags,
+                                  int ctrl0, int ctrl1)
+{
+       struct htc_frame_hdr *hdr;
+
+       packet->buf -= HTC_HDR_LENGTH;
+       hdr =  (struct htc_frame_hdr *)packet->buf;
+
+       /* Endianess? */
+       put_unaligned((u16)packet->act_len, &hdr->payld_len);
+       hdr->flags = flags;
+       hdr->eid = packet->endpoint;
+       hdr->ctrl[0] = ctrl0;
+       hdr->ctrl[1] = ctrl1;
+}
+
+static void htc_reclaim_txctrl_buf(struct htc_target *target,
+                                  struct htc_packet *pkt)
+{
+       spin_lock_bh(&target->htc_lock);
+       list_add_tail(&pkt->list, &target->free_ctrl_txbuf);
+       spin_unlock_bh(&target->htc_lock);
+}
+
+static struct htc_packet *htc_get_control_buf(struct htc_target *target,
+                                             bool tx)
+{
+       struct htc_packet *packet = NULL;
+       struct list_head *buf_list;
+
+       buf_list = tx ? &target->free_ctrl_txbuf : &target->free_ctrl_rxbuf;
+
+       spin_lock_bh(&target->htc_lock);
+
+       if (list_empty(buf_list)) {
+               spin_unlock_bh(&target->htc_lock);
+               return NULL;
+       }
+
+       packet = list_first_entry(buf_list, struct htc_packet, list);
+       list_del(&packet->list);
+       spin_unlock_bh(&target->htc_lock);
+
+       if (tx)
+               packet->buf = packet->buf_start + HTC_HDR_LENGTH;
+
+       return packet;
+}
+
+static void htc_tx_comp_update(struct htc_target *target,
+                              struct htc_endpoint *endpoint,
+                              struct htc_packet *packet)
+{
+       packet->completion = NULL;
+       packet->buf += HTC_HDR_LENGTH;
+
+       if (!packet->status)
+               return;
+
+       ath6kl_err("req failed (status:%d, ep:%d, len:%d creds:%d)\n",
+                  packet->status, packet->endpoint, packet->act_len,
+                  packet->info.tx.cred_used);
+
+       /* on failure to submit, reclaim credits for this packet */
+       spin_lock_bh(&target->tx_lock);
+       endpoint->cred_dist.cred_to_dist +=
+                               packet->info.tx.cred_used;
+       endpoint->cred_dist.txq_depth = get_queue_depth(&endpoint->txq);
+
+       ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx ctxt 0x%p dist 0x%p\n",
+                  target->credit_info, &target->cred_dist_list);
+
+       ath6kl_credit_distribute(target->credit_info,
+                                &target->cred_dist_list,
+                                HTC_CREDIT_DIST_SEND_COMPLETE);
+
+       spin_unlock_bh(&target->tx_lock);
+}
+
+static void htc_tx_complete(struct htc_endpoint *endpoint,
+                           struct list_head *txq)
+{
+       if (list_empty(txq))
+               return;
+
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "htc tx complete ep %d pkts %d\n",
+                  endpoint->eid, get_queue_depth(txq));
+
+       ath6kl_tx_complete(endpoint->target, txq);
+}
+
+static void htc_tx_comp_handler(struct htc_target *target,
+                               struct htc_packet *packet)
+{
+       struct htc_endpoint *endpoint = &target->endpoint[packet->endpoint];
+       struct list_head container;
+
+       ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx complete seqno %d\n",
+                  packet->info.tx.seqno);
+
+       htc_tx_comp_update(target, endpoint, packet);
+       INIT_LIST_HEAD(&container);
+       list_add_tail(&packet->list, &container);
+       /* do completion */
+       htc_tx_complete(endpoint, &container);
+}
+
+static void htc_async_tx_scat_complete(struct htc_target *target,
+                                      struct hif_scatter_req *scat_req)
+{
+       struct htc_endpoint *endpoint;
+       struct htc_packet *packet;
+       struct list_head tx_compq;
+       int i;
+
+       INIT_LIST_HEAD(&tx_compq);
+
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "htc tx scat complete len %d entries %d\n",
+                  scat_req->len, scat_req->scat_entries);
+
+       if (scat_req->status)
+               ath6kl_err("send scatter req failed: %d\n", scat_req->status);
+
+       packet = scat_req->scat_list[0].packet;
+       endpoint = &target->endpoint[packet->endpoint];
+
+       /* walk through the scatter list and process */
+       for (i = 0; i < scat_req->scat_entries; i++) {
+               packet = scat_req->scat_list[i].packet;
+               if (!packet) {
+                       WARN_ON(1);
+                       return;
+               }
+
+               packet->status = scat_req->status;
+               htc_tx_comp_update(target, endpoint, packet);
+               list_add_tail(&packet->list, &tx_compq);
+       }
+
+       /* free scatter request */
+       hif_scatter_req_add(target->dev->ar, scat_req);
+
+       /* complete all packets */
+       htc_tx_complete(endpoint, &tx_compq);
+}
+
+static int ath6kl_htc_tx_issue(struct htc_target *target,
+                              struct htc_packet *packet)
+{
+       int status;
+       bool sync = false;
+       u32 padded_len, send_len;
+
+       if (!packet->completion)
+               sync = true;
+
+       send_len = packet->act_len + HTC_HDR_LENGTH;
+
+       padded_len = CALC_TXRX_PADDED_LEN(target, send_len);
+
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "htc tx issue len %d seqno %d padded_len %d mbox 0x%X %s\n",
+                  send_len, packet->info.tx.seqno, padded_len,
+                  target->dev->ar->mbox_info.htc_addr,
+                  sync ? "sync" : "async");
+
+       if (sync) {
+               status = hif_read_write_sync(target->dev->ar,
+                               target->dev->ar->mbox_info.htc_addr,
+                                packet->buf, padded_len,
+                                HIF_WR_SYNC_BLOCK_INC);
+
+               packet->status = status;
+               packet->buf += HTC_HDR_LENGTH;
+       } else
+               status = hif_write_async(target->dev->ar,
+                               target->dev->ar->mbox_info.htc_addr,
+                               packet->buf, padded_len,
+                               HIF_WR_ASYNC_BLOCK_INC, packet);
+
+       return status;
+}
+
+static int htc_check_credits(struct htc_target *target,
+                            struct htc_endpoint *ep, u8 *flags,
+                            enum htc_endpoint_id eid, unsigned int len,
+                            int *req_cred)
+{
+
+       *req_cred = (len > target->tgt_cred_sz) ?
+                    DIV_ROUND_UP(len, target->tgt_cred_sz) : 1;
+
+       ath6kl_dbg(ATH6KL_DBG_CREDIT, "credit check need %d got %d\n",
+                  *req_cred, ep->cred_dist.credits);
+
+       if (ep->cred_dist.credits < *req_cred) {
+               if (eid == ENDPOINT_0)
+                       return -EINVAL;
+
+               /* Seek more credits */
+               ep->cred_dist.seek_cred = *req_cred - ep->cred_dist.credits;
+
+               ath6kl_credit_seek(target->credit_info, &ep->cred_dist);
+
+               ep->cred_dist.seek_cred = 0;
+
+               if (ep->cred_dist.credits < *req_cred) {
+                       ath6kl_dbg(ATH6KL_DBG_CREDIT,
+                                  "credit not found for ep %d\n",
+                                  eid);
+                       return -EINVAL;
+               }
+       }
+
+       ep->cred_dist.credits -= *req_cred;
+       ep->ep_st.cred_cosumd += *req_cred;
+
+        /* When we are getting low on credits, ask for more */
+       if (ep->cred_dist.credits < ep->cred_dist.cred_per_msg) {
+               ep->cred_dist.seek_cred =
+               ep->cred_dist.cred_per_msg - ep->cred_dist.credits;
+
+               ath6kl_credit_seek(target->credit_info, &ep->cred_dist);
+
+               /* see if we were successful in getting more */
+               if (ep->cred_dist.credits < ep->cred_dist.cred_per_msg) {
+                       /* tell the target we need credits ASAP! */
+                       *flags |= HTC_FLAGS_NEED_CREDIT_UPDATE;
+                       ep->ep_st.cred_low_indicate += 1;
+                       ath6kl_dbg(ATH6KL_DBG_CREDIT,
+                                  "credit we need credits asap\n");
+               }
+       }
+
+       return 0;
+}
+
+static void ath6kl_htc_tx_pkts_get(struct htc_target *target,
+                                  struct htc_endpoint *endpoint,
+                                  struct list_head *queue)
+{
+       int req_cred;
+       u8 flags;
+       struct htc_packet *packet;
+       unsigned int len;
+
+       while (true) {
+
+               flags = 0;
+
+               if (list_empty(&endpoint->txq))
+                       break;
+               packet = list_first_entry(&endpoint->txq, struct htc_packet,
+                                         list);
+
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "htc tx got packet 0x%p queue depth %d\n",
+                          packet, get_queue_depth(&endpoint->txq));
+
+               len = CALC_TXRX_PADDED_LEN(target,
+                                          packet->act_len + HTC_HDR_LENGTH);
+
+               if (htc_check_credits(target, endpoint, &flags,
+                                     packet->endpoint, len, &req_cred))
+                       break;
+
+               /* now we can fully move onto caller's queue */
+               packet = list_first_entry(&endpoint->txq, struct htc_packet,
+                                         list);
+               list_move_tail(&packet->list, queue);
+
+               /* save the number of credits this packet consumed */
+               packet->info.tx.cred_used = req_cred;
+
+               /* all TX packets are handled asynchronously */
+               packet->completion = htc_tx_comp_handler;
+               packet->context = target;
+               endpoint->ep_st.tx_issued += 1;
+
+               /* save send flags */
+               packet->info.tx.flags = flags;
+               packet->info.tx.seqno = endpoint->seqno;
+               endpoint->seqno++;
+       }
+}
+
+/* See if the padded tx length falls on a credit boundary */
+static int htc_get_credit_padding(unsigned int cred_sz, int *len,
+                                 struct htc_endpoint *ep)
+{
+       int rem_cred, cred_pad;
+
+       rem_cred = *len % cred_sz;
+
+       /* No padding needed */
+       if  (!rem_cred)
+               return 0;
+
+       if (!(ep->conn_flags & HTC_FLGS_TX_BNDL_PAD_EN))
+               return -1;
+
+       /*
+        * The transfer consumes a "partial" credit, this
+        * packet cannot be bundled unless we add
+        * additional "dummy" padding (max 255 bytes) to
+        * consume the entire credit.
+        */
+       cred_pad = *len < cred_sz ? (cred_sz - *len) : rem_cred;
+
+       if ((cred_pad > 0) && (cred_pad <= 255))
+               *len += cred_pad;
+       else
+               /* The amount of padding is too large, send as non-bundled */
+               return -1;
+
+       return cred_pad;
+}
+
+static int ath6kl_htc_tx_setup_scat_list(struct htc_target *target,
+                                        struct htc_endpoint *endpoint,
+                                        struct hif_scatter_req *scat_req,
+                                        int n_scat,
+                                        struct list_head *queue)
+{
+       struct htc_packet *packet;
+       int i, len, rem_scat, cred_pad;
+       int status = 0;
+       u8 flags;
+
+       rem_scat = target->max_tx_bndl_sz;
+
+       for (i = 0; i < n_scat; i++) {
+               scat_req->scat_list[i].packet = NULL;
+
+               if (list_empty(queue))
+                       break;
+
+               packet = list_first_entry(queue, struct htc_packet, list);
+               len = CALC_TXRX_PADDED_LEN(target,
+                                          packet->act_len + HTC_HDR_LENGTH);
+
+               cred_pad = htc_get_credit_padding(target->tgt_cred_sz,
+                                                 &len, endpoint);
+               if (cred_pad < 0 || rem_scat < len) {
+                       status = -ENOSPC;
+                       break;
+               }
+
+               rem_scat -= len;
+               /* now remove it from the queue */
+               list_del(&packet->list);
+
+               scat_req->scat_list[i].packet = packet;
+               /* prepare packet and flag message as part of a send bundle */
+               flags = packet->info.tx.flags | HTC_FLAGS_SEND_BUNDLE;
+               ath6kl_htc_tx_prep_pkt(packet, flags,
+                                      cred_pad, packet->info.tx.seqno);
+               /* Make sure the buffer is 4-byte aligned */
+               ath6kl_htc_tx_buf_align(&packet->buf,
+                                       packet->act_len + HTC_HDR_LENGTH);
+               scat_req->scat_list[i].buf = packet->buf;
+               scat_req->scat_list[i].len = len;
+
+               scat_req->len += len;
+               scat_req->scat_entries++;
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "htc tx adding (%d) pkt 0x%p seqno %d len %d remaining %d\n",
+                          i, packet, packet->info.tx.seqno, len, rem_scat);
+       }
+
+       /* Roll back scatter setup in case of any failure */
+       if (scat_req->scat_entries < HTC_MIN_HTC_MSGS_TO_BUNDLE) {
+               for (i = scat_req->scat_entries - 1; i >= 0; i--) {
+                       packet = scat_req->scat_list[i].packet;
+                       if (packet) {
+                               packet->buf += HTC_HDR_LENGTH;
+                               list_add(&packet->list, queue);
+                       }
+               }
+               return -EAGAIN;
+       }
+
+       return status;
+}
+
+/*
+ * Drain a queue and send as bundles this function may return without fully
+ * draining the queue when
+ *
+ *    1. scatter resources are exhausted
+ *    2. a message that will consume a partial credit will stop the
+ *    bundling process early
+ *    3. we drop below the minimum number of messages for a bundle
+ */
+static void ath6kl_htc_tx_bundle(struct htc_endpoint *endpoint,
+                                struct list_head *queue,
+                                int *sent_bundle, int *n_bundle_pkts)
+{
+       struct htc_target *target = endpoint->target;
+       struct hif_scatter_req *scat_req = NULL;
+       int n_scat, n_sent_bundle = 0, tot_pkts_bundle = 0;
+       int status;
+       u32 txb_mask;
+       u8 ac = WMM_NUM_AC;
+
+       if ((HTC_CTRL_RSVD_SVC != endpoint->svc_id) ||
+           (WMI_CONTROL_SVC != endpoint->svc_id))
+               ac = target->dev->ar->ep2ac_map[endpoint->eid];
+
+       while (true) {
+               status = 0;
+               n_scat = get_queue_depth(queue);
+               n_scat = min(n_scat, target->msg_per_bndl_max);
+
+               if (n_scat < HTC_MIN_HTC_MSGS_TO_BUNDLE)
+                       /* not enough to bundle */
+                       break;
+
+               scat_req = hif_scatter_req_get(target->dev->ar);
+
+               if (!scat_req) {
+                       /* no scatter resources  */
+                       ath6kl_dbg(ATH6KL_DBG_HTC,
+                                  "htc tx no more scatter resources\n");
+                       break;
+               }
+
+               if ((ac < WMM_NUM_AC) && (ac != WMM_AC_BK)) {
+                       if (WMM_AC_BE == ac)
+                               /*
+                                * BE, BK have priorities and bit
+                                * positions reversed
+                                */
+                               txb_mask = (1 << WMM_AC_BK);
+                       else
+                               /*
+                                * any AC with priority lower than
+                                * itself
+                                */
+                               txb_mask = ((1 << ac) - 1);
+               /*
+                * when the scatter request resources drop below a
+                * certain threshold, disable Tx bundling for all
+                * AC's with priority lower than the current requesting
+                * AC. Otherwise re-enable Tx bundling for them
+                */
+               if (scat_req->scat_q_depth < ATH6KL_SCATTER_REQS)
+                       target->tx_bndl_mask &= ~txb_mask;
+               else
+                       target->tx_bndl_mask |= txb_mask;
+               }
+
+               ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx pkts to scatter: %d\n",
+                          n_scat);
+
+               scat_req->len = 0;
+               scat_req->scat_entries = 0;
+
+               status = ath6kl_htc_tx_setup_scat_list(target, endpoint,
+                                                      scat_req, n_scat,
+                                                      queue);
+               if (status == -EAGAIN) {
+                       hif_scatter_req_add(target->dev->ar, scat_req);
+                       break;
+               }
+
+               /* send path is always asynchronous */
+               scat_req->complete = htc_async_tx_scat_complete;
+               n_sent_bundle++;
+               tot_pkts_bundle += scat_req->scat_entries;
+
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "htc tx scatter bytes %d entries %d\n",
+                          scat_req->len, scat_req->scat_entries);
+               ath6kl_hif_submit_scat_req(target->dev, scat_req, false);
+
+               if (status)
+                       break;
+       }
+
+       *sent_bundle = n_sent_bundle;
+       *n_bundle_pkts = tot_pkts_bundle;
+       ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx bundle sent %d pkts\n",
+                  n_sent_bundle);
+
+       return;
+}
+
+static void ath6kl_htc_tx_from_queue(struct htc_target *target,
+                                    struct htc_endpoint *endpoint)
+{
+       struct list_head txq;
+       struct htc_packet *packet;
+       int bundle_sent;
+       int n_pkts_bundle;
+       u8 ac = WMM_NUM_AC;
+
+       spin_lock_bh(&target->tx_lock);
+
+       endpoint->tx_proc_cnt++;
+       if (endpoint->tx_proc_cnt > 1) {
+               endpoint->tx_proc_cnt--;
+               spin_unlock_bh(&target->tx_lock);
+               ath6kl_dbg(ATH6KL_DBG_HTC, "htc tx busy\n");
+               return;
+       }
+
+       /*
+        * drain the endpoint TX queue for transmission as long
+        * as we have enough credits.
+        */
+       INIT_LIST_HEAD(&txq);
+
+       if ((HTC_CTRL_RSVD_SVC != endpoint->svc_id) ||
+           (WMI_CONTROL_SVC != endpoint->svc_id))
+               ac = target->dev->ar->ep2ac_map[endpoint->eid];
+
+       while (true) {
+
+               if (list_empty(&endpoint->txq))
+                       break;
+
+               ath6kl_htc_tx_pkts_get(target, endpoint, &txq);
+
+               if (list_empty(&txq))
+                       break;
+
+               spin_unlock_bh(&target->tx_lock);
+
+               bundle_sent = 0;
+               n_pkts_bundle = 0;
+
+               while (true) {
+                       /* try to send a bundle on each pass */
+                       if ((target->tx_bndl_mask) &&
+                           (get_queue_depth(&txq) >=
+                           HTC_MIN_HTC_MSGS_TO_BUNDLE)) {
+                               int temp1 = 0, temp2 = 0;
+
+                               /* check if bundling is enabled for an AC */
+                               if (target->tx_bndl_mask & (1 << ac)) {
+                                       ath6kl_htc_tx_bundle(endpoint, &txq,
+                                                            &temp1, &temp2);
+                                       bundle_sent += temp1;
+                                       n_pkts_bundle += temp2;
+                               }
+                       }
+
+                       if (list_empty(&txq))
+                               break;
+
+                       packet = list_first_entry(&txq, struct htc_packet,
+                                                 list);
+                       list_del(&packet->list);
+
+                       ath6kl_htc_tx_prep_pkt(packet, packet->info.tx.flags,
+                                              0, packet->info.tx.seqno);
+                       ath6kl_htc_tx_issue(target, packet);
+               }
+
+               spin_lock_bh(&target->tx_lock);
+
+               endpoint->ep_st.tx_bundles += bundle_sent;
+               endpoint->ep_st.tx_pkt_bundled += n_pkts_bundle;
+
+               /*
+                * if an AC has bundling disabled and no tx bundling
+                * has occured continously for a certain number of TX,
+                * enable tx bundling for this AC
+                */
+               if (!bundle_sent) {
+                       if (!(target->tx_bndl_mask & (1 << ac)) &&
+                           (ac < WMM_NUM_AC)) {
+                               if (++target->ac_tx_count[ac] >=
+                                       TX_RESUME_BUNDLE_THRESHOLD) {
+                                       target->ac_tx_count[ac] = 0;
+                                       target->tx_bndl_mask |= (1 << ac);
+                               }
+                       }
+               } else {
+                       /* tx bundling will reset the counter */
+                       if (ac < WMM_NUM_AC)
+                               target->ac_tx_count[ac] = 0;
+               }
+       }
+
+       endpoint->tx_proc_cnt = 0;
+       spin_unlock_bh(&target->tx_lock);
+}
+
+static bool ath6kl_htc_tx_try(struct htc_target *target,
+                             struct htc_endpoint *endpoint,
+                             struct htc_packet *tx_pkt)
+{
+       struct htc_ep_callbacks ep_cb;
+       int txq_depth;
+       bool overflow = false;
+
+       ep_cb = endpoint->ep_cb;
+
+       spin_lock_bh(&target->tx_lock);
+       txq_depth = get_queue_depth(&endpoint->txq);
+       spin_unlock_bh(&target->tx_lock);
+
+       if (txq_depth >= endpoint->max_txq_depth)
+               overflow = true;
+
+       if (overflow)
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "htc tx overflow ep %d depth %d max %d\n",
+                          endpoint->eid, txq_depth,
+                          endpoint->max_txq_depth);
+
+       if (overflow && ep_cb.tx_full) {
+               if (ep_cb.tx_full(endpoint->target, tx_pkt) ==
+                   HTC_SEND_FULL_DROP) {
+                       endpoint->ep_st.tx_dropped += 1;
+                       return false;
+               }
+       }
+
+       spin_lock_bh(&target->tx_lock);
+       list_add_tail(&tx_pkt->list, &endpoint->txq);
+       spin_unlock_bh(&target->tx_lock);
+
+       ath6kl_htc_tx_from_queue(target, endpoint);
+
+       return true;
+}
+
+static void htc_chk_ep_txq(struct htc_target *target)
+{
+       struct htc_endpoint *endpoint;
+       struct htc_endpoint_credit_dist *cred_dist;
+
+       /*
+        * Run through the credit distribution list to see if there are
+        * packets queued. NOTE: no locks need to be taken since the
+        * distribution list is not dynamic (cannot be re-ordered) and we
+        * are not modifying any state.
+        */
+       list_for_each_entry(cred_dist, &target->cred_dist_list, list) {
+               endpoint = cred_dist->htc_ep;
+
+               spin_lock_bh(&target->tx_lock);
+               if (!list_empty(&endpoint->txq)) {
+                       ath6kl_dbg(ATH6KL_DBG_HTC,
+                                  "htc creds ep %d credits %d pkts %d\n",
+                                  cred_dist->endpoint,
+                                  endpoint->cred_dist.credits,
+                                  get_queue_depth(&endpoint->txq));
+                       spin_unlock_bh(&target->tx_lock);
+                       /*
+                        * Try to start the stalled queue, this list is
+                        * ordered by priority. If there are credits
+                        * available the highest priority queue will get a
+                        * chance to reclaim credits from lower priority
+                        * ones.
+                        */
+                       ath6kl_htc_tx_from_queue(target, endpoint);
+                       spin_lock_bh(&target->tx_lock);
+               }
+               spin_unlock_bh(&target->tx_lock);
+       }
+}
+
+static int htc_setup_tx_complete(struct htc_target *target)
+{
+       struct htc_packet *send_pkt = NULL;
+       int status;
+
+       send_pkt = htc_get_control_buf(target, true);
+
+       if (!send_pkt)
+               return -ENOMEM;
+
+       if (target->htc_tgt_ver >= HTC_VERSION_2P1) {
+               struct htc_setup_comp_ext_msg *setup_comp_ext;
+               u32 flags = 0;
+
+               setup_comp_ext =
+                   (struct htc_setup_comp_ext_msg *)send_pkt->buf;
+               memset(setup_comp_ext, 0, sizeof(*setup_comp_ext));
+               setup_comp_ext->msg_id =
+                       cpu_to_le16(HTC_MSG_SETUP_COMPLETE_EX_ID);
+
+               if (target->msg_per_bndl_max > 0) {
+                       /* Indicate HTC bundling to the target */
+                       flags |= HTC_SETUP_COMP_FLG_RX_BNDL_EN;
+                       setup_comp_ext->msg_per_rxbndl =
+                                               target->msg_per_bndl_max;
+               }
+
+               memcpy(&setup_comp_ext->flags, &flags,
+                      sizeof(setup_comp_ext->flags));
+               set_htc_pkt_info(send_pkt, NULL, (u8 *) setup_comp_ext,
+                                sizeof(struct htc_setup_comp_ext_msg),
+                                ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
+
+       } else {
+               struct htc_setup_comp_msg *setup_comp;
+               setup_comp = (struct htc_setup_comp_msg *)send_pkt->buf;
+               memset(setup_comp, 0, sizeof(struct htc_setup_comp_msg));
+               setup_comp->msg_id = cpu_to_le16(HTC_MSG_SETUP_COMPLETE_ID);
+               set_htc_pkt_info(send_pkt, NULL, (u8 *) setup_comp,
+                                sizeof(struct htc_setup_comp_msg),
+                                ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
+       }
+
+       /* we want synchronous operation */
+       send_pkt->completion = NULL;
+       ath6kl_htc_tx_prep_pkt(send_pkt, 0, 0, 0);
+       status = ath6kl_htc_tx_issue(target, send_pkt);
+
+       if (send_pkt != NULL)
+               htc_reclaim_txctrl_buf(target, send_pkt);
+
+       return status;
+}
+
+static void ath6kl_htc_set_credit_dist(struct htc_target *target,
+                               struct ath6kl_htc_credit_info *credit_info,
+                               u16 srvc_pri_order[], int list_len)
+{
+       struct htc_endpoint *endpoint;
+       int i, ep;
+
+       target->credit_info = credit_info;
+
+       list_add_tail(&target->endpoint[ENDPOINT_0].cred_dist.list,
+                     &target->cred_dist_list);
+
+       for (i = 0; i < list_len; i++) {
+               for (ep = ENDPOINT_1; ep < ENDPOINT_MAX; ep++) {
+                       endpoint = &target->endpoint[ep];
+                       if (endpoint->svc_id == srvc_pri_order[i]) {
+                               list_add_tail(&endpoint->cred_dist.list,
+                                             &target->cred_dist_list);
+                               break;
+                       }
+               }
+               if (ep >= ENDPOINT_MAX) {
+                       WARN_ON(1);
+                       return;
+               }
+       }
+}
+
+static int ath6kl_htc_mbox_tx(struct htc_target *target,
+                             struct htc_packet *packet)
+{
+       struct htc_endpoint *endpoint;
+       struct list_head queue;
+
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "htc tx ep id %d buf 0x%p len %d\n",
+                  packet->endpoint, packet->buf, packet->act_len);
+
+       if (packet->endpoint >= ENDPOINT_MAX) {
+               WARN_ON(1);
+               return -EINVAL;
+       }
+
+       endpoint = &target->endpoint[packet->endpoint];
+
+       if (!ath6kl_htc_tx_try(target, endpoint, packet)) {
+               packet->status = (target->htc_flags & HTC_OP_STATE_STOPPING) ?
+                                -ECANCELED : -ENOSPC;
+               INIT_LIST_HEAD(&queue);
+               list_add(&packet->list, &queue);
+               htc_tx_complete(endpoint, &queue);
+       }
+
+       return 0;
+}
+
+/* flush endpoint TX queue */
+static void ath6kl_htc_mbox_flush_txep(struct htc_target *target,
+                          enum htc_endpoint_id eid, u16 tag)
+{
+       struct htc_packet *packet, *tmp_pkt;
+       struct list_head discard_q, container;
+       struct htc_endpoint *endpoint = &target->endpoint[eid];
+
+       if (!endpoint->svc_id) {
+               WARN_ON(1);
+               return;
+       }
+
+       /* initialize the discard queue */
+       INIT_LIST_HEAD(&discard_q);
+
+       spin_lock_bh(&target->tx_lock);
+
+       list_for_each_entry_safe(packet, tmp_pkt, &endpoint->txq, list) {
+               if ((tag == HTC_TX_PACKET_TAG_ALL) ||
+                   (tag == packet->info.tx.tag))
+                       list_move_tail(&packet->list, &discard_q);
+       }
+
+       spin_unlock_bh(&target->tx_lock);
+
+       list_for_each_entry_safe(packet, tmp_pkt, &discard_q, list) {
+               packet->status = -ECANCELED;
+               list_del(&packet->list);
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "htc tx flushing pkt 0x%p len %d  ep %d tag 0x%x\n",
+                          packet, packet->act_len,
+                          packet->endpoint, packet->info.tx.tag);
+
+               INIT_LIST_HEAD(&container);
+               list_add_tail(&packet->list, &container);
+               htc_tx_complete(endpoint, &container);
+       }
+
+}
+
+static void ath6kl_htc_flush_txep_all(struct htc_target *target)
+{
+       struct htc_endpoint *endpoint;
+       int i;
+
+       dump_cred_dist_stats(target);
+
+       for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
+               endpoint = &target->endpoint[i];
+               if (endpoint->svc_id == 0)
+                       /* not in use.. */
+                       continue;
+               ath6kl_htc_mbox_flush_txep(target, i, HTC_TX_PACKET_TAG_ALL);
+       }
+}
+
+static void ath6kl_htc_mbox_activity_changed(struct htc_target *target,
+                                            enum htc_endpoint_id eid,
+                                            bool active)
+{
+       struct htc_endpoint *endpoint = &target->endpoint[eid];
+       bool dist = false;
+
+       if (endpoint->svc_id == 0) {
+               WARN_ON(1);
+               return;
+       }
+
+       spin_lock_bh(&target->tx_lock);
+
+       if (active) {
+               if (!(endpoint->cred_dist.dist_flags & HTC_EP_ACTIVE)) {
+                       endpoint->cred_dist.dist_flags |= HTC_EP_ACTIVE;
+                       dist = true;
+               }
+       } else {
+               if (endpoint->cred_dist.dist_flags & HTC_EP_ACTIVE) {
+                       endpoint->cred_dist.dist_flags &= ~HTC_EP_ACTIVE;
+                       dist = true;
+               }
+       }
+
+       if (dist) {
+               endpoint->cred_dist.txq_depth =
+                       get_queue_depth(&endpoint->txq);
+
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "htc tx activity ctxt 0x%p dist 0x%p\n",
+                          target->credit_info, &target->cred_dist_list);
+
+               ath6kl_credit_distribute(target->credit_info,
+                                        &target->cred_dist_list,
+                                        HTC_CREDIT_DIST_ACTIVITY_CHANGE);
+       }
+
+       spin_unlock_bh(&target->tx_lock);
+
+       if (dist && !active)
+               htc_chk_ep_txq(target);
+}
+
+/* HTC Rx */
+
+static inline void ath6kl_htc_rx_update_stats(struct htc_endpoint *endpoint,
+                                             int n_look_ahds)
+{
+       endpoint->ep_st.rx_pkts++;
+       if (n_look_ahds == 1)
+               endpoint->ep_st.rx_lkahds++;
+       else if (n_look_ahds > 1)
+               endpoint->ep_st.rx_bundle_lkahd++;
+}
+
+static inline bool htc_valid_rx_frame_len(struct htc_target *target,
+                                         enum htc_endpoint_id eid, int len)
+{
+       return (eid == target->dev->ar->ctrl_ep) ?
+               len <= ATH6KL_BUFFER_SIZE : len <= ATH6KL_AMSDU_BUFFER_SIZE;
+}
+
+static int htc_add_rxbuf(struct htc_target *target, struct htc_packet *packet)
+{
+       struct list_head queue;
+
+       INIT_LIST_HEAD(&queue);
+       list_add_tail(&packet->list, &queue);
+       return ath6kl_htc_mbox_add_rxbuf_multiple(target, &queue);
+}
+
+static void htc_reclaim_rxbuf(struct htc_target *target,
+                             struct htc_packet *packet,
+                             struct htc_endpoint *ep)
+{
+       if (packet->info.rx.rx_flags & HTC_RX_PKT_NO_RECYCLE) {
+               htc_rxpkt_reset(packet);
+               packet->status = -ECANCELED;
+               ep->ep_cb.rx(ep->target, packet);
+       } else {
+               htc_rxpkt_reset(packet);
+               htc_add_rxbuf((void *)(target), packet);
+       }
+}
+
+static void reclaim_rx_ctrl_buf(struct htc_target *target,
+                               struct htc_packet *packet)
+{
+       spin_lock_bh(&target->htc_lock);
+       list_add_tail(&packet->list, &target->free_ctrl_rxbuf);
+       spin_unlock_bh(&target->htc_lock);
+}
+
+static int ath6kl_htc_rx_packet(struct htc_target *target,
+                               struct htc_packet *packet,
+                               u32 rx_len)
+{
+       struct ath6kl_device *dev = target->dev;
+       u32 padded_len;
+       int status;
+
+       padded_len = CALC_TXRX_PADDED_LEN(target, rx_len);
+
+       if (padded_len > packet->buf_len) {
+               ath6kl_err("not enough receive space for packet - padlen %d recvlen %d bufferlen %d\n",
+                          padded_len, rx_len, packet->buf_len);
+               return -ENOMEM;
+       }
+
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "htc rx 0x%p hdr x%x len %d mbox 0x%x\n",
+                  packet, packet->info.rx.exp_hdr,
+                  padded_len, dev->ar->mbox_info.htc_addr);
+
+       status = hif_read_write_sync(dev->ar,
+                                    dev->ar->mbox_info.htc_addr,
+                                    packet->buf, padded_len,
+                                    HIF_RD_SYNC_BLOCK_FIX);
+
+       packet->status = status;
+
+       return status;
+}
+
+/*
+ * optimization for recv packets, we can indicate a
+ * "hint" that there are more  single-packets to fetch
+ * on this endpoint.
+ */
+static void ath6kl_htc_rx_set_indicate(u32 lk_ahd,
+                                      struct htc_endpoint *endpoint,
+                                      struct htc_packet *packet)
+{
+       struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)&lk_ahd;
+
+       if (htc_hdr->eid == packet->endpoint) {
+               if (!list_empty(&endpoint->rx_bufq))
+                       packet->info.rx.indicat_flags |=
+                                       HTC_RX_FLAGS_INDICATE_MORE_PKTS;
+       }
+}
+
+static void ath6kl_htc_rx_chk_water_mark(struct htc_endpoint *endpoint)
+{
+       struct htc_ep_callbacks ep_cb = endpoint->ep_cb;
+
+       if (ep_cb.rx_refill_thresh > 0) {
+               spin_lock_bh(&endpoint->target->rx_lock);
+               if (get_queue_depth(&endpoint->rx_bufq)
+                   < ep_cb.rx_refill_thresh) {
+                       spin_unlock_bh(&endpoint->target->rx_lock);
+                       ep_cb.rx_refill(endpoint->target, endpoint->eid);
+                       return;
+               }
+               spin_unlock_bh(&endpoint->target->rx_lock);
+       }
+}
+
+/* This function is called with rx_lock held */
+static int ath6kl_htc_rx_setup(struct htc_target *target,
+                              struct htc_endpoint *ep,
+                              u32 *lk_ahds, struct list_head *queue, int n_msg)
+{
+       struct htc_packet *packet;
+       /* FIXME: type of lk_ahds can't be right */
+       struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)lk_ahds;
+       struct htc_ep_callbacks ep_cb;
+       int status = 0, j, full_len;
+       bool no_recycle;
+
+       full_len = CALC_TXRX_PADDED_LEN(target,
+                                       le16_to_cpu(htc_hdr->payld_len) +
+                                       sizeof(*htc_hdr));
+
+       if (!htc_valid_rx_frame_len(target, ep->eid, full_len)) {
+               ath6kl_warn("Rx buffer requested with invalid length htc_hdr:eid %d, flags 0x%x, len %d\n",
+                           htc_hdr->eid, htc_hdr->flags,
+                           le16_to_cpu(htc_hdr->payld_len));
+               return -EINVAL;
+       }
+
+       ep_cb = ep->ep_cb;
+       for (j = 0; j < n_msg; j++) {
+
+               /*
+                * Reset flag, any packets allocated using the
+                * rx_alloc() API cannot be recycled on
+                * cleanup,they must be explicitly returned.
+                */
+               no_recycle = false;
+
+               if (ep_cb.rx_allocthresh &&
+                   (full_len > ep_cb.rx_alloc_thresh)) {
+                       ep->ep_st.rx_alloc_thresh_hit += 1;
+                       ep->ep_st.rxalloc_thresh_byte +=
+                               le16_to_cpu(htc_hdr->payld_len);
+
+                       spin_unlock_bh(&target->rx_lock);
+                       no_recycle = true;
+
+                       packet = ep_cb.rx_allocthresh(ep->target, ep->eid,
+                                                     full_len);
+                       spin_lock_bh(&target->rx_lock);
+               } else {
+                       /* refill handler is being used */
+                       if (list_empty(&ep->rx_bufq)) {
+                               if (ep_cb.rx_refill) {
+                                       spin_unlock_bh(&target->rx_lock);
+                                       ep_cb.rx_refill(ep->target, ep->eid);
+                                       spin_lock_bh(&target->rx_lock);
+                               }
+                       }
+
+                       if (list_empty(&ep->rx_bufq))
+                               packet = NULL;
+                       else {
+                               packet = list_first_entry(&ep->rx_bufq,
+                                               struct htc_packet, list);
+                               list_del(&packet->list);
+                       }
+               }
+
+               if (!packet) {
+                       target->rx_st_flags |= HTC_RECV_WAIT_BUFFERS;
+                       target->ep_waiting = ep->eid;
+                       return -ENOSPC;
+               }
+
+               /* clear flags */
+               packet->info.rx.rx_flags = 0;
+               packet->info.rx.indicat_flags = 0;
+               packet->status = 0;
+
+               if (no_recycle)
+                       /*
+                        * flag that these packets cannot be
+                        * recycled, they have to be returned to
+                        * the user
+                        */
+                       packet->info.rx.rx_flags |= HTC_RX_PKT_NO_RECYCLE;
+
+               /* Caller needs to free this upon any failure */
+               list_add_tail(&packet->list, queue);
+
+               if (target->htc_flags & HTC_OP_STATE_STOPPING) {
+                       status = -ECANCELED;
+                       break;
+               }
+
+               if (j) {
+                       packet->info.rx.rx_flags |= HTC_RX_PKT_REFRESH_HDR;
+                       packet->info.rx.exp_hdr = 0xFFFFFFFF;
+               } else
+                       /* set expected look ahead */
+                       packet->info.rx.exp_hdr = *lk_ahds;
+
+               packet->act_len = le16_to_cpu(htc_hdr->payld_len) +
+                       HTC_HDR_LENGTH;
+       }
+
+       return status;
+}
+
+static int ath6kl_htc_rx_alloc(struct htc_target *target,
+                              u32 lk_ahds[], int msg,
+                              struct htc_endpoint *endpoint,
+                              struct list_head *queue)
+{
+       int status = 0;
+       struct htc_packet *packet, *tmp_pkt;
+       struct htc_frame_hdr *htc_hdr;
+       int i, n_msg;
+
+       spin_lock_bh(&target->rx_lock);
+
+       for (i = 0; i < msg; i++) {
+
+               htc_hdr = (struct htc_frame_hdr *)&lk_ahds[i];
+
+               if (htc_hdr->eid >= ENDPOINT_MAX) {
+                       ath6kl_err("invalid ep in look-ahead: %d\n",
+                                  htc_hdr->eid);
+                       status = -ENOMEM;
+                       break;
+               }
+
+               if (htc_hdr->eid != endpoint->eid) {
+                       ath6kl_err("invalid ep in look-ahead: %d should be : %d (index:%d)\n",
+                                  htc_hdr->eid, endpoint->eid, i);
+                       status = -ENOMEM;
+                       break;
+               }
+
+               if (le16_to_cpu(htc_hdr->payld_len) > HTC_MAX_PAYLOAD_LENGTH) {
+                       ath6kl_err("payload len %d exceeds max htc : %d !\n",
+                                  htc_hdr->payld_len,
+                                  (u32) HTC_MAX_PAYLOAD_LENGTH);
+                       status = -ENOMEM;
+                       break;
+               }
+
+               if (endpoint->svc_id == 0) {
+                       ath6kl_err("ep %d is not connected !\n", htc_hdr->eid);
+                       status = -ENOMEM;
+                       break;
+               }
+
+               if (htc_hdr->flags & HTC_FLG_RX_BNDL_CNT) {
+                       /*
+                        * HTC header indicates that every packet to follow
+                        * has the same padded length so that it can be
+                        * optimally fetched as a full bundle.
+                        */
+                       n_msg = (htc_hdr->flags & HTC_FLG_RX_BNDL_CNT) >>
+                               HTC_FLG_RX_BNDL_CNT_S;
+
+                       /* the count doesn't include the starter frame */
+                       n_msg++;
+                       if (n_msg > target->msg_per_bndl_max) {
+                               status = -ENOMEM;
+                               break;
+                       }
+
+                       endpoint->ep_st.rx_bundle_from_hdr += 1;
+                       ath6kl_dbg(ATH6KL_DBG_HTC,
+                                  "htc rx bundle pkts %d\n",
+                                  n_msg);
+               } else
+                       /* HTC header only indicates 1 message to fetch */
+                       n_msg = 1;
+
+               /* Setup packet buffers for each message */
+               status = ath6kl_htc_rx_setup(target, endpoint, &lk_ahds[i],
+                                            queue, n_msg);
+
+               /*
+                * This is due to unavailabilty of buffers to rx entire data.
+                * Return no error so that free buffers from queue can be used
+                * to receive partial data.
+                */
+               if (status == -ENOSPC) {
+                       spin_unlock_bh(&target->rx_lock);
+                       return 0;
+               }
+
+               if (status)
+                       break;
+       }
+
+       spin_unlock_bh(&target->rx_lock);
+
+       if (status) {
+               list_for_each_entry_safe(packet, tmp_pkt, queue, list) {
+                       list_del(&packet->list);
+                       htc_reclaim_rxbuf(target, packet,
+                                         &target->endpoint[packet->endpoint]);
+               }
+       }
+
+       return status;
+}
+
+static void htc_ctrl_rx(struct htc_target *context, struct htc_packet *packets)
+{
+       if (packets->endpoint != ENDPOINT_0) {
+               WARN_ON(1);
+               return;
+       }
+
+       if (packets->status == -ECANCELED) {
+               reclaim_rx_ctrl_buf(context, packets);
+               return;
+       }
+
+       if (packets->act_len > 0) {
+               ath6kl_err("htc_ctrl_rx, got message with len:%zu\n",
+                          packets->act_len + HTC_HDR_LENGTH);
+
+               ath6kl_dbg_dump(ATH6KL_DBG_HTC,
+                               "htc rx unexpected endpoint 0 message", "",
+                               packets->buf - HTC_HDR_LENGTH,
+                               packets->act_len + HTC_HDR_LENGTH);
+       }
+
+       htc_reclaim_rxbuf(context, packets, &context->endpoint[0]);
+}
+
+static void htc_proc_cred_rpt(struct htc_target *target,
+                             struct htc_credit_report *rpt,
+                             int n_entries,
+                             enum htc_endpoint_id from_ep)
+{
+       struct htc_endpoint *endpoint;
+       int tot_credits = 0, i;
+       bool dist = false;
+
+       spin_lock_bh(&target->tx_lock);
+
+       for (i = 0; i < n_entries; i++, rpt++) {
+               if (rpt->eid >= ENDPOINT_MAX) {
+                       WARN_ON(1);
+                       spin_unlock_bh(&target->tx_lock);
+                       return;
+               }
+
+               endpoint = &target->endpoint[rpt->eid];
+
+               ath6kl_dbg(ATH6KL_DBG_CREDIT,
+                          "credit report ep %d credits %d\n",
+                          rpt->eid, rpt->credits);
+
+               endpoint->ep_st.tx_cred_rpt += 1;
+               endpoint->ep_st.cred_retnd += rpt->credits;
+
+               if (from_ep == rpt->eid) {
+                       /*
+                        * This credit report arrived on the same endpoint
+                        * indicating it arrived in an RX packet.
+                        */
+                       endpoint->ep_st.cred_from_rx += rpt->credits;
+                       endpoint->ep_st.cred_rpt_from_rx += 1;
+               } else if (from_ep == ENDPOINT_0) {
+                       /* credit arrived on endpoint 0 as a NULL message */
+                       endpoint->ep_st.cred_from_ep0 += rpt->credits;
+                       endpoint->ep_st.cred_rpt_ep0 += 1;
+               } else {
+                       endpoint->ep_st.cred_from_other += rpt->credits;
+                       endpoint->ep_st.cred_rpt_from_other += 1;
+               }
+
+               if (rpt->eid == ENDPOINT_0)
+                       /* always give endpoint 0 credits back */
+                       endpoint->cred_dist.credits += rpt->credits;
+               else {
+                       endpoint->cred_dist.cred_to_dist += rpt->credits;
+                       dist = true;
+               }
+
+               /*
+                * Refresh tx depth for distribution function that will
+                * recover these credits NOTE: this is only valid when
+                * there are credits to recover!
+                */
+               endpoint->cred_dist.txq_depth =
+                       get_queue_depth(&endpoint->txq);
+
+               tot_credits += rpt->credits;
+       }
+
+       if (dist) {
+               /*
+                * This was a credit return based on a completed send
+                * operations note, this is done with the lock held
+                */
+               ath6kl_credit_distribute(target->credit_info,
+                                        &target->cred_dist_list,
+                                        HTC_CREDIT_DIST_SEND_COMPLETE);
+       }
+
+       spin_unlock_bh(&target->tx_lock);
+
+       if (tot_credits)
+               htc_chk_ep_txq(target);
+}
+
+static int htc_parse_trailer(struct htc_target *target,
+                            struct htc_record_hdr *record,
+                            u8 *record_buf, u32 *next_lk_ahds,
+                            enum htc_endpoint_id endpoint,
+                            int *n_lk_ahds)
+{
+       struct htc_bundle_lkahd_rpt *bundle_lkahd_rpt;
+       struct htc_lookahead_report *lk_ahd;
+       int len;
+
+       switch (record->rec_id) {
+       case HTC_RECORD_CREDITS:
+               len = record->len / sizeof(struct htc_credit_report);
+               if (!len) {
+                       WARN_ON(1);
+                       return -EINVAL;
+               }
+
+               htc_proc_cred_rpt(target,
+                                 (struct htc_credit_report *) record_buf,
+                                 len, endpoint);
+               break;
+       case HTC_RECORD_LOOKAHEAD:
+               len = record->len / sizeof(*lk_ahd);
+               if (!len) {
+                       WARN_ON(1);
+                       return -EINVAL;
+               }
+
+               lk_ahd = (struct htc_lookahead_report *) record_buf;
+               if ((lk_ahd->pre_valid == ((~lk_ahd->post_valid) & 0xFF)) &&
+                   next_lk_ahds) {
+
+                       ath6kl_dbg(ATH6KL_DBG_HTC,
+                                  "htc rx lk_ahd found pre_valid 0x%x post_valid 0x%x\n",
+                                  lk_ahd->pre_valid, lk_ahd->post_valid);
+
+                       /* look ahead bytes are valid, copy them over */
+                       memcpy((u8 *)&next_lk_ahds[0], lk_ahd->lk_ahd, 4);
+
+                       ath6kl_dbg_dump(ATH6KL_DBG_HTC,
+                                       "htc rx next look ahead",
+                                       "", next_lk_ahds, 4);
+
+                       *n_lk_ahds = 1;
+               }
+               break;
+       case HTC_RECORD_LOOKAHEAD_BUNDLE:
+               len = record->len / sizeof(*bundle_lkahd_rpt);
+               if (!len || (len > HTC_HOST_MAX_MSG_PER_BUNDLE)) {
+                       WARN_ON(1);
+                       return -EINVAL;
+               }
+
+               if (next_lk_ahds) {
+                       int i;
+
+                       bundle_lkahd_rpt =
+                               (struct htc_bundle_lkahd_rpt *) record_buf;
+
+                       ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx bundle lk_ahd",
+                                       "", record_buf, record->len);
+
+                       for (i = 0; i < len; i++) {
+                               memcpy((u8 *)&next_lk_ahds[i],
+                                      bundle_lkahd_rpt->lk_ahd, 4);
+                               bundle_lkahd_rpt++;
+                       }
+
+                       *n_lk_ahds = i;
+               }
+               break;
+       default:
+               ath6kl_err("unhandled record: id:%d len:%d\n",
+                          record->rec_id, record->len);
+               break;
+       }
+
+       return 0;
+
+}
+
+static int htc_proc_trailer(struct htc_target *target,
+                           u8 *buf, int len, u32 *next_lk_ahds,
+                           int *n_lk_ahds, enum htc_endpoint_id endpoint)
+{
+       struct htc_record_hdr *record;
+       int orig_len;
+       int status;
+       u8 *record_buf;
+       u8 *orig_buf;
+
+       ath6kl_dbg(ATH6KL_DBG_HTC, "htc rx trailer len %d\n", len);
+       ath6kl_dbg_dump(ATH6KL_DBG_HTC, NULL, "", buf, len);
+
+       orig_buf = buf;
+       orig_len = len;
+       status = 0;
+
+       while (len > 0) {
+
+               if (len < sizeof(struct htc_record_hdr)) {
+                       status = -ENOMEM;
+                       break;
+               }
+               /* these are byte aligned structs */
+               record = (struct htc_record_hdr *) buf;
+               len -= sizeof(struct htc_record_hdr);
+               buf += sizeof(struct htc_record_hdr);
+
+               if (record->len > len) {
+                       ath6kl_err("invalid record len: %d (id:%d) buf has: %d bytes left\n",
+                                  record->len, record->rec_id, len);
+                       status = -ENOMEM;
+                       break;
+               }
+               record_buf = buf;
+
+               status = htc_parse_trailer(target, record, record_buf,
+                                          next_lk_ahds, endpoint, n_lk_ahds);
+
+               if (status)
+                       break;
+
+               /* advance buffer past this record for next time around */
+               buf += record->len;
+               len -= record->len;
+       }
+
+       if (status)
+               ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx bad trailer",
+                               "", orig_buf, orig_len);
+
+       return status;
+}
+
+static int ath6kl_htc_rx_process_hdr(struct htc_target *target,
+                                    struct htc_packet *packet,
+                                    u32 *next_lkahds, int *n_lkahds)
+{
+       int status = 0;
+       u16 payload_len;
+       u32 lk_ahd;
+       struct htc_frame_hdr *htc_hdr = (struct htc_frame_hdr *)packet->buf;
+
+       if (n_lkahds != NULL)
+               *n_lkahds = 0;
+
+       /*
+        * NOTE: we cannot assume the alignment of buf, so we use the safe
+        * macros to retrieve 16 bit fields.
+        */
+       payload_len = le16_to_cpu(get_unaligned(&htc_hdr->payld_len));
+
+       memcpy((u8 *)&lk_ahd, packet->buf, sizeof(lk_ahd));
+
+       if (packet->info.rx.rx_flags & HTC_RX_PKT_REFRESH_HDR) {
+               /*
+                * Refresh the expected header and the actual length as it
+                * was unknown when this packet was grabbed as part of the
+                * bundle.
+                */
+               packet->info.rx.exp_hdr = lk_ahd;
+               packet->act_len = payload_len + HTC_HDR_LENGTH;
+
+               /* validate the actual header that was refreshed  */
+               if (packet->act_len > packet->buf_len) {
+                       ath6kl_err("refreshed hdr payload len (%d) in bundled recv is invalid (hdr: 0x%X)\n",
+                                  payload_len, lk_ahd);
+                       /*
+                        * Limit this to max buffer just to print out some
+                        * of the buffer.
+                        */
+                       packet->act_len = min(packet->act_len, packet->buf_len);
+                       status = -ENOMEM;
+                       goto fail_rx;
+               }
+
+               if (packet->endpoint != htc_hdr->eid) {
+                       ath6kl_err("refreshed hdr ep (%d) does not match expected ep (%d)\n",
+                                  htc_hdr->eid, packet->endpoint);
+                       status = -ENOMEM;
+                       goto fail_rx;
+               }
+       }
+
+       if (lk_ahd != packet->info.rx.exp_hdr) {
+               ath6kl_err("%s(): lk_ahd mismatch! (pPkt:0x%p flags:0x%X)\n",
+                          __func__, packet, packet->info.rx.rx_flags);
+               ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx expected lk_ahd",
+                               "", &packet->info.rx.exp_hdr, 4);
+               ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx current header",
+                               "", (u8 *)&lk_ahd, sizeof(lk_ahd));
+               status = -ENOMEM;
+               goto fail_rx;
+       }
+
+       if (htc_hdr->flags & HTC_FLG_RX_TRAILER) {
+               if (htc_hdr->ctrl[0] < sizeof(struct htc_record_hdr) ||
+                   htc_hdr->ctrl[0] > payload_len) {
+                       ath6kl_err("%s(): invalid hdr (payload len should be :%d, CB[0] is:%d)\n",
+                                  __func__, payload_len, htc_hdr->ctrl[0]);
+                       status = -ENOMEM;
+                       goto fail_rx;
+               }
+
+               if (packet->info.rx.rx_flags & HTC_RX_PKT_IGNORE_LOOKAHEAD) {
+                       next_lkahds = NULL;
+                       n_lkahds = NULL;
+               }
+
+               status = htc_proc_trailer(target, packet->buf + HTC_HDR_LENGTH
+                                         + payload_len - htc_hdr->ctrl[0],
+                                         htc_hdr->ctrl[0], next_lkahds,
+                                          n_lkahds, packet->endpoint);
+
+               if (status)
+                       goto fail_rx;
+
+               packet->act_len -= htc_hdr->ctrl[0];
+       }
+
+       packet->buf += HTC_HDR_LENGTH;
+       packet->act_len -= HTC_HDR_LENGTH;
+
+fail_rx:
+       if (status)
+               ath6kl_dbg_dump(ATH6KL_DBG_HTC, "htc rx bad packet",
+                               "", packet->buf, packet->act_len);
+
+       return status;
+}
+
+static void ath6kl_htc_rx_complete(struct htc_endpoint *endpoint,
+                                  struct htc_packet *packet)
+{
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "htc rx complete ep %d packet 0x%p\n",
+                          endpoint->eid, packet);
+               endpoint->ep_cb.rx(endpoint->target, packet);
+}
+
+static int ath6kl_htc_rx_bundle(struct htc_target *target,
+                               struct list_head *rxq,
+                               struct list_head *sync_compq,
+                               int *n_pkt_fetched, bool part_bundle)
+{
+       struct hif_scatter_req *scat_req;
+       struct htc_packet *packet;
+       int rem_space = target->max_rx_bndl_sz;
+       int n_scat_pkt, status = 0, i, len;
+
+       n_scat_pkt = get_queue_depth(rxq);
+       n_scat_pkt = min(n_scat_pkt, target->msg_per_bndl_max);
+
+       if ((get_queue_depth(rxq) - n_scat_pkt) > 0) {
+               /*
+                * We were forced to split this bundle receive operation
+                * all packets in this partial bundle must have their
+                * lookaheads ignored.
+                */
+               part_bundle = true;
+
+               /*
+                * This would only happen if the target ignored our max
+                * bundle limit.
+                */
+               ath6kl_warn("%s(): partial bundle detected num:%d , %d\n",
+                           __func__, get_queue_depth(rxq), n_scat_pkt);
+       }
+
+       len = 0;
+
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "htc rx bundle depth %d pkts %d\n",
+                  get_queue_depth(rxq), n_scat_pkt);
+
+       scat_req = hif_scatter_req_get(target->dev->ar);
+
+       if (scat_req == NULL)
+               goto fail_rx_pkt;
+
+       for (i = 0; i < n_scat_pkt; i++) {
+               int pad_len;
+
+               packet = list_first_entry(rxq, struct htc_packet, list);
+               list_del(&packet->list);
+
+               pad_len = CALC_TXRX_PADDED_LEN(target,
+                                                  packet->act_len);
+
+               if ((rem_space - pad_len) < 0) {
+                       list_add(&packet->list, rxq);
+                       break;
+               }
+
+               rem_space -= pad_len;
+
+               if (part_bundle || (i < (n_scat_pkt - 1)))
+                       /*
+                        * Packet 0..n-1 cannot be checked for look-aheads
+                        * since we are fetching a bundle the last packet
+                        * however can have it's lookahead used
+                        */
+                       packet->info.rx.rx_flags |=
+                           HTC_RX_PKT_IGNORE_LOOKAHEAD;
+
+               /* NOTE: 1 HTC packet per scatter entry */
+               scat_req->scat_list[i].buf = packet->buf;
+               scat_req->scat_list[i].len = pad_len;
+
+               packet->info.rx.rx_flags |= HTC_RX_PKT_PART_OF_BUNDLE;
+
+               list_add_tail(&packet->list, sync_compq);
+
+               WARN_ON(!scat_req->scat_list[i].len);
+               len += scat_req->scat_list[i].len;
+       }
+
+       scat_req->len = len;
+       scat_req->scat_entries = i;
+
+       status = ath6kl_hif_submit_scat_req(target->dev, scat_req, true);
+
+       if (!status)
+               *n_pkt_fetched = i;
+
+       /* free scatter request */
+       hif_scatter_req_add(target->dev->ar, scat_req);
+
+fail_rx_pkt:
+
+       return status;
+}
+
+static int ath6kl_htc_rx_process_packets(struct htc_target *target,
+                                        struct list_head *comp_pktq,
+                                        u32 lk_ahds[],
+                                        int *n_lk_ahd)
+{
+       struct htc_packet *packet, *tmp_pkt;
+       struct htc_endpoint *ep;
+       int status = 0;
+
+       list_for_each_entry_safe(packet, tmp_pkt, comp_pktq, list) {
+               ep = &target->endpoint[packet->endpoint];
+
+               /* process header for each of the recv packet */
+               status = ath6kl_htc_rx_process_hdr(target, packet, lk_ahds,
+                                                  n_lk_ahd);
+               if (status)
+                       return status;
+
+               list_del(&packet->list);
+
+               if (list_empty(comp_pktq)) {
+                       /*
+                        * Last packet's more packet flag is set
+                        * based on the lookahead.
+                        */
+                       if (*n_lk_ahd > 0)
+                               ath6kl_htc_rx_set_indicate(lk_ahds[0],
+                                                          ep, packet);
+               } else
+                       /*
+                        * Packets in a bundle automatically have
+                        * this flag set.
+                        */
+                       packet->info.rx.indicat_flags |=
+                               HTC_RX_FLAGS_INDICATE_MORE_PKTS;
+
+               ath6kl_htc_rx_update_stats(ep, *n_lk_ahd);
+
+               if (packet->info.rx.rx_flags & HTC_RX_PKT_PART_OF_BUNDLE)
+                       ep->ep_st.rx_bundl += 1;
+
+               ath6kl_htc_rx_complete(ep, packet);
+       }
+
+       return status;
+}
+
+static int ath6kl_htc_rx_fetch(struct htc_target *target,
+                              struct list_head *rx_pktq,
+                              struct list_head *comp_pktq)
+{
+       int fetched_pkts;
+       bool part_bundle = false;
+       int status = 0;
+       struct list_head tmp_rxq;
+       struct htc_packet *packet, *tmp_pkt;
+
+       /* now go fetch the list of HTC packets */
+       while (!list_empty(rx_pktq)) {
+               fetched_pkts = 0;
+
+               INIT_LIST_HEAD(&tmp_rxq);
+
+               if (target->rx_bndl_enable && (get_queue_depth(rx_pktq) > 1)) {
+                       /*
+                        * There are enough packets to attempt a
+                        * bundle transfer and recv bundling is
+                        * allowed.
+                        */
+                       status = ath6kl_htc_rx_bundle(target, rx_pktq,
+                                                     &tmp_rxq,
+                                                     &fetched_pkts,
+                                                     part_bundle);
+                       if (status)
+                               goto fail_rx;
+
+                       if (!list_empty(rx_pktq))
+                               part_bundle = true;
+
+                       list_splice_tail_init(&tmp_rxq, comp_pktq);
+               }
+
+               if (!fetched_pkts) {
+
+                       packet = list_first_entry(rx_pktq, struct htc_packet,
+                                                  list);
+
+                       /* fully synchronous */
+                       packet->completion = NULL;
+
+                       if (!list_is_singular(rx_pktq))
+                               /*
+                                * look_aheads in all packet
+                                * except the last one in the
+                                * bundle must be ignored
+                                */
+                               packet->info.rx.rx_flags |=
+                                       HTC_RX_PKT_IGNORE_LOOKAHEAD;
+
+                       /* go fetch the packet */
+                       status = ath6kl_htc_rx_packet(target, packet,
+                                                     packet->act_len);
+
+                       list_move_tail(&packet->list, &tmp_rxq);
+
+                       if (status)
+                               goto fail_rx;
+
+                       list_splice_tail_init(&tmp_rxq, comp_pktq);
+               }
+       }
+
+       return 0;
+
+fail_rx:
+
+       /*
+        * Cleanup any packets we allocated but didn't use to
+        * actually fetch any packets.
+        */
+
+       list_for_each_entry_safe(packet, tmp_pkt, rx_pktq, list) {
+               list_del(&packet->list);
+               htc_reclaim_rxbuf(target, packet,
+                                 &target->endpoint[packet->endpoint]);
+       }
+
+       list_for_each_entry_safe(packet, tmp_pkt, &tmp_rxq, list) {
+               list_del(&packet->list);
+               htc_reclaim_rxbuf(target, packet,
+                                 &target->endpoint[packet->endpoint]);
+       }
+
+       return status;
+}
+
+int ath6kl_htc_rxmsg_pending_handler(struct htc_target *target,
+                                    u32 msg_look_ahead, int *num_pkts)
+{
+       struct htc_packet *packets, *tmp_pkt;
+       struct htc_endpoint *endpoint;
+       struct list_head rx_pktq, comp_pktq;
+       int status = 0;
+       u32 look_aheads[HTC_HOST_MAX_MSG_PER_BUNDLE];
+       int num_look_ahead = 1;
+       enum htc_endpoint_id id;
+       int n_fetched = 0;
+
+       INIT_LIST_HEAD(&comp_pktq);
+       *num_pkts = 0;
+
+       /*
+        * On first entry copy the look_aheads into our temp array for
+        * processing
+        */
+       look_aheads[0] = msg_look_ahead;
+
+       while (true) {
+
+               /*
+                * First lookahead sets the expected endpoint IDs for all
+                * packets in a bundle.
+                */
+               id = ((struct htc_frame_hdr *)&look_aheads[0])->eid;
+               endpoint = &target->endpoint[id];
+
+               if (id >= ENDPOINT_MAX) {
+                       ath6kl_err("MsgPend, invalid endpoint in look-ahead: %d\n",
+                                  id);
+                       status = -ENOMEM;
+                       break;
+               }
+
+               INIT_LIST_HEAD(&rx_pktq);
+               INIT_LIST_HEAD(&comp_pktq);
+
+               /*
+                * Try to allocate as many HTC RX packets indicated by the
+                * look_aheads.
+                */
+               status = ath6kl_htc_rx_alloc(target, look_aheads,
+                                            num_look_ahead, endpoint,
+                                            &rx_pktq);
+               if (status)
+                       break;
+
+               if (get_queue_depth(&rx_pktq) >= 2)
+                       /*
+                        * A recv bundle was detected, force IRQ status
+                        * re-check again
+                        */
+                       target->chk_irq_status_cnt = 1;
+
+               n_fetched += get_queue_depth(&rx_pktq);
+
+               num_look_ahead = 0;
+
+               status = ath6kl_htc_rx_fetch(target, &rx_pktq, &comp_pktq);
+
+               if (!status)
+                       ath6kl_htc_rx_chk_water_mark(endpoint);
+
+               /* Process fetched packets */
+               status = ath6kl_htc_rx_process_packets(target, &comp_pktq,
+                                                      look_aheads,
+                                                      &num_look_ahead);
+
+               if (!num_look_ahead || status)
+                       break;
+
+               /*
+                * For SYNCH processing, if we get here, we are running
+                * through the loop again due to a detected lookahead. Set
+                * flag that we should re-check IRQ status registers again
+                * before leaving IRQ processing, this can net better
+                * performance in high throughput situations.
+                */
+               target->chk_irq_status_cnt = 1;
+       }
+
+       if (status) {
+               ath6kl_err("failed to get pending recv messages: %d\n",
+                          status);
+
+               /* cleanup any packets in sync completion queue */
+               list_for_each_entry_safe(packets, tmp_pkt, &comp_pktq, list) {
+                       list_del(&packets->list);
+                       htc_reclaim_rxbuf(target, packets,
+                                         &target->endpoint[packets->endpoint]);
+               }
+
+               if (target->htc_flags & HTC_OP_STATE_STOPPING) {
+                       ath6kl_warn("host is going to stop blocking receiver for htc_stop\n");
+                       ath6kl_hif_rx_control(target->dev, false);
+               }
+       }
+
+       /*
+        * Before leaving, check to see if host ran out of buffers and
+        * needs to stop the receiver.
+        */
+       if (target->rx_st_flags & HTC_RECV_WAIT_BUFFERS) {
+               ath6kl_warn("host has no rx buffers blocking receiver to prevent overrun\n");
+               ath6kl_hif_rx_control(target->dev, false);
+       }
+       *num_pkts = n_fetched;
+
+       return status;
+}
+
+/*
+ * Synchronously wait for a control message from the target,
+ * This function is used at initialization time ONLY.  At init messages
+ * on ENDPOINT 0 are expected.
+ */
+static struct htc_packet *htc_wait_for_ctrl_msg(struct htc_target *target)
+{
+       struct htc_packet *packet = NULL;
+       struct htc_frame_hdr *htc_hdr;
+       u32 look_ahead;
+
+       if (ath6kl_hif_poll_mboxmsg_rx(target->dev, &look_ahead,
+                                      HTC_TARGET_RESPONSE_TIMEOUT))
+               return NULL;
+
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "htc rx wait ctrl look_ahead 0x%X\n", look_ahead);
+
+       htc_hdr = (struct htc_frame_hdr *)&look_ahead;
+
+       if (htc_hdr->eid != ENDPOINT_0)
+               return NULL;
+
+       packet = htc_get_control_buf(target, false);
+
+       if (!packet)
+               return NULL;
+
+       packet->info.rx.rx_flags = 0;
+       packet->info.rx.exp_hdr = look_ahead;
+       packet->act_len = le16_to_cpu(htc_hdr->payld_len) + HTC_HDR_LENGTH;
+
+       if (packet->act_len > packet->buf_len)
+               goto fail_ctrl_rx;
+
+       /* we want synchronous operation */
+       packet->completion = NULL;
+
+       /* get the message from the device, this will block */
+       if (ath6kl_htc_rx_packet(target, packet, packet->act_len))
+               goto fail_ctrl_rx;
+
+       /* process receive header */
+       packet->status = ath6kl_htc_rx_process_hdr(target, packet, NULL, NULL);
+
+       if (packet->status) {
+               ath6kl_err("htc_wait_for_ctrl_msg, ath6kl_htc_rx_process_hdr failed (status = %d)\n",
+                          packet->status);
+               goto fail_ctrl_rx;
+       }
+
+       return packet;
+
+fail_ctrl_rx:
+       if (packet != NULL) {
+               htc_rxpkt_reset(packet);
+               reclaim_rx_ctrl_buf(target, packet);
+       }
+
+       return NULL;
+}
+
+static int ath6kl_htc_mbox_add_rxbuf_multiple(struct htc_target *target,
+                                 struct list_head *pkt_queue)
+{
+       struct htc_endpoint *endpoint;
+       struct htc_packet *first_pkt;
+       bool rx_unblock = false;
+       int status = 0, depth;
+
+       if (list_empty(pkt_queue))
+               return -ENOMEM;
+
+       first_pkt = list_first_entry(pkt_queue, struct htc_packet, list);
+
+       if (first_pkt->endpoint >= ENDPOINT_MAX)
+               return status;
+
+       depth = get_queue_depth(pkt_queue);
+
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "htc rx add multiple ep id %d cnt %d len %d\n",
+               first_pkt->endpoint, depth, first_pkt->buf_len);
+
+       endpoint = &target->endpoint[first_pkt->endpoint];
+
+       if (target->htc_flags & HTC_OP_STATE_STOPPING) {
+               struct htc_packet *packet, *tmp_pkt;
+
+               /* walk through queue and mark each one canceled */
+               list_for_each_entry_safe(packet, tmp_pkt, pkt_queue, list) {
+                       packet->status = -ECANCELED;
+                       list_del(&packet->list);
+                       ath6kl_htc_rx_complete(endpoint, packet);
+               }
+
+               return status;
+       }
+
+       spin_lock_bh(&target->rx_lock);
+
+       list_splice_tail_init(pkt_queue, &endpoint->rx_bufq);
+
+       /* check if we are blocked waiting for a new buffer */
+       if (target->rx_st_flags & HTC_RECV_WAIT_BUFFERS) {
+               if (target->ep_waiting == first_pkt->endpoint) {
+                       ath6kl_dbg(ATH6KL_DBG_HTC,
+                                  "htc rx blocked on ep %d, unblocking\n",
+                                  target->ep_waiting);
+                       target->rx_st_flags &= ~HTC_RECV_WAIT_BUFFERS;
+                       target->ep_waiting = ENDPOINT_MAX;
+                       rx_unblock = true;
+               }
+       }
+
+       spin_unlock_bh(&target->rx_lock);
+
+       if (rx_unblock && !(target->htc_flags & HTC_OP_STATE_STOPPING))
+               /* TODO : implement a buffer threshold count? */
+               ath6kl_hif_rx_control(target->dev, true);
+
+       return status;
+}
+
+static void ath6kl_htc_mbox_flush_rx_buf(struct htc_target *target)
+{
+       struct htc_endpoint *endpoint;
+       struct htc_packet *packet, *tmp_pkt;
+       int i;
+
+       for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
+               endpoint = &target->endpoint[i];
+               if (!endpoint->svc_id)
+                       /* not in use.. */
+                       continue;
+
+               spin_lock_bh(&target->rx_lock);
+               list_for_each_entry_safe(packet, tmp_pkt,
+                                        &endpoint->rx_bufq, list) {
+                       list_del(&packet->list);
+                       spin_unlock_bh(&target->rx_lock);
+                       ath6kl_dbg(ATH6KL_DBG_HTC,
+                                  "htc rx flush pkt 0x%p  len %d  ep %d\n",
+                                  packet, packet->buf_len,
+                                  packet->endpoint);
+                       /*
+                        * packets in rx_bufq of endpoint 0 have originally
+                        * been queued from target->free_ctrl_rxbuf where
+                        * packet and packet->buf_start are allocated
+                        * separately using kmalloc(). For other endpoint
+                        * rx_bufq, it is allocated as skb where packet is
+                        * skb->head. Take care of this difference while freeing
+                        * the memory.
+                        */
+                       if (packet->endpoint == ENDPOINT_0) {
+                               kfree(packet->buf_start);
+                               kfree(packet);
+                       } else {
+                               dev_kfree_skb(packet->pkt_cntxt);
+                       }
+                       spin_lock_bh(&target->rx_lock);
+               }
+               spin_unlock_bh(&target->rx_lock);
+       }
+}
+
+static int ath6kl_htc_mbox_conn_service(struct htc_target *target,
+                           struct htc_service_connect_req *conn_req,
+                           struct htc_service_connect_resp *conn_resp)
+{
+       struct htc_packet *rx_pkt = NULL;
+       struct htc_packet *tx_pkt = NULL;
+       struct htc_conn_service_resp *resp_msg;
+       struct htc_conn_service_msg *conn_msg;
+       struct htc_endpoint *endpoint;
+       enum htc_endpoint_id assigned_ep = ENDPOINT_MAX;
+       unsigned int max_msg_sz = 0;
+       int status = 0;
+       u16 msg_id;
+
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "htc connect service target 0x%p service id 0x%x\n",
+                  target, conn_req->svc_id);
+
+       if (conn_req->svc_id == HTC_CTRL_RSVD_SVC) {
+               /* special case for pseudo control service */
+               assigned_ep = ENDPOINT_0;
+               max_msg_sz = HTC_MAX_CTRL_MSG_LEN;
+       } else {
+               /* allocate a packet to send to the target */
+               tx_pkt = htc_get_control_buf(target, true);
+
+               if (!tx_pkt)
+                       return -ENOMEM;
+
+               conn_msg = (struct htc_conn_service_msg *)tx_pkt->buf;
+               memset(conn_msg, 0, sizeof(*conn_msg));
+               conn_msg->msg_id = cpu_to_le16(HTC_MSG_CONN_SVC_ID);
+               conn_msg->svc_id = cpu_to_le16(conn_req->svc_id);
+               conn_msg->conn_flags = cpu_to_le16(conn_req->conn_flags);
+
+               set_htc_pkt_info(tx_pkt, NULL, (u8 *) conn_msg,
+                                sizeof(*conn_msg) + conn_msg->svc_meta_len,
+                                ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
+
+               /* we want synchronous operation */
+               tx_pkt->completion = NULL;
+               ath6kl_htc_tx_prep_pkt(tx_pkt, 0, 0, 0);
+               status = ath6kl_htc_tx_issue(target, tx_pkt);
+
+               if (status)
+                       goto fail_tx;
+
+               /* wait for response */
+               rx_pkt = htc_wait_for_ctrl_msg(target);
+
+               if (!rx_pkt) {
+                       status = -ENOMEM;
+                       goto fail_tx;
+               }
+
+               resp_msg = (struct htc_conn_service_resp *)rx_pkt->buf;
+               msg_id = le16_to_cpu(resp_msg->msg_id);
+
+               if ((msg_id != HTC_MSG_CONN_SVC_RESP_ID) ||
+                   (rx_pkt->act_len < sizeof(*resp_msg))) {
+                       status = -ENOMEM;
+                       goto fail_tx;
+               }
+
+               conn_resp->resp_code = resp_msg->status;
+               /* check response status */
+               if (resp_msg->status != HTC_SERVICE_SUCCESS) {
+                       ath6kl_err("target failed service 0x%X connect request (status:%d)\n",
+                                  resp_msg->svc_id, resp_msg->status);
+                       status = -ENOMEM;
+                       goto fail_tx;
+               }
+
+               assigned_ep = (enum htc_endpoint_id)resp_msg->eid;
+               max_msg_sz = le16_to_cpu(resp_msg->max_msg_sz);
+       }
+
+       if (assigned_ep >= ENDPOINT_MAX || !max_msg_sz) {
+               status = -ENOMEM;
+               goto fail_tx;
+       }
+
+       endpoint = &target->endpoint[assigned_ep];
+       endpoint->eid = assigned_ep;
+       if (endpoint->svc_id) {
+               status = -ENOMEM;
+               goto fail_tx;
+       }
+
+       /* return assigned endpoint to caller */
+       conn_resp->endpoint = assigned_ep;
+       conn_resp->len_max = max_msg_sz;
+
+       /* setup the endpoint */
+
+       /* this marks the endpoint in use */
+       endpoint->svc_id = conn_req->svc_id;
+
+       endpoint->max_txq_depth = conn_req->max_txq_depth;
+       endpoint->len_max = max_msg_sz;
+       endpoint->ep_cb = conn_req->ep_cb;
+       endpoint->cred_dist.svc_id = conn_req->svc_id;
+       endpoint->cred_dist.htc_ep = endpoint;
+       endpoint->cred_dist.endpoint = assigned_ep;
+       endpoint->cred_dist.cred_sz = target->tgt_cred_sz;
+
+       switch (endpoint->svc_id) {
+       case WMI_DATA_BK_SVC:
+               endpoint->tx_drop_packet_threshold = MAX_DEF_COOKIE_NUM / 3;
+               break;
+       default:
+               endpoint->tx_drop_packet_threshold = MAX_HI_COOKIE_NUM;
+               break;
+       }
+
+       if (conn_req->max_rxmsg_sz) {
+               /*
+                * Override cred_per_msg calculation, this optimizes
+                * the credit-low indications since the host will actually
+                * issue smaller messages in the Send path.
+                */
+               if (conn_req->max_rxmsg_sz > max_msg_sz) {
+                       status = -ENOMEM;
+                       goto fail_tx;
+               }
+               endpoint->cred_dist.cred_per_msg =
+                   conn_req->max_rxmsg_sz / target->tgt_cred_sz;
+       } else
+               endpoint->cred_dist.cred_per_msg =
+                   max_msg_sz / target->tgt_cred_sz;
+
+       if (!endpoint->cred_dist.cred_per_msg)
+               endpoint->cred_dist.cred_per_msg = 1;
+
+       /* save local connection flags */
+       endpoint->conn_flags = conn_req->flags;
+
+fail_tx:
+       if (tx_pkt)
+               htc_reclaim_txctrl_buf(target, tx_pkt);
+
+       if (rx_pkt) {
+               htc_rxpkt_reset(rx_pkt);
+               reclaim_rx_ctrl_buf(target, rx_pkt);
+       }
+
+       return status;
+}
+
+static void reset_ep_state(struct htc_target *target)
+{
+       struct htc_endpoint *endpoint;
+       int i;
+
+       for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
+               endpoint = &target->endpoint[i];
+               memset(&endpoint->cred_dist, 0, sizeof(endpoint->cred_dist));
+               endpoint->svc_id = 0;
+               endpoint->len_max = 0;
+               endpoint->max_txq_depth = 0;
+               memset(&endpoint->ep_st, 0,
+                      sizeof(endpoint->ep_st));
+               INIT_LIST_HEAD(&endpoint->rx_bufq);
+               INIT_LIST_HEAD(&endpoint->txq);
+               endpoint->target = target;
+       }
+
+       /* reset distribution list */
+       /* FIXME: free existing entries */
+       INIT_LIST_HEAD(&target->cred_dist_list);
+}
+
+static int ath6kl_htc_mbox_get_rxbuf_num(struct htc_target *target,
+                            enum htc_endpoint_id endpoint)
+{
+       int num;
+
+       spin_lock_bh(&target->rx_lock);
+       num = get_queue_depth(&(target->endpoint[endpoint].rx_bufq));
+       spin_unlock_bh(&target->rx_lock);
+       return num;
+}
+
+static void htc_setup_msg_bndl(struct htc_target *target)
+{
+       /* limit what HTC can handle */
+       target->msg_per_bndl_max = min(HTC_HOST_MAX_MSG_PER_BUNDLE,
+                                      target->msg_per_bndl_max);
+
+       if (ath6kl_hif_enable_scatter(target->dev->ar)) {
+               target->msg_per_bndl_max = 0;
+               return;
+       }
+
+       /* limit bundle what the device layer can handle */
+       target->msg_per_bndl_max = min(target->max_scat_entries,
+                                      target->msg_per_bndl_max);
+
+       ath6kl_dbg(ATH6KL_DBG_BOOT,
+                  "htc bundling allowed msg_per_bndl_max %d\n",
+                  target->msg_per_bndl_max);
+
+       /* Max rx bundle size is limited by the max tx bundle size */
+       target->max_rx_bndl_sz = target->max_xfer_szper_scatreq;
+       /* Max tx bundle size if limited by the extended mbox address range */
+       target->max_tx_bndl_sz = min(HIF_MBOX0_EXT_WIDTH,
+                                    target->max_xfer_szper_scatreq);
+
+       ath6kl_dbg(ATH6KL_DBG_BOOT, "htc max_rx_bndl_sz %d max_tx_bndl_sz %d\n",
+                  target->max_rx_bndl_sz, target->max_tx_bndl_sz);
+
+       if (target->max_tx_bndl_sz)
+               /* tx_bndl_mask is enabled per AC, each has 1 bit */
+               target->tx_bndl_mask = (1 << WMM_NUM_AC) - 1;
+
+       if (target->max_rx_bndl_sz)
+               target->rx_bndl_enable = true;
+
+       if ((target->tgt_cred_sz % target->block_sz) != 0) {
+               ath6kl_warn("credit size: %d is not block aligned! Disabling send bundling\n",
+                           target->tgt_cred_sz);
+
+               /*
+                * Disallow send bundling since the credit size is
+                * not aligned to a block size the I/O block
+                * padding will spill into the next credit buffer
+                * which is fatal.
+                */
+               target->tx_bndl_mask = 0;
+       }
+}
+
+static int ath6kl_htc_mbox_wait_target(struct htc_target *target)
+{
+       struct htc_packet *packet = NULL;
+       struct htc_ready_ext_msg *rdy_msg;
+       struct htc_service_connect_req connect;
+       struct htc_service_connect_resp resp;
+       int status;
+
+       /* FIXME: remove once USB support is implemented */
+       if (target->dev->ar->hif_type == ATH6KL_HIF_TYPE_USB) {
+               ath6kl_err("HTC doesn't support USB yet. Patience!\n");
+               return -EOPNOTSUPP;
+       }
+
+       /* we should be getting 1 control message that the target is ready */
+       packet = htc_wait_for_ctrl_msg(target);
+
+       if (!packet)
+               return -ENOMEM;
+
+       /* we controlled the buffer creation so it's properly aligned */
+       rdy_msg = (struct htc_ready_ext_msg *)packet->buf;
+
+       if ((le16_to_cpu(rdy_msg->ver2_0_info.msg_id) != HTC_MSG_READY_ID) ||
+           (packet->act_len < sizeof(struct htc_ready_msg))) {
+               status = -ENOMEM;
+               goto fail_wait_target;
+       }
+
+       if (!rdy_msg->ver2_0_info.cred_cnt || !rdy_msg->ver2_0_info.cred_sz) {
+               status = -ENOMEM;
+               goto fail_wait_target;
+       }
+
+       target->tgt_creds = le16_to_cpu(rdy_msg->ver2_0_info.cred_cnt);
+       target->tgt_cred_sz = le16_to_cpu(rdy_msg->ver2_0_info.cred_sz);
+
+       ath6kl_dbg(ATH6KL_DBG_BOOT,
+                  "htc target ready credits %d size %d\n",
+                  target->tgt_creds, target->tgt_cred_sz);
+
+       /* check if this is an extended ready message */
+       if (packet->act_len >= sizeof(struct htc_ready_ext_msg)) {
+               /* this is an extended message */
+               target->htc_tgt_ver = rdy_msg->htc_ver;
+               target->msg_per_bndl_max = rdy_msg->msg_per_htc_bndl;
+       } else {
+               /* legacy */
+               target->htc_tgt_ver = HTC_VERSION_2P0;
+               target->msg_per_bndl_max = 0;
+       }
+
+       ath6kl_dbg(ATH6KL_DBG_BOOT, "htc using protocol %s (%d)\n",
+                  (target->htc_tgt_ver == HTC_VERSION_2P0) ? "2.0" : ">= 2.1",
+                  target->htc_tgt_ver);
+
+       if (target->msg_per_bndl_max > 0)
+               htc_setup_msg_bndl(target);
+
+       /* setup our pseudo HTC control endpoint connection */
+       memset(&connect, 0, sizeof(connect));
+       memset(&resp, 0, sizeof(resp));
+       connect.ep_cb.rx = htc_ctrl_rx;
+       connect.ep_cb.rx_refill = NULL;
+       connect.ep_cb.tx_full = NULL;
+       connect.max_txq_depth = NUM_CONTROL_BUFFERS;
+       connect.svc_id = HTC_CTRL_RSVD_SVC;
+
+       /* connect fake service */
+       status = ath6kl_htc_mbox_conn_service((void *)target, &connect, &resp);
+
+       if (status)
+               /*
+                * FIXME: this call doesn't make sense, the caller should
+                * call ath6kl_htc_mbox_cleanup() when it wants remove htc
+                */
+               ath6kl_hif_cleanup_scatter(target->dev->ar);
+
+fail_wait_target:
+       if (packet) {
+               htc_rxpkt_reset(packet);
+               reclaim_rx_ctrl_buf(target, packet);
+       }
+
+       return status;
+}
+
+/*
+ * Start HTC, enable interrupts and let the target know
+ * host has finished setup.
+ */
+static int ath6kl_htc_mbox_start(struct htc_target *target)
+{
+       struct htc_packet *packet;
+       int status;
+
+       memset(&target->dev->irq_proc_reg, 0,
+              sizeof(target->dev->irq_proc_reg));
+
+       /* Disable interrupts at the chip level */
+       ath6kl_hif_disable_intrs(target->dev);
+
+       target->htc_flags = 0;
+       target->rx_st_flags = 0;
+
+       /* Push control receive buffers into htc control endpoint */
+       while ((packet = htc_get_control_buf(target, false)) != NULL) {
+               status = htc_add_rxbuf(target, packet);
+               if (status)
+                       return status;
+       }
+
+       /* NOTE: the first entry in the distribution list is ENDPOINT_0 */
+       ath6kl_credit_init(target->credit_info, &target->cred_dist_list,
+                          target->tgt_creds);
+
+       dump_cred_dist_stats(target);
+
+       /* Indicate to the target of the setup completion */
+       status = htc_setup_tx_complete(target);
+
+       if (status)
+               return status;
+
+       /* unmask interrupts */
+       status = ath6kl_hif_unmask_intrs(target->dev);
+
+       if (status)
+               ath6kl_htc_mbox_stop(target);
+
+       return status;
+}
+
+static int ath6kl_htc_reset(struct htc_target *target)
+{
+       u32 block_size, ctrl_bufsz;
+       struct htc_packet *packet;
+       int i;
+
+       reset_ep_state(target);
+
+       block_size = target->dev->ar->mbox_info.block_size;
+
+       ctrl_bufsz = (block_size > HTC_MAX_CTRL_MSG_LEN) ?
+                     (block_size + HTC_HDR_LENGTH) :
+                     (HTC_MAX_CTRL_MSG_LEN + HTC_HDR_LENGTH);
+
+       for (i = 0; i < NUM_CONTROL_BUFFERS; i++) {
+               packet = kzalloc(sizeof(*packet), GFP_KERNEL);
+               if (!packet)
+                       return -ENOMEM;
+
+               packet->buf_start = kzalloc(ctrl_bufsz, GFP_KERNEL);
+               if (!packet->buf_start) {
+                       kfree(packet);
+                       return -ENOMEM;
+               }
+
+               packet->buf_len = ctrl_bufsz;
+               if (i < NUM_CONTROL_RX_BUFFERS) {
+                       packet->act_len = 0;
+                       packet->buf = packet->buf_start;
+                       packet->endpoint = ENDPOINT_0;
+                       list_add_tail(&packet->list, &target->free_ctrl_rxbuf);
+               } else
+                       list_add_tail(&packet->list, &target->free_ctrl_txbuf);
+       }
+
+       return 0;
+}
+
+/* htc_stop: stop interrupt reception, and flush all queued buffers */
+static void ath6kl_htc_mbox_stop(struct htc_target *target)
+{
+       spin_lock_bh(&target->htc_lock);
+       target->htc_flags |= HTC_OP_STATE_STOPPING;
+       spin_unlock_bh(&target->htc_lock);
+
+       /*
+        * Masking interrupts is a synchronous operation, when this
+        * function returns all pending HIF I/O has completed, we can
+        * safely flush the queues.
+        */
+       ath6kl_hif_mask_intrs(target->dev);
+
+       ath6kl_htc_flush_txep_all(target);
+
+       ath6kl_htc_mbox_flush_rx_buf(target);
+
+       ath6kl_htc_reset(target);
+}
+
+static void *ath6kl_htc_mbox_create(struct ath6kl *ar)
+{
+       struct htc_target *target = NULL;
+       int status = 0;
+
+       target = kzalloc(sizeof(*target), GFP_KERNEL);
+       if (!target) {
+               ath6kl_err("unable to allocate memory\n");
+               return NULL;
+       }
+
+       target->dev = kzalloc(sizeof(*target->dev), GFP_KERNEL);
+       if (!target->dev) {
+               ath6kl_err("unable to allocate memory\n");
+               status = -ENOMEM;
+               goto err_htc_cleanup;
+       }
+
+       spin_lock_init(&target->htc_lock);
+       spin_lock_init(&target->rx_lock);
+       spin_lock_init(&target->tx_lock);
+
+       INIT_LIST_HEAD(&target->free_ctrl_txbuf);
+       INIT_LIST_HEAD(&target->free_ctrl_rxbuf);
+       INIT_LIST_HEAD(&target->cred_dist_list);
+
+       target->dev->ar = ar;
+       target->dev->htc_cnxt = target;
+       target->ep_waiting = ENDPOINT_MAX;
+
+       status = ath6kl_hif_setup(target->dev);
+       if (status)
+               goto err_htc_cleanup;
+
+       status = ath6kl_htc_reset(target);
+       if (status)
+               goto err_htc_cleanup;
+
+       return target;
+
+err_htc_cleanup:
+       ath6kl_htc_mbox_cleanup(target);
+
+       return NULL;
+}
+
+/* cleanup the HTC instance */
+static void ath6kl_htc_mbox_cleanup(struct htc_target *target)
+{
+       struct htc_packet *packet, *tmp_packet;
+
+       /* FIXME: remove check once USB support is implemented */
+       if (target->dev->ar->hif_type != ATH6KL_HIF_TYPE_USB)
+               ath6kl_hif_cleanup_scatter(target->dev->ar);
+
+       list_for_each_entry_safe(packet, tmp_packet,
+                                &target->free_ctrl_txbuf, list) {
+               list_del(&packet->list);
+               kfree(packet->buf_start);
+               kfree(packet);
+       }
+
+       list_for_each_entry_safe(packet, tmp_packet,
+                                &target->free_ctrl_rxbuf, list) {
+               list_del(&packet->list);
+               kfree(packet->buf_start);
+               kfree(packet);
+       }
+
+       kfree(target->dev);
+       kfree(target);
+}
+
+static const struct ath6kl_htc_ops ath6kl_htc_mbox_ops = {
+       .create = ath6kl_htc_mbox_create,
+       .wait_target = ath6kl_htc_mbox_wait_target,
+       .start = ath6kl_htc_mbox_start,
+       .conn_service = ath6kl_htc_mbox_conn_service,
+       .tx = ath6kl_htc_mbox_tx,
+       .stop = ath6kl_htc_mbox_stop,
+       .cleanup = ath6kl_htc_mbox_cleanup,
+       .flush_txep = ath6kl_htc_mbox_flush_txep,
+       .flush_rx_buf = ath6kl_htc_mbox_flush_rx_buf,
+       .activity_changed = ath6kl_htc_mbox_activity_changed,
+       .get_rxbuf_num = ath6kl_htc_mbox_get_rxbuf_num,
+       .add_rxbuf_multiple = ath6kl_htc_mbox_add_rxbuf_multiple,
+       .credit_setup = ath6kl_htc_mbox_credit_setup,
+};
+
+void ath6kl_htc_mbox_attach(struct ath6kl *ar)
+{
+       ar->htc_ops = &ath6kl_htc_mbox_ops;
+}
diff --git a/drivers/net/wireless/ath/ath6kl/htc_pipe.c b/drivers/net/wireless/ath/ath6kl/htc_pipe.c
new file mode 100644 (file)
index 0000000..b277b34
--- /dev/null
@@ -0,0 +1,1713 @@
+/*
+ * Copyright (c) 2007-2011 Atheros Communications Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "core.h"
+#include "debug.h"
+#include "hif-ops.h"
+
+#define HTC_PACKET_CONTAINER_ALLOCATION 32
+#define HTC_CONTROL_BUFFER_SIZE (HTC_MAX_CTRL_MSG_LEN + HTC_HDR_LENGTH)
+
+static int ath6kl_htc_pipe_tx(struct htc_target *handle,
+                             struct htc_packet *packet);
+static void ath6kl_htc_pipe_cleanup(struct htc_target *handle);
+
+/* htc pipe tx path */
+static inline void restore_tx_packet(struct htc_packet *packet)
+{
+       if (packet->info.tx.flags & HTC_FLAGS_TX_FIXUP_NETBUF) {
+               skb_pull(packet->skb, sizeof(struct htc_frame_hdr));
+               packet->info.tx.flags &= ~HTC_FLAGS_TX_FIXUP_NETBUF;
+       }
+}
+
+static void do_send_completion(struct htc_endpoint *ep,
+                              struct list_head *queue_to_indicate)
+{
+       struct htc_packet *packet;
+
+       if (list_empty(queue_to_indicate)) {
+               /* nothing to indicate */
+               return;
+       }
+
+       if (ep->ep_cb.tx_comp_multi != NULL) {
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "%s: calling ep %d, send complete multiple callback (%d pkts)\n",
+                          __func__, ep->eid,
+                          get_queue_depth(queue_to_indicate));
+               /*
+                * a multiple send complete handler is being used,
+                * pass the queue to the handler
+                */
+               ep->ep_cb.tx_comp_multi(ep->target, queue_to_indicate);
+               /*
+                * all packets are now owned by the callback,
+                * reset queue to be safe
+                */
+               INIT_LIST_HEAD(queue_to_indicate);
+       } else {
+               /* using legacy EpTxComplete */
+               do {
+                       packet = list_first_entry(queue_to_indicate,
+                                                 struct htc_packet, list);
+
+                       list_del(&packet->list);
+                       ath6kl_dbg(ATH6KL_DBG_HTC,
+                                  "%s: calling ep %d send complete callback on packet 0x%p\n",
+                                  __func__, ep->eid, packet);
+                       ep->ep_cb.tx_complete(ep->target, packet);
+               } while (!list_empty(queue_to_indicate));
+       }
+}
+
+static void send_packet_completion(struct htc_target *target,
+                                  struct htc_packet *packet)
+{
+       struct htc_endpoint *ep = &target->endpoint[packet->endpoint];
+       struct list_head container;
+
+       restore_tx_packet(packet);
+       INIT_LIST_HEAD(&container);
+       list_add_tail(&packet->list, &container);
+
+       /* do completion */
+       do_send_completion(ep, &container);
+}
+
+static void get_htc_packet_credit_based(struct htc_target *target,
+                                       struct htc_endpoint *ep,
+                                       struct list_head *queue)
+{
+       int credits_required;
+       int remainder;
+       u8 send_flags;
+       struct htc_packet *packet;
+       unsigned int transfer_len;
+
+       /* NOTE : the TX lock is held when this function is called */
+
+       /* loop until we can grab as many packets out of the queue as we can */
+       while (true) {
+               send_flags = 0;
+               if (list_empty(&ep->txq))
+                       break;
+
+               /* get packet at head, but don't remove it */
+               packet = list_first_entry(&ep->txq, struct htc_packet, list);
+               if (packet == NULL)
+                       break;
+
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "%s: got head packet:0x%p , queue depth: %d\n",
+                          __func__, packet, get_queue_depth(&ep->txq));
+
+               transfer_len = packet->act_len + HTC_HDR_LENGTH;
+
+               if (transfer_len <= target->tgt_cred_sz) {
+                       credits_required = 1;
+               } else {
+                       /* figure out how many credits this message requires */
+                       credits_required = transfer_len / target->tgt_cred_sz;
+                       remainder = transfer_len % target->tgt_cred_sz;
+
+                       if (remainder)
+                               credits_required++;
+               }
+
+               ath6kl_dbg(ATH6KL_DBG_HTC, "%s: creds required:%d got:%d\n",
+                          __func__, credits_required, ep->cred_dist.credits);
+
+               if (ep->eid == ENDPOINT_0) {
+                       /*
+                        * endpoint 0 is special, it always has a credit and
+                        * does not require credit based flow control
+                        */
+                       credits_required = 0;
+
+               } else {
+
+                       if (ep->cred_dist.credits < credits_required)
+                               break;
+
+                       ep->cred_dist.credits -= credits_required;
+                       ep->ep_st.cred_cosumd += credits_required;
+
+                       /* check if we need credits back from the target */
+                       if (ep->cred_dist.credits <
+                                       ep->cred_dist.cred_per_msg) {
+                               /* tell the target we need credits ASAP! */
+                               send_flags |= HTC_FLAGS_NEED_CREDIT_UPDATE;
+                               ep->ep_st.cred_low_indicate += 1;
+                               ath6kl_dbg(ATH6KL_DBG_HTC,
+                                          "%s: host needs credits\n",
+                                          __func__);
+                       }
+               }
+
+               /* now we can fully dequeue */
+               packet = list_first_entry(&ep->txq, struct htc_packet, list);
+
+               list_del(&packet->list);
+               /* save the number of credits this packet consumed */
+               packet->info.tx.cred_used = credits_required;
+               /* save send flags */
+               packet->info.tx.flags = send_flags;
+               packet->info.tx.seqno = ep->seqno;
+               ep->seqno++;
+               /* queue this packet into the caller's queue */
+               list_add_tail(&packet->list, queue);
+       }
+
+}
+
+static void get_htc_packet(struct htc_target *target,
+                          struct htc_endpoint *ep,
+                          struct list_head *queue, int resources)
+{
+       struct htc_packet *packet;
+
+       /* NOTE : the TX lock is held when this function is called */
+
+       /* loop until we can grab as many packets out of the queue as we can */
+       while (resources) {
+               if (list_empty(&ep->txq))
+                       break;
+
+               packet = list_first_entry(&ep->txq, struct htc_packet, list);
+               list_del(&packet->list);
+
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "%s: got packet:0x%p , new queue depth: %d\n",
+                          __func__, packet, get_queue_depth(&ep->txq));
+               packet->info.tx.seqno = ep->seqno;
+               packet->info.tx.flags = 0;
+               packet->info.tx.cred_used = 0;
+               ep->seqno++;
+
+               /* queue this packet into the caller's queue */
+               list_add_tail(&packet->list, queue);
+               resources--;
+       }
+}
+
+static int htc_issue_packets(struct htc_target *target,
+                            struct htc_endpoint *ep,
+                            struct list_head *pkt_queue)
+{
+       int status = 0;
+       u16 payload_len;
+       struct sk_buff *skb;
+       struct htc_frame_hdr *htc_hdr;
+       struct htc_packet *packet;
+
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "%s: queue: 0x%p, pkts %d\n", __func__,
+                  pkt_queue, get_queue_depth(pkt_queue));
+
+       while (!list_empty(pkt_queue)) {
+               packet = list_first_entry(pkt_queue, struct htc_packet, list);
+               list_del(&packet->list);
+
+               skb = packet->skb;
+               if (!skb) {
+                       WARN_ON_ONCE(1);
+                       status = -EINVAL;
+                       break;
+               }
+
+               payload_len = packet->act_len;
+
+               /* setup HTC frame header */
+               htc_hdr = (struct htc_frame_hdr *) skb_push(skb,
+                                                           sizeof(*htc_hdr));
+               if (!htc_hdr) {
+                       WARN_ON_ONCE(1);
+                       status = -EINVAL;
+                       break;
+               }
+
+               packet->info.tx.flags |= HTC_FLAGS_TX_FIXUP_NETBUF;
+
+               /* Endianess? */
+               put_unaligned((u16) payload_len, &htc_hdr->payld_len);
+               htc_hdr->flags = packet->info.tx.flags;
+               htc_hdr->eid = (u8) packet->endpoint;
+               htc_hdr->ctrl[0] = 0;
+               htc_hdr->ctrl[1] = (u8) packet->info.tx.seqno;
+
+               spin_lock_bh(&target->tx_lock);
+
+               /* store in look up queue to match completions */
+               list_add_tail(&packet->list, &ep->pipe.tx_lookup_queue);
+               ep->ep_st.tx_issued += 1;
+               spin_unlock_bh(&target->tx_lock);
+
+               status = ath6kl_hif_pipe_send(target->dev->ar,
+                                             ep->pipe.pipeid_ul, NULL, skb);
+
+               if (status != 0) {
+                       if (status != -ENOMEM) {
+                               /* TODO: if more than 1 endpoint maps to the
+                                * same PipeID, it is possible to run out of
+                                * resources in the HIF layer.
+                                * Don't emit the error
+                                */
+                               ath6kl_dbg(ATH6KL_DBG_HTC,
+                                          "%s: failed status:%d\n",
+                                          __func__, status);
+                       }
+                       spin_lock_bh(&target->tx_lock);
+                       list_del(&packet->list);
+
+                       /* reclaim credits */
+                       ep->cred_dist.credits += packet->info.tx.cred_used;
+                       spin_unlock_bh(&target->tx_lock);
+
+                       /* put it back into the callers queue */
+                       list_add(&packet->list, pkt_queue);
+                       break;
+               }
+
+       }
+
+       if (status != 0) {
+               while (!list_empty(pkt_queue)) {
+                       if (status != -ENOMEM) {
+                               ath6kl_dbg(ATH6KL_DBG_HTC,
+                                          "%s: failed pkt:0x%p status:%d\n",
+                                          __func__, packet, status);
+                       }
+
+                       packet = list_first_entry(pkt_queue,
+                                                 struct htc_packet, list);
+                       list_del(&packet->list);
+                       packet->status = status;
+                       send_packet_completion(target, packet);
+               }
+       }
+
+       return status;
+}
+
+static enum htc_send_queue_result htc_try_send(struct htc_target *target,
+                                              struct htc_endpoint *ep,
+                                              struct list_head *txq)
+{
+       struct list_head send_queue;    /* temp queue to hold packets */
+       struct htc_packet *packet, *tmp_pkt;
+       struct ath6kl *ar = target->dev->ar;
+       enum htc_send_full_action action;
+       int tx_resources, overflow, txqueue_depth, i, good_pkts;
+       u8 pipeid;
+
+       ath6kl_dbg(ATH6KL_DBG_HTC, "%s: (queue:0x%p depth:%d)\n",
+                  __func__, txq,
+                  (txq == NULL) ? 0 : get_queue_depth(txq));
+
+       /* init the local send queue */
+       INIT_LIST_HEAD(&send_queue);
+
+       /*
+        * txq equals to NULL means
+        * caller didn't provide a queue, just wants us to
+        * check queues and send
+        */
+       if (txq != NULL) {
+               if (list_empty(txq)) {
+                       /* empty queue */
+                       return HTC_SEND_QUEUE_DROP;
+               }
+
+               spin_lock_bh(&target->tx_lock);
+               txqueue_depth = get_queue_depth(&ep->txq);
+               spin_unlock_bh(&target->tx_lock);
+
+               if (txqueue_depth >= ep->max_txq_depth) {
+                       /* we've already overflowed */
+                       overflow = get_queue_depth(txq);
+               } else {
+                       /* get how much we will overflow by */
+                       overflow = txqueue_depth;
+                       overflow += get_queue_depth(txq);
+                       /* get how much we will overflow the TX queue by */
+                       overflow -= ep->max_txq_depth;
+               }
+
+               /* if overflow is negative or zero, we are okay */
+               if (overflow > 0) {
+                       ath6kl_dbg(ATH6KL_DBG_HTC,
+                                  "%s: Endpoint %d, TX queue will overflow :%d, Tx Depth:%d, Max:%d\n",
+                                  __func__, ep->eid, overflow, txqueue_depth,
+                                  ep->max_txq_depth);
+               }
+               if ((overflow <= 0) ||
+                   (ep->ep_cb.tx_full == NULL)) {
+                       /*
+                        * all packets will fit or caller did not provide send
+                        * full indication handler -- just move all of them
+                        * to the local send_queue object
+                        */
+                       list_splice_tail_init(txq, &send_queue);
+               } else {
+                       good_pkts = get_queue_depth(txq) - overflow;
+                       if (good_pkts < 0) {
+                               WARN_ON_ONCE(1);
+                               return HTC_SEND_QUEUE_DROP;
+                       }
+
+                       /* we have overflowed, and a callback is provided */
+                       /* dequeue all non-overflow packets to the sendqueue */
+                       for (i = 0; i < good_pkts; i++) {
+                               /* pop off caller's queue */
+                               packet = list_first_entry(txq,
+                                                         struct htc_packet,
+                                                         list);
+                               list_del(&packet->list);
+                               /* insert into local queue */
+                               list_add_tail(&packet->list, &send_queue);
+                       }
+
+                       /*
+                        * the caller's queue has all the packets that won't fit
+                        * walk through the caller's queue and indicate each to
+                        * the send full handler
+                        */
+                       list_for_each_entry_safe(packet, tmp_pkt,
+                                                txq, list) {
+
+                               ath6kl_dbg(ATH6KL_DBG_HTC,
+                                          "%s: Indicat overflowed TX pkts: %p\n",
+                                          __func__, packet);
+                               action = ep->ep_cb.tx_full(ep->target, packet);
+                               if (action == HTC_SEND_FULL_DROP) {
+                                       /* callback wants the packet dropped */
+                                       ep->ep_st.tx_dropped += 1;
+
+                                       /* leave this one in the caller's queue
+                                        * for cleanup */
+                               } else {
+                                       /* callback wants to keep this packet,
+                                        * remove from caller's queue */
+                                       list_del(&packet->list);
+                                       /* put it in the send queue */
+                                       list_add_tail(&packet->list,
+                                                     &send_queue);
+                               }
+
+                       }
+
+                       if (list_empty(&send_queue)) {
+                               /* no packets made it in, caller will cleanup */
+                               return HTC_SEND_QUEUE_DROP;
+                       }
+               }
+       }
+
+       if (!ep->pipe.tx_credit_flow_enabled) {
+               tx_resources =
+                   ath6kl_hif_pipe_get_free_queue_number(ar,
+                                                         ep->pipe.pipeid_ul);
+       } else {
+               tx_resources = 0;
+       }
+
+       spin_lock_bh(&target->tx_lock);
+       if (!list_empty(&send_queue)) {
+               /* transfer packets to tail */
+               list_splice_tail_init(&send_queue, &ep->txq);
+               if (!list_empty(&send_queue)) {
+                       WARN_ON_ONCE(1);
+                       spin_unlock_bh(&target->tx_lock);
+                       return HTC_SEND_QUEUE_DROP;
+               }
+               INIT_LIST_HEAD(&send_queue);
+       }
+
+       /* increment tx processing count on entry */
+       ep->tx_proc_cnt++;
+
+       if (ep->tx_proc_cnt > 1) {
+               /*
+                * Another thread or task is draining the TX queues on this
+                * endpoint that thread will reset the tx processing count
+                * when the queue is drained.
+                */
+               ep->tx_proc_cnt--;
+               spin_unlock_bh(&target->tx_lock);
+               return HTC_SEND_QUEUE_OK;
+       }
+
+       /***** beyond this point only 1 thread may enter ******/
+
+       /*
+        * Now drain the endpoint TX queue for transmission as long as we have
+        * enough transmit resources.
+        */
+       while (true) {
+
+               if (get_queue_depth(&ep->txq) == 0)
+                       break;
+
+               if (ep->pipe.tx_credit_flow_enabled) {
+                       /*
+                        * Credit based mechanism provides flow control
+                        * based on target transmit resource availability,
+                        * we assume that the HIF layer will always have
+                        * bus resources greater than target transmit
+                        * resources.
+                        */
+                       get_htc_packet_credit_based(target, ep, &send_queue);
+               } else {
+                       /*
+                        * Get all packets for this endpoint that we can
+                        * for this pass.
+                        */
+                       get_htc_packet(target, ep, &send_queue, tx_resources);
+               }
+
+               if (get_queue_depth(&send_queue) == 0) {
+                       /*
+                        * Didn't get packets due to out of resources or TX
+                        * queue was drained.
+                        */
+                       break;
+               }
+
+               spin_unlock_bh(&target->tx_lock);
+
+               /* send what we can */
+               htc_issue_packets(target, ep, &send_queue);
+
+               if (!ep->pipe.tx_credit_flow_enabled) {
+                       pipeid = ep->pipe.pipeid_ul;
+                       tx_resources =
+                           ath6kl_hif_pipe_get_free_queue_number(ar, pipeid);
+               }
+
+               spin_lock_bh(&target->tx_lock);
+
+       }
+       /* done with this endpoint, we can clear the count */
+       ep->tx_proc_cnt = 0;
+       spin_unlock_bh(&target->tx_lock);
+
+       return HTC_SEND_QUEUE_OK;
+}
+
+/* htc control packet manipulation */
+static void destroy_htc_txctrl_packet(struct htc_packet *packet)
+{
+       struct sk_buff *skb;
+       skb = packet->skb;
+       if (skb != NULL)
+               dev_kfree_skb(skb);
+
+       kfree(packet);
+}
+
+static struct htc_packet *build_htc_txctrl_packet(void)
+{
+       struct htc_packet *packet = NULL;
+       struct sk_buff *skb;
+
+       packet = kzalloc(sizeof(struct htc_packet), GFP_KERNEL);
+       if (packet == NULL)
+               return NULL;
+
+       skb = __dev_alloc_skb(HTC_CONTROL_BUFFER_SIZE, GFP_KERNEL);
+
+       if (skb == NULL) {
+               kfree(packet);
+               return NULL;
+       }
+       packet->skb = skb;
+
+       return packet;
+}
+
+static void htc_free_txctrl_packet(struct htc_target *target,
+                                  struct htc_packet *packet)
+{
+       destroy_htc_txctrl_packet(packet);
+}
+
+static struct htc_packet *htc_alloc_txctrl_packet(struct htc_target *target)
+{
+       return build_htc_txctrl_packet();
+}
+
+static void htc_txctrl_complete(struct htc_target *target,
+                               struct htc_packet *packet)
+{
+       htc_free_txctrl_packet(target, packet);
+}
+
+#define MAX_MESSAGE_SIZE 1536
+
+static int htc_setup_target_buffer_assignments(struct htc_target *target)
+{
+       int status, credits, credit_per_maxmsg, i;
+       struct htc_pipe_txcredit_alloc *entry;
+       unsigned int hif_usbaudioclass = 0;
+
+       credit_per_maxmsg = MAX_MESSAGE_SIZE / target->tgt_cred_sz;
+       if (MAX_MESSAGE_SIZE % target->tgt_cred_sz)
+               credit_per_maxmsg++;
+
+       /* TODO, this should be configured by the caller! */
+
+       credits = target->tgt_creds;
+       entry = &target->pipe.txcredit_alloc[0];
+
+       status = -ENOMEM;
+
+       /* FIXME: hif_usbaudioclass is always zero */
+       if (hif_usbaudioclass) {
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "%s: For USB Audio Class- Total:%d\n",
+                          __func__, credits);
+               entry++;
+               entry++;
+               /* Setup VO Service To have Max Credits */
+               entry->service_id = WMI_DATA_VO_SVC;
+               entry->credit_alloc = (credits - 6);
+               if (entry->credit_alloc == 0)
+                       entry->credit_alloc++;
+
+               credits -= (int) entry->credit_alloc;
+               if (credits <= 0)
+                       return status;
+
+               entry++;
+               entry->service_id = WMI_CONTROL_SVC;
+               entry->credit_alloc = credit_per_maxmsg;
+               credits -= (int) entry->credit_alloc;
+               if (credits <= 0)
+                       return status;
+
+               /* leftovers go to best effort */
+               entry++;
+               entry++;
+               entry->service_id = WMI_DATA_BE_SVC;
+               entry->credit_alloc = (u8) credits;
+               status = 0;
+       } else {
+               entry++;
+               entry->service_id = WMI_DATA_VI_SVC;
+               entry->credit_alloc = credits / 4;
+               if (entry->credit_alloc == 0)
+                       entry->credit_alloc++;
+
+               credits -= (int) entry->credit_alloc;
+               if (credits <= 0)
+                       return status;
+
+               entry++;
+               entry->service_id = WMI_DATA_VO_SVC;
+               entry->credit_alloc = credits / 4;
+               if (entry->credit_alloc == 0)
+                       entry->credit_alloc++;
+
+               credits -= (int) entry->credit_alloc;
+               if (credits <= 0)
+                       return status;
+
+               entry++;
+               entry->service_id = WMI_CONTROL_SVC;
+               entry->credit_alloc = credit_per_maxmsg;
+               credits -= (int) entry->credit_alloc;
+               if (credits <= 0)
+                       return status;
+
+               entry++;
+               entry->service_id = WMI_DATA_BK_SVC;
+               entry->credit_alloc = credit_per_maxmsg;
+               credits -= (int) entry->credit_alloc;
+               if (credits <= 0)
+                       return status;
+
+               /* leftovers go to best effort */
+               entry++;
+               entry->service_id = WMI_DATA_BE_SVC;
+               entry->credit_alloc = (u8) credits;
+               status = 0;
+       }
+
+       if (status == 0) {
+               for (i = 0; i < ENDPOINT_MAX; i++) {
+                       if (target->pipe.txcredit_alloc[i].service_id != 0) {
+                               ath6kl_dbg(ATH6KL_DBG_HTC,
+                                          "HTC Service Index : %d TX : 0x%2.2X : alloc:%d\n",
+                                          i,
+                                          target->pipe.txcredit_alloc[i].
+                                          service_id,
+                                          target->pipe.txcredit_alloc[i].
+                                          credit_alloc);
+                       }
+               }
+       }
+       return status;
+}
+
+/* process credit reports and call distribution function */
+static void htc_process_credit_report(struct htc_target *target,
+                                     struct htc_credit_report *rpt,
+                                     int num_entries,
+                                     enum htc_endpoint_id from_ep)
+{
+       int total_credits = 0, i;
+       struct htc_endpoint *ep;
+
+       /* lock out TX while we update credits */
+       spin_lock_bh(&target->tx_lock);
+
+       for (i = 0; i < num_entries; i++, rpt++) {
+               if (rpt->eid >= ENDPOINT_MAX) {
+                       WARN_ON_ONCE(1);
+                       spin_unlock_bh(&target->tx_lock);
+                       return;
+               }
+
+               ep = &target->endpoint[rpt->eid];
+               ep->cred_dist.credits += rpt->credits;
+
+               if (ep->cred_dist.credits && get_queue_depth(&ep->txq)) {
+                       spin_unlock_bh(&target->tx_lock);
+                       htc_try_send(target, ep, NULL);
+                       spin_lock_bh(&target->tx_lock);
+               }
+
+               total_credits += rpt->credits;
+       }
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "Report indicated %d credits to distribute\n",
+                  total_credits);
+
+       spin_unlock_bh(&target->tx_lock);
+}
+
+/* flush endpoint TX queue */
+static void htc_flush_tx_endpoint(struct htc_target *target,
+                                 struct htc_endpoint *ep, u16 tag)
+{
+       struct htc_packet *packet;
+
+       spin_lock_bh(&target->tx_lock);
+       while (get_queue_depth(&ep->txq)) {
+               packet = list_first_entry(&ep->txq, struct htc_packet, list);
+               list_del(&packet->list);
+               packet->status = 0;
+               send_packet_completion(target, packet);
+       }
+       spin_unlock_bh(&target->tx_lock);
+}
+
+/*
+ * In the adapted HIF layer, struct sk_buff * are passed between HIF and HTC,
+ * since upper layers expects struct htc_packet containers we use the completed
+ * skb and lookup it's corresponding HTC packet buffer from a lookup list.
+ * This is extra overhead that can be fixed by re-aligning HIF interfaces with
+ * HTC.
+ */
+static struct htc_packet *htc_lookup_tx_packet(struct htc_target *target,
+                                              struct htc_endpoint *ep,
+                                              struct sk_buff *skb)
+{
+       struct htc_packet *packet, *tmp_pkt, *found_packet = NULL;
+
+       spin_lock_bh(&target->tx_lock);
+
+       /*
+        * interate from the front of tx lookup queue
+        * this lookup should be fast since lower layers completes in-order and
+        * so the completed packet should be at the head of the list generally
+        */
+       list_for_each_entry_safe(packet, tmp_pkt, &ep->pipe.tx_lookup_queue,
+                                list) {
+               /* check for removal */
+               if (skb == packet->skb) {
+                       /* found it */
+                       list_del(&packet->list);
+                       found_packet = packet;
+                       break;
+               }
+       }
+
+       spin_unlock_bh(&target->tx_lock);
+
+       return found_packet;
+}
+
+static int ath6kl_htc_pipe_tx_complete(struct ath6kl *ar, struct sk_buff *skb)
+{
+       struct htc_target *target = ar->htc_target;
+       struct htc_frame_hdr *htc_hdr;
+       struct htc_endpoint *ep;
+       struct htc_packet *packet;
+       u8 ep_id, *netdata;
+       u32 netlen;
+
+       netdata = skb->data;
+       netlen = skb->len;
+
+       htc_hdr = (struct htc_frame_hdr *) netdata;
+
+       ep_id = htc_hdr->eid;
+       ep = &target->endpoint[ep_id];
+
+       packet = htc_lookup_tx_packet(target, ep, skb);
+       if (packet == NULL) {
+               /* may have already been flushed and freed */
+               ath6kl_err("HTC TX lookup failed!\n");
+       } else {
+               /* will be giving this buffer back to upper layers */
+               packet->status = 0;
+               send_packet_completion(target, packet);
+       }
+       skb = NULL;
+
+       if (!ep->pipe.tx_credit_flow_enabled) {
+               /*
+                * note: when using TX credit flow, the re-checking of queues
+                * happens when credits flow back from the target. in the
+                * non-TX credit case, we recheck after the packet completes
+                */
+               htc_try_send(target, ep, NULL);
+       }
+
+       return 0;
+}
+
+static int htc_send_packets_multiple(struct htc_target *target,
+                                    struct list_head *pkt_queue)
+{
+       struct htc_endpoint *ep;
+       struct htc_packet *packet, *tmp_pkt;
+
+       if (list_empty(pkt_queue))
+               return -EINVAL;
+
+       /* get first packet to find out which ep the packets will go into */
+       packet = list_first_entry(pkt_queue, struct htc_packet, list);
+       if (packet == NULL)
+               return -EINVAL;
+
+       if (packet->endpoint >= ENDPOINT_MAX) {
+               WARN_ON_ONCE(1);
+               return -EINVAL;
+       }
+       ep = &target->endpoint[packet->endpoint];
+
+       htc_try_send(target, ep, pkt_queue);
+
+       /* do completion on any packets that couldn't get in */
+       if (!list_empty(pkt_queue)) {
+               list_for_each_entry_safe(packet, tmp_pkt, pkt_queue, list) {
+                       packet->status = -ENOMEM;
+               }
+
+               do_send_completion(ep, pkt_queue);
+       }
+
+       return 0;
+}
+
+/* htc pipe rx path */
+static struct htc_packet *alloc_htc_packet_container(struct htc_target *target)
+{
+       struct htc_packet *packet;
+       spin_lock_bh(&target->rx_lock);
+
+       if (target->pipe.htc_packet_pool == NULL) {
+               spin_unlock_bh(&target->rx_lock);
+               return NULL;
+       }
+
+       packet = target->pipe.htc_packet_pool;
+       target->pipe.htc_packet_pool = (struct htc_packet *) packet->list.next;
+
+       spin_unlock_bh(&target->rx_lock);
+
+       packet->list.next = NULL;
+       return packet;
+}
+
+static void free_htc_packet_container(struct htc_target *target,
+                                     struct htc_packet *packet)
+{
+       struct list_head *lh;
+
+       spin_lock_bh(&target->rx_lock);
+
+       if (target->pipe.htc_packet_pool == NULL) {
+               target->pipe.htc_packet_pool = packet;
+               packet->list.next = NULL;
+       } else {
+               lh = (struct list_head *) target->pipe.htc_packet_pool;
+               packet->list.next = lh;
+               target->pipe.htc_packet_pool = packet;
+       }
+
+       spin_unlock_bh(&target->rx_lock);
+}
+
+static int htc_process_trailer(struct htc_target *target, u8 *buffer,
+                              int len, enum htc_endpoint_id from_ep)
+{
+       struct htc_credit_report *report;
+       struct htc_record_hdr *record;
+       u8 *record_buf, *orig_buf;
+       int orig_len, status;
+
+       orig_buf = buffer;
+       orig_len = len;
+       status = 0;
+
+       while (len > 0) {
+               if (len < sizeof(struct htc_record_hdr)) {
+                       status = -EINVAL;
+                       break;
+               }
+
+               /* these are byte aligned structs */
+               record = (struct htc_record_hdr *) buffer;
+               len -= sizeof(struct htc_record_hdr);
+               buffer += sizeof(struct htc_record_hdr);
+
+               if (record->len > len) {
+                       /* no room left in buffer for record */
+                       ath6kl_dbg(ATH6KL_DBG_HTC,
+                                  "invalid length: %d (id:%d) buffer has: %d bytes left\n",
+                                  record->len, record->rec_id, len);
+                       status = -EINVAL;
+                       break;
+               }
+
+               /* start of record follows the header */
+               record_buf = buffer;
+
+               switch (record->rec_id) {
+               case HTC_RECORD_CREDITS:
+                       if (record->len < sizeof(struct htc_credit_report)) {
+                               WARN_ON_ONCE(1);
+                               return -EINVAL;
+                       }
+
+                       report = (struct htc_credit_report *) record_buf;
+                       htc_process_credit_report(target, report,
+                                                 record->len / sizeof(*report),
+                                                 from_ep);
+                       break;
+               default:
+                       ath6kl_dbg(ATH6KL_DBG_HTC,
+                                  "unhandled record: id:%d length:%d\n",
+                                  record->rec_id, record->len);
+                       break;
+               }
+
+               if (status != 0)
+                       break;
+
+               /* advance buffer past this record for next time around */
+               buffer += record->len;
+               len -= record->len;
+       }
+
+       return status;
+}
+
+static void do_recv_completion(struct htc_endpoint *ep,
+                              struct list_head *queue_to_indicate)
+{
+       struct htc_packet *packet;
+
+       if (list_empty(queue_to_indicate)) {
+               /* nothing to indicate */
+               return;
+       }
+
+       /* using legacy EpRecv */
+       while (!list_empty(queue_to_indicate)) {
+               packet = list_first_entry(queue_to_indicate,
+                                         struct htc_packet, list);
+               list_del(&packet->list);
+               ep->ep_cb.rx(ep->target, packet);
+       }
+
+       return;
+}
+
+static void recv_packet_completion(struct htc_target *target,
+                                  struct htc_endpoint *ep,
+                                  struct htc_packet *packet)
+{
+       struct list_head container;
+       INIT_LIST_HEAD(&container);
+       list_add_tail(&packet->list, &container);
+
+       /* do completion */
+       do_recv_completion(ep, &container);
+}
+
+static int ath6kl_htc_pipe_rx_complete(struct ath6kl *ar, struct sk_buff *skb,
+                                      u8 pipeid)
+{
+       struct htc_target *target = ar->htc_target;
+       u8 *netdata, *trailer, hdr_info;
+       struct htc_frame_hdr *htc_hdr;
+       u32 netlen, trailerlen = 0;
+       struct htc_packet *packet;
+       struct htc_endpoint *ep;
+       u16 payload_len;
+       int status = 0;
+
+       netdata = skb->data;
+       netlen = skb->len;
+
+       htc_hdr = (struct htc_frame_hdr *) netdata;
+
+       ep = &target->endpoint[htc_hdr->eid];
+
+       if (htc_hdr->eid >= ENDPOINT_MAX) {
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "HTC Rx: invalid EndpointID=%d\n",
+                          htc_hdr->eid);
+               status = -EINVAL;
+               goto free_skb;
+       }
+
+       payload_len = le16_to_cpu(get_unaligned(&htc_hdr->payld_len));
+
+       if (netlen < (payload_len + HTC_HDR_LENGTH)) {
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "HTC Rx: insufficient length, got:%d expected =%u\n",
+                          netlen, payload_len + HTC_HDR_LENGTH);
+               status = -EINVAL;
+               goto free_skb;
+       }
+
+       /* get flags to check for trailer */
+       hdr_info = htc_hdr->flags;
+       if (hdr_info & HTC_FLG_RX_TRAILER) {
+               /* extract the trailer length */
+               hdr_info = htc_hdr->ctrl[0];
+               if ((hdr_info < sizeof(struct htc_record_hdr)) ||
+                   (hdr_info > payload_len)) {
+                       ath6kl_dbg(ATH6KL_DBG_HTC,
+                                  "invalid header: payloadlen should be %d, CB[0]: %d\n",
+                                  payload_len, hdr_info);
+                       status = -EINVAL;
+                       goto free_skb;
+               }
+
+               trailerlen = hdr_info;
+               /* process trailer after hdr/apps payload */
+               trailer = (u8 *) htc_hdr + HTC_HDR_LENGTH +
+                       payload_len - hdr_info;
+               status = htc_process_trailer(target, trailer, hdr_info,
+                                            htc_hdr->eid);
+               if (status != 0)
+                       goto free_skb;
+       }
+
+       if (((int) payload_len - (int) trailerlen) <= 0) {
+               /* zero length packet with trailer, just drop these */
+               goto free_skb;
+       }
+
+       if (htc_hdr->eid == ENDPOINT_0) {
+               /* handle HTC control message */
+               if (target->htc_flags & HTC_OP_STATE_SETUP_COMPLETE) {
+                       /*
+                        * fatal: target should not send unsolicited
+                        * messageson the endpoint 0
+                        */
+                       ath6kl_dbg(ATH6KL_DBG_HTC,
+                                  "HTC ignores Rx Ctrl after setup complete\n");
+                       status = -EINVAL;
+                       goto free_skb;
+               }
+
+               /* remove HTC header */
+               skb_pull(skb, HTC_HDR_LENGTH);
+
+               netdata = skb->data;
+               netlen = skb->len;
+
+               spin_lock_bh(&target->rx_lock);
+
+               target->pipe.ctrl_response_valid = true;
+               target->pipe.ctrl_response_len = min_t(int, netlen,
+                                                      HTC_MAX_CTRL_MSG_LEN);
+               memcpy(target->pipe.ctrl_response_buf, netdata,
+                      target->pipe.ctrl_response_len);
+
+               spin_unlock_bh(&target->rx_lock);
+
+               dev_kfree_skb(skb);
+               skb = NULL;
+               goto free_skb;
+       }
+
+       /*
+        * TODO: the message based HIF architecture allocates net bufs
+        * for recv packets since it bridges that HIF to upper layers,
+        * which expects HTC packets, we form the packets here
+        */
+       packet = alloc_htc_packet_container(target);
+       if (packet == NULL) {
+               status = -ENOMEM;
+               goto free_skb;
+       }
+
+       packet->status = 0;
+       packet->endpoint = htc_hdr->eid;
+       packet->pkt_cntxt = skb;
+
+       /* TODO: for backwards compatibility */
+       packet->buf = skb_push(skb, 0) + HTC_HDR_LENGTH;
+       packet->act_len = netlen - HTC_HDR_LENGTH - trailerlen;
+
+       /*
+        * TODO: this is a hack because the driver layer will set the
+        * actual len of the skb again which will just double the len
+        */
+       skb_trim(skb, 0);
+
+       recv_packet_completion(target, ep, packet);
+
+       /* recover the packet container */
+       free_htc_packet_container(target, packet);
+       skb = NULL;
+
+free_skb:
+       if (skb != NULL)
+               dev_kfree_skb(skb);
+
+       return status;
+
+}
+
+static void htc_flush_rx_queue(struct htc_target *target,
+                              struct htc_endpoint *ep)
+{
+       struct list_head container;
+       struct htc_packet *packet;
+
+       spin_lock_bh(&target->rx_lock);
+
+       while (1) {
+               if (list_empty(&ep->rx_bufq))
+                       break;
+
+               packet = list_first_entry(&ep->rx_bufq,
+                                         struct htc_packet, list);
+               list_del(&packet->list);
+
+               spin_unlock_bh(&target->rx_lock);
+               packet->status = -ECANCELED;
+               packet->act_len = 0;
+
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "Flushing RX packet:0x%p, length:%d, ep:%d\n",
+                          packet, packet->buf_len,
+                          packet->endpoint);
+
+               INIT_LIST_HEAD(&container);
+               list_add_tail(&packet->list, &container);
+
+               /* give the packet back */
+               do_recv_completion(ep, &container);
+               spin_lock_bh(&target->rx_lock);
+       }
+
+       spin_unlock_bh(&target->rx_lock);
+}
+
+/* polling routine to wait for a control packet to be received */
+static int htc_wait_recv_ctrl_message(struct htc_target *target)
+{
+       int count = HTC_TARGET_RESPONSE_POLL_COUNT;
+
+       while (count > 0) {
+               spin_lock_bh(&target->rx_lock);
+
+               if (target->pipe.ctrl_response_valid) {
+                       target->pipe.ctrl_response_valid = false;
+                       spin_unlock_bh(&target->rx_lock);
+                       break;
+               }
+
+               spin_unlock_bh(&target->rx_lock);
+
+               count--;
+
+               msleep_interruptible(HTC_TARGET_RESPONSE_POLL_WAIT);
+       }
+
+       if (count <= 0) {
+               ath6kl_dbg(ATH6KL_DBG_HTC, "%s: Timeout!\n", __func__);
+               return -ECOMM;
+       }
+
+       return 0;
+}
+
+static void htc_rxctrl_complete(struct htc_target *context,
+                               struct htc_packet *packet)
+{
+       /* TODO, can't really receive HTC control messages yet.... */
+       ath6kl_dbg(ATH6KL_DBG_HTC, "%s: invalid call function\n", __func__);
+}
+
+/* htc pipe initialization */
+static void reset_endpoint_states(struct htc_target *target)
+{
+       struct htc_endpoint *ep;
+       int i;
+
+       for (i = ENDPOINT_0; i < ENDPOINT_MAX; i++) {
+               ep = &target->endpoint[i];
+               ep->svc_id = 0;
+               ep->len_max = 0;
+               ep->max_txq_depth = 0;
+               ep->eid = i;
+               INIT_LIST_HEAD(&ep->txq);
+               INIT_LIST_HEAD(&ep->pipe.tx_lookup_queue);
+               INIT_LIST_HEAD(&ep->rx_bufq);
+               ep->target = target;
+               ep->pipe.tx_credit_flow_enabled = (bool) 1; /* FIXME */
+       }
+}
+
+/* start HTC, this is called after all services are connected */
+static int htc_config_target_hif_pipe(struct htc_target *target)
+{
+       return 0;
+}
+
+/* htc service functions */
+static u8 htc_get_credit_alloc(struct htc_target *target, u16 service_id)
+{
+       u8 allocation = 0;
+       int i;
+
+       for (i = 0; i < ENDPOINT_MAX; i++) {
+               if (target->pipe.txcredit_alloc[i].service_id == service_id)
+                       allocation =
+                               target->pipe.txcredit_alloc[i].credit_alloc;
+       }
+
+       if (allocation == 0) {
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "HTC Service TX : 0x%2.2X : allocation is zero!\n",
+                          service_id);
+       }
+
+       return allocation;
+}
+
+static int ath6kl_htc_pipe_conn_service(struct htc_target *target,
+                    struct htc_service_connect_req *conn_req,
+                    struct htc_service_connect_resp *conn_resp)
+{
+       struct ath6kl *ar = target->dev->ar;
+       struct htc_packet *packet = NULL;
+       struct htc_conn_service_resp *resp_msg;
+       struct htc_conn_service_msg *conn_msg;
+       enum htc_endpoint_id assigned_epid = ENDPOINT_MAX;
+       bool disable_credit_flowctrl = false;
+       unsigned int max_msg_size = 0;
+       struct htc_endpoint *ep;
+       int length, status = 0;
+       struct sk_buff *skb;
+       u8 tx_alloc;
+       u16 flags;
+
+       if (conn_req->svc_id == 0) {
+               WARN_ON_ONCE(1);
+               status = -EINVAL;
+               goto free_packet;
+       }
+
+       if (conn_req->svc_id == HTC_CTRL_RSVD_SVC) {
+               /* special case for pseudo control service */
+               assigned_epid = ENDPOINT_0;
+               max_msg_size = HTC_MAX_CTRL_MSG_LEN;
+               tx_alloc = 0;
+
+       } else {
+
+               tx_alloc = htc_get_credit_alloc(target, conn_req->svc_id);
+               if (tx_alloc == 0) {
+                       status = -ENOMEM;
+                       goto free_packet;
+               }
+
+               /* allocate a packet to send to the target */
+               packet = htc_alloc_txctrl_packet(target);
+
+               if (packet == NULL) {
+                       WARN_ON_ONCE(1);
+                       status = -ENOMEM;
+                       goto free_packet;
+               }
+
+               skb = packet->skb;
+               length = sizeof(struct htc_conn_service_msg);
+
+               /* assemble connect service message */
+               conn_msg = (struct htc_conn_service_msg *) skb_put(skb,
+                                                                  length);
+               if (conn_msg == NULL) {
+                       WARN_ON_ONCE(1);
+                       status = -EINVAL;
+                       goto free_packet;
+               }
+
+               memset(conn_msg, 0,
+                      sizeof(struct htc_conn_service_msg));
+               conn_msg->msg_id = cpu_to_le16(HTC_MSG_CONN_SVC_ID);
+               conn_msg->svc_id = cpu_to_le16(conn_req->svc_id);
+               conn_msg->conn_flags = cpu_to_le16(conn_req->conn_flags &
+                                       ~HTC_CONN_FLGS_SET_RECV_ALLOC_MASK);
+
+               /* tell target desired recv alloc for this ep */
+               flags = tx_alloc << HTC_CONN_FLGS_SET_RECV_ALLOC_SHIFT;
+               conn_msg->conn_flags |= cpu_to_le16(flags);
+
+               if (conn_req->conn_flags &
+                   HTC_CONN_FLGS_DISABLE_CRED_FLOW_CTRL) {
+                       disable_credit_flowctrl = true;
+               }
+
+               set_htc_pkt_info(packet, NULL, (u8 *) conn_msg,
+                                length,
+                                ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
+
+               status = ath6kl_htc_pipe_tx(target, packet);
+
+               /* we don't own it anymore */
+               packet = NULL;
+               if (status != 0)
+                       goto free_packet;
+
+               /* wait for response */
+               status = htc_wait_recv_ctrl_message(target);
+               if (status != 0)
+                       goto free_packet;
+
+               /* we controlled the buffer creation so it has to be
+                * properly aligned
+                */
+               resp_msg = (struct htc_conn_service_resp *)
+                   target->pipe.ctrl_response_buf;
+
+               if (resp_msg->msg_id != cpu_to_le16(HTC_MSG_CONN_SVC_RESP_ID) ||
+                   (target->pipe.ctrl_response_len < sizeof(*resp_msg))) {
+                       /* this message is not valid */
+                       WARN_ON_ONCE(1);
+                       status = -EINVAL;
+                       goto free_packet;
+               }
+
+               ath6kl_dbg(ATH6KL_DBG_TRC,
+                          "%s: service 0x%X conn resp: status: %d ep: %d\n",
+                          __func__, resp_msg->svc_id, resp_msg->status,
+                          resp_msg->eid);
+
+               conn_resp->resp_code = resp_msg->status;
+               /* check response status */
+               if (resp_msg->status != HTC_SERVICE_SUCCESS) {
+                       ath6kl_dbg(ATH6KL_DBG_HTC,
+                                  "Target failed service 0x%X connect request (status:%d)\n",
+                                  resp_msg->svc_id, resp_msg->status);
+                       status = -EINVAL;
+                       goto free_packet;
+               }
+
+               assigned_epid = (enum htc_endpoint_id) resp_msg->eid;
+               max_msg_size = le16_to_cpu(resp_msg->max_msg_sz);
+       }
+
+       /* the rest are parameter checks so set the error status */
+       status = -EINVAL;
+
+       if (assigned_epid >= ENDPOINT_MAX) {
+               WARN_ON_ONCE(1);
+               goto free_packet;
+       }
+
+       if (max_msg_size == 0) {
+               WARN_ON_ONCE(1);
+               goto free_packet;
+       }
+
+       ep = &target->endpoint[assigned_epid];
+       ep->eid = assigned_epid;
+       if (ep->svc_id != 0) {
+               /* endpoint already in use! */
+               WARN_ON_ONCE(1);
+               goto free_packet;
+       }
+
+       /* return assigned endpoint to caller */
+       conn_resp->endpoint = assigned_epid;
+       conn_resp->len_max = max_msg_size;
+
+       /* setup the endpoint */
+       ep->svc_id = conn_req->svc_id; /* this marks ep in use */
+       ep->max_txq_depth = conn_req->max_txq_depth;
+       ep->len_max = max_msg_size;
+       ep->cred_dist.credits = tx_alloc;
+       ep->cred_dist.cred_sz = target->tgt_cred_sz;
+       ep->cred_dist.cred_per_msg = max_msg_size / target->tgt_cred_sz;
+       if (max_msg_size % target->tgt_cred_sz)
+               ep->cred_dist.cred_per_msg++;
+
+       /* copy all the callbacks */
+       ep->ep_cb = conn_req->ep_cb;
+
+       status = ath6kl_hif_pipe_map_service(ar, ep->svc_id,
+                                            &ep->pipe.pipeid_ul,
+                                            &ep->pipe.pipeid_dl);
+       if (status != 0)
+               goto free_packet;
+
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "SVC Ready: 0x%4.4X: ULpipe:%d DLpipe:%d id:%d\n",
+                  ep->svc_id, ep->pipe.pipeid_ul,
+                  ep->pipe.pipeid_dl, ep->eid);
+
+       if (disable_credit_flowctrl && ep->pipe.tx_credit_flow_enabled) {
+               ep->pipe.tx_credit_flow_enabled = false;
+               ath6kl_dbg(ATH6KL_DBG_HTC,
+                          "SVC: 0x%4.4X ep:%d TX flow control off\n",
+                          ep->svc_id, assigned_epid);
+       }
+
+free_packet:
+       if (packet != NULL)
+               htc_free_txctrl_packet(target, packet);
+       return status;
+}
+
+/* htc export functions */
+static void *ath6kl_htc_pipe_create(struct ath6kl *ar)
+{
+       int status = 0;
+       struct htc_endpoint *ep = NULL;
+       struct htc_target *target = NULL;
+       struct htc_packet *packet;
+       int i;
+
+       target = kzalloc(sizeof(struct htc_target), GFP_KERNEL);
+       if (target == NULL) {
+               ath6kl_err("htc create unable to allocate memory\n");
+               status = -ENOMEM;
+               goto fail_htc_create;
+       }
+
+       spin_lock_init(&target->htc_lock);
+       spin_lock_init(&target->rx_lock);
+       spin_lock_init(&target->tx_lock);
+
+       reset_endpoint_states(target);
+
+       for (i = 0; i < HTC_PACKET_CONTAINER_ALLOCATION; i++) {
+               packet = kzalloc(sizeof(struct htc_packet), GFP_KERNEL);
+
+               if (packet != NULL)
+                       free_htc_packet_container(target, packet);
+       }
+
+       target->dev = kzalloc(sizeof(*target->dev), GFP_KERNEL);
+       if (!target->dev) {
+               ath6kl_err("unable to allocate memory\n");
+               status = -ENOMEM;
+               goto fail_htc_create;
+       }
+       target->dev->ar = ar;
+       target->dev->htc_cnxt = target;
+
+       /* Get HIF default pipe for HTC message exchange */
+       ep = &target->endpoint[ENDPOINT_0];
+
+       ath6kl_hif_pipe_get_default(ar, &ep->pipe.pipeid_ul,
+                                   &ep->pipe.pipeid_dl);
+
+       return target;
+
+fail_htc_create:
+       if (status != 0) {
+               if (target != NULL)
+                       ath6kl_htc_pipe_cleanup(target);
+
+               target = NULL;
+       }
+       return target;
+}
+
+/* cleanup the HTC instance */
+static void ath6kl_htc_pipe_cleanup(struct htc_target *target)
+{
+       struct htc_packet *packet;
+
+       while (true) {
+               packet = alloc_htc_packet_container(target);
+               if (packet == NULL)
+                       break;
+               kfree(packet);
+       }
+
+       kfree(target->dev);
+
+       /* kfree our instance */
+       kfree(target);
+}
+
+static int ath6kl_htc_pipe_start(struct htc_target *target)
+{
+       struct sk_buff *skb;
+       struct htc_setup_comp_ext_msg *setup;
+       struct htc_packet *packet;
+
+       htc_config_target_hif_pipe(target);
+
+       /* allocate a buffer to send */
+       packet = htc_alloc_txctrl_packet(target);
+       if (packet == NULL) {
+               WARN_ON_ONCE(1);
+               return -ENOMEM;
+       }
+
+       skb = packet->skb;
+
+       /* assemble setup complete message */
+       setup = (struct htc_setup_comp_ext_msg *) skb_put(skb,
+                                                         sizeof(*setup));
+       memset(setup, 0, sizeof(struct htc_setup_comp_ext_msg));
+       setup->msg_id = cpu_to_le16(HTC_MSG_SETUP_COMPLETE_EX_ID);
+
+       ath6kl_dbg(ATH6KL_DBG_HTC, "HTC using TX credit flow control\n");
+
+       set_htc_pkt_info(packet, NULL, (u8 *) setup,
+                        sizeof(struct htc_setup_comp_ext_msg),
+                        ENDPOINT_0, HTC_SERVICE_TX_PACKET_TAG);
+
+       target->htc_flags |= HTC_OP_STATE_SETUP_COMPLETE;
+
+       return ath6kl_htc_pipe_tx(target, packet);
+}
+
+static void ath6kl_htc_pipe_stop(struct htc_target *target)
+{
+       int i;
+       struct htc_endpoint *ep;
+
+       /* cleanup endpoints */
+       for (i = 0; i < ENDPOINT_MAX; i++) {
+               ep = &target->endpoint[i];
+               htc_flush_rx_queue(target, ep);
+               htc_flush_tx_endpoint(target, ep, HTC_TX_PACKET_TAG_ALL);
+       }
+
+       reset_endpoint_states(target);
+       target->htc_flags &= ~HTC_OP_STATE_SETUP_COMPLETE;
+}
+
+static int ath6kl_htc_pipe_get_rxbuf_num(struct htc_target *target,
+                                        enum htc_endpoint_id endpoint)
+{
+       int num;
+
+       spin_lock_bh(&target->rx_lock);
+       num = get_queue_depth(&(target->endpoint[endpoint].rx_bufq));
+       spin_unlock_bh(&target->rx_lock);
+
+       return num;
+}
+
+static int ath6kl_htc_pipe_tx(struct htc_target *target,
+                             struct htc_packet *packet)
+{
+       struct list_head queue;
+
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "%s: endPointId: %d, buffer: 0x%p, length: %d\n",
+                  __func__, packet->endpoint, packet->buf,
+                  packet->act_len);
+
+       INIT_LIST_HEAD(&queue);
+       list_add_tail(&packet->list, &queue);
+
+       return htc_send_packets_multiple(target, &queue);
+}
+
+static int ath6kl_htc_pipe_wait_target(struct htc_target *target)
+{
+       struct htc_ready_ext_msg *ready_msg;
+       struct htc_service_connect_req connect;
+       struct htc_service_connect_resp resp;
+       int status = 0;
+
+       status = htc_wait_recv_ctrl_message(target);
+
+       if (status != 0)
+               return status;
+
+       if (target->pipe.ctrl_response_len < sizeof(*ready_msg)) {
+               ath6kl_dbg(ATH6KL_DBG_HTC, "invalid htc ready msg len:%d!\n",
+                          target->pipe.ctrl_response_len);
+               return -ECOMM;
+       }
+
+       ready_msg = (struct htc_ready_ext_msg *) target->pipe.ctrl_response_buf;
+
+       if (ready_msg->ver2_0_info.msg_id != cpu_to_le16(HTC_MSG_READY_ID)) {
+               ath6kl_dbg(ATH6KL_DBG_HTC, "invalid htc ready msg : 0x%X !\n",
+                          ready_msg->ver2_0_info.msg_id);
+               return -ECOMM;
+       }
+
+       ath6kl_dbg(ATH6KL_DBG_HTC,
+                  "Target Ready! : transmit resources : %d size:%d\n",
+                  ready_msg->ver2_0_info.cred_cnt,
+                  ready_msg->ver2_0_info.cred_sz);
+
+       target->tgt_creds = le16_to_cpu(ready_msg->ver2_0_info.cred_cnt);
+       target->tgt_cred_sz = le16_to_cpu(ready_msg->ver2_0_info.cred_sz);
+
+       if ((target->tgt_creds == 0) || (target->tgt_cred_sz == 0))
+               return -ECOMM;
+
+       htc_setup_target_buffer_assignments(target);
+
+       /* setup our pseudo HTC control endpoint connection */
+       memset(&connect, 0, sizeof(connect));
+       memset(&resp, 0, sizeof(resp));
+       connect.ep_cb.tx_complete = htc_txctrl_complete;
+       connect.ep_cb.rx = htc_rxctrl_complete;
+       connect.max_txq_depth = NUM_CONTROL_TX_BUFFERS;
+       connect.svc_id = HTC_CTRL_RSVD_SVC;
+
+       /* connect fake service */
+       status = ath6kl_htc_pipe_conn_service(target, &connect, &resp);
+
+       return status;
+}
+
+static void ath6kl_htc_pipe_flush_txep(struct htc_target *target,
+                                      enum htc_endpoint_id endpoint, u16 tag)
+{
+       struct htc_endpoint *ep = &target->endpoint[endpoint];
+
+       if (ep->svc_id == 0) {
+               WARN_ON_ONCE(1);
+               /* not in use.. */
+               return;
+       }
+
+       htc_flush_tx_endpoint(target, ep, tag);
+}
+
+static int ath6kl_htc_pipe_add_rxbuf_multiple(struct htc_target *target,
+                                             struct list_head *pkt_queue)
+{
+       struct htc_packet *packet, *tmp_pkt, *first;
+       struct htc_endpoint *ep;
+       int status = 0;
+
+       if (list_empty(pkt_queue))
+               return -EINVAL;
+
+       first = list_first_entry(pkt_queue, struct htc_packet, list);
+       if (first == NULL) {
+               WARN_ON_ONCE(1);
+               return -EINVAL;
+       }
+
+       if (first->endpoint >= ENDPOINT_MAX) {
+               WARN_ON_ONCE(1);
+               return -EINVAL;
+       }
+
+       ath6kl_dbg(ATH6KL_DBG_HTC, "%s: epid: %d, cnt:%d, len: %d\n",
+                  __func__, first->endpoint, get_queue_depth(pkt_queue),
+                  first->buf_len);
+
+       ep = &target->endpoint[first->endpoint];
+
+       spin_lock_bh(&target->rx_lock);
+
+       /* store receive packets */
+       list_splice_tail_init(pkt_queue, &ep->rx_bufq);
+
+       spin_unlock_bh(&target->rx_lock);
+
+       if (status != 0) {
+               /* walk through queue and mark each one canceled */
+               list_for_each_entry_safe(packet, tmp_pkt, pkt_queue, list) {
+                       packet->status = -ECANCELED;
+               }
+
+               do_recv_completion(ep, pkt_queue);
+       }
+
+       return status;
+}
+
+static void ath6kl_htc_pipe_activity_changed(struct htc_target *target,
+                                            enum htc_endpoint_id ep,
+                                            bool active)
+{
+       /* TODO */
+}
+
+static void ath6kl_htc_pipe_flush_rx_buf(struct htc_target *target)
+{
+       /* TODO */
+}
+
+static int ath6kl_htc_pipe_credit_setup(struct htc_target *target,
+                                       struct ath6kl_htc_credit_info *info)
+{
+       return 0;
+}
+
+static const struct ath6kl_htc_ops ath6kl_htc_pipe_ops = {
+       .create = ath6kl_htc_pipe_create,
+       .wait_target = ath6kl_htc_pipe_wait_target,
+       .start = ath6kl_htc_pipe_start,
+       .conn_service = ath6kl_htc_pipe_conn_service,
+       .tx = ath6kl_htc_pipe_tx,
+       .stop = ath6kl_htc_pipe_stop,
+       .cleanup = ath6kl_htc_pipe_cleanup,
+       .flush_txep = ath6kl_htc_pipe_flush_txep,
+       .flush_rx_buf = ath6kl_htc_pipe_flush_rx_buf,
+       .activity_changed = ath6kl_htc_pipe_activity_changed,
+       .get_rxbuf_num = ath6kl_htc_pipe_get_rxbuf_num,
+       .add_rxbuf_multiple = ath6kl_htc_pipe_add_rxbuf_multiple,
+       .credit_setup = ath6kl_htc_pipe_credit_setup,
+       .tx_complete = ath6kl_htc_pipe_tx_complete,
+       .rx_complete = ath6kl_htc_pipe_rx_complete,
+};
+
+void ath6kl_htc_pipe_attach(struct ath6kl *ar)
+{
+       ar->htc_ops = &ath6kl_htc_pipe_ops;
+}
index eb7cc2f5b96f14f428f2f3590cf17abe92abdb79..29ef50ea07d570036154416fcca0848b1d83e34f 100644 (file)
 #include <linux/export.h>
 #include <linux/of.h>
 #include <linux/mmc/sdio_func.h>
+#include <linux/vmalloc.h>
 
 #include "core.h"
 #include "cfg80211.h"
 #include "target.h"
 #include "debug.h"
 #include "hif-ops.h"
+#include "htc-ops.h"
 
 static const struct ath6kl_hw hw_list[] = {
        {
@@ -258,6 +260,7 @@ static int ath6kl_init_service_ep(struct ath6kl *ar)
        memset(&connect, 0, sizeof(connect));
 
        /* these fields are the same for all service endpoints */
+       connect.ep_cb.tx_comp_multi = ath6kl_tx_complete;
        connect.ep_cb.rx = ath6kl_rx;
        connect.ep_cb.rx_refill = ath6kl_rx_refill;
        connect.ep_cb.tx_full = ath6kl_tx_queue_full;
@@ -487,22 +490,31 @@ int ath6kl_configure_target(struct ath6kl *ar)
                fw_mode |= fw_iftype << (i * HI_OPTION_FW_MODE_BITS);
 
        /*
-        * By default, submodes :
+        * Submodes when fw does not support dynamic interface
+        * switching:
         *              vif[0] - AP/STA/IBSS
         *              vif[1] - "P2P dev"/"P2P GO"/"P2P Client"
         *              vif[2] - "P2P dev"/"P2P GO"/"P2P Client"
+        * Otherwise, All the interface are initialized to p2p dev.
         */
 
-       for (i = 0; i < ar->max_norm_iface; i++)
-               fw_submode |= HI_OPTION_FW_SUBMODE_NONE <<
-                             (i * HI_OPTION_FW_SUBMODE_BITS);
+       if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
+                    ar->fw_capabilities)) {
+               for (i = 0; i < ar->vif_max; i++)
+                       fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV <<
+                               (i * HI_OPTION_FW_SUBMODE_BITS);
+       } else {
+               for (i = 0; i < ar->max_norm_iface; i++)
+                       fw_submode |= HI_OPTION_FW_SUBMODE_NONE <<
+                               (i * HI_OPTION_FW_SUBMODE_BITS);
 
-       for (i = ar->max_norm_iface; i < ar->vif_max; i++)
-               fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV <<
-                             (i * HI_OPTION_FW_SUBMODE_BITS);
+               for (i = ar->max_norm_iface; i < ar->vif_max; i++)
+                       fw_submode |= HI_OPTION_FW_SUBMODE_P2PDEV <<
+                               (i * HI_OPTION_FW_SUBMODE_BITS);
 
-       if (ar->p2p && ar->vif_max == 1)
-               fw_submode = HI_OPTION_FW_SUBMODE_P2PDEV;
+               if (ar->p2p && ar->vif_max == 1)
+                       fw_submode = HI_OPTION_FW_SUBMODE_P2PDEV;
+       }
 
        if (ath6kl_bmi_write_hi32(ar, hi_app_host_interest,
                                  HTC_PROTOCOL_VERSION) != 0) {
@@ -541,18 +553,20 @@ int ath6kl_configure_target(struct ath6kl *ar)
         * but possible in theory.
         */
 
-       param = ar->hw.board_ext_data_addr;
-       ram_reserved_size = ar->hw.reserved_ram_size;
+       if (ar->target_type == TARGET_TYPE_AR6003) {
+               param = ar->hw.board_ext_data_addr;
+               ram_reserved_size = ar->hw.reserved_ram_size;
 
-       if (ath6kl_bmi_write_hi32(ar, hi_board_ext_data, param) != 0) {
-               ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
-               return -EIO;
-       }
+               if (ath6kl_bmi_write_hi32(ar, hi_board_ext_data, param) != 0) {
+                       ath6kl_err("bmi_write_memory for hi_board_ext_data failed\n");
+                       return -EIO;
+               }
 
-       if (ath6kl_bmi_write_hi32(ar, hi_end_ram_reserve_sz,
-                                 ram_reserved_size) != 0) {
-               ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
-               return -EIO;
+               if (ath6kl_bmi_write_hi32(ar, hi_end_ram_reserve_sz,
+                                         ram_reserved_size) != 0) {
+                       ath6kl_err("bmi_write_memory for hi_end_ram_reserve_sz failed\n");
+                       return -EIO;
+               }
        }
 
        /* set the block size for the target */
@@ -926,13 +940,14 @@ static int ath6kl_fetch_fw_apin(struct ath6kl *ar, const char *name)
                        if (ar->fw != NULL)
                                break;
 
-                       ar->fw = kmemdup(data, ie_len, GFP_KERNEL);
+                       ar->fw = vmalloc(ie_len);
 
                        if (ar->fw == NULL) {
                                ret = -ENOMEM;
                                goto out;
                        }
 
+                       memcpy(ar->fw, data, ie_len);
                        ar->fw_len = ie_len;
                        break;
                case ATH6KL_FW_IE_PATCH_IMAGE:
@@ -1509,7 +1524,7 @@ int ath6kl_init_hw_start(struct ath6kl *ar)
        }
 
        /* setup credit distribution */
-       ath6kl_credit_setup(ar->htc_target, &ar->credit_state_info);
+       ath6kl_htc_credit_setup(ar->htc_target, &ar->credit_state_info);
 
        /* start HTC */
        ret = ath6kl_htc_start(ar->htc_target);
index 07071fce8a0e0196391ad06d6d4d7e18ae47da57..4d818f96c415e372f2e2a8ba6d4ffc0fb164a190 100644 (file)
@@ -758,6 +758,10 @@ static void ath6kl_update_target_stats(struct ath6kl_vif *vif, u8 *ptr, u32 len)
        stats->wow_evt_discarded +=
                le16_to_cpu(tgt_stats->wow_stats.wow_evt_discarded);
 
+       stats->arp_received = le32_to_cpu(tgt_stats->arp_stats.arp_received);
+       stats->arp_replied = le32_to_cpu(tgt_stats->arp_stats.arp_replied);
+       stats->arp_matched = le32_to_cpu(tgt_stats->arp_stats.arp_matched);
+
        if (test_bit(STATS_UPDATE_PEND, &vif->flags)) {
                clear_bit(STATS_UPDATE_PEND, &vif->flags);
                wake_up(&ar->event_wq);
index 53528648b425807c7785c2f7a2facb57bc790f9e..44ea7a742101b31f4160f490b41e8cbcf818596c 100644 (file)
@@ -1362,7 +1362,7 @@ static int ath6kl_sdio_probe(struct sdio_func *func,
                goto err_core_alloc;
        }
 
-       ret = ath6kl_core_init(ar);
+       ret = ath6kl_core_init(ar, ATH6KL_HTC_TYPE_MBOX);
        if (ret) {
                ath6kl_err("Failed to init ath6kl core\n");
                goto err_core_alloc;
index 521f0be990f1db589faca36aa2e7d98af963e668..82f2f5cb475b0b3ba8e7bebf6fea1d86472d56fa 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "core.h"
 #include "debug.h"
+#include "htc-ops.h"
 
 /*
  * tid - tid_mux0..tid_mux3
@@ -324,6 +325,7 @@ int ath6kl_control_tx(void *devt, struct sk_buff *skb,
        cookie->map_no = 0;
        set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len,
                         eid, ATH6KL_CONTROL_PKT_TAG);
+       cookie->htc_pkt.skb = skb;
 
        /*
         * This interface is asynchronous, if there is an error, cleanup
@@ -492,6 +494,7 @@ int ath6kl_data_tx(struct sk_buff *skb, struct net_device *dev)
        cookie->map_no = map_no;
        set_htc_pkt_info(&cookie->htc_pkt, cookie, skb->data, skb->len,
                         eid, htc_tag);
+       cookie->htc_pkt.skb = skb;
 
        ath6kl_dbg_dump(ATH6KL_DBG_RAW_BYTES, __func__, "tx ",
                        skb->data, skb->len);
@@ -572,7 +575,7 @@ void ath6kl_indicate_tx_activity(void *devt, u8 traffic_class, bool active)
 
 notify_htc:
        /* notify HTC, this may cause credit distribution changes */
-       ath6kl_htc_indicate_activity_change(ar->htc_target, eid, active);
+       ath6kl_htc_activity_changed(ar->htc_target, eid, active);
 }
 
 enum htc_send_full_action ath6kl_tx_queue_full(struct htc_target *target,
@@ -668,9 +671,10 @@ static void ath6kl_tx_clear_node_map(struct ath6kl_vif *vif,
        }
 }
 
-void ath6kl_tx_complete(void *context, struct list_head *packet_queue)
+void ath6kl_tx_complete(struct htc_target *target,
+                       struct list_head *packet_queue)
 {
-       struct ath6kl *ar = context;
+       struct ath6kl *ar = target->dev->ar;
        struct sk_buff_head skb_queue;
        struct htc_packet *packet;
        struct sk_buff *skb;
@@ -889,6 +893,7 @@ void ath6kl_rx_refill(struct htc_target *target, enum htc_endpoint_id endpoint)
                        skb->data = PTR_ALIGN(skb->data - 4, 4);
                set_htc_rxpkt_info(packet, skb, skb->data,
                                   ATH6KL_BUFFER_SIZE, endpoint);
+               packet->skb = skb;
                list_add_tail(&packet->list, &queue);
        }
 
@@ -911,6 +916,8 @@ void ath6kl_refill_amsdu_rxbufs(struct ath6kl *ar, int count)
                        skb->data = PTR_ALIGN(skb->data - 4, 4);
                set_htc_rxpkt_info(packet, skb, skb->data,
                                   ATH6KL_AMSDU_BUFFER_SIZE, 0);
+               packet->skb = skb;
+
                spin_lock_bh(&ar->lock);
                list_add_tail(&packet->list, &ar->amsdu_rx_buffer_queue);
                spin_unlock_bh(&ar->lock);
@@ -1283,6 +1290,7 @@ void ath6kl_rx(struct htc_target *target, struct htc_packet *packet)
        struct wmi_data_hdr *dhdr;
        int min_hdr_len;
        u8 meta_type, dot11_hdr = 0;
+       u8 pad_before_data_start;
        int status = packet->status;
        enum htc_endpoint_id ept = packet->endpoint;
        bool is_amsdu, prev_ps, ps_state = false;
@@ -1494,6 +1502,10 @@ void ath6kl_rx(struct htc_target *target, struct htc_packet *packet)
        seq_no = wmi_data_hdr_get_seqno(dhdr);
        meta_type = wmi_data_hdr_get_meta(dhdr);
        dot11_hdr = wmi_data_hdr_get_dot11(dhdr);
+       pad_before_data_start =
+               (le16_to_cpu(dhdr->info3) >> WMI_DATA_HDR_PAD_BEFORE_DATA_SHIFT)
+                       & WMI_DATA_HDR_PAD_BEFORE_DATA_MASK;
+
        skb_pull(skb, sizeof(struct wmi_data_hdr));
 
        switch (meta_type) {
@@ -1512,6 +1524,8 @@ void ath6kl_rx(struct htc_target *target, struct htc_packet *packet)
                break;
        }
 
+       skb_pull(skb, pad_before_data_start);
+
        if (dot11_hdr)
                status = ath6kl_wmi_dot11_hdr_remove(ar->wmi, skb);
        else if (!is_amsdu)
@@ -1581,7 +1595,8 @@ void ath6kl_rx(struct htc_target *target, struct htc_packet *packet)
                        /* aggregation code will handle the skb */
                        return;
                }
-       }
+       } else if (!is_broadcast_ether_addr(datap->h_dest))
+               vif->net_stats.multicast++;
 
        ath6kl_deliver_frames_to_nw_stack(vif->ndev, skb);
 }
index 325b1224c2b13b6bf9aae818acb01e3aeac0862e..ec7f1f5fd1cac4a335e04b5f8db39e639fe9c43e 100644 (file)
 #include "debug.h"
 #include "core.h"
 
+/* constants */
+#define TX_URB_COUNT            32
+#define RX_URB_COUNT            32
+#define ATH6KL_USB_RX_BUFFER_SIZE  1700
+
+/* tx/rx pipes for usb */
+enum ATH6KL_USB_PIPE_ID {
+       ATH6KL_USB_PIPE_TX_CTRL = 0,
+       ATH6KL_USB_PIPE_TX_DATA_LP,
+       ATH6KL_USB_PIPE_TX_DATA_MP,
+       ATH6KL_USB_PIPE_TX_DATA_HP,
+       ATH6KL_USB_PIPE_RX_CTRL,
+       ATH6KL_USB_PIPE_RX_DATA,
+       ATH6KL_USB_PIPE_RX_DATA2,
+       ATH6KL_USB_PIPE_RX_INT,
+       ATH6KL_USB_PIPE_MAX
+};
+
+#define ATH6KL_USB_PIPE_INVALID ATH6KL_USB_PIPE_MAX
+
+struct ath6kl_usb_pipe {
+       struct list_head urb_list_head;
+       struct usb_anchor urb_submitted;
+       u32 urb_alloc;
+       u32 urb_cnt;
+       u32 urb_cnt_thresh;
+       unsigned int usb_pipe_handle;
+       u32 flags;
+       u8 ep_address;
+       u8 logical_pipe_num;
+       struct ath6kl_usb *ar_usb;
+       u16 max_packet_size;
+       struct work_struct io_complete_work;
+       struct sk_buff_head io_comp_queue;
+       struct usb_endpoint_descriptor *ep_desc;
+};
+
+#define ATH6KL_USB_PIPE_FLAG_TX    (1 << 0)
+
 /* usb device object */
 struct ath6kl_usb {
+       /* protects pipe->urb_list_head and  pipe->urb_cnt */
+       spinlock_t cs_lock;
+
        struct usb_device *udev;
        struct usb_interface *interface;
+       struct ath6kl_usb_pipe pipes[ATH6KL_USB_PIPE_MAX];
        u8 *diag_cmd_buffer;
        u8 *diag_resp_buffer;
        struct ath6kl *ar;
 };
 
+/* usb urb object */
+struct ath6kl_urb_context {
+       struct list_head link;
+       struct ath6kl_usb_pipe *pipe;
+       struct sk_buff *skb;
+       struct ath6kl *ar;
+};
+
+/* USB endpoint definitions */
+#define ATH6KL_USB_EP_ADDR_APP_CTRL_IN          0x81
+#define ATH6KL_USB_EP_ADDR_APP_DATA_IN          0x82
+#define ATH6KL_USB_EP_ADDR_APP_DATA2_IN         0x83
+#define ATH6KL_USB_EP_ADDR_APP_INT_IN           0x84
+
+#define ATH6KL_USB_EP_ADDR_APP_CTRL_OUT         0x01
+#define ATH6KL_USB_EP_ADDR_APP_DATA_LP_OUT      0x02
+#define ATH6KL_USB_EP_ADDR_APP_DATA_MP_OUT      0x03
+#define ATH6KL_USB_EP_ADDR_APP_DATA_HP_OUT      0x04
+
 /* diagnostic command defnitions */
 #define ATH6KL_USB_CONTROL_REQ_SEND_BMI_CMD        1
 #define ATH6KL_USB_CONTROL_REQ_RECV_BMI_RESP       2
@@ -55,11 +117,493 @@ struct ath6kl_usb_ctrl_diag_resp_read {
        __le32 value;
 } __packed;
 
+/* function declarations */
+static void ath6kl_usb_recv_complete(struct urb *urb);
+
+#define ATH6KL_USB_IS_BULK_EP(attr) (((attr) & 3) == 0x02)
+#define ATH6KL_USB_IS_INT_EP(attr)  (((attr) & 3) == 0x03)
+#define ATH6KL_USB_IS_ISOC_EP(attr)  (((attr) & 3) == 0x01)
+#define ATH6KL_USB_IS_DIR_IN(addr)  ((addr) & 0x80)
+
+/* pipe/urb operations */
+static struct ath6kl_urb_context *
+ath6kl_usb_alloc_urb_from_pipe(struct ath6kl_usb_pipe *pipe)
+{
+       struct ath6kl_urb_context *urb_context = NULL;
+       unsigned long flags;
+
+       spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags);
+       if (!list_empty(&pipe->urb_list_head)) {
+               urb_context =
+                   list_first_entry(&pipe->urb_list_head,
+                                    struct ath6kl_urb_context, link);
+               list_del(&urb_context->link);
+               pipe->urb_cnt--;
+       }
+       spin_unlock_irqrestore(&pipe->ar_usb->cs_lock, flags);
+
+       return urb_context;
+}
+
+static void ath6kl_usb_free_urb_to_pipe(struct ath6kl_usb_pipe *pipe,
+                                       struct ath6kl_urb_context *urb_context)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&pipe->ar_usb->cs_lock, flags);
+       pipe->urb_cnt++;
+
+       list_add(&urb_context->link, &pipe->urb_list_head);
+       spin_unlock_irqrestore(&pipe->ar_usb->cs_lock, flags);
+}
+
+static void ath6kl_usb_cleanup_recv_urb(struct ath6kl_urb_context *urb_context)
+{
+       if (urb_context->skb != NULL) {
+               dev_kfree_skb(urb_context->skb);
+               urb_context->skb = NULL;
+       }
+
+       ath6kl_usb_free_urb_to_pipe(urb_context->pipe, urb_context);
+}
+
+static inline struct ath6kl_usb *ath6kl_usb_priv(struct ath6kl *ar)
+{
+       return ar->hif_priv;
+}
+
+/* pipe resource allocation/cleanup */
+static int ath6kl_usb_alloc_pipe_resources(struct ath6kl_usb_pipe *pipe,
+                                          int urb_cnt)
+{
+       struct ath6kl_urb_context *urb_context;
+       int status = 0, i;
+
+       INIT_LIST_HEAD(&pipe->urb_list_head);
+       init_usb_anchor(&pipe->urb_submitted);
+
+       for (i = 0; i < urb_cnt; i++) {
+               urb_context = kzalloc(sizeof(struct ath6kl_urb_context),
+                                     GFP_KERNEL);
+               if (urb_context == NULL)
+                       /* FIXME: set status to -ENOMEM */
+                       break;
+
+               urb_context->pipe = pipe;
+
+               /*
+                * we are only allocate the urb contexts here, the actual URB
+                * is allocated from the kernel as needed to do a transaction
+                */
+               pipe->urb_alloc++;
+               ath6kl_usb_free_urb_to_pipe(pipe, urb_context);
+       }
+
+       ath6kl_dbg(ATH6KL_DBG_USB,
+                  "ath6kl usb: alloc resources lpipe:%d hpipe:0x%X urbs:%d\n",
+                  pipe->logical_pipe_num, pipe->usb_pipe_handle,
+                  pipe->urb_alloc);
+
+       return status;
+}
+
+static void ath6kl_usb_free_pipe_resources(struct ath6kl_usb_pipe *pipe)
+{
+       struct ath6kl_urb_context *urb_context;
+
+       if (pipe->ar_usb == NULL) {
+               /* nothing allocated for this pipe */
+               return;
+       }
+
+       ath6kl_dbg(ATH6KL_DBG_USB,
+                  "ath6kl usb: free resources lpipe:%d"
+                  "hpipe:0x%X urbs:%d avail:%d\n",
+                  pipe->logical_pipe_num, pipe->usb_pipe_handle,
+                  pipe->urb_alloc, pipe->urb_cnt);
+
+       if (pipe->urb_alloc != pipe->urb_cnt) {
+               ath6kl_dbg(ATH6KL_DBG_USB,
+                          "ath6kl usb: urb leak! lpipe:%d"
+                          "hpipe:0x%X urbs:%d avail:%d\n",
+                          pipe->logical_pipe_num, pipe->usb_pipe_handle,
+                          pipe->urb_alloc, pipe->urb_cnt);
+       }
+
+       while (true) {
+               urb_context = ath6kl_usb_alloc_urb_from_pipe(pipe);
+               if (urb_context == NULL)
+                       break;
+               kfree(urb_context);
+       }
+
+}
+
+static void ath6kl_usb_cleanup_pipe_resources(struct ath6kl_usb *ar_usb)
+{
+       int i;
+
+       for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++)
+               ath6kl_usb_free_pipe_resources(&ar_usb->pipes[i]);
+
+}
+
+static u8 ath6kl_usb_get_logical_pipe_num(struct ath6kl_usb *ar_usb,
+                                         u8 ep_address, int *urb_count)
+{
+       u8 pipe_num = ATH6KL_USB_PIPE_INVALID;
+
+       switch (ep_address) {
+       case ATH6KL_USB_EP_ADDR_APP_CTRL_IN:
+               pipe_num = ATH6KL_USB_PIPE_RX_CTRL;
+               *urb_count = RX_URB_COUNT;
+               break;
+       case ATH6KL_USB_EP_ADDR_APP_DATA_IN:
+               pipe_num = ATH6KL_USB_PIPE_RX_DATA;
+               *urb_count = RX_URB_COUNT;
+               break;
+       case ATH6KL_USB_EP_ADDR_APP_INT_IN:
+               pipe_num = ATH6KL_USB_PIPE_RX_INT;
+               *urb_count = RX_URB_COUNT;
+               break;
+       case ATH6KL_USB_EP_ADDR_APP_DATA2_IN:
+               pipe_num = ATH6KL_USB_PIPE_RX_DATA2;
+               *urb_count = RX_URB_COUNT;
+               break;
+       case ATH6KL_USB_EP_ADDR_APP_CTRL_OUT:
+               pipe_num = ATH6KL_USB_PIPE_TX_CTRL;
+               *urb_count = TX_URB_COUNT;
+               break;
+       case ATH6KL_USB_EP_ADDR_APP_DATA_LP_OUT:
+               pipe_num = ATH6KL_USB_PIPE_TX_DATA_LP;
+               *urb_count = TX_URB_COUNT;
+               break;
+       case ATH6KL_USB_EP_ADDR_APP_DATA_MP_OUT:
+               pipe_num = ATH6KL_USB_PIPE_TX_DATA_MP;
+               *urb_count = TX_URB_COUNT;
+               break;
+       case ATH6KL_USB_EP_ADDR_APP_DATA_HP_OUT:
+               pipe_num = ATH6KL_USB_PIPE_TX_DATA_HP;
+               *urb_count = TX_URB_COUNT;
+               break;
+       default:
+               /* note: there may be endpoints not currently used */
+               break;
+       }
+
+       return pipe_num;
+}
+
+static int ath6kl_usb_setup_pipe_resources(struct ath6kl_usb *ar_usb)
+{
+       struct usb_interface *interface = ar_usb->interface;
+       struct usb_host_interface *iface_desc = interface->cur_altsetting;
+       struct usb_endpoint_descriptor *endpoint;
+       struct ath6kl_usb_pipe *pipe;
+       int i, urbcount, status = 0;
+       u8 pipe_num;
+
+       ath6kl_dbg(ATH6KL_DBG_USB, "setting up USB Pipes using interface\n");
+
+       /* walk decriptors and setup pipes */
+       for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
+               endpoint = &iface_desc->endpoint[i].desc;
+
+               if (ATH6KL_USB_IS_BULK_EP(endpoint->bmAttributes)) {
+                       ath6kl_dbg(ATH6KL_DBG_USB,
+                                  "%s Bulk Ep:0x%2.2X maxpktsz:%d\n",
+                                  ATH6KL_USB_IS_DIR_IN
+                                  (endpoint->bEndpointAddress) ?
+                                  "RX" : "TX", endpoint->bEndpointAddress,
+                                  le16_to_cpu(endpoint->wMaxPacketSize));
+               } else if (ATH6KL_USB_IS_INT_EP(endpoint->bmAttributes)) {
+                       ath6kl_dbg(ATH6KL_DBG_USB,
+                                  "%s Int Ep:0x%2.2X maxpktsz:%d interval:%d\n",
+                                  ATH6KL_USB_IS_DIR_IN
+                                  (endpoint->bEndpointAddress) ?
+                                  "RX" : "TX", endpoint->bEndpointAddress,
+                                  le16_to_cpu(endpoint->wMaxPacketSize),
+                                  endpoint->bInterval);
+               } else if (ATH6KL_USB_IS_ISOC_EP(endpoint->bmAttributes)) {
+                       /* TODO for ISO */
+                       ath6kl_dbg(ATH6KL_DBG_USB,
+                                  "%s ISOC Ep:0x%2.2X maxpktsz:%d interval:%d\n",
+                                  ATH6KL_USB_IS_DIR_IN
+                                  (endpoint->bEndpointAddress) ?
+                                  "RX" : "TX", endpoint->bEndpointAddress,
+                                  le16_to_cpu(endpoint->wMaxPacketSize),
+                                  endpoint->bInterval);
+               }
+               urbcount = 0;
+
+               pipe_num =
+                   ath6kl_usb_get_logical_pipe_num(ar_usb,
+                                                   endpoint->bEndpointAddress,
+                                                   &urbcount);
+               if (pipe_num == ATH6KL_USB_PIPE_INVALID)
+                       continue;
+
+               pipe = &ar_usb->pipes[pipe_num];
+               if (pipe->ar_usb != NULL) {
+                       /* hmmm..pipe was already setup */
+                       continue;
+               }
+
+               pipe->ar_usb = ar_usb;
+               pipe->logical_pipe_num = pipe_num;
+               pipe->ep_address = endpoint->bEndpointAddress;
+               pipe->max_packet_size = le16_to_cpu(endpoint->wMaxPacketSize);
+
+               if (ATH6KL_USB_IS_BULK_EP(endpoint->bmAttributes)) {
+                       if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) {
+                               pipe->usb_pipe_handle =
+                                   usb_rcvbulkpipe(ar_usb->udev,
+                                                   pipe->ep_address);
+                       } else {
+                               pipe->usb_pipe_handle =
+                                   usb_sndbulkpipe(ar_usb->udev,
+                                                   pipe->ep_address);
+                       }
+               } else if (ATH6KL_USB_IS_INT_EP(endpoint->bmAttributes)) {
+                       if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) {
+                               pipe->usb_pipe_handle =
+                                   usb_rcvintpipe(ar_usb->udev,
+                                                  pipe->ep_address);
+                       } else {
+                               pipe->usb_pipe_handle =
+                                   usb_sndintpipe(ar_usb->udev,
+                                                  pipe->ep_address);
+                       }
+               } else if (ATH6KL_USB_IS_ISOC_EP(endpoint->bmAttributes)) {
+                       /* TODO for ISO */
+                       if (ATH6KL_USB_IS_DIR_IN(pipe->ep_address)) {
+                               pipe->usb_pipe_handle =
+                                   usb_rcvisocpipe(ar_usb->udev,
+                                                   pipe->ep_address);
+                       } else {
+                               pipe->usb_pipe_handle =
+                                   usb_sndisocpipe(ar_usb->udev,
+                                                   pipe->ep_address);
+                       }
+               }
+
+               pipe->ep_desc = endpoint;
+
+               if (!ATH6KL_USB_IS_DIR_IN(pipe->ep_address))
+                       pipe->flags |= ATH6KL_USB_PIPE_FLAG_TX;
+
+               status = ath6kl_usb_alloc_pipe_resources(pipe, urbcount);
+               if (status != 0)
+                       break;
+       }
+
+       return status;
+}
+
+/* pipe operations */
+static void ath6kl_usb_post_recv_transfers(struct ath6kl_usb_pipe *recv_pipe,
+                                          int buffer_length)
+{
+       struct ath6kl_urb_context *urb_context;
+       struct urb *urb;
+       int usb_status;
+
+       while (true) {
+               urb_context = ath6kl_usb_alloc_urb_from_pipe(recv_pipe);
+               if (urb_context == NULL)
+                       break;
+
+               urb_context->skb = dev_alloc_skb(buffer_length);
+               if (urb_context->skb == NULL)
+                       goto err_cleanup_urb;
+
+               urb = usb_alloc_urb(0, GFP_ATOMIC);
+               if (urb == NULL)
+                       goto err_cleanup_urb;
+
+               usb_fill_bulk_urb(urb,
+                                 recv_pipe->ar_usb->udev,
+                                 recv_pipe->usb_pipe_handle,
+                                 urb_context->skb->data,
+                                 buffer_length,
+                                 ath6kl_usb_recv_complete, urb_context);
+
+               ath6kl_dbg(ATH6KL_DBG_USB_BULK,
+                          "ath6kl usb: bulk recv submit:%d, 0x%X (ep:0x%2.2X), %d bytes buf:0x%p\n",
+                          recv_pipe->logical_pipe_num,
+                          recv_pipe->usb_pipe_handle, recv_pipe->ep_address,
+                          buffer_length, urb_context->skb);
+
+               usb_anchor_urb(urb, &recv_pipe->urb_submitted);
+               usb_status = usb_submit_urb(urb, GFP_ATOMIC);
+
+               if (usb_status) {
+                       ath6kl_dbg(ATH6KL_DBG_USB_BULK,
+                                  "ath6kl usb : usb bulk recv failed %d\n",
+                                  usb_status);
+                       usb_unanchor_urb(urb);
+                       usb_free_urb(urb);
+                       goto err_cleanup_urb;
+               }
+               usb_free_urb(urb);
+       }
+       return;
+
+err_cleanup_urb:
+       ath6kl_usb_cleanup_recv_urb(urb_context);
+       return;
+}
+
+static void ath6kl_usb_flush_all(struct ath6kl_usb *ar_usb)
+{
+       int i;
+
+       for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++) {
+               if (ar_usb->pipes[i].ar_usb != NULL)
+                       usb_kill_anchored_urbs(&ar_usb->pipes[i].urb_submitted);
+       }
+
+       /*
+        * Flushing any pending I/O may schedule work this call will block
+        * until all scheduled work runs to completion.
+        */
+       flush_scheduled_work();
+}
+
+static void ath6kl_usb_start_recv_pipes(struct ath6kl_usb *ar_usb)
+{
+       /*
+        * note: control pipe is no longer used
+        * ar_usb->pipes[ATH6KL_USB_PIPE_RX_CTRL].urb_cnt_thresh =
+        *      ar_usb->pipes[ATH6KL_USB_PIPE_RX_CTRL].urb_alloc/2;
+        * ath6kl_usb_post_recv_transfers(&ar_usb->
+        *              pipes[ATH6KL_USB_PIPE_RX_CTRL],
+        *              ATH6KL_USB_RX_BUFFER_SIZE);
+        */
+
+       ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA].urb_cnt_thresh =
+           ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA].urb_alloc / 2;
+       ath6kl_usb_post_recv_transfers(&ar_usb->pipes[ATH6KL_USB_PIPE_RX_DATA],
+                                      ATH6KL_USB_RX_BUFFER_SIZE);
+}
+
+/* hif usb rx/tx completion functions */
+static void ath6kl_usb_recv_complete(struct urb *urb)
+{
+       struct ath6kl_urb_context *urb_context = urb->context;
+       struct ath6kl_usb_pipe *pipe = urb_context->pipe;
+       struct sk_buff *skb = NULL;
+       int status = 0;
+
+       ath6kl_dbg(ATH6KL_DBG_USB_BULK,
+                  "%s: recv pipe: %d, stat:%d, len:%d urb:0x%p\n", __func__,
+                  pipe->logical_pipe_num, urb->status, urb->actual_length,
+                  urb);
+
+       if (urb->status != 0) {
+               status = -EIO;
+               switch (urb->status) {
+               case -ECONNRESET:
+               case -ENOENT:
+               case -ESHUTDOWN:
+                       /*
+                        * no need to spew these errors when device
+                        * removed or urb killed due to driver shutdown
+                        */
+                       status = -ECANCELED;
+                       break;
+               default:
+                       ath6kl_dbg(ATH6KL_DBG_USB_BULK,
+                                  "%s recv pipe: %d (ep:0x%2.2X), failed:%d\n",
+                                  __func__, pipe->logical_pipe_num,
+                                  pipe->ep_address, urb->status);
+                       break;
+               }
+               goto cleanup_recv_urb;
+       }
+
+       if (urb->actual_length == 0)
+               goto cleanup_recv_urb;
+
+       skb = urb_context->skb;
+
+       /* we are going to pass it up */
+       urb_context->skb = NULL;
+       skb_put(skb, urb->actual_length);
+
+       /* note: queue implements a lock */
+       skb_queue_tail(&pipe->io_comp_queue, skb);
+       schedule_work(&pipe->io_complete_work);
+
+cleanup_recv_urb:
+       ath6kl_usb_cleanup_recv_urb(urb_context);
+
+       if (status == 0 &&
+           pipe->urb_cnt >= pipe->urb_cnt_thresh) {
+               /* our free urbs are piling up, post more transfers */
+               ath6kl_usb_post_recv_transfers(pipe, ATH6KL_USB_RX_BUFFER_SIZE);
+       }
+}
+
+static void ath6kl_usb_usb_transmit_complete(struct urb *urb)
+{
+       struct ath6kl_urb_context *urb_context = urb->context;
+       struct ath6kl_usb_pipe *pipe = urb_context->pipe;
+       struct sk_buff *skb;
+
+       ath6kl_dbg(ATH6KL_DBG_USB_BULK,
+                  "%s: pipe: %d, stat:%d, len:%d\n",
+                  __func__, pipe->logical_pipe_num, urb->status,
+                  urb->actual_length);
+
+       if (urb->status != 0) {
+               ath6kl_dbg(ATH6KL_DBG_USB_BULK,
+                          "%s:  pipe: %d, failed:%d\n",
+                          __func__, pipe->logical_pipe_num, urb->status);
+       }
+
+       skb = urb_context->skb;
+       urb_context->skb = NULL;
+       ath6kl_usb_free_urb_to_pipe(urb_context->pipe, urb_context);
+
+       /* note: queue implements a lock */
+       skb_queue_tail(&pipe->io_comp_queue, skb);
+       schedule_work(&pipe->io_complete_work);
+}
+
+static void ath6kl_usb_io_comp_work(struct work_struct *work)
+{
+       struct ath6kl_usb_pipe *pipe = container_of(work,
+                                                   struct ath6kl_usb_pipe,
+                                                   io_complete_work);
+       struct ath6kl_usb *ar_usb;
+       struct sk_buff *skb;
+
+       ar_usb = pipe->ar_usb;
+
+       while ((skb = skb_dequeue(&pipe->io_comp_queue))) {
+               if (pipe->flags & ATH6KL_USB_PIPE_FLAG_TX) {
+                       ath6kl_dbg(ATH6KL_DBG_USB_BULK,
+                                  "ath6kl usb xmit callback buf:0x%p\n", skb);
+                       ath6kl_core_tx_complete(ar_usb->ar, skb);
+               } else {
+                       ath6kl_dbg(ATH6KL_DBG_USB_BULK,
+                                  "ath6kl usb recv callback buf:0x%p\n", skb);
+                       ath6kl_core_rx_complete(ar_usb->ar, skb,
+                                               pipe->logical_pipe_num);
+               }
+       }
+}
+
 #define ATH6KL_USB_MAX_DIAG_CMD (sizeof(struct ath6kl_usb_ctrl_diag_cmd_write))
 #define ATH6KL_USB_MAX_DIAG_RESP (sizeof(struct ath6kl_usb_ctrl_diag_resp_read))
 
 static void ath6kl_usb_destroy(struct ath6kl_usb *ar_usb)
 {
+       ath6kl_usb_flush_all(ar_usb);
+
+       ath6kl_usb_cleanup_pipe_resources(ar_usb);
+
        usb_set_intfdata(ar_usb->interface, NULL);
 
        kfree(ar_usb->diag_cmd_buffer);
@@ -70,19 +614,28 @@ static void ath6kl_usb_destroy(struct ath6kl_usb *ar_usb)
 
 static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface)
 {
-       struct ath6kl_usb *ar_usb = NULL;
        struct usb_device *dev = interface_to_usbdev(interface);
+       struct ath6kl_usb *ar_usb;
+       struct ath6kl_usb_pipe *pipe;
        int status = 0;
+       int i;
 
        ar_usb = kzalloc(sizeof(struct ath6kl_usb), GFP_KERNEL);
        if (ar_usb == NULL)
                goto fail_ath6kl_usb_create;
 
-       memset(ar_usb, 0, sizeof(struct ath6kl_usb));
        usb_set_intfdata(interface, ar_usb);
+       spin_lock_init(&(ar_usb->cs_lock));
        ar_usb->udev = dev;
        ar_usb->interface = interface;
 
+       for (i = 0; i < ATH6KL_USB_PIPE_MAX; i++) {
+               pipe = &ar_usb->pipes[i];
+               INIT_WORK(&pipe->io_complete_work,
+                         ath6kl_usb_io_comp_work);
+               skb_queue_head_init(&pipe->io_comp_queue);
+       }
+
        ar_usb->diag_cmd_buffer = kzalloc(ATH6KL_USB_MAX_DIAG_CMD, GFP_KERNEL);
        if (ar_usb->diag_cmd_buffer == NULL) {
                status = -ENOMEM;
@@ -96,6 +649,8 @@ static struct ath6kl_usb *ath6kl_usb_create(struct usb_interface *interface)
                goto fail_ath6kl_usb_create;
        }
 
+       status = ath6kl_usb_setup_pipe_resources(ar_usb);
+
 fail_ath6kl_usb_create:
        if (status != 0) {
                ath6kl_usb_destroy(ar_usb);
@@ -114,11 +669,177 @@ static void ath6kl_usb_device_detached(struct usb_interface *interface)
 
        ath6kl_stop_txrx(ar_usb->ar);
 
+       /* Delay to wait for the target to reboot */
+       mdelay(20);
        ath6kl_core_cleanup(ar_usb->ar);
-
        ath6kl_usb_destroy(ar_usb);
 }
 
+/* exported hif usb APIs for htc pipe */
+static void hif_start(struct ath6kl *ar)
+{
+       struct ath6kl_usb *device = ath6kl_usb_priv(ar);
+       int i;
+
+       ath6kl_usb_start_recv_pipes(device);
+
+       /* set the TX resource avail threshold for each TX pipe */
+       for (i = ATH6KL_USB_PIPE_TX_CTRL;
+            i <= ATH6KL_USB_PIPE_TX_DATA_HP; i++) {
+               device->pipes[i].urb_cnt_thresh =
+                   device->pipes[i].urb_alloc / 2;
+       }
+}
+
+static int ath6kl_usb_send(struct ath6kl *ar, u8 PipeID,
+                          struct sk_buff *hdr_skb, struct sk_buff *skb)
+{
+       struct ath6kl_usb *device = ath6kl_usb_priv(ar);
+       struct ath6kl_usb_pipe *pipe = &device->pipes[PipeID];
+       struct ath6kl_urb_context *urb_context;
+       int usb_status, status = 0;
+       struct urb *urb;
+       u8 *data;
+       u32 len;
+
+       ath6kl_dbg(ATH6KL_DBG_USB_BULK, "+%s pipe : %d, buf:0x%p\n",
+                  __func__, PipeID, skb);
+
+       urb_context = ath6kl_usb_alloc_urb_from_pipe(pipe);
+
+       if (urb_context == NULL) {
+               /*
+                * TODO: it is possible to run out of urbs if
+                * 2 endpoints map to the same pipe ID
+                */
+               ath6kl_dbg(ATH6KL_DBG_USB_BULK,
+                          "%s pipe:%d no urbs left. URB Cnt : %d\n",
+                          __func__, PipeID, pipe->urb_cnt);
+               status = -ENOMEM;
+               goto fail_hif_send;
+       }
+
+       urb_context->skb = skb;
+
+       data = skb->data;
+       len = skb->len;
+
+       urb = usb_alloc_urb(0, GFP_ATOMIC);
+       if (urb == NULL) {
+               status = -ENOMEM;
+               ath6kl_usb_free_urb_to_pipe(urb_context->pipe,
+                                           urb_context);
+               goto fail_hif_send;
+       }
+
+       usb_fill_bulk_urb(urb,
+                         device->udev,
+                         pipe->usb_pipe_handle,
+                         data,
+                         len,
+                         ath6kl_usb_usb_transmit_complete, urb_context);
+
+       if ((len % pipe->max_packet_size) == 0) {
+               /* hit a max packet boundary on this pipe */
+               urb->transfer_flags |= URB_ZERO_PACKET;
+       }
+
+       ath6kl_dbg(ATH6KL_DBG_USB_BULK,
+                  "athusb bulk send submit:%d, 0x%X (ep:0x%2.2X), %d bytes\n",
+                  pipe->logical_pipe_num, pipe->usb_pipe_handle,
+                  pipe->ep_address, len);
+
+       usb_anchor_urb(urb, &pipe->urb_submitted);
+       usb_status = usb_submit_urb(urb, GFP_ATOMIC);
+
+       if (usb_status) {
+               ath6kl_dbg(ATH6KL_DBG_USB_BULK,
+                          "ath6kl usb : usb bulk transmit failed %d\n",
+                          usb_status);
+               usb_unanchor_urb(urb);
+               ath6kl_usb_free_urb_to_pipe(urb_context->pipe,
+                                           urb_context);
+               status = -EINVAL;
+       }
+       usb_free_urb(urb);
+
+fail_hif_send:
+       return status;
+}
+
+static void hif_stop(struct ath6kl *ar)
+{
+       struct ath6kl_usb *device = ath6kl_usb_priv(ar);
+
+       ath6kl_usb_flush_all(device);
+}
+
+static void ath6kl_usb_get_default_pipe(struct ath6kl *ar,
+                                       u8 *ul_pipe, u8 *dl_pipe)
+{
+       *ul_pipe = ATH6KL_USB_PIPE_TX_CTRL;
+       *dl_pipe = ATH6KL_USB_PIPE_RX_CTRL;
+}
+
+static int ath6kl_usb_map_service_pipe(struct ath6kl *ar, u16 svc_id,
+                                      u8 *ul_pipe, u8 *dl_pipe)
+{
+       int status = 0;
+
+       switch (svc_id) {
+       case HTC_CTRL_RSVD_SVC:
+       case WMI_CONTROL_SVC:
+               *ul_pipe = ATH6KL_USB_PIPE_TX_CTRL;
+               /* due to large control packets, shift to data pipe */
+               *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
+               break;
+       case WMI_DATA_BE_SVC:
+       case WMI_DATA_BK_SVC:
+               *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_LP;
+               /*
+               * Disable rxdata2 directly, it will be enabled
+               * if FW enable rxdata2
+               */
+               *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
+               break;
+       case WMI_DATA_VI_SVC:
+               *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_MP;
+               /*
+               * Disable rxdata2 directly, it will be enabled
+               * if FW enable rxdata2
+               */
+               *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
+               break;
+       case WMI_DATA_VO_SVC:
+               *ul_pipe = ATH6KL_USB_PIPE_TX_DATA_HP;
+               /*
+               * Disable rxdata2 directly, it will be enabled
+               * if FW enable rxdata2
+               */
+               *dl_pipe = ATH6KL_USB_PIPE_RX_DATA;
+               break;
+       default:
+               status = -EPERM;
+               break;
+       }
+
+       return status;
+}
+
+static u16 ath6kl_usb_get_free_queue_number(struct ath6kl *ar, u8 pipe_id)
+{
+       struct ath6kl_usb *device = ath6kl_usb_priv(ar);
+
+       return device->pipes[pipe_id].urb_cnt;
+}
+
+static void hif_detach_htc(struct ath6kl *ar)
+{
+       struct ath6kl_usb *device = ath6kl_usb_priv(ar);
+
+       ath6kl_usb_flush_all(device);
+}
+
 static int ath6kl_usb_submit_ctrl_out(struct ath6kl_usb *ar_usb,
                                   u8 req, u16 value, u16 index, void *data,
                                   u32 size)
@@ -301,14 +1022,21 @@ static int ath6kl_usb_bmi_write(struct ath6kl *ar, u8 *buf, u32 len)
 
 static int ath6kl_usb_power_on(struct ath6kl *ar)
 {
+       hif_start(ar);
        return 0;
 }
 
 static int ath6kl_usb_power_off(struct ath6kl *ar)
 {
+       hif_detach_htc(ar);
        return 0;
 }
 
+static void ath6kl_usb_stop(struct ath6kl *ar)
+{
+       hif_stop(ar);
+}
+
 static const struct ath6kl_hif_ops ath6kl_usb_ops = {
        .diag_read32 = ath6kl_usb_diag_read32,
        .diag_write32 = ath6kl_usb_diag_write32,
@@ -316,6 +1044,11 @@ static const struct ath6kl_hif_ops ath6kl_usb_ops = {
        .bmi_write = ath6kl_usb_bmi_write,
        .power_on = ath6kl_usb_power_on,
        .power_off = ath6kl_usb_power_off,
+       .stop = ath6kl_usb_stop,
+       .pipe_send = ath6kl_usb_send,
+       .pipe_get_default = ath6kl_usb_get_default_pipe,
+       .pipe_map_service = ath6kl_usb_map_service_pipe,
+       .pipe_get_free_queue_number = ath6kl_usb_get_free_queue_number,
 };
 
 /* ath6kl usb driver registered functions */
@@ -368,7 +1101,7 @@ static int ath6kl_usb_probe(struct usb_interface *interface,
 
        ar_usb->ar = ar;
 
-       ret = ath6kl_core_init(ar);
+       ret = ath6kl_core_init(ar, ATH6KL_HTC_TYPE_PIPE);
        if (ret) {
                ath6kl_err("Failed to init ath6kl core: %d\n", ret);
                goto err_core_free;
@@ -392,6 +1125,46 @@ static void ath6kl_usb_remove(struct usb_interface *interface)
        ath6kl_usb_device_detached(interface);
 }
 
+#ifdef CONFIG_PM
+
+static int ath6kl_usb_suspend(struct usb_interface *interface,
+                             pm_message_t message)
+{
+       struct ath6kl_usb *device;
+       device = usb_get_intfdata(interface);
+
+       ath6kl_usb_flush_all(device);
+       return 0;
+}
+
+static int ath6kl_usb_resume(struct usb_interface *interface)
+{
+       struct ath6kl_usb *device;
+       device = usb_get_intfdata(interface);
+
+       ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA],
+                                      ATH6KL_USB_RX_BUFFER_SIZE);
+       ath6kl_usb_post_recv_transfers(&device->pipes[ATH6KL_USB_PIPE_RX_DATA2],
+                                      ATH6KL_USB_RX_BUFFER_SIZE);
+
+       return 0;
+}
+
+static int ath6kl_usb_reset_resume(struct usb_interface *intf)
+{
+       if (usb_get_intfdata(intf))
+               ath6kl_usb_remove(intf);
+       return 0;
+}
+
+#else
+
+#define ath6kl_usb_suspend NULL
+#define ath6kl_usb_resume NULL
+#define ath6kl_usb_reset_resume NULL
+
+#endif
+
 /* table of devices that work with this driver */
 static struct usb_device_id ath6kl_usb_ids[] = {
        {USB_DEVICE(0x0cf3, 0x9374)},
@@ -403,8 +1176,12 @@ MODULE_DEVICE_TABLE(usb, ath6kl_usb_ids);
 static struct usb_driver ath6kl_usb_driver = {
        .name = "ath6kl_usb",
        .probe = ath6kl_usb_probe,
+       .suspend = ath6kl_usb_suspend,
+       .resume = ath6kl_usb_resume,
+       .reset_resume = ath6kl_usb_reset_resume,
        .disconnect = ath6kl_usb_remove,
        .id_table = ath6kl_usb_ids,
+       .supports_autosuspend = true,
 };
 
 static int ath6kl_usb_init(void)
index 2b442332cd0f7f2aa9b93df4c1eabbb83b1bf0f4..7c8a9977faf5a99b19529fd383782bd30714a514 100644 (file)
@@ -2882,6 +2882,43 @@ int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
        return ret;
 }
 
+int ath6kl_wmi_set_htcap_cmd(struct wmi *wmi, u8 if_idx,
+                            enum ieee80211_band band,
+                            struct ath6kl_htcap *htcap)
+{
+       struct sk_buff *skb;
+       struct wmi_set_htcap_cmd *cmd;
+
+       skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
+       if (!skb)
+               return -ENOMEM;
+
+       cmd = (struct wmi_set_htcap_cmd *) skb->data;
+
+       /*
+        * NOTE: Band in firmware matches enum ieee80211_band, it is unlikely
+        * this will be changed in firmware. If at all there is any change in
+        * band value, the host needs to be fixed.
+        */
+       cmd->band = band;
+       cmd->ht_enable = !!htcap->ht_enable;
+       cmd->ht20_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_20);
+       cmd->ht40_supported =
+               !!(htcap->cap_info & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
+       cmd->ht40_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_40);
+       cmd->intolerant_40mhz =
+               !!(htcap->cap_info & IEEE80211_HT_CAP_40MHZ_INTOLERANT);
+       cmd->max_ampdu_len_exp = htcap->ampdu_factor;
+
+       ath6kl_dbg(ATH6KL_DBG_WMI,
+                  "Set htcap: band:%d ht_enable:%d 40mhz:%d sgi_20mhz:%d sgi_40mhz:%d 40mhz_intolerant:%d ampdu_len_exp:%d\n",
+                  cmd->band, cmd->ht_enable, cmd->ht40_supported,
+                  cmd->ht20_sgi, cmd->ht40_sgi, cmd->intolerant_40mhz,
+                  cmd->max_ampdu_len_exp);
+       return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_HT_CAP_CMDID,
+                                  NO_SYNC_WMIFLAG);
+}
+
 int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
 {
        struct sk_buff *skb;
@@ -3032,6 +3069,9 @@ int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
        cm->reason = cpu_to_le16(reason);
        cm->cmd = cmd;
 
+       ath6kl_dbg(ATH6KL_DBG_WMI, "ap_set_mlme: cmd=%d reason=%d\n", cm->cmd,
+                  cm->reason);
+
        return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
                                   NO_SYNC_WMIFLAG);
 }
@@ -3181,6 +3221,29 @@ int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
                                   NO_SYNC_WMIFLAG);
 }
 
+int ath6kl_wmi_set_ie_cmd(struct wmi *wmi, u8 if_idx, u8 ie_id, u8 ie_field,
+                         const u8 *ie_info, u8 ie_len)
+{
+       struct sk_buff *skb;
+       struct wmi_set_ie_cmd *p;
+
+       skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
+       if (!skb)
+               return -ENOMEM;
+
+       ath6kl_dbg(ATH6KL_DBG_WMI, "set_ie_cmd: ie_id=%u ie_ie_field=%u ie_len=%u\n",
+                  ie_id, ie_field, ie_len);
+       p = (struct wmi_set_ie_cmd *) skb->data;
+       p->ie_id = ie_id;
+       p->ie_field = ie_field;
+       p->ie_len = ie_len;
+       if (ie_info && ie_len > 0)
+               memcpy(p->ie_info, ie_info, ie_len);
+
+       return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IE_CMDID,
+                                  NO_SYNC_WMIFLAG);
+}
+
 int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
 {
        struct sk_buff *skb;
@@ -3392,6 +3455,23 @@ int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
                                     WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
 }
 
+int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout)
+{
+       struct sk_buff *skb;
+       struct wmi_set_inact_period_cmd *cmd;
+
+       skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
+       if (!skb)
+               return -ENOMEM;
+
+       cmd = (struct wmi_set_inact_period_cmd *) skb->data;
+       cmd->inact_period = cpu_to_le32(inact_timeout);
+       cmd->num_null_func = 0;
+
+       return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_CONN_INACT_CMDID,
+                                  NO_SYNC_WMIFLAG);
+}
+
 static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
 {
        struct wmix_cmd_hdr *cmd;
index 4092e3e80790f6d4ee58672c56e66d87f6f81f38..d3d2ab5c1689aa85695352d4c7dd97ad8e916a0c 100644 (file)
@@ -182,6 +182,9 @@ enum wmi_data_hdr_flags {
 #define WMI_DATA_HDR_META_MASK      0x7
 #define WMI_DATA_HDR_META_SHIFT     13
 
+#define WMI_DATA_HDR_PAD_BEFORE_DATA_MASK               0xFF
+#define WMI_DATA_HDR_PAD_BEFORE_DATA_SHIFT              0x8
+
 /* Macros for operating on WMI_DATA_HDR (info3) field */
 #define WMI_DATA_HDR_IF_IDX_MASK    0xF
 
@@ -423,6 +426,7 @@ enum wmi_cmd_id {
        WMI_SET_FRAMERATES_CMDID,
        WMI_SET_AP_PS_CMDID,
        WMI_SET_QOS_SUPP_CMDID,
+       WMI_SET_IE_CMDID,
 
        /* WMI_THIN_RESERVED_... mark the start and end
         * values for WMI_THIN_RESERVED command IDs. These
@@ -629,6 +633,11 @@ enum wmi_mgmt_frame_type {
        WMI_NUM_MGMT_FRAME
 };
 
+enum wmi_ie_field_type {
+       WMI_RSN_IE_CAPB = 0x1,
+       WMI_IE_FULL     = 0xFF,  /* indicats full IE */
+};
+
 /* WMI_CONNECT_CMDID  */
 enum network_type {
        INFRA_NETWORK = 0x01,
@@ -1268,6 +1277,16 @@ struct wmi_mcast_filter_add_del_cmd {
        u8 mcast_mac[ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE];
 } __packed;
 
+struct wmi_set_htcap_cmd {
+       u8 band;
+       u8 ht_enable;
+       u8 ht40_supported;
+       u8 ht20_sgi;
+       u8 ht40_sgi;
+       u8 intolerant_40mhz;
+       u8 max_ampdu_len_exp;
+} __packed;
+
 /* Command Replies */
 
 /* WMI_GET_CHANNEL_LIST_CMDID reply */
@@ -1913,6 +1932,14 @@ struct wmi_set_appie_cmd {
        u8 ie_info[0];
 } __packed;
 
+struct wmi_set_ie_cmd {
+       u8 ie_id;
+       u8 ie_field;    /* enum wmi_ie_field_type */
+       u8 ie_len;
+       u8 reserved;
+       u8 ie_info[0];
+} __packed;
+
 /* Notify the WSC registration status to the target */
 #define WSC_REG_ACTIVE     1
 #define WSC_REG_INACTIVE   0
@@ -2141,6 +2168,11 @@ struct wmi_ap_hidden_ssid_cmd {
        u8 hidden_ssid;
 } __packed;
 
+struct wmi_set_inact_period_cmd {
+       __le32 inact_period;
+       u8 num_null_func;
+} __packed;
+
 /* AP mode events */
 struct wmi_ap_set_apsd_cmd {
        u8 enable;
@@ -2465,6 +2497,9 @@ int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi);
 int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg);
 int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
                                 u8 keep_alive_intvl);
+int ath6kl_wmi_set_htcap_cmd(struct wmi *wmi, u8 if_idx,
+                            enum ieee80211_band band,
+                            struct ath6kl_htcap *htcap);
 int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len);
 
 s32 ath6kl_wmi_get_rate(s8 rate_index);
@@ -2515,6 +2550,9 @@ int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
 int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
                             const u8 *ie, u8 ie_len);
 
+int ath6kl_wmi_set_ie_cmd(struct wmi *wmi, u8 if_idx, u8 ie_id, u8 ie_field,
+                         const u8 *ie_info, u8 ie_len);
+
 /* P2P */
 int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable);
 
@@ -2538,6 +2576,8 @@ int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx);
 int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
                             const u8 *ie, u8 ie_len);
 
+int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout);
+
 void ath6kl_wmi_sscan_timer(unsigned long ptr);
 
 struct ath6kl_vif *ath6kl_get_vif_by_index(struct ath6kl *ar, u8 if_idx);
index 47a9fb4a116a0cfd6b9e15992c3c692a4f20fdd8..b4c77f9d74701163c08e20ea4096a5acace22b64 100644 (file)
@@ -274,7 +274,9 @@ static void ath9k_hw_set_ofdm_nil(struct ath_hw *ah, u8 immunityLevel)
                aniState->rssiThrLow, aniState->rssiThrHigh);
 
        if (aniState->update_ani)
-               aniState->ofdmNoiseImmunityLevel = immunityLevel;
+               aniState->ofdmNoiseImmunityLevel =
+                       (immunityLevel > ATH9K_ANI_OFDM_DEF_LEVEL) ?
+                       immunityLevel : ATH9K_ANI_OFDM_DEF_LEVEL;
 
        entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
        entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
@@ -340,7 +342,9 @@ static void ath9k_hw_set_cck_nil(struct ath_hw *ah, u_int8_t immunityLevel)
                immunityLevel = ATH9K_ANI_CCK_MAX_LEVEL_LOW_RSSI;
 
        if (aniState->update_ani)
-               aniState->cckNoiseImmunityLevel = immunityLevel;
+               aniState->cckNoiseImmunityLevel =
+                       (immunityLevel > ATH9K_ANI_CCK_DEF_LEVEL) ?
+                       immunityLevel : ATH9K_ANI_CCK_DEF_LEVEL;
 
        entry_ofdm = &ofdm_level_table[aniState->ofdmNoiseImmunityLevel];
        entry_cck = &cck_level_table[aniState->cckNoiseImmunityLevel];
index 52ff5caf2d0bce7d4be359aef4380e951deb7b2c..de30cb34b8f3c4aefe19ddd2502d361a447ef8f1 100644 (file)
@@ -245,7 +245,6 @@ static int ar5008_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
        REG_WRITE(ah, AR_PHY(0x37), reg32);
 
        ah->curchan = chan;
-       ah->curchan_rad_index = -1;
 
        return 0;
 }
index aa2abaf31cbaae42b1313fc27579482c4ae80616..8d78253c26cee6f459121e7e8ef5c3e0e44b8b2a 100644 (file)
@@ -136,6 +136,7 @@ static bool ar9002_hw_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
        }
 
        if (sync_cause) {
+               ath9k_debug_sync_cause(common, sync_cause);
                fatal_int =
                        (sync_cause &
                         (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
index 3cbbb033fcea545c0f9e013ee02799227a79e2d6..846dd7974eb8ff4c571574d5f26dcd2c1ed98a64 100644 (file)
@@ -152,7 +152,6 @@ static int ar9002_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
        REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
 
        ah->curchan = chan;
-       ah->curchan_rad_index = -1;
 
        return 0;
 }
index 6bb4db052bb0b23aef5d50a607fcafdca9c20a16..1188db205e32d0c7b1d7c102b8dce9339f0d62b0 100644 (file)
 #define CTL_11A_EXT (CTL_11A | EXT_ADDITIVE)
 #define CTL_11G_EXT (CTL_11G | EXT_ADDITIVE)
 #define CTL_11B_EXT (CTL_11B | EXT_ADDITIVE)
-#define REDUCE_SCALED_POWER_BY_TWO_CHAIN     6  /* 10*log10(2)*2 */
-#define REDUCE_SCALED_POWER_BY_THREE_CHAIN   9  /* 10*log10(3)*2 */
-#define PWRINCR_3_TO_1_CHAIN      9             /* 10*log(3)*2 */
-#define PWRINCR_3_TO_2_CHAIN      3             /* floor(10*log(3/2)*2) */
-#define PWRINCR_2_TO_1_CHAIN      6             /* 10*log(2)*2 */
 
 #define SUB_NUM_CTL_MODES_AT_5G_40 2    /* excluding HT40, EXT-OFDM */
 #define SUB_NUM_CTL_MODES_AT_2G_40 3    /* excluding HT40, EXT-OFDM, EXT-CCK */
@@ -2936,15 +2931,6 @@ static const struct ar9300_eeprom *ar9003_eeprom_struct_find_by_id(int id)
 #undef N_LOOP
 }
 
-
-static u16 ath9k_hw_fbin2freq(u8 fbin, bool is2GHz)
-{
-       if (fbin == AR5416_BCHAN_UNUSED)
-               return fbin;
-
-       return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
-}
-
 static int ath9k_hw_ar9300_check_eeprom(struct ath_hw *ah)
 {
        return 0;
@@ -4070,7 +4056,7 @@ static u8 ar9003_hw_eeprom_get_tgt_pwr(struct ath_hw *ah,
         * targetpower piers stored on eeprom
         */
        for (i = 0; i < numPiers; i++) {
-               freqArray[i] = FBIN2FREQ(pFreqBin[i], is2GHz);
+               freqArray[i] = ath9k_hw_fbin2freq(pFreqBin[i], is2GHz);
                targetPowerArray[i] = pEepromTargetPwr[i].tPow2x[rateIndex];
        }
 
@@ -4106,7 +4092,7 @@ static u8 ar9003_hw_eeprom_get_ht20_tgt_pwr(struct ath_hw *ah,
         * from targetpower piers stored on eeprom
         */
        for (i = 0; i < numPiers; i++) {
-               freqArray[i] = FBIN2FREQ(pFreqBin[i], is2GHz);
+               freqArray[i] = ath9k_hw_fbin2freq(pFreqBin[i], is2GHz);
                targetPowerArray[i] = pEepromTargetPwr[i].tPow2x[rateIndex];
        }
 
@@ -4142,7 +4128,7 @@ static u8 ar9003_hw_eeprom_get_ht40_tgt_pwr(struct ath_hw *ah,
         * targetpower piers stored on eeprom
         */
        for (i = 0; i < numPiers; i++) {
-               freqArray[i] = FBIN2FREQ(pFreqBin[i], is2GHz);
+               freqArray[i] = ath9k_hw_fbin2freq(pFreqBin[i], is2GHz);
                targetPowerArray[i] = pEepromTargetPwr[i].tPow2x[rateIndex];
        }
 
@@ -4167,7 +4153,7 @@ static u8 ar9003_hw_eeprom_get_cck_tgt_pwr(struct ath_hw *ah,
         * targetpower piers stored on eeprom
         */
        for (i = 0; i < numPiers; i++) {
-               freqArray[i] = FBIN2FREQ(pFreqBin[i], 1);
+               freqArray[i] = ath9k_hw_fbin2freq(pFreqBin[i], 1);
                targetPowerArray[i] = pEepromTargetPwr[i].tPow2x[rateIndex];
        }
 
@@ -4464,7 +4450,7 @@ static int ar9003_hw_cal_pier_get(struct ath_hw *ah,
                is2GHz = 1;
        }
 
-       *pfrequency = FBIN2FREQ(*pCalPier, is2GHz);
+       *pfrequency = ath9k_hw_fbin2freq(*pCalPier, is2GHz);
        *pcorrection = pCalPierStruct->refPower;
        *ptemperature = pCalPierStruct->tempMeas;
        *pvoltage = pCalPierStruct->voltMeas;
@@ -4789,30 +4775,8 @@ static void ar9003_hw_set_power_per_rate_table(struct ath_hw *ah,
        bool is2ghz = IS_CHAN_2GHZ(chan);
 
        ath9k_hw_get_channel_centers(ah, chan, &centers);
-       scaledPower = powerLimit - antenna_reduction;
-
-       /*
-        * Reduce scaled Power by number of chains active to get
-        * to per chain tx power level
-        */
-       switch (ar5416_get_ntxchains(ah->txchainmask)) {
-       case 1:
-               break;
-       case 2:
-               if (scaledPower > REDUCE_SCALED_POWER_BY_TWO_CHAIN)
-                       scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
-               else
-                       scaledPower = 0;
-               break;
-       case 3:
-               if (scaledPower > REDUCE_SCALED_POWER_BY_THREE_CHAIN)
-                       scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
-               else
-                       scaledPower = 0;
-               break;
-       }
-
-       scaledPower = max((u16)0, scaledPower);
+       scaledPower = ath9k_hw_get_scaled_power(ah, powerLimit,
+                                               antenna_reduction);
 
        /*
         * Get target powers from EEPROM - our baseline for TX Power
@@ -5060,8 +5024,6 @@ static void ath9k_hw_ar9300_set_txpower(struct ath_hw *ah,
                        i, targetPowerValT2[i]);
        }
 
-       ah->txpower_limit = regulatory->max_power_level;
-
        /* Write target power array to registers */
        ar9003_hw_tx_power_regwrite(ah, targetPowerValT2);
        ar9003_hw_calibration_apply(ah, chan->channel);
index bb223fe82816fdc892327b60e6f473f7c254851e..2505ac44f0c16ff248be27b145b91cd1b90dde49 100644 (file)
@@ -42,7 +42,6 @@
 #define AR9300_EEPMISC_WOW           0x02
 #define AR9300_CUSTOMER_DATA_SIZE    20
 
-#define FBIN2FREQ(x, y) ((y) ? (2300 + x) : (4800 + 5 * x))
 #define AR9300_MAX_CHAINS            3
 #define AR9300_ANT_16S               25
 #define AR9300_FUTURE_MODAL_SZ       6
index 0f56e322dd3bb8157e850723c6a12f30f3ba9a53..a0e3394b10dc6e3696933b6435fdceedbbcdbec6 100644 (file)
@@ -305,11 +305,6 @@ static void ar9003_hw_init_mode_regs(struct ath_hw *ah)
                                ar9462_common_rx_gain_table_2p0,
                                ARRAY_SIZE(ar9462_common_rx_gain_table_2p0), 2);
 
-               INIT_INI_ARRAY(&ah->ini_BTCOEX_MAX_TXPWR,
-                               ar9462_2p0_BTCOEX_MAX_TXPWR_table,
-                               ARRAY_SIZE(ar9462_2p0_BTCOEX_MAX_TXPWR_table),
-                               2);
-
                /* Awake -> Sleep Setting */
                INIT_INI_ARRAY(&ah->iniPcieSerdes,
                                PCIE_PLL_ON_CREQ_DIS_L1_2P0,
index a66a13b768487746b96c1ebdca96c87df89681f4..d9e0824af0933ffc3d008eff856e504c508b5b2b 100644 (file)
@@ -306,6 +306,8 @@ static bool ar9003_hw_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
                ar9003_mci_get_isr(ah, masked);
 
        if (sync_cause) {
+               ath9k_debug_sync_cause(common, sync_cause);
+
                if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
                        REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
                        REG_WRITE(ah, AR_RC, 0);
index 79070bf04eab487406efd7ba4469a197a1b81a52..bbda25f4e9f0daeed3c91dccce76d7f148ac7ca6 100644 (file)
@@ -152,7 +152,6 @@ static int ar9003_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
        REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
 
        ah->curchan = chan;
-       ah->curchan_rad_index = -1;
 
        return 0;
 }
@@ -209,11 +208,12 @@ static void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah,
                        continue;
                negative = 0;
                if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah))
-                       cur_bb_spur = FBIN2FREQ(spur_fbin_ptr[i],
-                                       IS_CHAN_2GHZ(chan)) - synth_freq;
+                       cur_bb_spur = ath9k_hw_fbin2freq(spur_fbin_ptr[i],
+                                                        IS_CHAN_2GHZ(chan));
                else
-                       cur_bb_spur = spur_freq[i] - synth_freq;
+                       cur_bb_spur = spur_freq[i];
 
+               cur_bb_spur -= synth_freq;
                if (cur_bb_spur < 0) {
                        negative = 1;
                        cur_bb_spur = -cur_bb_spur;
@@ -443,7 +443,8 @@ static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
        ar9003_hw_spur_ofdm_clear(ah);
 
        for (i = 0; i < AR_EEPROM_MODAL_SPURS && spurChansPtr[i]; i++) {
-               freq_offset = FBIN2FREQ(spurChansPtr[i], mode) - synth_freq;
+               freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i], mode);
+               freq_offset -= synth_freq;
                if (abs(freq_offset) < range) {
                        ar9003_hw_spur_ofdm_work(ah, chan, freq_offset);
                        break;
@@ -684,9 +685,6 @@ static int ar9003_hw_process_ini(struct ath_hw *ah,
 
        REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites);
 
-       if (AR_SREV_9462(ah))
-               ar9003_hw_prog_ini(ah, &ah->ini_BTCOEX_MAX_TXPWR, 1);
-
        if (chan->channel == 2484)
                ar9003_hw_prog_ini(ah, &ah->ini_japan2484, 1);
 
index b6ba1e8149be5eaf85022eaecf662c9d016d452e..1d6658e139b56203460f5df454de83de6d0a1b73 100644 (file)
@@ -1115,9 +1115,9 @@ static const u32 ar9462_2p0_mac_core[][2] = {
        {0x000081f8, 0x00000000},
        {0x000081fc, 0x00000000},
        {0x00008240, 0x00100000},
-       {0x00008244, 0x0010f400},
+       {0x00008244, 0x0010f424},
        {0x00008248, 0x00000800},
-       {0x0000824c, 0x0001e800},
+       {0x0000824c, 0x0001e848},
        {0x00008250, 0x00000000},
        {0x00008254, 0x00000000},
        {0x00008258, 0x00000000},
@@ -1448,16 +1448,4 @@ static const u32 ar9462_common_mixed_rx_gain_table_2p0[][2] = {
        {0x0000b1fc, 0x00000196},
 };
 
-static const u32 ar9462_2p0_BTCOEX_MAX_TXPWR_table[][2] = {
-       /* Addr      allmodes  */
-       {0x000018c0, 0x10101010},
-       {0x000018c4, 0x10101010},
-       {0x000018c8, 0x10101010},
-       {0x000018cc, 0x10101010},
-       {0x000018d0, 0x10101010},
-       {0x000018d4, 0x10101010},
-       {0x000018d8, 0x10101010},
-       {0x000018dc, 0x10101010},
-};
-
 #endif /* INITVALS_9462_2P0_H */
index 0a37631390db8dc9c6b9c734c77a731b6298283b..a277cf6f339d4364413548f95e2f7fa5823ad45f 100644 (file)
@@ -370,7 +370,7 @@ struct ath_vif {
  * number of beacon intervals, the game's up.
  */
 #define BSTUCK_THRESH                  9
-#define        ATH_BCBUF                       4
+#define        ATH_BCBUF                       8
 #define ATH_DEFAULT_BINTVAL            100 /* TU */
 #define ATH_DEFAULT_BMISS_LIMIT        10
 #define IEEE80211_MS_TO_TU(x)           (((x) * 1000) / 1024)
index 626418222c8588ffc5e0db4dfe0368eb79849af4..702e5abc38b281a6ef7bcb2128d721e3bd3b4349 100644 (file)
@@ -91,7 +91,7 @@ static void ath_beacon_setup(struct ath_softc *sc, struct ieee80211_vif *vif,
        info.txpower = MAX_RATE_POWER;
        info.keyix = ATH9K_TXKEYIX_INVALID;
        info.keytype = ATH9K_KEY_TYPE_CLEAR;
-       info.flags = ATH9K_TXDESC_NOACK | ATH9K_TXDESC_INTREQ;
+       info.flags = ATH9K_TXDESC_NOACK | ATH9K_TXDESC_CLRDMASK;
 
        info.buf_addr[0] = bf->bf_buf_addr;
        info.buf_len[0] = roundup(skb->len, 4);
@@ -359,6 +359,11 @@ void ath_beacon_tasklet(unsigned long data)
        int slot;
        u32 bfaddr, bc = 0;
 
+       if (work_pending(&sc->hw_reset_work)) {
+               ath_dbg(common, RESET,
+                       "reset work is pending, skip beaconing now\n");
+               return;
+       }
        /*
         * Check if the previous beacon has gone out.  If
         * not don't try to post another, skip this period
@@ -369,6 +374,9 @@ void ath_beacon_tasklet(unsigned long data)
        if (ath9k_hw_numtxpending(ah, sc->beacon.beaconq) != 0) {
                sc->beacon.bmisscnt++;
 
+               if (!ath9k_hw_check_alive(ah))
+                       ieee80211_queue_work(sc->hw, &sc->hw_check_work);
+
                if (sc->beacon.bmisscnt < BSTUCK_THRESH * sc->nbcnvifs) {
                        ath_dbg(common, BSTUCK,
                                "missed %u consecutive beacons\n",
@@ -378,6 +386,7 @@ void ath_beacon_tasklet(unsigned long data)
                                ath9k_hw_bstuck_nfcal(ah);
                } else if (sc->beacon.bmisscnt >= BSTUCK_THRESH) {
                        ath_dbg(common, BSTUCK, "beacon is officially stuck\n");
+                       sc->beacon.bmisscnt = 0;
                        sc->sc_flags |= SC_OP_TSF_RESET;
                        ieee80211_queue_work(sc->hw, &sc->hw_reset_work);
                }
@@ -650,6 +659,8 @@ static void ath_beacon_config_adhoc(struct ath_softc *sc,
        u32 tsf, intval, nexttbtt;
 
        ath9k_reset_beacon_status(sc);
+       if (!(sc->sc_flags & SC_OP_BEACONS))
+               ath9k_hw_settsf64(ah, sc->beacon.bc_tstamp);
 
        intval = TU_TO_USEC(conf->beacon_interval);
        tsf = roundup(ath9k_hw_gettsf32(ah) + TU_TO_USEC(FUDGE), intval);
index 04edce941cb7a19cf53c837de2eee62980d85fc6..fde700c4e49092d760e537ba6dda6409b609fa63 100644 (file)
@@ -380,63 +380,75 @@ static ssize_t read_file_interrupt(struct file *file, char __user *user_buf,
                                   size_t count, loff_t *ppos)
 {
        struct ath_softc *sc = file->private_data;
-       char buf[512];
        unsigned int len = 0;
+       int rv;
+       int mxlen = 4000;
+       char *buf = kmalloc(mxlen, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
+#define PR_IS(a, s)                                            \
+       do {                                                    \
+               len += snprintf(buf + len, mxlen - len,         \
+                               "%21s: %10u\n", a,              \
+                               sc->debug.stats.istats.s);      \
+       } while (0)
 
        if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) {
-               len += snprintf(buf + len, sizeof(buf) - len,
-                       "%8s: %10u\n", "RXLP", sc->debug.stats.istats.rxlp);
-               len += snprintf(buf + len, sizeof(buf) - len,
-                       "%8s: %10u\n", "RXHP", sc->debug.stats.istats.rxhp);
-               len += snprintf(buf + len, sizeof(buf) - len,
-                       "%8s: %10u\n", "WATCHDOG",
-                       sc->debug.stats.istats.bb_watchdog);
+               PR_IS("RXLP", rxlp);
+               PR_IS("RXHP", rxhp);
+               PR_IS("WATHDOG", bb_watchdog);
        } else {
-               len += snprintf(buf + len, sizeof(buf) - len,
-                       "%8s: %10u\n", "RX", sc->debug.stats.istats.rxok);
+               PR_IS("RX", rxok);
        }
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "RXEOL", sc->debug.stats.istats.rxeol);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "RXORN", sc->debug.stats.istats.rxorn);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "TX", sc->debug.stats.istats.txok);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "TXURN", sc->debug.stats.istats.txurn);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "MIB", sc->debug.stats.istats.mib);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "RXPHY", sc->debug.stats.istats.rxphyerr);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "RXKCM", sc->debug.stats.istats.rx_keycache_miss);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "SWBA", sc->debug.stats.istats.swba);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "BMISS", sc->debug.stats.istats.bmiss);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "BNR", sc->debug.stats.istats.bnr);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "CST", sc->debug.stats.istats.cst);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "GTT", sc->debug.stats.istats.gtt);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "TIM", sc->debug.stats.istats.tim);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "CABEND", sc->debug.stats.istats.cabend);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "DTIMSYNC", sc->debug.stats.istats.dtimsync);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "DTIM", sc->debug.stats.istats.dtim);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "TSFOOR", sc->debug.stats.istats.tsfoor);
-       len += snprintf(buf + len, sizeof(buf) - len,
-               "%8s: %10u\n", "TOTAL", sc->debug.stats.istats.total);
-
-
-       if (len > sizeof(buf))
-               len = sizeof(buf);
-
-       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+       PR_IS("RXEOL", rxeol);
+       PR_IS("RXORN", rxorn);
+       PR_IS("TX", txok);
+       PR_IS("TXURN", txurn);
+       PR_IS("MIB", mib);
+       PR_IS("RXPHY", rxphyerr);
+       PR_IS("RXKCM", rx_keycache_miss);
+       PR_IS("SWBA", swba);
+       PR_IS("BMISS", bmiss);
+       PR_IS("BNR", bnr);
+       PR_IS("CST", cst);
+       PR_IS("GTT", gtt);
+       PR_IS("TIM", tim);
+       PR_IS("CABEND", cabend);
+       PR_IS("DTIMSYNC", dtimsync);
+       PR_IS("DTIM", dtim);
+       PR_IS("TSFOOR", tsfoor);
+       PR_IS("TOTAL", total);
+
+       len += snprintf(buf + len, mxlen - len,
+                       "SYNC_CAUSE stats:\n");
+
+       PR_IS("Sync-All", sync_cause_all);
+       PR_IS("RTC-IRQ", sync_rtc_irq);
+       PR_IS("MAC-IRQ", sync_mac_irq);
+       PR_IS("EEPROM-Illegal-Access", eeprom_illegal_access);
+       PR_IS("APB-Timeout", apb_timeout);
+       PR_IS("PCI-Mode-Conflict", pci_mode_conflict);
+       PR_IS("HOST1-Fatal", host1_fatal);
+       PR_IS("HOST1-Perr", host1_perr);
+       PR_IS("TRCV-FIFO-Perr", trcv_fifo_perr);
+       PR_IS("RADM-CPL-EP", radm_cpl_ep);
+       PR_IS("RADM-CPL-DLLP-Abort", radm_cpl_dllp_abort);
+       PR_IS("RADM-CPL-TLP-Abort", radm_cpl_tlp_abort);
+       PR_IS("RADM-CPL-ECRC-Err", radm_cpl_ecrc_err);
+       PR_IS("RADM-CPL-Timeout", radm_cpl_timeout);
+       PR_IS("Local-Bus-Timeout", local_timeout);
+       PR_IS("PM-Access", pm_access);
+       PR_IS("MAC-Awake", mac_awake);
+       PR_IS("MAC-Asleep", mac_asleep);
+       PR_IS("MAC-Sleep-Access", mac_sleep_access);
+
+       if (len > mxlen)
+               len = mxlen;
+
+       rv = simple_read_from_buffer(user_buf, count, ppos, buf, len);
+       kfree(buf);
+       return rv;
 }
 
 static const struct file_operations fops_interrupt = {
@@ -881,6 +893,13 @@ static ssize_t read_file_recv(struct file *file, char __user *user_buf,
        len += snprintf(buf + len, size - len, "%22s : %10u\n", s, \
                        sc->debug.stats.rxstats.phy_err_stats[p]);
 
+#define RXS_ERR(s, e)                                      \
+       do {                                                \
+               len += snprintf(buf + len, size - len,      \
+                               "%22s : %10u\n", s,         \
+                               sc->debug.stats.rxstats.e); \
+       } while (0)
+
        struct ath_softc *sc = file->private_data;
        char *buf;
        unsigned int len = 0, size = 1600;
@@ -890,42 +909,18 @@ static ssize_t read_file_recv(struct file *file, char __user *user_buf,
        if (buf == NULL)
                return -ENOMEM;
 
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "CRC ERR",
-                       sc->debug.stats.rxstats.crc_err);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "DECRYPT CRC ERR",
-                       sc->debug.stats.rxstats.decrypt_crc_err);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "PHY ERR",
-                       sc->debug.stats.rxstats.phy_err);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "MIC ERR",
-                       sc->debug.stats.rxstats.mic_err);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "PRE-DELIM CRC ERR",
-                       sc->debug.stats.rxstats.pre_delim_crc_err);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "POST-DELIM CRC ERR",
-                       sc->debug.stats.rxstats.post_delim_crc_err);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "DECRYPT BUSY ERR",
-                       sc->debug.stats.rxstats.decrypt_busy_err);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "RX-LENGTH-ERR",
-                       sc->debug.stats.rxstats.rx_len_err);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "RX-OOM-ERR",
-                       sc->debug.stats.rxstats.rx_oom_err);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "RX-RATE-ERR",
-                       sc->debug.stats.rxstats.rx_rate_err);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "RX-DROP-RXFLUSH",
-                       sc->debug.stats.rxstats.rx_drop_rxflush);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "RX-TOO-MANY-FRAGS",
-                       sc->debug.stats.rxstats.rx_too_many_frags_err);
+       RXS_ERR("CRC ERR", crc_err);
+       RXS_ERR("DECRYPT CRC ERR", decrypt_crc_err);
+       RXS_ERR("PHY ERR", phy_err);
+       RXS_ERR("MIC ERR", mic_err);
+       RXS_ERR("PRE-DELIM CRC ERR", pre_delim_crc_err);
+       RXS_ERR("POST-DELIM CRC ERR", post_delim_crc_err);
+       RXS_ERR("DECRYPT BUSY ERR", decrypt_busy_err);
+       RXS_ERR("RX-LENGTH-ERR", rx_len_err);
+       RXS_ERR("RX-OOM-ERR", rx_oom_err);
+       RXS_ERR("RX-RATE-ERR", rx_rate_err);
+       RXS_ERR("RX-DROP-RXFLUSH", rx_drop_rxflush);
+       RXS_ERR("RX-TOO-MANY-FRAGS", rx_too_many_frags_err);
 
        PHY_ERR("UNDERRUN ERR", ATH9K_PHYERR_UNDERRUN);
        PHY_ERR("TIMING ERR", ATH9K_PHYERR_TIMING);
@@ -954,18 +949,10 @@ static ssize_t read_file_recv(struct file *file, char __user *user_buf,
        PHY_ERR("HT-LENGTH ERR", ATH9K_PHYERR_HT_LENGTH_ILLEGAL);
        PHY_ERR("HT-RATE ERR", ATH9K_PHYERR_HT_RATE_ILLEGAL);
 
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "RX-Pkts-All",
-                       sc->debug.stats.rxstats.rx_pkts_all);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "RX-Bytes-All",
-                       sc->debug.stats.rxstats.rx_bytes_all);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "RX-Beacons",
-                       sc->debug.stats.rxstats.rx_beacons);
-       len += snprintf(buf + len, size - len,
-                       "%22s : %10u\n", "RX-Frags",
-                       sc->debug.stats.rxstats.rx_frags);
+       RXS_ERR("RX-Pkts-All", rx_pkts_all);
+       RXS_ERR("RX-Bytes-All", rx_bytes_all);
+       RXS_ERR("RX-Beacons", rx_beacons);
+       RXS_ERR("RX-Frags", rx_frags);
 
        if (len > size)
                len = size;
@@ -975,6 +962,7 @@ static ssize_t read_file_recv(struct file *file, char __user *user_buf,
 
        return retval;
 
+#undef RXS_ERR
 #undef PHY_ERR
 }
 
index 17f6cc27af32f8af1979c4b11d76bd1e68ad5f84..c34da09d91032518b7ad49fea2e41f31b2bc9152 100644 (file)
@@ -60,6 +60,7 @@ struct ath_buf;
  * @tsfoor: TSF out of range, indicates that the corrected TSF received
  * from a beacon differs from the PCU's internal TSF by more than a
  * (programmable) threshold
+ * @local_timeout: Internal bus timeout.
  */
 struct ath_interrupt_stats {
        u32 total;
@@ -85,8 +86,30 @@ struct ath_interrupt_stats {
        u32 dtim;
        u32 bb_watchdog;
        u32 tsfoor;
+
+       /* Sync-cause stats */
+       u32 sync_cause_all;
+       u32 sync_rtc_irq;
+       u32 sync_mac_irq;
+       u32 eeprom_illegal_access;
+       u32 apb_timeout;
+       u32 pci_mode_conflict;
+       u32 host1_fatal;
+       u32 host1_perr;
+       u32 trcv_fifo_perr;
+       u32 radm_cpl_ep;
+       u32 radm_cpl_dllp_abort;
+       u32 radm_cpl_tlp_abort;
+       u32 radm_cpl_ecrc_err;
+       u32 radm_cpl_timeout;
+       u32 local_timeout;
+       u32 pm_access;
+       u32 mac_awake;
+       u32 mac_asleep;
+       u32 mac_sleep_access;
 };
 
+
 /**
  * struct ath_tx_stats - Statistics about TX
  * @tx_pkts_all:  No. of total frames transmitted, including ones that
index c43523233319a8d5d66af5ac221b3495d5df9632..0512397a293c9a50a41cb61389f6aeb1c6da2d7a 100644 (file)
 
 #include "hw.h"
 
-static inline u16 ath9k_hw_fbin2freq(u8 fbin, bool is2GHz)
-{
-       if (fbin == AR5416_BCHAN_UNUSED)
-               return fbin;
-
-       return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
-}
-
 void ath9k_hw_analog_shift_regwrite(struct ath_hw *ah, u32 reg, u32 val)
 {
         REG_WRITE(ah, reg, val);
@@ -290,6 +282,34 @@ u16 ath9k_hw_get_max_edge_power(u16 freq, struct cal_ctl_edges *pRdEdgesPower,
        return twiceMaxEdgePower;
 }
 
+u16 ath9k_hw_get_scaled_power(struct ath_hw *ah, u16 power_limit,
+                             u8 antenna_reduction)
+{
+       u16 reduction = antenna_reduction;
+
+       /*
+        * Reduce scaled Power by number of chains active
+        * to get the per chain tx power level.
+        */
+       switch (ar5416_get_ntxchains(ah->txchainmask)) {
+       case 1:
+               break;
+       case 2:
+               reduction += POWER_CORRECTION_FOR_TWO_CHAIN;
+               break;
+       case 3:
+               reduction += POWER_CORRECTION_FOR_THREE_CHAIN;
+               break;
+       }
+
+       if (power_limit > reduction)
+               power_limit -= reduction;
+       else
+               power_limit = 0;
+
+       return power_limit;
+}
+
 void ath9k_hw_update_regulatory_maxpower(struct ath_hw *ah)
 {
        struct ath_common *common = ath9k_hw_common(ah);
@@ -299,10 +319,10 @@ void ath9k_hw_update_regulatory_maxpower(struct ath_hw *ah)
        case 1:
                break;
        case 2:
-               regulatory->max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
+               regulatory->max_power_level += POWER_CORRECTION_FOR_TWO_CHAIN;
                break;
        case 3:
-               regulatory->max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
+               regulatory->max_power_level += POWER_CORRECTION_FOR_THREE_CHAIN;
                break;
        default:
                ath_dbg(common, EEPROM, "Invalid chainmask configuration\n");
index 5ff7ab96512036b35ab74beec9f22ebe78917a7c..33acb920ed3fc5931d52828b3c1b16f5b32aedbf 100644 (file)
@@ -79,8 +79,8 @@
 #define SUB_NUM_CTL_MODES_AT_5G_40 2
 #define SUB_NUM_CTL_MODES_AT_2G_40 3
 
-#define INCREASE_MAXPOW_BY_TWO_CHAIN     6  /* 10*log10(2)*2 */
-#define INCREASE_MAXPOW_BY_THREE_CHAIN   10 /* 10*log10(3)*2 */
+#define POWER_CORRECTION_FOR_TWO_CHAIN         6  /* 10*log10(2)*2 */
+#define POWER_CORRECTION_FOR_THREE_CHAIN       10 /* 10*log10(3)*2 */
 
 /*
  * For AR9285 and later chipsets, the following bits are not being programmed
@@ -686,6 +686,8 @@ void ath9k_hw_get_target_powers(struct ath_hw *ah,
                                u16 numRates, bool isHt40Target);
 u16 ath9k_hw_get_max_edge_power(u16 freq, struct cal_ctl_edges *pRdEdgesPower,
                                bool is2GHz, int num_band_edges);
+u16 ath9k_hw_get_scaled_power(struct ath_hw *ah, u16 power_limit,
+                             u8 antenna_reduction);
 void ath9k_hw_update_regulatory_maxpower(struct ath_hw *ah);
 int ath9k_hw_eeprom_init(struct ath_hw *ah);
 
@@ -697,6 +699,14 @@ void ath9k_hw_get_gain_boundaries_pdadcs(struct ath_hw *ah,
                                u16 *pPdGainBoundaries, u8 *pPDADCValues,
                                u16 numXpdGains);
 
+static inline u16 ath9k_hw_fbin2freq(u8 fbin, bool is2GHz)
+{
+       if (fbin == AR5416_BCHAN_UNUSED)
+               return fbin;
+
+       return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
+}
+
 #define ar5416_get_ntxchains(_txchainmask)                     \
        (((_txchainmask >> 2) & 1) +                            \
         ((_txchainmask >> 1) & 1) + (_txchainmask & 1))
index f272236d8053d58201b973b6397b11362a112bb1..5ab0e6ed4655be2d532b213d92c47350b5b2f843 100644 (file)
@@ -564,9 +564,6 @@ static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
        (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
         ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
 
-#define REDUCE_SCALED_POWER_BY_TWO_CHAIN     6
-#define REDUCE_SCALED_POWER_BY_THREE_CHAIN   10
-
        u16 twiceMaxEdgePower;
        int i;
        struct cal_ctl_data_ar9287 *rep;
@@ -591,29 +588,8 @@ static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
        tx_chainmask = ah->txchainmask;
 
        ath9k_hw_get_channel_centers(ah, chan, &centers);
-       scaledPower = powerLimit - antenna_reduction;
-
-       /*
-        * Reduce scaled Power by number of chains active
-        * to get the per chain tx power level.
-        */
-       switch (ar5416_get_ntxchains(tx_chainmask)) {
-       case 1:
-               break;
-       case 2:
-               if (scaledPower > REDUCE_SCALED_POWER_BY_TWO_CHAIN)
-                       scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
-               else
-                       scaledPower = 0;
-               break;
-       case 3:
-               if (scaledPower > REDUCE_SCALED_POWER_BY_THREE_CHAIN)
-                       scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
-               else
-                       scaledPower = 0;
-               break;
-       }
-       scaledPower = max((u16)0, scaledPower);
+       scaledPower = ath9k_hw_get_scaled_power(ah, powerLimit,
+                                               antenna_reduction);
 
        /*
         * Get TX power from EEPROM.
@@ -786,8 +762,6 @@ static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
 
 #undef CMP_CTL
 #undef CMP_NO_CTL
-#undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
-#undef REDUCE_SCALED_POWER_BY_THREE_CHAIN
 }
 
 static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
index 619b95d764ff33ea0adceabd8a15cb5c93815f1e..b5fba8b18b8b851fbe985820c9d8021729171290 100644 (file)
@@ -991,9 +991,6 @@ static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
                                                  u16 antenna_reduction,
                                                  u16 powerLimit)
 {
-#define REDUCE_SCALED_POWER_BY_TWO_CHAIN     6  /* 10*log10(2)*2 */
-#define REDUCE_SCALED_POWER_BY_THREE_CHAIN   9 /* 10*log10(3)*2 */
-
        struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
        u16 twiceMaxEdgePower;
        int i;
@@ -1027,24 +1024,8 @@ static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
 
        ath9k_hw_get_channel_centers(ah, chan, &centers);
 
-       scaledPower = powerLimit - antenna_reduction;
-
-       switch (ar5416_get_ntxchains(tx_chainmask)) {
-       case 1:
-               break;
-       case 2:
-               if (scaledPower > REDUCE_SCALED_POWER_BY_TWO_CHAIN)
-                       scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
-               else
-                       scaledPower = 0;
-               break;
-       case 3:
-               if (scaledPower > REDUCE_SCALED_POWER_BY_THREE_CHAIN)
-                       scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
-               else
-                       scaledPower = 0;
-               break;
-       }
+       scaledPower = ath9k_hw_get_scaled_power(ah, powerLimit,
+                                               antenna_reduction);
 
        if (IS_CHAN_2GHZ(chan)) {
                numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
@@ -1263,20 +1244,7 @@ static void ath9k_hw_def_set_txpower(struct ath_hw *ah,
                        regulatory->max_power_level = ratesArray[i];
        }
 
-       switch(ar5416_get_ntxchains(ah->txchainmask)) {
-       case 1:
-               break;
-       case 2:
-               regulatory->max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
-               break;
-       case 3:
-               regulatory->max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
-               break;
-       default:
-               ath_dbg(ath9k_hw_common(ah), EEPROM,
-                       "Invalid chainmask configuration\n");
-               break;
-       }
+       ath9k_hw_update_regulatory_maxpower(ah);
 
        if (test)
                return;
index fbe23de1297f67cbf520007b160f719cb6af3e43..dd10f4ac03efabd6c12e528629a46a87d62be1eb 100644 (file)
@@ -41,6 +41,9 @@ void ath_init_leds(struct ath_softc *sc)
 {
        int ret;
 
+       if (AR_SREV_9100(sc->sc_ah))
+               return;
+
        if (sc->sc_ah->led_pin < 0) {
                if (AR_SREV_9287(sc->sc_ah))
                        sc->sc_ah->led_pin = ATH_LED_PIN_9287;
index 424aabb2c7302db2bc74d4ca52256ae61fcac222..f67cd952e741c0d2c63175b8966a041f7a4589f2 100644 (file)
@@ -53,6 +53,8 @@ static struct usb_device_id ath9k_hif_usb_ids[] = {
          .driver_info = AR9280_USB },  /* SMC Networks */
        { USB_DEVICE(0x0411, 0x017f),
          .driver_info = AR9280_USB },  /* Sony UWA-BR100 */
+       { USB_DEVICE(0x04da, 0x3904),
+         .driver_info = AR9280_USB },
 
        { USB_DEVICE(0x0cf3, 0x20ff),
          .driver_info = STORAGE_DEVICE },
index d1345a8a2b15e4b290672490a16b9c8fb479520a..72c5bcd4886d18122dfd1f8509e4785c92ca6110 100644 (file)
@@ -24,6 +24,8 @@
 #include "rc.h"
 #include "ar9003_mac.h"
 #include "ar9003_mci.h"
+#include "debug.h"
+#include "ath9k.h"
 
 static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
 
@@ -83,6 +85,53 @@ static void ath9k_hw_ani_cache_ini_regs(struct ath_hw *ah)
 /* Helper Functions */
 /********************/
 
+#ifdef CONFIG_ATH9K_DEBUGFS
+
+void ath9k_debug_sync_cause(struct ath_common *common, u32 sync_cause)
+{
+       struct ath_softc *sc = common->priv;
+       if (sync_cause)
+               sc->debug.stats.istats.sync_cause_all++;
+       if (sync_cause & AR_INTR_SYNC_RTC_IRQ)
+               sc->debug.stats.istats.sync_rtc_irq++;
+       if (sync_cause & AR_INTR_SYNC_MAC_IRQ)
+               sc->debug.stats.istats.sync_mac_irq++;
+       if (sync_cause & AR_INTR_SYNC_EEPROM_ILLEGAL_ACCESS)
+               sc->debug.stats.istats.eeprom_illegal_access++;
+       if (sync_cause & AR_INTR_SYNC_APB_TIMEOUT)
+               sc->debug.stats.istats.apb_timeout++;
+       if (sync_cause & AR_INTR_SYNC_PCI_MODE_CONFLICT)
+               sc->debug.stats.istats.pci_mode_conflict++;
+       if (sync_cause & AR_INTR_SYNC_HOST1_FATAL)
+               sc->debug.stats.istats.host1_fatal++;
+       if (sync_cause & AR_INTR_SYNC_HOST1_PERR)
+               sc->debug.stats.istats.host1_perr++;
+       if (sync_cause & AR_INTR_SYNC_TRCV_FIFO_PERR)
+               sc->debug.stats.istats.trcv_fifo_perr++;
+       if (sync_cause & AR_INTR_SYNC_RADM_CPL_EP)
+               sc->debug.stats.istats.radm_cpl_ep++;
+       if (sync_cause & AR_INTR_SYNC_RADM_CPL_DLLP_ABORT)
+               sc->debug.stats.istats.radm_cpl_dllp_abort++;
+       if (sync_cause & AR_INTR_SYNC_RADM_CPL_TLP_ABORT)
+               sc->debug.stats.istats.radm_cpl_tlp_abort++;
+       if (sync_cause & AR_INTR_SYNC_RADM_CPL_ECRC_ERR)
+               sc->debug.stats.istats.radm_cpl_ecrc_err++;
+       if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT)
+               sc->debug.stats.istats.radm_cpl_timeout++;
+       if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT)
+               sc->debug.stats.istats.local_timeout++;
+       if (sync_cause & AR_INTR_SYNC_PM_ACCESS)
+               sc->debug.stats.istats.pm_access++;
+       if (sync_cause & AR_INTR_SYNC_MAC_AWAKE)
+               sc->debug.stats.istats.mac_awake++;
+       if (sync_cause & AR_INTR_SYNC_MAC_ASLEEP)
+               sc->debug.stats.istats.mac_asleep++;
+       if (sync_cause & AR_INTR_SYNC_MAC_SLEEP_ACCESS)
+               sc->debug.stats.istats.mac_sleep_access++;
+}
+#endif
+
+
 static void ath9k_hw_set_clockrate(struct ath_hw *ah)
 {
        struct ieee80211_conf *conf = &ath9k_hw_common(ah)->hw->conf;
@@ -388,8 +437,8 @@ static void ath9k_hw_init_config(struct ath_hw *ah)
 {
        int i;
 
-       ah->config.dma_beacon_response_time = 2;
-       ah->config.sw_beacon_response_time = 10;
+       ah->config.dma_beacon_response_time = 1;
+       ah->config.sw_beacon_response_time = 6;
        ah->config.additional_swba_backoff = 0;
        ah->config.ack_6mb = 0x0;
        ah->config.cwm_ignore_extcca = 0;
@@ -445,7 +494,6 @@ static void ath9k_hw_init_defaults(struct ath_hw *ah)
                AR_STA_ID1_MCAST_KSRCH;
        if (AR_SREV_9100(ah))
                ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
-       ah->enable_32kHz_clock = DONT_USE_32KHZ;
        ah->slottime = ATH9K_SLOT_TIME_9;
        ah->globaltxtimeout = (u32) -1;
        ah->power_mode = ATH9K_PM_UNDEFINED;
index aa1680a0c7fdbeccd4ba36a7be8733b5a1a0ed4c..dd4b8f4097c837663dea38538bb20b97bdb9aad8 100644 (file)
@@ -708,7 +708,6 @@ struct ath_hw {
        struct ar5416Stats stats;
        struct ath9k_tx_queue_info txq[ATH9K_NUM_TX_QUEUES];
 
-       int16_t curchan_rad_index;
        enum ath9k_int imask;
        u32 imrs2_reg;
        u32 txok_interrupt_mask;
@@ -762,11 +761,6 @@ struct ath_hw {
 
        u32 sta_id1_defaults;
        u32 misc_mode;
-       enum {
-               AUTO_32KHZ,
-               USE_32KHZ,
-               DONT_USE_32KHZ,
-       } enable_32kHz_clock;
 
        /* Private to hardware code */
        struct ath_hw_private_ops private_ops;
@@ -783,7 +777,6 @@ struct ath_hw {
        u32 *analogBank7Data;
        u32 *bank6Temp;
 
-       u8 txpower_limit;
        int coverage_class;
        u32 slottime;
        u32 globaltxtimeout;
@@ -848,7 +841,6 @@ struct ath_hw {
        struct ath_gen_timer_table hw_gen_timers;
 
        struct ar9003_txs *ts_ring;
-       void *ts_start;
        u32 ts_paddr_start;
        u32 ts_paddr_end;
        u16 ts_tail;
@@ -915,7 +907,6 @@ static inline u8 get_streams(int mask)
 }
 
 /* Initialization, Detach, Reset */
-const char *ath9k_hw_probe(u16 vendorid, u16 devid);
 void ath9k_hw_deinit(struct ath_hw *ah);
 int ath9k_hw_init(struct ath_hw *ah);
 int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
@@ -965,6 +956,12 @@ bool ath9k_hw_check_alive(struct ath_hw *ah);
 
 bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode);
 
+#ifdef CONFIG_ATH9K_DEBUGFS
+void ath9k_debug_sync_cause(struct ath_common *common, u32 sync_cause);
+#else
+static void ath9k_debug_sync_cause(struct ath_common *common, u32 sync_cause) {}
+#endif
+
 /* Generic hw timer primitives */
 struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
                                          void (*trigger)(void *),
@@ -1011,7 +1008,6 @@ int ar9003_paprd_create_curve(struct ath_hw *ah,
 int ar9003_paprd_setup_gain_table(struct ath_hw *ah, int chain);
 int ar9003_paprd_init_table(struct ath_hw *ah);
 bool ar9003_paprd_is_done(struct ath_hw *ah);
-void ar9003_hw_set_paprd_txdesc(struct ath_hw *ah, void *ds, u8 chains);
 
 /* Hardware family op attach helpers */
 void ar5008_hw_attach_phy_ops(struct ath_hw *ah);
index c8d1239571883097ae87707ff8988603b9196e7c..384e5c498440376fd51a55d9875e4ec5671ae1f3 100644 (file)
@@ -692,17 +692,6 @@ void ath9k_tasklet(unsigned long data)
                goto out;
        }
 
-       /*
-        * Only run the baseband hang check if beacons stop working in AP or
-        * IBSS mode, because it has a high false positive rate. For station
-        * mode it should not be necessary, since the upper layers will detect
-        * this through a beacon miss automatically and the following channel
-        * change will trigger a hardware reset anyway
-        */
-       if (ath9k_hw_numtxpending(ah, sc->beacon.beaconq) != 0 &&
-           !ath9k_hw_check_alive(ah))
-               ieee80211_queue_work(sc->hw, &sc->hw_check_work);
-
        if ((status & ATH9K_INT_TSFOOR) && sc->ps_enabled) {
                /*
                 * TSF sync does not look correct; remain awake to sync with
index 6c87a823f5a9d4c6ec228651687b14c7fb545c8e..d07c0301da6abeca20f1aa8fbbaf1cf0b8ae4d32 100644 (file)
@@ -3989,8 +3989,7 @@ static int reset_atmel_card(struct net_device *dev)
                        atmel_copy_to_card(priv->dev, 0x8000, &fw[0x6000], len - 0x6000);
                }
 
-               if (fw_entry)
-                       release_firmware(fw_entry);
+               release_firmware(fw_entry);
        }
 
        err = atmel_wakeup_firmware(priv);
index 9ab1192004c038c92316238362a46d82b0093f3e..51e33b53386e58a3d85c180d271c1678b8b08a01 100644 (file)
@@ -74,15 +74,4 @@ static void __devexit atmel_pci_remove(struct pci_dev *pdev)
        stop_atmel_card(pci_get_drvdata(pdev));
 }
 
-static int __init atmel_init_module(void)
-{
-       return pci_register_driver(&atmel_driver);
-}
-
-static void __exit atmel_cleanup_module(void)
-{
-       pci_unregister_driver(&atmel_driver);
-}
-
-module_init(atmel_init_module);
-module_exit(atmel_cleanup_module);
+module_pci_driver(atmel_driver);
index cba413536270bbc831e80a34a2d655179a9bfaae..b31ccc02fa21c406bb7179f30faced26d2e7aadc 100644 (file)
@@ -290,7 +290,8 @@ int b43_generate_txhdr(struct b43_wldev *dev,
                txhdr->dur_fb = wlhdr->duration_id;
        } else {
                txhdr->dur_fb = ieee80211_generic_frame_duration(
-                       dev->wl->hw, info->control.vif, fragment_len, fbrate);
+                       dev->wl->hw, info->control.vif, info->band,
+                       fragment_len, fbrate);
        }
 
        plcp_fragment_len = fragment_len + FCS_LEN;
index df7e16dfb36c56ca426274fd9d9e7270f1dd1932..1be214b815fbd58267e3e089b8912b7869b31356 100644 (file)
@@ -1056,6 +1056,7 @@ static void b43legacy_write_probe_resp_plcp(struct b43legacy_wldev *dev,
        b43legacy_generate_plcp_hdr(&plcp, size + FCS_LEN, rate->hw_value);
        dur = ieee80211_generic_frame_duration(dev->wl->hw,
                                               dev->wl->vif,
+                                              IEEE80211_BAND_2GHZ,
                                               size,
                                               rate);
        /* Write PLCP in two parts and timing for packet transfer */
@@ -1121,6 +1122,7 @@ static const u8 *b43legacy_generate_probe_resp(struct b43legacy_wldev *dev,
                                         IEEE80211_STYPE_PROBE_RESP);
        dur = ieee80211_generic_frame_duration(dev->wl->hw,
                                               dev->wl->vif,
+                                              IEEE80211_BAND_2GHZ,
                                               *dest_size,
                                               rate);
        hdr->duration_id = dur;
index e6c573af494d1937992fbaef2cd0c3d5a17746b7..a8012f2749eeb993c7691a66b4c636842678ba81 100644 (file)
@@ -228,6 +228,7 @@ static int generate_txhdr_fw3(struct b43legacy_wldev *dev,
        } else {
                txhdr->dur_fb = ieee80211_generic_frame_duration(dev->wl->hw,
                                                         info->control.vif,
+                                                        info->band,
                                                         fragment_len,
                                                         rate_fb);
        }
index 07686a748d3cf3ae3746784d34f40d796f93fbc2..9f637014486e3d84b00a73cfd7fe5f8297761fd5 100644 (file)
@@ -632,7 +632,6 @@ extern const struct bcmevent_name bcmevent_names[];
 extern uint brcmf_c_mkiovar(char *name, char *data, uint datalen,
                          char *buf, uint len);
 
-extern int brcmf_net_attach(struct brcmf_pub *drvr, int idx);
 extern int brcmf_netdev_wait_pend8021x(struct net_device *ndev);
 
 extern s32 brcmf_exec_dcmd(struct net_device *dev, u32 cmd, void *arg, u32 len);
index b3e3b7f25d82332226be904263de4b7109b84823..a5c15cac5e7d4c1357c20f9dc2956ea4ab51ea14 100644 (file)
@@ -421,6 +421,7 @@ int brcmf_proto_hdrpull(struct device *dev, int *ifidx,
        pktbuf->priority = h->priority & BDC_PRIORITY_MASK;
 
        skb_pull(pktbuf, BDC_HEADER_LEN);
+       skb_pull(pktbuf, h->data_offset << 2);
 
        return 0;
 }
index 4187435220f34fbbb5b33fb9d266ffaff121c713..236cb9fa460c7fb5d9f2934bf91a91706d7b5362 100644 (file)
@@ -799,7 +799,6 @@ int brcmf_c_preinit_dcmds(struct brcmf_pub *drvr)
 {
        char iovbuf[BRCMF_EVENTING_MASK_LEN + 12];      /*  Room for
                                 "event_msgs" + '\0' + bitvec  */
-       uint up = 0;
        char buf[128], *ptr;
        u32 dongle_align = drvr->bus_if->align;
        u32 glom = 0;
@@ -853,9 +852,6 @@ int brcmf_c_preinit_dcmds(struct brcmf_pub *drvr)
        brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
                                  sizeof(iovbuf));
 
-       /* Force STA UP */
-       brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_UP, (char *)&up, sizeof(up));
-
        /* Setup event_msgs */
        brcmf_c_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
                      iovbuf, sizeof(iovbuf));
index 2a1e5ae0c4024ff560b40dade098c4599894feb5..8933f9b31a9a64a7c2c3f5428aba47a4e85d88d5 100644 (file)
@@ -799,6 +799,7 @@ static int brcmf_netdev_open(struct net_device *ndev)
        struct brcmf_bus *bus_if = drvr->bus_if;
        u32 toe_ol;
        s32 ret = 0;
+       uint up = 0;
 
        brcmf_dbg(TRACE, "ifidx %d\n", ifp->idx);
 
@@ -822,6 +823,10 @@ static int brcmf_netdev_open(struct net_device *ndev)
                        drvr->iflist[ifp->idx]->ndev->features &=
                                ~NETIF_F_IP_CSUM;
        }
+
+       /* make sure RF is ready for work */
+       brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_UP, (char *)&up, sizeof(up));
+
        /* Allow transmit calls */
        netif_start_queue(ndev);
        drvr->bus_if->drvr_up = true;
@@ -843,6 +848,63 @@ static const struct net_device_ops brcmf_netdev_ops_pri = {
        .ndo_set_rx_mode = brcmf_netdev_set_multicast_list
 };
 
+static int brcmf_net_attach(struct brcmf_if *ifp)
+{
+       struct brcmf_pub *drvr = ifp->drvr;
+       struct net_device *ndev;
+       u8 temp_addr[ETH_ALEN];
+
+       brcmf_dbg(TRACE, "ifidx %d\n", ifp->idx);
+
+       ndev = drvr->iflist[ifp->idx]->ndev;
+       ndev->netdev_ops = &brcmf_netdev_ops_pri;
+
+       /*
+        * determine mac address to use
+        */
+       if (is_valid_ether_addr(ifp->mac_addr))
+               memcpy(temp_addr, ifp->mac_addr, ETH_ALEN);
+       else
+               memcpy(temp_addr, drvr->mac, ETH_ALEN);
+
+       if (ifp->idx == 1) {
+               brcmf_dbg(TRACE, "ACCESS POINT MAC:\n");
+               /*  ACCESSPOINT INTERFACE CASE */
+               temp_addr[0] |= 0X02;   /* set bit 2 ,
+                        - Locally Administered address  */
+
+       }
+       ndev->hard_header_len = ETH_HLEN + drvr->hdrlen;
+       ndev->ethtool_ops = &brcmf_ethtool_ops;
+
+       drvr->rxsz = ndev->mtu + ndev->hard_header_len +
+                             drvr->hdrlen;
+
+       memcpy(ndev->dev_addr, temp_addr, ETH_ALEN);
+
+       /* attach to cfg80211 for primary interface */
+       if (!ifp->idx) {
+               drvr->config = brcmf_cfg80211_attach(ndev, drvr->dev, drvr);
+               if (drvr->config == NULL) {
+                       brcmf_dbg(ERROR, "wl_cfg80211_attach failed\n");
+                       goto fail;
+               }
+       }
+
+       if (register_netdev(ndev) != 0) {
+               brcmf_dbg(ERROR, "couldn't register the net device\n");
+               goto fail;
+       }
+
+       brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
+
+       return 0;
+
+fail:
+       ndev->netdev_ops = NULL;
+       return -EBADE;
+}
+
 int
 brcmf_add_if(struct device *dev, int ifidx, char *name, u8 *mac_addr)
 {
@@ -882,7 +944,7 @@ brcmf_add_if(struct device *dev, int ifidx, char *name, u8 *mac_addr)
        if (mac_addr != NULL)
                memcpy(&ifp->mac_addr, mac_addr, ETH_ALEN);
 
-       if (brcmf_net_attach(drvr, ifp->idx)) {
+       if (brcmf_net_attach(ifp)) {
                brcmf_dbg(ERROR, "brcmf_net_attach failed");
                free_netdev(ifp->ndev);
                drvr->iflist[ifidx] = NULL;
@@ -1016,69 +1078,16 @@ int brcmf_bus_start(struct device *dev)
        if (ret < 0)
                return ret;
 
+       /* add primary networking interface */
+       ret = brcmf_add_if(dev, 0, "wlan%d", drvr->mac);
+       if (ret < 0)
+               return ret;
+
        /* signal bus ready */
        bus_if->state = BRCMF_BUS_DATA;
        return 0;
 }
 
-int brcmf_net_attach(struct brcmf_pub *drvr, int ifidx)
-{
-       struct net_device *ndev;
-       u8 temp_addr[ETH_ALEN] = {
-               0x00, 0x90, 0x4c, 0x11, 0x22, 0x33};
-
-       brcmf_dbg(TRACE, "ifidx %d\n", ifidx);
-
-       ndev = drvr->iflist[ifidx]->ndev;
-       ndev->netdev_ops = &brcmf_netdev_ops_pri;
-
-       /*
-        * We have to use the primary MAC for virtual interfaces
-        */
-       if (ifidx != 0) {
-               /* for virtual interfaces use the primary MAC  */
-               memcpy(temp_addr, drvr->mac, ETH_ALEN);
-
-       }
-
-       if (ifidx == 1) {
-               brcmf_dbg(TRACE, "ACCESS POINT MAC:\n");
-               /*  ACCESSPOINT INTERFACE CASE */
-               temp_addr[0] |= 0X02;   /* set bit 2 ,
-                        - Locally Administered address  */
-
-       }
-       ndev->hard_header_len = ETH_HLEN + drvr->hdrlen;
-       ndev->ethtool_ops = &brcmf_ethtool_ops;
-
-       drvr->rxsz = ndev->mtu + ndev->hard_header_len +
-                             drvr->hdrlen;
-
-       memcpy(ndev->dev_addr, temp_addr, ETH_ALEN);
-
-       /* attach to cfg80211 for primary interface */
-       if (!ifidx) {
-               drvr->config = brcmf_cfg80211_attach(ndev, drvr->dev, drvr);
-               if (drvr->config == NULL) {
-                       brcmf_dbg(ERROR, "wl_cfg80211_attach failed\n");
-                       goto fail;
-               }
-       }
-
-       if (register_netdev(ndev) != 0) {
-               brcmf_dbg(ERROR, "couldn't register the net device\n");
-               goto fail;
-       }
-
-       brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);
-
-       return 0;
-
-fail:
-       ndev->netdev_ops = NULL;
-       return -EBADE;
-}
-
 static void brcmf_bus_detach(struct brcmf_pub *drvr)
 {
        brcmf_dbg(TRACE, "Enter\n");
index 2bf5dda292919868a90a9dad3722f0a4991f7024..a83fbea04c046f2d1310442ae4120082334464c1 100644 (file)
@@ -3948,12 +3948,6 @@ void *brcmf_sdbrcm_probe(u32 regsva, struct brcmf_sdio_dev *sdiodev)
                }
        }
 
-       /* add interface and open for business */
-       if (brcmf_add_if(bus->sdiodev->dev, 0, "wlan%d", NULL)) {
-               brcmf_dbg(ERROR, "Add primary net device interface failed!!\n");
-               goto fail;
-       }
-
        return bus;
 
 fail:
index 82364223e81785e0023b0d56136dd2b170cac4eb..1d67ecf681b767b43bd739568435fba67aad7b83 100644 (file)
@@ -1383,14 +1383,6 @@ static int brcmf_usb_probe_cb(struct device *dev, const char *desc,
                goto fail;
        }
 
-       /* add interface and open for business */
-       ret = brcmf_add_if(dev, 0, "wlan%d", NULL);
-       if (ret) {
-               brcmf_dbg(ERROR, "Add primary net device interface failed!!\n");
-               brcmf_detach(dev);
-               goto fail;
-       }
-
        return 0;
 fail:
        /* Release resources in reverse order */
index 55e9f45fce22ec82315bd7559e346d8b02615f33..0efe88e25a9af1575c958dc70bf60d94fcea01ff 100644 (file)
@@ -628,6 +628,40 @@ brcms_c_country_aggregate_map(struct brcms_cm_info *wlc_cm, const char *ccode,
        return false;
 }
 
+/*
+ * Indicates whether the country provided is valid to pass
+ * to cfg80211 or not.
+ *
+ * returns true if valid; false if not.
+ */
+static bool brcms_c_country_valid(const char *ccode)
+{
+       /*
+        * only allow ascii alpha uppercase for the first 2
+        * chars.
+        */
+       if (!((0x80 & ccode[0]) == 0 && ccode[0] >= 0x41 && ccode[0] <= 0x5A &&
+             (0x80 & ccode[1]) == 0 && ccode[1] >= 0x41 && ccode[1] <= 0x5A &&
+             ccode[2] == '\0'))
+               return false;
+
+       /*
+        * do not match ISO 3166-1 user assigned country codes
+        * that may be in the driver table
+        */
+       if (!strcmp("AA", ccode) ||        /* AA */
+           !strcmp("ZZ", ccode) ||        /* ZZ */
+           ccode[0] == 'X' ||             /* XA - XZ */
+           (ccode[0] == 'Q' &&            /* QM - QZ */
+            (ccode[1] >= 'M' && ccode[1] <= 'Z')))
+               return false;
+
+       if (!strcmp("NA", ccode))
+               return false;
+
+       return true;
+}
+
 /* Lookup a country info structure from a null terminated country
  * abbreviation and regrev directly with no translation.
  */
@@ -1089,7 +1123,7 @@ struct brcms_cm_info *brcms_c_channel_mgr_attach(struct brcms_c_info *wlc)
 
        /* store the country code for passing up as a regulatory hint */
        ccode = getvar(wlc->hw->sih, BRCMS_SROM_CCODE);
-       if (ccode)
+       if (ccode && brcms_c_country_valid(ccode))
                strncpy(wlc->pub->srom_ccode, ccode, BRCM_CNTRY_BUF_SZ - 1);
 
        /*
index 569ab8abd2a1c2d132eb1fbe273d09f077d68c3e..aa15558f75c8f993aca0c93222e54b507c170aca 100644 (file)
@@ -1069,11 +1069,7 @@ static struct brcms_info *brcms_attach(struct bcma_device *pdev)
                wiphy_err(wl->wiphy, "%s: ieee80211_register_hw failed, status"
                          "%d\n", __func__, err);
 
-       if (wl->pub->srom_ccode[0])
-               err = brcms_set_hint(wl, wl->pub->srom_ccode);
-       else
-               err = brcms_set_hint(wl, "US");
-       if (err)
+       if (wl->pub->srom_ccode[0] && brcms_set_hint(wl, wl->pub->srom_ccode))
                wiphy_err(wl->wiphy, "%s: regulatory_hint failed, status %d\n",
                          __func__, err);
 
index ce8562aa5db0bee06c59244ef9c3099b6cf58c81..0fce56235f38c2040d6b6bff716029d23a6030d6 100644 (file)
@@ -207,8 +207,7 @@ static const iqcal_gain_params_lcnphy *tbl_iqcal_gainparams_lcnphy[1] = {
 };
 
 static const u16 iqcal_gainparams_numgains_lcnphy[1] = {
-       sizeof(tbl_iqcal_gainparams_lcnphy_2G) /
-       sizeof(*tbl_iqcal_gainparams_lcnphy_2G),
+       ARRAY_SIZE(tbl_iqcal_gainparams_lcnphy_2G),
 };
 
 static const struct lcnphy_sfo_cfg lcnphy_sfo_cfg[] = {
index 39095741fd05f948a9538d1b2740db7530112ccc..812b6e38526e3252bc1e720a70c51ee8d502232c 100644 (file)
@@ -16353,11 +16353,7 @@ static void wlc_phy_workarounds_nphy(struct brcms_phy *pi)
                        wlc_phy_set_rfseq_nphy(pi, NPHY_RFSEQ_RX2TX,
                                               rfseq_rx2tx_events_rev3_ipa,
                                               rfseq_rx2tx_dlys_rev3_ipa,
-                                              sizeof
-                                              (rfseq_rx2tx_events_rev3_ipa) /
-                                              sizeof
-                                              (rfseq_rx2tx_events_rev3_ipa
-                                               [0]));
+                                              ARRAY_SIZE(rfseq_rx2tx_events_rev3_ipa));
 
                mod_phy_reg(pi, 0x299, (0x3 << 14), (0x1 << 14));
                mod_phy_reg(pi, 0x29d, (0x3 << 14), (0x1 << 14));
@@ -16858,18 +16854,13 @@ static void wlc_phy_workarounds_nphy(struct brcms_phy *pi)
                wlc_phy_set_rfseq_nphy(pi, NPHY_RFSEQ_TX2RX,
                                       rfseq_tx2rx_events_rev3,
                                       rfseq_tx2rx_dlys_rev3,
-                                      sizeof(rfseq_tx2rx_events_rev3) /
-                                      sizeof(rfseq_tx2rx_events_rev3[0]));
+                                      ARRAY_SIZE(rfseq_tx2rx_events_rev3));
 
                if (PHY_IPA(pi))
                        wlc_phy_set_rfseq_nphy(pi, NPHY_RFSEQ_RX2TX,
                                               rfseq_rx2tx_events_rev3_ipa,
                                               rfseq_rx2tx_dlys_rev3_ipa,
-                                              sizeof
-                                              (rfseq_rx2tx_events_rev3_ipa) /
-                                              sizeof
-                                              (rfseq_rx2tx_events_rev3_ipa
-                                               [0]));
+                                              ARRAY_SIZE(rfseq_rx2tx_events_rev3_ipa));
 
                if ((pi->sh->hw_phyrxchain != 0x3) &&
                    (pi->sh->hw_phyrxchain != pi->sh->hw_phytxchain)) {
@@ -16885,8 +16876,7 @@ static void wlc_phy_workarounds_nphy(struct brcms_phy *pi)
                                pi, NPHY_RFSEQ_RX2TX,
                                rfseq_rx2tx_events_rev3,
                                rfseq_rx2tx_dlys_rev3,
-                               sizeof(rfseq_rx2tx_events_rev3) /
-                               sizeof(rfseq_rx2tx_events_rev3[0]));
+                               ARRAY_SIZE(rfseq_rx2tx_events_rev3));
                }
 
                if (CHSPEC_IS2G(pi->radio_chanspec))
@@ -17209,13 +17199,11 @@ static void wlc_phy_workarounds_nphy(struct brcms_phy *pi)
 
                wlc_phy_set_rfseq_nphy(pi, NPHY_RFSEQ_RX2TX, rfseq_rx2tx_events,
                                       rfseq_rx2tx_dlys,
-                                      sizeof(rfseq_rx2tx_events) /
-                                      sizeof(rfseq_rx2tx_events[0]));
+                                      ARRAY_SIZE(rfseq_rx2tx_events));
 
                wlc_phy_set_rfseq_nphy(pi, NPHY_RFSEQ_TX2RX, rfseq_tx2rx_events,
                                       rfseq_tx2rx_dlys,
-                                      sizeof(rfseq_tx2rx_events) /
-                                      sizeof(rfseq_tx2rx_events[0]));
+                                      ARRAY_SIZE(rfseq_tx2rx_events));
 
                wlc_phy_workarounds_nphy_gainctrl(pi);
 
@@ -19357,8 +19345,7 @@ static void wlc_phy_spurwar_nphy(struct brcms_phy *pi)
                        }
 
                        if (isAdjustNoiseVar) {
-                               numTonesAdjust = sizeof(nphy_adj_tone_id_buf) /
-                                               sizeof(nphy_adj_tone_id_buf[0]);
+                               numTonesAdjust = ARRAY_SIZE(nphy_adj_tone_id_buf);
 
                                wlc_phy_adjust_min_noisevar_nphy(
                                        pi,
@@ -25204,32 +25191,26 @@ static u8 wlc_phy_a3_nphy(struct brcms_phy *pi, u8 start_gain, u8 core)
 
                                phy_a15 = pad_gain_codes_used_2057rev5;
                                phy_a13 =
-                                       sizeof(pad_gain_codes_used_2057rev5) /
-                                       sizeof(pad_gain_codes_used_2057rev5
-                                               [0]) - 1;
+                                       ARRAY_SIZE(pad_gain_codes_used_2057rev5) - 1;
 
                        } else if ((pi->pubpi.radiorev == 7)
                                   || (pi->pubpi.radiorev == 8)) {
 
                                phy_a15 = pad_gain_codes_used_2057rev7;
                                phy_a13 =
-                                       sizeof(pad_gain_codes_used_2057rev7) /
-                                       sizeof(pad_gain_codes_used_2057rev7
-                                               [0]) - 1;
+                                       ARRAY_SIZE(pad_gain_codes_used_2057rev7) - 1;
 
                        } else {
 
                                phy_a15 = pad_all_gain_codes_2057;
-                               phy_a13 = sizeof(pad_all_gain_codes_2057) /
-                                         sizeof(pad_all_gain_codes_2057[0]) -
+                               phy_a13 = ARRAY_SIZE(pad_all_gain_codes_2057) -
                                          1;
                        }
 
                } else {
 
                        phy_a15 = pga_all_gain_codes_2057;
-                       phy_a13 = sizeof(pga_all_gain_codes_2057) /
-                                 sizeof(pga_all_gain_codes_2057[0]) - 1;
+                       phy_a13 = ARRAY_SIZE(pga_all_gain_codes_2057) - 1;
                }
 
                phy_a14 = 0;
index 5fb17d53c9b28e51b1eee8229966bae761757f5d..333193f20e1cfeb9071ee483bc30f6f272564300 100644 (file)
 #ifndef        _BRCM_HW_IDS_H_
 #define        _BRCM_HW_IDS_H_
 
-#define        BCM4325_D11DUAL_ID      0x431b
-#define        BCM4325_D11G_ID         0x431c
-#define        BCM4325_D11A_ID         0x431d
-
-#define BCM4329_D11N2G_ID      0x432f  /* 4329 802.11n 2.4G device */
-#define BCM4329_D11N5G_ID      0x4330  /* 4329 802.11n 5G device */
-#define BCM4329_D11NDUAL_ID    0x432e
-
-#define BCM4319_D11N_ID                0x4337  /* 4319 802.11n dualband device */
-#define BCM4319_D11N2G_ID      0x4338  /* 4319 802.11n 2.4G device */
-#define BCM4319_D11N5G_ID      0x4339  /* 4319 802.11n 5G device */
+#define BCM4313_D11N2G_ID      0x4727  /* 4313 802.11n 2.4G device */
 
 #define BCM43224_D11N_ID       0x4353  /* 43224 802.11n dualband device */
 #define BCM43224_D11N_ID_VEN1  0x0576  /* Vendor specific 43224 802.11n db */
 #define BCM43236_D11N_ID       0x4346  /* 43236 802.11n dualband device */
 #define BCM43236_D11N2G_ID     0x4347  /* 43236 802.11n 2.4GHz device */
 
-#define BCM4313_D11N2G_ID      0x4727  /* 4313 802.11n 2.4G device */
-
-/* Chip IDs */
-#define BCM4313_CHIP_ID                0x4313  /* 4313 chip id */
-#define        BCM4319_CHIP_ID         0x4319  /* 4319 chip id */
-
-#define        BCM43224_CHIP_ID        43224   /* 43224 chipcommon chipid */
-#define        BCM43225_CHIP_ID        43225   /* 43225 chipcommon chipid */
-#define        BCM43421_CHIP_ID        43421   /* 43421 chipcommon chipid */
-#define        BCM43235_CHIP_ID        43235   /* 43235 chipcommon chipid */
-#define        BCM43236_CHIP_ID        43236   /* 43236 chipcommon chipid */
-#define        BCM43238_CHIP_ID        43238   /* 43238 chipcommon chipid */
-#define        BCM4329_CHIP_ID         0x4329  /* 4329 chipcommon chipid */
-#define        BCM4325_CHIP_ID         0x4325  /* 4325 chipcommon chipid */
-#define        BCM4331_CHIP_ID         0x4331  /* 4331 chipcommon chipid */
-#define BCM4336_CHIP_ID                0x4336  /* 4336 chipcommon chipid */
-#define BCM4330_CHIP_ID                0x4330  /* 4330 chipcommon chipid */
-#define BCM6362_CHIP_ID                0x6362  /* 6362 chipcommon chipid */
+/* Chipcommon Core Chip IDs */
+#define BCM4313_CHIP_ID                0x4313
+#define BCM43224_CHIP_ID       43224
+#define BCM43225_CHIP_ID       43225
+#define BCM43235_CHIP_ID       43235
+#define BCM43236_CHIP_ID       43236
+#define BCM43238_CHIP_ID       43238
+#define BCM4329_CHIP_ID                0x4329
+#define BCM4330_CHIP_ID                0x4330
+#define BCM4331_CHIP_ID                0x4331
 
 #endif                         /* _BRCM_HW_IDS_H_ */
index bfa0d54221e8f48d4201f62b4a44ba777067f2fa..627bc12074c729a37426199e52cb119dce01fdda 100644 (file)
@@ -244,8 +244,7 @@ u16 hostap_tx_callback_register(local_info_t *local,
        unsigned long flags;
        struct hostap_tx_callback_info *entry;
 
-       entry = kmalloc(sizeof(*entry),
-                                                          GFP_ATOMIC);
+       entry = kmalloc(sizeof(*entry), GFP_KERNEL);
        if (entry == NULL)
                return 0;
 
index 972a9c3af39e5e7ad11dafa354b5f7314083a985..05ca3402dca707d8cca9eb9f1d5432fdc44b3b7b 100644 (file)
@@ -457,18 +457,4 @@ static struct pci_driver prism2_pci_driver = {
 #endif /* CONFIG_PM */
 };
 
-
-static int __init init_prism2_pci(void)
-{
-       return pci_register_driver(&prism2_pci_driver);
-}
-
-
-static void __exit exit_prism2_pci(void)
-{
-       pci_unregister_driver(&prism2_pci_driver);
-}
-
-
-module_init(init_prism2_pci);
-module_exit(exit_prism2_pci);
+module_pci_driver(prism2_pci_driver);
index 33e79037770b38673e2e5c0fa18ec39a4619cba5..c3d067ee4db9cdbd2f34e3d5ede9461abe28f59c 100644 (file)
@@ -616,18 +616,4 @@ static struct pci_driver prism2_plx_driver = {
        .remove         = prism2_plx_remove,
 };
 
-
-static int __init init_prism2_plx(void)
-{
-       return pci_register_driver(&prism2_plx_driver);
-}
-
-
-static void __exit exit_prism2_plx(void)
-{
-       pci_unregister_driver(&prism2_plx_driver);
-}
-
-
-module_init(init_prism2_plx);
-module_exit(exit_prism2_plx);
+module_pci_driver(prism2_plx_driver);
diff --git a/drivers/net/wireless/ipw2x00/ipw.h b/drivers/net/wireless/ipw2x00/ipw.h
new file mode 100644 (file)
index 0000000..4007bf5
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Intel Pro/Wireless 2100, 2200BG, 2915ABG network connection driver
+ *
+ * Copyright 2012 Stanislav Yakovlev <stas.yakovlev@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __IPW_H__
+#define __IPW_H__
+
+#include <linux/ieee80211.h>
+
+static const u32 ipw_cipher_suites[] = {
+       WLAN_CIPHER_SUITE_WEP40,
+       WLAN_CIPHER_SUITE_WEP104,
+       WLAN_CIPHER_SUITE_TKIP,
+       WLAN_CIPHER_SUITE_CCMP,
+};
+
+#endif
index 2662d46134d0538d4673e405c96c1bf6f972f9e4..c72136c0777439bbe84f5bd7a27e25d96e5cd821 100644 (file)
@@ -166,6 +166,7 @@ that only one external action is invoked at a time.
 #include <net/lib80211.h>
 
 #include "ipw2100.h"
+#include "ipw.h"
 
 #define IPW2100_VERSION "git-1.2.2"
 
@@ -1958,6 +1959,9 @@ static int ipw2100_wdev_init(struct net_device *dev)
                wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = bg_band;
        }
 
+       wdev->wiphy->cipher_suites = ipw_cipher_suites;
+       wdev->wiphy->n_cipher_suites = ARRAY_SIZE(ipw_cipher_suites);
+
        set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
        if (wiphy_register(wdev->wiphy)) {
                ipw2100_down(priv);
@@ -8503,8 +8507,7 @@ static void ipw2100_release_firmware(struct ipw2100_priv *priv,
                                     struct ipw2100_fw *fw)
 {
        fw->version = 0;
-       if (fw->fw_entry)
-               release_firmware(fw->fw_entry);
+       release_firmware(fw->fw_entry);
        fw->fw_entry = NULL;
 }
 
index 809b7a70974b490b114b633bc3ac2dedbcc44081..d57522c64073463763d619edc6162a381d27f668 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/slab.h>
 #include <net/cfg80211-wext.h>
 #include "ipw2200.h"
+#include "ipw.h"
 
 
 #ifndef KBUILD_EXTMOD
@@ -3657,8 +3658,7 @@ static int ipw_load(struct ipw_priv *priv)
                priv->rxq = NULL;
        }
        ipw_tx_queue_free(priv);
-       if (raw)
-               release_firmware(raw);
+       release_firmware(raw);
 #ifdef CONFIG_PM
        fw_loaded = 0;
        raw = NULL;
@@ -11533,6 +11533,9 @@ static int ipw_wdev_init(struct net_device *dev)
                wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = a_band;
        }
 
+       wdev->wiphy->cipher_suites = ipw_cipher_suites;
+       wdev->wiphy->n_cipher_suites = ARRAY_SIZE(ipw_cipher_suites);
+
        set_wiphy_dev(wdev->wiphy, &priv->pci_dev->dev);
 
        /* With that information in place, we can now register the wiphy... */
index 565611eef0d44f0410c3ee8a5308756207955758..db6c6e528022635638f8aa8594c2a6872da52f9b 100644 (file)
@@ -113,20 +113,21 @@ config IWLWIFI_DEVICE_TESTMODE
          generic netlink message via NL80211_TESTMODE channel.
 
 config IWLWIFI_P2P
-       bool "iwlwifi experimental P2P support"
-       depends on IWLWIFI
-       help
-         This option enables experimental P2P support for some devices
-         based on microcode support. Since P2P support is still under
-         development, this option may even enable it for some devices
-         now that turn out to not support it in the future due to
-         microcode restrictions.
-
-         To determine if your microcode supports the experimental P2P
-         offered by this option, check if the driver advertises AP
-         support when it is loaded.
-
-         Say Y only if you want to experiment with P2P.
+       def_bool y
+       bool "iwlwifi experimental P2P support"
+       depends on IWLWIFI
+       help
+         This option enables experimental P2P support for some devices
+         based on microcode support. Since P2P support is still under
+         development, this option may even enable it for some devices
+         now that turn out to not support it in the future due to
+         microcode restrictions.
+
+         To determine if your microcode supports the experimental P2P
+         offered by this option, check if the driver advertises AP
+         support when it is loaded.
+
+         Say Y only if you want to experiment with P2P.
 
 config IWLWIFI_EXPERIMENTAL_MFP
        bool "support MFP (802.11w) even if uCode doesn't advertise"
index c7c4a995dfe58291640ce154521c7c670a4cdadc..f2cd67874cf4de655c26347e35babb9899abae01 100644 (file)
@@ -7,7 +7,7 @@ iwlwifi-objs            += iwl-agn-tt.o iwl-agn-sta.o iwl-agn-rx.o
 
 iwlwifi-objs           += iwl-core.o iwl-eeprom.o iwl-power.o
 iwlwifi-objs           += iwl-scan.o iwl-led.o
-iwlwifi-objs           += iwl-agn-rxon.o
+iwlwifi-objs           += iwl-agn-rxon.o iwl-agn-devices.o
 iwlwifi-objs           += iwl-5000.o
 iwlwifi-objs           += iwl-6000.o
 iwlwifi-objs           += iwl-1000.o
index 95c59e39b803a0c4c137e69803dc640716db5822..e9006078f4e2c2ffb707029263cee267369c7ef8 100644 (file)
  *
  *****************************************************************************/
 
-#include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/init.h>
-#include <linux/delay.h>
-#include <linux/skbuff.h>
-#include <linux/netdevice.h>
-#include <net/mac80211.h>
-#include <linux/etherdevice.h>
-#include <asm/unaligned.h>
 #include <linux/stringify.h>
-
-#include "iwl-eeprom.h"
-#include "iwl-dev.h"
-#include "iwl-core.h"
-#include "iwl-io.h"
-#include "iwl-agn.h"
-#include "iwl-agn-hw.h"
-#include "iwl-shared.h"
+#include "iwl-config.h"
 #include "iwl-cfg.h"
-#include "iwl-prph.h"
+#include "iwl-dev.h" /* still needed */
 
 /* Highest firmware API version supported */
 #define IWL1000_UCODE_API_MAX 6
 #define IWL100_MODULE_FIRMWARE(api) IWL100_FW_PRE __stringify(api) ".ucode"
 
 
-/*
- * For 1000, use advance thermal throttling critical temperature threshold,
- * but legacy thermal management implementation for now.
- * This is for the reason of 1000 uCode using advance thermal throttling API
- * but not implement ct_kill_exit based on ct_kill exit temperature
- * so the thermal throttling will still based on legacy thermal throttling
- * management.
- * The code here need to be modified once 1000 uCode has the advanced thermal
- * throttling algorithm in place
- */
-static void iwl1000_set_ct_threshold(struct iwl_priv *priv)
-{
-       /* want Celsius */
-       hw_params(priv).ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY;
-       hw_params(priv).ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD;
-}
-
-/* NIC configuration for 1000 series */
-static void iwl1000_nic_config(struct iwl_priv *priv)
-{
-       /* set CSR_HW_CONFIG_REG for uCode use */
-       iwl_set_bit(trans(priv), CSR_HW_IF_CONFIG_REG,
-                   CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
-                   CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
-
-       /* Setting digital SVR for 1000 card to 1.32V */
-       /* locking is acquired in iwl_set_bits_mask_prph() function */
-       iwl_set_bits_mask_prph(trans(priv), APMG_DIGITAL_SVR_REG,
-                               APMG_SVR_DIGITAL_VOLTAGE_1_32,
-                               ~APMG_SVR_VOLTAGE_CONFIG_BIT_MSK);
-}
-
-static const struct iwl_sensitivity_ranges iwl1000_sensitivity = {
-       .min_nrg_cck = 95,
-       .auto_corr_min_ofdm = 90,
-       .auto_corr_min_ofdm_mrc = 170,
-       .auto_corr_min_ofdm_x1 = 120,
-       .auto_corr_min_ofdm_mrc_x1 = 240,
-
-       .auto_corr_max_ofdm = 120,
-       .auto_corr_max_ofdm_mrc = 210,
-       .auto_corr_max_ofdm_x1 = 155,
-       .auto_corr_max_ofdm_mrc_x1 = 290,
-
-       .auto_corr_min_cck = 125,
-       .auto_corr_max_cck = 200,
-       .auto_corr_min_cck_mrc = 170,
-       .auto_corr_max_cck_mrc = 400,
-       .nrg_th_cck = 95,
-       .nrg_th_ofdm = 95,
-
-       .barker_corr_th_min = 190,
-       .barker_corr_th_min_mrc = 390,
-       .nrg_th_cca = 62,
-};
-
-static void iwl1000_hw_set_hw_params(struct iwl_priv *priv)
-{
-       hw_params(priv).ht40_channel =  BIT(IEEE80211_BAND_2GHZ);
-
-       hw_params(priv).tx_chains_num =
-               num_of_ant(hw_params(priv).valid_tx_ant);
-       if (cfg(priv)->rx_with_siso_diversity)
-               hw_params(priv).rx_chains_num = 1;
-       else
-               hw_params(priv).rx_chains_num =
-                       num_of_ant(hw_params(priv).valid_rx_ant);
-
-       iwl1000_set_ct_threshold(priv);
-
-       /* Set initial sensitivity parameters */
-       hw_params(priv).sens = &iwl1000_sensitivity;
-}
-
-static struct iwl_lib_ops iwl1000_lib = {
-       .set_hw_params = iwl1000_hw_set_hw_params,
-       .nic_config = iwl1000_nic_config,
-       .eeprom_ops = {
-               .regulatory_bands = {
-                       EEPROM_REG_BAND_1_CHANNELS,
-                       EEPROM_REG_BAND_2_CHANNELS,
-                       EEPROM_REG_BAND_3_CHANNELS,
-                       EEPROM_REG_BAND_4_CHANNELS,
-                       EEPROM_REG_BAND_5_CHANNELS,
-                       EEPROM_REG_BAND_24_HT40_CHANNELS,
-                       EEPROM_REGULATORY_BAND_NO_HT40,
-               },
-       },
-       .temperature = iwlagn_temperature,
-};
-
 static const struct iwl_base_params iwl1000_base_params = {
        .num_of_queues = IWLAGN_NUM_QUEUES,
        .eeprom_size = OTP_LOW_IMAGE_SIZE,
@@ -165,9 +59,8 @@ static const struct iwl_base_params iwl1000_base_params = {
        .support_ct_kill_exit = true,
        .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF,
        .chain_noise_scale = 1000,
-       .wd_timeout = IWL_DEF_WD_TIMEOUT,
+       .wd_timeout = IWL_WATCHHDOG_DISABLED,
        .max_event_log_size = 128,
-       .wd_disable = true,
 };
 
 static const struct iwl_ht_params iwl1000_ht_params = {
@@ -181,11 +74,11 @@ static const struct iwl_ht_params iwl1000_ht_params = {
        .ucode_api_max = IWL1000_UCODE_API_MAX,                 \
        .ucode_api_ok = IWL1000_UCODE_API_OK,                   \
        .ucode_api_min = IWL1000_UCODE_API_MIN,                 \
+       .device_family = IWL_DEVICE_FAMILY_1000,                \
        .max_inst_size = IWLAGN_RTC_INST_SIZE,                  \
        .max_data_size = IWLAGN_RTC_DATA_SIZE,                  \
        .eeprom_ver = EEPROM_1000_EEPROM_VERSION,               \
        .eeprom_calib_ver = EEPROM_1000_TX_POWER_VERSION,       \
-       .lib = &iwl1000_lib,                                    \
        .base_params = &iwl1000_base_params,                    \
        .led_mode = IWL_LED_BLINK
 
@@ -205,11 +98,11 @@ const struct iwl_cfg iwl1000_bg_cfg = {
        .ucode_api_max = IWL100_UCODE_API_MAX,                  \
        .ucode_api_ok = IWL100_UCODE_API_OK,                    \
        .ucode_api_min = IWL100_UCODE_API_MIN,                  \
+       .device_family = IWL_DEVICE_FAMILY_100,                 \
        .max_inst_size = IWLAGN_RTC_INST_SIZE,                  \
        .max_data_size = IWLAGN_RTC_DATA_SIZE,                  \
        .eeprom_ver = EEPROM_1000_EEPROM_VERSION,               \
        .eeprom_calib_ver = EEPROM_1000_TX_POWER_VERSION,       \
-       .lib = &iwl1000_lib,                                    \
        .base_params = &iwl1000_base_params,                    \
        .led_mode = IWL_LED_RF_STATE,                           \
        .rx_with_siso_diversity = true
index e1329a13f0fd74ed2313c81489d5688761cc93de..3d4a36cf0408634300ef72c2c5c778f6fcf82417 100644 (file)
  *
  *****************************************************************************/
 
-#include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/init.h>
-#include <linux/delay.h>
-#include <linux/skbuff.h>
-#include <linux/netdevice.h>
-#include <net/mac80211.h>
-#include <linux/etherdevice.h>
-#include <asm/unaligned.h>
 #include <linux/stringify.h>
-
-#include "iwl-eeprom.h"
-#include "iwl-dev.h"
-#include "iwl-core.h"
-#include "iwl-io.h"
-#include "iwl-agn.h"
-#include "iwl-agn-hw.h"
-#include "iwl-shared.h"
+#include "iwl-config.h"
 #include "iwl-cfg.h"
+#include "iwl-dev.h" /* still needed */
 
 /* Highest firmware API version supported */
 #define IWL2030_UCODE_API_MAX 6
 #define IWL135_FW_PRE "iwlwifi-135-"
 #define IWL135_MODULE_FIRMWARE(api) IWL135_FW_PRE __stringify(api) ".ucode"
 
-static void iwl2000_set_ct_threshold(struct iwl_priv *priv)
-{
-       /* want Celsius */
-       hw_params(priv).ct_kill_threshold = CT_KILL_THRESHOLD;
-       hw_params(priv).ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD;
-}
-
-/* NIC configuration for 2000 series */
-static void iwl2000_nic_config(struct iwl_priv *priv)
-{
-       iwl_rf_config(priv);
-
-       iwl_set_bit(trans(priv), CSR_GP_DRIVER_REG,
-                   CSR_GP_DRIVER_REG_BIT_RADIO_IQ_INVER);
-}
-
-static const struct iwl_sensitivity_ranges iwl2000_sensitivity = {
-       .min_nrg_cck = 97,
-       .auto_corr_min_ofdm = 80,
-       .auto_corr_min_ofdm_mrc = 128,
-       .auto_corr_min_ofdm_x1 = 105,
-       .auto_corr_min_ofdm_mrc_x1 = 192,
-
-       .auto_corr_max_ofdm = 145,
-       .auto_corr_max_ofdm_mrc = 232,
-       .auto_corr_max_ofdm_x1 = 110,
-       .auto_corr_max_ofdm_mrc_x1 = 232,
-
-       .auto_corr_min_cck = 125,
-       .auto_corr_max_cck = 175,
-       .auto_corr_min_cck_mrc = 160,
-       .auto_corr_max_cck_mrc = 310,
-       .nrg_th_cck = 97,
-       .nrg_th_ofdm = 100,
-
-       .barker_corr_th_min = 190,
-       .barker_corr_th_min_mrc = 390,
-       .nrg_th_cca = 62,
-};
-
-static void iwl2000_hw_set_hw_params(struct iwl_priv *priv)
-{
-       hw_params(priv).ht40_channel =  BIT(IEEE80211_BAND_2GHZ);
-
-       hw_params(priv).tx_chains_num =
-               num_of_ant(hw_params(priv).valid_tx_ant);
-       if (cfg(priv)->rx_with_siso_diversity)
-               hw_params(priv).rx_chains_num = 1;
-       else
-               hw_params(priv).rx_chains_num =
-                       num_of_ant(hw_params(priv).valid_rx_ant);
-
-       iwl2000_set_ct_threshold(priv);
-
-       /* Set initial sensitivity parameters */
-       hw_params(priv).sens = &iwl2000_sensitivity;
-}
-
-static struct iwl_lib_ops iwl2000_lib = {
-       .set_hw_params = iwl2000_hw_set_hw_params,
-       .nic_config = iwl2000_nic_config,
-       .eeprom_ops = {
-               .regulatory_bands = {
-                       EEPROM_REG_BAND_1_CHANNELS,
-                       EEPROM_REG_BAND_2_CHANNELS,
-                       EEPROM_REG_BAND_3_CHANNELS,
-                       EEPROM_REG_BAND_4_CHANNELS,
-                       EEPROM_REG_BAND_5_CHANNELS,
-                       EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
-                       EEPROM_REGULATORY_BAND_NO_HT40,
-               },
-               .enhanced_txpower = true,
-       },
-       .temperature = iwlagn_temperature,
-};
-
-static struct iwl_lib_ops iwl2030_lib = {
-       .set_hw_params = iwl2000_hw_set_hw_params,
-       .nic_config = iwl2000_nic_config,
-       .eeprom_ops = {
-               .regulatory_bands = {
-                       EEPROM_REG_BAND_1_CHANNELS,
-                       EEPROM_REG_BAND_2_CHANNELS,
-                       EEPROM_REG_BAND_3_CHANNELS,
-                       EEPROM_REG_BAND_4_CHANNELS,
-                       EEPROM_REG_BAND_5_CHANNELS,
-                       EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
-                       EEPROM_REGULATORY_BAND_NO_HT40,
-               },
-               .enhanced_txpower = true,
-       },
-       .temperature = iwlagn_temperature,
-};
-
 static const struct iwl_base_params iwl2000_base_params = {
        .eeprom_size = OTP_LOW_IMAGE_SIZE,
        .num_of_queues = IWLAGN_NUM_QUEUES,
@@ -223,11 +115,11 @@ static const struct iwl_bt_params iwl2030_bt_params = {
        .ucode_api_max = IWL2000_UCODE_API_MAX,                 \
        .ucode_api_ok = IWL2000_UCODE_API_OK,                   \
        .ucode_api_min = IWL2000_UCODE_API_MIN,                 \
+       .device_family = IWL_DEVICE_FAMILY_2000,                \
        .max_inst_size = IWL60_RTC_INST_SIZE,                   \
        .max_data_size = IWL60_RTC_DATA_SIZE,                   \
        .eeprom_ver = EEPROM_2000_EEPROM_VERSION,               \
        .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION,       \
-       .lib = &iwl2000_lib,                                    \
        .base_params = &iwl2000_base_params,                    \
        .need_temp_offset_calib = true,                         \
        .temp_offset_v2 = true,                                 \
@@ -250,11 +142,11 @@ const struct iwl_cfg iwl2000_2bgn_d_cfg = {
        .ucode_api_max = IWL2030_UCODE_API_MAX,                 \
        .ucode_api_ok = IWL2030_UCODE_API_OK,                   \
        .ucode_api_min = IWL2030_UCODE_API_MIN,                 \
+       .device_family = IWL_DEVICE_FAMILY_2030,                \
        .max_inst_size = IWL60_RTC_INST_SIZE,                   \
        .max_data_size = IWL60_RTC_DATA_SIZE,                   \
        .eeprom_ver = EEPROM_2000_EEPROM_VERSION,               \
        .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION,       \
-       .lib = &iwl2030_lib,                                    \
        .base_params = &iwl2030_base_params,                    \
        .bt_params = &iwl2030_bt_params,                        \
        .need_temp_offset_calib = true,                         \
@@ -273,11 +165,11 @@ const struct iwl_cfg iwl2030_2bgn_cfg = {
        .ucode_api_max = IWL105_UCODE_API_MAX,                  \
        .ucode_api_ok = IWL105_UCODE_API_OK,                    \
        .ucode_api_min = IWL105_UCODE_API_MIN,                  \
+       .device_family = IWL_DEVICE_FAMILY_105,                 \
        .max_inst_size = IWL60_RTC_INST_SIZE,                   \
        .max_data_size = IWL60_RTC_DATA_SIZE,                   \
        .eeprom_ver = EEPROM_2000_EEPROM_VERSION,               \
        .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION,       \
-       .lib = &iwl2000_lib,                                    \
        .base_params = &iwl2000_base_params,                    \
        .need_temp_offset_calib = true,                         \
        .temp_offset_v2 = true,                                 \
@@ -302,11 +194,11 @@ const struct iwl_cfg iwl105_bgn_d_cfg = {
        .ucode_api_max = IWL135_UCODE_API_MAX,                  \
        .ucode_api_ok = IWL135_UCODE_API_OK,                    \
        .ucode_api_min = IWL135_UCODE_API_MIN,                  \
+       .device_family = IWL_DEVICE_FAMILY_135,                 \
        .max_inst_size = IWL60_RTC_INST_SIZE,                   \
        .max_data_size = IWL60_RTC_DATA_SIZE,                   \
        .eeprom_ver = EEPROM_2000_EEPROM_VERSION,               \
        .eeprom_calib_ver = EEPROM_2000_TX_POWER_VERSION,       \
-       .lib = &iwl2030_lib,                                    \
        .base_params = &iwl2030_base_params,                    \
        .bt_params = &iwl2030_bt_params,                        \
        .need_temp_offset_calib = true,                         \
index 34bc8dd0064b859bd43b4ef3032e29fb64fda531..ffa9ac5fe086858cb336ab143ce675d345ae3b92 100644 (file)
  *
  *****************************************************************************/
 
-#include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/init.h>
-#include <linux/delay.h>
-#include <linux/sched.h>
-#include <linux/skbuff.h>
-#include <linux/netdevice.h>
-#include <net/mac80211.h>
-#include <linux/etherdevice.h>
-#include <asm/unaligned.h>
 #include <linux/stringify.h>
-
-#include "iwl-eeprom.h"
-#include "iwl-dev.h"
-#include "iwl-core.h"
-#include "iwl-io.h"
-#include "iwl-agn.h"
-#include "iwl-agn-hw.h"
-#include "iwl-trans.h"
-#include "iwl-shared.h"
+#include "iwl-config.h"
 #include "iwl-cfg.h"
-#include "iwl-prph.h"
+#include "iwl-dev.h" /* still needed */
 
 /* Highest firmware API version supported */
 #define IWL5000_UCODE_API_MAX 5
 #define IWL5150_FW_PRE "iwlwifi-5150-"
 #define IWL5150_MODULE_FIRMWARE(api) IWL5150_FW_PRE __stringify(api) ".ucode"
 
-/* NIC configuration for 5000 series */
-static void iwl5000_nic_config(struct iwl_priv *priv)
-{
-       iwl_rf_config(priv);
-
-       /* W/A : NIC is stuck in a reset state after Early PCIe power off
-        * (PCIe power is lost before PERST# is asserted),
-        * causing ME FW to lose ownership and not being able to obtain it back.
-        */
-       iwl_set_bits_mask_prph(trans(priv), APMG_PS_CTRL_REG,
-                               APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
-                               ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
-}
-
-static const struct iwl_sensitivity_ranges iwl5000_sensitivity = {
-       .min_nrg_cck = 100,
-       .auto_corr_min_ofdm = 90,
-       .auto_corr_min_ofdm_mrc = 170,
-       .auto_corr_min_ofdm_x1 = 105,
-       .auto_corr_min_ofdm_mrc_x1 = 220,
-
-       .auto_corr_max_ofdm = 120,
-       .auto_corr_max_ofdm_mrc = 210,
-       .auto_corr_max_ofdm_x1 = 120,
-       .auto_corr_max_ofdm_mrc_x1 = 240,
-
-       .auto_corr_min_cck = 125,
-       .auto_corr_max_cck = 200,
-       .auto_corr_min_cck_mrc = 200,
-       .auto_corr_max_cck_mrc = 400,
-       .nrg_th_cck = 100,
-       .nrg_th_ofdm = 100,
-
-       .barker_corr_th_min = 190,
-       .barker_corr_th_min_mrc = 390,
-       .nrg_th_cca = 62,
-};
-
-static struct iwl_sensitivity_ranges iwl5150_sensitivity = {
-       .min_nrg_cck = 95,
-       .auto_corr_min_ofdm = 90,
-       .auto_corr_min_ofdm_mrc = 170,
-       .auto_corr_min_ofdm_x1 = 105,
-       .auto_corr_min_ofdm_mrc_x1 = 220,
-
-       .auto_corr_max_ofdm = 120,
-       .auto_corr_max_ofdm_mrc = 210,
-       /* max = min for performance bug in 5150 DSP */
-       .auto_corr_max_ofdm_x1 = 105,
-       .auto_corr_max_ofdm_mrc_x1 = 220,
-
-       .auto_corr_min_cck = 125,
-       .auto_corr_max_cck = 200,
-       .auto_corr_min_cck_mrc = 170,
-       .auto_corr_max_cck_mrc = 400,
-       .nrg_th_cck = 95,
-       .nrg_th_ofdm = 95,
-
-       .barker_corr_th_min = 190,
-       .barker_corr_th_min_mrc = 390,
-       .nrg_th_cca = 62,
-};
-
-#define IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF  (-5)
-
-static s32 iwl_temp_calib_to_offset(struct iwl_shared *shrd)
-{
-       u16 temperature, voltage;
-       __le16 *temp_calib = (__le16 *)iwl_eeprom_query_addr(shrd,
-                               EEPROM_KELVIN_TEMPERATURE);
-
-       temperature = le16_to_cpu(temp_calib[0]);
-       voltage = le16_to_cpu(temp_calib[1]);
-
-       /* offset = temp - volt / coeff */
-       return (s32)(temperature - voltage / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF);
-}
-
-static void iwl5150_set_ct_threshold(struct iwl_priv *priv)
-{
-       const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF;
-       s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY) -
-                       iwl_temp_calib_to_offset(priv->shrd);
-
-       hw_params(priv).ct_kill_threshold = threshold * volt2temp_coef;
-}
-
-static void iwl5000_set_ct_threshold(struct iwl_priv *priv)
-{
-       /* want Celsius */
-       hw_params(priv).ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY;
-}
-
-static void iwl5000_hw_set_hw_params(struct iwl_priv *priv)
-{
-       hw_params(priv).ht40_channel =  BIT(IEEE80211_BAND_2GHZ) |
-                                       BIT(IEEE80211_BAND_5GHZ);
-
-       hw_params(priv).tx_chains_num =
-               num_of_ant(hw_params(priv).valid_tx_ant);
-       hw_params(priv).rx_chains_num =
-               num_of_ant(hw_params(priv).valid_rx_ant);
-
-       iwl5000_set_ct_threshold(priv);
-
-       /* Set initial sensitivity parameters */
-       hw_params(priv).sens = &iwl5000_sensitivity;
-}
-
-static void iwl5150_hw_set_hw_params(struct iwl_priv *priv)
-{
-       hw_params(priv).ht40_channel =  BIT(IEEE80211_BAND_2GHZ) |
-                                       BIT(IEEE80211_BAND_5GHZ);
-
-       hw_params(priv).tx_chains_num =
-               num_of_ant(hw_params(priv).valid_tx_ant);
-       hw_params(priv).rx_chains_num =
-               num_of_ant(hw_params(priv).valid_rx_ant);
-
-       iwl5150_set_ct_threshold(priv);
-
-       /* Set initial sensitivity parameters */
-       hw_params(priv).sens = &iwl5150_sensitivity;
-}
-
-static void iwl5150_temperature(struct iwl_priv *priv)
-{
-       u32 vt = 0;
-       s32 offset =  iwl_temp_calib_to_offset(priv->shrd);
-
-       vt = le32_to_cpu(priv->statistics.common.temperature);
-       vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
-       /* now vt hold the temperature in Kelvin */
-       priv->temperature = KELVIN_TO_CELSIUS(vt);
-       iwl_tt_handler(priv);
-}
-
-static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
-                                    struct ieee80211_channel_switch *ch_switch)
-{
-       /*
-        * MULTI-FIXME
-        * See iwlagn_mac_channel_switch.
-        */
-       struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
-       struct iwl5000_channel_switch_cmd cmd;
-       const struct iwl_channel_info *ch_info;
-       u32 switch_time_in_usec, ucode_switch_time;
-       u16 ch;
-       u32 tsf_low;
-       u8 switch_count;
-       u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
-       struct ieee80211_vif *vif = ctx->vif;
-       struct iwl_host_cmd hcmd = {
-               .id = REPLY_CHANNEL_SWITCH,
-               .len = { sizeof(cmd), },
-               .flags = CMD_SYNC,
-               .data = { &cmd, },
-       };
-
-       cmd.band = priv->band == IEEE80211_BAND_2GHZ;
-       ch = ch_switch->channel->hw_value;
-       IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
-                     ctx->active.channel, ch);
-       cmd.channel = cpu_to_le16(ch);
-       cmd.rxon_flags = ctx->staging.flags;
-       cmd.rxon_filter_flags = ctx->staging.filter_flags;
-       switch_count = ch_switch->count;
-       tsf_low = ch_switch->timestamp & 0x0ffffffff;
-       /*
-        * calculate the ucode channel switch time
-        * adding TSF as one of the factor for when to switch
-        */
-       if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
-               if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
-                   beacon_interval)) {
-                       switch_count -= (priv->ucode_beacon_time -
-                               tsf_low) / beacon_interval;
-               } else
-                       switch_count = 0;
-       }
-       if (switch_count <= 1)
-               cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
-       else {
-               switch_time_in_usec =
-                       vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
-               ucode_switch_time = iwl_usecs_to_beacons(priv,
-                                                        switch_time_in_usec,
-                                                        beacon_interval);
-               cmd.switch_time = iwl_add_beacon_time(priv,
-                                                     priv->ucode_beacon_time,
-                                                     ucode_switch_time,
-                                                     beacon_interval);
-       }
-       IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
-                     cmd.switch_time);
-       ch_info = iwl_get_channel_info(priv, priv->band, ch);
-       if (ch_info)
-               cmd.expect_beacon = is_channel_radar(ch_info);
-       else {
-               IWL_ERR(priv, "invalid channel switch from %u to %u\n",
-                       ctx->active.channel, ch);
-               return -EFAULT;
-       }
-
-       return iwl_dvm_send_cmd(priv, &hcmd);
-}
-
-static struct iwl_lib_ops iwl5000_lib = {
-       .set_hw_params = iwl5000_hw_set_hw_params,
-       .set_channel_switch = iwl5000_hw_channel_switch,
-       .nic_config = iwl5000_nic_config,
-       .eeprom_ops = {
-               .regulatory_bands = {
-                       EEPROM_REG_BAND_1_CHANNELS,
-                       EEPROM_REG_BAND_2_CHANNELS,
-                       EEPROM_REG_BAND_3_CHANNELS,
-                       EEPROM_REG_BAND_4_CHANNELS,
-                       EEPROM_REG_BAND_5_CHANNELS,
-                       EEPROM_REG_BAND_24_HT40_CHANNELS,
-                       EEPROM_REG_BAND_52_HT40_CHANNELS
-               },
-       },
-       .temperature = iwlagn_temperature,
-};
-
-static struct iwl_lib_ops iwl5150_lib = {
-       .set_hw_params = iwl5150_hw_set_hw_params,
-       .set_channel_switch = iwl5000_hw_channel_switch,
-       .nic_config = iwl5000_nic_config,
-       .eeprom_ops = {
-               .regulatory_bands = {
-                       EEPROM_REG_BAND_1_CHANNELS,
-                       EEPROM_REG_BAND_2_CHANNELS,
-                       EEPROM_REG_BAND_3_CHANNELS,
-                       EEPROM_REG_BAND_4_CHANNELS,
-                       EEPROM_REG_BAND_5_CHANNELS,
-                       EEPROM_REG_BAND_24_HT40_CHANNELS,
-                       EEPROM_REG_BAND_52_HT40_CHANNELS
-               },
-       },
-       .temperature = iwl5150_temperature,
-};
-
 static const struct iwl_base_params iwl5000_base_params = {
        .eeprom_size = IWLAGN_EEPROM_IMG_SIZE,
        .num_of_queues = IWLAGN_NUM_QUEUES,
@@ -312,10 +51,9 @@ static const struct iwl_base_params iwl5000_base_params = {
        .led_compensation = 51,
        .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF,
        .chain_noise_scale = 1000,
-       .wd_timeout = IWL_LONG_WD_TIMEOUT,
+       .wd_timeout = IWL_WATCHHDOG_DISABLED,
        .max_event_log_size = 512,
        .no_idle_support = true,
-       .wd_disable = true,
 };
 
 static const struct iwl_ht_params iwl5000_ht_params = {
@@ -326,11 +64,11 @@ static const struct iwl_ht_params iwl5000_ht_params = {
        .fw_name_pre = IWL5000_FW_PRE,                          \
        .ucode_api_max = IWL5000_UCODE_API_MAX,                 \
        .ucode_api_min = IWL5000_UCODE_API_MIN,                 \
+       .device_family = IWL_DEVICE_FAMILY_5000,                \
        .max_inst_size = IWLAGN_RTC_INST_SIZE,                  \
        .max_data_size = IWLAGN_RTC_DATA_SIZE,                  \
        .eeprom_ver = EEPROM_5000_EEPROM_VERSION,               \
        .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,       \
-       .lib = &iwl5000_lib,                                    \
        .base_params = &iwl5000_base_params,                    \
        .led_mode = IWL_LED_BLINK
 
@@ -371,11 +109,11 @@ const struct iwl_cfg iwl5350_agn_cfg = {
        .fw_name_pre = IWL5000_FW_PRE,
        .ucode_api_max = IWL5000_UCODE_API_MAX,
        .ucode_api_min = IWL5000_UCODE_API_MIN,
+       .device_family = IWL_DEVICE_FAMILY_5000,
        .max_inst_size = IWLAGN_RTC_INST_SIZE,
        .max_data_size = IWLAGN_RTC_DATA_SIZE,
        .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
        .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
-       .lib = &iwl5000_lib,
        .base_params = &iwl5000_base_params,
        .ht_params = &iwl5000_ht_params,
        .led_mode = IWL_LED_BLINK,
@@ -386,11 +124,11 @@ const struct iwl_cfg iwl5350_agn_cfg = {
        .fw_name_pre = IWL5150_FW_PRE,                          \
        .ucode_api_max = IWL5150_UCODE_API_MAX,                 \
        .ucode_api_min = IWL5150_UCODE_API_MIN,                 \
+       .device_family = IWL_DEVICE_FAMILY_5150,                \
        .max_inst_size = IWLAGN_RTC_INST_SIZE,                  \
        .max_data_size = IWLAGN_RTC_DATA_SIZE,                  \
        .eeprom_ver = EEPROM_5050_EEPROM_VERSION,               \
        .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,       \
-       .lib = &iwl5150_lib,                                    \
        .base_params = &iwl5000_base_params,                    \
        .no_xtal_calib = true,                                  \
        .led_mode = IWL_LED_BLINK,                              \
index 7075570a0f2ceec9fcf307b928321af7119b9c2b..00da2520a4b76038bb2325b481f8244eb8fcdde5 100644 (file)
  *
  *****************************************************************************/
 
-#include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/init.h>
-#include <linux/delay.h>
-#include <linux/skbuff.h>
-#include <linux/netdevice.h>
-#include <net/mac80211.h>
-#include <linux/etherdevice.h>
-#include <asm/unaligned.h>
 #include <linux/stringify.h>
-
-#include "iwl-eeprom.h"
-#include "iwl-dev.h"
-#include "iwl-core.h"
-#include "iwl-io.h"
-#include "iwl-agn.h"
-#include "iwl-agn-hw.h"
-#include "iwl-trans.h"
-#include "iwl-shared.h"
+#include "iwl-config.h"
 #include "iwl-cfg.h"
+#include "iwl-dev.h" /* still needed */
 
 /* Highest firmware API version supported */
 #define IWL6000_UCODE_API_MAX 6
 #define IWL6030_FW_PRE "iwlwifi-6000g2b-"
 #define IWL6030_MODULE_FIRMWARE(api) IWL6030_FW_PRE __stringify(api) ".ucode"
 
-static void iwl6000_set_ct_threshold(struct iwl_priv *priv)
-{
-       /* want Celsius */
-       hw_params(priv).ct_kill_threshold = CT_KILL_THRESHOLD;
-       hw_params(priv).ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD;
-}
-
-static void iwl6050_additional_nic_config(struct iwl_priv *priv)
-{
-       /* Indicate calibration version to uCode. */
-       if (iwl_eeprom_calib_version(priv->shrd) >= 6)
-               iwl_set_bit(trans(priv), CSR_GP_DRIVER_REG,
-                               CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6);
-}
-
-static void iwl6150_additional_nic_config(struct iwl_priv *priv)
-{
-       /* Indicate calibration version to uCode. */
-       if (iwl_eeprom_calib_version(priv->shrd) >= 6)
-               iwl_set_bit(trans(priv), CSR_GP_DRIVER_REG,
-                               CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6);
-       iwl_set_bit(trans(priv), CSR_GP_DRIVER_REG,
-                   CSR_GP_DRIVER_REG_BIT_6050_1x2);
-}
-
-static void iwl6000i_additional_nic_config(struct iwl_priv *priv)
-{
-       /* 2x2 IPA phy type */
-       iwl_write32(trans(priv), CSR_GP_DRIVER_REG,
-                    CSR_GP_DRIVER_REG_BIT_RADIO_SKU_2x2_IPA);
-}
-
-/* NIC configuration for 6000 series */
-static void iwl6000_nic_config(struct iwl_priv *priv)
-{
-       iwl_rf_config(priv);
-
-       /* do additional nic configuration if needed */
-       if (cfg(priv)->additional_nic_config)
-               cfg(priv)->additional_nic_config(priv);
-}
-
-static const struct iwl_sensitivity_ranges iwl6000_sensitivity = {
-       .min_nrg_cck = 110,
-       .auto_corr_min_ofdm = 80,
-       .auto_corr_min_ofdm_mrc = 128,
-       .auto_corr_min_ofdm_x1 = 105,
-       .auto_corr_min_ofdm_mrc_x1 = 192,
-
-       .auto_corr_max_ofdm = 145,
-       .auto_corr_max_ofdm_mrc = 232,
-       .auto_corr_max_ofdm_x1 = 110,
-       .auto_corr_max_ofdm_mrc_x1 = 232,
-
-       .auto_corr_min_cck = 125,
-       .auto_corr_max_cck = 175,
-       .auto_corr_min_cck_mrc = 160,
-       .auto_corr_max_cck_mrc = 310,
-       .nrg_th_cck = 110,
-       .nrg_th_ofdm = 110,
-
-       .barker_corr_th_min = 190,
-       .barker_corr_th_min_mrc = 336,
-       .nrg_th_cca = 62,
-};
-
-static void iwl6000_hw_set_hw_params(struct iwl_priv *priv)
-{
-       hw_params(priv).ht40_channel =  BIT(IEEE80211_BAND_2GHZ) |
-                                       BIT(IEEE80211_BAND_5GHZ);
-
-       hw_params(priv).tx_chains_num =
-               num_of_ant(hw_params(priv).valid_tx_ant);
-       if (cfg(priv)->rx_with_siso_diversity)
-               hw_params(priv).rx_chains_num = 1;
-       else
-               hw_params(priv).rx_chains_num =
-                       num_of_ant(hw_params(priv).valid_rx_ant);
-
-       iwl6000_set_ct_threshold(priv);
-
-       /* Set initial sensitivity parameters */
-       hw_params(priv).sens = &iwl6000_sensitivity;
-
-}
-
-static int iwl6000_hw_channel_switch(struct iwl_priv *priv,
-                                    struct ieee80211_channel_switch *ch_switch)
-{
-       /*
-        * MULTI-FIXME
-        * See iwlagn_mac_channel_switch.
-        */
-       struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
-       struct iwl6000_channel_switch_cmd cmd;
-       const struct iwl_channel_info *ch_info;
-       u32 switch_time_in_usec, ucode_switch_time;
-       u16 ch;
-       u32 tsf_low;
-       u8 switch_count;
-       u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
-       struct ieee80211_vif *vif = ctx->vif;
-       struct iwl_host_cmd hcmd = {
-               .id = REPLY_CHANNEL_SWITCH,
-               .len = { sizeof(cmd), },
-               .flags = CMD_SYNC,
-               .data = { &cmd, },
-       };
-
-       cmd.band = priv->band == IEEE80211_BAND_2GHZ;
-       ch = ch_switch->channel->hw_value;
-       IWL_DEBUG_11H(priv, "channel switch from %u to %u\n",
-                     ctx->active.channel, ch);
-       cmd.channel = cpu_to_le16(ch);
-       cmd.rxon_flags = ctx->staging.flags;
-       cmd.rxon_filter_flags = ctx->staging.filter_flags;
-       switch_count = ch_switch->count;
-       tsf_low = ch_switch->timestamp & 0x0ffffffff;
-       /*
-        * calculate the ucode channel switch time
-        * adding TSF as one of the factor for when to switch
-        */
-       if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
-               if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
-                   beacon_interval)) {
-                       switch_count -= (priv->ucode_beacon_time -
-                               tsf_low) / beacon_interval;
-               } else
-                       switch_count = 0;
-       }
-       if (switch_count <= 1)
-               cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
-       else {
-               switch_time_in_usec =
-                       vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
-               ucode_switch_time = iwl_usecs_to_beacons(priv,
-                                                        switch_time_in_usec,
-                                                        beacon_interval);
-               cmd.switch_time = iwl_add_beacon_time(priv,
-                                                     priv->ucode_beacon_time,
-                                                     ucode_switch_time,
-                                                     beacon_interval);
-       }
-       IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
-                     cmd.switch_time);
-       ch_info = iwl_get_channel_info(priv, priv->band, ch);
-       if (ch_info)
-               cmd.expect_beacon = is_channel_radar(ch_info);
-       else {
-               IWL_ERR(priv, "invalid channel switch from %u to %u\n",
-                       ctx->active.channel, ch);
-               return -EFAULT;
-       }
-
-       return iwl_dvm_send_cmd(priv, &hcmd);
-}
-
-static struct iwl_lib_ops iwl6000_lib = {
-       .set_hw_params = iwl6000_hw_set_hw_params,
-       .set_channel_switch = iwl6000_hw_channel_switch,
-       .nic_config = iwl6000_nic_config,
-       .eeprom_ops = {
-               .regulatory_bands = {
-                       EEPROM_REG_BAND_1_CHANNELS,
-                       EEPROM_REG_BAND_2_CHANNELS,
-                       EEPROM_REG_BAND_3_CHANNELS,
-                       EEPROM_REG_BAND_4_CHANNELS,
-                       EEPROM_REG_BAND_5_CHANNELS,
-                       EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
-                       EEPROM_REG_BAND_52_HT40_CHANNELS
-               },
-               .enhanced_txpower = true,
-       },
-       .temperature = iwlagn_temperature,
-};
-
-static struct iwl_lib_ops iwl6030_lib = {
-       .set_hw_params = iwl6000_hw_set_hw_params,
-       .set_channel_switch = iwl6000_hw_channel_switch,
-       .nic_config = iwl6000_nic_config,
-       .eeprom_ops = {
-               .regulatory_bands = {
-                       EEPROM_REG_BAND_1_CHANNELS,
-                       EEPROM_REG_BAND_2_CHANNELS,
-                       EEPROM_REG_BAND_3_CHANNELS,
-                       EEPROM_REG_BAND_4_CHANNELS,
-                       EEPROM_REG_BAND_5_CHANNELS,
-                       EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
-                       EEPROM_REG_BAND_52_HT40_CHANNELS
-               },
-               .enhanced_txpower = true,
-       },
-       .temperature = iwlagn_temperature,
-};
-
 static const struct iwl_base_params iwl6000_base_params = {
        .eeprom_size = OTP_LOW_IMAGE_SIZE,
        .num_of_queues = IWLAGN_NUM_QUEUES,
@@ -333,11 +123,11 @@ static const struct iwl_bt_params iwl6000_bt_params = {
        .ucode_api_max = IWL6000G2_UCODE_API_MAX,               \
        .ucode_api_ok = IWL6000G2_UCODE_API_OK,                 \
        .ucode_api_min = IWL6000G2_UCODE_API_MIN,               \
+       .device_family = IWL_DEVICE_FAMILY_6005,                \
        .max_inst_size = IWL60_RTC_INST_SIZE,                   \
        .max_data_size = IWL60_RTC_DATA_SIZE,                   \
        .eeprom_ver = EEPROM_6005_EEPROM_VERSION,               \
        .eeprom_calib_ver = EEPROM_6005_TX_POWER_VERSION,       \
-       .lib = &iwl6000_lib,                                    \
        .base_params = &iwl6000_g2_base_params,                 \
        .need_temp_offset_calib = true,                         \
        .led_mode = IWL_LED_RF_STATE
@@ -387,11 +177,11 @@ const struct iwl_cfg iwl6005_2agn_mow2_cfg = {
        .ucode_api_max = IWL6000G2_UCODE_API_MAX,               \
        .ucode_api_ok = IWL6000G2_UCODE_API_OK,                 \
        .ucode_api_min = IWL6000G2_UCODE_API_MIN,               \
+       .device_family = IWL_DEVICE_FAMILY_6030,                \
        .max_inst_size = IWL60_RTC_INST_SIZE,                   \
        .max_data_size = IWL60_RTC_DATA_SIZE,                   \
        .eeprom_ver = EEPROM_6030_EEPROM_VERSION,               \
        .eeprom_calib_ver = EEPROM_6030_TX_POWER_VERSION,       \
-       .lib = &iwl6030_lib,                                    \
        .base_params = &iwl6000_g2_base_params,                 \
        .bt_params = &iwl6000_bt_params,                        \
        .need_temp_offset_calib = true,                         \
@@ -458,14 +248,13 @@ const struct iwl_cfg iwl130_bg_cfg = {
        .ucode_api_max = IWL6000_UCODE_API_MAX,                 \
        .ucode_api_ok = IWL6000_UCODE_API_OK,                   \
        .ucode_api_min = IWL6000_UCODE_API_MIN,                 \
+       .device_family = IWL_DEVICE_FAMILY_6000i,               \
        .max_inst_size = IWL60_RTC_INST_SIZE,                   \
        .max_data_size = IWL60_RTC_DATA_SIZE,                   \
        .valid_tx_ant = ANT_BC,         /* .cfg overwrite */    \
        .valid_rx_ant = ANT_BC,         /* .cfg overwrite */    \
        .eeprom_ver = EEPROM_6000_EEPROM_VERSION,               \
        .eeprom_calib_ver = EEPROM_6000_TX_POWER_VERSION,       \
-       .lib = &iwl6000_lib,                                    \
-       .additional_nic_config = iwl6000i_additional_nic_config,\
        .base_params = &iwl6000_base_params,                    \
        .led_mode = IWL_LED_BLINK
 
@@ -489,12 +278,11 @@ const struct iwl_cfg iwl6000i_2bg_cfg = {
        .fw_name_pre = IWL6050_FW_PRE,                          \
        .ucode_api_max = IWL6050_UCODE_API_MAX,                 \
        .ucode_api_min = IWL6050_UCODE_API_MIN,                 \
+       .device_family = IWL_DEVICE_FAMILY_6050,                \
        .max_inst_size = IWL60_RTC_INST_SIZE,                   \
        .max_data_size = IWL60_RTC_DATA_SIZE,                   \
        .valid_tx_ant = ANT_AB,         /* .cfg overwrite */    \
        .valid_rx_ant = ANT_AB,         /* .cfg overwrite */    \
-       .lib = &iwl6000_lib,                                    \
-       .additional_nic_config = iwl6050_additional_nic_config, \
        .eeprom_ver = EEPROM_6050_EEPROM_VERSION,               \
        .eeprom_calib_ver = EEPROM_6050_TX_POWER_VERSION,       \
        .base_params = &iwl6050_base_params,                    \
@@ -516,10 +304,9 @@ const struct iwl_cfg iwl6050_2abg_cfg = {
        .fw_name_pre = IWL6050_FW_PRE,                          \
        .ucode_api_max = IWL6050_UCODE_API_MAX,                 \
        .ucode_api_min = IWL6050_UCODE_API_MIN,                 \
+       .device_family = IWL_DEVICE_FAMILY_6150,                \
        .max_inst_size = IWL60_RTC_INST_SIZE,                   \
        .max_data_size = IWL60_RTC_DATA_SIZE,                   \
-       .lib = &iwl6000_lib,                                    \
-       .additional_nic_config = iwl6150_additional_nic_config, \
        .eeprom_ver = EEPROM_6150_EEPROM_VERSION,               \
        .eeprom_calib_ver = EEPROM_6150_TX_POWER_VERSION,       \
        .base_params = &iwl6050_base_params,                    \
@@ -543,11 +330,11 @@ const struct iwl_cfg iwl6000_3agn_cfg = {
        .ucode_api_max = IWL6000_UCODE_API_MAX,
        .ucode_api_ok = IWL6000_UCODE_API_OK,
        .ucode_api_min = IWL6000_UCODE_API_MIN,
+       .device_family = IWL_DEVICE_FAMILY_6000,
        .max_inst_size = IWL60_RTC_INST_SIZE,
        .max_data_size = IWL60_RTC_DATA_SIZE,
        .eeprom_ver = EEPROM_6000_EEPROM_VERSION,
        .eeprom_calib_ver = EEPROM_6000_TX_POWER_VERSION,
-       .lib = &iwl6000_lib,
        .base_params = &iwl6000_base_params,
        .ht_params = &iwl6000_ht_params,
        .led_mode = IWL_LED_BLINK,
index 84cbe7bb504cad1c3cfdb68cb9bcc1270c4d80ad..61c243f7395f05b2611a07a8349258f9fd981a3e 100644 (file)
@@ -190,7 +190,7 @@ static int iwl_sens_energy_cck(struct iwl_priv *priv,
        u32 max_false_alarms = MAX_FA_CCK * rx_enable_time;
        u32 min_false_alarms = MIN_FA_CCK * rx_enable_time;
        struct iwl_sensitivity_data *data = NULL;
-       const struct iwl_sensitivity_ranges *ranges = hw_params(priv).sens;
+       const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens;
 
        data = &(priv->sensitivity_data);
 
@@ -373,7 +373,7 @@ static int iwl_sens_auto_corr_ofdm(struct iwl_priv *priv,
        u32 max_false_alarms = MAX_FA_OFDM * rx_enable_time;
        u32 min_false_alarms = MIN_FA_OFDM * rx_enable_time;
        struct iwl_sensitivity_data *data = NULL;
-       const struct iwl_sensitivity_ranges *ranges = hw_params(priv).sens;
+       const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens;
 
        data = &(priv->sensitivity_data);
 
@@ -597,9 +597,9 @@ void iwl_init_sensitivity(struct iwl_priv *priv)
        int ret = 0;
        int i;
        struct iwl_sensitivity_data *data = NULL;
-       const struct iwl_sensitivity_ranges *ranges = hw_params(priv).sens;
+       const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens;
 
-       if (priv->disable_sens_cal)
+       if (priv->calib_disabled & IWL_SENSITIVITY_CALIB_DISABLED)
                return;
 
        IWL_DEBUG_CALIB(priv, "Start iwl_init_sensitivity\n");
@@ -663,7 +663,7 @@ void iwl_sensitivity_calibration(struct iwl_priv *priv)
        struct statistics_rx_phy *ofdm, *cck;
        struct statistics_general_data statis;
 
-       if (priv->disable_sens_cal)
+       if (priv->calib_disabled & IWL_SENSITIVITY_CALIB_DISABLED)
                return;
 
        data = &(priv->sensitivity_data);
@@ -833,28 +833,28 @@ static void iwl_find_disconn_antenna(struct iwl_priv *priv, u32* average_sig,
         * To be safe, simply mask out any chains that we know
         * are not on the device.
         */
-       active_chains &= hw_params(priv).valid_rx_ant;
+       active_chains &= priv->hw_params.valid_rx_ant;
 
        num_tx_chains = 0;
        for (i = 0; i < NUM_RX_CHAINS; i++) {
                /* loops on all the bits of
                 * priv->hw_setting.valid_tx_ant */
                u8 ant_msk = (1 << i);
-               if (!(hw_params(priv).valid_tx_ant & ant_msk))
+               if (!(priv->hw_params.valid_tx_ant & ant_msk))
                        continue;
 
                num_tx_chains++;
                if (data->disconn_array[i] == 0)
                        /* there is a Tx antenna connected */
                        break;
-               if (num_tx_chains == hw_params(priv).tx_chains_num &&
+               if (num_tx_chains == priv->hw_params.tx_chains_num &&
                    data->disconn_array[i]) {
                        /*
                         * If all chains are disconnected
                         * connect the first valid tx chain
                         */
                        first_chain =
-                               find_first_chain(hw_params(priv).valid_tx_ant);
+                               find_first_chain(priv->hw_params.valid_tx_ant);
                        data->disconn_array[first_chain] = 0;
                        active_chains |= BIT(first_chain);
                        IWL_DEBUG_CALIB(priv,
@@ -864,13 +864,13 @@ static void iwl_find_disconn_antenna(struct iwl_priv *priv, u32* average_sig,
                }
        }
 
-       if (active_chains != hw_params(priv).valid_rx_ant &&
+       if (active_chains != priv->hw_params.valid_rx_ant &&
            active_chains != priv->chain_noise_data.active_chains)
                IWL_DEBUG_CALIB(priv,
                                "Detected that not all antennas are connected! "
                                "Connected: %#x, valid: %#x.\n",
                                active_chains,
-                               hw_params(priv).valid_rx_ant);
+                               priv->hw_params.valid_rx_ant);
 
        /* Save for use within RXON, TX, SCAN commands, etc. */
        data->active_chains = active_chains;
@@ -970,7 +970,7 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv)
         */
        struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
 
-       if (priv->disable_chain_noise_cal)
+       if (priv->calib_disabled & IWL_CHAIN_NOISE_CALIB_DISABLED)
                return;
 
        data = &(priv->chain_noise_data);
@@ -1055,7 +1055,7 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv)
            cfg(priv)->bt_params->advanced_bt_coexist) {
                /* Disable disconnected antenna algorithm for advanced
                   bt coex, assuming valid antennas are connected */
-               data->active_chains = hw_params(priv).valid_rx_ant;
+               data->active_chains = priv->hw_params.valid_rx_ant;
                for (i = 0; i < NUM_RX_CHAINS; i++)
                        if (!(data->active_chains & (1<<i)))
                                data->disconn_array[i] = 1;
@@ -1085,7 +1085,7 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv)
                        min_average_noise, min_average_noise_antenna_i);
 
        iwlagn_gain_computation(priv, average_noise,
-                               find_first_chain(hw_params(priv).valid_rx_ant));
+                               find_first_chain(priv->hw_params.valid_rx_ant));
 
        /* Some power changes may have been made during the calibration.
         * Update and commit the RXON
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-devices.c b/drivers/net/wireless/iwlwifi/iwl-agn-devices.c
new file mode 100644 (file)
index 0000000..08718ca
--- /dev/null
@@ -0,0 +1,756 @@
+/******************************************************************************
+ *
+ * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
+ *
+ * The full GNU General Public License is included in this distribution in the
+ * file called LICENSE.
+ *
+ * Contact Information:
+ *  Intel Linux Wireless <ilw@linux.intel.com>
+ * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
+ *
+ *****************************************************************************/
+
+/*
+ * DVM device-specific data & functions
+ */
+#include "iwl-core.h"
+#include "iwl-agn.h"
+#include "iwl-dev.h"
+#include "iwl-commands.h"
+#include "iwl-io.h"
+#include "iwl-prph.h"
+
+/*
+ * 1000 series
+ * ===========
+ */
+
+/*
+ * For 1000, use advance thermal throttling critical temperature threshold,
+ * but legacy thermal management implementation for now.
+ * This is for the reason of 1000 uCode using advance thermal throttling API
+ * but not implement ct_kill_exit based on ct_kill exit temperature
+ * so the thermal throttling will still based on legacy thermal throttling
+ * management.
+ * The code here need to be modified once 1000 uCode has the advanced thermal
+ * throttling algorithm in place
+ */
+static void iwl1000_set_ct_threshold(struct iwl_priv *priv)
+{
+       /* want Celsius */
+       priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY;
+       priv->hw_params.ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD;
+}
+
+/* NIC configuration for 1000 series */
+static void iwl1000_nic_config(struct iwl_priv *priv)
+{
+       /* set CSR_HW_CONFIG_REG for uCode use */
+       iwl_set_bit(trans(priv), CSR_HW_IF_CONFIG_REG,
+                   CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
+                   CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
+
+       /* Setting digital SVR for 1000 card to 1.32V */
+       /* locking is acquired in iwl_set_bits_mask_prph() function */
+       iwl_set_bits_mask_prph(trans(priv), APMG_DIGITAL_SVR_REG,
+                               APMG_SVR_DIGITAL_VOLTAGE_1_32,
+                               ~APMG_SVR_VOLTAGE_CONFIG_BIT_MSK);
+}
+
+/**
+ * iwl_beacon_time_mask_low - mask of lower 32 bit of beacon time
+ * @priv -- pointer to iwl_priv data structure
+ * @tsf_bits -- number of bits need to shift for masking)
+ */
+static inline u32 iwl_beacon_time_mask_low(struct iwl_priv *priv,
+                                          u16 tsf_bits)
+{
+       return (1 << tsf_bits) - 1;
+}
+
+/**
+ * iwl_beacon_time_mask_high - mask of higher 32 bit of beacon time
+ * @priv -- pointer to iwl_priv data structure
+ * @tsf_bits -- number of bits need to shift for masking)
+ */
+static inline u32 iwl_beacon_time_mask_high(struct iwl_priv *priv,
+                                           u16 tsf_bits)
+{
+       return ((1 << (32 - tsf_bits)) - 1) << tsf_bits;
+}
+
+/*
+ * extended beacon time format
+ * time in usec will be changed into a 32-bit value in extended:internal format
+ * the extended part is the beacon counts
+ * the internal part is the time in usec within one beacon interval
+ */
+static u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec,
+                               u32 beacon_interval)
+{
+       u32 quot;
+       u32 rem;
+       u32 interval = beacon_interval * TIME_UNIT;
+
+       if (!interval || !usec)
+               return 0;
+
+       quot = (usec / interval) &
+               (iwl_beacon_time_mask_high(priv, IWLAGN_EXT_BEACON_TIME_POS) >>
+               IWLAGN_EXT_BEACON_TIME_POS);
+       rem = (usec % interval) & iwl_beacon_time_mask_low(priv,
+                                  IWLAGN_EXT_BEACON_TIME_POS);
+
+       return (quot << IWLAGN_EXT_BEACON_TIME_POS) + rem;
+}
+
+/* base is usually what we get from ucode with each received frame,
+ * the same as HW timer counter counting down
+ */
+static __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base,
+                          u32 addon, u32 beacon_interval)
+{
+       u32 base_low = base & iwl_beacon_time_mask_low(priv,
+                               IWLAGN_EXT_BEACON_TIME_POS);
+       u32 addon_low = addon & iwl_beacon_time_mask_low(priv,
+                               IWLAGN_EXT_BEACON_TIME_POS);
+       u32 interval = beacon_interval * TIME_UNIT;
+       u32 res = (base & iwl_beacon_time_mask_high(priv,
+                               IWLAGN_EXT_BEACON_TIME_POS)) +
+                               (addon & iwl_beacon_time_mask_high(priv,
+                               IWLAGN_EXT_BEACON_TIME_POS));
+
+       if (base_low > addon_low)
+               res += base_low - addon_low;
+       else if (base_low < addon_low) {
+               res += interval + base_low - addon_low;
+               res += (1 << IWLAGN_EXT_BEACON_TIME_POS);
+       } else
+               res += (1 << IWLAGN_EXT_BEACON_TIME_POS);
+
+       return cpu_to_le32(res);
+}
+
+static const struct iwl_sensitivity_ranges iwl1000_sensitivity = {
+       .min_nrg_cck = 95,
+       .auto_corr_min_ofdm = 90,
+       .auto_corr_min_ofdm_mrc = 170,
+       .auto_corr_min_ofdm_x1 = 120,
+       .auto_corr_min_ofdm_mrc_x1 = 240,
+
+       .auto_corr_max_ofdm = 120,
+       .auto_corr_max_ofdm_mrc = 210,
+       .auto_corr_max_ofdm_x1 = 155,
+       .auto_corr_max_ofdm_mrc_x1 = 290,
+
+       .auto_corr_min_cck = 125,
+       .auto_corr_max_cck = 200,
+       .auto_corr_min_cck_mrc = 170,
+       .auto_corr_max_cck_mrc = 400,
+       .nrg_th_cck = 95,
+       .nrg_th_ofdm = 95,
+
+       .barker_corr_th_min = 190,
+       .barker_corr_th_min_mrc = 390,
+       .nrg_th_cca = 62,
+};
+
+static void iwl1000_hw_set_hw_params(struct iwl_priv *priv)
+{
+       priv->hw_params.ht40_channel =  BIT(IEEE80211_BAND_2GHZ);
+
+       priv->hw_params.tx_chains_num =
+               num_of_ant(priv->hw_params.valid_tx_ant);
+       if (cfg(priv)->rx_with_siso_diversity)
+               priv->hw_params.rx_chains_num = 1;
+       else
+               priv->hw_params.rx_chains_num =
+                       num_of_ant(priv->hw_params.valid_rx_ant);
+
+       iwl1000_set_ct_threshold(priv);
+
+       /* Set initial sensitivity parameters */
+       priv->hw_params.sens = &iwl1000_sensitivity;
+}
+
+struct iwl_lib_ops iwl1000_lib = {
+       .set_hw_params = iwl1000_hw_set_hw_params,
+       .nic_config = iwl1000_nic_config,
+       .eeprom_ops = {
+               .regulatory_bands = {
+                       EEPROM_REG_BAND_1_CHANNELS,
+                       EEPROM_REG_BAND_2_CHANNELS,
+                       EEPROM_REG_BAND_3_CHANNELS,
+                       EEPROM_REG_BAND_4_CHANNELS,
+                       EEPROM_REG_BAND_5_CHANNELS,
+                       EEPROM_REG_BAND_24_HT40_CHANNELS,
+                       EEPROM_REGULATORY_BAND_NO_HT40,
+               },
+       },
+       .temperature = iwlagn_temperature,
+};
+
+
+/*
+ * 2000 series
+ * ===========
+ */
+
+static void iwl2000_set_ct_threshold(struct iwl_priv *priv)
+{
+       /* want Celsius */
+       priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
+       priv->hw_params.ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD;
+}
+
+/* NIC configuration for 2000 series */
+static void iwl2000_nic_config(struct iwl_priv *priv)
+{
+       iwl_rf_config(priv);
+
+       iwl_set_bit(trans(priv), CSR_GP_DRIVER_REG,
+                   CSR_GP_DRIVER_REG_BIT_RADIO_IQ_INVER);
+}
+
+static const struct iwl_sensitivity_ranges iwl2000_sensitivity = {
+       .min_nrg_cck = 97,
+       .auto_corr_min_ofdm = 80,
+       .auto_corr_min_ofdm_mrc = 128,
+       .auto_corr_min_ofdm_x1 = 105,
+       .auto_corr_min_ofdm_mrc_x1 = 192,
+
+       .auto_corr_max_ofdm = 145,
+       .auto_corr_max_ofdm_mrc = 232,
+       .auto_corr_max_ofdm_x1 = 110,
+       .auto_corr_max_ofdm_mrc_x1 = 232,
+
+       .auto_corr_min_cck = 125,
+       .auto_corr_max_cck = 175,
+       .auto_corr_min_cck_mrc = 160,
+       .auto_corr_max_cck_mrc = 310,
+       .nrg_th_cck = 97,
+       .nrg_th_ofdm = 100,
+
+       .barker_corr_th_min = 190,
+       .barker_corr_th_min_mrc = 390,
+       .nrg_th_cca = 62,
+};
+
+static void iwl2000_hw_set_hw_params(struct iwl_priv *priv)
+{
+       priv->hw_params.ht40_channel =  BIT(IEEE80211_BAND_2GHZ);
+
+       priv->hw_params.tx_chains_num =
+               num_of_ant(priv->hw_params.valid_tx_ant);
+       if (cfg(priv)->rx_with_siso_diversity)
+               priv->hw_params.rx_chains_num = 1;
+       else
+               priv->hw_params.rx_chains_num =
+                       num_of_ant(priv->hw_params.valid_rx_ant);
+
+       iwl2000_set_ct_threshold(priv);
+
+       /* Set initial sensitivity parameters */
+       priv->hw_params.sens = &iwl2000_sensitivity;
+}
+
+struct iwl_lib_ops iwl2000_lib = {
+       .set_hw_params = iwl2000_hw_set_hw_params,
+       .nic_config = iwl2000_nic_config,
+       .eeprom_ops = {
+               .regulatory_bands = {
+                       EEPROM_REG_BAND_1_CHANNELS,
+                       EEPROM_REG_BAND_2_CHANNELS,
+                       EEPROM_REG_BAND_3_CHANNELS,
+                       EEPROM_REG_BAND_4_CHANNELS,
+                       EEPROM_REG_BAND_5_CHANNELS,
+                       EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
+                       EEPROM_REGULATORY_BAND_NO_HT40,
+               },
+               .enhanced_txpower = true,
+       },
+       .temperature = iwlagn_temperature,
+};
+
+struct iwl_lib_ops iwl2030_lib = {
+       .set_hw_params = iwl2000_hw_set_hw_params,
+       .nic_config = iwl2000_nic_config,
+       .eeprom_ops = {
+               .regulatory_bands = {
+                       EEPROM_REG_BAND_1_CHANNELS,
+                       EEPROM_REG_BAND_2_CHANNELS,
+                       EEPROM_REG_BAND_3_CHANNELS,
+                       EEPROM_REG_BAND_4_CHANNELS,
+                       EEPROM_REG_BAND_5_CHANNELS,
+                       EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
+                       EEPROM_REGULATORY_BAND_NO_HT40,
+               },
+               .enhanced_txpower = true,
+       },
+       .temperature = iwlagn_temperature,
+};
+
+/*
+ * 5000 series
+ * ===========
+ */
+
+/* NIC configuration for 5000 series */
+static void iwl5000_nic_config(struct iwl_priv *priv)
+{
+       iwl_rf_config(priv);
+
+       /* W/A : NIC is stuck in a reset state after Early PCIe power off
+        * (PCIe power is lost before PERST# is asserted),
+        * causing ME FW to lose ownership and not being able to obtain it back.
+        */
+       iwl_set_bits_mask_prph(trans(priv), APMG_PS_CTRL_REG,
+                               APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
+                               ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
+}
+
+static const struct iwl_sensitivity_ranges iwl5000_sensitivity = {
+       .min_nrg_cck = 100,
+       .auto_corr_min_ofdm = 90,
+       .auto_corr_min_ofdm_mrc = 170,
+       .auto_corr_min_ofdm_x1 = 105,
+       .auto_corr_min_ofdm_mrc_x1 = 220,
+
+       .auto_corr_max_ofdm = 120,
+       .auto_corr_max_ofdm_mrc = 210,
+       .auto_corr_max_ofdm_x1 = 120,
+       .auto_corr_max_ofdm_mrc_x1 = 240,
+
+       .auto_corr_min_cck = 125,
+       .auto_corr_max_cck = 200,
+       .auto_corr_min_cck_mrc = 200,
+       .auto_corr_max_cck_mrc = 400,
+       .nrg_th_cck = 100,
+       .nrg_th_ofdm = 100,
+
+       .barker_corr_th_min = 190,
+       .barker_corr_th_min_mrc = 390,
+       .nrg_th_cca = 62,
+};
+
+static struct iwl_sensitivity_ranges iwl5150_sensitivity = {
+       .min_nrg_cck = 95,
+       .auto_corr_min_ofdm = 90,
+       .auto_corr_min_ofdm_mrc = 170,
+       .auto_corr_min_ofdm_x1 = 105,
+       .auto_corr_min_ofdm_mrc_x1 = 220,
+
+       .auto_corr_max_ofdm = 120,
+       .auto_corr_max_ofdm_mrc = 210,
+       /* max = min for performance bug in 5150 DSP */
+       .auto_corr_max_ofdm_x1 = 105,
+       .auto_corr_max_ofdm_mrc_x1 = 220,
+
+       .auto_corr_min_cck = 125,
+       .auto_corr_max_cck = 200,
+       .auto_corr_min_cck_mrc = 170,
+       .auto_corr_max_cck_mrc = 400,
+       .nrg_th_cck = 95,
+       .nrg_th_ofdm = 95,
+
+       .barker_corr_th_min = 190,
+       .barker_corr_th_min_mrc = 390,
+       .nrg_th_cca = 62,
+};
+
+#define IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF  (-5)
+
+static s32 iwl_temp_calib_to_offset(struct iwl_priv *priv)
+{
+       u16 temperature, voltage;
+       __le16 *temp_calib = (__le16 *)iwl_eeprom_query_addr(priv,
+                               EEPROM_KELVIN_TEMPERATURE);
+
+       temperature = le16_to_cpu(temp_calib[0]);
+       voltage = le16_to_cpu(temp_calib[1]);
+
+       /* offset = temp - volt / coeff */
+       return (s32)(temperature -
+                       voltage / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF);
+}
+
+static void iwl5150_set_ct_threshold(struct iwl_priv *priv)
+{
+       const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF;
+       s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY) -
+                       iwl_temp_calib_to_offset(priv);
+
+       priv->hw_params.ct_kill_threshold = threshold * volt2temp_coef;
+}
+
+static void iwl5000_set_ct_threshold(struct iwl_priv *priv)
+{
+       /* want Celsius */
+       priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY;
+}
+
+static void iwl5000_hw_set_hw_params(struct iwl_priv *priv)
+{
+       priv->hw_params.ht40_channel =  BIT(IEEE80211_BAND_2GHZ) |
+                                       BIT(IEEE80211_BAND_5GHZ);
+
+       priv->hw_params.tx_chains_num =
+               num_of_ant(priv->hw_params.valid_tx_ant);
+       priv->hw_params.rx_chains_num =
+               num_of_ant(priv->hw_params.valid_rx_ant);
+
+       iwl5000_set_ct_threshold(priv);
+
+       /* Set initial sensitivity parameters */
+       priv->hw_params.sens = &iwl5000_sensitivity;
+}
+
+static void iwl5150_hw_set_hw_params(struct iwl_priv *priv)
+{
+       priv->hw_params.ht40_channel =  BIT(IEEE80211_BAND_2GHZ) |
+                                       BIT(IEEE80211_BAND_5GHZ);
+
+       priv->hw_params.tx_chains_num =
+               num_of_ant(priv->hw_params.valid_tx_ant);
+       priv->hw_params.rx_chains_num =
+               num_of_ant(priv->hw_params.valid_rx_ant);
+
+       iwl5150_set_ct_threshold(priv);
+
+       /* Set initial sensitivity parameters */
+       priv->hw_params.sens = &iwl5150_sensitivity;
+}
+
+static void iwl5150_temperature(struct iwl_priv *priv)
+{
+       u32 vt = 0;
+       s32 offset =  iwl_temp_calib_to_offset(priv);
+
+       vt = le32_to_cpu(priv->statistics.common.temperature);
+       vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
+       /* now vt hold the temperature in Kelvin */
+       priv->temperature = KELVIN_TO_CELSIUS(vt);
+       iwl_tt_handler(priv);
+}
+
+static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
+                                    struct ieee80211_channel_switch *ch_switch)
+{
+       /*
+        * MULTI-FIXME
+        * See iwlagn_mac_channel_switch.
+        */
+       struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
+       struct iwl5000_channel_switch_cmd cmd;
+       const struct iwl_channel_info *ch_info;
+       u32 switch_time_in_usec, ucode_switch_time;
+       u16 ch;
+       u32 tsf_low;
+       u8 switch_count;
+       u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
+       struct ieee80211_vif *vif = ctx->vif;
+       struct iwl_host_cmd hcmd = {
+               .id = REPLY_CHANNEL_SWITCH,
+               .len = { sizeof(cmd), },
+               .flags = CMD_SYNC,
+               .data = { &cmd, },
+       };
+
+       cmd.band = priv->band == IEEE80211_BAND_2GHZ;
+       ch = ch_switch->channel->hw_value;
+       IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
+                     ctx->active.channel, ch);
+       cmd.channel = cpu_to_le16(ch);
+       cmd.rxon_flags = ctx->staging.flags;
+       cmd.rxon_filter_flags = ctx->staging.filter_flags;
+       switch_count = ch_switch->count;
+       tsf_low = ch_switch->timestamp & 0x0ffffffff;
+       /*
+        * calculate the ucode channel switch time
+        * adding TSF as one of the factor for when to switch
+        */
+       if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
+               if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
+                   beacon_interval)) {
+                       switch_count -= (priv->ucode_beacon_time -
+                               tsf_low) / beacon_interval;
+               } else
+                       switch_count = 0;
+       }
+       if (switch_count <= 1)
+               cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
+       else {
+               switch_time_in_usec =
+                       vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
+               ucode_switch_time = iwl_usecs_to_beacons(priv,
+                                                        switch_time_in_usec,
+                                                        beacon_interval);
+               cmd.switch_time = iwl_add_beacon_time(priv,
+                                                     priv->ucode_beacon_time,
+                                                     ucode_switch_time,
+                                                     beacon_interval);
+       }
+       IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
+                     cmd.switch_time);
+       ch_info = iwl_get_channel_info(priv, priv->band, ch);
+       if (ch_info)
+               cmd.expect_beacon = is_channel_radar(ch_info);
+       else {
+               IWL_ERR(priv, "invalid channel switch from %u to %u\n",
+                       ctx->active.channel, ch);
+               return -EFAULT;
+       }
+
+       return iwl_dvm_send_cmd(priv, &hcmd);
+}
+
+struct iwl_lib_ops iwl5000_lib = {
+       .set_hw_params = iwl5000_hw_set_hw_params,
+       .set_channel_switch = iwl5000_hw_channel_switch,
+       .nic_config = iwl5000_nic_config,
+       .eeprom_ops = {
+               .regulatory_bands = {
+                       EEPROM_REG_BAND_1_CHANNELS,
+                       EEPROM_REG_BAND_2_CHANNELS,
+                       EEPROM_REG_BAND_3_CHANNELS,
+                       EEPROM_REG_BAND_4_CHANNELS,
+                       EEPROM_REG_BAND_5_CHANNELS,
+                       EEPROM_REG_BAND_24_HT40_CHANNELS,
+                       EEPROM_REG_BAND_52_HT40_CHANNELS
+               },
+       },
+       .temperature = iwlagn_temperature,
+};
+
+struct iwl_lib_ops iwl5150_lib = {
+       .set_hw_params = iwl5150_hw_set_hw_params,
+       .set_channel_switch = iwl5000_hw_channel_switch,
+       .nic_config = iwl5000_nic_config,
+       .eeprom_ops = {
+               .regulatory_bands = {
+                       EEPROM_REG_BAND_1_CHANNELS,
+                       EEPROM_REG_BAND_2_CHANNELS,
+                       EEPROM_REG_BAND_3_CHANNELS,
+                       EEPROM_REG_BAND_4_CHANNELS,
+                       EEPROM_REG_BAND_5_CHANNELS,
+                       EEPROM_REG_BAND_24_HT40_CHANNELS,
+                       EEPROM_REG_BAND_52_HT40_CHANNELS
+               },
+       },
+       .temperature = iwl5150_temperature,
+};
+
+
+
+/*
+ * 6000 series
+ * ===========
+ */
+
+static void iwl6000_set_ct_threshold(struct iwl_priv *priv)
+{
+       /* want Celsius */
+       priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
+       priv->hw_params.ct_kill_exit_threshold = CT_KILL_EXIT_THRESHOLD;
+}
+
+/* NIC configuration for 6000 series */
+static void iwl6000_nic_config(struct iwl_priv *priv)
+{
+       iwl_rf_config(priv);
+
+       switch (cfg(priv)->device_family) {
+       case IWL_DEVICE_FAMILY_6005:
+       case IWL_DEVICE_FAMILY_6030:
+       case IWL_DEVICE_FAMILY_6000:
+               break;
+       case IWL_DEVICE_FAMILY_6000i:
+               /* 2x2 IPA phy type */
+               iwl_write32(trans(priv), CSR_GP_DRIVER_REG,
+                            CSR_GP_DRIVER_REG_BIT_RADIO_SKU_2x2_IPA);
+               break;
+       case IWL_DEVICE_FAMILY_6050:
+               /* Indicate calibration version to uCode. */
+               if (iwl_eeprom_calib_version(priv) >= 6)
+                       iwl_set_bit(trans(priv), CSR_GP_DRIVER_REG,
+                                       CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6);
+               break;
+       case IWL_DEVICE_FAMILY_6150:
+               /* Indicate calibration version to uCode. */
+               if (iwl_eeprom_calib_version(priv) >= 6)
+                       iwl_set_bit(trans(priv), CSR_GP_DRIVER_REG,
+                                       CSR_GP_DRIVER_REG_BIT_CALIB_VERSION6);
+               iwl_set_bit(trans(priv), CSR_GP_DRIVER_REG,
+                           CSR_GP_DRIVER_REG_BIT_6050_1x2);
+               break;
+       default:
+               WARN_ON(1);
+       }
+}
+
+static const struct iwl_sensitivity_ranges iwl6000_sensitivity = {
+       .min_nrg_cck = 110,
+       .auto_corr_min_ofdm = 80,
+       .auto_corr_min_ofdm_mrc = 128,
+       .auto_corr_min_ofdm_x1 = 105,
+       .auto_corr_min_ofdm_mrc_x1 = 192,
+
+       .auto_corr_max_ofdm = 145,
+       .auto_corr_max_ofdm_mrc = 232,
+       .auto_corr_max_ofdm_x1 = 110,
+       .auto_corr_max_ofdm_mrc_x1 = 232,
+
+       .auto_corr_min_cck = 125,
+       .auto_corr_max_cck = 175,
+       .auto_corr_min_cck_mrc = 160,
+       .auto_corr_max_cck_mrc = 310,
+       .nrg_th_cck = 110,
+       .nrg_th_ofdm = 110,
+
+       .barker_corr_th_min = 190,
+       .barker_corr_th_min_mrc = 336,
+       .nrg_th_cca = 62,
+};
+
+static void iwl6000_hw_set_hw_params(struct iwl_priv *priv)
+{
+       priv->hw_params.ht40_channel =  BIT(IEEE80211_BAND_2GHZ) |
+                                       BIT(IEEE80211_BAND_5GHZ);
+
+       priv->hw_params.tx_chains_num =
+               num_of_ant(priv->hw_params.valid_tx_ant);
+       if (cfg(priv)->rx_with_siso_diversity)
+               priv->hw_params.rx_chains_num = 1;
+       else
+               priv->hw_params.rx_chains_num =
+                       num_of_ant(priv->hw_params.valid_rx_ant);
+
+       iwl6000_set_ct_threshold(priv);
+
+       /* Set initial sensitivity parameters */
+       priv->hw_params.sens = &iwl6000_sensitivity;
+
+}
+
+static int iwl6000_hw_channel_switch(struct iwl_priv *priv,
+                                    struct ieee80211_channel_switch *ch_switch)
+{
+       /*
+        * MULTI-FIXME
+        * See iwlagn_mac_channel_switch.
+        */
+       struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
+       struct iwl6000_channel_switch_cmd cmd;
+       const struct iwl_channel_info *ch_info;
+       u32 switch_time_in_usec, ucode_switch_time;
+       u16 ch;
+       u32 tsf_low;
+       u8 switch_count;
+       u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
+       struct ieee80211_vif *vif = ctx->vif;
+       struct iwl_host_cmd hcmd = {
+               .id = REPLY_CHANNEL_SWITCH,
+               .len = { sizeof(cmd), },
+               .flags = CMD_SYNC,
+               .data = { &cmd, },
+       };
+
+       cmd.band = priv->band == IEEE80211_BAND_2GHZ;
+       ch = ch_switch->channel->hw_value;
+       IWL_DEBUG_11H(priv, "channel switch from %u to %u\n",
+                     ctx->active.channel, ch);
+       cmd.channel = cpu_to_le16(ch);
+       cmd.rxon_flags = ctx->staging.flags;
+       cmd.rxon_filter_flags = ctx->staging.filter_flags;
+       switch_count = ch_switch->count;
+       tsf_low = ch_switch->timestamp & 0x0ffffffff;
+       /*
+        * calculate the ucode channel switch time
+        * adding TSF as one of the factor for when to switch
+        */
+       if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
+               if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
+                   beacon_interval)) {
+                       switch_count -= (priv->ucode_beacon_time -
+                               tsf_low) / beacon_interval;
+               } else
+                       switch_count = 0;
+       }
+       if (switch_count <= 1)
+               cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
+       else {
+               switch_time_in_usec =
+                       vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
+               ucode_switch_time = iwl_usecs_to_beacons(priv,
+                                                        switch_time_in_usec,
+                                                        beacon_interval);
+               cmd.switch_time = iwl_add_beacon_time(priv,
+                                                     priv->ucode_beacon_time,
+                                                     ucode_switch_time,
+                                                     beacon_interval);
+       }
+       IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
+                     cmd.switch_time);
+       ch_info = iwl_get_channel_info(priv, priv->band, ch);
+       if (ch_info)
+               cmd.expect_beacon = is_channel_radar(ch_info);
+       else {
+               IWL_ERR(priv, "invalid channel switch from %u to %u\n",
+                       ctx->active.channel, ch);
+               return -EFAULT;
+       }
+
+       return iwl_dvm_send_cmd(priv, &hcmd);
+}
+
+struct iwl_lib_ops iwl6000_lib = {
+       .set_hw_params = iwl6000_hw_set_hw_params,
+       .set_channel_switch = iwl6000_hw_channel_switch,
+       .nic_config = iwl6000_nic_config,
+       .eeprom_ops = {
+               .regulatory_bands = {
+                       EEPROM_REG_BAND_1_CHANNELS,
+                       EEPROM_REG_BAND_2_CHANNELS,
+                       EEPROM_REG_BAND_3_CHANNELS,
+                       EEPROM_REG_BAND_4_CHANNELS,
+                       EEPROM_REG_BAND_5_CHANNELS,
+                       EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
+                       EEPROM_REG_BAND_52_HT40_CHANNELS
+               },
+               .enhanced_txpower = true,
+       },
+       .temperature = iwlagn_temperature,
+};
+
+struct iwl_lib_ops iwl6030_lib = {
+       .set_hw_params = iwl6000_hw_set_hw_params,
+       .set_channel_switch = iwl6000_hw_channel_switch,
+       .nic_config = iwl6000_nic_config,
+       .eeprom_ops = {
+               .regulatory_bands = {
+                       EEPROM_REG_BAND_1_CHANNELS,
+                       EEPROM_REG_BAND_2_CHANNELS,
+                       EEPROM_REG_BAND_3_CHANNELS,
+                       EEPROM_REG_BAND_4_CHANNELS,
+                       EEPROM_REG_BAND_5_CHANNELS,
+                       EEPROM_6000_REG_BAND_24_HT40_CHANNELS,
+                       EEPROM_REG_BAND_52_HT40_CHANNELS
+               },
+               .enhanced_txpower = true,
+       },
+       .temperature = iwlagn_temperature,
+};
index 4da4ab23cce7f01f55e9ae06ab768892d9944c1a..4e0c248a0050a1bf0ab7737518b8ca27644e1994 100644 (file)
@@ -94,77 +94,13 @@ void iwlagn_temperature(struct iwl_priv *priv)
        iwl_tt_handler(priv);
 }
 
-u16 iwl_eeprom_calib_version(struct iwl_shared *shrd)
-{
-       struct iwl_eeprom_calib_hdr *hdr;
-
-       hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(shrd,
-                                                       EEPROM_CALIB_ALL);
-       return hdr->version;
-
-}
-
-/*
- * EEPROM
- */
-static u32 eeprom_indirect_address(const struct iwl_shared *shrd, u32 address)
-{
-       u16 offset = 0;
-
-       if ((address & INDIRECT_ADDRESS) == 0)
-               return address;
-
-       switch (address & INDIRECT_TYPE_MSK) {
-       case INDIRECT_HOST:
-               offset = iwl_eeprom_query16(shrd, EEPROM_LINK_HOST);
-               break;
-       case INDIRECT_GENERAL:
-               offset = iwl_eeprom_query16(shrd, EEPROM_LINK_GENERAL);
-               break;
-       case INDIRECT_REGULATORY:
-               offset = iwl_eeprom_query16(shrd, EEPROM_LINK_REGULATORY);
-               break;
-       case INDIRECT_TXP_LIMIT:
-               offset = iwl_eeprom_query16(shrd, EEPROM_LINK_TXP_LIMIT);
-               break;
-       case INDIRECT_TXP_LIMIT_SIZE:
-               offset = iwl_eeprom_query16(shrd, EEPROM_LINK_TXP_LIMIT_SIZE);
-               break;
-       case INDIRECT_CALIBRATION:
-               offset = iwl_eeprom_query16(shrd, EEPROM_LINK_CALIBRATION);
-               break;
-       case INDIRECT_PROCESS_ADJST:
-               offset = iwl_eeprom_query16(shrd, EEPROM_LINK_PROCESS_ADJST);
-               break;
-       case INDIRECT_OTHERS:
-               offset = iwl_eeprom_query16(shrd, EEPROM_LINK_OTHERS);
-               break;
-       default:
-               IWL_ERR(shrd->trans, "illegal indirect type: 0x%X\n",
-               address & INDIRECT_TYPE_MSK);
-               break;
-       }
-
-       /* translate the offset from words to byte */
-       return (address & ADDRESS_MSK) + (offset << 1);
-}
-
-const u8 *iwl_eeprom_query_addr(const struct iwl_shared *shrd, size_t offset)
-{
-       u32 address = eeprom_indirect_address(shrd, offset);
-       BUG_ON(address >= shrd->cfg->base_params->eeprom_size);
-       return &shrd->eeprom[address];
-}
-
 struct iwl_mod_params iwlagn_mod_params = {
        .amsdu_size_8K = 1,
        .restart_fw = 1,
        .plcp_check = true,
        .bt_coex_active = true,
-       .no_sleep_autoadjust = true,
        .power_level = IWL_POWER_INDEX_1,
        .bt_ch_announce = true,
-       .wanted_ucode_alternative = 1,
        .auto_agg = true,
        /* the rest are 0 by default */
 };
@@ -234,7 +170,7 @@ int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control)
                                IWL_PAN_SCD_BK_MSK | IWL_PAN_SCD_MGMT_MSK |
                                IWL_PAN_SCD_MULTICAST_MSK;
 
-       if (hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE)
+       if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE)
                flush_cmd.fifo_control |= IWL_AGG_TX_QUEUE_MSK;
 
        IWL_DEBUG_INFO(priv, "fifo queue control: 0X%x\n",
@@ -369,24 +305,30 @@ void iwlagn_send_advance_bt_config(struct iwl_priv *priv)
                .bt3_prio_sample_time = IWLAGN_BT3_PRIO_SAMPLE_DEFAULT,
                .bt3_timer_t2_value = IWLAGN_BT3_T2_DEFAULT,
        };
-       struct iwl6000_bt_cmd bt_cmd_6000;
-       struct iwl2000_bt_cmd bt_cmd_2000;
+       struct iwl_bt_cmd_v1 bt_cmd_v1;
+       struct iwl_bt_cmd_v2 bt_cmd_v2;
        int ret;
 
        BUILD_BUG_ON(sizeof(iwlagn_def_3w_lookup) !=
                        sizeof(basic.bt3_lookup_table));
 
        if (cfg(priv)->bt_params) {
+               /*
+                * newer generation of devices (2000 series and newer)
+                * use the version 2 of the bt command
+                * we need to make sure sending the host command
+                * with correct data structure to avoid uCode assert
+                */
                if (cfg(priv)->bt_params->bt_session_2) {
-                       bt_cmd_2000.prio_boost = cpu_to_le32(
+                       bt_cmd_v2.prio_boost = cpu_to_le32(
                                cfg(priv)->bt_params->bt_prio_boost);
-                       bt_cmd_2000.tx_prio_boost = 0;
-                       bt_cmd_2000.rx_prio_boost = 0;
+                       bt_cmd_v2.tx_prio_boost = 0;
+                       bt_cmd_v2.rx_prio_boost = 0;
                } else {
-                       bt_cmd_6000.prio_boost =
+                       bt_cmd_v1.prio_boost =
                                cfg(priv)->bt_params->bt_prio_boost;
-                       bt_cmd_6000.tx_prio_boost = 0;
-                       bt_cmd_6000.rx_prio_boost = 0;
+                       bt_cmd_v1.tx_prio_boost = 0;
+                       bt_cmd_v1.rx_prio_boost = 0;
                }
        } else {
                IWL_ERR(priv, "failed to construct BT Coex Config\n");
@@ -433,15 +375,15 @@ void iwlagn_send_advance_bt_config(struct iwl_priv *priv)
                       "full concurrency" : "3-wire");
 
        if (cfg(priv)->bt_params->bt_session_2) {
-               memcpy(&bt_cmd_2000.basic, &basic,
+               memcpy(&bt_cmd_v2.basic, &basic,
                        sizeof(basic));
                ret = iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
-                       CMD_SYNC, sizeof(bt_cmd_2000), &bt_cmd_2000);
+                       CMD_SYNC, sizeof(bt_cmd_v2), &bt_cmd_v2);
        } else {
-               memcpy(&bt_cmd_6000.basic, &basic,
+               memcpy(&bt_cmd_v1.basic, &basic,
                        sizeof(basic));
                ret = iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
-                       CMD_SYNC, sizeof(bt_cmd_6000), &bt_cmd_6000);
+                       CMD_SYNC, sizeof(bt_cmd_v1), &bt_cmd_v1);
        }
        if (ret)
                IWL_ERR(priv, "failed to send BT Coex Config\n");
@@ -868,7 +810,7 @@ void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
        if (priv->chain_noise_data.active_chains)
                active_chains = priv->chain_noise_data.active_chains;
        else
-               active_chains = hw_params(priv).valid_rx_ant;
+               active_chains = priv->hw_params.valid_rx_ant;
 
        if (cfg(priv)->bt_params &&
            cfg(priv)->bt_params->advanced_bt_coexist &&
@@ -1300,7 +1242,7 @@ int iwl_dvm_send_cmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
 
        if (test_bit(STATUS_FW_ERROR, &priv->status)) {
                IWL_ERR(priv, "Command %s failed: FW Error\n",
-                       get_cmd_string(cmd->id));
+                       iwl_dvm_get_cmd_string(cmd->id));
                return -EIO;
        }
 
index b936ae7e00a36b9fc59a1bb188c93f0ebd349582..8b13b6cf940ad4c144a44e4eecae3ee67a98f5aa 100644 (file)
@@ -819,7 +819,7 @@ static u32 rs_get_lower_rate(struct iwl_lq_sta *lq_sta,
 
                if (num_of_ant(tbl->ant_type) > 1)
                        tbl->ant_type =
-                           first_antenna(hw_params(priv).valid_tx_ant);
+                           first_antenna(priv->hw_params.valid_tx_ant);
 
                tbl->is_ht40 = 0;
                tbl->is_SGI = 0;
@@ -1291,7 +1291,7 @@ static int rs_switch_to_mimo2(struct iwl_priv *priv,
                return -1;
 
        /* Need both Tx chains/antennas to support MIMO */
-       if (hw_params(priv).tx_chains_num < 2)
+       if (priv->hw_params.tx_chains_num < 2)
                return -1;
 
        IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO2\n");
@@ -1347,7 +1347,7 @@ static int rs_switch_to_mimo3(struct iwl_priv *priv,
                return -1;
 
        /* Need both Tx chains/antennas to support MIMO */
-       if (hw_params(priv).tx_chains_num < 3)
+       if (priv->hw_params.tx_chains_num < 3)
                return -1;
 
        IWL_DEBUG_RATE(priv, "LQ: try to switch to MIMO3\n");
@@ -1446,8 +1446,8 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
        u32 sz = (sizeof(struct iwl_scale_tbl_info) -
                  (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
        u8 start_action;
-       u8 valid_tx_ant = hw_params(priv).valid_tx_ant;
-       u8 tx_chains_num = hw_params(priv).tx_chains_num;
+       u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
+       u8 tx_chains_num = priv->hw_params.tx_chains_num;
        int ret = 0;
        u8 update_search_tbl_counter = 0;
 
@@ -1464,7 +1464,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
        case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
                /* avoid antenna B and MIMO */
                valid_tx_ant =
-                       first_antenna(hw_params(priv).valid_tx_ant);
+                       first_antenna(priv->hw_params.valid_tx_ant);
                if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2 &&
                    tbl->action != IWL_LEGACY_SWITCH_SISO)
                        tbl->action = IWL_LEGACY_SWITCH_SISO;
@@ -1488,7 +1488,7 @@ static int rs_move_legacy_other(struct iwl_priv *priv,
                else if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2)
                        tbl->action = IWL_LEGACY_SWITCH_SISO;
                valid_tx_ant =
-                       first_antenna(hw_params(priv).valid_tx_ant);
+                       first_antenna(priv->hw_params.valid_tx_ant);
        }
 
        start_action = tbl->action;
@@ -1622,8 +1622,8 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
        u32 sz = (sizeof(struct iwl_scale_tbl_info) -
                  (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
        u8 start_action;
-       u8 valid_tx_ant = hw_params(priv).valid_tx_ant;
-       u8 tx_chains_num = hw_params(priv).tx_chains_num;
+       u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
+       u8 tx_chains_num = priv->hw_params.tx_chains_num;
        u8 update_search_tbl_counter = 0;
        int ret;
 
@@ -1640,7 +1640,7 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
        case IWL_BT_COEX_TRAFFIC_LOAD_CONTINUOUS:
                /* avoid antenna B and MIMO */
                valid_tx_ant =
-                       first_antenna(hw_params(priv).valid_tx_ant);
+                       first_antenna(priv->hw_params.valid_tx_ant);
                if (tbl->action != IWL_SISO_SWITCH_ANTENNA1)
                        tbl->action = IWL_SISO_SWITCH_ANTENNA1;
                break;
@@ -1658,7 +1658,7 @@ static int rs_move_siso_to_other(struct iwl_priv *priv,
        /* configure as 1x1 if bt full concurrency */
        if (priv->bt_full_concurrent) {
                valid_tx_ant =
-                       first_antenna(hw_params(priv).valid_tx_ant);
+                       first_antenna(priv->hw_params.valid_tx_ant);
                if (tbl->action >= IWL_LEGACY_SWITCH_ANTENNA2)
                        tbl->action = IWL_SISO_SWITCH_ANTENNA1;
        }
@@ -1794,8 +1794,8 @@ static int rs_move_mimo2_to_other(struct iwl_priv *priv,
        u32 sz = (sizeof(struct iwl_scale_tbl_info) -
                  (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
        u8 start_action;
-       u8 valid_tx_ant = hw_params(priv).valid_tx_ant;
-       u8 tx_chains_num = hw_params(priv).tx_chains_num;
+       u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
+       u8 tx_chains_num = priv->hw_params.tx_chains_num;
        u8 update_search_tbl_counter = 0;
        int ret;
 
@@ -1964,8 +1964,8 @@ static int rs_move_mimo3_to_other(struct iwl_priv *priv,
        u32 sz = (sizeof(struct iwl_scale_tbl_info) -
                  (sizeof(struct iwl_rate_scale_data) * IWL_RATE_COUNT));
        u8 start_action;
-       u8 valid_tx_ant = hw_params(priv).valid_tx_ant;
-       u8 tx_chains_num = hw_params(priv).tx_chains_num;
+       u8 valid_tx_ant = priv->hw_params.valid_tx_ant;
+       u8 tx_chains_num = priv->hw_params.tx_chains_num;
        int ret;
        u8 update_search_tbl_counter = 0;
 
@@ -2698,7 +2698,7 @@ static void rs_initialize_lq(struct iwl_priv *priv,
 
        i = lq_sta->last_txrate_idx;
 
-       valid_tx_ant = hw_params(priv).valid_tx_ant;
+       valid_tx_ant = priv->hw_params.valid_tx_ant;
 
        if (!lq_sta->search_better_tbl)
                active_tbl = lq_sta->active_tbl;
@@ -2826,6 +2826,7 @@ void iwl_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta, u8 sta_i
        struct iwl_station_priv *sta_priv;
        struct iwl_lq_sta *lq_sta;
        struct ieee80211_supported_band *sband;
+       unsigned long supp; /* must be unsigned long for for_each_set_bit */
 
        sta_priv = (struct iwl_station_priv *) sta->drv_priv;
        lq_sta = &sta_priv->lq_sta;
@@ -2855,8 +2856,15 @@ void iwl_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta, u8 sta_i
        lq_sta->max_rate_idx = -1;
        lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX;
        lq_sta->is_green = rs_use_green(sta);
-       lq_sta->active_legacy_rate = priv->active_rate & ~(0x1000);
-       lq_sta->band = priv->band;
+       lq_sta->band = sband->band;
+       /*
+        * active legacy rates as per supported rates bitmap
+        */
+       supp = sta->supp_rates[sband->band];
+       lq_sta->active_legacy_rate = 0;
+       for_each_set_bit(i, &supp, BITS_PER_LONG)
+               lq_sta->active_legacy_rate |= BIT(sband->bitrates[i].hw_value);
+
        /*
         * active_siso_rate mask includes 9 MBits (bit 5), and CCK (bits 0-3),
         * supp_rates[] does not; shift to convert format, force 9 MBits off.
@@ -2884,15 +2892,15 @@ void iwl_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta, u8 sta_i
 
        /* These values will be overridden later */
        lq_sta->lq.general_params.single_stream_ant_msk =
-               first_antenna(hw_params(priv).valid_tx_ant);
+               first_antenna(priv->hw_params.valid_tx_ant);
        lq_sta->lq.general_params.dual_stream_ant_msk =
-               hw_params(priv).valid_tx_ant &
-               ~first_antenna(hw_params(priv).valid_tx_ant);
+               priv->hw_params.valid_tx_ant &
+               ~first_antenna(priv->hw_params.valid_tx_ant);
        if (!lq_sta->lq.general_params.dual_stream_ant_msk) {
                lq_sta->lq.general_params.dual_stream_ant_msk = ANT_AB;
-       } else if (num_of_ant(hw_params(priv).valid_tx_ant) == 2) {
+       } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) {
                lq_sta->lq.general_params.dual_stream_ant_msk =
-                       hw_params(priv).valid_tx_ant;
+                       priv->hw_params.valid_tx_ant;
        }
 
        /* as default allow aggregation for all tids */
@@ -2938,7 +2946,7 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
        if (priv && priv->bt_full_concurrent) {
                /* 1x1 only */
                tbl_type.ant_type =
-                       first_antenna(hw_params(priv).valid_tx_ant);
+                       first_antenna(priv->hw_params.valid_tx_ant);
        }
 
        /* How many times should we repeat the initial rate? */
@@ -2970,7 +2978,7 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
                if (priv->bt_full_concurrent)
                        valid_tx_ant = ANT_A;
                else
-                       valid_tx_ant = hw_params(priv).valid_tx_ant;
+                       valid_tx_ant = priv->hw_params.valid_tx_ant;
        }
 
        /* Fill rest of rate table */
@@ -3004,7 +3012,7 @@ static void rs_fill_link_cmd(struct iwl_priv *priv,
                if (priv && priv->bt_full_concurrent) {
                        /* 1x1 only */
                        tbl_type.ant_type =
-                           first_antenna(hw_params(priv).valid_tx_ant);
+                           first_antenna(priv->hw_params.valid_tx_ant);
                }
 
                /* Indicate to uCode which entries might be MIMO.
@@ -3091,7 +3099,7 @@ static void rs_dbgfs_set_mcs(struct iwl_lq_sta *lq_sta,
        u8 ant_sel_tx;
 
        priv = lq_sta->drv;
-       valid_tx_ant = hw_params(priv).valid_tx_ant;
+       valid_tx_ant = priv->hw_params.valid_tx_ant;
        if (lq_sta->dbg_fixed_rate) {
                ant_sel_tx =
                  ((lq_sta->dbg_fixed_rate & RATE_MCS_ANT_ABC_MSK)
@@ -3162,9 +3170,9 @@ static ssize_t rs_sta_dbgfs_scale_table_read(struct file *file,
        desc += sprintf(buff+desc, "fixed rate 0x%X\n",
                        lq_sta->dbg_fixed_rate);
        desc += sprintf(buff+desc, "valid_tx_ant %s%s%s\n",
-           (hw_params(priv).valid_tx_ant & ANT_A) ? "ANT_A," : "",
-           (hw_params(priv).valid_tx_ant & ANT_B) ? "ANT_B," : "",
-           (hw_params(priv).valid_tx_ant & ANT_C) ? "ANT_C" : "");
+           (priv->hw_params.valid_tx_ant & ANT_A) ? "ANT_A," : "",
+           (priv->hw_params.valid_tx_ant & ANT_B) ? "ANT_B," : "",
+           (priv->hw_params.valid_tx_ant & ANT_C) ? "ANT_C" : "");
        desc += sprintf(buff+desc, "lq type %s\n",
           (is_legacy(tbl->lq_type)) ? "legacy" : "HT");
        if (is_Ht(tbl->lq_type)) {
index e12f11d50b88f72bcf2d87d1cf8dc0f53bd5eb7e..db6c90f6affe4e3c90c923b921b77d66be01f6ea 100644 (file)
 #include "iwl-agn.h"
 #include "iwl-shared.h"
 
-const char *get_cmd_string(u8 cmd)
-{
-       switch (cmd) {
-               IWL_CMD(REPLY_ALIVE);
-               IWL_CMD(REPLY_ERROR);
-               IWL_CMD(REPLY_ECHO);
-               IWL_CMD(REPLY_RXON);
-               IWL_CMD(REPLY_RXON_ASSOC);
-               IWL_CMD(REPLY_QOS_PARAM);
-               IWL_CMD(REPLY_RXON_TIMING);
-               IWL_CMD(REPLY_ADD_STA);
-               IWL_CMD(REPLY_REMOVE_STA);
-               IWL_CMD(REPLY_REMOVE_ALL_STA);
-               IWL_CMD(REPLY_TXFIFO_FLUSH);
-               IWL_CMD(REPLY_WEPKEY);
-               IWL_CMD(REPLY_TX);
-               IWL_CMD(REPLY_LEDS_CMD);
-               IWL_CMD(REPLY_TX_LINK_QUALITY_CMD);
-               IWL_CMD(COEX_PRIORITY_TABLE_CMD);
-               IWL_CMD(COEX_MEDIUM_NOTIFICATION);
-               IWL_CMD(COEX_EVENT_CMD);
-               IWL_CMD(REPLY_QUIET_CMD);
-               IWL_CMD(REPLY_CHANNEL_SWITCH);
-               IWL_CMD(CHANNEL_SWITCH_NOTIFICATION);
-               IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD);
-               IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION);
-               IWL_CMD(POWER_TABLE_CMD);
-               IWL_CMD(PM_SLEEP_NOTIFICATION);
-               IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC);
-               IWL_CMD(REPLY_SCAN_CMD);
-               IWL_CMD(REPLY_SCAN_ABORT_CMD);
-               IWL_CMD(SCAN_START_NOTIFICATION);
-               IWL_CMD(SCAN_RESULTS_NOTIFICATION);
-               IWL_CMD(SCAN_COMPLETE_NOTIFICATION);
-               IWL_CMD(BEACON_NOTIFICATION);
-               IWL_CMD(REPLY_TX_BEACON);
-               IWL_CMD(WHO_IS_AWAKE_NOTIFICATION);
-               IWL_CMD(QUIET_NOTIFICATION);
-               IWL_CMD(REPLY_TX_PWR_TABLE_CMD);
-               IWL_CMD(MEASURE_ABORT_NOTIFICATION);
-               IWL_CMD(REPLY_BT_CONFIG);
-               IWL_CMD(REPLY_STATISTICS_CMD);
-               IWL_CMD(STATISTICS_NOTIFICATION);
-               IWL_CMD(REPLY_CARD_STATE_CMD);
-               IWL_CMD(CARD_STATE_NOTIFICATION);
-               IWL_CMD(MISSED_BEACONS_NOTIFICATION);
-               IWL_CMD(REPLY_CT_KILL_CONFIG_CMD);
-               IWL_CMD(SENSITIVITY_CMD);
-               IWL_CMD(REPLY_PHY_CALIBRATION_CMD);
-               IWL_CMD(REPLY_RX_PHY_CMD);
-               IWL_CMD(REPLY_RX_MPDU_CMD);
-               IWL_CMD(REPLY_RX);
-               IWL_CMD(REPLY_COMPRESSED_BA);
-               IWL_CMD(CALIBRATION_CFG_CMD);
-               IWL_CMD(CALIBRATION_RES_NOTIFICATION);
-               IWL_CMD(CALIBRATION_COMPLETE_NOTIFICATION);
-               IWL_CMD(REPLY_TX_POWER_DBM_CMD);
-               IWL_CMD(TEMPERATURE_NOTIFICATION);
-               IWL_CMD(TX_ANT_CONFIGURATION_CMD);
-               IWL_CMD(REPLY_BT_COEX_PROFILE_NOTIF);
-               IWL_CMD(REPLY_BT_COEX_PRIO_TABLE);
-               IWL_CMD(REPLY_BT_COEX_PROT_ENV);
-               IWL_CMD(REPLY_WIPAN_PARAMS);
-               IWL_CMD(REPLY_WIPAN_RXON);
-               IWL_CMD(REPLY_WIPAN_RXON_TIMING);
-               IWL_CMD(REPLY_WIPAN_RXON_ASSOC);
-               IWL_CMD(REPLY_WIPAN_QOS_PARAM);
-               IWL_CMD(REPLY_WIPAN_WEPKEY);
-               IWL_CMD(REPLY_WIPAN_P2P_CHANNEL_SWITCH);
-               IWL_CMD(REPLY_WIPAN_NOA_NOTIFICATION);
-               IWL_CMD(REPLY_WIPAN_DEACTIVATION_COMPLETE);
-               IWL_CMD(REPLY_WOWLAN_PATTERNS);
-               IWL_CMD(REPLY_WOWLAN_WAKEUP_FILTER);
-               IWL_CMD(REPLY_WOWLAN_TSC_RSC_PARAMS);
-               IWL_CMD(REPLY_WOWLAN_TKIP_PARAMS);
-               IWL_CMD(REPLY_WOWLAN_KEK_KCK_MATERIAL);
-               IWL_CMD(REPLY_WOWLAN_GET_STATUS);
-               IWL_CMD(REPLY_D3_CONFIG);
-       default:
-               return "UNKNOWN";
-
-       }
-}
+#define IWL_CMD_ENTRY(x) [x] = #x
+
+const char *iwl_dvm_cmd_strings[REPLY_MAX] = {
+       IWL_CMD_ENTRY(REPLY_ALIVE),
+       IWL_CMD_ENTRY(REPLY_ERROR),
+       IWL_CMD_ENTRY(REPLY_ECHO),
+       IWL_CMD_ENTRY(REPLY_RXON),
+       IWL_CMD_ENTRY(REPLY_RXON_ASSOC),
+       IWL_CMD_ENTRY(REPLY_QOS_PARAM),
+       IWL_CMD_ENTRY(REPLY_RXON_TIMING),
+       IWL_CMD_ENTRY(REPLY_ADD_STA),
+       IWL_CMD_ENTRY(REPLY_REMOVE_STA),
+       IWL_CMD_ENTRY(REPLY_REMOVE_ALL_STA),
+       IWL_CMD_ENTRY(REPLY_TXFIFO_FLUSH),
+       IWL_CMD_ENTRY(REPLY_WEPKEY),
+       IWL_CMD_ENTRY(REPLY_TX),
+       IWL_CMD_ENTRY(REPLY_LEDS_CMD),
+       IWL_CMD_ENTRY(REPLY_TX_LINK_QUALITY_CMD),
+       IWL_CMD_ENTRY(COEX_PRIORITY_TABLE_CMD),
+       IWL_CMD_ENTRY(COEX_MEDIUM_NOTIFICATION),
+       IWL_CMD_ENTRY(COEX_EVENT_CMD),
+       IWL_CMD_ENTRY(REPLY_QUIET_CMD),
+       IWL_CMD_ENTRY(REPLY_CHANNEL_SWITCH),
+       IWL_CMD_ENTRY(CHANNEL_SWITCH_NOTIFICATION),
+       IWL_CMD_ENTRY(REPLY_SPECTRUM_MEASUREMENT_CMD),
+       IWL_CMD_ENTRY(SPECTRUM_MEASURE_NOTIFICATION),
+       IWL_CMD_ENTRY(POWER_TABLE_CMD),
+       IWL_CMD_ENTRY(PM_SLEEP_NOTIFICATION),
+       IWL_CMD_ENTRY(PM_DEBUG_STATISTIC_NOTIFIC),
+       IWL_CMD_ENTRY(REPLY_SCAN_CMD),
+       IWL_CMD_ENTRY(REPLY_SCAN_ABORT_CMD),
+       IWL_CMD_ENTRY(SCAN_START_NOTIFICATION),
+       IWL_CMD_ENTRY(SCAN_RESULTS_NOTIFICATION),
+       IWL_CMD_ENTRY(SCAN_COMPLETE_NOTIFICATION),
+       IWL_CMD_ENTRY(BEACON_NOTIFICATION),
+       IWL_CMD_ENTRY(REPLY_TX_BEACON),
+       IWL_CMD_ENTRY(WHO_IS_AWAKE_NOTIFICATION),
+       IWL_CMD_ENTRY(QUIET_NOTIFICATION),
+       IWL_CMD_ENTRY(REPLY_TX_PWR_TABLE_CMD),
+       IWL_CMD_ENTRY(MEASURE_ABORT_NOTIFICATION),
+       IWL_CMD_ENTRY(REPLY_BT_CONFIG),
+       IWL_CMD_ENTRY(REPLY_STATISTICS_CMD),
+       IWL_CMD_ENTRY(STATISTICS_NOTIFICATION),
+       IWL_CMD_ENTRY(REPLY_CARD_STATE_CMD),
+       IWL_CMD_ENTRY(CARD_STATE_NOTIFICATION),
+       IWL_CMD_ENTRY(MISSED_BEACONS_NOTIFICATION),
+       IWL_CMD_ENTRY(REPLY_CT_KILL_CONFIG_CMD),
+       IWL_CMD_ENTRY(SENSITIVITY_CMD),
+       IWL_CMD_ENTRY(REPLY_PHY_CALIBRATION_CMD),
+       IWL_CMD_ENTRY(REPLY_RX_PHY_CMD),
+       IWL_CMD_ENTRY(REPLY_RX_MPDU_CMD),
+       IWL_CMD_ENTRY(REPLY_RX),
+       IWL_CMD_ENTRY(REPLY_COMPRESSED_BA),
+       IWL_CMD_ENTRY(CALIBRATION_CFG_CMD),
+       IWL_CMD_ENTRY(CALIBRATION_RES_NOTIFICATION),
+       IWL_CMD_ENTRY(CALIBRATION_COMPLETE_NOTIFICATION),
+       IWL_CMD_ENTRY(REPLY_TX_POWER_DBM_CMD),
+       IWL_CMD_ENTRY(TEMPERATURE_NOTIFICATION),
+       IWL_CMD_ENTRY(TX_ANT_CONFIGURATION_CMD),
+       IWL_CMD_ENTRY(REPLY_BT_COEX_PROFILE_NOTIF),
+       IWL_CMD_ENTRY(REPLY_BT_COEX_PRIO_TABLE),
+       IWL_CMD_ENTRY(REPLY_BT_COEX_PROT_ENV),
+       IWL_CMD_ENTRY(REPLY_WIPAN_PARAMS),
+       IWL_CMD_ENTRY(REPLY_WIPAN_RXON),
+       IWL_CMD_ENTRY(REPLY_WIPAN_RXON_TIMING),
+       IWL_CMD_ENTRY(REPLY_WIPAN_RXON_ASSOC),
+       IWL_CMD_ENTRY(REPLY_WIPAN_QOS_PARAM),
+       IWL_CMD_ENTRY(REPLY_WIPAN_WEPKEY),
+       IWL_CMD_ENTRY(REPLY_WIPAN_P2P_CHANNEL_SWITCH),
+       IWL_CMD_ENTRY(REPLY_WIPAN_NOA_NOTIFICATION),
+       IWL_CMD_ENTRY(REPLY_WIPAN_DEACTIVATION_COMPLETE),
+       IWL_CMD_ENTRY(REPLY_WOWLAN_PATTERNS),
+       IWL_CMD_ENTRY(REPLY_WOWLAN_WAKEUP_FILTER),
+       IWL_CMD_ENTRY(REPLY_WOWLAN_TSC_RSC_PARAMS),
+       IWL_CMD_ENTRY(REPLY_WOWLAN_TKIP_PARAMS),
+       IWL_CMD_ENTRY(REPLY_WOWLAN_KEK_KCK_MATERIAL),
+       IWL_CMD_ENTRY(REPLY_WOWLAN_GET_STATUS),
+       IWL_CMD_ENTRY(REPLY_D3_CONFIG),
+};
+#undef IWL_CMD_ENTRY
 
 /******************************************************************************
  *
@@ -137,10 +134,9 @@ static int iwlagn_rx_reply_error(struct iwl_priv *priv,
        struct iwl_rx_packet *pkt = rxb_addr(rxb);
        struct iwl_error_resp *err_resp = (void *)pkt->data;
 
-       IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
+       IWL_ERR(priv, "Error Reply type 0x%08X cmd REPLY_ERROR (0x%02X) "
                "seq 0x%04X ser 0x%08X\n",
                le32_to_cpu(err_resp->error_type),
-               get_cmd_string(err_resp->cmd_id),
                err_resp->cmd_id,
                le16_to_cpu(err_resp->bad_cmd_seq_num),
                le32_to_cpu(err_resp->error_info));
@@ -216,8 +212,7 @@ static int iwlagn_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
        u32 __maybe_unused len =
                le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
        IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
-                       "notification for %s:\n", len,
-                       get_cmd_string(pkt->hdr.cmd));
+                       "notification for PM_DEBUG_STATISTIC_NOTIFIC:\n", len);
        iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->data, len);
        return 0;
 }
@@ -246,69 +241,6 @@ static int iwlagn_rx_beacon_notif(struct iwl_priv *priv,
        return 0;
 }
 
-/* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */
-#define ACK_CNT_RATIO (50)
-#define BA_TIMEOUT_CNT (5)
-#define BA_TIMEOUT_MAX (16)
-
-/**
- * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries.
- *
- * When the ACK count ratio is low and aggregated BA timeout retries exceeding
- * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal
- * operation state.
- */
-static bool iwlagn_good_ack_health(struct iwl_priv *priv,
-                               struct statistics_tx *cur)
-{
-       int actual_delta, expected_delta, ba_timeout_delta;
-       struct statistics_tx *old;
-
-       if (priv->agg_tids_count)
-               return true;
-
-       lockdep_assert_held(&priv->statistics.lock);
-
-       old = &priv->statistics.tx;
-
-       actual_delta = le32_to_cpu(cur->actual_ack_cnt) -
-                      le32_to_cpu(old->actual_ack_cnt);
-       expected_delta = le32_to_cpu(cur->expected_ack_cnt) -
-                        le32_to_cpu(old->expected_ack_cnt);
-
-       /* Values should not be negative, but we do not trust the firmware */
-       if (actual_delta <= 0 || expected_delta <= 0)
-               return true;
-
-       ba_timeout_delta = le32_to_cpu(cur->agg.ba_timeout) -
-                          le32_to_cpu(old->agg.ba_timeout);
-
-       if ((actual_delta * 100 / expected_delta) < ACK_CNT_RATIO &&
-           ba_timeout_delta > BA_TIMEOUT_CNT) {
-               IWL_DEBUG_RADIO(priv,
-                       "deltas: actual %d expected %d ba_timeout %d\n",
-                       actual_delta, expected_delta, ba_timeout_delta);
-
-#ifdef CONFIG_IWLWIFI_DEBUGFS
-               /*
-                * This is ifdef'ed on DEBUGFS because otherwise the
-                * statistics aren't available. If DEBUGFS is set but
-                * DEBUG is not, these will just compile out.
-                */
-               IWL_DEBUG_RADIO(priv, "rx_detected_cnt delta %d\n",
-                               priv->delta_stats.tx.rx_detected_cnt);
-               IWL_DEBUG_RADIO(priv,
-                               "ack_or_ba_timeout_collision delta %d\n",
-                               priv->delta_stats.tx.ack_or_ba_timeout_collision);
-#endif
-
-               if (ba_timeout_delta >= BA_TIMEOUT_MAX)
-                       return false;
-       }
-
-       return true;
-}
-
 /**
  * iwl_good_plcp_health - checks for plcp error.
  *
@@ -347,6 +279,45 @@ static bool iwlagn_good_plcp_health(struct iwl_priv *priv,
        return true;
 }
 
+int iwl_force_rf_reset(struct iwl_priv *priv, bool external)
+{
+       struct iwl_rf_reset *rf_reset;
+
+       if (test_bit(STATUS_EXIT_PENDING, &priv->status))
+               return -EAGAIN;
+
+       if (!iwl_is_any_associated(priv)) {
+               IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
+               return -ENOLINK;
+       }
+
+       rf_reset = &priv->rf_reset;
+       rf_reset->reset_request_count++;
+       if (!external && rf_reset->last_reset_jiffies &&
+           time_after(rf_reset->last_reset_jiffies +
+                      IWL_DELAY_NEXT_FORCE_RF_RESET, jiffies)) {
+               IWL_DEBUG_INFO(priv, "RF reset rejected\n");
+               rf_reset->reset_reject_count++;
+               return -EAGAIN;
+       }
+       rf_reset->reset_success_count++;
+       rf_reset->last_reset_jiffies = jiffies;
+
+       /*
+        * There is no easy and better way to force reset the radio,
+        * the only known method is switching channel which will force to
+        * reset and tune the radio.
+        * Use internal short scan (single channel) operation to should
+        * achieve this objective.
+        * Driver should reset the radio when number of consecutive missed
+        * beacon, or any other uCode error condition detected.
+        */
+       IWL_DEBUG_INFO(priv, "perform radio reset.\n");
+       iwl_internal_short_hw_scan(priv);
+       return 0;
+}
+
+
 static void iwlagn_recover_from_statistics(struct iwl_priv *priv,
                                struct statistics_rx_phy *cur_ofdm,
                                struct statistics_rx_ht_phy *cur_ofdm_ht,
@@ -368,15 +339,9 @@ static void iwlagn_recover_from_statistics(struct iwl_priv *priv,
        if (msecs < 99)
                return;
 
-       if (iwlagn_mod_params.ack_check && !iwlagn_good_ack_health(priv, tx)) {
-               IWL_ERR(priv, "low ack count detected, restart firmware\n");
-               if (!iwl_force_reset(priv, IWL_FW_RESET, false))
-                       return;
-       }
-
        if (iwlagn_mod_params.plcp_check &&
            !iwlagn_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs))
-               iwl_force_reset(priv, IWL_RF_RESET, false);
+               iwl_force_rf_reset(priv, false);
 }
 
 /* Calculate noise level, based on measurements during network silence just
@@ -589,8 +554,8 @@ static int iwlagn_rx_statistics(struct iwl_priv *priv,
                iwlagn_rx_calc_noise(priv);
                queue_work(priv->workqueue, &priv->run_time_calib_work);
        }
-       if (cfg(priv)->lib->temperature && change)
-               cfg(priv)->lib->temperature(priv);
+       if (priv->lib->temperature && change)
+               priv->lib->temperature(priv);
 
        spin_unlock(&priv->statistics.lock);
 
@@ -1182,9 +1147,9 @@ int iwl_rx_dispatch(struct iwl_op_mode *op_mode, struct iwl_rx_cmd_buffer *rxb,
                        err = priv->rx_handlers[pkt->hdr.cmd] (priv, rxb, cmd);
                } else {
                        /* No handling needed */
-                       IWL_DEBUG_RX(priv,
-                               "No handler needed for %s, 0x%02x\n",
-                               get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
+                       IWL_DEBUG_RX(priv, "No handler needed for %s, 0x%02x\n",
+                                    iwl_dvm_get_cmd_string(pkt->hdr.cmd),
+                                    pkt->hdr.cmd);
                }
        }
        return err;
index 79d857d81b410fc0e0dc3932b7745ab32ce7a373..5c7bddd5cfefb6d78c0f40086ff5b66a4ad36d66 100644 (file)
 #include "iwl-trans.h"
 #include "iwl-shared.h"
 
+/*
+ * initialize rxon structure with default values from eeprom
+ */
+void iwl_connection_init_rx_config(struct iwl_priv *priv,
+                                  struct iwl_rxon_context *ctx)
+{
+       const struct iwl_channel_info *ch_info;
+
+       memset(&ctx->staging, 0, sizeof(ctx->staging));
+
+       if (!ctx->vif) {
+               ctx->staging.dev_type = ctx->unused_devtype;
+       } else
+       switch (ctx->vif->type) {
+       case NL80211_IFTYPE_AP:
+               ctx->staging.dev_type = ctx->ap_devtype;
+               break;
+
+       case NL80211_IFTYPE_STATION:
+               ctx->staging.dev_type = ctx->station_devtype;
+               ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
+               break;
+
+       case NL80211_IFTYPE_ADHOC:
+               ctx->staging.dev_type = ctx->ibss_devtype;
+               ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
+               ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
+                                                 RXON_FILTER_ACCEPT_GRP_MSK;
+               break;
+
+       default:
+               IWL_ERR(priv, "Unsupported interface type %d\n",
+                       ctx->vif->type);
+               break;
+       }
+
+#if 0
+       /* TODO:  Figure out when short_preamble would be set and cache from
+        * that */
+       if (!hw_to_local(priv->hw)->short_preamble)
+               ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
+       else
+               ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
+#endif
+
+       ch_info = iwl_get_channel_info(priv, priv->band,
+                                      le16_to_cpu(ctx->active.channel));
+
+       if (!ch_info)
+               ch_info = &priv->channel_info[0];
+
+       ctx->staging.channel = cpu_to_le16(ch_info->channel);
+       priv->band = ch_info->band;
+
+       iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
+
+       ctx->staging.ofdm_basic_rates =
+           (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
+       ctx->staging.cck_basic_rates =
+           (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
+
+       /* clear both MIX and PURE40 mode flag */
+       ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
+                                       RXON_FLG_CHANNEL_MODE_PURE_40);
+       if (ctx->vif)
+               memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
+
+       ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
+       ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
+       ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
+}
+
 static int iwlagn_disable_bss(struct iwl_priv *priv,
                              struct iwl_rxon_context *ctx,
                              struct iwl_rxon_cmd *send)
@@ -105,8 +177,7 @@ static int iwlagn_disconn_pan(struct iwl_priv *priv,
        return ret;
 }
 
-static void iwlagn_update_qos(struct iwl_priv *priv,
-                             struct iwl_rxon_context *ctx)
+void iwlagn_update_qos(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
 {
        int ret;
 
@@ -133,8 +204,8 @@ static void iwlagn_update_qos(struct iwl_priv *priv,
                IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
 }
 
-static int iwlagn_update_beacon(struct iwl_priv *priv,
-                               struct ieee80211_vif *vif)
+int iwlagn_update_beacon(struct iwl_priv *priv,
+                        struct ieee80211_vif *vif)
 {
        lockdep_assert_held(&priv->mutex);
 
@@ -335,6 +406,64 @@ static int iwlagn_rxon_disconn(struct iwl_priv *priv,
        return 0;
 }
 
+static int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
+{
+       int ret;
+       s8 prev_tx_power;
+       bool defer;
+       struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
+
+       if (priv->calib_disabled & IWL_TX_POWER_CALIB_DISABLED)
+               return 0;
+
+       lockdep_assert_held(&priv->mutex);
+
+       if (priv->tx_power_user_lmt == tx_power && !force)
+               return 0;
+
+       if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
+               IWL_WARN(priv,
+                        "Requested user TXPOWER %d below lower limit %d.\n",
+                        tx_power,
+                        IWLAGN_TX_POWER_TARGET_POWER_MIN);
+               return -EINVAL;
+       }
+
+       if (tx_power > priv->tx_power_device_lmt) {
+               IWL_WARN(priv,
+                       "Requested user TXPOWER %d above upper limit %d.\n",
+                        tx_power, priv->tx_power_device_lmt);
+               return -EINVAL;
+       }
+
+       if (!iwl_is_ready_rf(priv))
+               return -EIO;
+
+       /* scan complete and commit_rxon use tx_power_next value,
+        * it always need to be updated for newest request */
+       priv->tx_power_next = tx_power;
+
+       /* do not set tx power when scanning or channel changing */
+       defer = test_bit(STATUS_SCANNING, &priv->status) ||
+               memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
+       if (defer && !force) {
+               IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
+               return 0;
+       }
+
+       prev_tx_power = priv->tx_power_user_lmt;
+       priv->tx_power_user_lmt = tx_power;
+
+       ret = iwlagn_send_tx_power(priv);
+
+       /* if fail to set tx_power, restore the orig. tx power */
+       if (ret) {
+               priv->tx_power_user_lmt = prev_tx_power;
+               priv->tx_power_next = prev_tx_power;
+       }
+       return ret;
+}
+
 static int iwlagn_rxon_connect(struct iwl_priv *priv,
                               struct iwl_rxon_context *ctx)
 {
@@ -501,6 +630,161 @@ int iwlagn_set_pan_params(struct iwl_priv *priv)
        return ret;
 }
 
+static void _iwl_set_rxon_ht(struct iwl_priv *priv,
+                            struct iwl_ht_config *ht_conf,
+                            struct iwl_rxon_context *ctx)
+{
+       struct iwl_rxon_cmd *rxon = &ctx->staging;
+
+       if (!ctx->ht.enabled) {
+               rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
+                       RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
+                       RXON_FLG_HT40_PROT_MSK |
+                       RXON_FLG_HT_PROT_MSK);
+               return;
+       }
+
+       /* FIXME: if the definition of ht.protection changed, the "translation"
+        * will be needed for rxon->flags
+        */
+       rxon->flags |= cpu_to_le32(ctx->ht.protection <<
+                                  RXON_FLG_HT_OPERATING_MODE_POS);
+
+       /* Set up channel bandwidth:
+        * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
+       /* clear the HT channel mode before set the mode */
+       rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
+                        RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
+       if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
+               /* pure ht40 */
+               if (ctx->ht.protection ==
+                   IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
+                       rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
+                       /*
+                        * Note: control channel is opposite of extension
+                        * channel
+                        */
+                       switch (ctx->ht.extension_chan_offset) {
+                       case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
+                               rxon->flags &=
+                                       ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
+                               break;
+                       case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
+                               rxon->flags |=
+                                       RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
+                               break;
+                       }
+               } else {
+                       /*
+                        * Note: control channel is opposite of extension
+                        * channel
+                        */
+                       switch (ctx->ht.extension_chan_offset) {
+                       case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
+                               rxon->flags &=
+                                       ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
+                               rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
+                               break;
+                       case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
+                               rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
+                               rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
+                               break;
+                       case IEEE80211_HT_PARAM_CHA_SEC_NONE:
+                       default:
+                               /*
+                                * channel location only valid if in Mixed
+                                * mode
+                                */
+                               IWL_ERR(priv,
+                                       "invalid extension channel offset\n");
+                               break;
+                       }
+               }
+       } else {
+               rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
+       }
+
+       iwlagn_set_rxon_chain(priv, ctx);
+
+       IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
+                       "extension channel offset 0x%x\n",
+                       le32_to_cpu(rxon->flags), ctx->ht.protection,
+                       ctx->ht.extension_chan_offset);
+}
+
+void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
+{
+       struct iwl_rxon_context *ctx;
+
+       for_each_context(priv, ctx)
+               _iwl_set_rxon_ht(priv, ht_conf, ctx);
+}
+
+/**
+ * iwl_set_rxon_channel - Set the band and channel values in staging RXON
+ * @ch: requested channel as a pointer to struct ieee80211_channel
+
+ * NOTE:  Does not commit to the hardware; it sets appropriate bit fields
+ * in the staging RXON flag structure based on the ch->band
+ */
+void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
+                        struct iwl_rxon_context *ctx)
+{
+       enum ieee80211_band band = ch->band;
+       u16 channel = ch->hw_value;
+
+       if ((le16_to_cpu(ctx->staging.channel) == channel) &&
+           (priv->band == band))
+               return;
+
+       ctx->staging.channel = cpu_to_le16(channel);
+       if (band == IEEE80211_BAND_5GHZ)
+               ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
+       else
+               ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
+
+       priv->band = band;
+
+       IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
+
+}
+
+void iwl_set_flags_for_band(struct iwl_priv *priv,
+                           struct iwl_rxon_context *ctx,
+                           enum ieee80211_band band,
+                           struct ieee80211_vif *vif)
+{
+       if (band == IEEE80211_BAND_5GHZ) {
+               ctx->staging.flags &=
+                   ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
+                     | RXON_FLG_CCK_MSK);
+               ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
+       } else {
+               /* Copied from iwl_post_associate() */
+               if (vif && vif->bss_conf.use_short_slot)
+                       ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
+               else
+                       ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
+
+               ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
+               ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
+               ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
+       }
+}
+
+void iwl_set_rate(struct iwl_priv *priv)
+{
+       struct iwl_rxon_context *ctx;
+
+       for_each_context(priv, ctx) {
+               ctx->staging.cck_basic_rates =
+                   (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
+
+               ctx->staging.ofdm_basic_rates =
+                  (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
+       }
+}
+
 static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv,
                                  struct iwl_rxon_context *ctx, int hw_decrypt)
 {
@@ -594,8 +878,8 @@ static int iwl_check_rxon_cmd(struct iwl_priv *priv,
  * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  */
-static int iwl_full_rxon_required(struct iwl_priv *priv,
-                                 struct iwl_rxon_context *ctx)
+int iwl_full_rxon_required(struct iwl_priv *priv,
+                          struct iwl_rxon_context *ctx)
 {
        const struct iwl_rxon_cmd *staging = &ctx->staging;
        const struct iwl_rxon_cmd *active = &ctx->active;
@@ -649,6 +933,33 @@ static int iwl_full_rxon_required(struct iwl_priv *priv,
        return 0;
 }
 
+#ifdef CONFIG_IWLWIFI_DEBUG
+void iwl_print_rx_config_cmd(struct iwl_priv *priv,
+                            enum iwl_rxon_context_id ctxid)
+{
+       struct iwl_rxon_context *ctx = &priv->contexts[ctxid];
+       struct iwl_rxon_cmd *rxon = &ctx->staging;
+
+       IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
+       iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
+       IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n",
+                       le16_to_cpu(rxon->channel));
+       IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n",
+                       le32_to_cpu(rxon->flags));
+       IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
+                       le32_to_cpu(rxon->filter_flags));
+       IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
+       IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
+                       rxon->ofdm_basic_rates);
+       IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n",
+                       rxon->cck_basic_rates);
+       IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
+       IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
+       IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n",
+                       le16_to_cpu(rxon->assoc_id));
+}
+#endif
+
 /**
  * iwlagn_commit_rxon - commit staging_rxon to hardware
  *
@@ -692,7 +1003,7 @@ int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
         * force CTS-to-self frames protection if RTS-CTS is not preferred
         * one aggregation protection method
         */
-       if (!hw_params(priv).use_rts_for_aggregation)
+       if (!priv->hw_params.use_rts_for_aggregation)
                ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
 
        if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
@@ -911,9 +1222,9 @@ int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
        return ret;
 }
 
-static void iwlagn_check_needed_chains(struct iwl_priv *priv,
-                                      struct iwl_rxon_context *ctx,
-                                      struct ieee80211_bss_conf *bss_conf)
+void iwlagn_check_needed_chains(struct iwl_priv *priv,
+                               struct iwl_rxon_context *ctx,
+                               struct ieee80211_bss_conf *bss_conf)
 {
        struct ieee80211_vif *vif = ctx->vif;
        struct iwl_rxon_context *tmp;
@@ -1005,11 +1316,14 @@ static void iwlagn_check_needed_chains(struct iwl_priv *priv,
        ht_conf->single_chain_sufficient = !need_multiple;
 }
 
-static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
+void iwlagn_chain_noise_reset(struct iwl_priv *priv)
 {
        struct iwl_chain_noise_data *data = &priv->chain_noise_data;
        int ret;
 
+       if (!(priv->calib_disabled & IWL_CHAIN_NOISE_CALIB_DISABLED))
+               return;
+
        if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
            iwl_is_any_associated(priv)) {
                struct iwl_calib_chain_noise_reset_cmd cmd;
@@ -1162,8 +1476,7 @@ void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
                        iwl_power_update_mode(priv, false);
 
                /* Enable RX differential gain and sensitivity calibrations */
-               if (!priv->disable_chain_noise_cal)
-                       iwlagn_chain_noise_reset(priv);
+               iwlagn_chain_noise_reset(priv);
                priv->start_calib = 1;
        }
 
index c4175603864b24f195cd0aa9dda554783a67a80f..0119e7a7b78df65ac5dcc18bc707d5a9d14e0db7 100644 (file)
@@ -34,6 +34,8 @@
 #include "iwl-agn.h"
 #include "iwl-trans.h"
 
+const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
+
 static int iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id)
 {
        lockdep_assert_held(&priv->sta_lock);
@@ -170,6 +172,50 @@ int iwl_send_add_sta(struct iwl_priv *priv,
        return cmd.handler_status;
 }
 
+static bool iwl_is_channel_extension(struct iwl_priv *priv,
+                                    enum ieee80211_band band,
+                                    u16 channel, u8 extension_chan_offset)
+{
+       const struct iwl_channel_info *ch_info;
+
+       ch_info = iwl_get_channel_info(priv, band, channel);
+       if (!is_channel_valid(ch_info))
+               return false;
+
+       if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
+               return !(ch_info->ht40_extension_channel &
+                                       IEEE80211_CHAN_NO_HT40PLUS);
+       else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
+               return !(ch_info->ht40_extension_channel &
+                                       IEEE80211_CHAN_NO_HT40MINUS);
+
+       return false;
+}
+
+bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
+                           struct iwl_rxon_context *ctx,
+                           struct ieee80211_sta_ht_cap *ht_cap)
+{
+       if (!ctx->ht.enabled || !ctx->ht.is_40mhz)
+               return false;
+
+       /*
+        * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
+        * the bit will not set if it is pure 40MHz case
+        */
+       if (ht_cap && !ht_cap->ht_supported)
+               return false;
+
+#ifdef CONFIG_IWLWIFI_DEBUGFS
+       if (priv->disable_ht40)
+               return false;
+#endif
+
+       return iwl_is_channel_extension(priv, priv->band,
+                       le16_to_cpu(ctx->staging.channel),
+                       ctx->ht.extension_chan_offset);
+}
+
 static void iwl_sta_calc_ht_flags(struct iwl_priv *priv,
                                  struct ieee80211_sta *sta,
                                  struct iwl_rxon_context *ctx,
@@ -581,6 +627,56 @@ void iwl_deactivate_station(struct iwl_priv *priv, const u8 sta_id,
        spin_unlock_bh(&priv->sta_lock);
 }
 
+static void iwl_sta_fill_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
+                           u8 sta_id, struct iwl_link_quality_cmd *link_cmd)
+{
+       int i, r;
+       u32 rate_flags = 0;
+       __le32 rate_n_flags;
+
+       lockdep_assert_held(&priv->mutex);
+
+       memset(link_cmd, 0, sizeof(*link_cmd));
+
+       /* Set up the rate scaling to start at selected rate, fall back
+        * all the way down to 1M in IEEE order, and then spin on 1M */
+       if (priv->band == IEEE80211_BAND_5GHZ)
+               r = IWL_RATE_6M_INDEX;
+       else if (ctx && ctx->vif && ctx->vif->p2p)
+               r = IWL_RATE_6M_INDEX;
+       else
+               r = IWL_RATE_1M_INDEX;
+
+       if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
+               rate_flags |= RATE_MCS_CCK_MSK;
+
+       rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
+                               RATE_MCS_ANT_POS;
+       rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
+       for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
+               link_cmd->rs_table[i].rate_n_flags = rate_n_flags;
+
+       link_cmd->general_params.single_stream_ant_msk =
+                       first_antenna(priv->hw_params.valid_tx_ant);
+
+       link_cmd->general_params.dual_stream_ant_msk =
+               priv->hw_params.valid_tx_ant &
+               ~first_antenna(priv->hw_params.valid_tx_ant);
+       if (!link_cmd->general_params.dual_stream_ant_msk) {
+               link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
+       } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) {
+               link_cmd->general_params.dual_stream_ant_msk =
+                       priv->hw_params.valid_tx_ant;
+       }
+
+       link_cmd->agg_params.agg_dis_start_th =
+               LINK_QUAL_AGG_DISABLE_START_DEF;
+       link_cmd->agg_params.agg_time_limit =
+               cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
+
+       link_cmd->sta_id = sta_id;
+}
+
 /**
  * iwl_clear_ucode_stations - clear ucode station table bits
  *
@@ -841,56 +937,6 @@ int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
 }
 
 
-void iwl_sta_fill_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
-                    u8 sta_id, struct iwl_link_quality_cmd *link_cmd)
-{
-       int i, r;
-       u32 rate_flags = 0;
-       __le32 rate_n_flags;
-
-       lockdep_assert_held(&priv->mutex);
-
-       memset(link_cmd, 0, sizeof(*link_cmd));
-
-       /* Set up the rate scaling to start at selected rate, fall back
-        * all the way down to 1M in IEEE order, and then spin on 1M */
-       if (priv->band == IEEE80211_BAND_5GHZ)
-               r = IWL_RATE_6M_INDEX;
-       else if (ctx && ctx->vif && ctx->vif->p2p)
-               r = IWL_RATE_6M_INDEX;
-       else
-               r = IWL_RATE_1M_INDEX;
-
-       if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
-               rate_flags |= RATE_MCS_CCK_MSK;
-
-       rate_flags |= first_antenna(hw_params(priv).valid_tx_ant) <<
-                               RATE_MCS_ANT_POS;
-       rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
-       for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
-               link_cmd->rs_table[i].rate_n_flags = rate_n_flags;
-
-       link_cmd->general_params.single_stream_ant_msk =
-                       first_antenna(hw_params(priv).valid_tx_ant);
-
-       link_cmd->general_params.dual_stream_ant_msk =
-               hw_params(priv).valid_tx_ant &
-               ~first_antenna(hw_params(priv).valid_tx_ant);
-       if (!link_cmd->general_params.dual_stream_ant_msk) {
-               link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
-       } else if (num_of_ant(hw_params(priv).valid_tx_ant) == 2) {
-               link_cmd->general_params.dual_stream_ant_msk =
-                       hw_params(priv).valid_tx_ant;
-       }
-
-       link_cmd->agg_params.agg_dis_start_th =
-               LINK_QUAL_AGG_DISABLE_START_DEF;
-       link_cmd->agg_params.agg_time_limit =
-               cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
-
-       link_cmd->sta_id = sta_id;
-}
-
 static struct iwl_link_quality_cmd *
 iwl_sta_alloc_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
                 u8 sta_id)
index 697f2032bfd6eae891f1ed144b2558cc13ecb724..ad21b5ddf59d971fc67661d073c178a3c571ebd7 100644 (file)
@@ -208,10 +208,10 @@ static void iwlagn_tx_cmd_build_rate(struct iwl_priv *priv,
             priv->bt_full_concurrent) {
                /* operated as 1x1 in full concurrency mode */
                priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
-                               first_antenna(hw_params(priv).valid_tx_ant));
+                               first_antenna(priv->hw_params.valid_tx_ant));
        } else
                priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
-                                               hw_params(priv).valid_tx_ant);
+                                               priv->hw_params.valid_tx_ant);
        rate_flags |= iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
 
        /* Set the rate in the TX cmd */
@@ -689,7 +689,7 @@ int iwlagn_tx_agg_oper(struct iwl_priv *priv, struct ieee80211_vif *vif,
        sta_priv->max_agg_bufsize =
                min(sta_priv->max_agg_bufsize, buf_size);
 
-       if (hw_params(priv).use_rts_for_aggregation) {
+       if (priv->hw_params.use_rts_for_aggregation) {
                /*
                 * switch to RTS/CTS if it is the prefer protection
                 * method for HT traffic
index 22c953d65be5fdbfb833237bf56d76f821a69469..7db39866bdc455cb900cd2515820246434b1bd86 100644 (file)
@@ -180,7 +180,7 @@ int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
                rate = info->control.rates[0].idx;
 
        priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
-                                             hw_params(priv).valid_tx_ant);
+                                             priv->hw_params.valid_tx_ant);
        rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
 
        /* In mac80211, rates for 5 GHz start at 0 */
@@ -289,6 +289,25 @@ out:
        mutex_unlock(&priv->mutex);
 }
 
+int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
+{
+       struct iwl_statistics_cmd statistics_cmd = {
+               .configuration_flags =
+                       clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
+       };
+
+       if (flags & CMD_ASYNC)
+               return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
+                                       CMD_ASYNC,
+                                       sizeof(struct iwl_statistics_cmd),
+                                       &statistics_cmd);
+       else
+               return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
+                                       CMD_SYNC,
+                                       sizeof(struct iwl_statistics_cmd),
+                                       &statistics_cmd);
+}
+
 /**
  * iwl_bg_statistics_periodic - Timer callback to queue statistics
  *
@@ -578,7 +597,7 @@ static const u8 iwlagn_pan_queue_to_ac[] = {
        IEEE80211_AC_VO,
 };
 
-static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
+void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
 {
        int i;
 
@@ -645,7 +664,7 @@ static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
        BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
 }
 
-static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
+void iwl_rf_kill_ct_config(struct iwl_priv *priv)
 {
        struct iwl_ct_kill_config cmd;
        struct iwl_ct_kill_throttling_config adv_cmd;
@@ -658,9 +677,9 @@ static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
 
        if (cfg(priv)->base_params->support_ct_kill_exit) {
                adv_cmd.critical_temperature_enter =
-                       cpu_to_le32(hw_params(priv).ct_kill_threshold);
+                       cpu_to_le32(priv->hw_params.ct_kill_threshold);
                adv_cmd.critical_temperature_exit =
-                       cpu_to_le32(hw_params(priv).ct_kill_exit_threshold);
+                       cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
 
                ret = iwl_dvm_send_cmd_pdu(priv,
                                       REPLY_CT_KILL_CONFIG_CMD,
@@ -671,11 +690,11 @@ static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
                        IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
                                "succeeded, critical temperature enter is %d,"
                                "exit is %d\n",
-                               hw_params(priv).ct_kill_threshold,
-                               hw_params(priv).ct_kill_exit_threshold);
+                               priv->hw_params.ct_kill_threshold,
+                               priv->hw_params.ct_kill_exit_threshold);
        } else {
                cmd.critical_temperature_R =
-                       cpu_to_le32(hw_params(priv).ct_kill_threshold);
+                       cpu_to_le32(priv->hw_params.ct_kill_threshold);
 
                ret = iwl_dvm_send_cmd_pdu(priv,
                                       REPLY_CT_KILL_CONFIG_CMD,
@@ -686,7 +705,7 @@ static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
                        IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
                                "succeeded, "
                                "critical temperature is %d\n",
-                               hw_params(priv).ct_kill_threshold);
+                               priv->hw_params.ct_kill_threshold);
        }
 }
 
@@ -726,6 +745,29 @@ static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
        }
 }
 
+void iwl_send_bt_config(struct iwl_priv *priv)
+{
+       struct iwl_bt_cmd bt_cmd = {
+               .lead_time = BT_LEAD_TIME_DEF,
+               .max_kill = BT_MAX_KILL_DEF,
+               .kill_ack_mask = 0,
+               .kill_cts_mask = 0,
+       };
+
+       if (!iwlagn_mod_params.bt_coex_active)
+               bt_cmd.flags = BT_COEX_DISABLE;
+       else
+               bt_cmd.flags = BT_COEX_ENABLE;
+
+       priv->bt_enable_flag = bt_cmd.flags;
+       IWL_DEBUG_INFO(priv, "BT coex %s\n",
+               (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
+
+       if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
+                            CMD_SYNC, sizeof(struct iwl_bt_cmd), &bt_cmd))
+               IWL_ERR(priv, "failed to send BT Coex Config\n");
+}
+
 /**
  * iwl_alive_start - called after REPLY_ALIVE notification received
  *                   from protocol/runtime uCode (initialization uCode's
@@ -741,9 +783,6 @@ int iwl_alive_start(struct iwl_priv *priv)
        /* After the ALIVE response, we can send host commands to the uCode */
        set_bit(STATUS_ALIVE, &priv->status);
 
-       /* Enable watchdog to monitor the driver tx queues */
-       iwl_setup_watchdog(priv);
-
        if (iwl_is_rfkill(priv))
                return -ERFKILL;
 
@@ -793,10 +832,8 @@ int iwl_alive_start(struct iwl_priv *priv)
 
        ieee80211_wake_queues(priv->hw);
 
-       priv->active_rate = IWL_RATES_MASK;
-
        /* Configure Tx antenna selection based on H/W config */
-       iwlagn_send_tx_ant_config(priv, hw_params(priv).valid_tx_ant);
+       iwlagn_send_tx_ant_config(priv, priv->hw_params.valid_tx_ant);
 
        if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
                struct iwl_rxon_cmd *active_rxon =
@@ -887,10 +924,6 @@ void iwl_down(struct iwl_priv *priv)
        exit_pending =
                test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
 
-       /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
-        * to prevent rearm timer */
-       del_timer_sync(&priv->watchdog);
-
        iwl_clear_ucode_stations(priv, NULL);
        iwl_dealloc_bcast_stations(priv);
        iwl_clear_driver_stations(priv);
@@ -1067,7 +1100,7 @@ static void iwlagn_disable_roc_work(struct work_struct *work)
  *
  *****************************************************************************/
 
-static void iwl_setup_deferred_work(struct iwl_priv *priv)
+void iwl_setup_deferred_work(struct iwl_priv *priv)
 {
        priv->workqueue = create_singlethread_workqueue(DRV_NAME);
 
@@ -1092,10 +1125,6 @@ static void iwl_setup_deferred_work(struct iwl_priv *priv)
        init_timer(&priv->ucode_trace);
        priv->ucode_trace.data = (unsigned long)priv;
        priv->ucode_trace.function = iwl_bg_ucode_trace;
-
-       init_timer(&priv->watchdog);
-       priv->watchdog.data = (unsigned long)priv;
-       priv->watchdog.function = iwl_bg_watchdog;
 }
 
 void iwl_cancel_deferred_work(struct iwl_priv *priv)
@@ -1143,8 +1172,8 @@ static void iwl_init_ht_hw_capab(const struct iwl_priv *priv,
                              enum ieee80211_band band)
 {
        u16 max_bit_rate = 0;
-       u8 rx_chains_num = hw_params(priv).rx_chains_num;
-       u8 tx_chains_num = hw_params(priv).tx_chains_num;
+       u8 rx_chains_num = priv->hw_params.rx_chains_num;
+       u8 tx_chains_num = priv->hw_params.tx_chains_num;
 
        ht_info->cap = 0;
        memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
@@ -1156,7 +1185,7 @@ static void iwl_init_ht_hw_capab(const struct iwl_priv *priv,
                ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
        ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
        max_bit_rate = MAX_BIT_RATE_20_MHZ;
-       if (hw_params(priv).ht40_channel & BIT(band)) {
+       if (priv->hw_params.ht40_channel & BIT(band)) {
                ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
                ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
                ht_info->mcs.rx_mask[4] = 0x01;
@@ -1228,7 +1257,7 @@ static int iwl_init_geos(struct iwl_priv *priv)
        sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
        sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
 
-       if (hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE)
+       if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE)
                iwl_init_ht_hw_capab(priv, &sband->ht_cap,
                                         IEEE80211_BAND_5GHZ);
 
@@ -1238,7 +1267,7 @@ static int iwl_init_geos(struct iwl_priv *priv)
        sband->bitrates = rates;
        sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
 
-       if (hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE)
+       if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE)
                iwl_init_ht_hw_capab(priv, &sband->ht_cap,
                                         IEEE80211_BAND_2GHZ);
 
@@ -1293,11 +1322,11 @@ static int iwl_init_geos(struct iwl_priv *priv)
        priv->tx_power_next = max_tx_power;
 
        if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
-            hw_params(priv).sku & EEPROM_SKU_CAP_BAND_52GHZ) {
+            priv->hw_params.sku & EEPROM_SKU_CAP_BAND_52GHZ) {
                IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
                        "Please send your %s to maintainer.\n",
                        trans(priv)->hw_id_str);
-               hw_params(priv).sku &= ~EEPROM_SKU_CAP_BAND_52GHZ;
+               priv->hw_params.sku &= ~EEPROM_SKU_CAP_BAND_52GHZ;
        }
 
        IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
@@ -1319,7 +1348,7 @@ static void iwl_free_geos(struct iwl_priv *priv)
        clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
 }
 
-static int iwl_init_drv(struct iwl_priv *priv)
+int iwl_init_drv(struct iwl_priv *priv)
 {
        int ret;
 
@@ -1343,12 +1372,6 @@ static int iwl_init_drv(struct iwl_priv *priv)
 
        priv->ucode_owner = IWL_OWNERSHIP_DRIVER;
 
-       /* initialize force reset */
-       priv->force_reset[IWL_RF_RESET].reset_duration =
-               IWL_DELAY_NEXT_FORCE_RF_RESET;
-       priv->force_reset[IWL_FW_RESET].reset_duration =
-               IWL_DELAY_NEXT_FORCE_FW_RELOAD;
-
        priv->rx_statistics_jiffies = jiffies;
 
        /* Choose which receivers/antennas to use */
@@ -1388,7 +1411,7 @@ err:
        return ret;
 }
 
-static void iwl_uninit_drv(struct iwl_priv *priv)
+void iwl_uninit_drv(struct iwl_priv *priv)
 {
        iwl_free_geos(priv);
        iwl_free_channel_map(priv);
@@ -1401,35 +1424,22 @@ static void iwl_uninit_drv(struct iwl_priv *priv)
 #endif
 }
 
-/* Size of one Rx buffer in host DRAM */
-#define IWL_RX_BUF_SIZE_4K (4 * 1024)
-#define IWL_RX_BUF_SIZE_8K (8 * 1024)
-
-static void iwl_set_hw_params(struct iwl_priv *priv)
+void iwl_set_hw_params(struct iwl_priv *priv)
 {
        if (cfg(priv)->ht_params)
-               hw_params(priv).use_rts_for_aggregation =
+               priv->hw_params.use_rts_for_aggregation =
                        cfg(priv)->ht_params->use_rts_for_aggregation;
 
-       if (iwlagn_mod_params.amsdu_size_8K)
-               hw_params(priv).rx_page_order =
-                       get_order(IWL_RX_BUF_SIZE_8K);
-       else
-               hw_params(priv).rx_page_order =
-                       get_order(IWL_RX_BUF_SIZE_4K);
-
        if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
-               hw_params(priv).sku &= ~EEPROM_SKU_CAP_11N_ENABLE;
-
-       hw_params(priv).wd_timeout = cfg(priv)->base_params->wd_timeout;
+               priv->hw_params.sku &= ~EEPROM_SKU_CAP_11N_ENABLE;
 
        /* Device-specific setup */
-       cfg(priv)->lib->set_hw_params(priv);
+       priv->lib->set_hw_params(priv);
 }
 
 
 
-static void iwl_debug_config(struct iwl_priv *priv)
+void iwl_debug_config(struct iwl_priv *priv)
 {
        dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEBUG "
 #ifdef CONFIG_IWLWIFI_DEBUG
@@ -1501,6 +1511,42 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
        priv->shrd = trans->shrd;
        priv->fw = fw;
 
+       switch (cfg(priv)->device_family) {
+       case IWL_DEVICE_FAMILY_1000:
+       case IWL_DEVICE_FAMILY_100:
+               priv->lib = &iwl1000_lib;
+               break;
+       case IWL_DEVICE_FAMILY_2000:
+       case IWL_DEVICE_FAMILY_105:
+               priv->lib = &iwl2000_lib;
+               break;
+       case IWL_DEVICE_FAMILY_2030:
+       case IWL_DEVICE_FAMILY_135:
+               priv->lib = &iwl2030_lib;
+               break;
+       case IWL_DEVICE_FAMILY_5000:
+               priv->lib = &iwl5000_lib;
+               break;
+       case IWL_DEVICE_FAMILY_5150:
+               priv->lib = &iwl5150_lib;
+               break;
+       case IWL_DEVICE_FAMILY_6000:
+       case IWL_DEVICE_FAMILY_6005:
+       case IWL_DEVICE_FAMILY_6000i:
+       case IWL_DEVICE_FAMILY_6050:
+       case IWL_DEVICE_FAMILY_6150:
+               priv->lib = &iwl6000_lib;
+               break;
+       case IWL_DEVICE_FAMILY_6030:
+               priv->lib = &iwl6030_lib;
+               break;
+       default:
+               break;
+       }
+
+       if (WARN_ON(!priv->lib))
+               goto out_free_traffic_mem;
+
        /*
         * Populate the state variables that the transport layer needs
         * to know about.
@@ -1508,11 +1554,18 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
        trans_cfg.op_mode = op_mode;
        trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
        trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
+       trans_cfg.rx_buf_size_8k = iwlagn_mod_params.amsdu_size_8K;
+       if (!iwlagn_mod_params.wd_disable)
+               trans_cfg.queue_watchdog_timeout =
+                       cfg(priv)->base_params->wd_timeout;
+       else
+               trans_cfg.queue_watchdog_timeout = IWL_WATCHHDOG_DISABLED;
+       trans_cfg.command_names = iwl_dvm_cmd_strings;
 
        ucode_flags = fw->ucode_capa.flags;
 
 #ifndef CONFIG_IWLWIFI_P2P
-       ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
+       ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
 #endif
 
        if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
@@ -1574,11 +1627,8 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
        if (iwl_trans_start_hw(trans(priv)))
                goto out_free_traffic_mem;
 
-       /*****************
-        * 3. Read EEPROM
-        *****************/
        /* Read the EEPROM */
-       if (iwl_eeprom_init(trans(priv), trans(priv)->hw_rev)) {
+       if (iwl_eeprom_init(priv, trans(priv)->hw_rev)) {
                IWL_ERR(priv, "Unable to init EEPROM\n");
                goto out_free_traffic_mem;
        }
@@ -1592,11 +1642,11 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
                goto out_free_eeprom;
 
        /* extract MAC Address */
-       iwl_eeprom_get_mac(priv->shrd, priv->addresses[0].addr);
+       iwl_eeprom_get_mac(priv, priv->addresses[0].addr);
        IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
        priv->hw->wiphy->addresses = priv->addresses;
        priv->hw->wiphy->n_addresses = 1;
-       num_mac = iwl_eeprom_query16(priv->shrd, EEPROM_NUM_MAC_ADDRESS);
+       num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS);
        if (num_mac > 1) {
                memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
                       ETH_ALEN);
@@ -1609,7 +1659,7 @@ static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
         ************************/
        iwl_set_hw_params(priv);
 
-       if (!(hw_params(priv).sku & EEPROM_SKU_CAP_IPAN_ENABLE)) {
+       if (!(priv->hw_params.sku & EEPROM_SKU_CAP_IPAN_ENABLE)) {
                IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN");
                ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
                /*
@@ -1694,7 +1744,7 @@ out_destroy_workqueue:
        priv->workqueue = NULL;
        iwl_uninit_drv(priv);
 out_free_eeprom:
-       iwl_eeprom_free(priv->shrd);
+       iwl_eeprom_free(priv);
 out_free_traffic_mem:
        iwl_free_traffic_mem(priv);
        ieee80211_free_hw(priv->hw);
@@ -1703,7 +1753,7 @@ out:
        return op_mode;
 }
 
-static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
+void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
 {
        struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
 
@@ -1720,7 +1770,7 @@ static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
        priv->ucode_loaded = false;
        iwl_trans_stop_device(trans(priv));
 
-       iwl_eeprom_free(priv->shrd);
+       iwl_eeprom_free(priv);
 
        /*netif_stop_queue(dev); */
        flush_workqueue(priv->workqueue);
@@ -1838,7 +1888,7 @@ static void iwl_dump_nic_error_log(struct iwl_priv *priv)
        if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
                IWL_ERR(trans, "Start IWL Error Log Dump:\n");
                IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
-                       priv->shrd->status, table.valid);
+                       priv->status, table.valid);
        }
 
        trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
@@ -2112,7 +2162,63 @@ int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
        return pos;
 }
 
-static void iwl_nic_error(struct iwl_op_mode *op_mode)
+static void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
+{
+       unsigned int reload_msec;
+       unsigned long reload_jiffies;
+
+#ifdef CONFIG_IWLWIFI_DEBUG
+       if (iwl_have_debug_level(IWL_DL_FW_ERRORS))
+               iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS);
+#endif
+
+       /* uCode is no longer loaded. */
+       priv->ucode_loaded = false;
+
+       /* Set the FW error flag -- cleared on iwl_down */
+       set_bit(STATUS_FW_ERROR, &priv->status);
+
+       iwl_abort_notification_waits(&priv->notif_wait);
+
+       /* Keep the restart process from trying to send host
+        * commands by clearing the ready bit */
+       clear_bit(STATUS_READY, &priv->status);
+
+       wake_up(&trans(priv)->wait_command_queue);
+
+       if (!ondemand) {
+               /*
+                * If firmware keep reloading, then it indicate something
+                * serious wrong and firmware having problem to recover
+                * from it. Instead of keep trying which will fill the syslog
+                * and hang the system, let's just stop it
+                */
+               reload_jiffies = jiffies;
+               reload_msec = jiffies_to_msecs((long) reload_jiffies -
+                                       (long) priv->reload_jiffies);
+               priv->reload_jiffies = reload_jiffies;
+               if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
+                       priv->reload_count++;
+                       if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
+                               IWL_ERR(priv, "BUG_ON, Stop restarting\n");
+                               return;
+                       }
+               } else
+                       priv->reload_count = 0;
+       }
+
+       if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
+               if (iwlagn_mod_params.restart_fw) {
+                       IWL_DEBUG_FW_ERRORS(priv,
+                                 "Restarting adapter due to uCode error.\n");
+                       queue_work(priv->workqueue, &priv->restart);
+               } else
+                       IWL_DEBUG_FW_ERRORS(priv,
+                                 "Detected FW error, but not restarting\n");
+       }
+}
+
+void iwl_nic_error(struct iwl_op_mode *op_mode)
 {
        struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
 
@@ -2125,7 +2231,7 @@ static void iwl_nic_error(struct iwl_op_mode *op_mode)
        iwlagn_fw_error(priv, false);
 }
 
-static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
+void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
 {
        struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
 
@@ -2135,14 +2241,22 @@ static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
        }
 }
 
-static void iwl_nic_config(struct iwl_op_mode *op_mode)
+void iwl_nic_config(struct iwl_op_mode *op_mode)
 {
        struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
 
-       cfg(priv)->lib->nic_config(priv);
+       priv->lib->nic_config(priv);
 }
 
-static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
+static void iwl_wimax_active(struct iwl_op_mode *op_mode)
+{
+       struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
+
+       clear_bit(STATUS_READY, &priv->status);
+       IWL_ERR(priv, "RF is used by WiMAX\n");
+}
+
+void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
 {
        struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
        int ac = priv->queue_to_ac[queue];
@@ -2161,7 +2275,7 @@ static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
        ieee80211_stop_queue(priv->hw, ac);
 }
 
-static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
+void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
 {
        struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
        int ac = priv->queue_to_ac[queue];
@@ -2201,6 +2315,27 @@ void iwlagn_lift_passive_no_rx(struct iwl_priv *priv)
        priv->passive_no_rx = false;
 }
 
+void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
+{
+       struct ieee80211_tx_info *info;
+
+       info = IEEE80211_SKB_CB(skb);
+       kmem_cache_free(iwl_tx_cmd_pool, (info->driver_data[1]));
+       dev_kfree_skb_any(skb);
+}
+
+void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
+{
+       struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
+
+       if (state)
+               set_bit(STATUS_RF_KILL_HW, &priv->status);
+       else
+               clear_bit(STATUS_RF_KILL_HW, &priv->status);
+
+       wiphy_rfkill_set_hw_state(priv->hw->wiphy, state);
+}
+
 const struct iwl_op_mode_ops iwl_dvm_ops = {
        .start = iwl_op_mode_dvm_start,
        .stop = iwl_op_mode_dvm_stop,
@@ -2212,6 +2347,7 @@ const struct iwl_op_mode_ops iwl_dvm_ops = {
        .nic_error = iwl_nic_error,
        .cmd_queue_full = iwl_cmd_queue_full,
        .nic_config = iwl_nic_config,
+       .wimax_active = iwl_wimax_active,
 };
 
 /*****************************************************************************
@@ -2280,12 +2416,6 @@ MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
 module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
 MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
 
-module_param_named(ucode_alternative,
-                  iwlagn_mod_params.wanted_ucode_alternative,
-                  int, S_IRUGO);
-MODULE_PARM_DESC(ucode_alternative,
-                "specify ucode alternative to use from ucode file");
-
 module_param_named(antenna_coupling, iwlagn_mod_params.ant_coupling,
                   int, S_IRUGO);
 MODULE_PARM_DESC(antenna_coupling,
@@ -2299,9 +2429,6 @@ MODULE_PARM_DESC(bt_ch_inhibition,
 module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
 MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
 
-module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
-MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");
-
 module_param_named(wd_disable, iwlagn_mod_params.wd_disable, int, S_IRUGO);
 MODULE_PARM_DESC(wd_disable,
                "Disable stuck queue watchdog timer 0=system default, "
@@ -2345,13 +2472,3 @@ module_param_named(auto_agg, iwlagn_mod_params.auto_agg,
                bool, S_IRUGO);
 MODULE_PARM_DESC(auto_agg,
                 "enable agg w/o check traffic load (default: enable)");
-
-/*
- * For now, keep using power level 1 instead of automatically
- * adjusting ...
- */
-module_param_named(no_sleep_autoadjust, iwlagn_mod_params.no_sleep_autoadjust,
-               bool, S_IRUGO);
-MODULE_PARM_DESC(no_sleep_autoadjust,
-                "don't automatically adjust sleep level "
-                "according to maximum network latency (default: true)");
index 51001622430b3238e865e773e0527e3019be7394..20100c72ec6b20b64ea2f527c464438c319feaa8 100644 (file)
 /* AUX (TX during scan dwell) queue */
 #define IWL_AUX_QUEUE          10
 
+/* device operations */
+extern struct iwl_lib_ops iwl1000_lib;
+extern struct iwl_lib_ops iwl2000_lib;
+extern struct iwl_lib_ops iwl2030_lib;
+extern struct iwl_lib_ops iwl5000_lib;
+extern struct iwl_lib_ops iwl5150_lib;
+extern struct iwl_lib_ops iwl6000_lib;
+extern struct iwl_lib_ops iwl6030_lib;
+
+
+
+/*****************************************************
+* DRIVER STATUS FUNCTIONS
+******************************************************/
+#define STATUS_RF_KILL_HW      0
+#define STATUS_CT_KILL         1
+#define STATUS_ALIVE           2
+#define STATUS_READY           3
+#define STATUS_GEO_CONFIGURED  4
+#define STATUS_EXIT_PENDING    5
+#define STATUS_STATISTICS      6
+#define STATUS_SCANNING                7
+#define STATUS_SCAN_ABORTING   8
+#define STATUS_SCAN_HW         9
+#define STATUS_FW_ERROR                10
+#define STATUS_CHANNEL_SWITCH_PENDING 11
+#define STATUS_SCAN_COMPLETE   12
+#define STATUS_POWER_PMI       13
 
 struct iwl_ucode_capabilities;
 
@@ -87,11 +115,9 @@ static inline void iwl_set_calib_hdr(struct iwl_calib_hdr *hdr, u8 cmd)
 void iwl_down(struct iwl_priv *priv);
 void iwl_cancel_deferred_work(struct iwl_priv *priv);
 void iwlagn_prepare_restart(struct iwl_priv *priv);
-void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb);
 int __must_check iwl_rx_dispatch(struct iwl_op_mode *op_mode,
                                 struct iwl_rx_cmd_buffer *rxb,
                                 struct iwl_device_cmd *cmd);
-void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state);
 
 bool iwl_check_for_ct_kill(struct iwl_priv *priv);
 
@@ -109,6 +135,8 @@ int iwl_dvm_send_cmd_pdu(struct iwl_priv *priv, u8 id,
                         u32 flags, u16 len, const void *data);
 
 /* RXON */
+void iwl_connection_init_rx_config(struct iwl_priv *priv,
+                                  struct iwl_rxon_context *ctx);
 int iwlagn_set_pan_params(struct iwl_priv *priv);
 int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
 void iwlagn_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
@@ -119,6 +147,14 @@ void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
                             u32 changes);
 void iwlagn_config_ht40(struct ieee80211_conf *conf,
                        struct iwl_rxon_context *ctx);
+void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf);
+void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
+                        struct iwl_rxon_context *ctx);
+void iwl_set_flags_for_band(struct iwl_priv *priv,
+                           struct iwl_rxon_context *ctx,
+                           enum ieee80211_band band,
+                           struct ieee80211_vif *vif);
+void iwl_set_rate(struct iwl_priv *priv);
 
 /* uCode */
 int iwl_send_bt_env(struct iwl_priv *priv, u8 action, u8 type);
@@ -131,17 +167,25 @@ int iwl_send_calib_results(struct iwl_priv *priv);
 int iwl_calib_set(struct iwl_priv *priv,
                  const struct iwl_calib_hdr *cmd, int len);
 void iwl_calib_free_results(struct iwl_priv *priv);
-void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand);
 int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
                            char **buf, bool display);
+int iwlagn_hw_valid_rtc_data_addr(u32 addr);
 
 /* lib */
 int iwlagn_send_tx_power(struct iwl_priv *priv);
 void iwlagn_temperature(struct iwl_priv *priv);
-u16 iwl_eeprom_calib_version(struct iwl_shared *shrd);
 int iwlagn_txfifo_flush(struct iwl_priv *priv, u16 flush_control);
 void iwlagn_dev_txfifo_flush(struct iwl_priv *priv, u16 flush_control);
 int iwlagn_send_beacon_cmd(struct iwl_priv *priv);
+int iwl_send_statistics_request(struct iwl_priv *priv,
+                               u8 flags, bool clear);
+
+static inline const struct ieee80211_supported_band *iwl_get_hw_mode(
+                       struct iwl_priv *priv, enum ieee80211_band band)
+{
+       return priv->hw->wiphy->bands[band];
+}
+
 #ifdef CONFIG_PM_SLEEP
 int iwlagn_send_patterns(struct iwl_priv *priv,
                         struct cfg80211_wowlan *wowlan);
@@ -151,6 +195,7 @@ int iwlagn_suspend(struct iwl_priv *priv, struct cfg80211_wowlan *wowlan);
 /* rx */
 int iwlagn_hwrate_to_mac80211_idx(u32 rate_n_flags, enum ieee80211_band band);
 void iwl_setup_rx_handlers(struct iwl_priv *priv);
+void iwl_chswitch_done(struct iwl_priv *priv, bool is_success);
 
 
 /* tx */
@@ -195,6 +240,31 @@ u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant_idx, u8 valid);
 /* scan */
 void iwlagn_post_scan(struct iwl_priv *priv);
 void iwlagn_disable_roc(struct iwl_priv *priv);
+int iwl_force_rf_reset(struct iwl_priv *priv, bool external);
+void iwl_init_scan_params(struct iwl_priv *priv);
+int iwl_scan_cancel(struct iwl_priv *priv);
+void iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms);
+void iwl_force_scan_end(struct iwl_priv *priv);
+void iwl_internal_short_hw_scan(struct iwl_priv *priv);
+void iwl_setup_rx_scan_handlers(struct iwl_priv *priv);
+void iwl_setup_scan_deferred_work(struct iwl_priv *priv);
+void iwl_cancel_scan_deferred_work(struct iwl_priv *priv);
+int __must_check iwl_scan_initiate(struct iwl_priv *priv,
+                                  struct ieee80211_vif *vif,
+                                  enum iwl_scan_type scan_type,
+                                  enum ieee80211_band band);
+
+/* For faster active scanning, scan will move to the next channel if fewer than
+ * PLCP_QUIET_THRESH packets are heard on this channel within
+ * ACTIVE_QUIET_TIME after sending probe request.  This shortens the dwell
+ * time if it's a quiet channel (nothing responded to our probe, and there's
+ * no other traffic).
+ * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
+#define IWL_ACTIVE_QUIET_TIME       cpu_to_le16(10)  /* msec */
+#define IWL_PLCP_QUIET_THRESH       cpu_to_le16(1)  /* packets */
+
+#define IWL_SCAN_CHECK_WATCHDOG                (HZ * 7)
+
 
 /* bt coex */
 void iwlagn_send_advance_bt_config(struct iwl_priv *priv);
@@ -207,6 +277,12 @@ void iwlagn_bt_cancel_deferred_work(struct iwl_priv *priv);
 void iwlagn_bt_coex_rssi_monitor(struct iwl_priv *priv);
 void iwlagn_bt_adjust_rssi_monitor(struct iwl_priv *priv, bool rssi_ena);
 
+static inline bool iwl_advanced_bt_coexist(struct iwl_priv *priv)
+{
+       return cfg(priv)->bt_params &&
+              cfg(priv)->bt_params->advanced_bt_coexist;
+}
+
 #ifdef CONFIG_IWLWIFI_DEBUG
 const char *iwl_get_tx_fail_reason(u32 status);
 const char *iwl_get_agg_tx_fail_reason(u16 status);
@@ -245,8 +321,6 @@ void iwl_deactivate_station(struct iwl_priv *priv, const u8 sta_id,
 u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
                    const u8 *addr, bool is_ap, struct ieee80211_sta *sta);
 
-void iwl_sta_fill_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
-                    u8 sta_id, struct iwl_link_quality_cmd *link_cmd);
 int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
                    struct iwl_link_quality_cmd *lq, u8 flags, bool init);
 int iwl_add_sta_callback(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb,
@@ -254,6 +328,9 @@ int iwl_add_sta_callback(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb,
 int iwl_sta_update_ht(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
                      struct ieee80211_sta *sta);
 
+bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
+                           struct iwl_rxon_context *ctx,
+                           struct ieee80211_sta_ht_cap *ht_cap);
 
 static inline int iwl_sta_id(struct ieee80211_sta *sta)
 {
@@ -311,9 +388,6 @@ static inline __le32 iwl_hw_set_rate_n_flags(u8 rate, u32 flags)
        return cpu_to_le32(flags|(u32)rate);
 }
 
-/* eeprom */
-void iwl_eeprom_get_mac(const struct iwl_shared *shrd, u8 *mac);
-
 extern int iwl_alive_start(struct iwl_priv *priv);
 /* svtool */
 #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
@@ -421,4 +495,95 @@ do {                                                                       \
 } while (0)
 #endif                         /* CONFIG_IWLWIFI_DEBUG */
 
+extern const char *iwl_dvm_cmd_strings[REPLY_MAX];
+
+static inline const char *iwl_dvm_get_cmd_string(u8 cmd)
+{
+       const char *s = iwl_dvm_cmd_strings[cmd];
+       if (s)
+               return s;
+       return "UNKNOWN";
+}
+
+/* API method exported for mvm hybrid state */
+void iwl_setup_deferred_work(struct iwl_priv *priv);
+int iwl_send_wimax_coex(struct iwl_priv *priv);
+int iwl_send_bt_env(struct iwl_priv *priv, u8 action, u8 type);
+void iwl_debug_config(struct iwl_priv *priv);
+int iwl_alloc_traffic_mem(struct iwl_priv *priv);
+void iwl_set_hw_params(struct iwl_priv *priv);
+void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags);
+int iwl_init_drv(struct iwl_priv *priv);
+void iwl_uninit_drv(struct iwl_priv *priv);
+void iwl_send_bt_config(struct iwl_priv *priv);
+void iwl_rf_kill_ct_config(struct iwl_priv *priv);
+int iwl_setup_interface(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
+void iwl_teardown_interface(struct iwl_priv *priv,
+                           struct ieee80211_vif *vif,
+                           bool mode_change);
+int iwl_full_rxon_required(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
+void iwlagn_update_qos(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
+void iwlagn_check_needed_chains(struct iwl_priv *priv,
+                               struct iwl_rxon_context *ctx,
+                               struct ieee80211_bss_conf *bss_conf);
+void iwlagn_chain_noise_reset(struct iwl_priv *priv);
+int iwlagn_update_beacon(struct iwl_priv *priv,
+                        struct ieee80211_vif *vif);
+void iwl_tt_handler(struct iwl_priv *priv);
+void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode);
+void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue);
+void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state);
+void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb);
+void iwl_nic_error(struct iwl_op_mode *op_mode);
+void iwl_cmd_queue_full(struct iwl_op_mode *op_mode);
+void iwl_nic_config(struct iwl_op_mode *op_mode);
+int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
+                      struct ieee80211_sta *sta, bool set);
+void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
+                             enum ieee80211_rssi_event rssi_event);
+int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw);
+int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw);
+void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop);
+void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue);
+void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
+                              struct ieee80211_channel_switch *ch_switch);
+int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
+                        struct ieee80211_vif *vif,
+                        struct ieee80211_sta *sta,
+                        enum ieee80211_sta_state old_state,
+                        enum ieee80211_sta_state new_state);
+int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
+                           struct ieee80211_vif *vif,
+                           enum ieee80211_ampdu_mlme_action action,
+                           struct ieee80211_sta *sta, u16 tid, u16 *ssn,
+                           u8 buf_size);
+int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
+                      struct ieee80211_vif *vif,
+                      struct cfg80211_scan_request *req);
+void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
+                          struct ieee80211_vif *vif,
+                          enum sta_notify_cmd cmd,
+                          struct ieee80211_sta *sta);
+void iwlagn_configure_filter(struct ieee80211_hw *hw,
+                            unsigned int changed_flags,
+                            unsigned int *total_flags,
+                            u64 multicast);
+int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
+                      struct ieee80211_vif *vif, u16 queue,
+                      const struct ieee80211_tx_queue_params *params);
+void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
+                              struct ieee80211_vif *vif,
+                              struct cfg80211_gtk_rekey_data *data);
+void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
+                               struct ieee80211_vif *vif,
+                               struct ieee80211_key_conf *keyconf,
+                               struct ieee80211_sta *sta,
+                               u32 iv32, u16 *phase1key);
+int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
+                      struct ieee80211_vif *vif,
+                      struct ieee80211_sta *sta,
+                      struct ieee80211_key_conf *key);
+void iwlagn_mac_stop(struct ieee80211_hw *hw);
+void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
+int iwlagn_mac_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan);
 #endif /* __iwl_agn_h__ */
index 9ed73e5154be908a18662fb9493292233594e0d8..296347a8290fe659da9d3913e5d7d6880f0d8448 100644 (file)
@@ -1918,7 +1918,7 @@ struct iwl_basic_bt_cmd {
        __le16 valid;
 };
 
-struct iwl6000_bt_cmd {
+struct iwl_bt_cmd_v1 {
        struct iwl_basic_bt_cmd basic;
        u8 prio_boost;
        /*
@@ -1929,7 +1929,7 @@ struct iwl6000_bt_cmd {
        __le16 rx_prio_boost;   /* SW boost of WiFi rx priority */
 };
 
-struct iwl2000_bt_cmd {
+struct iwl_bt_cmd_v2 {
        struct iwl_basic_bt_cmd basic;
        __le32 prio_boost;
        /*
diff --git a/drivers/net/wireless/iwlwifi/iwl-config.h b/drivers/net/wireless/iwlwifi/iwl-config.h
new file mode 100644 (file)
index 0000000..47bfd5e
--- /dev/null
@@ -0,0 +1,227 @@
+/******************************************************************************
+ *
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2007 - 2012 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
+ * USA
+ *
+ * The full GNU General Public License is included in this distribution
+ * in the file called LICENSE.GPL.
+ *
+ * Contact Information:
+ *  Intel Linux Wireless <ilw@linux.intel.com>
+ * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2005 - 2012 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  * Neither the name Intel Corporation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *****************************************************************************/
+#ifndef __IWL_CONFIG_H__
+#define __IWL_CONFIG_H__
+
+#include <linux/types.h>
+#include <net/mac80211.h>
+
+
+enum iwl_device_family {
+       IWL_DEVICE_FAMILY_UNDEFINED,
+       IWL_DEVICE_FAMILY_1000,
+       IWL_DEVICE_FAMILY_100,
+       IWL_DEVICE_FAMILY_2000,
+       IWL_DEVICE_FAMILY_2030,
+       IWL_DEVICE_FAMILY_105,
+       IWL_DEVICE_FAMILY_135,
+       IWL_DEVICE_FAMILY_5000,
+       IWL_DEVICE_FAMILY_5150,
+       IWL_DEVICE_FAMILY_6000,
+       IWL_DEVICE_FAMILY_6000i,
+       IWL_DEVICE_FAMILY_6005,
+       IWL_DEVICE_FAMILY_6030,
+       IWL_DEVICE_FAMILY_6050,
+       IWL_DEVICE_FAMILY_6150,
+};
+
+/*
+ * LED mode
+ *    IWL_LED_DEFAULT:  use device default
+ *    IWL_LED_RF_STATE: turn LED on/off based on RF state
+ *                     LED ON  = RF ON
+ *                     LED OFF = RF OFF
+ *    IWL_LED_BLINK:    adjust led blink rate based on blink table
+ *    IWL_LED_DISABLE: led disabled
+ */
+enum iwl_led_mode {
+       IWL_LED_DEFAULT,
+       IWL_LED_RF_STATE,
+       IWL_LED_BLINK,
+       IWL_LED_DISABLE,
+};
+
+/*
+ * @max_ll_items: max number of OTP blocks
+ * @shadow_ram_support: shadow support for OTP memory
+ * @led_compensation: compensate on the led on/off time per HW according
+ *     to the deviation to achieve the desired led frequency.
+ *     The detail algorithm is described in iwl-led.c
+ * @chain_noise_num_beacons: number of beacons used to compute chain noise
+ * @adv_thermal_throttle: support advance thermal throttle
+ * @support_ct_kill_exit: support ct kill exit condition
+ * @plcp_delta_threshold: plcp error rate threshold used to trigger
+ *     radio tuning when there is a high receiving plcp error rate
+ * @chain_noise_scale: default chain noise scale used for gain computation
+ * @wd_timeout: TX queues watchdog timeout
+ * @max_event_log_size: size of event log buffer size for ucode event logging
+ * @shadow_reg_enable: HW shadhow register bit
+ * @hd_v2: v2 of enhanced sensitivity value, used for 2000 series and up
+ * @no_idle_support: do not support idle mode
+ */
+struct iwl_base_params {
+       int eeprom_size;
+       int num_of_queues;      /* def: HW dependent */
+       /* for iwl_apm_init() */
+       u32 pll_cfg_val;
+
+       const u16 max_ll_items;
+       const bool shadow_ram_support;
+       u16 led_compensation;
+       bool adv_thermal_throttle;
+       bool support_ct_kill_exit;
+       u8 plcp_delta_threshold;
+       s32 chain_noise_scale;
+       unsigned int wd_timeout;
+       u32 max_event_log_size;
+       const bool shadow_reg_enable;
+       const bool hd_v2;
+       const bool no_idle_support;
+};
+
+/*
+ * @advanced_bt_coexist: support advanced bt coexist
+ * @bt_init_traffic_load: specify initial bt traffic load
+ * @bt_prio_boost: default bt priority boost value
+ * @agg_time_limit: maximum number of uSec in aggregation
+ * @bt_sco_disable: uCode should not response to BT in SCO/ESCO mode
+ */
+struct iwl_bt_params {
+       bool advanced_bt_coexist;
+       u8 bt_init_traffic_load;
+       u8 bt_prio_boost;
+       u16 agg_time_limit;
+       bool bt_sco_disable;
+       bool bt_session_2;
+};
+/*
+ * @use_rts_for_aggregation: use rts/cts protection for HT traffic
+ */
+struct iwl_ht_params {
+       const bool ht_greenfield_support; /* if used set to true */
+       bool use_rts_for_aggregation;
+       enum ieee80211_smps_mode smps_mode;
+};
+
+/**
+ * struct iwl_cfg
+ * @name: Offical name of the device
+ * @fw_name_pre: Firmware filename prefix. The api version and extension
+ *     (.ucode) will be added to filename before loading from disk. The
+ *     filename is constructed as fw_name_pre<api>.ucode.
+ * @ucode_api_max: Highest version of uCode API supported by driver.
+ * @ucode_api_ok: oldest version of the uCode API that is OK to load
+ *     without a warning, for use in transitions
+ * @ucode_api_min: Lowest version of uCode API supported by driver.
+ * @max_inst_size: The maximal length of the fw inst section
+ * @max_data_size: The maximal length of the fw data section
+ * @valid_tx_ant: valid transmit antenna
+ * @valid_rx_ant: valid receive antenna
+ * @eeprom_ver: EEPROM version
+ * @eeprom_calib_ver: EEPROM calibration version
+ * @lib: pointer to the lib ops
+ * @base_params: pointer to basic parameters
+ * @ht_params: point to ht patameters
+ * @bt_params: pointer to bt parameters
+ * @need_temp_offset_calib: need to perform temperature offset calibration
+ * @no_xtal_calib: some devices do not need crystal calibration data,
+ *     don't send it to those
+ * @led_mode: 0=blinking, 1=On(RF On)/Off(RF Off)
+ * @adv_pm: advance power management
+ * @rx_with_siso_diversity: 1x1 device with rx antenna diversity
+ * @internal_wimax_coex: internal wifi/wimax combo device
+ * @temp_offset_v2: support v2 of temperature offset calibration
+ *
+ * We enable the driver to be backward compatible wrt. hardware features.
+ * API differences in uCode shouldn't be handled here but through TLVs
+ * and/or the uCode API version instead.
+ */
+struct iwl_cfg {
+       /* params specific to an individual device within a device family */
+       const char *name;
+       const char *fw_name_pre;
+       const unsigned int ucode_api_max;
+       const unsigned int ucode_api_ok;
+       const unsigned int ucode_api_min;
+       const enum iwl_device_family device_family;
+       const u32 max_data_size;
+       const u32 max_inst_size;
+       u8   valid_tx_ant;
+       u8   valid_rx_ant;
+       u16  eeprom_ver;
+       u16  eeprom_calib_ver;
+       /* params not likely to change within a device family */
+       const struct iwl_base_params *base_params;
+       /* params likely to change within a device family */
+       const struct iwl_ht_params *ht_params;
+       const struct iwl_bt_params *bt_params;
+       const bool need_temp_offset_calib; /* if used set to true */
+       const bool no_xtal_calib;
+       enum iwl_led_mode led_mode;
+       const bool adv_pm;
+       const bool rx_with_siso_diversity;
+       const bool internal_wimax_coex;
+       const bool temp_offset_v2;
+};
+
+#endif /* __IWL_CONFIG_H__ */
index 88ea31d9eb758ef611048fd2c6cc7651379fa793..d7a8cde249ff48191fff6c9c325ec096747a7de7 100644 (file)
 #include "iwl-agn.h"
 #include "iwl-trans.h"
 
-const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
-
-static bool iwl_is_channel_extension(struct iwl_priv *priv,
-                                    enum ieee80211_band band,
-                                    u16 channel, u8 extension_chan_offset)
-{
-       const struct iwl_channel_info *ch_info;
-
-       ch_info = iwl_get_channel_info(priv, band, channel);
-       if (!is_channel_valid(ch_info))
-               return false;
-
-       if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
-               return !(ch_info->ht40_extension_channel &
-                                       IEEE80211_CHAN_NO_HT40PLUS);
-       else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
-               return !(ch_info->ht40_extension_channel &
-                                       IEEE80211_CHAN_NO_HT40MINUS);
-
-       return false;
-}
-
-bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
-                           struct iwl_rxon_context *ctx,
-                           struct ieee80211_sta_ht_cap *ht_cap)
-{
-       if (!ctx->ht.enabled || !ctx->ht.is_40mhz)
-               return false;
-
-       /*
-        * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
-        * the bit will not set if it is pure 40MHz case
-        */
-       if (ht_cap && !ht_cap->ht_supported)
-               return false;
-
-#ifdef CONFIG_IWLWIFI_DEBUGFS
-       if (priv->disable_ht40)
-               return false;
-#endif
-
-       return iwl_is_channel_extension(priv, priv->band,
-                       le16_to_cpu(ctx->staging.channel),
-                       ctx->ht.extension_chan_offset);
-}
-
-static void _iwl_set_rxon_ht(struct iwl_priv *priv,
-                            struct iwl_ht_config *ht_conf,
-                            struct iwl_rxon_context *ctx)
-{
-       struct iwl_rxon_cmd *rxon = &ctx->staging;
-
-       if (!ctx->ht.enabled) {
-               rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
-                       RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
-                       RXON_FLG_HT40_PROT_MSK |
-                       RXON_FLG_HT_PROT_MSK);
-               return;
-       }
-
-       /* FIXME: if the definition of ht.protection changed, the "translation"
-        * will be needed for rxon->flags
-        */
-       rxon->flags |= cpu_to_le32(ctx->ht.protection << RXON_FLG_HT_OPERATING_MODE_POS);
-
-       /* Set up channel bandwidth:
-        * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
-       /* clear the HT channel mode before set the mode */
-       rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
-                        RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
-       if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
-               /* pure ht40 */
-               if (ctx->ht.protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
-                       rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
-                       /* Note: control channel is opposite of extension channel */
-                       switch (ctx->ht.extension_chan_offset) {
-                       case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
-                               rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
-                               break;
-                       case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
-                               rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
-                               break;
-                       }
-               } else {
-                       /* Note: control channel is opposite of extension channel */
-                       switch (ctx->ht.extension_chan_offset) {
-                       case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
-                               rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
-                               rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
-                               break;
-                       case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
-                               rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
-                               rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
-                               break;
-                       case IEEE80211_HT_PARAM_CHA_SEC_NONE:
-                       default:
-                               /* channel location only valid if in Mixed mode */
-                               IWL_ERR(priv, "invalid extension channel offset\n");
-                               break;
-                       }
-               }
-       } else {
-               rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
-       }
-
-       iwlagn_set_rxon_chain(priv, ctx);
-
-       IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
-                       "extension channel offset 0x%x\n",
-                       le32_to_cpu(rxon->flags), ctx->ht.protection,
-                       ctx->ht.extension_chan_offset);
-}
-
-void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
-{
-       struct iwl_rxon_context *ctx;
-
-       for_each_context(priv, ctx)
-               _iwl_set_rxon_ht(priv, ht_conf, ctx);
-}
-
-/**
- * iwl_set_rxon_channel - Set the band and channel values in staging RXON
- * @ch: requested channel as a pointer to struct ieee80211_channel
-
- * NOTE:  Does not commit to the hardware; it sets appropriate bit fields
- * in the staging RXON flag structure based on the ch->band
- */
-void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
-                        struct iwl_rxon_context *ctx)
-{
-       enum ieee80211_band band = ch->band;
-       u16 channel = ch->hw_value;
-
-       if ((le16_to_cpu(ctx->staging.channel) == channel) &&
-           (priv->band == band))
-               return;
-
-       ctx->staging.channel = cpu_to_le16(channel);
-       if (band == IEEE80211_BAND_5GHZ)
-               ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
-       else
-               ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
-
-       priv->band = band;
-
-       IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
-
-}
-
-void iwl_set_flags_for_band(struct iwl_priv *priv,
-                           struct iwl_rxon_context *ctx,
-                           enum ieee80211_band band,
-                           struct ieee80211_vif *vif)
-{
-       if (band == IEEE80211_BAND_5GHZ) {
-               ctx->staging.flags &=
-                   ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
-                     | RXON_FLG_CCK_MSK);
-               ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
-       } else {
-               /* Copied from iwl_post_associate() */
-               if (vif && vif->bss_conf.use_short_slot)
-                       ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
-               else
-                       ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
-
-               ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
-               ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
-               ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
-       }
-}
-
-/*
- * initialize rxon structure with default values from eeprom
- */
-void iwl_connection_init_rx_config(struct iwl_priv *priv,
-                                  struct iwl_rxon_context *ctx)
-{
-       const struct iwl_channel_info *ch_info;
-
-       memset(&ctx->staging, 0, sizeof(ctx->staging));
-
-       if (!ctx->vif) {
-               ctx->staging.dev_type = ctx->unused_devtype;
-       } else switch (ctx->vif->type) {
-       case NL80211_IFTYPE_AP:
-               ctx->staging.dev_type = ctx->ap_devtype;
-               break;
-
-       case NL80211_IFTYPE_STATION:
-               ctx->staging.dev_type = ctx->station_devtype;
-               ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
-               break;
-
-       case NL80211_IFTYPE_ADHOC:
-               ctx->staging.dev_type = ctx->ibss_devtype;
-               ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
-               ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
-                                                 RXON_FILTER_ACCEPT_GRP_MSK;
-               break;
-
-       default:
-               IWL_ERR(priv, "Unsupported interface type %d\n",
-                       ctx->vif->type);
-               break;
-       }
-
-#if 0
-       /* TODO:  Figure out when short_preamble would be set and cache from
-        * that */
-       if (!hw_to_local(priv->hw)->short_preamble)
-               ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
-       else
-               ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
-#endif
-
-       ch_info = iwl_get_channel_info(priv, priv->band,
-                                      le16_to_cpu(ctx->active.channel));
-
-       if (!ch_info)
-               ch_info = &priv->channel_info[0];
-
-       ctx->staging.channel = cpu_to_le16(ch_info->channel);
-       priv->band = ch_info->band;
-
-       iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
-
-       ctx->staging.ofdm_basic_rates =
-           (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
-       ctx->staging.cck_basic_rates =
-           (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
-
-       /* clear both MIX and PURE40 mode flag */
-       ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
-                                       RXON_FLG_CHANNEL_MODE_PURE_40);
-       if (ctx->vif)
-               memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
-
-       ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
-       ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
-       ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
-}
-
-void iwl_set_rate(struct iwl_priv *priv)
-{
-       const struct ieee80211_supported_band *hw = NULL;
-       struct ieee80211_rate *rate;
-       struct iwl_rxon_context *ctx;
-       int i;
-
-       hw = iwl_get_hw_mode(priv, priv->band);
-       if (!hw) {
-               IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
-               return;
-       }
-
-       priv->active_rate = 0;
-
-       for (i = 0; i < hw->n_bitrates; i++) {
-               rate = &(hw->bitrates[i]);
-               if (rate->hw_value < IWL_RATE_COUNT_LEGACY)
-                       priv->active_rate |= (1 << rate->hw_value);
-       }
-
-       IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate);
-
-       for_each_context(priv, ctx) {
-               ctx->staging.cck_basic_rates =
-                   (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
-
-               ctx->staging.ofdm_basic_rates =
-                  (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
-       }
-}
-
-void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
-{
-       /*
-        * MULTI-FIXME
-        * See iwlagn_mac_channel_switch.
-        */
-       struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
-
-       if (test_bit(STATUS_EXIT_PENDING, &priv->status))
-               return;
-
-       if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
-               ieee80211_chswitch_done(ctx->vif, is_success);
-}
-
-#ifdef CONFIG_IWLWIFI_DEBUG
-void iwl_print_rx_config_cmd(struct iwl_priv *priv,
-                            enum iwl_rxon_context_id ctxid)
-{
-       struct iwl_rxon_context *ctx = &priv->contexts[ctxid];
-       struct iwl_rxon_cmd *rxon = &ctx->staging;
-
-       IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
-       iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
-       IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
-       IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
-       IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
-                       le32_to_cpu(rxon->filter_flags));
-       IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
-       IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
-                       rxon->ofdm_basic_rates);
-       IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
-       IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
-       IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
-       IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
-}
-#endif
-
-void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
-{
-       unsigned int reload_msec;
-       unsigned long reload_jiffies;
-
-#ifdef CONFIG_IWLWIFI_DEBUG
-       if (iwl_have_debug_level(IWL_DL_FW_ERRORS))
-               iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS);
-#endif
-
-       /* uCode is no longer loaded. */
-       priv->ucode_loaded = false;
-
-       /* Set the FW error flag -- cleared on iwl_down */
-       set_bit(STATUS_FW_ERROR, &priv->status);
-
-       /* Cancel currently queued command. */
-       clear_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status);
-
-       iwl_abort_notification_waits(&priv->notif_wait);
-
-       /* Keep the restart process from trying to send host
-        * commands by clearing the ready bit */
-       clear_bit(STATUS_READY, &priv->status);
-
-       wake_up(&trans(priv)->wait_command_queue);
-
-       if (!ondemand) {
-               /*
-                * If firmware keep reloading, then it indicate something
-                * serious wrong and firmware having problem to recover
-                * from it. Instead of keep trying which will fill the syslog
-                * and hang the system, let's just stop it
-                */
-               reload_jiffies = jiffies;
-               reload_msec = jiffies_to_msecs((long) reload_jiffies -
-                                       (long) priv->reload_jiffies);
-               priv->reload_jiffies = reload_jiffies;
-               if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
-                       priv->reload_count++;
-                       if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
-                               IWL_ERR(priv, "BUG_ON, Stop restarting\n");
-                               return;
-                       }
-               } else
-                       priv->reload_count = 0;
-       }
-
-       if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
-               if (iwlagn_mod_params.restart_fw) {
-                       IWL_DEBUG_FW_ERRORS(priv,
-                                 "Restarting adapter due to uCode error.\n");
-                       queue_work(priv->workqueue, &priv->restart);
-               } else
-                       IWL_DEBUG_FW_ERRORS(priv,
-                                 "Detected FW error, but not restarting\n");
-       }
-}
-
-int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
-{
-       int ret;
-       s8 prev_tx_power;
-       bool defer;
-       struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
-
-       lockdep_assert_held(&priv->mutex);
-
-       if (priv->tx_power_user_lmt == tx_power && !force)
-               return 0;
-
-       if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
-               IWL_WARN(priv,
-                        "Requested user TXPOWER %d below lower limit %d.\n",
-                        tx_power,
-                        IWLAGN_TX_POWER_TARGET_POWER_MIN);
-               return -EINVAL;
-       }
-
-       if (tx_power > priv->tx_power_device_lmt) {
-               IWL_WARN(priv,
-                       "Requested user TXPOWER %d above upper limit %d.\n",
-                        tx_power, priv->tx_power_device_lmt);
-               return -EINVAL;
-       }
-
-       if (!iwl_is_ready_rf(priv))
-               return -EIO;
-
-       /* scan complete and commit_rxon use tx_power_next value,
-        * it always need to be updated for newest request */
-       priv->tx_power_next = tx_power;
-
-       /* do not set tx power when scanning or channel changing */
-       defer = test_bit(STATUS_SCANNING, &priv->status) ||
-               memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
-       if (defer && !force) {
-               IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
-               return 0;
-       }
-
-       prev_tx_power = priv->tx_power_user_lmt;
-       priv->tx_power_user_lmt = tx_power;
-
-       ret = iwlagn_send_tx_power(priv);
-
-       /* if fail to set tx_power, restore the orig. tx power */
-       if (ret) {
-               priv->tx_power_user_lmt = prev_tx_power;
-               priv->tx_power_next = prev_tx_power;
-       }
-       return ret;
-}
-
-void iwl_send_bt_config(struct iwl_priv *priv)
-{
-       struct iwl_bt_cmd bt_cmd = {
-               .lead_time = BT_LEAD_TIME_DEF,
-               .max_kill = BT_MAX_KILL_DEF,
-               .kill_ack_mask = 0,
-               .kill_cts_mask = 0,
-       };
-
-       if (!iwlagn_mod_params.bt_coex_active)
-               bt_cmd.flags = BT_COEX_DISABLE;
-       else
-               bt_cmd.flags = BT_COEX_ENABLE;
-
-       priv->bt_enable_flag = bt_cmd.flags;
-       IWL_DEBUG_INFO(priv, "BT coex %s\n",
-               (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
-
-       if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
-                            CMD_SYNC, sizeof(struct iwl_bt_cmd), &bt_cmd))
-               IWL_ERR(priv, "failed to send BT Coex Config\n");
-}
-
-int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
-{
-       struct iwl_statistics_cmd statistics_cmd = {
-               .configuration_flags =
-                       clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
-       };
-
-       if (flags & CMD_ASYNC)
-               return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
-                                             CMD_ASYNC,
-                                              sizeof(struct iwl_statistics_cmd),
-                                              &statistics_cmd);
-       else
-               return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
-                                       CMD_SYNC,
-                                       sizeof(struct iwl_statistics_cmd),
-                                       &statistics_cmd);
-}
-
-
 
 
 #ifdef CONFIG_IWLWIFI_DEBUGFS
@@ -611,6 +140,7 @@ void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
 
 const char *get_mgmt_string(int cmd)
 {
+#define IWL_CMD(x) case x: return #x
        switch (cmd) {
                IWL_CMD(MANAGEMENT_ASSOC_REQ);
                IWL_CMD(MANAGEMENT_ASSOC_RESP);
@@ -628,10 +158,12 @@ const char *get_mgmt_string(int cmd)
                return "UNKNOWN";
 
        }
+#undef IWL_CMD
 }
 
 const char *get_ctrl_string(int cmd)
 {
+#define IWL_CMD(x) case x: return #x
        switch (cmd) {
                IWL_CMD(CONTROL_BACK_REQ);
                IWL_CMD(CONTROL_BACK);
@@ -645,6 +177,7 @@ const char *get_ctrl_string(int cmd)
                return "UNKNOWN";
 
        }
+#undef IWL_CMD
 }
 
 void iwl_clear_traffic_stats(struct iwl_priv *priv)
@@ -746,80 +279,6 @@ void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
 }
 #endif
 
-static void iwl_force_rf_reset(struct iwl_priv *priv)
-{
-       if (test_bit(STATUS_EXIT_PENDING, &priv->status))
-               return;
-
-       if (!iwl_is_any_associated(priv)) {
-               IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
-               return;
-       }
-       /*
-        * There is no easy and better way to force reset the radio,
-        * the only known method is switching channel which will force to
-        * reset and tune the radio.
-        * Use internal short scan (single channel) operation to should
-        * achieve this objective.
-        * Driver should reset the radio when number of consecutive missed
-        * beacon, or any other uCode error condition detected.
-        */
-       IWL_DEBUG_INFO(priv, "perform radio reset.\n");
-       iwl_internal_short_hw_scan(priv);
-}
-
-
-int iwl_force_reset(struct iwl_priv *priv, int mode, bool external)
-{
-       struct iwl_force_reset *force_reset;
-
-       if (test_bit(STATUS_EXIT_PENDING, &priv->status))
-               return -EINVAL;
-
-       if (mode >= IWL_MAX_FORCE_RESET) {
-               IWL_DEBUG_INFO(priv, "invalid reset request.\n");
-               return -EINVAL;
-       }
-       force_reset = &priv->force_reset[mode];
-       force_reset->reset_request_count++;
-       if (!external) {
-               if (force_reset->last_force_reset_jiffies &&
-                   time_after(force_reset->last_force_reset_jiffies +
-                   force_reset->reset_duration, jiffies)) {
-                       IWL_DEBUG_INFO(priv, "force reset rejected\n");
-                       force_reset->reset_reject_count++;
-                       return -EAGAIN;
-               }
-       }
-       force_reset->reset_success_count++;
-       force_reset->last_force_reset_jiffies = jiffies;
-       IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode);
-       switch (mode) {
-       case IWL_RF_RESET:
-               iwl_force_rf_reset(priv);
-               break;
-       case IWL_FW_RESET:
-               /*
-                * if the request is from external(ex: debugfs),
-                * then always perform the request in regardless the module
-                * parameter setting
-                * if the request is from internal (uCode error or driver
-                * detect failure), then fw_restart module parameter
-                * need to be check before performing firmware reload
-                */
-               if (!external && !iwlagn_mod_params.restart_fw) {
-                       IWL_DEBUG_INFO(priv, "Cancel firmware reload based on "
-                                      "module parameter setting\n");
-                       break;
-               }
-               IWL_ERR(priv, "On demand firmware reload\n");
-               iwlagn_fw_error(priv, true);
-               break;
-       }
-       return 0;
-}
-
-
 int iwl_cmd_echo_test(struct iwl_priv *priv)
 {
        int ret;
@@ -836,165 +295,3 @@ int iwl_cmd_echo_test(struct iwl_priv *priv)
                IWL_DEBUG_INFO(priv, "echo testing pass\n");
        return ret;
 }
-
-static inline int iwl_check_stuck_queue(struct iwl_priv *priv, int txq)
-{
-       if (iwl_trans_check_stuck_queue(trans(priv), txq)) {
-               int ret;
-               ret = iwl_force_reset(priv, IWL_FW_RESET, false);
-               return (ret == -EAGAIN) ? 0 : 1;
-       }
-       return 0;
-}
-
-/*
- * Making watchdog tick be a quarter of timeout assure we will
- * discover the queue hung between timeout and 1.25*timeout
- */
-#define IWL_WD_TICK(timeout) ((timeout) / 4)
-
-/*
- * Watchdog timer callback, we check each tx queue for stuck, if if hung
- * we reset the firmware. If everything is fine just rearm the timer.
- */
-void iwl_bg_watchdog(unsigned long data)
-{
-       struct iwl_priv *priv = (struct iwl_priv *)data;
-       int cnt;
-       unsigned long timeout;
-
-       if (test_bit(STATUS_EXIT_PENDING, &priv->status))
-               return;
-
-       if (iwl_is_rfkill(priv))
-               return;
-
-       timeout = hw_params(priv).wd_timeout;
-       if (timeout == 0)
-               return;
-
-       /* monitor and check for stuck queues */
-       for (cnt = 0; cnt < cfg(priv)->base_params->num_of_queues; cnt++)
-               if (iwl_check_stuck_queue(priv, cnt))
-                       return;
-
-       mod_timer(&priv->watchdog, jiffies +
-                 msecs_to_jiffies(IWL_WD_TICK(timeout)));
-}
-
-void iwl_setup_watchdog(struct iwl_priv *priv)
-{
-       unsigned int timeout = hw_params(priv).wd_timeout;
-
-       if (!iwlagn_mod_params.wd_disable) {
-               /* use system default */
-               if (timeout && !cfg(priv)->base_params->wd_disable)
-                       mod_timer(&priv->watchdog,
-                               jiffies +
-                               msecs_to_jiffies(IWL_WD_TICK(timeout)));
-               else
-                       del_timer(&priv->watchdog);
-       } else {
-               /* module parameter overwrite default configuration */
-               if (timeout && iwlagn_mod_params.wd_disable == 2)
-                       mod_timer(&priv->watchdog,
-                               jiffies +
-                               msecs_to_jiffies(IWL_WD_TICK(timeout)));
-               else
-                       del_timer(&priv->watchdog);
-       }
-}
-
-/**
- * iwl_beacon_time_mask_low - mask of lower 32 bit of beacon time
- * @priv -- pointer to iwl_priv data structure
- * @tsf_bits -- number of bits need to shift for masking)
- */
-static inline u32 iwl_beacon_time_mask_low(struct iwl_priv *priv,
-                                          u16 tsf_bits)
-{
-       return (1 << tsf_bits) - 1;
-}
-
-/**
- * iwl_beacon_time_mask_high - mask of higher 32 bit of beacon time
- * @priv -- pointer to iwl_priv data structure
- * @tsf_bits -- number of bits need to shift for masking)
- */
-static inline u32 iwl_beacon_time_mask_high(struct iwl_priv *priv,
-                                           u16 tsf_bits)
-{
-       return ((1 << (32 - tsf_bits)) - 1) << tsf_bits;
-}
-
-/*
- * extended beacon time format
- * time in usec will be changed into a 32-bit value in extended:internal format
- * the extended part is the beacon counts
- * the internal part is the time in usec within one beacon interval
- */
-u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec, u32 beacon_interval)
-{
-       u32 quot;
-       u32 rem;
-       u32 interval = beacon_interval * TIME_UNIT;
-
-       if (!interval || !usec)
-               return 0;
-
-       quot = (usec / interval) &
-               (iwl_beacon_time_mask_high(priv, IWLAGN_EXT_BEACON_TIME_POS) >>
-               IWLAGN_EXT_BEACON_TIME_POS);
-       rem = (usec % interval) & iwl_beacon_time_mask_low(priv,
-                                  IWLAGN_EXT_BEACON_TIME_POS);
-
-       return (quot << IWLAGN_EXT_BEACON_TIME_POS) + rem;
-}
-
-/* base is usually what we get from ucode with each received frame,
- * the same as HW timer counter counting down
- */
-__le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base,
-                          u32 addon, u32 beacon_interval)
-{
-       u32 base_low = base & iwl_beacon_time_mask_low(priv,
-                               IWLAGN_EXT_BEACON_TIME_POS);
-       u32 addon_low = addon & iwl_beacon_time_mask_low(priv,
-                               IWLAGN_EXT_BEACON_TIME_POS);
-       u32 interval = beacon_interval * TIME_UNIT;
-       u32 res = (base & iwl_beacon_time_mask_high(priv,
-                               IWLAGN_EXT_BEACON_TIME_POS)) +
-                               (addon & iwl_beacon_time_mask_high(priv,
-                               IWLAGN_EXT_BEACON_TIME_POS));
-
-       if (base_low > addon_low)
-               res += base_low - addon_low;
-       else if (base_low < addon_low) {
-               res += interval + base_low - addon_low;
-               res += (1 << IWLAGN_EXT_BEACON_TIME_POS);
-       } else
-               res += (1 << IWLAGN_EXT_BEACON_TIME_POS);
-
-       return cpu_to_le32(res);
-}
-
-void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
-{
-       struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
-
-       if (state)
-               set_bit(STATUS_RF_KILL_HW, &priv->status);
-       else
-               clear_bit(STATUS_RF_KILL_HW, &priv->status);
-
-       wiphy_rfkill_set_hw_state(priv->hw->wiphy, state);
-}
-
-void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
-{
-       struct ieee80211_tx_info *info;
-
-       info = IEEE80211_SKB_CB(skb);
-       kmem_cache_free(iwl_tx_cmd_pool, (info->driver_data[1]));
-       dev_kfree_skb_any(skb);
-}
index 7aa3060fc6b5988bf11d569eed793f4384a004ef..199a0c03774c41f76cc0efb5f6119a98ecbb1df2 100644 (file)
@@ -74,38 +74,10 @@ struct iwl_cmd;
 
 #define TIME_UNIT              1024
 
-struct iwl_lib_ops {
-       /* set hw dependent parameters */
-       void (*set_hw_params)(struct iwl_priv *priv);
-       int (*set_channel_switch)(struct iwl_priv *priv,
-                                 struct ieee80211_channel_switch *ch_switch);
-       /* device specific configuration */
-       void (*nic_config)(struct iwl_priv *priv);
-
-       /* eeprom operations (as defined in iwl-eeprom.h) */
-       struct iwl_eeprom_ops eeprom_ops;
-
-       /* temperature */
-       void (*temperature)(struct iwl_priv *priv);
-};
-
 /***************************
  *   L i b                 *
  ***************************/
 
-void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
-                        struct iwl_rxon_context *ctx);
-void iwl_set_flags_for_band(struct iwl_priv *priv,
-                           struct iwl_rxon_context *ctx,
-                           enum ieee80211_band band,
-                           struct ieee80211_vif *vif);
-void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf);
-bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
-                           struct iwl_rxon_context *ctx,
-                           struct ieee80211_sta_ht_cap *ht_cap);
-void iwl_connection_init_rx_config(struct iwl_priv *priv,
-                                  struct iwl_rxon_context *ctx);
-void iwl_set_rate(struct iwl_priv *priv);
 int iwl_cmd_echo_test(struct iwl_priv *priv);
 #ifdef CONFIG_IWLWIFI_DEBUGFS
 int iwl_alloc_traffic_mem(struct iwl_priv *priv);
@@ -146,45 +118,9 @@ static inline void iwl_update_stats(struct iwl_priv *priv, bool is_tx,
 }
 #endif
 
-/*****************************************************
-* RX
-******************************************************/
-void iwl_chswitch_done(struct iwl_priv *priv, bool is_success);
-
-void iwl_setup_watchdog(struct iwl_priv *priv);
-/*****************************************************
- * TX power
- ****************************************************/
-int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force);
-
 /*******************************************************************************
  * Scanning
  ******************************************************************************/
-void iwl_init_scan_params(struct iwl_priv *priv);
-int iwl_scan_cancel(struct iwl_priv *priv);
-void iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms);
-void iwl_force_scan_end(struct iwl_priv *priv);
-void iwl_internal_short_hw_scan(struct iwl_priv *priv);
-int iwl_force_reset(struct iwl_priv *priv, int mode, bool external);
-void iwl_setup_rx_scan_handlers(struct iwl_priv *priv);
-void iwl_setup_scan_deferred_work(struct iwl_priv *priv);
-void iwl_cancel_scan_deferred_work(struct iwl_priv *priv);
-int __must_check iwl_scan_initiate(struct iwl_priv *priv,
-                                  struct ieee80211_vif *vif,
-                                  enum iwl_scan_type scan_type,
-                                  enum ieee80211_band band);
-
-/* For faster active scanning, scan will move to the next channel if fewer than
- * PLCP_QUIET_THRESH packets are heard on this channel within
- * ACTIVE_QUIET_TIME after sending probe request.  This shortens the dwell
- * time if it's a quiet channel (nothing responded to our probe, and there's
- * no other traffic).
- * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
-#define IWL_ACTIVE_QUIET_TIME       cpu_to_le16(10)  /* msec */
-#define IWL_PLCP_QUIET_THRESH       cpu_to_le16(1)  /* packets */
-
-#define IWL_SCAN_CHECK_WATCHDOG                (HZ * 7)
-
 /* traffic log definitions */
 #define IWL_TRAFFIC_ENTRIES    (256)
 #define IWL_TRAFFIC_ENTRY_SIZE  (64)
@@ -192,28 +128,6 @@ int __must_check iwl_scan_initiate(struct iwl_priv *priv,
 /*****************************************************
  *   S e n d i n g     H o s t     C o m m a n d s   *
  *****************************************************/
-
-void iwl_bg_watchdog(unsigned long data);
-u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec, u32 beacon_interval);
-__le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base,
-                          u32 addon, u32 beacon_interval);
-
-extern void iwl_send_bt_config(struct iwl_priv *priv);
-extern int iwl_send_statistics_request(struct iwl_priv *priv,
-                                      u8 flags, bool clear);
-
-static inline const struct ieee80211_supported_band *iwl_get_hw_mode(
-                       struct iwl_priv *priv, enum ieee80211_band band)
-{
-       return priv->hw->wiphy->bands[band];
-}
-
-static inline bool iwl_advanced_bt_coexist(struct iwl_priv *priv)
-{
-       return cfg(priv)->bt_params &&
-              cfg(priv)->bt_params->advanced_bt_coexist;
-}
-
 extern bool bt_siso_mode;
 
 #endif /* __iwl_core_h__ */
index 5f96ce105f08c1916abd41246a57b1ce610b3082..59750543fce7366ce68ccafa7bfeab2c4e923b54 100644 (file)
 #define HBUS_TARG_PRPH_WDAT     (HBUS_BASE+0x04c)
 #define HBUS_TARG_PRPH_RDAT     (HBUS_BASE+0x050)
 
+/* Used to enable DBGM */
+#define HBUS_TARG_TEST_REG     (HBUS_BASE+0x05c)
+
 /*
  * Per-Tx-queue write pointer (index, really!)
  * Indicates index to next TFD that driver will fill (1 past latest filled).
index d109d1bbb3a2e00d10494f3becd9c8d586a0ba73..32834a797d11546b4c0f7eda0702e5aeb6ade06a 100644 (file)
@@ -416,7 +416,7 @@ static ssize_t iwl_dbgfs_nvm_read(struct file *file,
                return -ENODATA;
        }
 
-       ptr = priv->shrd->eeprom;
+       ptr = priv->eeprom;
        if (!ptr) {
                IWL_ERR(priv, "Invalid EEPROM/OTP memory\n");
                return -ENOMEM;
@@ -428,10 +428,10 @@ static ssize_t iwl_dbgfs_nvm_read(struct file *file,
                IWL_ERR(priv, "Can not allocate Buffer\n");
                return -ENOMEM;
        }
-       eeprom_ver = iwl_eeprom_query16(priv->shrd, EEPROM_VERSION);
+       eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
        pos += scnprintf(buf + pos, buf_size - pos, "NVM Type: %s, "
                        "version: 0x%x\n",
-                       (trans(priv)->nvm_device_type == NVM_DEVICE_TYPE_OTP)
+                       (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
                         ? "OTP" : "EEPROM", eeprom_ver);
        for (ofs = 0 ; ofs < eeprom_len ; ofs += 16) {
                pos += scnprintf(buf + pos, buf_size - pos, "0x%.4x ", ofs);
@@ -526,8 +526,6 @@ static ssize_t iwl_dbgfs_status_read(struct file *file,
        int pos = 0;
        const size_t bufsz = sizeof(buf);
 
-       pos += scnprintf(buf + pos, bufsz - pos, "STATUS_HCMD_ACTIVE:\t %d\n",
-               test_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status));
        pos += scnprintf(buf + pos, bufsz - pos, "STATUS_RF_KILL_HW:\t %d\n",
                test_bit(STATUS_RF_KILL_HW, &priv->status));
        pos += scnprintf(buf + pos, bufsz - pos, "STATUS_CT_KILL:\t\t %d\n",
@@ -577,7 +575,7 @@ static ssize_t iwl_dbgfs_rx_handlers_read(struct file *file,
                if (priv->rx_handlers_stats[cnt] > 0)
                        pos += scnprintf(buf + pos, bufsz - pos,
                                "\tRx handler[%36s]:\t\t %u\n",
-                               get_cmd_string(cnt),
+                               iwl_dvm_get_cmd_string(cnt),
                                priv->rx_handlers_stats[cnt]);
        }
 
@@ -1541,17 +1539,17 @@ static ssize_t iwl_dbgfs_ucode_tx_stats_read(struct file *file,
        if (tx->tx_power.ant_a || tx->tx_power.ant_b || tx->tx_power.ant_c) {
                pos += scnprintf(buf + pos, bufsz - pos,
                        "tx power: (1/2 dB step)\n");
-               if ((hw_params(priv).valid_tx_ant & ANT_A) &&
+               if ((priv->hw_params.valid_tx_ant & ANT_A) &&
                    tx->tx_power.ant_a)
                        pos += scnprintf(buf + pos, bufsz - pos,
                                        fmt_hex, "antenna A:",
                                        tx->tx_power.ant_a);
-               if ((hw_params(priv).valid_tx_ant & ANT_B) &&
+               if ((priv->hw_params.valid_tx_ant & ANT_B) &&
                    tx->tx_power.ant_b)
                        pos += scnprintf(buf + pos, bufsz - pos,
                                        fmt_hex, "antenna B:",
                                        tx->tx_power.ant_b);
-               if ((hw_params(priv).valid_tx_ant & ANT_C) &&
+               if ((priv->hw_params.valid_tx_ant & ANT_C) &&
                    tx->tx_power.ant_c)
                        pos += scnprintf(buf + pos, bufsz - pos,
                                        fmt_hex, "antenna C:",
@@ -2267,59 +2265,39 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
        return count;
 }
 
-static ssize_t iwl_dbgfs_force_reset_read(struct file *file,
-                                       char __user *user_buf,
-                                       size_t count, loff_t *ppos)
+static ssize_t iwl_dbgfs_rf_reset_read(struct file *file,
+                                      char __user *user_buf,
+                                      size_t count, loff_t *ppos)
 {
        struct iwl_priv *priv = file->private_data;
-       int i, pos = 0;
+       int pos = 0;
        char buf[300];
        const size_t bufsz = sizeof(buf);
-       struct iwl_force_reset *force_reset;
+       struct iwl_rf_reset *rf_reset = &priv->rf_reset;
+
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "RF reset statistics\n");
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "\tnumber of reset request: %d\n",
+                       rf_reset->reset_request_count);
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "\tnumber of reset request success: %d\n",
+                       rf_reset->reset_success_count);
+       pos += scnprintf(buf + pos, bufsz - pos,
+                       "\tnumber of reset request reject: %d\n",
+                       rf_reset->reset_reject_count);
 
-       for (i = 0; i < IWL_MAX_FORCE_RESET; i++) {
-               force_reset = &priv->force_reset[i];
-               pos += scnprintf(buf + pos, bufsz - pos,
-                               "Force reset method %d\n", i);
-               pos += scnprintf(buf + pos, bufsz - pos,
-                               "\tnumber of reset request: %d\n",
-                               force_reset->reset_request_count);
-               pos += scnprintf(buf + pos, bufsz - pos,
-                               "\tnumber of reset request success: %d\n",
-                               force_reset->reset_success_count);
-               pos += scnprintf(buf + pos, bufsz - pos,
-                               "\tnumber of reset request reject: %d\n",
-                               force_reset->reset_reject_count);
-               pos += scnprintf(buf + pos, bufsz - pos,
-                               "\treset duration: %lu\n",
-                               force_reset->reset_duration);
-       }
        return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
 }
 
-static ssize_t iwl_dbgfs_force_reset_write(struct file *file,
+static ssize_t iwl_dbgfs_rf_reset_write(struct file *file,
                                        const char __user *user_buf,
                                        size_t count, loff_t *ppos) {
 
        struct iwl_priv *priv = file->private_data;
-       char buf[8];
-       int buf_size;
-       int reset, ret;
+       int ret;
 
-       memset(buf, 0, sizeof(buf));
-       buf_size = min(count, sizeof(buf) -  1);
-       if (copy_from_user(buf, user_buf, buf_size))
-               return -EFAULT;
-       if (sscanf(buf, "%d", &reset) != 1)
-               return -EINVAL;
-       switch (reset) {
-       case IWL_RF_RESET:
-       case IWL_FW_RESET:
-               ret = iwl_force_reset(priv, reset, true);
-               break;
-       default:
-               return -EINVAL;
-       }
+       ret = iwl_force_rf_reset(priv, true);
        return ret ? ret : count;
 }
 
@@ -2347,29 +2325,6 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
        return count;
 }
 
-static ssize_t iwl_dbgfs_wd_timeout_write(struct file *file,
-                                       const char __user *user_buf,
-                                       size_t count, loff_t *ppos)
-{
-       struct iwl_priv *priv = file->private_data;
-       char buf[8];
-       int buf_size;
-       int timeout;
-
-       memset(buf, 0, sizeof(buf));
-       buf_size = min(count, sizeof(buf) -  1);
-       if (copy_from_user(buf, user_buf, buf_size))
-               return -EFAULT;
-       if (sscanf(buf, "%d", &timeout) != 1)
-               return -EINVAL;
-       if (timeout < 0 || timeout > IWL_MAX_WD_TIMEOUT)
-               timeout = IWL_DEF_WD_TIMEOUT;
-
-       hw_params(priv).wd_timeout = timeout;
-       iwl_setup_watchdog(priv);
-       return count;
-}
-
 static ssize_t iwl_dbgfs_bt_traffic_read(struct file *file,
                                        char __user *user_buf,
                                        size_t count, loff_t *ppos) {
@@ -2428,7 +2383,7 @@ static ssize_t iwl_dbgfs_protection_mode_read(struct file *file,
        if (cfg(priv)->ht_params)
                pos += scnprintf(buf + pos, bufsz - pos,
                         "use %s for aggregation\n",
-                        (hw_params(priv).use_rts_for_aggregation) ?
+                        (priv->hw_params.use_rts_for_aggregation) ?
                                "rts/cts" : "cts-to-self");
        else
                pos += scnprintf(buf + pos, bufsz - pos, "N/A");
@@ -2455,9 +2410,9 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
        if (sscanf(buf, "%d", &rts) != 1)
                return -EINVAL;
        if (rts)
-               hw_params(priv).use_rts_for_aggregation = true;
+               priv->hw_params.use_rts_for_aggregation = true;
        else
-               hw_params(priv).use_rts_for_aggregation = false;
+               priv->hw_params.use_rts_for_aggregation = false;
        return count;
 }
 
@@ -2516,6 +2471,34 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
        return count;
 }
 
+static ssize_t iwl_dbgfs_calib_disabled_read(struct file *file,
+                                        char __user *user_buf,
+                                        size_t count, loff_t *ppos)
+{
+       struct iwl_priv *priv = file->private_data;
+       char buf[120];
+       int pos = 0;
+       const size_t bufsz = sizeof(buf);
+
+       pos += scnprintf(buf + pos, bufsz - pos,
+                        "Sensitivity calibrations %s\n",
+                        (priv->calib_disabled &
+                                       IWL_SENSITIVITY_CALIB_DISABLED) ?
+                        "DISABLED" : "ENABLED");
+       pos += scnprintf(buf + pos, bufsz - pos,
+                        "Chain noise calibrations %s\n",
+                        (priv->calib_disabled &
+                                       IWL_CHAIN_NOISE_CALIB_DISABLED) ?
+                        "DISABLED" : "ENABLED");
+       pos += scnprintf(buf + pos, bufsz - pos,
+                        "Tx power calibrations %s\n",
+                        (priv->calib_disabled &
+                                       IWL_TX_POWER_CALIB_DISABLED) ?
+                        "DISABLED" : "ENABLED");
+
+       return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
+}
+
 DEBUGFS_READ_FILE_OPS(rx_statistics);
 DEBUGFS_READ_FILE_OPS(tx_statistics);
 DEBUGFS_READ_WRITE_FILE_OPS(traffic_log);
@@ -2530,17 +2513,17 @@ DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics);
 DEBUGFS_READ_WRITE_FILE_OPS(ucode_tracing);
 DEBUGFS_READ_WRITE_FILE_OPS(missed_beacon);
 DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta);
-DEBUGFS_READ_WRITE_FILE_OPS(force_reset);
+DEBUGFS_READ_WRITE_FILE_OPS(rf_reset);
 DEBUGFS_READ_FILE_OPS(rxon_flags);
 DEBUGFS_READ_FILE_OPS(rxon_filter_flags);
 DEBUGFS_WRITE_FILE_OPS(txfifo_flush);
 DEBUGFS_READ_FILE_OPS(ucode_bt_stats);
-DEBUGFS_WRITE_FILE_OPS(wd_timeout);
 DEBUGFS_READ_FILE_OPS(bt_traffic);
 DEBUGFS_READ_WRITE_FILE_OPS(protection_mode);
 DEBUGFS_READ_FILE_OPS(reply_tx_error);
 DEBUGFS_WRITE_FILE_OPS(echo_test);
 DEBUGFS_READ_WRITE_FILE_OPS(log_event);
+DEBUGFS_READ_FILE_OPS(calib_disabled);
 
 /*
  * Create the debugfs files and directories
@@ -2589,7 +2572,7 @@ int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
        DEBUGFS_ADD_FILE(clear_traffic_statistics, dir_debug, S_IWUSR);
        DEBUGFS_ADD_FILE(missed_beacon, dir_debug, S_IWUSR);
        DEBUGFS_ADD_FILE(plcp_delta, dir_debug, S_IWUSR | S_IRUSR);
-       DEBUGFS_ADD_FILE(force_reset, dir_debug, S_IWUSR | S_IRUSR);
+       DEBUGFS_ADD_FILE(rf_reset, dir_debug, S_IWUSR | S_IRUSR);
        DEBUGFS_ADD_FILE(ucode_rx_stats, dir_debug, S_IRUSR);
        DEBUGFS_ADD_FILE(ucode_tx_stats, dir_debug, S_IRUSR);
        DEBUGFS_ADD_FILE(ucode_general_stats, dir_debug, S_IRUSR);
@@ -2602,17 +2585,14 @@ int iwl_dbgfs_register(struct iwl_priv *priv, const char *name)
        DEBUGFS_ADD_FILE(reply_tx_error, dir_debug, S_IRUSR);
        DEBUGFS_ADD_FILE(rxon_flags, dir_debug, S_IWUSR);
        DEBUGFS_ADD_FILE(rxon_filter_flags, dir_debug, S_IWUSR);
-       DEBUGFS_ADD_FILE(wd_timeout, dir_debug, S_IWUSR);
        DEBUGFS_ADD_FILE(echo_test, dir_debug, S_IWUSR);
        DEBUGFS_ADD_FILE(log_event, dir_debug, S_IWUSR | S_IRUSR);
 
        if (iwl_advanced_bt_coexist(priv))
                DEBUGFS_ADD_FILE(bt_traffic, dir_debug, S_IRUSR);
 
-       DEBUGFS_ADD_BOOL(disable_sensitivity, dir_rf,
-                        &priv->disable_sens_cal);
-       DEBUGFS_ADD_BOOL(disable_chain_noise, dir_rf,
-                        &priv->disable_chain_noise_cal);
+       /* Calibrations disabled/enabled status*/
+       DEBUGFS_ADD_FILE(calib_disabled, dir_rf, S_IRUSR);
 
        if (iwl_trans_dbgfs_register(trans(priv), dir_debug))
                goto err;
index 99be58940e275128a2f17bad4059dd5a33d734bd..c235a1ea71b4adf9d89146536cb875cf98816fa7 100644 (file)
@@ -51,8 +51,6 @@
 #include "iwl-op-mode.h"
 #include "iwl-notif-wait.h"
 
-struct iwl_tx_queue;
-
 /* CT-KILL constants */
 #define CT_KILL_THRESHOLD_LEGACY   110 /* in Celsius */
 #define CT_KILL_THRESHOLD         114 /* in Celsius */
@@ -582,9 +580,9 @@ struct iwl_event_log {
 #define IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE     (0)
 
 #define IWL_DELAY_NEXT_FORCE_RF_RESET  (HZ*3)
-#define IWL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5)
 
 /* TX queue watchdog timeouts in mSecs */
+#define IWL_WATCHHDOG_DISABLED (0)
 #define IWL_DEF_WD_TIMEOUT     (2000)
 #define IWL_LONG_WD_TIMEOUT    (10000)
 #define IWL_MAX_WD_TIMEOUT     (120000)
@@ -597,18 +595,11 @@ struct iwl_event_log {
 #define IWL_MAX_CONTINUE_RELOAD_CNT    4
 
 
-enum iwl_reset {
-       IWL_RF_RESET = 0,
-       IWL_FW_RESET,
-       IWL_MAX_FORCE_RESET,
-};
-
-struct iwl_force_reset {
+struct iwl_rf_reset {
        int reset_request_count;
        int reset_success_count;
        int reset_reject_count;
-       unsigned long reset_duration;
-       unsigned long last_force_reset_jiffies;
+       unsigned long last_reset_jiffies;
 };
 
 /* extend beacon time format bit shifting  */
@@ -680,6 +671,52 @@ enum iwl_scan_type {
        IWL_SCAN_ROC,
 };
 
+/**
+ * struct iwl_hw_params
+ *
+ * Holds the module parameters
+ *
+ * @tx_chains_num: Number of TX chains
+ * @rx_chains_num: Number of RX chains
+ * @valid_tx_ant: usable antennas for TX
+ * @valid_rx_ant: usable antennas for RX
+ * @ht40_channel: is 40MHz width possible: BIT(IEEE80211_BAND_XXX)
+ * @sku: sku read from EEPROM
+ * @ct_kill_threshold: temperature threshold - in hw dependent unit
+ * @ct_kill_exit_threshold: when to reeable the device - in hw dependent unit
+ *     relevant for 1000, 6000 and up
+ * @struct iwl_sensitivity_ranges: range of sensitivity values
+ * @use_rts_for_aggregation: use rts/cts protection for HT traffic
+ */
+struct iwl_hw_params {
+       u8  tx_chains_num;
+       u8  rx_chains_num;
+       u8  valid_tx_ant;
+       u8  valid_rx_ant;
+       u8  ht40_channel;
+       bool use_rts_for_aggregation;
+       u16 sku;
+       u32 ct_kill_threshold;
+       u32 ct_kill_exit_threshold;
+
+       const struct iwl_sensitivity_ranges *sens;
+};
+
+struct iwl_lib_ops {
+       /* set hw dependent parameters */
+       void (*set_hw_params)(struct iwl_priv *priv);
+       int (*set_channel_switch)(struct iwl_priv *priv,
+                                 struct ieee80211_channel_switch *ch_switch);
+       /* device specific configuration */
+       void (*nic_config)(struct iwl_priv *priv);
+
+       /* eeprom operations (as defined in iwl-eeprom.h) */
+       struct iwl_eeprom_ops eeprom_ops;
+
+       /* temperature */
+       void (*temperature)(struct iwl_priv *priv);
+};
+
 #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
 struct iwl_testmode_trace {
        u32 buff_size;
@@ -704,6 +741,14 @@ struct iwl_wipan_noa_data {
        u8 data[];
 };
 
+/* Calibration disabling bit mask */
+#define IWL_SENSITIVITY_CALIB_DISABLED BIT(1)
+#define IWL_CHAIN_NOISE_CALIB_DISABLED BIT(2)
+#define IWL_TX_POWER_CALIB_DISABLED    BIT(3)
+
+#define IWL_CALIB_ENABLE_ALL   0
+#define IWL_CALIB_DISABLE_ALL  0xFFFFFFFF
+
 #define IWL_OP_MODE_GET_DVM(_iwl_op_mode) \
        ((struct iwl_priv *) ((_iwl_op_mode)->op_mode_specific))
 
@@ -716,6 +761,7 @@ struct iwl_priv {
        /*data shared among all the driver's layers */
        struct iwl_shared *shrd;
        const struct iwl_fw *fw;
+       const struct iwl_lib_ops *lib;
        unsigned long status;
 
        spinlock_t sta_lock;
@@ -738,6 +784,8 @@ struct iwl_priv {
 
        struct workqueue_struct *workqueue;
 
+       struct iwl_hw_params hw_params;
+
        enum ieee80211_band band;
        u8 valid_contexts;
 
@@ -772,8 +820,8 @@ struct iwl_priv {
        /*counters */
        u32 rx_handlers_stats[REPLY_MAX];
 
-       /* force reset */
-       struct iwl_force_reset force_reset[IWL_MAX_FORCE_RESET];
+       /* rf reset */
+       struct iwl_rf_reset rf_reset;
 
        /* firmware reload counter and timestamp */
        unsigned long reload_jiffies;
@@ -819,8 +867,6 @@ struct iwl_priv {
 
        __le16 switch_channel;
 
-       u16 active_rate;
-
        u8 start_calib;
        struct iwl_sensitivity_data sensitivity_data;
        struct iwl_chain_noise_data chain_noise_data;
@@ -967,13 +1013,15 @@ struct iwl_priv {
        void *wowlan_sram;
 #endif /* CONFIG_IWLWIFI_DEBUGFS */
 
+       /* eeprom -- this is in the card's little endian byte order */
+       u8 *eeprom;
+       enum iwl_nvm_type nvm_device_type;
+
        struct work_struct txpower_work;
-       u32 disable_sens_cal;
-       u32 disable_chain_noise_cal;
+       u32 calib_disabled;
        struct work_struct run_time_calib_work;
        struct timer_list statistics_periodic;
        struct timer_list ucode_trace;
-       struct timer_list watchdog;
 
        struct iwl_event_log event_log;
 
index 6f312c77af5ef279388f6447884618ec386fbede..17485e715424d9392577d337d675b369072bbad7 100644 (file)
@@ -284,6 +284,7 @@ static int iwl_store_ucode_sec(struct iwl_firmware_pieces *pieces,
 
        sec->offset = le32_to_cpu(sec_parse->offset);
        sec->data = sec_parse->data;
+       sec->size = size - sizeof(sec_parse->offset);
 
        ++img->sec_counter;
 
@@ -414,9 +415,6 @@ static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
        struct iwl_ucode_tlv *tlv;
        size_t len = ucode_raw->size;
        const u8 *data;
-       int wanted_alternative = iwlagn_mod_params.wanted_ucode_alternative;
-       int tmp;
-       u64 alternatives;
        u32 tlv_len;
        enum iwl_ucode_tlv_type tlv_type;
        const u8 *tlv_data;
@@ -434,23 +432,6 @@ static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
                return -EINVAL;
        }
 
-       /*
-        * Check which alternatives are present, and "downgrade"
-        * when the chosen alternative is not present, warning
-        * the user when that happens. Some files may not have
-        * any alternatives, so don't warn in that case.
-        */
-       alternatives = le64_to_cpu(ucode->alternatives);
-       tmp = wanted_alternative;
-       if (wanted_alternative > 63)
-               wanted_alternative = 63;
-       while (wanted_alternative && !(alternatives & BIT(wanted_alternative)))
-               wanted_alternative--;
-       if (wanted_alternative && wanted_alternative != tmp)
-               IWL_WARN(drv,
-                        "uCode alternative %d not available, choosing %d\n",
-                        tmp, wanted_alternative);
-
        drv->fw.ucode_ver = le32_to_cpu(ucode->ver);
        build = le32_to_cpu(ucode->build);
 
@@ -475,14 +456,11 @@ static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
        len -= sizeof(*ucode);
 
        while (len >= sizeof(*tlv)) {
-               u16 tlv_alt;
-
                len -= sizeof(*tlv);
                tlv = (void *)data;
 
                tlv_len = le32_to_cpu(tlv->length);
-               tlv_type = le16_to_cpu(tlv->type);
-               tlv_alt = le16_to_cpu(tlv->alternative);
+               tlv_type = le32_to_cpu(tlv->type);
                tlv_data = tlv->data;
 
                if (len < tlv_len) {
@@ -493,14 +471,6 @@ static int iwl_parse_tlv_firmware(struct iwl_drv *drv,
                len -= ALIGN(tlv_len, 4);
                data += sizeof(*tlv) + ALIGN(tlv_len, 4);
 
-               /*
-                * Alternative 0 is always valid.
-                *
-                * Skip alternative TLVs that are not selected.
-                */
-               if (tlv_alt != 0 && tlv_alt != wanted_alternative)
-                       continue;
-
                switch (tlv_type) {
                case IWL_UCODE_TLV_INST:
                        set_sec_data(pieces, IWL_UCODE_REGULAR,
@@ -837,42 +807,6 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
 
        IWL_INFO(drv, "loaded firmware version %s", drv->fw.fw_version);
 
-       /*
-        * For any of the failures below (before allocating pci memory)
-        * we will try to load a version with a smaller API -- maybe the
-        * user just got a corrupted version of the latest API.
-        */
-
-       IWL_DEBUG_INFO(drv, "f/w package hdr ucode version raw = 0x%x\n",
-                      drv->fw.ucode_ver);
-       IWL_DEBUG_INFO(drv, "f/w package hdr runtime inst size = %Zd\n",
-               get_sec_size(&pieces, IWL_UCODE_REGULAR,
-                            IWL_UCODE_SECTION_INST));
-       IWL_DEBUG_INFO(drv, "f/w package hdr runtime data size = %Zd\n",
-               get_sec_size(&pieces, IWL_UCODE_REGULAR,
-                            IWL_UCODE_SECTION_DATA));
-       IWL_DEBUG_INFO(drv, "f/w package hdr init inst size = %Zd\n",
-               get_sec_size(&pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_INST));
-       IWL_DEBUG_INFO(drv, "f/w package hdr init data size = %Zd\n",
-               get_sec_size(&pieces, IWL_UCODE_INIT, IWL_UCODE_SECTION_DATA));
-
-       /* Verify that uCode images will fit in card's SRAM */
-       if (get_sec_size(&pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_INST) >
-                                                       cfg->max_inst_size) {
-               IWL_ERR(drv, "uCode instr len %Zd too large to fit in\n",
-                       get_sec_size(&pieces, IWL_UCODE_REGULAR,
-                                    IWL_UCODE_SECTION_INST));
-               goto try_again;
-       }
-
-       if (get_sec_size(&pieces, IWL_UCODE_REGULAR, IWL_UCODE_SECTION_DATA) >
-                                                       cfg->max_data_size) {
-               IWL_ERR(drv, "uCode data len %Zd too large to fit in\n",
-                       get_sec_size(&pieces, IWL_UCODE_REGULAR,
-                                    IWL_UCODE_SECTION_DATA));
-               goto try_again;
-       }
-
        /*
         * In mvm uCode there is no difference between data and instructions
         * sections.
index 23cea42b94959ba5c09ad852b24b7c28ad3a85dc..a004431d1a60ae5b01aee1a355bed248c8105d68 100644 (file)
@@ -187,33 +187,33 @@ static void iwl_eeprom_release_semaphore(struct iwl_trans *trans)
 
 }
 
-static int iwl_eeprom_verify_signature(struct iwl_trans *trans)
+static int iwl_eeprom_verify_signature(struct iwl_priv *priv)
 {
-       u32 gp = iwl_read32(trans, CSR_EEPROM_GP) &
+       u32 gp = iwl_read32(trans(priv), CSR_EEPROM_GP) &
                           CSR_EEPROM_GP_VALID_MSK;
        int ret = 0;
 
-       IWL_DEBUG_EEPROM(trans, "EEPROM signature=0x%08x\n", gp);
+       IWL_DEBUG_EEPROM(priv, "EEPROM signature=0x%08x\n", gp);
        switch (gp) {
        case CSR_EEPROM_GP_BAD_SIG_EEP_GOOD_SIG_OTP:
-               if (trans->nvm_device_type != NVM_DEVICE_TYPE_OTP) {
-                       IWL_ERR(trans, "EEPROM with bad signature: 0x%08x\n",
+               if (priv->nvm_device_type != NVM_DEVICE_TYPE_OTP) {
+                       IWL_ERR(priv, "EEPROM with bad signature: 0x%08x\n",
                                gp);
                        ret = -ENOENT;
                }
                break;
        case CSR_EEPROM_GP_GOOD_SIG_EEP_LESS_THAN_4K:
        case CSR_EEPROM_GP_GOOD_SIG_EEP_MORE_THAN_4K:
-               if (trans->nvm_device_type != NVM_DEVICE_TYPE_EEPROM) {
-                       IWL_ERR(trans, "OTP with bad signature: 0x%08x\n", gp);
+               if (priv->nvm_device_type != NVM_DEVICE_TYPE_EEPROM) {
+                       IWL_ERR(priv, "OTP with bad signature: 0x%08x\n", gp);
                        ret = -ENOENT;
                }
                break;
        case CSR_EEPROM_GP_BAD_SIGNATURE_BOTH_EEP_AND_OTP:
        default:
-               IWL_ERR(trans, "bad EEPROM/OTP signature, type=%s, "
+               IWL_ERR(priv, "bad EEPROM/OTP signature, type=%s, "
                        "EEPROM_GP=0x%08x\n",
-                       (trans->nvm_device_type == NVM_DEVICE_TYPE_OTP)
+                       (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
                        ? "OTP" : "EEPROM", gp);
                ret = -ENOENT;
                break;
@@ -221,11 +221,11 @@ static int iwl_eeprom_verify_signature(struct iwl_trans *trans)
        return ret;
 }
 
-u16 iwl_eeprom_query16(const struct iwl_shared *shrd, size_t offset)
+u16 iwl_eeprom_query16(struct iwl_priv *priv, size_t offset)
 {
-       if (!shrd->eeprom)
+       if (!priv->eeprom)
                return 0;
-       return (u16)shrd->eeprom[offset] | ((u16)shrd->eeprom[offset + 1] << 8);
+       return (u16)priv->eeprom[offset] | ((u16)priv->eeprom[offset + 1] << 8);
 }
 
 int iwl_eeprom_check_version(struct iwl_priv *priv)
@@ -233,8 +233,8 @@ int iwl_eeprom_check_version(struct iwl_priv *priv)
        u16 eeprom_ver;
        u16 calib_ver;
 
-       eeprom_ver = iwl_eeprom_query16(priv->shrd, EEPROM_VERSION);
-       calib_ver = iwl_eeprom_calib_version(priv->shrd);
+       eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
+       calib_ver = iwl_eeprom_calib_version(priv);
 
        if (eeprom_ver < cfg(priv)->eeprom_ver ||
            calib_ver < cfg(priv)->eeprom_calib_ver)
@@ -255,50 +255,107 @@ err:
 
 int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
 {
-       struct iwl_shared *shrd = priv->shrd;
        u16 radio_cfg;
 
-       hw_params(priv).sku = iwl_eeprom_query16(shrd, EEPROM_SKU_CAP);
-       if (hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE &&
+       priv->hw_params.sku = iwl_eeprom_query16(priv, EEPROM_SKU_CAP);
+       if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE &&
            !cfg(priv)->ht_params) {
                IWL_ERR(priv, "Invalid 11n configuration\n");
                return -EINVAL;
        }
 
-       if (!hw_params(priv).sku) {
+       if (!priv->hw_params.sku) {
                IWL_ERR(priv, "Invalid device sku\n");
                return -EINVAL;
        }
 
-       IWL_INFO(priv, "Device SKU: 0x%X\n", hw_params(priv).sku);
+       IWL_INFO(priv, "Device SKU: 0x%X\n", priv->hw_params.sku);
 
-       radio_cfg = iwl_eeprom_query16(shrd, EEPROM_RADIO_CONFIG);
+       radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
 
-       hw_params(priv).valid_tx_ant = EEPROM_RF_CFG_TX_ANT_MSK(radio_cfg);
-       hw_params(priv).valid_rx_ant = EEPROM_RF_CFG_RX_ANT_MSK(radio_cfg);
+       priv->hw_params.valid_tx_ant = EEPROM_RF_CFG_TX_ANT_MSK(radio_cfg);
+       priv->hw_params.valid_rx_ant = EEPROM_RF_CFG_RX_ANT_MSK(radio_cfg);
 
        /* check overrides (some devices have wrong EEPROM) */
        if (cfg(priv)->valid_tx_ant)
-               hw_params(priv).valid_tx_ant = cfg(priv)->valid_tx_ant;
+               priv->hw_params.valid_tx_ant = cfg(priv)->valid_tx_ant;
        if (cfg(priv)->valid_rx_ant)
-               hw_params(priv).valid_rx_ant = cfg(priv)->valid_rx_ant;
+               priv->hw_params.valid_rx_ant = cfg(priv)->valid_rx_ant;
 
-       if (!hw_params(priv).valid_tx_ant || !hw_params(priv).valid_rx_ant) {
+       if (!priv->hw_params.valid_tx_ant || !priv->hw_params.valid_rx_ant) {
                IWL_ERR(priv, "Invalid chain (0x%X, 0x%X)\n",
-                       hw_params(priv).valid_tx_ant,
-                       hw_params(priv).valid_rx_ant);
+                       priv->hw_params.valid_tx_ant,
+                       priv->hw_params.valid_rx_ant);
                return -EINVAL;
        }
 
        IWL_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
-                hw_params(priv).valid_tx_ant, hw_params(priv).valid_rx_ant);
+                priv->hw_params.valid_tx_ant, priv->hw_params.valid_rx_ant);
 
        return 0;
 }
 
-void iwl_eeprom_get_mac(const struct iwl_shared *shrd, u8 *mac)
+u16 iwl_eeprom_calib_version(struct iwl_priv *priv)
 {
-       const u8 *addr = iwl_eeprom_query_addr(shrd,
+       struct iwl_eeprom_calib_hdr *hdr;
+
+       hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
+                                                       EEPROM_CALIB_ALL);
+       return hdr->version;
+}
+
+static u32 eeprom_indirect_address(struct iwl_priv *priv, u32 address)
+{
+       u16 offset = 0;
+
+       if ((address & INDIRECT_ADDRESS) == 0)
+               return address;
+
+       switch (address & INDIRECT_TYPE_MSK) {
+       case INDIRECT_HOST:
+               offset = iwl_eeprom_query16(priv, EEPROM_LINK_HOST);
+               break;
+       case INDIRECT_GENERAL:
+               offset = iwl_eeprom_query16(priv, EEPROM_LINK_GENERAL);
+               break;
+       case INDIRECT_REGULATORY:
+               offset = iwl_eeprom_query16(priv, EEPROM_LINK_REGULATORY);
+               break;
+       case INDIRECT_TXP_LIMIT:
+               offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT);
+               break;
+       case INDIRECT_TXP_LIMIT_SIZE:
+               offset = iwl_eeprom_query16(priv, EEPROM_LINK_TXP_LIMIT_SIZE);
+               break;
+       case INDIRECT_CALIBRATION:
+               offset = iwl_eeprom_query16(priv, EEPROM_LINK_CALIBRATION);
+               break;
+       case INDIRECT_PROCESS_ADJST:
+               offset = iwl_eeprom_query16(priv, EEPROM_LINK_PROCESS_ADJST);
+               break;
+       case INDIRECT_OTHERS:
+               offset = iwl_eeprom_query16(priv, EEPROM_LINK_OTHERS);
+               break;
+       default:
+               IWL_ERR(priv, "illegal indirect type: 0x%X\n",
+               address & INDIRECT_TYPE_MSK);
+               break;
+       }
+
+       /* translate the offset from words to byte */
+       return (address & ADDRESS_MSK) + (offset << 1);
+}
+
+const u8 *iwl_eeprom_query_addr(struct iwl_priv *priv, size_t offset)
+{
+       u32 address = eeprom_indirect_address(priv, offset);
+       BUG_ON(address >= cfg(priv)->base_params->eeprom_size);
+       return &priv->eeprom[address];
+}
+
+void iwl_eeprom_get_mac(struct iwl_priv *priv, u8 *mac)
+{
+       const u8 *addr = iwl_eeprom_query_addr(priv,
                                        EEPROM_MAC_ADDRESS);
        memcpy(mac, addr, ETH_ALEN);
 }
@@ -591,7 +648,6 @@ iwl_eeprom_enh_txp_read_element(struct iwl_priv *priv,
 
 static void iwl_eeprom_enhanced_txpower(struct iwl_priv *priv)
 {
-       struct iwl_shared *shrd = priv->shrd;
        struct iwl_eeprom_enhanced_txpwr *txp_array, *txp;
        int idx, entries;
        __le16 *txp_len;
@@ -600,10 +656,10 @@ static void iwl_eeprom_enhanced_txpower(struct iwl_priv *priv)
        BUILD_BUG_ON(sizeof(struct iwl_eeprom_enhanced_txpwr) != 8);
 
        /* the length is in 16-bit words, but we want entries */
-       txp_len = (__le16 *) iwl_eeprom_query_addr(shrd, EEPROM_TXP_SZ_OFFS);
+       txp_len = (__le16 *) iwl_eeprom_query_addr(priv, EEPROM_TXP_SZ_OFFS);
        entries = le16_to_cpup(txp_len) * 2 / EEPROM_TXP_ENTRY_LEN;
 
-       txp_array = (void *) iwl_eeprom_query_addr(shrd, EEPROM_TXP_OFFS);
+       txp_array = (void *) iwl_eeprom_query_addr(priv, EEPROM_TXP_OFFS);
 
        for (idx = 0; idx < entries; idx++) {
                txp = &txp_array[idx];
@@ -656,66 +712,66 @@ static void iwl_eeprom_enhanced_txpower(struct iwl_priv *priv)
 /**
  * iwl_eeprom_init - read EEPROM contents
  *
- * Load the EEPROM contents from adapter into shrd->eeprom
+ * Load the EEPROM contents from adapter into priv->eeprom
  *
  * NOTE:  This routine uses the non-debug IO access functions.
  */
-int iwl_eeprom_init(struct iwl_trans *trans, u32 hw_rev)
+int iwl_eeprom_init(struct iwl_priv *priv, u32 hw_rev)
 {
        __le16 *e;
-       u32 gp = iwl_read32(trans, CSR_EEPROM_GP);
+       u32 gp = iwl_read32(trans(priv), CSR_EEPROM_GP);
        int sz;
        int ret;
        u16 addr;
        u16 validblockaddr = 0;
        u16 cache_addr = 0;
 
-       trans->nvm_device_type = iwl_get_nvm_type(trans, hw_rev);
-       if (trans->nvm_device_type == -ENOENT)
+       priv->nvm_device_type = iwl_get_nvm_type(trans(priv), hw_rev);
+       if (priv->nvm_device_type == -ENOENT)
                return -ENOENT;
        /* allocate eeprom */
-       sz = cfg(trans)->base_params->eeprom_size;
-       IWL_DEBUG_EEPROM(trans, "NVM size = %d\n", sz);
-       trans->shrd->eeprom = kzalloc(sz, GFP_KERNEL);
-       if (!trans->shrd->eeprom) {
+       sz = cfg(priv)->base_params->eeprom_size;
+       IWL_DEBUG_EEPROM(priv, "NVM size = %d\n", sz);
+       priv->eeprom = kzalloc(sz, GFP_KERNEL);
+       if (!priv->eeprom) {
                ret = -ENOMEM;
                goto alloc_err;
        }
-       e = (__le16 *)trans->shrd->eeprom;
+       e = (__le16 *)priv->eeprom;
 
-       ret = iwl_eeprom_verify_signature(trans);
+       ret = iwl_eeprom_verify_signature(priv);
        if (ret < 0) {
-               IWL_ERR(trans, "EEPROM not found, EEPROM_GP=0x%08x\n", gp);
+               IWL_ERR(priv, "EEPROM not found, EEPROM_GP=0x%08x\n", gp);
                ret = -ENOENT;
                goto err;
        }
 
        /* Make sure driver (instead of uCode) is allowed to read EEPROM */
-       ret = iwl_eeprom_acquire_semaphore(trans);
+       ret = iwl_eeprom_acquire_semaphore(trans(priv));
        if (ret < 0) {
-               IWL_ERR(trans, "Failed to acquire EEPROM semaphore.\n");
+               IWL_ERR(priv, "Failed to acquire EEPROM semaphore.\n");
                ret = -ENOENT;
                goto err;
        }
 
-       if (trans->nvm_device_type == NVM_DEVICE_TYPE_OTP) {
+       if (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP) {
 
-               ret = iwl_init_otp_access(trans);
+               ret = iwl_init_otp_access(trans(priv));
                if (ret) {
-                       IWL_ERR(trans, "Failed to initialize OTP access.\n");
+                       IWL_ERR(priv, "Failed to initialize OTP access.\n");
                        ret = -ENOENT;
                        goto done;
                }
-               iwl_write32(trans, CSR_EEPROM_GP,
-                           iwl_read32(trans, CSR_EEPROM_GP) &
+               iwl_write32(trans(priv), CSR_EEPROM_GP,
+                           iwl_read32(trans(priv), CSR_EEPROM_GP) &
                            ~CSR_EEPROM_GP_IF_OWNER_MSK);
 
-               iwl_set_bit(trans, CSR_OTP_GP_REG,
+               iwl_set_bit(trans(priv), CSR_OTP_GP_REG,
                             CSR_OTP_GP_REG_ECC_CORR_STATUS_MSK |
                             CSR_OTP_GP_REG_ECC_UNCORR_STATUS_MSK);
                /* traversing the linked list if no shadow ram supported */
-               if (!cfg(trans)->base_params->shadow_ram_support) {
-                       if (iwl_find_otp_image(trans, &validblockaddr)) {
+               if (!cfg(priv)->base_params->shadow_ram_support) {
+                       if (iwl_find_otp_image(trans(priv), &validblockaddr)) {
                                ret = -ENOENT;
                                goto done;
                        }
@@ -724,7 +780,8 @@ int iwl_eeprom_init(struct iwl_trans *trans, u32 hw_rev)
                     addr += sizeof(u16)) {
                        __le16 eeprom_data;
 
-                       ret = iwl_read_otp_word(trans, addr, &eeprom_data);
+                       ret = iwl_read_otp_word(trans(priv), addr,
+                                               &eeprom_data);
                        if (ret)
                                goto done;
                        e[cache_addr / 2] = eeprom_data;
@@ -735,94 +792,93 @@ int iwl_eeprom_init(struct iwl_trans *trans, u32 hw_rev)
                for (addr = 0; addr < sz; addr += sizeof(u16)) {
                        u32 r;
 
-                       iwl_write32(trans, CSR_EEPROM_REG,
+                       iwl_write32(trans(priv), CSR_EEPROM_REG,
                                    CSR_EEPROM_REG_MSK_ADDR & (addr << 1));
 
-                       ret = iwl_poll_bit(trans, CSR_EEPROM_REG,
+                       ret = iwl_poll_bit(trans(priv), CSR_EEPROM_REG,
                                                  CSR_EEPROM_REG_READ_VALID_MSK,
                                                  CSR_EEPROM_REG_READ_VALID_MSK,
                                                  IWL_EEPROM_ACCESS_TIMEOUT);
                        if (ret < 0) {
-                               IWL_ERR(trans,
+                               IWL_ERR(priv,
                                        "Time out reading EEPROM[%d]\n", addr);
                                goto done;
                        }
-                       r = iwl_read32(trans, CSR_EEPROM_REG);
+                       r = iwl_read32(trans(priv), CSR_EEPROM_REG);
                        e[addr / 2] = cpu_to_le16(r >> 16);
                }
        }
 
-       IWL_DEBUG_EEPROM(trans, "NVM Type: %s, version: 0x%x\n",
-                      (trans->nvm_device_type == NVM_DEVICE_TYPE_OTP)
+       IWL_DEBUG_EEPROM(priv, "NVM Type: %s, version: 0x%x\n",
+                      (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
                       ? "OTP" : "EEPROM",
-                      iwl_eeprom_query16(trans->shrd, EEPROM_VERSION));
+                      iwl_eeprom_query16(priv, EEPROM_VERSION));
 
        ret = 0;
 done:
-       iwl_eeprom_release_semaphore(trans);
+       iwl_eeprom_release_semaphore(trans(priv));
 
 err:
        if (ret)
-               iwl_eeprom_free(trans->shrd);
+               iwl_eeprom_free(priv);
 alloc_err:
        return ret;
 }
 
-void iwl_eeprom_free(struct iwl_shared *shrd)
+void iwl_eeprom_free(struct iwl_priv *priv)
 {
-       kfree(shrd->eeprom);
-       shrd->eeprom = NULL;
+       kfree(priv->eeprom);
+       priv->eeprom = NULL;
 }
 
-static void iwl_init_band_reference(const struct iwl_priv *priv,
+static void iwl_init_band_reference(struct iwl_priv *priv,
                        int eep_band, int *eeprom_ch_count,
                        const struct iwl_eeprom_channel **eeprom_ch_info,
                        const u8 **eeprom_ch_index)
 {
-       struct iwl_shared *shrd = priv->shrd;
-       u32 offset = cfg(priv)->lib->
+       u32 offset = priv->lib->
                        eeprom_ops.regulatory_bands[eep_band - 1];
        switch (eep_band) {
        case 1:         /* 2.4GHz band */
                *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_1);
                *eeprom_ch_info = (struct iwl_eeprom_channel *)
-                               iwl_eeprom_query_addr(shrd, offset);
+                               iwl_eeprom_query_addr(priv, offset);
                *eeprom_ch_index = iwl_eeprom_band_1;
                break;
        case 2:         /* 4.9GHz band */
                *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_2);
                *eeprom_ch_info = (struct iwl_eeprom_channel *)
-                               iwl_eeprom_query_addr(shrd, offset);
+                               iwl_eeprom_query_addr(priv, offset);
                *eeprom_ch_index = iwl_eeprom_band_2;
                break;
        case 3:         /* 5.2GHz band */
                *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_3);
                *eeprom_ch_info = (struct iwl_eeprom_channel *)
-                               iwl_eeprom_query_addr(shrd, offset);
+                               iwl_eeprom_query_addr(priv, offset);
                *eeprom_ch_index = iwl_eeprom_band_3;
                break;
        case 4:         /* 5.5GHz band */
                *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_4);
                *eeprom_ch_info = (struct iwl_eeprom_channel *)
-                               iwl_eeprom_query_addr(shrd, offset);
+                               iwl_eeprom_query_addr(priv, offset);
                *eeprom_ch_index = iwl_eeprom_band_4;
                break;
        case 5:         /* 5.7GHz band */
                *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_5);
                *eeprom_ch_info = (struct iwl_eeprom_channel *)
-                               iwl_eeprom_query_addr(shrd, offset);
+                               iwl_eeprom_query_addr(priv, offset);
                *eeprom_ch_index = iwl_eeprom_band_5;
                break;
        case 6:         /* 2.4GHz ht40 channels */
                *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_6);
                *eeprom_ch_info = (struct iwl_eeprom_channel *)
-                               iwl_eeprom_query_addr(shrd, offset);
+                               iwl_eeprom_query_addr(priv, offset);
                *eeprom_ch_index = iwl_eeprom_band_6;
                break;
        case 7:         /* 5 GHz ht40 channels */
                *eeprom_ch_count = ARRAY_SIZE(iwl_eeprom_band_7);
                *eeprom_ch_info = (struct iwl_eeprom_channel *)
-                               iwl_eeprom_query_addr(shrd, offset);
+                               iwl_eeprom_query_addr(priv, offset);
                *eeprom_ch_index = iwl_eeprom_band_7;
                break;
        default:
@@ -987,9 +1043,9 @@ int iwl_init_channel_map(struct iwl_priv *priv)
        }
 
        /* Check if we do have HT40 channels */
-       if (cfg(priv)->lib->eeprom_ops.regulatory_bands[5] ==
+       if (priv->lib->eeprom_ops.regulatory_bands[5] ==
            EEPROM_REGULATORY_BAND_NO_HT40 &&
-           cfg(priv)->lib->eeprom_ops.regulatory_bands[6] ==
+           priv->lib->eeprom_ops.regulatory_bands[6] ==
            EEPROM_REGULATORY_BAND_NO_HT40)
                return 0;
 
@@ -1025,7 +1081,7 @@ int iwl_init_channel_map(struct iwl_priv *priv)
         * driver need to process addition information
         * to determine the max channel tx power limits
         */
-       if (cfg(priv)->lib->eeprom_ops.enhanced_txpower)
+       if (priv->lib->eeprom_ops.enhanced_txpower)
                iwl_eeprom_enhanced_txpower(priv);
 
        return 0;
@@ -1072,7 +1128,7 @@ void iwl_rf_config(struct iwl_priv *priv)
 {
        u16 radio_cfg;
 
-       radio_cfg = iwl_eeprom_query16(priv->shrd, EEPROM_RADIO_CONFIG);
+       radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
 
        /* write radio config values to register */
        if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) <= EEPROM_RF_CONFIG_TYPE_MAX) {
index e4a758340996211f8072c5cdb3223e536741802e..b3a3b1f0fdc4f5f805447a20e9d75b57d1815d10 100644 (file)
@@ -66,8 +66,6 @@
 #include <net/mac80211.h>
 
 struct iwl_priv;
-struct iwl_shared;
-struct iwl_trans;
 
 /*
  * EEPROM access time values:
@@ -306,12 +304,14 @@ struct iwl_eeprom_ops {
 };
 
 
-int iwl_eeprom_init(struct iwl_trans *trans, u32 hw_rev);
-void iwl_eeprom_free(struct iwl_shared *shrd);
-int  iwl_eeprom_check_version(struct iwl_priv *priv);
+int iwl_eeprom_init(struct iwl_priv *priv, u32 hw_rev);
+void iwl_eeprom_free(struct iwl_priv *priv);
+int iwl_eeprom_check_version(struct iwl_priv *priv);
 int iwl_eeprom_init_hw_params(struct iwl_priv *priv);
-const u8 *iwl_eeprom_query_addr(const struct iwl_shared *shrd, size_t offset);
-u16 iwl_eeprom_query16(const struct iwl_shared *shrd, size_t offset);
+u16 iwl_eeprom_calib_version(struct iwl_priv *priv);
+const u8 *iwl_eeprom_query_addr(struct iwl_priv *priv, size_t offset);
+u16 iwl_eeprom_query16(struct iwl_priv *priv, size_t offset);
+void iwl_eeprom_get_mac(struct iwl_priv *priv, u8 *mac);
 int iwl_init_channel_map(struct iwl_priv *priv);
 void iwl_free_channel_map(struct iwl_priv *priv);
 const struct iwl_channel_info *iwl_get_channel_info(
index c924ccb93c8ca566bd9286e50ec440957eaf40bd..e71564053e7f822ac3a1ea8b092512dbf91fe36f 100644 (file)
@@ -93,15 +93,7 @@ struct iwl_ucode_header {
  * new TLV uCode file layout
  *
  * The new TLV file format contains TLVs, that each specify
- * some piece of data. To facilitate "groups", for example
- * different instruction image with different capabilities,
- * bundled with the same init image, an alternative mechanism
- * is provided:
- * When the alternative field is 0, that means that the item
- * is always valid. When it is non-zero, then it is only
- * valid in conjunction with items of the same alternative,
- * in which case the driver (user) selects one alternative
- * to use.
+ * some piece of data.
  */
 
 enum iwl_ucode_tlv_type {
@@ -132,8 +124,7 @@ enum iwl_ucode_tlv_type {
 };
 
 struct iwl_ucode_tlv {
-       __le16 type;            /* see above */
-       __le16 alternative;     /* see comment */
+       __le32 type;            /* see above */
        __le32 length;          /* not including type/length fields */
        u8 data[0];
 };
@@ -152,7 +143,7 @@ struct iwl_tlv_ucode_header {
        u8 human_readable[64];
        __le32 ver;             /* major/minor/API/serial */
        __le32 build;
-       __le64 alternatives;    /* bitmask of valid alternatives */
+       __le64 ignore;
        /*
         * The data contained herein has a TLV layout,
         * see above for the TLV header and types.
index f1c675a2a6f335ae01469598d6c240aeaf326daa..3f82ff4f3afe9bc9592d48d590fb3f9196fb1b21 100644 (file)
@@ -160,7 +160,7 @@ int iwlagn_mac_setup_register(struct iwl_priv *priv,
                     IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
                     IEEE80211_HW_SCAN_WHILE_IDLE;
 
-       if (hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE)
+       if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE)
                hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
                             IEEE80211_HW_SUPPORTS_STATIC_SMPS;
 
@@ -333,7 +333,7 @@ static int iwlagn_mac_start(struct ieee80211_hw *hw)
        return 0;
 }
 
-static void iwlagn_mac_stop(struct ieee80211_hw *hw)
+void iwlagn_mac_stop(struct ieee80211_hw *hw)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
 
@@ -361,9 +361,9 @@ static void iwlagn_mac_stop(struct ieee80211_hw *hw)
        IWL_DEBUG_MAC80211(priv, "leave\n");
 }
 
-static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
-                                     struct ieee80211_vif *vif,
-                                     struct cfg80211_gtk_rekey_data *data)
+void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
+                              struct ieee80211_vif *vif,
+                              struct cfg80211_gtk_rekey_data *data)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
 
@@ -389,8 +389,7 @@ static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
 
 #ifdef CONFIG_PM_SLEEP
 
-static int iwlagn_mac_suspend(struct ieee80211_hw *hw,
-                             struct cfg80211_wowlan *wowlan)
+int iwlagn_mac_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
        struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
@@ -499,7 +498,7 @@ static int iwlagn_mac_resume(struct ieee80211_hw *hw)
 
 #endif
 
-static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
+void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
 
@@ -510,21 +509,21 @@ static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
                dev_kfree_skb_any(skb);
 }
 
-static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
-                                      struct ieee80211_vif *vif,
-                                      struct ieee80211_key_conf *keyconf,
-                                      struct ieee80211_sta *sta,
-                                      u32 iv32, u16 *phase1key)
+void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
+                               struct ieee80211_vif *vif,
+                               struct ieee80211_key_conf *keyconf,
+                               struct ieee80211_sta *sta,
+                               u32 iv32, u16 *phase1key)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
 
        iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key);
 }
 
-static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
-                             struct ieee80211_vif *vif,
-                             struct ieee80211_sta *sta,
-                             struct ieee80211_key_conf *key)
+int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
+                      struct ieee80211_vif *vif,
+                      struct ieee80211_sta *sta,
+                      struct ieee80211_key_conf *key)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
        struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
@@ -624,11 +623,11 @@ static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
        return ret;
 }
 
-static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
-                                  struct ieee80211_vif *vif,
-                                  enum ieee80211_ampdu_mlme_action action,
-                                  struct ieee80211_sta *sta, u16 tid, u16 *ssn,
-                                  u8 buf_size)
+int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
+                           struct ieee80211_vif *vif,
+                           enum ieee80211_ampdu_mlme_action action,
+                           struct ieee80211_sta *sta, u16 tid, u16 *ssn,
+                           u8 buf_size)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
        int ret = -EINVAL;
@@ -637,7 +636,7 @@ static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
        IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
                     sta->addr, tid);
 
-       if (!(hw_params(priv).sku & EEPROM_SKU_CAP_11N_ENABLE))
+       if (!(priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE))
                return -EACCES;
 
        IWL_DEBUG_MAC80211(priv, "enter\n");
@@ -671,7 +670,7 @@ static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
                                     priv->agg_tids_count);
                }
                if (!priv->agg_tids_count &&
-                   hw_params(priv).use_rts_for_aggregation) {
+                   priv->hw_params.use_rts_for_aggregation) {
                        /*
                         * switch off RTS/CTS if it was previously enabled
                         */
@@ -750,11 +749,11 @@ static int iwlagn_mac_sta_remove(struct ieee80211_hw *hw,
        return ret;
 }
 
-static int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
-                               struct ieee80211_vif *vif,
-                               struct ieee80211_sta *sta,
-                               enum ieee80211_sta_state old_state,
-                               enum ieee80211_sta_state new_state)
+int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
+                        struct ieee80211_vif *vif,
+                        struct ieee80211_sta *sta,
+                        enum ieee80211_sta_state old_state,
+                        enum ieee80211_sta_state new_state)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
        struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
@@ -833,8 +832,8 @@ static int iwlagn_mac_sta_state(struct ieee80211_hw *hw,
        return ret;
 }
 
-static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
-                               struct ieee80211_channel_switch *ch_switch)
+void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
+                              struct ieee80211_channel_switch *ch_switch)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
        const struct iwl_channel_info *ch_info;
@@ -867,7 +866,7 @@ static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
        if (!iwl_is_associated_ctx(ctx))
                goto out;
 
-       if (!cfg(priv)->lib->set_channel_switch)
+       if (!priv->lib->set_channel_switch)
                goto out;
 
        ch = channel->hw_value;
@@ -903,7 +902,7 @@ static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
         */
        set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
        priv->switch_channel = cpu_to_le16(ch);
-       if (cfg(priv)->lib->set_channel_switch(priv, ch_switch)) {
+       if (priv->lib->set_channel_switch(priv, ch_switch)) {
                clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
                priv->switch_channel = 0;
                ieee80211_chswitch_done(ctx->vif, false);
@@ -914,10 +913,25 @@ out:
        IWL_DEBUG_MAC80211(priv, "leave\n");
 }
 
-static void iwlagn_configure_filter(struct ieee80211_hw *hw,
-                                   unsigned int changed_flags,
-                                   unsigned int *total_flags,
-                                   u64 multicast)
+void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
+{
+       /*
+        * MULTI-FIXME
+        * See iwlagn_mac_channel_switch.
+        */
+       struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
+
+       if (test_bit(STATUS_EXIT_PENDING, &priv->status))
+               return;
+
+       if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
+               ieee80211_chswitch_done(ctx->vif, is_success);
+}
+
+void iwlagn_configure_filter(struct ieee80211_hw *hw,
+                            unsigned int changed_flags,
+                            unsigned int *total_flags,
+                            u64 multicast)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
        __le32 filter_or = 0, filter_nand = 0;
@@ -964,7 +978,7 @@ static void iwlagn_configure_filter(struct ieee80211_hw *hw,
                        FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
 }
 
-static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
+void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
 
@@ -1091,7 +1105,7 @@ static int iwlagn_mac_remain_on_channel(struct ieee80211_hw *hw,
        return err;
 }
 
-static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
+int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
 
@@ -1108,8 +1122,8 @@ static int iwlagn_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
        return 0;
 }
 
-static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
-                          enum ieee80211_rssi_event rssi_event)
+void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
+                             enum ieee80211_rssi_event rssi_event)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
 
@@ -1133,8 +1147,8 @@ static void iwlagn_mac_rssi_callback(struct ieee80211_hw *hw,
        IWL_DEBUG_MAC80211(priv, "leave\n");
 }
 
-static int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
-                          struct ieee80211_sta *sta, bool set)
+int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
+                      struct ieee80211_sta *sta, bool set)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
 
@@ -1143,9 +1157,9 @@ static int iwlagn_mac_set_tim(struct ieee80211_hw *hw,
        return 0;
 }
 
-static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
-                   struct ieee80211_vif *vif, u16 queue,
-                   const struct ieee80211_tx_queue_params *params)
+int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
+                      struct ieee80211_vif *vif, u16 queue,
+                      const struct ieee80211_tx_queue_params *params)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
        struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
@@ -1187,7 +1201,7 @@ static int iwlagn_mac_conf_tx(struct ieee80211_hw *hw,
        return 0;
 }
 
-static int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw)
+int iwlagn_mac_tx_last_beacon(struct ieee80211_hw *hw)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
 
@@ -1203,8 +1217,7 @@ static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
        return iwlagn_commit_rxon(priv, ctx);
 }
 
-static int iwl_setup_interface(struct iwl_priv *priv,
-                              struct iwl_rxon_context *ctx)
+int iwl_setup_interface(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
 {
        struct ieee80211_vif *vif = ctx->vif;
        int err;
@@ -1307,9 +1320,9 @@ static int iwlagn_mac_add_interface(struct ieee80211_hw *hw,
        return err;
 }
 
-static void iwl_teardown_interface(struct iwl_priv *priv,
-                                  struct ieee80211_vif *vif,
-                                  bool mode_change)
+void iwl_teardown_interface(struct iwl_priv *priv,
+                           struct ieee80211_vif *vif,
+                           bool mode_change)
 {
        struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
 
@@ -1450,9 +1463,9 @@ static int iwlagn_mac_change_interface(struct ieee80211_hw *hw,
        return err;
 }
 
-static int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
-                   struct ieee80211_vif *vif,
-                   struct cfg80211_scan_request *req)
+int iwlagn_mac_hw_scan(struct ieee80211_hw *hw,
+                      struct ieee80211_vif *vif,
+                      struct cfg80211_scan_request *req)
 {
        struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
        int ret;
@@ -1507,7 +1520,7 @@ static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
        iwl_send_add_sta(priv, &cmd, CMD_ASYNC);
 }
 
-static void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
+void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
                           struct ieee80211_vif *vif,
                           enum sta_notify_cmd cmd,
                           struct ieee80211_sta *sta)
index b1fd251e88d5e761e5dcc3dfe45c6c7f10339410..ca947aebb727576200c9e8ae38a14c33d97b4c22 100644 (file)
@@ -125,6 +125,7 @@ struct iwl_fw;
  * @cmd_queue_full: Called when the command queue gets full. Must be atomic.
  * @nic_config: configure NIC, called before firmware is started.
  *     May sleep
+ * @wimax_active: invoked when WiMax becomes active.  Must be atomic.
  */
 struct iwl_op_mode_ops {
        struct iwl_op_mode *(*start)(struct iwl_trans *trans,
@@ -139,6 +140,7 @@ struct iwl_op_mode_ops {
        void (*nic_error)(struct iwl_op_mode *op_mode);
        void (*cmd_queue_full)(struct iwl_op_mode *op_mode);
        void (*nic_config)(struct iwl_op_mode *op_mode);
+       void (*wimax_active)(struct iwl_op_mode *op_mode);
 };
 
 /**
@@ -209,6 +211,11 @@ static inline void iwl_op_mode_nic_config(struct iwl_op_mode *op_mode)
        op_mode->ops->nic_config(op_mode);
 }
 
+static inline void iwl_op_mode_wimax_active(struct iwl_op_mode *op_mode)
+{
+       op_mode->ops->wimax_active(op_mode);
+}
+
 /*****************************************************
 * Op mode layers implementations
 ******************************************************/
index f3e56b04d775810b8840838bce9cbe9e0150d344..754001581340818af4a1f6646906659901932e4e 100644 (file)
 #include <linux/pci.h>
 #include <linux/pci-aspm.h>
 
-#include "iwl-io.h"
 #include "iwl-shared.h"
 #include "iwl-trans.h"
-#include "iwl-csr.h"
 #include "iwl-cfg.h"
 #include "iwl-drv.h"
 #include "iwl-trans.h"
index d65305d08ebf327c8524ccb5df379ff587e0a013..1a791af82d155d232f1668433b93741fcfd8dbcb 100644 (file)
@@ -228,8 +228,24 @@ static u16 channel_id_to_papd(u16 ch_id)
 
 static u16 channel_id_to_txp(struct iwl_phy_db *phy_db, u16 ch_id)
 {
-       /* TODO David*/
-       return 0;
+       struct iwl_phy_db_chg_txp *txp_chg;
+       int i;
+       u8 ch_index = ch_id_to_ch_index(ch_id);
+       if (ch_index == 0xff)
+               return 0xff;
+
+       for (i = 0; i < IWL_NUM_TXP_CH_GROUPS; i++) {
+               txp_chg = (void *)phy_db->calib_ch_group_txp[i].data;
+               if (!txp_chg)
+                       return 0xff;
+               /*
+                * Looking for the first channel group that its max channel is
+                * higher then wanted channel.
+                */
+               if (le16_to_cpu(txp_chg->max_channel_idx) >= ch_index)
+                       return i;
+       }
+       return 0xff;
 }
 
 int iwl_phy_db_get_section_data(struct iwl_phy_db *phy_db,
index ba91a8b28398097709ffac6e9598bb4f89b77b45..5e86305de66aef96491ca2b8af931c5cbd4565b5 100644 (file)
@@ -108,6 +108,12 @@ enum iwl_phy_db_section_type {
        IWL_PHY_DB_MAX
 };
 
+/* for parsing of tx power channel group data that comes from the firmware*/
+struct iwl_phy_db_chg_txp {
+       __le32 space;
+       __le16 max_channel_idx;
+} __packed;
+
 struct iwl_phy_db *iwl_phy_db_init(struct iwl_shared *shrd);
 
 void iwl_phy_db_free(struct iwl_phy_db *phy_db);
index 7bc7a82aba47b73e77d697b12948a73eef41a410..174a0f737214154c2237797e426d02e9cc83ec13 100644 (file)
@@ -268,61 +268,6 @@ static void iwl_power_sleep_cam_cmd(struct iwl_priv *priv,
        IWL_DEBUG_POWER(priv, "Sleep command for CAM\n");
 }
 
-static void iwl_power_fill_sleep_cmd(struct iwl_priv *priv,
-                                    struct iwl_powertable_cmd *cmd,
-                                    int dynps_ms, int wakeup_period)
-{
-       /*
-        * These are the original power level 3 sleep successions. The
-        * device may behave better with such succession and was also
-        * only tested with that. Just like the original sleep commands,
-        * also adjust the succession here to the wakeup_period below.
-        * The ranges are the same as for the sleep commands, 0-2, 3-9
-        * and >10, which is selected based on the DTIM interval for
-        * the sleep index but here we use the wakeup period since that
-        * is what we need to do for the latency requirements.
-        */
-       static const u8 slp_succ_r0[IWL_POWER_VEC_SIZE] = { 2, 2, 2, 2, 2 };
-       static const u8 slp_succ_r1[IWL_POWER_VEC_SIZE] = { 2, 4, 6, 7, 9 };
-       static const u8 slp_succ_r2[IWL_POWER_VEC_SIZE] = { 2, 7, 9, 9, 0xFF };
-       const u8 *slp_succ = slp_succ_r0;
-       int i;
-
-       if (wakeup_period > IWL_DTIM_RANGE_0_MAX)
-               slp_succ = slp_succ_r1;
-       if (wakeup_period > IWL_DTIM_RANGE_1_MAX)
-               slp_succ = slp_succ_r2;
-
-       memset(cmd, 0, sizeof(*cmd));
-
-       cmd->flags = IWL_POWER_DRIVER_ALLOW_SLEEP_MSK |
-                    IWL_POWER_FAST_PD; /* no use seeing frames for others */
-
-       if (priv->power_data.bus_pm)
-               cmd->flags |= IWL_POWER_PCI_PM_MSK;
-
-       if (cfg(priv)->base_params->shadow_reg_enable)
-               cmd->flags |= IWL_POWER_SHADOW_REG_ENA;
-       else
-               cmd->flags &= ~IWL_POWER_SHADOW_REG_ENA;
-
-       if (iwl_advanced_bt_coexist(priv)) {
-               if (!cfg(priv)->bt_params->bt_sco_disable)
-                       cmd->flags |= IWL_POWER_BT_SCO_ENA;
-               else
-                       cmd->flags &= ~IWL_POWER_BT_SCO_ENA;
-       }
-
-       cmd->rx_data_timeout = cpu_to_le32(1000 * dynps_ms);
-       cmd->tx_data_timeout = cpu_to_le32(1000 * dynps_ms);
-
-       for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
-               cmd->sleep_interval[i] =
-                       cpu_to_le32(min_t(int, slp_succ[i], wakeup_period));
-
-       IWL_DEBUG_POWER(priv, "Automatic sleep command\n");
-}
-
 static int iwl_set_power(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd)
 {
        IWL_DEBUG_POWER(priv, "Sending power/sleep command\n");
@@ -363,7 +308,7 @@ static void iwl_power_build_cmd(struct iwl_priv *priv,
                iwl_static_sleep_cmd(priv, cmd,
                                     priv->power_data.debug_sleep_level_override,
                                     dtimper);
-       else if (iwlagn_mod_params.no_sleep_autoadjust) {
+       else {
                if (iwlagn_mod_params.power_level > IWL_POWER_INDEX_1 &&
                    iwlagn_mod_params.power_level <= IWL_POWER_INDEX_5)
                        iwl_static_sleep_cmd(priv, cmd,
@@ -371,10 +316,7 @@ static void iwl_power_build_cmd(struct iwl_priv *priv,
                else
                        iwl_static_sleep_cmd(priv, cmd,
                                IWL_POWER_INDEX_1, dtimper);
-       } else
-               iwl_power_fill_sleep_cmd(priv, cmd,
-                                        priv->hw->conf.dynamic_ps_timeout,
-                                        priv->hw->conf.max_sleep_period);
+       }
 }
 
 int iwl_power_set_mode(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd,
index dcf5b12071b4012ef355791f135e156f883b7219..490a60d8ad7d265875f454219853bb639ec84544 100644 (file)
@@ -673,12 +673,12 @@ static int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
        u16 rx_chain = 0;
        enum ieee80211_band band;
        u8 n_probes = 0;
-       u8 rx_ant = hw_params(priv).valid_rx_ant;
+       u8 rx_ant = priv->hw_params.valid_rx_ant;
        u8 rate;
        bool is_active = false;
        int  chan_mod;
        u8 active_chains;
-       u8 scan_tx_antennas = hw_params(priv).valid_tx_ant;
+       u8 scan_tx_antennas = priv->hw_params.valid_tx_ant;
        int ret;
 
        lockdep_assert_held(&priv->mutex);
@@ -872,7 +872,7 @@ static int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
 
        /* MIMO is not used here, but value is required */
        rx_chain |=
-               hw_params(priv).valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
+               priv->hw_params.valid_rx_ant << RXON_RX_CHAIN_VALID_POS;
        rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
        rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS;
        rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
@@ -985,7 +985,7 @@ static int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
 
 void iwl_init_scan_params(struct iwl_priv *priv)
 {
-       u8 ant_idx = fls(hw_params(priv).valid_tx_ant) - 1;
+       u8 ant_idx = fls(priv->hw_params.valid_tx_ant) - 1;
        if (!priv->scan_tx_ant[IEEE80211_BAND_5GHZ])
                priv->scan_tx_ant[IEEE80211_BAND_5GHZ] = ant_idx;
        if (!priv->scan_tx_ant[IEEE80211_BAND_2GHZ])
index 983b41e43d4be459a06506405c944619364ea0c3..35bd83ce3dae18157e47691c504db6079685ba99 100644 (file)
@@ -70,6 +70,7 @@
 
 #include "iwl-commands.h"
 #include "iwl-fw.h"
+#include "iwl-config.h"
 
 /**
  * DOC: shared area - role and goal
@@ -95,7 +96,6 @@
 
 struct iwl_priv;
 struct iwl_trans;
-struct iwl_sensitivity_ranges;
 struct iwl_trans_ops;
 
 #define DRV_NAME        "iwlwifi"
@@ -118,252 +118,56 @@ extern struct iwl_mod_params iwlagn_mod_params;
  * @disable_11n: disable 11n capabilities, default = 0,
  *     use IWL_DISABLE_HT_* constants
  * @amsdu_size_8K: enable 8K amsdu size, default = 1
- * @antenna: both antennas (use diversity), default = 0
  * @restart_fw: restart firmware, default = 1
  * @plcp_check: enable plcp health check, default = true
- * @ack_check: disable ack health check, default = false
  * @wd_disable: enable stuck queue check, default = 0
  * @bt_coex_active: enable bt coex, default = true
  * @led_mode: system default, default = 0
- * @no_sleep_autoadjust: disable autoadjust, default = true
  * @power_save: disable power save, default = false
  * @power_level: power level, default = 1
  * @debug_level: levels are IWL_DL_*
  * @ant_coupling: antenna coupling in dB, default = 0
  * @bt_ch_announce: BT channel inhibition, default = enable
- * @wanted_ucode_alternative: ucode alternative to use, default = 1
  * @auto_agg: enable agg. without check, default = true
  */
 struct iwl_mod_params {
        int sw_crypto;
        unsigned int disable_11n;
        int amsdu_size_8K;
-       int antenna;
        int restart_fw;
        bool plcp_check;
-       bool ack_check;
        int  wd_disable;
        bool bt_coex_active;
        int led_mode;
-       bool no_sleep_autoadjust;
        bool power_save;
        int power_level;
        u32 debug_level;
        int ant_coupling;
        bool bt_ch_announce;
-       int wanted_ucode_alternative;
        bool auto_agg;
 };
 
-/**
- * struct iwl_hw_params
- *
- * Holds the module parameters
- *
- * @tx_chains_num: Number of TX chains
- * @rx_chains_num: Number of RX chains
- * @valid_tx_ant: usable antennas for TX
- * @valid_rx_ant: usable antennas for RX
- * @ht40_channel: is 40MHz width possible: BIT(IEEE80211_BAND_XXX)
- * @sku: sku read from EEPROM
- * @rx_page_order: Rx buffer page order
- * @ct_kill_threshold: temperature threshold - in hw dependent unit
- * @ct_kill_exit_threshold: when to reeable the device - in hw dependent unit
- *     relevant for 1000, 6000 and up
- * @wd_timeout: TX queues watchdog timeout
- * @struct iwl_sensitivity_ranges: range of sensitivity values
- * @use_rts_for_aggregation: use rts/cts protection for HT traffic
- */
-struct iwl_hw_params {
-       u8  tx_chains_num;
-       u8  rx_chains_num;
-       u8  valid_tx_ant;
-       u8  valid_rx_ant;
-       u8  ht40_channel;
-       bool use_rts_for_aggregation;
-       u16 sku;
-       u32 rx_page_order;
-       u32 ct_kill_threshold;
-       u32 ct_kill_exit_threshold;
-       unsigned int wd_timeout;
-
-       const struct iwl_sensitivity_ranges *sens;
-};
-
-/*
- * LED mode
- *    IWL_LED_DEFAULT:  use device default
- *    IWL_LED_RF_STATE: turn LED on/off based on RF state
- *                     LED ON  = RF ON
- *                     LED OFF = RF OFF
- *    IWL_LED_BLINK:    adjust led blink rate based on blink table
- *    IWL_LED_DISABLE: led disabled
- */
-enum iwl_led_mode {
-       IWL_LED_DEFAULT,
-       IWL_LED_RF_STATE,
-       IWL_LED_BLINK,
-       IWL_LED_DISABLE,
-};
-
-/*
- * @max_ll_items: max number of OTP blocks
- * @shadow_ram_support: shadow support for OTP memory
- * @led_compensation: compensate on the led on/off time per HW according
- *     to the deviation to achieve the desired led frequency.
- *     The detail algorithm is described in iwl-led.c
- * @chain_noise_num_beacons: number of beacons used to compute chain noise
- * @adv_thermal_throttle: support advance thermal throttle
- * @support_ct_kill_exit: support ct kill exit condition
- * @plcp_delta_threshold: plcp error rate threshold used to trigger
- *     radio tuning when there is a high receiving plcp error rate
- * @chain_noise_scale: default chain noise scale used for gain computation
- * @wd_timeout: TX queues watchdog timeout
- * @max_event_log_size: size of event log buffer size for ucode event logging
- * @shadow_reg_enable: HW shadhow register bit
- * @hd_v2: v2 of enhanced sensitivity value, used for 2000 series and up
- * @no_idle_support: do not support idle mode
- * wd_disable: disable watchdog timer
- */
-struct iwl_base_params {
-       int eeprom_size;
-       int num_of_queues;      /* def: HW dependent */
-       /* for iwl_apm_init() */
-       u32 pll_cfg_val;
-
-       const u16 max_ll_items;
-       const bool shadow_ram_support;
-       u16 led_compensation;
-       bool adv_thermal_throttle;
-       bool support_ct_kill_exit;
-       u8 plcp_delta_threshold;
-       s32 chain_noise_scale;
-       unsigned int wd_timeout;
-       u32 max_event_log_size;
-       const bool shadow_reg_enable;
-       const bool hd_v2;
-       const bool no_idle_support;
-       const bool wd_disable;
-};
-
-/*
- * @advanced_bt_coexist: support advanced bt coexist
- * @bt_init_traffic_load: specify initial bt traffic load
- * @bt_prio_boost: default bt priority boost value
- * @agg_time_limit: maximum number of uSec in aggregation
- * @bt_sco_disable: uCode should not response to BT in SCO/ESCO mode
- */
-struct iwl_bt_params {
-       bool advanced_bt_coexist;
-       u8 bt_init_traffic_load;
-       u8 bt_prio_boost;
-       u16 agg_time_limit;
-       bool bt_sco_disable;
-       bool bt_session_2;
-};
-/*
- * @use_rts_for_aggregation: use rts/cts protection for HT traffic
- */
-struct iwl_ht_params {
-       const bool ht_greenfield_support; /* if used set to true */
-       bool use_rts_for_aggregation;
-       enum ieee80211_smps_mode smps_mode;
-};
-
-/**
- * struct iwl_cfg
- * @name: Offical name of the device
- * @fw_name_pre: Firmware filename prefix. The api version and extension
- *     (.ucode) will be added to filename before loading from disk. The
- *     filename is constructed as fw_name_pre<api>.ucode.
- * @ucode_api_max: Highest version of uCode API supported by driver.
- * @ucode_api_ok: oldest version of the uCode API that is OK to load
- *     without a warning, for use in transitions
- * @ucode_api_min: Lowest version of uCode API supported by driver.
- * @max_inst_size: The maximal length of the fw inst section
- * @max_data_size: The maximal length of the fw data section
- * @valid_tx_ant: valid transmit antenna
- * @valid_rx_ant: valid receive antenna
- * @eeprom_ver: EEPROM version
- * @eeprom_calib_ver: EEPROM calibration version
- * @lib: pointer to the lib ops
- * @additional_nic_config: additional nic configuration
- * @base_params: pointer to basic parameters
- * @ht_params: point to ht patameters
- * @bt_params: pointer to bt parameters
- * @need_temp_offset_calib: need to perform temperature offset calibration
- * @no_xtal_calib: some devices do not need crystal calibration data,
- *     don't send it to those
- * @led_mode: 0=blinking, 1=On(RF On)/Off(RF Off)
- * @adv_pm: advance power management
- * @rx_with_siso_diversity: 1x1 device with rx antenna diversity
- * @internal_wimax_coex: internal wifi/wimax combo device
- * @temp_offset_v2: support v2 of temperature offset calibration
- *
- * We enable the driver to be backward compatible wrt. hardware features.
- * API differences in uCode shouldn't be handled here but through TLVs
- * and/or the uCode API version instead.
- */
-struct iwl_cfg {
-       /* params specific to an individual device within a device family */
-       const char *name;
-       const char *fw_name_pre;
-       const unsigned int ucode_api_max;
-       const unsigned int ucode_api_ok;
-       const unsigned int ucode_api_min;
-       const u32 max_data_size;
-       const u32 max_inst_size;
-       u8   valid_tx_ant;
-       u8   valid_rx_ant;
-       u16  eeprom_ver;
-       u16  eeprom_calib_ver;
-       const struct iwl_lib_ops *lib;
-       void (*additional_nic_config)(struct iwl_priv *priv);
-       /* params not likely to change within a device family */
-       const struct iwl_base_params *base_params;
-       /* params likely to change within a device family */
-       const struct iwl_ht_params *ht_params;
-       const struct iwl_bt_params *bt_params;
-       const bool need_temp_offset_calib; /* if used set to true */
-       const bool no_xtal_calib;
-       enum iwl_led_mode led_mode;
-       const bool adv_pm;
-       const bool rx_with_siso_diversity;
-       const bool internal_wimax_coex;
-       const bool temp_offset_v2;
-};
-
 /**
  * struct iwl_shared - shared fields for all the layers of the driver
  *
- * @status: STATUS_*
  * @wowlan: are we running wowlan uCode
  * @bus: pointer to the bus layer data
  * @cfg: see struct iwl_cfg
  * @priv: pointer to the upper layer data
  * @trans: pointer to the transport layer data
  * @nic: pointer to the nic data
- * @hw_params: see struct iwl_hw_params
  * @lock: protect general shared data
  * @eeprom: pointer to the eeprom/OTP image
  */
 struct iwl_shared {
-       unsigned long status;
-
        const struct iwl_cfg *cfg;
        struct iwl_trans *trans;
        void *drv;
-       struct iwl_hw_params hw_params;
-
-       /* eeprom -- this is in the card's little endian byte order */
-       u8 *eeprom;
-
 };
 
 /*Whatever _m is (iwl_trans, iwl_priv, these macros will work */
 #define cfg(_m)                ((_m)->shrd->cfg)
 #define trans(_m)      ((_m)->shrd->trans)
-#define hw_params(_m)  ((_m)->shrd->hw_params)
 
 static inline bool iwl_have_debug_level(u32 level)
 {
@@ -377,33 +181,4 @@ enum iwl_rxon_context_id {
        NUM_IWL_RXON_CTX
 };
 
-int iwlagn_hw_valid_rtc_data_addr(u32 addr);
-const char *get_cmd_string(u8 cmd);
-
-#define IWL_CMD(x) case x: return #x
-
-/*****************************************************
-* DRIVER STATUS FUNCTIONS
-******************************************************/
-#define STATUS_HCMD_ACTIVE     0       /* host command in progress */
-/* 1 is unused (used to be STATUS_HCMD_SYNC_ACTIVE) */
-#define STATUS_INT_ENABLED     2
-#define STATUS_RF_KILL_HW      3
-#define STATUS_CT_KILL         4
-#define STATUS_INIT            5
-#define STATUS_ALIVE           6
-#define STATUS_READY           7
-#define STATUS_TEMPERATURE     8
-#define STATUS_GEO_CONFIGURED  9
-#define STATUS_EXIT_PENDING    10
-#define STATUS_STATISTICS      12
-#define STATUS_SCANNING                13
-#define STATUS_SCAN_ABORTING   14
-#define STATUS_SCAN_HW         15
-#define STATUS_POWER_PMI       16
-#define STATUS_FW_ERROR                17
-#define STATUS_DEVICE_ENABLED  18
-#define STATUS_CHANNEL_SWITCH_PENDING 19
-#define STATUS_SCAN_COMPLETE   20
-
 #endif /* #__iwl_shared_h__ */
index f31a0629c6c672bf2c3c8f5502d2ec18d7299e4a..bb275098bb108869085b414dccf9b06e9dc96b49 100644 (file)
@@ -536,7 +536,7 @@ static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb)
                break;
 
        case IWL_TM_CMD_APP2DEV_GET_EEPROM:
-               if (priv->shrd->eeprom) {
+               if (priv->eeprom) {
                        skb = cfg80211_testmode_alloc_reply_skb(hw->wiphy,
                                cfg(priv)->base_params->eeprom_size + 20);
                        if (!skb) {
@@ -547,7 +547,7 @@ static int iwl_testmode_driver(struct ieee80211_hw *hw, struct nlattr **tb)
                                        IWL_TM_CMD_DEV2APP_EEPROM_RSP) ||
                            nla_put(skb, IWL_TM_ATTR_EEPROM,
                                    cfg(priv)->base_params->eeprom_size,
-                                   priv->shrd->eeprom))
+                                   priv->eeprom))
                                goto nla_put_failure;
                        status = cfg80211_testmode_reply(skb);
                        if (status < 0)
index 32adee3b54e3e315a4d7f6d48b726555f8374d5d..70bdd0e2df3897c09287dc3ab52efc39092e5c3a 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/skbuff.h>
 #include <linux/wait.h>
 #include <linux/pci.h>
+#include <linux/timer.h>
 
 #include "iwl-fh.h"
 #include "iwl-csr.h"
@@ -43,8 +44,6 @@
 #include "iwl-io.h"
 #include "iwl-op-mode.h"
 
-struct iwl_tx_queue;
-struct iwl_queue;
 struct iwl_host_cmd;
 
 /*This file includes the declaration that are internal to the
@@ -140,10 +139,10 @@ struct iwl_cmd_meta {
        /* only for SYNC commands, iff the reply skb is wanted */
        struct iwl_host_cmd *source;
 
-       u32 flags;
-
        DEFINE_DMA_UNMAP_ADDR(mapping);
        DEFINE_DMA_UNMAP_LEN(len);
+
+       u32 flags;
 };
 
 /*
@@ -206,7 +205,8 @@ struct iwl_tx_queue {
        struct iwl_cmd_meta *meta;
        struct sk_buff **skbs;
        spinlock_t lock;
-       unsigned long time_stamp;
+       struct timer_list stuck_timer;
+       struct iwl_trans_pcie *trans_pcie;
        u8 need_update;
        u8 active;
 };
@@ -227,6 +227,9 @@ struct iwl_tx_queue {
  * @ucode_write_waitq: wait queue for uCode load
  * @status - transport specific status flags
  * @cmd_queue - command queue number
+ * @rx_buf_size_8k: 8 kB RX buffer size
+ * @rx_page_order: page order for receive buffer size
+ * @wd_timeout: queue watchdog timeout (jiffies)
  */
 struct iwl_trans_pcie {
        struct iwl_rx_queue rxq;
@@ -266,11 +269,34 @@ struct iwl_trans_pcie {
        u8 no_reclaim_cmds[MAX_NO_RECLAIM_CMDS];
        u8 setup_q_to_fifo[IWL_MAX_HW_QUEUES];
        u8 n_q_to_fifo;
+
+       bool rx_buf_size_8k;
+       u32 rx_page_order;
+
+       const char **command_names;
+
+       /* queue watchdog */
+       unsigned long wd_timeout;
 };
 
+/*****************************************************
+* DRIVER STATUS FUNCTIONS
+******************************************************/
+#define STATUS_HCMD_ACTIVE     0
+#define STATUS_DEVICE_ENABLED  1
+#define STATUS_TPOWER_PMI      2
+#define STATUS_INT_ENABLED     3
+
 #define IWL_TRANS_GET_PCIE_TRANS(_iwl_trans) \
        ((struct iwl_trans_pcie *) ((_iwl_trans)->trans_specific))
 
+static inline struct iwl_trans *
+iwl_trans_pcie_get_trans(struct iwl_trans_pcie *trans_pcie)
+{
+       return container_of((void *)trans_pcie, struct iwl_trans,
+                           trans_specific);
+}
+
 /*****************************************************
 * RX
 ******************************************************/
@@ -392,4 +418,12 @@ static inline u8 get_cmd_index(struct iwl_queue *q, u32 index)
        return index & (q->n_window - 1);
 }
 
+static inline const char *
+trans_pcie_get_cmd_string(struct iwl_trans_pcie *trans_pcie, u8 cmd)
+{
+       if (!trans_pcie->command_names || !trans_pcie->command_names[cmd])
+               return "UNKNOWN";
+       return trans_pcie->command_names[cmd];
+}
+
 #endif /* __iwl_trans_int_pcie_h__ */
index ab0f3fc22b87197c87b6ee0066aa29c9a10d4f85..de78fb8dca9f8b24b6a401bfd878641c91b7f3d6 100644 (file)
@@ -150,7 +150,7 @@ void iwl_rx_queue_update_write_ptr(struct iwl_trans *trans,
                        IWL_TRANS_GET_PCIE_TRANS(trans);
 
                /* If power-saving is in use, make sure device is awake */
-               if (test_bit(STATUS_POWER_PMI, &trans_pcie->status)) {
+               if (test_bit(STATUS_TPOWER_PMI, &trans_pcie->status)) {
                        reg = iwl_read32(trans, CSR_UCODE_DRV_GP1);
 
                        if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
@@ -274,17 +274,17 @@ static void iwlagn_rx_allocate(struct iwl_trans *trans, gfp_t priority)
                if (rxq->free_count > RX_LOW_WATERMARK)
                        gfp_mask |= __GFP_NOWARN;
 
-               if (hw_params(trans).rx_page_order > 0)
+               if (trans_pcie->rx_page_order > 0)
                        gfp_mask |= __GFP_COMP;
 
                /* Alloc a new receive buffer */
                page = alloc_pages(gfp_mask,
-                                 hw_params(trans).rx_page_order);
+                                 trans_pcie->rx_page_order);
                if (!page) {
                        if (net_ratelimit())
                                IWL_DEBUG_INFO(trans, "alloc_pages failed, "
                                           "order: %d\n",
-                                          hw_params(trans).rx_page_order);
+                                          trans_pcie->rx_page_order);
 
                        if ((rxq->free_count <= RX_LOW_WATERMARK) &&
                            net_ratelimit())
@@ -303,7 +303,7 @@ static void iwlagn_rx_allocate(struct iwl_trans *trans, gfp_t priority)
 
                if (list_empty(&rxq->rx_used)) {
                        spin_unlock_irqrestore(&rxq->lock, flags);
-                       __free_pages(page, hw_params(trans).rx_page_order);
+                       __free_pages(page, trans_pcie->rx_page_order);
                        return;
                }
                element = rxq->rx_used.next;
@@ -316,7 +316,7 @@ static void iwlagn_rx_allocate(struct iwl_trans *trans, gfp_t priority)
                rxb->page = page;
                /* Get physical address of the RB */
                rxb->page_dma = dma_map_page(trans->dev, page, 0,
-                               PAGE_SIZE << hw_params(trans).rx_page_order,
+                               PAGE_SIZE << trans_pcie->rx_page_order,
                                DMA_FROM_DEVICE);
                /* dma address must be no more than 36 bits */
                BUG_ON(rxb->page_dma & ~DMA_BIT_MASK(36));
@@ -367,7 +367,7 @@ static void iwl_rx_handle_rxbuf(struct iwl_trans *trans,
        struct iwl_tx_queue *txq = &trans_pcie->txq[trans_pcie->cmd_queue];
        unsigned long flags;
        bool page_stolen = false;
-       int max_len = PAGE_SIZE << hw_params(trans).rx_page_order;
+       int max_len = PAGE_SIZE << trans_pcie->rx_page_order;
        u32 offset = 0;
 
        if (WARN_ON(!rxb))
@@ -393,8 +393,9 @@ static void iwl_rx_handle_rxbuf(struct iwl_trans *trans,
                        break;
 
                IWL_DEBUG_RX(trans, "cmd at offset %d: %s (0x%.2x)\n",
-                            rxcb._offset, get_cmd_string(pkt->hdr.cmd),
-                            pkt->hdr.cmd);
+                       rxcb._offset,
+                       trans_pcie_get_cmd_string(trans_pcie, pkt->hdr.cmd),
+                       pkt->hdr.cmd);
 
                len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
                len += sizeof(u32); /* account for status word */
@@ -452,7 +453,7 @@ static void iwl_rx_handle_rxbuf(struct iwl_trans *trans,
 
        /* page was stolen from us -- free our reference */
        if (page_stolen) {
-               __free_pages(rxb->page, hw_params(trans).rx_page_order);
+               __free_pages(rxb->page, trans_pcie->rx_page_order);
                rxb->page = NULL;
        }
 
@@ -463,7 +464,7 @@ static void iwl_rx_handle_rxbuf(struct iwl_trans *trans,
        if (rxb->page != NULL) {
                rxb->page_dma =
                        dma_map_page(trans->dev, rxb->page, 0,
-                               PAGE_SIZE << hw_params(trans).rx_page_order,
+                               PAGE_SIZE << trans_pcie->rx_page_order,
                                DMA_FROM_DEVICE);
                list_add_tail(&rxb->list, &rxq->rx_free);
                rxq->free_count++;
@@ -547,14 +548,12 @@ static void iwl_irq_handle_error(struct iwl_trans *trans)
                        APMS_CLK_VAL_MRB_FUNC_MODE) ||
             (iwl_read_prph(trans, APMG_PS_CTRL_REG) &
                        APMG_PS_CTRL_VAL_RESET_REQ))) {
-               /*
-                * Keep the restart process from trying to send host
-                * commands by clearing the ready bit.
-                */
-               clear_bit(STATUS_READY, &trans->shrd->status);
-               clear_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status);
+               struct iwl_trans_pcie *trans_pcie;
+
+               trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
+               clear_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status);
+               iwl_op_mode_wimax_active(trans->op_mode);
                wake_up(&trans->wait_command_queue);
-               IWL_ERR(trans, "RF is used by WiMAX\n");
                return;
        }
 
index 4684e2310cd89ac9c4f920e854dce0e78cf5b4b3..918874067bd35df7f7892e4444e14550ee6a5d69 100644 (file)
@@ -107,7 +107,7 @@ void iwl_txq_update_write_ptr(struct iwl_trans *trans, struct iwl_tx_queue *txq)
                struct iwl_trans_pcie *trans_pcie =
                        IWL_TRANS_GET_PCIE_TRANS(trans);
                /* if we're trying to save power */
-               if (test_bit(STATUS_POWER_PMI, &trans_pcie->status)) {
+               if (test_bit(STATUS_TPOWER_PMI, &trans_pcie->status)) {
                        /* wake up nic if it's powered down ...
                         * uCode will wake up, and interrupt us again, so next
                         * time we'll skip this part. */
@@ -605,12 +605,11 @@ static int iwl_enqueue_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
                cmd_dest += cmd->len[i];
        }
 
-       IWL_DEBUG_HC(trans, "Sending command %s (#%x), seq: 0x%04X, "
-                       "%d bytes at %d[%d]:%d\n",
-                       get_cmd_string(out_cmd->hdr.cmd),
-                       out_cmd->hdr.cmd,
-                       le16_to_cpu(out_cmd->hdr.sequence), cmd_size,
-                       q->write_ptr, idx, trans_pcie->cmd_queue);
+       IWL_DEBUG_HC(trans,
+               "Sending command %s (#%x), seq: 0x%04X, %d bytes at %d[%d]:%d\n",
+               trans_pcie_get_cmd_string(trans_pcie, out_cmd->hdr.cmd),
+               out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), cmd_size,
+               q->write_ptr, idx, trans_pcie->cmd_queue);
 
        phys_addr = dma_map_single(trans->dev, &out_cmd->hdr, copy_size,
                                DMA_BIDIRECTIONAL);
@@ -668,6 +667,10 @@ static int iwl_enqueue_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
                               trace_bufs[2], trace_lens[2]);
 #endif
 
+       /* start timer if queue currently empty */
+       if (q->read_ptr == q->write_ptr && trans_pcie->wd_timeout)
+               mod_timer(&txq->stuck_timer, jiffies + trans_pcie->wd_timeout);
+
        /* Increment and update queue's write index */
        q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
        iwl_txq_update_write_ptr(trans, txq);
@@ -677,6 +680,22 @@ static int iwl_enqueue_hcmd(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
        return idx;
 }
 
+static inline void iwl_queue_progress(struct iwl_trans_pcie *trans_pcie,
+                                     struct iwl_tx_queue *txq)
+{
+       if (!trans_pcie->wd_timeout)
+               return;
+
+       /*
+        * if empty delete timer, otherwise move timer forward
+        * since we're making progress on this queue
+        */
+       if (txq->q.read_ptr == txq->q.write_ptr)
+               del_timer(&txq->stuck_timer);
+       else
+               mod_timer(&txq->stuck_timer, jiffies + trans_pcie->wd_timeout);
+}
+
 /**
  * iwl_hcmd_queue_reclaim - Reclaim TX command queue entries already Tx'd
  *
@@ -711,6 +730,8 @@ static void iwl_hcmd_queue_reclaim(struct iwl_trans *trans, int txq_id,
                }
 
        }
+
+       iwl_queue_progress(trans_pcie, txq);
 }
 
 /**
@@ -754,8 +775,6 @@ void iwl_tx_cmd_complete(struct iwl_trans *trans, struct iwl_rx_cmd_buffer *rxb,
        cmd = txq->cmd[cmd_index];
        meta = &txq->meta[cmd_index];
 
-       txq->time_stamp = jiffies;
-
        iwlagn_unmap_tfd(trans, meta, &txq->tfds[index],
                         DMA_BIDIRECTIONAL);
 
@@ -765,21 +784,23 @@ void iwl_tx_cmd_complete(struct iwl_trans *trans, struct iwl_rx_cmd_buffer *rxb,
 
                meta->source->resp_pkt = pkt;
                meta->source->_rx_page_addr = (unsigned long)page_address(p);
-               meta->source->_rx_page_order = hw_params(trans).rx_page_order;
+               meta->source->_rx_page_order = trans_pcie->rx_page_order;
                meta->source->handler_status = handler_status;
        }
 
        iwl_hcmd_queue_reclaim(trans, txq_id, index);
 
        if (!(meta->flags & CMD_ASYNC)) {
-               if (!test_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status)) {
+               if (!test_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status)) {
                        IWL_WARN(trans,
                                 "HCMD_ACTIVE already clear for command %s\n",
-                                get_cmd_string(cmd->hdr.cmd));
+                                trans_pcie_get_cmd_string(trans_pcie,
+                                                          cmd->hdr.cmd));
                }
-               clear_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status);
+               clear_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status);
                IWL_DEBUG_INFO(trans, "Clearing HCMD_ACTIVE for command %s\n",
-                              get_cmd_string(cmd->hdr.cmd));
+                              trans_pcie_get_cmd_string(trans_pcie,
+                                                        cmd->hdr.cmd));
                wake_up(&trans->wait_command_queue);
        }
 
@@ -792,6 +813,7 @@ void iwl_tx_cmd_complete(struct iwl_trans *trans, struct iwl_rx_cmd_buffer *rxb,
 
 static int iwl_send_cmd_async(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
 {
+       struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
        int ret;
 
        /* An asynchronous command can not expect an SKB to be set. */
@@ -803,7 +825,7 @@ static int iwl_send_cmd_async(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
        if (ret < 0) {
                IWL_ERR(trans,
                        "Error sending %s: enqueue_hcmd failed: %d\n",
-                         get_cmd_string(cmd->id), ret);
+                       trans_pcie_get_cmd_string(trans_pcie, cmd->id), ret);
                return ret;
        }
        return 0;
@@ -816,49 +838,51 @@ static int iwl_send_cmd_sync(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
        int ret;
 
        IWL_DEBUG_INFO(trans, "Attempting to send sync command %s\n",
-                       get_cmd_string(cmd->id));
+                      trans_pcie_get_cmd_string(trans_pcie, cmd->id));
 
        if (WARN_ON(test_and_set_bit(STATUS_HCMD_ACTIVE,
-                                    &trans->shrd->status))) {
+                                    &trans_pcie->status))) {
                IWL_ERR(trans, "Command %s: a command is already active!\n",
-                       get_cmd_string(cmd->id));
+                       trans_pcie_get_cmd_string(trans_pcie, cmd->id));
                return -EIO;
        }
 
        IWL_DEBUG_INFO(trans, "Setting HCMD_ACTIVE for command %s\n",
-                       get_cmd_string(cmd->id));
+                      trans_pcie_get_cmd_string(trans_pcie, cmd->id));
 
        cmd_idx = iwl_enqueue_hcmd(trans, cmd);
        if (cmd_idx < 0) {
                ret = cmd_idx;
-               clear_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status);
+               clear_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status);
                IWL_ERR(trans,
                        "Error sending %s: enqueue_hcmd failed: %d\n",
-                         get_cmd_string(cmd->id), ret);
+                       trans_pcie_get_cmd_string(trans_pcie, cmd->id), ret);
                return ret;
        }
 
        ret = wait_event_timeout(trans->wait_command_queue,
-                       !test_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status),
+                       !test_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status),
                        HOST_COMPLETE_TIMEOUT);
        if (!ret) {
-               if (test_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status)) {
+               if (test_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status)) {
                        struct iwl_tx_queue *txq =
                                &trans_pcie->txq[trans_pcie->cmd_queue];
                        struct iwl_queue *q = &txq->q;
 
                        IWL_ERR(trans,
                                "Error sending %s: time out after %dms.\n",
-                               get_cmd_string(cmd->id),
+                               trans_pcie_get_cmd_string(trans_pcie, cmd->id),
                                jiffies_to_msecs(HOST_COMPLETE_TIMEOUT));
 
                        IWL_ERR(trans,
                                "Current CMD queue read_ptr %d write_ptr %d\n",
                                q->read_ptr, q->write_ptr);
 
-                       clear_bit(STATUS_HCMD_ACTIVE, &trans->shrd->status);
-                       IWL_DEBUG_INFO(trans, "Clearing HCMD_ACTIVE for command"
-                                "%s\n", get_cmd_string(cmd->id));
+                       clear_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status);
+                       IWL_DEBUG_INFO(trans,
+                                      "Clearing HCMD_ACTIVE for command %s\n",
+                                      trans_pcie_get_cmd_string(trans_pcie,
+                                                                cmd->id));
                        ret = -ETIMEDOUT;
                        goto cancel;
                }
@@ -866,7 +890,7 @@ static int iwl_send_cmd_sync(struct iwl_trans *trans, struct iwl_host_cmd *cmd)
 
        if ((cmd->flags & CMD_WANT_SKB) && !cmd->resp_pkt) {
                IWL_ERR(trans, "Error: Response NULL in '%s'\n",
-                         get_cmd_string(cmd->id));
+                       trans_pcie_get_cmd_string(trans_pcie, cmd->id));
                ret = -EIO;
                goto cancel;
        }
@@ -949,5 +973,8 @@ int iwl_tx_queue_reclaim(struct iwl_trans *trans, int txq_id, int index,
                iwlagn_txq_free_tfd(trans, txq, txq->q.read_ptr, DMA_TO_DEVICE);
                freed++;
        }
+
+       iwl_queue_progress(trans_pcie, txq);
+
        return freed;
 }
index 9f62283504e35b046ab277e14d127e882949184f..14a32c420fd49c38ddd120bf39e9973dc8bf9357 100644 (file)
@@ -132,10 +132,10 @@ static void iwl_trans_rxq_free_rx_bufs(struct iwl_trans *trans)
                 * to an SKB, so we need to unmap and free potential storage */
                if (rxq->pool[i].page != NULL) {
                        dma_unmap_page(trans->dev, rxq->pool[i].page_dma,
-                               PAGE_SIZE << hw_params(trans).rx_page_order,
+                               PAGE_SIZE << trans_pcie->rx_page_order,
                                DMA_FROM_DEVICE);
                        __free_pages(rxq->pool[i].page,
-                                    hw_params(trans).rx_page_order);
+                                    trans_pcie->rx_page_order);
                        rxq->pool[i].page = NULL;
                }
                list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
@@ -145,11 +145,12 @@ static void iwl_trans_rxq_free_rx_bufs(struct iwl_trans *trans)
 static void iwl_trans_rx_hw_init(struct iwl_trans *trans,
                                 struct iwl_rx_queue *rxq)
 {
+       struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
        u32 rb_size;
        const u32 rfdnlog = RX_QUEUE_SIZE_LOG; /* 256 RBDs */
        u32 rb_timeout = RX_RB_TIMEOUT; /* FIXME: RX_RB_TIMEOUT for all devices? */
 
-       if (iwlagn_mod_params.amsdu_size_8K)
+       if (trans_pcie->rx_buf_size_8k)
                rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
        else
                rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
@@ -298,6 +299,33 @@ static inline void iwlagn_free_dma_ptr(struct iwl_trans *trans,
        memset(ptr, 0, sizeof(*ptr));
 }
 
+static void iwl_trans_pcie_queue_stuck_timer(unsigned long data)
+{
+       struct iwl_tx_queue *txq = (void *)data;
+       struct iwl_trans_pcie *trans_pcie = txq->trans_pcie;
+       struct iwl_trans *trans = iwl_trans_pcie_get_trans(trans_pcie);
+
+       spin_lock(&txq->lock);
+       /* check if triggered erroneously */
+       if (txq->q.read_ptr == txq->q.write_ptr) {
+               spin_unlock(&txq->lock);
+               return;
+       }
+       spin_unlock(&txq->lock);
+
+
+       IWL_ERR(trans, "Queue %d stuck for %u ms.\n", txq->q.id,
+               jiffies_to_msecs(trans_pcie->wd_timeout));
+       IWL_ERR(trans, "Current SW read_ptr %d write_ptr %d\n",
+               txq->q.read_ptr, txq->q.write_ptr);
+       IWL_ERR(trans, "Current HW read_ptr %d write_ptr %d\n",
+               iwl_read_prph(trans, SCD_QUEUE_RDPTR(txq->q.id))
+                                       & (TFD_QUEUE_SIZE_MAX - 1),
+               iwl_read_prph(trans, SCD_QUEUE_WRPTR(txq->q.id)));
+
+       iwl_op_mode_nic_error(trans->op_mode);
+}
+
 static int iwl_trans_txq_alloc(struct iwl_trans *trans,
                                struct iwl_tx_queue *txq, int slots_num,
                                u32 txq_id)
@@ -309,6 +337,10 @@ static int iwl_trans_txq_alloc(struct iwl_trans *trans,
        if (WARN_ON(txq->meta || txq->cmd || txq->skbs || txq->tfds))
                return -EINVAL;
 
+       setup_timer(&txq->stuck_timer, iwl_trans_pcie_queue_stuck_timer,
+                   (unsigned long)txq);
+       txq->trans_pcie = trans_pcie;
+
        txq->q.n_window = slots_num;
 
        txq->meta = kcalloc(slots_num, sizeof(txq->meta[0]), GFP_KERNEL);
@@ -471,6 +503,8 @@ static void iwl_tx_queue_free(struct iwl_trans *trans, int txq_id)
        txq->cmd = NULL;
        txq->meta = NULL;
 
+       del_timer_sync(&txq->stuck_timer);
+
        /* 0-fill queue descriptor structure */
        memset(txq, 0, sizeof(*txq));
 }
@@ -1214,6 +1248,12 @@ static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
 
        /* stop and reset the on-board processor */
        iwl_write32(trans, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
+
+       /* clear all status bits */
+       clear_bit(STATUS_HCMD_ACTIVE, &trans_pcie->status);
+       clear_bit(STATUS_INT_ENABLED, &trans_pcie->status);
+       clear_bit(STATUS_DEVICE_ENABLED, &trans_pcie->status);
+       clear_bit(STATUS_TPOWER_PMI, &trans_pcie->status);
 }
 
 static void iwl_trans_pcie_wowlan_suspend(struct iwl_trans *trans)
@@ -1346,6 +1386,10 @@ static int iwl_trans_pcie_tx(struct iwl_trans *trans, struct sk_buff *skb,
                             &dev_cmd->hdr, firstlen,
                             skb->data + hdr_len, secondlen);
 
+       /* start timer if queue currently empty */
+       if (q->read_ptr == q->write_ptr && trans_pcie->wd_timeout)
+               mod_timer(&txq->stuck_timer, jiffies + trans_pcie->wd_timeout);
+
        /* Tell device the write index *just past* this latest filled TFD */
        q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
        iwl_txq_update_write_ptr(trans, txq);
@@ -1441,8 +1485,6 @@ static void iwl_trans_pcie_reclaim(struct iwl_trans *trans, int txq_id, int ssn,
 
        spin_lock(&txq->lock);
 
-       txq->time_stamp = jiffies;
-
        if (txq->q.read_ptr != tfd_num) {
                IWL_DEBUG_TX_REPLY(trans, "[Q %d] %d -> %d (%d)\n",
                                   txq_id, txq->q.read_ptr, tfd_num, ssn);
@@ -1493,6 +1535,17 @@ static void iwl_trans_pcie_configure(struct iwl_trans *trans,
 
        memcpy(trans_pcie->setup_q_to_fifo, trans_cfg->queue_to_fifo,
               trans_pcie->n_q_to_fifo * sizeof(u8));
+
+       trans_pcie->rx_buf_size_8k = trans_cfg->rx_buf_size_8k;
+       if (trans_pcie->rx_buf_size_8k)
+               trans_pcie->rx_page_order = get_order(8 * 1024);
+       else
+               trans_pcie->rx_page_order = get_order(4 * 1024);
+
+       trans_pcie->wd_timeout =
+               msecs_to_jiffies(trans_cfg->queue_watchdog_timeout);
+
+       trans_pcie->command_names = trans_cfg->command_names;
 }
 
 static void iwl_trans_pcie_free(struct iwl_trans *trans)
@@ -1523,9 +1576,9 @@ static void iwl_trans_pcie_set_pmi(struct iwl_trans *trans, bool state)
        struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
 
        if (state)
-               set_bit(STATUS_POWER_PMI, &trans_pcie->status);
+               set_bit(STATUS_TPOWER_PMI, &trans_pcie->status);
        else
-               clear_bit(STATUS_POWER_PMI, &trans_pcie->status);
+               clear_bit(STATUS_TPOWER_PMI, &trans_pcie->status);
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -1582,42 +1635,9 @@ static int iwl_trans_pcie_wait_tx_queue_empty(struct iwl_trans *trans)
        return ret;
 }
 
-/*
- * On every watchdog tick we check (latest) time stamp. If it does not
- * change during timeout period and queue is not empty we reset firmware.
- */
-static int iwl_trans_pcie_check_stuck_queue(struct iwl_trans *trans, int cnt)
-{
-       struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
-       struct iwl_tx_queue *txq = &trans_pcie->txq[cnt];
-       struct iwl_queue *q = &txq->q;
-       unsigned long timeout;
-
-       if (q->read_ptr == q->write_ptr) {
-               txq->time_stamp = jiffies;
-               return 0;
-       }
-
-       timeout = txq->time_stamp +
-                 msecs_to_jiffies(hw_params(trans).wd_timeout);
-
-       if (time_after(jiffies, timeout)) {
-               IWL_ERR(trans, "Queue %d stuck for %u ms.\n", q->id,
-                       hw_params(trans).wd_timeout);
-               IWL_ERR(trans, "Current SW read_ptr %d write_ptr %d\n",
-                       q->read_ptr, q->write_ptr);
-               IWL_ERR(trans, "Current HW read_ptr %d write_ptr %d\n",
-                       iwl_read_prph(trans, SCD_QUEUE_RDPTR(cnt))
-                               & (TFD_QUEUE_SIZE_MAX - 1),
-                       iwl_read_prph(trans, SCD_QUEUE_WRPTR(cnt)));
-               return 1;
-       }
-
-       return 0;
-}
-
 static const char *get_fh_string(int cmd)
 {
+#define IWL_CMD(x) case x: return #x
        switch (cmd) {
        IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
        IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
@@ -1631,6 +1651,7 @@ static const char *get_fh_string(int cmd)
        default:
                return "UNKNOWN";
        }
+#undef IWL_CMD
 }
 
 int iwl_dump_fh(struct iwl_trans *trans, char **buf, bool display)
@@ -1679,6 +1700,7 @@ int iwl_dump_fh(struct iwl_trans *trans, char **buf, bool display)
 
 static const char *get_csr_string(int cmd)
 {
+#define IWL_CMD(x) case x: return #x
        switch (cmd) {
        IWL_CMD(CSR_HW_IF_CONFIG_REG);
        IWL_CMD(CSR_INT_COALESCING);
@@ -1706,6 +1728,7 @@ static const char *get_csr_string(int cmd)
        default:
                return "UNKNOWN";
        }
+#undef IWL_CMD
 }
 
 void iwl_dump_csr(struct iwl_trans *trans)
@@ -1983,11 +2006,26 @@ static ssize_t iwl_dbgfs_fh_reg_read(struct file *file,
        return ret;
 }
 
+static ssize_t iwl_dbgfs_fw_restart_write(struct file *file,
+                                         const char __user *user_buf,
+                                         size_t count, loff_t *ppos)
+{
+       struct iwl_trans *trans = file->private_data;
+
+       if (!trans->op_mode)
+               return -EAGAIN;
+
+       iwl_op_mode_nic_error(trans->op_mode);
+
+       return count;
+}
+
 DEBUGFS_READ_WRITE_FILE_OPS(interrupt);
 DEBUGFS_READ_FILE_OPS(fh_reg);
 DEBUGFS_READ_FILE_OPS(rx_queue);
 DEBUGFS_READ_FILE_OPS(tx_queue);
 DEBUGFS_WRITE_FILE_OPS(csr);
+DEBUGFS_WRITE_FILE_OPS(fw_restart);
 
 /*
  * Create the debugfs files and directories
@@ -2001,6 +2039,7 @@ static int iwl_trans_pcie_dbgfs_register(struct iwl_trans *trans,
        DEBUGFS_ADD_FILE(interrupt, dir, S_IWUSR | S_IRUSR);
        DEBUGFS_ADD_FILE(csr, dir, S_IWUSR);
        DEBUGFS_ADD_FILE(fh_reg, dir, S_IRUSR);
+       DEBUGFS_ADD_FILE(fw_restart, dir, S_IWUSR);
        return 0;
 }
 #else
@@ -2032,7 +2071,6 @@ const struct iwl_trans_ops trans_ops_pcie = {
        .dbgfs_register = iwl_trans_pcie_dbgfs_register,
 
        .wait_tx_queue_empty = iwl_trans_pcie_wait_tx_queue_empty,
-       .check_stuck_queue = iwl_trans_pcie_check_stuck_queue,
 
 #ifdef CONFIG_PM_SLEEP
        .suspend = iwl_trans_pcie_suspend,
index 66c54c1b404ed696e56ea0977b6eea78be1797cc..f3496a0490f0a1d194b3d1ffbedf30cb432b1dd9 100644 (file)
@@ -305,6 +305,12 @@ static inline struct page *rxb_steal_page(struct iwl_rx_cmd_buffer *r)
  *     list of such notifications to filter. Max length is
  *     %MAX_NO_RECLAIM_CMDS.
  * @n_no_reclaim_cmds: # of commands in list
+ * @rx_buf_size_8k: 8 kB RX buffer size needed for A-MSDUs,
+ *     if unset 4k will be the RX buffer size
+ * @queue_watchdog_timeout: time (in ms) after which queues
+ *     are considered stuck and will trigger device restart
+ * @command_names: array of command names, must be 256 entries
+ *     (one for each command); for debugging only
  */
 struct iwl_trans_config {
        struct iwl_op_mode *op_mode;
@@ -314,6 +320,10 @@ struct iwl_trans_config {
        u8 cmd_queue;
        const u8 *no_reclaim_cmds;
        int n_no_reclaim_cmds;
+
+       bool rx_buf_size_8k;
+       unsigned int queue_watchdog_timeout;
+       const char **command_names;
 };
 
 /**
@@ -351,7 +361,6 @@ struct iwl_trans_config {
  *     irq, tasklet etc... From this point on, the device may not issue
  *     any interrupt (incl. RFKILL).
  *     May sleep
- * @check_stuck_queue: check if a specific queue is stuck
  * @wait_tx_queue_empty: wait until all tx queues are empty
  *     May sleep
  * @dbgfs_register: add the dbgfs files under this directory. Files will be
@@ -390,7 +399,6 @@ struct iwl_trans_ops {
        void (*free)(struct iwl_trans *trans);
 
        int (*dbgfs_register)(struct iwl_trans *trans, struct dentry* dir);
-       int (*check_stuck_queue)(struct iwl_trans *trans, int q);
        int (*wait_tx_queue_empty)(struct iwl_trans *trans);
 #ifdef CONFIG_PM_SLEEP
        int (*suspend)(struct iwl_trans *trans);
@@ -426,7 +434,6 @@ enum iwl_trans_state {
  * @hw_id: a u32 with the ID of the device / subdevice.
  *     Set during transport allocation.
  * @hw_id_str: a string with info about HW ID. Set during transport allocation.
- * @nvm_device_type: indicates OTP or eeprom
  * @pm_support: set to true in start_hw if link pm is supported
  * @wait_command_queue: the wait_queue for SYNC host commands
  */
@@ -442,7 +449,6 @@ struct iwl_trans {
        u32 hw_id;
        char hw_id_str[52];
 
-       int    nvm_device_type;
        bool pm_support;
 
        wait_queue_head_t wait_command_queue;
@@ -573,13 +579,6 @@ static inline int iwl_trans_wait_tx_queue_empty(struct iwl_trans *trans)
        return trans->ops->wait_tx_queue_empty(trans);
 }
 
-static inline int iwl_trans_check_stuck_queue(struct iwl_trans *trans, int q)
-{
-       WARN_ONCE(trans->state != IWL_TRANS_FW_ALIVE,
-                 "%s bad state = %d", __func__, trans->state);
-
-       return trans->ops->check_stuck_queue(trans, q);
-}
 static inline int iwl_trans_dbgfs_register(struct iwl_trans *trans,
                                            struct dentry *dir)
 {
index ba7c9f883cb6804f68bdc032a546f85ded1e40d6..539171945610cbc508f4c46d08f716e2884cd542 100644 (file)
@@ -62,7 +62,7 @@ static int iwl_set_Xtal_calib(struct iwl_priv *priv)
 {
        struct iwl_calib_xtal_freq_cmd cmd;
        __le16 *xtal_calib =
-               (__le16 *)iwl_eeprom_query_addr(priv->shrd, EEPROM_XTAL);
+               (__le16 *)iwl_eeprom_query_addr(priv, EEPROM_XTAL);
 
        iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD);
        cmd.cap_pin1 = le16_to_cpu(xtal_calib[0]);
@@ -74,8 +74,7 @@ static int iwl_set_temperature_offset_calib(struct iwl_priv *priv)
 {
        struct iwl_calib_temperature_offset_cmd cmd;
        __le16 *offset_calib =
-               (__le16 *)iwl_eeprom_query_addr(priv->shrd,
-                                               EEPROM_RAW_TEMPERATURE);
+               (__le16 *)iwl_eeprom_query_addr(priv, EEPROM_RAW_TEMPERATURE);
 
        memset(&cmd, 0, sizeof(cmd));
        iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
@@ -91,16 +90,15 @@ static int iwl_set_temperature_offset_calib(struct iwl_priv *priv)
 static int iwl_set_temperature_offset_calib_v2(struct iwl_priv *priv)
 {
        struct iwl_calib_temperature_offset_v2_cmd cmd;
-       __le16 *offset_calib_high = (__le16 *)iwl_eeprom_query_addr(priv->shrd,
+       __le16 *offset_calib_high = (__le16 *)iwl_eeprom_query_addr(priv,
                                     EEPROM_KELVIN_TEMPERATURE);
        __le16 *offset_calib_low =
-               (__le16 *)iwl_eeprom_query_addr(priv->shrd,
-                                               EEPROM_RAW_TEMPERATURE);
+               (__le16 *)iwl_eeprom_query_addr(priv, EEPROM_RAW_TEMPERATURE);
        struct iwl_eeprom_calib_hdr *hdr;
 
        memset(&cmd, 0, sizeof(cmd));
        iwl_set_calib_hdr(&cmd.hdr, IWL_PHY_CALIBRATE_TEMP_OFFSET_CMD);
-       hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv->shrd,
+       hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
                                                        EEPROM_CALIB_ALL);
        memcpy(&cmd.radio_sensor_offset_high, offset_calib_high,
                sizeof(*offset_calib_high));
@@ -180,7 +178,7 @@ int iwl_init_alive_start(struct iwl_priv *priv)
        return 0;
 }
 
-static int iwl_send_wimax_coex(struct iwl_priv *priv)
+int iwl_send_wimax_coex(struct iwl_priv *priv)
 {
        struct iwl_wimax_coex_cmd coex_cmd;
 
index f7d01bfa2e4a1ccd8046607457b32639037cb7cc..eac72f7bd341f7463f1f3d9e7cc28f201c76f714 100644 (file)
@@ -6,6 +6,7 @@ libertas-y += ethtool.o
 libertas-y += main.o
 libertas-y += rx.o
 libertas-y += tx.o
+libertas-y += firmware.o
 libertas-$(CONFIG_LIBERTAS_MESH) += mesh.o
 
 usb8xxx-objs += if_usb.o
index bc951ab4b6818954c756d6da0c0455915757a31d..84a3aa7ac5705c300e11fad5df4cccde1405101d 100644 (file)
@@ -18,6 +18,10 @@ struct lbs_fw_table {
        const char *fwname;
 };
 
+struct lbs_private;
+typedef void (*lbs_fw_cb)(struct lbs_private *priv, int ret,
+               const struct firmware *helper, const struct firmware *mainfw);
+
 struct lbs_private;
 struct sk_buff;
 struct net_device;
@@ -66,10 +70,13 @@ int lbs_exit_auto_deep_sleep(struct lbs_private *priv);
 u32 lbs_fw_index_to_data_rate(u8 index);
 u8 lbs_data_rate_to_fw_index(u32 rate);
 
-int lbs_get_firmware(struct device *dev, const char *user_helper,
-                       const char *user_mainfw, u32 card_model,
+int lbs_get_firmware(struct device *dev, u32 card_model,
                        const struct lbs_fw_table *fw_table,
                        const struct firmware **helper,
                        const struct firmware **mainfw);
+int lbs_get_firmware_async(struct lbs_private *priv, struct device *device,
+                          u32 card_model, const struct lbs_fw_table *fw_table,
+                          lbs_fw_cb callback);
+void lbs_wait_for_firmware_load(struct lbs_private *priv);
 
 #endif
index f3fd447131c2c9d20ffa84b52a5ffff20ee7f233..672005430acab75e0b650bda1a490245e79d2167 100644 (file)
@@ -7,6 +7,7 @@
 #define _LBS_DEV_H_
 
 #include "defs.h"
+#include "decl.h"
 #include "host.h"
 
 #include <linux/kfifo.h>
@@ -180,6 +181,15 @@ struct lbs_private {
        wait_queue_head_t scan_q;
        /* Whether the scan was initiated internally and not by cfg80211 */
        bool internal_scan;
+
+       /* Firmware load */
+       u32 fw_model;
+       wait_queue_head_t fw_waitq;
+       struct device *fw_device;
+       const struct firmware *helper_fw;
+       const struct lbs_fw_table *fw_table;
+       const struct lbs_fw_table *fw_iter;
+       lbs_fw_cb fw_callback;
 };
 
 extern struct cmd_confirm_sleep confirm_sleep;
diff --git a/drivers/net/wireless/libertas/firmware.c b/drivers/net/wireless/libertas/firmware.c
new file mode 100644 (file)
index 0000000..cd23f1a
--- /dev/null
@@ -0,0 +1,222 @@
+/*
+ * Firmware loading and handling functions.
+ */
+
+#include <linux/firmware.h>
+#include <linux/firmware.h>
+#include <linux/module.h>
+
+#include "dev.h"
+#include "decl.h"
+
+static void load_next_firmware_from_table(struct lbs_private *private);
+
+static void lbs_fw_loaded(struct lbs_private *priv, int ret,
+       const struct firmware *helper, const struct firmware *mainfw)
+{
+       unsigned long flags;
+
+       lbs_deb_fw("firmware load complete, code %d\n", ret);
+
+       /* User must free helper/mainfw */
+       priv->fw_callback(priv, ret, helper, mainfw);
+
+       spin_lock_irqsave(&priv->driver_lock, flags);
+       priv->fw_callback = NULL;
+       wake_up(&priv->fw_waitq);
+       spin_unlock_irqrestore(&priv->driver_lock, flags);
+}
+
+static void do_load_firmware(struct lbs_private *priv, const char *name,
+       void (*cb)(const struct firmware *fw, void *context))
+{
+       int ret;
+
+       lbs_deb_fw("Requesting %s\n", name);
+       ret = request_firmware_nowait(THIS_MODULE, true, name,
+                       priv->fw_device, GFP_KERNEL, priv, cb);
+       if (ret) {
+               lbs_deb_fw("request_firmware_nowait error %d\n", ret);
+               lbs_fw_loaded(priv, ret, NULL, NULL);
+       }
+}
+
+static void main_firmware_cb(const struct firmware *firmware, void *context)
+{
+       struct lbs_private *priv = context;
+
+       if (!firmware) {
+               /* Failed to find firmware: try next table entry */
+               load_next_firmware_from_table(priv);
+               return;
+       }
+
+       /* Firmware found! */
+       lbs_fw_loaded(priv, 0, priv->helper_fw, firmware);
+}
+
+static void helper_firmware_cb(const struct firmware *firmware, void *context)
+{
+       struct lbs_private *priv = context;
+
+       if (!firmware) {
+               /* Failed to find firmware: try next table entry */
+               load_next_firmware_from_table(priv);
+               return;
+       }
+
+       /* Firmware found! */
+       if (priv->fw_iter->fwname) {
+               priv->helper_fw = firmware;
+               do_load_firmware(priv, priv->fw_iter->fwname, main_firmware_cb);
+       } else {
+               /* No main firmware needed for this helper --> success! */
+               lbs_fw_loaded(priv, 0, firmware, NULL);
+       }
+}
+
+static void load_next_firmware_from_table(struct lbs_private *priv)
+{
+       const struct lbs_fw_table *iter;
+
+       if (!priv->fw_iter)
+               iter = priv->fw_table;
+       else
+               iter = ++priv->fw_iter;
+
+       if (priv->helper_fw) {
+               release_firmware(priv->helper_fw);
+               priv->helper_fw = NULL;
+       }
+
+next:
+       if (!iter->helper) {
+               /* End of table hit. */
+               lbs_fw_loaded(priv, -ENOENT, NULL, NULL);
+               return;
+       }
+
+       if (iter->model != priv->fw_model) {
+               iter++;
+               goto next;
+       }
+
+       priv->fw_iter = iter;
+       do_load_firmware(priv, iter->helper, helper_firmware_cb);
+}
+
+void lbs_wait_for_firmware_load(struct lbs_private *priv)
+{
+       wait_event(priv->fw_waitq, priv->fw_callback == NULL);
+}
+
+/**
+ *  lbs_get_firmware_async - Retrieves firmware asynchronously. Can load
+ *  either a helper firmware and a main firmware (2-stage), or just the helper.
+ *
+ *  @priv:      Pointer to lbs_private instance
+ *  @dev:      A pointer to &device structure
+ *  @card_model: Bus-specific card model ID used to filter firmware table
+ *             elements
+ *  @fw_table: Table of firmware file names and device model numbers
+ *             terminated by an entry with a NULL helper name
+ *     @callback: User callback to invoke when firmware load succeeds or fails.
+ */
+int lbs_get_firmware_async(struct lbs_private *priv, struct device *device,
+                           u32 card_model, const struct lbs_fw_table *fw_table,
+                           lbs_fw_cb callback)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&priv->driver_lock, flags);
+       if (priv->fw_callback) {
+               lbs_deb_fw("firmware load already in progress\n");
+               spin_unlock_irqrestore(&priv->driver_lock, flags);
+               return -EBUSY;
+       }
+
+       priv->fw_device = device;
+       priv->fw_callback = callback;
+       priv->fw_table = fw_table;
+       priv->fw_iter = NULL;
+       priv->fw_model = card_model;
+       spin_unlock_irqrestore(&priv->driver_lock, flags);
+
+       lbs_deb_fw("Starting async firmware load\n");
+       load_next_firmware_from_table(priv);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(lbs_get_firmware_async);
+
+/**
+ *  lbs_get_firmware - Retrieves two-stage firmware
+ *
+ *  @dev:      A pointer to &device structure
+ *  @card_model: Bus-specific card model ID used to filter firmware table
+ *             elements
+ *  @fw_table: Table of firmware file names and device model numbers
+ *             terminated by an entry with a NULL helper name
+ *  @helper:   On success, the helper firmware; caller must free
+ *  @mainfw:   On success, the main firmware; caller must free
+ *
+ * Deprecated: use lbs_get_firmware_async() instead.
+ *
+ *  returns:           0 on success, non-zero on failure
+ */
+int lbs_get_firmware(struct device *dev, u32 card_model,
+                       const struct lbs_fw_table *fw_table,
+                       const struct firmware **helper,
+                       const struct firmware **mainfw)
+{
+       const struct lbs_fw_table *iter;
+       int ret;
+
+       BUG_ON(helper == NULL);
+       BUG_ON(mainfw == NULL);
+
+       /* Search for firmware to use from the table. */
+       iter = fw_table;
+       while (iter && iter->helper) {
+               if (iter->model != card_model)
+                       goto next;
+
+               if (*helper == NULL) {
+                       ret = request_firmware(helper, iter->helper, dev);
+                       if (ret)
+                               goto next;
+
+                       /* If the device has one-stage firmware (ie cf8305) and
+                        * we've got it then we don't need to bother with the
+                        * main firmware.
+                        */
+                       if (iter->fwname == NULL)
+                               return 0;
+               }
+
+               if (*mainfw == NULL) {
+                       ret = request_firmware(mainfw, iter->fwname, dev);
+                       if (ret) {
+                               /* Clear the helper to ensure we don't have
+                                * mismatched firmware pairs.
+                                */
+                               release_firmware(*helper);
+                               *helper = NULL;
+                       }
+               }
+
+               if (*helper && *mainfw)
+                       return 0;
+
+  next:
+               iter++;
+       }
+
+       /* Failed */
+       release_firmware(*helper);
+       *helper = NULL;
+       release_firmware(*mainfw);
+       *mainfw = NULL;
+
+       return -ENOENT;
+}
+EXPORT_SYMBOL_GPL(lbs_get_firmware);
index 234ee88dec95400f4e6fce337d6e500251a805f8..cee50528522b863e7c19b8bdf3be6673519f3c74 100644 (file)
@@ -890,8 +890,8 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
                goto out2;
        }
 
-       ret = lbs_get_firmware(&p_dev->dev, NULL, NULL, card->model,
-                               &fw_table[0], &helper, &mainfw);
+       ret = lbs_get_firmware(&p_dev->dev, card->model, &fw_table[0],
+                               &helper, &mainfw);
        if (ret) {
                pr_err("failed to find firmware (%d)\n", ret);
                goto out2;
@@ -951,10 +951,8 @@ out2:
 out1:
        pcmcia_disable_device(p_dev);
 out:
-       if (helper)
-               release_firmware(helper);
-       if (mainfw)
-               release_firmware(mainfw);
+       release_firmware(helper);
+       release_firmware(mainfw);
 
        lbs_deb_leave_args(LBS_DEB_CS, "ret %d", ret);
        return ret;
index 9804ebc892d46dab0171bb90f964391146825831..76caebaa43977f722cbd707d666f1f014002792e 100644 (file)
@@ -65,12 +65,6 @@ static void if_sdio_interrupt(struct sdio_func *func);
  */
 static u8 user_rmmod;
 
-static char *lbs_helper_name = NULL;
-module_param_named(helper_name, lbs_helper_name, charp, 0644);
-
-static char *lbs_fw_name = NULL;
-module_param_named(fw_name, lbs_fw_name, charp, 0644);
-
 static const struct sdio_device_id if_sdio_ids[] = {
        { SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL,
                        SDIO_DEVICE_ID_MARVELL_LIBERTAS) },
@@ -123,11 +117,8 @@ struct if_sdio_card {
        int                     model;
        unsigned long           ioport;
        unsigned int            scratch_reg;
-
-       const char              *helper;
-       const char              *firmware;
-       bool                    helper_allocated;
-       bool                    firmware_allocated;
+       bool                    started;
+       wait_queue_head_t       pwron_waitq;
 
        u8                      buffer[65536] __attribute__((aligned(4)));
 
@@ -140,6 +131,9 @@ struct if_sdio_card {
        u8                      rx_unit;
 };
 
+static void if_sdio_finish_power_on(struct if_sdio_card *card);
+static int if_sdio_power_off(struct if_sdio_card *card);
+
 /********************************************************************/
 /* I/O                                                              */
 /********************************************************************/
@@ -680,12 +674,39 @@ out:
        return ret;
 }
 
+static void if_sdio_do_prog_firmware(struct lbs_private *priv, int ret,
+                                    const struct firmware *helper,
+                                    const struct firmware *mainfw)
+{
+       struct if_sdio_card *card = priv->card;
+
+       if (ret) {
+               pr_err("failed to find firmware (%d)\n", ret);
+               return;
+       }
+
+       ret = if_sdio_prog_helper(card, helper);
+       if (ret)
+               goto out;
+
+       lbs_deb_sdio("Helper firmware loaded\n");
+
+       ret = if_sdio_prog_real(card, mainfw);
+       if (ret)
+               goto out;
+
+       lbs_deb_sdio("Firmware loaded\n");
+       if_sdio_finish_power_on(card);
+
+out:
+       release_firmware(helper);
+       release_firmware(mainfw);
+}
+
 static int if_sdio_prog_firmware(struct if_sdio_card *card)
 {
        int ret;
        u16 scratch;
-       const struct firmware *helper = NULL;
-       const struct firmware *mainfw = NULL;
 
        lbs_deb_enter(LBS_DEB_SDIO);
 
@@ -719,43 +740,18 @@ static int if_sdio_prog_firmware(struct if_sdio_card *card)
         */
        if (scratch == IF_SDIO_FIRMWARE_OK) {
                lbs_deb_sdio("firmware already loaded\n");
-               goto success;
+               if_sdio_finish_power_on(card);
+               return 0;
        } else if ((card->model == MODEL_8686) && (scratch & 0x7fff)) {
                lbs_deb_sdio("firmware may be running\n");
-               goto success;
-       }
-
-       ret = lbs_get_firmware(&card->func->dev, lbs_helper_name, lbs_fw_name,
-                               card->model, &fw_table[0], &helper, &mainfw);
-       if (ret) {
-               pr_err("failed to find firmware (%d)\n", ret);
-               goto out;
+               if_sdio_finish_power_on(card);
+               return 0;
        }
 
-       ret = if_sdio_prog_helper(card, helper);
-       if (ret)
-               goto out;
-
-       lbs_deb_sdio("Helper firmware loaded\n");
-
-       ret = if_sdio_prog_real(card, mainfw);
-       if (ret)
-               goto out;
-
-       lbs_deb_sdio("Firmware loaded\n");
-
-success:
-       sdio_claim_host(card->func);
-       sdio_set_block_size(card->func, IF_SDIO_BLOCK_SIZE);
-       sdio_release_host(card->func);
-       ret = 0;
+       ret = lbs_get_firmware_async(card->priv, &card->func->dev, card->model,
+                                    fw_table, if_sdio_do_prog_firmware);
 
 out:
-       if (helper)
-               release_firmware(helper);
-       if (mainfw)
-               release_firmware(mainfw);
-
        lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret);
        return ret;
 }
@@ -764,55 +760,15 @@ out:
 /* Power management                                                 */
 /********************************************************************/
 
-static int if_sdio_power_on(struct if_sdio_card *card)
+/* Finish power on sequence (after firmware is loaded) */
+static void if_sdio_finish_power_on(struct if_sdio_card *card)
 {
        struct sdio_func *func = card->func;
        struct lbs_private *priv = card->priv;
-       struct mmc_host *host = func->card->host;
        int ret;
 
        sdio_claim_host(func);
-
-       ret = sdio_enable_func(func);
-       if (ret)
-               goto release;
-
-       /* For 1-bit transfers to the 8686 model, we need to enable the
-        * interrupt flag in the CCCR register. Set the MMC_QUIRK_LENIENT_FN0
-        * bit to allow access to non-vendor registers. */
-       if ((card->model == MODEL_8686) &&
-           (host->caps & MMC_CAP_SDIO_IRQ) &&
-           (host->ios.bus_width == MMC_BUS_WIDTH_1)) {
-               u8 reg;
-
-               func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
-               reg = sdio_f0_readb(func, SDIO_CCCR_IF, &ret);
-               if (ret)
-                       goto disable;
-
-               reg |= SDIO_BUS_ECSI;
-               sdio_f0_writeb(func, reg, SDIO_CCCR_IF, &ret);
-               if (ret)
-                       goto disable;
-       }
-
-       card->ioport = sdio_readb(func, IF_SDIO_IOPORT, &ret);
-       if (ret)
-               goto disable;
-
-       card->ioport |= sdio_readb(func, IF_SDIO_IOPORT + 1, &ret) << 8;
-       if (ret)
-               goto disable;
-
-       card->ioport |= sdio_readb(func, IF_SDIO_IOPORT + 2, &ret) << 16;
-       if (ret)
-               goto disable;
-
-       sdio_release_host(func);
-       ret = if_sdio_prog_firmware(card);
-       sdio_claim_host(func);
-       if (ret)
-               goto disable;
+       sdio_set_block_size(card->func, IF_SDIO_BLOCK_SIZE);
 
        /*
         * Get rx_unit if the chip is SD8688 or newer.
@@ -837,7 +793,7 @@ static int if_sdio_power_on(struct if_sdio_card *card)
         */
        ret = sdio_claim_irq(func, if_sdio_interrupt);
        if (ret)
-               goto disable;
+               goto release;
 
        /*
         * Enable interrupts now that everything is set up
@@ -863,11 +819,79 @@ static int if_sdio_power_on(struct if_sdio_card *card)
        }
 
        priv->fw_ready = 1;
+       wake_up(&card->pwron_waitq);
 
-       return 0;
+       if (!card->started) {
+               ret = lbs_start_card(priv);
+               if_sdio_power_off(card);
+               if (ret == 0) {
+                       card->started = true;
+                       /* Tell PM core that we don't need the card to be
+                        * powered now */
+                       pm_runtime_put_noidle(&func->dev);
+               }
+       }
+
+       return;
 
 release_irq:
        sdio_release_irq(func);
+release:
+       sdio_release_host(func);
+}
+
+static int if_sdio_power_on(struct if_sdio_card *card)
+{
+       struct sdio_func *func = card->func;
+       struct mmc_host *host = func->card->host;
+       int ret;
+
+       sdio_claim_host(func);
+
+       ret = sdio_enable_func(func);
+       if (ret)
+               goto release;
+
+       /* For 1-bit transfers to the 8686 model, we need to enable the
+        * interrupt flag in the CCCR register. Set the MMC_QUIRK_LENIENT_FN0
+        * bit to allow access to non-vendor registers. */
+       if ((card->model == MODEL_8686) &&
+           (host->caps & MMC_CAP_SDIO_IRQ) &&
+           (host->ios.bus_width == MMC_BUS_WIDTH_1)) {
+               u8 reg;
+
+               func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
+               reg = sdio_f0_readb(func, SDIO_CCCR_IF, &ret);
+               if (ret)
+                       goto disable;
+
+               reg |= SDIO_BUS_ECSI;
+               sdio_f0_writeb(func, reg, SDIO_CCCR_IF, &ret);
+               if (ret)
+                       goto disable;
+       }
+
+       card->ioport = sdio_readb(func, IF_SDIO_IOPORT, &ret);
+       if (ret)
+               goto disable;
+
+       card->ioport |= sdio_readb(func, IF_SDIO_IOPORT + 1, &ret) << 8;
+       if (ret)
+               goto disable;
+
+       card->ioport |= sdio_readb(func, IF_SDIO_IOPORT + 2, &ret) << 16;
+       if (ret)
+               goto disable;
+
+       sdio_release_host(func);
+       ret = if_sdio_prog_firmware(card);
+       if (ret) {
+               sdio_disable_func(func);
+               return ret;
+       }
+
+       return 0;
+
 disable:
        sdio_disable_func(func);
 release:
@@ -1074,11 +1098,17 @@ static int if_sdio_power_save(struct lbs_private *priv)
 static int if_sdio_power_restore(struct lbs_private *priv)
 {
        struct if_sdio_card *card = priv->card;
+       int r;
 
        /* Make sure the card will not be powered off by runtime PM */
        pm_runtime_get_sync(&card->func->dev);
 
-       return if_sdio_power_on(card);
+       r = if_sdio_power_on(card);
+       if (r)
+               return r;
+
+       wait_event(card->pwron_waitq, priv->fw_ready);
+       return 0;
 }
 
 
@@ -1179,6 +1209,7 @@ static int if_sdio_probe(struct sdio_func *func,
        spin_lock_init(&card->lock);
        card->workqueue = create_workqueue("libertas_sdio");
        INIT_WORK(&card->packet_worker, if_sdio_host_to_card_worker);
+       init_waitqueue_head(&card->pwron_waitq);
 
        /* Check if we support this card */
        for (i = 0; i < ARRAY_SIZE(fw_table); i++) {
@@ -1220,14 +1251,6 @@ static int if_sdio_probe(struct sdio_func *func,
        if (ret)
                goto err_activate_card;
 
-       ret = lbs_start_card(priv);
-       if_sdio_power_off(card);
-       if (ret)
-               goto err_activate_card;
-
-       /* Tell PM core that we don't need the card to be powered now */
-       pm_runtime_put_noidle(&func->dev);
-
 out:
        lbs_deb_leave_args(LBS_DEB_SDIO, "ret %d", ret);
 
@@ -1244,10 +1267,6 @@ free:
                kfree(packet);
        }
 
-       if (card->helper_allocated)
-               kfree(card->helper);
-       if (card->firmware_allocated)
-               kfree(card->firmware);
        kfree(card);
 
        goto out;
@@ -1295,12 +1314,6 @@ static void if_sdio_remove(struct sdio_func *func)
                kfree(packet);
        }
 
-       if (card->helper_allocated)
-               kfree(card->helper);
-       if (card->firmware_allocated)
-               kfree(card->firmware);
-       kfree(card);
-
        lbs_deb_leave(LBS_DEB_SDIO);
 }
 
index 50b1ee7721e99254120c00722345f62e540d321b..9604a1c4a74d9ac158d6ea6f4928ed75765fada1 100644 (file)
@@ -1064,9 +1064,8 @@ static int if_spi_init_card(struct if_spi_card *card)
                        goto out;
                }
 
-               err = lbs_get_firmware(&card->spi->dev, NULL, NULL,
-                                       card->card_id, &fw_table[0], &helper,
-                                       &mainfw);
+               err = lbs_get_firmware(&card->spi->dev, card->card_id,
+                                       &fw_table[0], &helper, &mainfw);
                if (err) {
                        netdev_err(priv->dev, "failed to find firmware (%d)\n",
                                   err);
@@ -1095,10 +1094,8 @@ static int if_spi_init_card(struct if_spi_card *card)
                goto out;
 
 out:
-       if (helper)
-               release_firmware(helper);
-       if (mainfw)
-               release_firmware(mainfw);
+       release_firmware(helper);
+       release_firmware(mainfw);
 
        lbs_deb_leave_args(LBS_DEB_SPI, "err %d\n", err);
 
index 74da5f1ea243eae088c227ecc15861a640f95bca..75403e6e3990ef5d64fadc3d3e1bc3dbc38e6795 100644 (file)
@@ -29,9 +29,6 @@
 
 #define MESSAGE_HEADER_LEN     4
 
-static char *lbs_fw_name = NULL;
-module_param_named(fw_name, lbs_fw_name, charp, 0644);
-
 MODULE_FIRMWARE("libertas/usb8388_v9.bin");
 MODULE_FIRMWARE("libertas/usb8388_v5.bin");
 MODULE_FIRMWARE("libertas/usb8388.bin");
@@ -44,6 +41,16 @@ enum {
        MODEL_8682 = 0x2
 };
 
+/* table of firmware file names */
+static const struct lbs_fw_table fw_table[] = {
+       { MODEL_8388, "libertas/usb8388_olpc.bin", NULL },
+       { MODEL_8388, "libertas/usb8388_v9.bin", NULL },
+       { MODEL_8388, "libertas/usb8388_v5.bin", NULL },
+       { MODEL_8388, "libertas/usb8388.bin", NULL },
+       { MODEL_8388, "usb8388.bin", NULL },
+       { MODEL_8682, "libertas/usb8682.bin", NULL }
+};
+
 static struct usb_device_id if_usb_table[] = {
        /* Enter the device signature inside */
        { USB_DEVICE(0x1286, 0x2001), .driver_info = MODEL_8388 },
@@ -55,10 +62,9 @@ MODULE_DEVICE_TABLE(usb, if_usb_table);
 
 static void if_usb_receive(struct urb *urb);
 static void if_usb_receive_fwload(struct urb *urb);
-static int __if_usb_prog_firmware(struct if_usb_card *cardp,
-                                       const char *fwname, int cmd);
-static int if_usb_prog_firmware(struct if_usb_card *cardp,
-                                       const char *fwname, int cmd);
+static void if_usb_prog_firmware(struct lbs_private *priv, int ret,
+                                const struct firmware *fw,
+                                const struct firmware *unused);
 static int if_usb_host_to_card(struct lbs_private *priv, uint8_t type,
                               uint8_t *payload, uint16_t nb);
 static int usb_tx_block(struct if_usb_card *cardp, uint8_t *payload,
@@ -67,69 +73,6 @@ static void if_usb_free(struct if_usb_card *cardp);
 static int if_usb_submit_rx_urb(struct if_usb_card *cardp);
 static int if_usb_reset_device(struct if_usb_card *cardp);
 
-/* sysfs hooks */
-
-/*
- *  Set function to write firmware to device's persistent memory
- */
-static ssize_t if_usb_firmware_set(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t count)
-{
-       struct lbs_private *priv = to_net_dev(dev)->ml_priv;
-       struct if_usb_card *cardp = priv->card;
-       int ret;
-
-       BUG_ON(buf == NULL);
-
-       ret = if_usb_prog_firmware(cardp, buf, BOOT_CMD_UPDATE_FW);
-       if (ret == 0)
-               return count;
-
-       return ret;
-}
-
-/*
- * lbs_flash_fw attribute to be exported per ethX interface through sysfs
- * (/sys/class/net/ethX/lbs_flash_fw).  Use this like so to write firmware to
- * the device's persistent memory:
- * echo usb8388-5.126.0.p5.bin > /sys/class/net/ethX/lbs_flash_fw
- */
-static DEVICE_ATTR(lbs_flash_fw, 0200, NULL, if_usb_firmware_set);
-
-/**
- * if_usb_boot2_set - write firmware to device's persistent memory
- *
- * @dev: target device
- * @attr: device attributes
- * @buf: firmware buffer to write
- * @count: number of bytes to write
- *
- * returns: number of bytes written or negative error code
- */
-static ssize_t if_usb_boot2_set(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t count)
-{
-       struct lbs_private *priv = to_net_dev(dev)->ml_priv;
-       struct if_usb_card *cardp = priv->card;
-       int ret;
-
-       BUG_ON(buf == NULL);
-
-       ret = if_usb_prog_firmware(cardp, buf, BOOT_CMD_UPDATE_BOOT2);
-       if (ret == 0)
-               return count;
-
-       return ret;
-}
-
-/*
- * lbs_flash_boot2 attribute to be exported per ethX interface through sysfs
- * (/sys/class/net/ethX/lbs_flash_boot2).  Use this like so to write firmware
- * to the device's persistent memory:
- * echo usb8388-5.126.0.p5.bin > /sys/class/net/ethX/lbs_flash_boot2
- */
-static DEVICE_ATTR(lbs_flash_boot2, 0200, NULL, if_usb_boot2_set);
-
 /**
  * if_usb_write_bulk_callback - callback function to handle the status
  * of the URB
@@ -256,6 +199,7 @@ static int if_usb_probe(struct usb_interface *intf,
        struct usb_endpoint_descriptor *endpoint;
        struct lbs_private *priv;
        struct if_usb_card *cardp;
+       int r = -ENOMEM;
        int i;
 
        udev = interface_to_usbdev(intf);
@@ -313,20 +257,10 @@ static int if_usb_probe(struct usb_interface *intf,
                goto dealloc;
        }
 
-       /* Upload firmware */
-       kparam_block_sysfs_write(fw_name);
-       if (__if_usb_prog_firmware(cardp, lbs_fw_name, BOOT_CMD_FW_BY_USB)) {
-               kparam_unblock_sysfs_write(fw_name);
-               lbs_deb_usbd(&udev->dev, "FW upload failed\n");
-               goto err_prog_firmware;
-       }
-       kparam_unblock_sysfs_write(fw_name);
-
        if (!(priv = lbs_add_card(cardp, &intf->dev)))
-               goto err_prog_firmware;
+               goto err_add_card;
 
        cardp->priv = priv;
-       cardp->priv->fw_ready = 1;
 
        priv->hw_host_to_card = if_usb_host_to_card;
        priv->enter_deep_sleep = NULL;
@@ -339,42 +273,25 @@ static int if_usb_probe(struct usb_interface *intf,
 
        cardp->boot2_version = udev->descriptor.bcdDevice;
 
-       if_usb_submit_rx_urb(cardp);
-
-       if (lbs_start_card(priv))
-               goto err_start_card;
-
-       if_usb_setup_firmware(priv);
-
        usb_get_dev(udev);
        usb_set_intfdata(intf, cardp);
 
-       if (device_create_file(&priv->dev->dev, &dev_attr_lbs_flash_fw))
-               netdev_err(priv->dev,
-                          "cannot register lbs_flash_fw attribute\n");
-
-       if (device_create_file(&priv->dev->dev, &dev_attr_lbs_flash_boot2))
-               netdev_err(priv->dev,
-                          "cannot register lbs_flash_boot2 attribute\n");
-
-       /*
-        * EHS_REMOVE_WAKEUP is not supported on all versions of the firmware.
-        */
-       priv->wol_criteria = EHS_REMOVE_WAKEUP;
-       if (lbs_host_sleep_cfg(priv, priv->wol_criteria, NULL))
-               priv->ehs_remove_supported = false;
+       r = lbs_get_firmware_async(priv, &udev->dev, cardp->model,
+                                  fw_table, if_usb_prog_firmware);
+       if (r)
+               goto err_get_fw;
 
        return 0;
 
-err_start_card:
+err_get_fw:
        lbs_remove_card(priv);
-err_prog_firmware:
+err_add_card:
        if_usb_reset_device(cardp);
 dealloc:
        if_usb_free(cardp);
 
 error:
-       return -ENOMEM;
+       return r;
 }
 
 /**
@@ -389,9 +306,6 @@ static void if_usb_disconnect(struct usb_interface *intf)
 
        lbs_deb_enter(LBS_DEB_MAIN);
 
-       device_remove_file(&priv->dev->dev, &dev_attr_lbs_flash_boot2);
-       device_remove_file(&priv->dev->dev, &dev_attr_lbs_flash_fw);
-
        cardp->surprise_removed = 1;
 
        if (priv) {
@@ -912,121 +826,22 @@ static int check_fwfile_format(const uint8_t *data, uint32_t totlen)
        return ret;
 }
 
-
-/**
-*  if_usb_prog_firmware - programs the firmware subject to cmd
-*
-*  @cardp:     the if_usb_card descriptor
-*  @fwname:    firmware or boot2 image file name
-*  @cmd:       either BOOT_CMD_FW_BY_USB, BOOT_CMD_UPDATE_FW,
-*              or BOOT_CMD_UPDATE_BOOT2.
-*  returns:    0 or error code
-*/
-static int if_usb_prog_firmware(struct if_usb_card *cardp,
-                               const char *fwname, int cmd)
-{
-       struct lbs_private *priv = cardp->priv;
-       unsigned long flags, caps;
-       int ret;
-
-       caps = priv->fwcapinfo;
-       if (((cmd == BOOT_CMD_UPDATE_FW) && !(caps & FW_CAPINFO_FIRMWARE_UPGRADE)) ||
-           ((cmd == BOOT_CMD_UPDATE_BOOT2) && !(caps & FW_CAPINFO_BOOT2_UPGRADE)))
-               return -EOPNOTSUPP;
-
-       /* Ensure main thread is idle. */
-       spin_lock_irqsave(&priv->driver_lock, flags);
-       while (priv->cur_cmd != NULL || priv->dnld_sent != DNLD_RES_RECEIVED) {
-               spin_unlock_irqrestore(&priv->driver_lock, flags);
-               if (wait_event_interruptible(priv->waitq,
-                               (priv->cur_cmd == NULL &&
-                               priv->dnld_sent == DNLD_RES_RECEIVED))) {
-                       return -ERESTARTSYS;
-               }
-               spin_lock_irqsave(&priv->driver_lock, flags);
-       }
-       priv->dnld_sent = DNLD_BOOTCMD_SENT;
-       spin_unlock_irqrestore(&priv->driver_lock, flags);
-
-       ret = __if_usb_prog_firmware(cardp, fwname, cmd);
-
-       spin_lock_irqsave(&priv->driver_lock, flags);
-       priv->dnld_sent = DNLD_RES_RECEIVED;
-       spin_unlock_irqrestore(&priv->driver_lock, flags);
-
-       wake_up(&priv->waitq);
-
-       return ret;
-}
-
-/* table of firmware file names */
-static const struct {
-       u32 model;
-       const char *fwname;
-} fw_table[] = {
-       { MODEL_8388, "libertas/usb8388_v9.bin" },
-       { MODEL_8388, "libertas/usb8388_v5.bin" },
-       { MODEL_8388, "libertas/usb8388.bin" },
-       { MODEL_8388, "usb8388.bin" },
-       { MODEL_8682, "libertas/usb8682.bin" }
-};
-
-#ifdef CONFIG_OLPC
-
-static int try_olpc_fw(struct if_usb_card *cardp)
-{
-       int retval = -ENOENT;
-
-       /* try the OLPC firmware first; fall back to fw_table list */
-       if (machine_is_olpc() && cardp->model == MODEL_8388)
-               retval = request_firmware(&cardp->fw,
-                               "libertas/usb8388_olpc.bin", &cardp->udev->dev);
-       return retval;
-}
-
-#else
-static int try_olpc_fw(struct if_usb_card *cardp) { return -ENOENT; }
-#endif /* !CONFIG_OLPC */
-
-static int get_fw(struct if_usb_card *cardp, const char *fwname)
-{
-       int i;
-
-       /* Try user-specified firmware first */
-       if (fwname)
-               return request_firmware(&cardp->fw, fwname, &cardp->udev->dev);
-
-       /* Handle OLPC firmware */
-       if (try_olpc_fw(cardp) == 0)
-               return 0;
-
-       /* Otherwise search for firmware to use */
-       for (i = 0; i < ARRAY_SIZE(fw_table); i++) {
-               if (fw_table[i].model != cardp->model)
-                       continue;
-               if (request_firmware(&cardp->fw, fw_table[i].fwname,
-                                       &cardp->udev->dev) == 0)
-                       return 0;
-       }
-
-       return -ENOENT;
-}
-
-static int __if_usb_prog_firmware(struct if_usb_card *cardp,
-                                       const char *fwname, int cmd)
+static void if_usb_prog_firmware(struct lbs_private *priv, int ret,
+                                const struct firmware *fw,
+                                const struct firmware *unused)
 {
+       struct if_usb_card *cardp = priv->card;
        int i = 0;
        static int reset_count = 10;
-       int ret = 0;
 
        lbs_deb_enter(LBS_DEB_USB);
 
-       ret = get_fw(cardp, fwname);
        if (ret) {
                pr_err("failed to find firmware (%d)\n", ret);
                goto done;
        }
 
+       cardp->fw = fw;
        if (check_fwfile_format(cardp->fw->data, cardp->fw->size)) {
                ret = -EINVAL;
                goto release_fw;
@@ -1053,7 +868,7 @@ restart:
        do {
                int j = 0;
                i++;
-               if_usb_issue_boot_command(cardp, cmd);
+               if_usb_issue_boot_command(cardp, BOOT_CMD_FW_BY_USB);
                /* wait for command response */
                do {
                        j++;
@@ -1109,13 +924,27 @@ restart:
                goto release_fw;
        }
 
+       cardp->priv->fw_ready = 1;
+       if_usb_submit_rx_urb(cardp);
+
+       if (lbs_start_card(priv))
+               goto release_fw;
+
+       if_usb_setup_firmware(priv);
+
+       /*
+        * EHS_REMOVE_WAKEUP is not supported on all versions of the firmware.
+        */
+       priv->wol_criteria = EHS_REMOVE_WAKEUP;
+       if (lbs_host_sleep_cfg(priv, priv->wol_criteria, NULL))
+               priv->ehs_remove_supported = false;
+
  release_fw:
        release_firmware(cardp->fw);
        cardp->fw = NULL;
 
  done:
-       lbs_deb_leave_args(LBS_DEB_USB, "ret %d", ret);
-       return ret;
+       lbs_deb_leave(LBS_DEB_USB);
 }
 
 
@@ -1128,8 +957,10 @@ static int if_usb_suspend(struct usb_interface *intf, pm_message_t message)
 
        lbs_deb_enter(LBS_DEB_USB);
 
-       if (priv->psstate != PS_STATE_FULL_POWER)
-               return -1;
+       if (priv->psstate != PS_STATE_FULL_POWER) {
+               ret = -1;
+               goto out;
+       }
 
 #ifdef CONFIG_OLPC
        if (machine_is_olpc()) {
index 957681dede1776b1a9ee94ab87626bb9e0f9ee63..e96ee0aa8439420954b4f78a8571ab161eb50145 100644 (file)
@@ -878,6 +878,7 @@ static int lbs_init_adapter(struct lbs_private *priv)
        priv->is_host_sleep_configured = 0;
        priv->is_host_sleep_activated = 0;
        init_waitqueue_head(&priv->host_sleep_q);
+       init_waitqueue_head(&priv->fw_waitq);
        mutex_init(&priv->lock);
 
        setup_timer(&priv->command_timer, lbs_cmd_timeout_handler,
@@ -1033,7 +1034,11 @@ void lbs_remove_card(struct lbs_private *priv)
        lbs_deb_enter(LBS_DEB_MAIN);
 
        lbs_remove_mesh(priv);
-       lbs_scan_deinit(priv);
+
+       if (priv->wiphy_registered)
+               lbs_scan_deinit(priv);
+
+       lbs_wait_for_firmware_load(priv);
 
        /* worker thread destruction blocks on the in-flight command which
         * should have been cleared already in lbs_stop_card().
@@ -1128,6 +1133,11 @@ void lbs_stop_card(struct lbs_private *priv)
                goto out;
        dev = priv->dev;
 
+       /* If the netdev isn't registered, it means that lbs_start_card() was
+        * never called so we have nothing to do here. */
+       if (dev->reg_state != NETREG_REGISTERED)
+               goto out;
+
        netif_stop_queue(dev);
        netif_carrier_off(dev);
 
@@ -1177,111 +1187,6 @@ void lbs_notify_command_response(struct lbs_private *priv, u8 resp_idx)
 }
 EXPORT_SYMBOL_GPL(lbs_notify_command_response);
 
-/**
- *  lbs_get_firmware - Retrieves two-stage firmware
- *
- *  @dev:      A pointer to &device structure
- *  @user_helper: User-defined helper firmware file
- *  @user_mainfw: User-defined main firmware file
- *  @card_model: Bus-specific card model ID used to filter firmware table
- *             elements
- *  @fw_table: Table of firmware file names and device model numbers
- *             terminated by an entry with a NULL helper name
- *  @helper:   On success, the helper firmware; caller must free
- *  @mainfw:   On success, the main firmware; caller must free
- *
- *  returns:           0 on success, non-zero on failure
- */
-int lbs_get_firmware(struct device *dev, const char *user_helper,
-                       const char *user_mainfw, u32 card_model,
-                       const struct lbs_fw_table *fw_table,
-                       const struct firmware **helper,
-                       const struct firmware **mainfw)
-{
-       const struct lbs_fw_table *iter;
-       int ret;
-
-       BUG_ON(helper == NULL);
-       BUG_ON(mainfw == NULL);
-
-       /* Try user-specified firmware first */
-       if (user_helper) {
-               ret = request_firmware(helper, user_helper, dev);
-               if (ret) {
-                       dev_err(dev, "couldn't find helper firmware %s\n",
-                               user_helper);
-                       goto fail;
-               }
-       }
-       if (user_mainfw) {
-               ret = request_firmware(mainfw, user_mainfw, dev);
-               if (ret) {
-                       dev_err(dev, "couldn't find main firmware %s\n",
-                               user_mainfw);
-                       goto fail;
-               }
-       }
-
-       if (*helper && *mainfw)
-               return 0;
-
-       /* Otherwise search for firmware to use.  If neither the helper or
-        * the main firmware were specified by the user, then we need to
-        * make sure that found helper & main are from the same entry in
-        * fw_table.
-        */
-       iter = fw_table;
-       while (iter && iter->helper) {
-               if (iter->model != card_model)
-                       goto next;
-
-               if (*helper == NULL) {
-                       ret = request_firmware(helper, iter->helper, dev);
-                       if (ret)
-                               goto next;
-
-                       /* If the device has one-stage firmware (ie cf8305) and
-                        * we've got it then we don't need to bother with the
-                        * main firmware.
-                        */
-                       if (iter->fwname == NULL)
-                               return 0;
-               }
-
-               if (*mainfw == NULL) {
-                       ret = request_firmware(mainfw, iter->fwname, dev);
-                       if (ret && !user_helper) {
-                               /* Clear the helper if it wasn't user-specified
-                                * and the main firmware load failed, to ensure
-                                * we don't have mismatched firmware pairs.
-                                */
-                               release_firmware(*helper);
-                               *helper = NULL;
-                       }
-               }
-
-               if (*helper && *mainfw)
-                       return 0;
-
-  next:
-               iter++;
-       }
-
-  fail:
-       /* Failed */
-       if (*helper) {
-               release_firmware(*helper);
-               *helper = NULL;
-       }
-       if (*mainfw) {
-               release_firmware(*mainfw);
-               *mainfw = NULL;
-       }
-
-       return -ENOENT;
-}
-EXPORT_SYMBOL_GPL(lbs_get_firmware);
-
 static int __init lbs_init_module(void)
 {
        lbs_deb_enter(LBS_DEB_MAIN);
index 2d913644d92b5d202a065dd55f1c6dab58bcdaca..03c0c6b1372ca8cf68e1b464efdf376b8603ed06 100644 (file)
@@ -699,6 +699,7 @@ static bool mac80211_hwsim_tx_frame_no_nl(struct ieee80211_hw *hw,
                    ieee80211_is_probe_resp(mgmt->frame_control))
                        mgmt->u.beacon.timestamp = cpu_to_le64(
                                rx_status.mactime +
+                               (data->tsf_offset - data2->tsf_offset) +
                                24 * 8 * 10 / txrate->bitrate);
 
                memcpy(IEEE80211_SKB_RXCB(nskb), &rx_status, sizeof(rx_status));
index c7e89188c35078cf6cc3e2410544e91f01548529..c78ea873a63a2ecd5a1ba23c84a756cd4bc5d16f 100644 (file)
@@ -1162,6 +1162,17 @@ mwifiex_cfg80211_scan(struct wiphy *wiphy, struct net_device *dev,
        priv->user_scan_cfg->num_ssids = request->n_ssids;
        priv->user_scan_cfg->ssid_list = request->ssids;
 
+       if (request->ie && request->ie_len) {
+               for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
+                       if (priv->vs_ie[i].mask != MWIFIEX_VSIE_MASK_CLEAR)
+                               continue;
+                       priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_SCAN;
+                       memcpy(&priv->vs_ie[i].ie, request->ie,
+                              request->ie_len);
+                       break;
+               }
+       }
+
        for (i = 0; i < request->n_channels; i++) {
                chan = request->channels[i];
                priv->user_scan_cfg->chan_list[i].chan_number = chan->hw_value;
@@ -1179,6 +1190,15 @@ mwifiex_cfg80211_scan(struct wiphy *wiphy, struct net_device *dev,
        if (mwifiex_set_user_scan_ioctl(priv, priv->user_scan_cfg))
                return -EFAULT;
 
+       if (request->ie && request->ie_len) {
+               for (i = 0; i < MWIFIEX_MAX_VSIE_NUM; i++) {
+                       if (priv->vs_ie[i].mask == MWIFIEX_VSIE_MASK_SCAN) {
+                               priv->vs_ie[i].mask = MWIFIEX_VSIE_MASK_CLEAR;
+                               memset(&priv->vs_ie[i].ie, 0,
+                                      MWIFIEX_MAX_VSIE_LEN);
+                       }
+               }
+       }
        return 0;
 }
 
@@ -1422,6 +1442,7 @@ int mwifiex_register_cfg80211(struct mwifiex_private *priv)
        void *wdev_priv;
        struct wireless_dev *wdev;
        struct ieee80211_sta_ht_cap *ht_info;
+       u8 *country_code;
 
        wdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
        if (!wdev) {
@@ -1438,6 +1459,7 @@ int mwifiex_register_cfg80211(struct mwifiex_private *priv)
        }
        wdev->iftype = NL80211_IFTYPE_STATION;
        wdev->wiphy->max_scan_ssids = 10;
+       wdev->wiphy->max_scan_ie_len = MWIFIEX_MAX_VSIE_LEN;
        wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
                                       BIT(NL80211_IFTYPE_ADHOC);
 
@@ -1460,8 +1482,8 @@ int mwifiex_register_cfg80211(struct mwifiex_private *priv)
        memcpy(wdev->wiphy->perm_addr, priv->curr_addr, ETH_ALEN);
        wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
 
-       /* Reserve space for bss band information */
-       wdev->wiphy->bss_priv_size = sizeof(u8);
+       /* Reserve space for mwifiex specific private data for BSS */
+       wdev->wiphy->bss_priv_size = sizeof(struct mwifiex_bss_priv);
 
        wdev->wiphy->reg_notifier = mwifiex_reg_notifier;
 
@@ -1484,6 +1506,11 @@ int mwifiex_register_cfg80211(struct mwifiex_private *priv)
                        "info: successfully registered wiphy device\n");
        }
 
+       country_code = mwifiex_11d_code_2_region(priv->adapter->region_code);
+       if (country_code && regulatory_hint(wdev->wiphy, country_code))
+               dev_err(priv->adapter->dev,
+                       "%s: regulatory_hint failed\n", __func__);
+
        priv->wdev = wdev;
 
        return ret;
index 2fe1c33765b85cf435eb36f1fc15bbed20e5d8fe..560871b0e2369797cb252f8e39b3c83bce9d9813 100644 (file)
@@ -71,6 +71,37 @@ u16 region_code_index[MWIFIEX_MAX_REGION_CODE] = { 0x10, 0x20, 0x30,
 
 static u8 supported_rates_n[N_SUPPORTED_RATES] = { 0x02, 0x04, 0 };
 
+struct region_code_mapping {
+       u8 code;
+       u8 region[IEEE80211_COUNTRY_STRING_LEN];
+};
+
+static struct region_code_mapping region_code_mapping_t[] = {
+       { 0x10, "US " }, /* US FCC */
+       { 0x20, "CA " }, /* IC Canada */
+       { 0x30, "EU " }, /* ETSI */
+       { 0x31, "ES " }, /* Spain */
+       { 0x32, "FR " }, /* France */
+       { 0x40, "JP " }, /* Japan */
+       { 0x41, "JP " }, /* Japan */
+       { 0x50, "CN " }, /* China */
+};
+
+/* This function converts integer code to region string */
+u8 *mwifiex_11d_code_2_region(u8 code)
+{
+       u8 i;
+       u8 size = sizeof(region_code_mapping_t)/
+                               sizeof(struct region_code_mapping);
+
+       /* Look for code in mapping table */
+       for (i = 0; i < size; i++)
+               if (region_code_mapping_t[i].code == code)
+                       return region_code_mapping_t[i].region;
+
+       return NULL;
+}
+
 /*
  * This function maps an index in supported rates table into
  * the corresponding data rate.
index 1a845074c52ac967273f17beb57bbedd924795ba..a870b5885c09364872c597108f019135828d23bf 100644 (file)
@@ -212,7 +212,7 @@ mwifiex_info_read(struct file *file, char __user *ubuf,
                p += sprintf(p, "essid=\"%s\"\n", info.ssid.ssid);
                p += sprintf(p, "bssid=\"%pM\"\n", info.bssid);
                p += sprintf(p, "channel=\"%d\"\n", (int) info.bss_chan);
-               p += sprintf(p, "region_code = \"%02x\"\n", info.region_code);
+               p += sprintf(p, "country_code = \"%s\"\n", info.country_code);
 
                netdev_for_each_mc_addr(ha, netdev)
                        p += sprintf(p, "multicast_address[%d]=\"%pM\"\n",
index bb26114bdb96f4a7947072e194a724b92fc96a07..6b15449a4cb78bf809fef81285c07855f989d4d1 100644 (file)
@@ -104,6 +104,7 @@ enum MWIFIEX_802_11_PRIVACY_FILTER {
 #define TLV_TYPE_RATE_SCOPE         (PROPRIETARY_TLV_BASE_ID + 83)
 #define TLV_TYPE_POWER_GROUP        (PROPRIETARY_TLV_BASE_ID + 84)
 #define TLV_TYPE_WAPI_IE            (PROPRIETARY_TLV_BASE_ID + 94)
+#define TLV_TYPE_MGMT_IE            (PROPRIETARY_TLV_BASE_ID + 105)
 #define TLV_TYPE_AUTO_DS_PARAM      (PROPRIETARY_TLV_BASE_ID + 113)
 #define TLV_TYPE_PS_PARAM           (PROPRIETARY_TLV_BASE_ID + 114)
 
@@ -818,7 +819,7 @@ struct host_cmd_ds_txpwr_cfg {
 struct mwifiex_bcn_param {
        u8 bssid[ETH_ALEN];
        u8 rssi;
-       __le32 timestamp[2];
+       __le64 timestamp;
        __le16 beacon_period;
        __le16 cap_info_bitmap;
 } __packed;
index 54bb4839b57c7cc8f2e1dc4c11ab7f97896bbd9f..0d55c5b542d7fc121f031e7b4be96a3bbb3529b7 100644 (file)
@@ -131,6 +131,8 @@ static int mwifiex_init_priv(struct mwifiex_private *priv)
        priv->wmm_qosinfo = 0;
        priv->curr_bcn_buf = NULL;
        priv->curr_bcn_size = 0;
+       priv->wps_ie = NULL;
+       priv->wps_ie_len = 0;
 
        priv->scan_block = false;
 
index 99c06649f94cbbf39a5ad9197c463acf649c1521..f0f95524e96b704f924e70be81a86531596ec2b3 100644 (file)
@@ -96,7 +96,7 @@ struct mwifiex_bss_info {
        u32 bss_mode;
        struct cfg80211_ssid ssid;
        u32 bss_chan;
-       u32 region_code;
+       u8 country_code[3];
        u32 media_connected;
        u32 max_power_level;
        u32 min_power_level;
@@ -303,6 +303,7 @@ struct mwifiex_ds_misc_subsc_evt {
 
 #define MWIFIEX_MAX_VSIE_LEN       (256)
 #define MWIFIEX_MAX_VSIE_NUM       (8)
+#define MWIFIEX_VSIE_MASK_CLEAR    0x00
 #define MWIFIEX_VSIE_MASK_SCAN     0x01
 #define MWIFIEX_VSIE_MASK_ASSOC    0x02
 #define MWIFIEX_VSIE_MASK_ADHOC    0x04
index bca8b6d52273f74838888a779575c41e3a4cc0c2..8a390982463ecd909c0262a0fc2c380109ed5066 100644 (file)
@@ -118,15 +118,15 @@ mwifiex_cmd_append_tsf_tlv(struct mwifiex_private *priv, u8 **buffer,
        *buffer += sizeof(tsf_tlv.header);
 
        /* TSF at the time when beacon/probe_response was received */
-       tsf_val = cpu_to_le64(bss_desc->network_tsf);
+       tsf_val = cpu_to_le64(bss_desc->fw_tsf);
        memcpy(*buffer, &tsf_val, sizeof(tsf_val));
        *buffer += sizeof(tsf_val);
 
-       memcpy(&tsf_val, bss_desc->time_stamp, sizeof(tsf_val));
+       tsf_val = cpu_to_le64(bss_desc->timestamp);
 
        dev_dbg(priv->adapter->dev,
                "info: %s: TSF offset calc: %016llx - %016llx\n",
-               __func__, tsf_val, bss_desc->network_tsf);
+               __func__, bss_desc->timestamp, bss_desc->fw_tsf);
 
        memcpy(*buffer, &tsf_val, sizeof(tsf_val));
        *buffer += sizeof(tsf_val);
@@ -224,6 +224,48 @@ mwifiex_setup_rates_from_bssdesc(struct mwifiex_private *priv,
        return 0;
 }
 
+/*
+ * This function appends a WPS IE. It is called from the network join command
+ * preparation routine.
+ *
+ * If the IE buffer has been setup by the application, this routine appends
+ * the buffer as a WPS TLV type to the request.
+ */
+static int
+mwifiex_cmd_append_wps_ie(struct mwifiex_private *priv, u8 **buffer)
+{
+       int retLen = 0;
+       struct mwifiex_ie_types_header ie_header;
+
+       if (!buffer || !*buffer)
+               return 0;
+
+       /*
+        * If there is a wps ie buffer setup, append it to the return
+        * parameter buffer pointer.
+        */
+       if (priv->wps_ie_len) {
+               dev_dbg(priv->adapter->dev, "cmd: append wps ie %d to %p\n",
+                       priv->wps_ie_len, *buffer);
+
+               /* Wrap the generic IE buffer with a pass through TLV type */
+               ie_header.type = cpu_to_le16(TLV_TYPE_MGMT_IE);
+               ie_header.len = cpu_to_le16(priv->wps_ie_len);
+               memcpy(*buffer, &ie_header, sizeof(ie_header));
+               *buffer += sizeof(ie_header);
+               retLen += sizeof(ie_header);
+
+               memcpy(*buffer, priv->wps_ie, priv->wps_ie_len);
+               *buffer += priv->wps_ie_len;
+               retLen += priv->wps_ie_len;
+
+       }
+
+       kfree(priv->wps_ie);
+       priv->wps_ie_len = 0;
+       return retLen;
+}
+
 /*
  * This function appends a WAPI IE.
  *
@@ -480,6 +522,8 @@ int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
        if (priv->sec_info.wapi_enabled && priv->wapi_ie_len)
                mwifiex_cmd_append_wapi_ie(priv, &pos);
 
+       if (priv->wps.session_enable && priv->wps_ie_len)
+               mwifiex_cmd_append_wps_ie(priv, &pos);
 
        mwifiex_cmd_append_generic_ie(priv, &pos);
 
index 9d1b3ca6334b70a827cb047a0a4b2bb54378a0ec..245b7329e0c9254bbbeaba04ba63feb888aeb56e 100644 (file)
@@ -292,29 +292,28 @@ static void mwifiex_free_adapter(struct mwifiex_adapter *adapter)
 }
 
 /*
- * This function initializes the hardware and firmware.
+ * This function gets firmware and initializes it.
  *
  * The main initialization steps followed are -
  *      - Download the correct firmware to card
- *      - Allocate and initialize the adapter structure
- *      - Initialize the private structures
  *      - Issue the init commands to firmware
  */
-static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter)
+static void mwifiex_fw_dpc(const struct firmware *firmware, void *context)
 {
-       int ret, err;
+       int ret;
+       char fmt[64];
+       struct mwifiex_private *priv;
+       struct mwifiex_adapter *adapter = context;
        struct mwifiex_fw_image fw;
 
-       memset(&fw, 0, sizeof(struct mwifiex_fw_image));
-
-       err = request_firmware(&adapter->firmware, adapter->fw_name,
-                              adapter->dev);
-       if (err < 0) {
-               dev_err(adapter->dev, "request_firmware() returned"
-                               " error code %#x\n", err);
-               ret = -1;
+       if (!firmware) {
+               dev_err(adapter->dev,
+                       "Failed to get firmware %s\n", adapter->fw_name);
                goto done;
        }
+
+       memset(&fw, 0, sizeof(struct mwifiex_fw_image));
+       adapter->firmware = firmware;
        fw.fw_buf = (u8 *) adapter->firmware->data;
        fw.fw_len = adapter->firmware->size;
 
@@ -335,17 +334,54 @@ static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter)
        /* Wait for mwifiex_init to complete */
        wait_event_interruptible(adapter->init_wait_q,
                                 adapter->init_wait_q_woken);
-       if (adapter->hw_status != MWIFIEX_HW_STATUS_READY) {
-               ret = -1;
+       if (adapter->hw_status != MWIFIEX_HW_STATUS_READY)
                goto done;
+
+       priv = adapter->priv[0];
+       if (mwifiex_register_cfg80211(priv) != 0) {
+               dev_err(adapter->dev, "cannot register with cfg80211\n");
+               goto err_init_fw;
+       }
+
+       rtnl_lock();
+       /* Create station interface by default */
+       if (!mwifiex_add_virtual_intf(priv->wdev->wiphy, "mlan%d",
+                                     NL80211_IFTYPE_STATION, NULL, NULL)) {
+               dev_err(adapter->dev, "cannot create default STA interface\n");
+               goto err_add_intf;
        }
-       ret = 0;
+       rtnl_unlock();
+
+       mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
+       dev_notice(adapter->dev, "driver_version = %s\n", fmt);
+       goto done;
 
+err_add_intf:
+       mwifiex_del_virtual_intf(priv->wdev->wiphy, priv->netdev);
+       rtnl_unlock();
+err_init_fw:
+       pr_debug("info: %s: unregister device\n", __func__);
+       adapter->if_ops.unregister_dev(adapter);
 done:
-       if (adapter->firmware)
-               release_firmware(adapter->firmware);
-       if (ret)
-               ret = -1;
+       release_firmware(adapter->firmware);
+       complete(&adapter->fw_load);
+       return;
+}
+
+/*
+ * This function initializes the hardware and gets firmware.
+ */
+static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter)
+{
+       int ret;
+
+       init_completion(&adapter->fw_load);
+       ret = request_firmware_nowait(THIS_MODULE, 1, adapter->fw_name,
+                                     adapter->dev, GFP_KERNEL, adapter,
+                                     mwifiex_fw_dpc);
+       if (ret < 0)
+               dev_err(adapter->dev,
+                       "request_firmware_nowait() returned error %d\n", ret);
        return ret;
 }
 
@@ -650,8 +686,6 @@ mwifiex_add_card(void *card, struct semaphore *sem,
                 struct mwifiex_if_ops *if_ops, u8 iface_type)
 {
        struct mwifiex_adapter *adapter;
-       char fmt[64];
-       struct mwifiex_private *priv;
 
        if (down_interruptible(sem))
                goto exit_sem_err;
@@ -692,37 +726,9 @@ mwifiex_add_card(void *card, struct semaphore *sem,
                goto err_init_fw;
        }
 
-       priv = adapter->priv[0];
-
-       if (mwifiex_register_cfg80211(priv) != 0) {
-               dev_err(adapter->dev, "cannot register netdevice"
-                              " with cfg80211\n");
-                       goto err_init_fw;
-       }
-
-       rtnl_lock();
-       /* Create station interface by default */
-       if (!mwifiex_add_virtual_intf(priv->wdev->wiphy, "mlan%d",
-                                     NL80211_IFTYPE_STATION, NULL, NULL)) {
-               rtnl_unlock();
-               dev_err(adapter->dev, "cannot create default station"
-                               " interface\n");
-               goto err_add_intf;
-       }
-
-       rtnl_unlock();
-
        up(sem);
-
-       mwifiex_drv_get_driver_version(adapter, fmt, sizeof(fmt) - 1);
-       dev_notice(adapter->dev, "driver_version = %s\n", fmt);
-
        return 0;
 
-err_add_intf:
-       rtnl_lock();
-       mwifiex_del_virtual_intf(priv->wdev->wiphy, priv->netdev);
-       rtnl_unlock();
 err_init_fw:
        pr_debug("info: %s: unregister device\n", __func__);
        adapter->if_ops.unregister_dev(adapter);
index fcccf6b1373fcf6c2937efbb0e803ce1e11861d6..a4000f9608d530c6a92d3d150e417fa51d498a37 100644 (file)
@@ -260,8 +260,8 @@ struct mwifiex_bssdescriptor {
         * BAND_A(0X04): 'a' band
         */
        u16 bss_band;
-       u64 network_tsf;
-       u8 time_stamp[8];
+       u64 fw_tsf;
+       u64 timestamp;
        union ieee_types_phy_param_set phy_param_set;
        union ieee_types_ss_param_set ss_param_set;
        u16 cap_info_bitmap;
@@ -407,6 +407,8 @@ struct mwifiex_private {
        struct host_cmd_ds_802_11_key_material aes_key;
        u8 wapi_ie[256];
        u8 wapi_ie_len;
+       u8 *wps_ie;
+       u8 wps_ie_len;
        u8 wmm_required;
        u8 wmm_enabled;
        u8 wmm_qosinfo;
@@ -520,6 +522,11 @@ struct cmd_ctrl_node {
        u8 cmd_wait_q_woken;
 };
 
+struct mwifiex_bss_priv {
+       u8 band;
+       u64 fw_tsf;
+};
+
 struct mwifiex_if_ops {
        int (*init_if) (struct mwifiex_adapter *);
        void (*cleanup_if) (struct mwifiex_adapter *);
@@ -653,6 +660,7 @@ struct mwifiex_adapter {
        u8 scan_wait_q_woken;
        struct cmd_ctrl_node *cmd_queued;
        spinlock_t queue_lock;          /* lock for tx queues */
+       struct completion fw_load;
 };
 
 int mwifiex_init_lock_list(struct mwifiex_adapter *adapter);
@@ -950,13 +958,10 @@ int mwifiex_bss_set_channel(struct mwifiex_private *,
 int mwifiex_get_bss_info(struct mwifiex_private *,
                         struct mwifiex_bss_info *);
 int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
-                             u8 *bssid, s32 rssi, u8 *ie_buf,
-                             size_t ie_len, u16 beacon_period,
-                             u16 cap_info_bitmap, u8 band,
+                             struct cfg80211_bss *bss,
                              struct mwifiex_bssdescriptor *bss_desc);
 int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
-                               struct mwifiex_bssdescriptor *bss_entry,
-                               u8 *ie_buf, u32 ie_len);
+                                   struct mwifiex_bssdescriptor *bss_entry);
 int mwifiex_check_network_compatibility(struct mwifiex_private *priv,
                                        struct mwifiex_bssdescriptor *bss_desc);
 
@@ -965,6 +970,7 @@ struct net_device *mwifiex_add_virtual_intf(struct wiphy *wiphy,
                                        u32 *flags, struct vif_params *params);
 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct net_device *dev);
 
+u8 *mwifiex_11d_code_2_region(u8 code);
 
 #ifdef CONFIG_DEBUG_FS
 void mwifiex_debugfs_init(void);
index 5867facd415d445e1bfd12ae160dd6834ba6aa3e..13fbc4eb15952fe375be1e10c55518bb2b6b3836 100644 (file)
@@ -119,6 +119,9 @@ static void mwifiex_pcie_remove(struct pci_dev *pdev)
        if (!adapter || !adapter->priv_num)
                return;
 
+       /* In case driver is removed when asynchronous FW load is in progress */
+       wait_for_completion(&adapter->fw_load);
+
        if (user_rmmod) {
 #ifdef CONFIG_PM
                if (adapter->is_suspended)
index ef84a1a6742f7e7aaa56b1cd5c3261d230609bfe..74f0457157235d8a3100eb95e66027976493b19c 100644 (file)
@@ -1048,10 +1048,8 @@ mwifiex_ret_802_11_scan_get_tlv_ptrs(struct mwifiex_adapter *adapter,
  * This function parses provided beacon buffer and updates
  * respective fields in bss descriptor structure.
  */
-int
-mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
-                               struct mwifiex_bssdescriptor *bss_entry,
-                               u8 *ie_buf, u32 ie_len)
+int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
+                                   struct mwifiex_bssdescriptor *bss_entry)
 {
        int ret = 0;
        u8 element_id;
@@ -1073,10 +1071,8 @@ mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
 
        found_data_rate_ie = false;
        rate_size = 0;
-       current_ptr = ie_buf;
-       bytes_left = ie_len;
-       bss_entry->beacon_buf = ie_buf;
-       bss_entry->beacon_buf_size = ie_len;
+       current_ptr = bss_entry->beacon_buf;
+       bytes_left = bss_entry->beacon_buf_size;
 
        /* Process variable IE */
        while (bytes_left >= 2) {
@@ -1447,15 +1443,12 @@ int mwifiex_check_network_compatibility(struct mwifiex_private *priv,
        return ret;
 }
 
-static int
-mwifiex_update_curr_bss_params(struct mwifiex_private *priv, u8 *bssid,
-                              s32 rssi, const u8 *ie_buf, size_t ie_len,
-                              u16 beacon_period, u16 cap_info_bitmap, u8 band)
+static int mwifiex_update_curr_bss_params(struct mwifiex_private *priv,
+                                         struct cfg80211_bss *bss)
 {
        struct mwifiex_bssdescriptor *bss_desc;
        int ret;
        unsigned long flags;
-       u8 *beacon_ie;
 
        /* Allocate and fill new bss descriptor */
        bss_desc = kzalloc(sizeof(struct mwifiex_bssdescriptor),
@@ -1465,16 +1458,7 @@ mwifiex_update_curr_bss_params(struct mwifiex_private *priv, u8 *bssid,
                return -ENOMEM;
        }
 
-       beacon_ie = kmemdup(ie_buf, ie_len, GFP_KERNEL);
-       if (!beacon_ie) {
-               kfree(bss_desc);
-               dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
-               return -ENOMEM;
-       }
-
-       ret = mwifiex_fill_new_bss_desc(priv, bssid, rssi, beacon_ie,
-                                       ie_len, beacon_period,
-                                       cap_info_bitmap, band, bss_desc);
+       ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
        if (ret)
                goto done;
 
@@ -1514,7 +1498,6 @@ mwifiex_update_curr_bss_params(struct mwifiex_private *priv, u8 *bssid,
 
 done:
        kfree(bss_desc);
-       kfree(beacon_ie);
        return 0;
 }
 
@@ -1620,14 +1603,16 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
                const u8 *ie_buf;
                size_t ie_len;
                u16 channel = 0;
-               u64 network_tsf = 0;
+               u64 fw_tsf = 0;
                u16 beacon_size = 0;
                u32 curr_bcn_bytes;
                u32 freq;
                u16 beacon_period;
                u16 cap_info_bitmap;
                u8 *current_ptr;
+               u64 timestamp;
                struct mwifiex_bcn_param *bcn_param;
+               struct mwifiex_bss_priv *bss_priv;
 
                if (bytes_left >= sizeof(beacon_size)) {
                        /* Extract & convert beacon size from command buffer */
@@ -1671,6 +1656,7 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
                rssi = (-rssi) * 100;           /* Convert dBm to mBm */
                dev_dbg(adapter->dev, "info: InterpretIE: RSSI=%d\n", rssi);
 
+               timestamp = le64_to_cpu(bcn_param->timestamp);
                beacon_period = le16_to_cpu(bcn_param->beacon_period);
 
                cap_info_bitmap = le16_to_cpu(bcn_param->cap_info_bitmap);
@@ -1710,14 +1696,13 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
 
                /*
                 * If the TSF TLV was appended to the scan results, save this
-                * entry's TSF value in the networkTSF field.The networkTSF is
-                * the firmware's TSF value at the time the beacon or probe
-                * response was received.
+                * entry's TSF value in the fw_tsf field. It is the firmware's
+                * TSF value at the time the beacon or probe response was
+                * received.
                 */
                if (tsf_tlv)
-                       memcpy(&network_tsf,
-                              &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE],
-                              sizeof(network_tsf));
+                       memcpy(&fw_tsf, &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE],
+                              sizeof(fw_tsf));
 
                if (channel) {
                        struct ieee80211_channel *chan;
@@ -1740,21 +1725,19 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
 
                        if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
                                bss = cfg80211_inform_bss(priv->wdev->wiphy,
-                                             chan, bssid, network_tsf,
+                                             chan, bssid, timestamp,
                                              cap_info_bitmap, beacon_period,
                                              ie_buf, ie_len, rssi, GFP_KERNEL);
-                               *(u8 *)bss->priv = band;
-                               cfg80211_put_bss(bss);
-
+                               bss_priv = (struct mwifiex_bss_priv *)bss->priv;
+                               bss_priv->band = band;
+                               bss_priv->fw_tsf = fw_tsf;
                                if (priv->media_connected &&
                                    !memcmp(bssid,
                                            priv->curr_bss_params.bss_descriptor
                                            .mac_address, ETH_ALEN))
-                                       mwifiex_update_curr_bss_params
-                                                       (priv, bssid, rssi,
-                                                        ie_buf, ie_len,
-                                                        beacon_period,
-                                                        cap_info_bitmap, band);
+                                       mwifiex_update_curr_bss_params(priv,
+                                                                      bss);
+                               cfg80211_put_bss(bss);
                        }
                } else {
                        dev_dbg(adapter->dev, "missing BSS channel IE\n");
index f8012e2b7f7c735c99394f314a314073a330dd87..1aa45c4295bb082a17828e7da0c18a079a095b06 100644 (file)
@@ -123,6 +123,9 @@ mwifiex_sdio_remove(struct sdio_func *func)
        if (!adapter || !adapter->priv_num)
                return;
 
+       /* In case driver is removed when asynchronous FW load is in progress */
+       wait_for_completion(&adapter->fw_load);
+
        if (user_rmmod) {
                if (adapter->is_suspended)
                        mwifiex_sdio_resume(adapter->dev);
index e90c34d9c63d550223914e30c4087cd825e644a9..1f7110577b9d9205d26b4aec4d2590b46db5a075 100644 (file)
@@ -988,7 +988,7 @@ mwifiex_cmd_802_11_subsc_evt(struct mwifiex_private *priv,
                rssi_tlv->abs_value = subsc_evt_cfg->bcn_h_rssi_cfg.abs_value;
                rssi_tlv->evt_freq = subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq;
 
-               dev_dbg(priv->adapter->dev, "Cfg Beacon Low Rssi event, "
+               dev_dbg(priv->adapter->dev, "Cfg Beacon High Rssi event, "
                        "RSSI:-%d dBm, Freq:%d\n",
                        subsc_evt_cfg->bcn_h_rssi_cfg.abs_value,
                        subsc_evt_cfg->bcn_h_rssi_cfg.evt_freq);
index 8ba58d9353280e3cbac90dc8efafbd79463ab56d..58970e0f7d136e88cf6242ba52654989c21df0c3 100644 (file)
@@ -155,20 +155,29 @@ int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
  * information.
  */
 int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
-                             u8 *bssid, s32 rssi, u8 *ie_buf,
-                             size_t ie_len, u16 beacon_period,
-                             u16 cap_info_bitmap, u8 band,
+                             struct cfg80211_bss *bss,
                              struct mwifiex_bssdescriptor *bss_desc)
 {
        int ret;
+       u8 *beacon_ie;
+       struct mwifiex_bss_priv *bss_priv = (void *)bss->priv;
 
-       memcpy(bss_desc->mac_address, bssid, ETH_ALEN);
-       bss_desc->rssi = rssi;
-       bss_desc->beacon_buf = ie_buf;
-       bss_desc->beacon_buf_size = ie_len;
-       bss_desc->beacon_period = beacon_period;
-       bss_desc->cap_info_bitmap = cap_info_bitmap;
-       bss_desc->bss_band = band;
+       beacon_ie = kmemdup(bss->information_elements, bss->len_beacon_ies,
+                           GFP_KERNEL);
+       if (!beacon_ie) {
+               dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
+               return -ENOMEM;
+       }
+
+       memcpy(bss_desc->mac_address, bss->bssid, ETH_ALEN);
+       bss_desc->rssi = bss->signal;
+       bss_desc->beacon_buf = beacon_ie;
+       bss_desc->beacon_buf_size = bss->len_beacon_ies;
+       bss_desc->beacon_period = bss->beacon_interval;
+       bss_desc->cap_info_bitmap = bss->capability;
+       bss_desc->bss_band = bss_priv->band;
+       bss_desc->fw_tsf = bss_priv->fw_tsf;
+       bss_desc->timestamp = bss->tsf;
        if (bss_desc->cap_info_bitmap & WLAN_CAPABILITY_PRIVACY) {
                dev_dbg(priv->adapter->dev, "info: InterpretIE: AP WEP enabled\n");
                bss_desc->privacy = MWIFIEX_802_11_PRIV_FILTER_8021X_WEP;
@@ -180,9 +189,9 @@ int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
        else
                bss_desc->bss_mode = NL80211_IFTYPE_STATION;
 
-       ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc,
-                                             ie_buf, ie_len);
+       ret = mwifiex_update_bss_desc_with_ie(priv->adapter, bss_desc);
 
+       kfree(beacon_ie);
        return ret;
 }
 
@@ -197,7 +206,6 @@ int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
        int ret;
        struct mwifiex_adapter *adapter = priv->adapter;
        struct mwifiex_bssdescriptor *bss_desc = NULL;
-       u8 *beacon_ie = NULL;
 
        priv->scan_block = false;
 
@@ -210,19 +218,7 @@ int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
                        return -ENOMEM;
                }
 
-               beacon_ie = kmemdup(bss->information_elements,
-                                       bss->len_beacon_ies, GFP_KERNEL);
-               if (!beacon_ie) {
-                       kfree(bss_desc);
-                       dev_err(priv->adapter->dev, " failed to alloc beacon_ie\n");
-                       return -ENOMEM;
-               }
-
-               ret = mwifiex_fill_new_bss_desc(priv, bss->bssid, bss->signal,
-                                               beacon_ie, bss->len_beacon_ies,
-                                               bss->beacon_interval,
-                                               bss->capability,
-                                               *(u8 *)bss->priv, bss_desc);
+               ret = mwifiex_fill_new_bss_desc(priv, bss, bss_desc);
                if (ret)
                        goto done;
        }
@@ -269,7 +265,6 @@ int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
                    (!mwifiex_ssid_cmp(&priv->curr_bss_params.bss_descriptor.
                                       ssid, &bss_desc->ssid))) {
                        kfree(bss_desc);
-                       kfree(beacon_ie);
                        return 0;
                }
 
@@ -304,7 +299,6 @@ int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
 
 done:
        kfree(bss_desc);
-       kfree(beacon_ie);
        return ret;
 }
 
@@ -468,7 +462,8 @@ int mwifiex_get_bss_info(struct mwifiex_private *priv,
 
        info->bss_chan = bss_desc->channel;
 
-       info->region_code = adapter->region_code;
+       memcpy(info->country_code, priv->country_code,
+              IEEE80211_COUNTRY_STRING_LEN);
 
        info->media_connected = priv->media_connected;
 
@@ -995,6 +990,39 @@ static int mwifiex_set_wapi_ie(struct mwifiex_private *priv,
        return 0;
 }
 
+/*
+ * IOCTL request handler to set/reset WPS IE.
+ *
+ * The supplied WPS IE is treated as a opaque buffer. Only the first field
+ * is checked to internally enable WPS. If buffer length is zero, the existing
+ * WPS IE is reset.
+ */
+static int mwifiex_set_wps_ie(struct mwifiex_private *priv,
+                              u8 *ie_data_ptr, u16 ie_len)
+{
+       if (ie_len) {
+               priv->wps_ie = kzalloc(MWIFIEX_MAX_VSIE_LEN, GFP_KERNEL);
+               if (!priv->wps_ie)
+                       return -ENOMEM;
+               if (ie_len > sizeof(priv->wps_ie)) {
+                       dev_dbg(priv->adapter->dev,
+                               "info: failed to copy WPS IE, too big\n");
+                       kfree(priv->wps_ie);
+                       return -1;
+               }
+               memcpy(priv->wps_ie, ie_data_ptr, ie_len);
+               priv->wps_ie_len = ie_len;
+               dev_dbg(priv->adapter->dev, "cmd: Set wps_ie_len=%d IE=%#x\n",
+                       priv->wps_ie_len, priv->wps_ie[0]);
+       } else {
+               kfree(priv->wps_ie);
+               priv->wps_ie_len = ie_len;
+               dev_dbg(priv->adapter->dev,
+                       "info: Reset wps_ie_len=%d\n", priv->wps_ie_len);
+       }
+       return 0;
+}
+
 /*
  * IOCTL request handler to set WAPI key.
  *
@@ -1408,6 +1436,7 @@ mwifiex_set_gen_ie_helper(struct mwifiex_private *priv, u8 *ie_data_ptr,
                        priv->wps.session_enable = true;
                        dev_dbg(priv->adapter->dev,
                                "info: WPS Session Enabled.\n");
+                       ret = mwifiex_set_wps_ie(priv, ie_data_ptr, ie_len);
                }
 
                /* Append the passed data to the end of the
index b48674b577e6938e34e10af87c447ec66195e065..e30cc32f82791a69a910ab79dfc8bc8541c60bab 100644 (file)
@@ -5893,18 +5893,7 @@ static struct pci_driver mwl8k_driver = {
        .shutdown       = __devexit_p(mwl8k_shutdown),
 };
 
-static int __init mwl8k_init(void)
-{
-       return pci_register_driver(&mwl8k_driver);
-}
-
-static void __exit mwl8k_exit(void)
-{
-       pci_unregister_driver(&mwl8k_driver);
-}
-
-module_init(mwl8k_init);
-module_exit(mwl8k_exit);
+module_pci_driver(mwl8k_driver);
 
 MODULE_DESCRIPTION(MWL8K_DESC);
 MODULE_VERSION(MWL8K_VERSION);
index 4df8cf64b56ce553d1c1a537741d2f995d414b4c..400a3521764406df48dbde06c5074ee298dd6c69 100644 (file)
@@ -379,11 +379,8 @@ void orinoco_cache_fw(struct orinoco_private *priv, int ap)
 
 void orinoco_uncache_fw(struct orinoco_private *priv)
 {
-       if (priv->cached_pri_fw)
-               release_firmware(priv->cached_pri_fw);
-       if (priv->cached_fw)
-               release_firmware(priv->cached_fw);
-
+       release_firmware(priv->cached_pri_fw);
+       release_firmware(priv->cached_fw);
        priv->cached_pri_fw = NULL;
        priv->cached_fw = NULL;
 }
index 45df728183fdec6b4bd12017a154103d7069821f..89318adc8c7f0427ec8e95caed78a36312a934b8 100644 (file)
@@ -667,15 +667,4 @@ static struct pci_driver p54p_driver = {
        .driver.pm      = P54P_PM_OPS,
 };
 
-static int __init p54p_init(void)
-{
-       return pci_register_driver(&p54p_driver);
-}
-
-static void __exit p54p_exit(void)
-{
-       pci_unregister_driver(&p54p_driver);
-}
-
-module_init(p54p_init);
-module_exit(p54p_exit);
+module_pci_driver(p54p_driver);
index 9b796cae4afe8436ee04556d0227d8b57d021ff7..a01606b36e03f836a5cc57ab292dd47f2ba2352f 100644 (file)
@@ -693,8 +693,6 @@ mgt_update_addr(islpci_private *priv)
        return ret;
 }
 
-#define VEC_SIZE(a) ARRAY_SIZE(a)
-
 int
 mgt_commit(islpci_private *priv)
 {
@@ -704,10 +702,10 @@ mgt_commit(islpci_private *priv)
        if (islpci_get_state(priv) < PRV_STATE_INIT)
                return 0;
 
-       rvalue = mgt_commit_list(priv, commit_part1, VEC_SIZE(commit_part1));
+       rvalue = mgt_commit_list(priv, commit_part1, ARRAY_SIZE(commit_part1));
 
        if (priv->iw_mode != IW_MODE_MONITOR)
-               rvalue |= mgt_commit_list(priv, commit_part2, VEC_SIZE(commit_part2));
+               rvalue |= mgt_commit_list(priv, commit_part2, ARRAY_SIZE(commit_part2));
 
        u = OID_INL_MODE;
        rvalue |= mgt_commit_list(priv, &u, 1);
index 3a6b40239bc1473a219921f11b0f5e50a72c7bf7..5e6b5014316591114884536de8c349e7a2ec0b4b 100644 (file)
@@ -1828,15 +1828,4 @@ static struct pci_driver rt2400pci_driver = {
        .resume         = rt2x00pci_resume,
 };
 
-static int __init rt2400pci_init(void)
-{
-       return pci_register_driver(&rt2400pci_driver);
-}
-
-static void __exit rt2400pci_exit(void)
-{
-       pci_unregister_driver(&rt2400pci_driver);
-}
-
-module_init(rt2400pci_init);
-module_exit(rt2400pci_exit);
+module_pci_driver(rt2400pci_driver);
index dcc0e1fcca77726e002ed490dc41aa640655830b..136b849f11b5c911d9d83285a139b68cc1133396 100644 (file)
@@ -2119,15 +2119,4 @@ static struct pci_driver rt2500pci_driver = {
        .resume         = rt2x00pci_resume,
 };
 
-static int __init rt2500pci_init(void)
-{
-       return pci_register_driver(&rt2500pci_driver);
-}
-
-static void __exit rt2500pci_exit(void)
-{
-       pci_unregister_driver(&rt2500pci_driver);
-}
-
-module_init(rt2500pci_init);
-module_exit(rt2500pci_exit);
+module_pci_driver(rt2500pci_driver);
index 1de9c752c88b54094b320a08812f83dc931f66e7..c88fd3e6109002c0e95bcd10737af0d64c0d27a6 100644 (file)
@@ -1912,7 +1912,7 @@ static struct usb_device_id rt2500usb_device_table[] = {
        { USB_DEVICE(0x0b05, 0x1706) },
        { USB_DEVICE(0x0b05, 0x1707) },
        /* Belkin */
-       { USB_DEVICE(0x050d, 0x7050) },
+       { USB_DEVICE(0x050d, 0x7050) }, /* FCC ID: K7SF5D7050A ver. 2.x */
        { USB_DEVICE(0x050d, 0x7051) },
        /* Cisco Systems */
        { USB_DEVICE(0x13b1, 0x000d) },
index 6c0a12ea6a15a44ca94a85f5e2ca79b75d08f916..bd1980202f19a5eae9bb33f449479884e27531dd 100644 (file)
@@ -290,11 +290,25 @@ int rt2800_wait_wpdma_ready(struct rt2x00_dev *rt2x00dev)
                msleep(10);
        }
 
-       ERROR(rt2x00dev, "WPDMA TX/RX busy, aborting.\n");
+       ERROR(rt2x00dev, "WPDMA TX/RX busy [0x%08x].\n", reg);
        return -EACCES;
 }
 EXPORT_SYMBOL_GPL(rt2800_wait_wpdma_ready);
 
+void rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev)
+{
+       u32 reg;
+
+       rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
+       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
+       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
+       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
+       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
+       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
+       rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
+}
+EXPORT_SYMBOL_GPL(rt2800_disable_wpdma);
+
 static bool rt2800_check_firmware_crc(const u8 *data, const size_t len)
 {
        u16 fw_crc;
@@ -412,6 +426,8 @@ int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
                rt2800_register_write(rt2x00dev, PWR_PIN_CFG, 0x00000002);
        }
 
+       rt2800_disable_wpdma(rt2x00dev);
+
        /*
         * Write firmware to the device.
         */
@@ -436,10 +452,7 @@ int rt2800_load_firmware(struct rt2x00_dev *rt2x00dev,
         * Disable DMA, will be reenabled later when enabling
         * the radio.
         */
-       rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
-       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
-       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
-       rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
+       rt2800_disable_wpdma(rt2x00dev);
 
        /*
         * Initialize firmware.
@@ -2717,13 +2730,7 @@ static int rt2800_init_registers(struct rt2x00_dev *rt2x00dev)
        unsigned int i;
        int ret;
 
-       rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
-       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
-       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_DMA_BUSY, 0);
-       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
-       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_RX_DMA_BUSY, 0);
-       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
-       rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
+       rt2800_disable_wpdma(rt2x00dev);
 
        ret = rt2800_drv_init_registers(rt2x00dev);
        if (ret)
@@ -3997,10 +4004,7 @@ void rt2800_disable_radio(struct rt2x00_dev *rt2x00dev)
 {
        u32 reg;
 
-       rt2800_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
-       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
-       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
-       rt2800_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
+       rt2800_disable_wpdma(rt2x00dev);
 
        /* Wait for DMA, ignore error */
        rt2800_wait_wpdma_ready(rt2x00dev);
index 419e36cb06be3d393ec036ccc614414e4e3f2ddc..18a0b67b4c68daa23f6759a5ac407e04209bfc2c 100644 (file)
@@ -208,5 +208,6 @@ int rt2800_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
                        u8 buf_size);
 int rt2800_get_survey(struct ieee80211_hw *hw, int idx,
                      struct survey_info *survey);
+void rt2800_disable_wpdma(struct rt2x00_dev *rt2x00dev);
 
 #endif /* RT2800LIB_H */
index 0397bbf0ce018d7d651fc0eb82283aeb4db9abe7..931331d952172ca8ba92f5b77c1814e2f613b141 100644 (file)
@@ -361,7 +361,6 @@ static void rt2800pci_clear_entry(struct queue_entry *entry)
 static int rt2800pci_init_queues(struct rt2x00_dev *rt2x00dev)
 {
        struct queue_entry_priv_pci *entry_priv;
-       u32 reg;
 
        /*
         * Initialize registers.
@@ -394,6 +393,16 @@ static int rt2800pci_init_queues(struct rt2x00_dev *rt2x00dev)
        rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX3, 0);
        rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX3, 0);
 
+       rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR4, 0);
+       rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT4, 0);
+       rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX4, 0);
+       rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX4, 0);
+
+       rt2x00pci_register_write(rt2x00dev, TX_BASE_PTR5, 0);
+       rt2x00pci_register_write(rt2x00dev, TX_MAX_CNT5, 0);
+       rt2x00pci_register_write(rt2x00dev, TX_CTX_IDX5, 0);
+       rt2x00pci_register_write(rt2x00dev, TX_DTX_IDX5, 0);
+
        entry_priv = rt2x00dev->rx->entries[0].priv_data;
        rt2x00pci_register_write(rt2x00dev, RX_BASE_PTR, entry_priv->desc_dma);
        rt2x00pci_register_write(rt2x00dev, RX_MAX_CNT,
@@ -402,14 +411,7 @@ static int rt2800pci_init_queues(struct rt2x00_dev *rt2x00dev)
                                 rt2x00dev->rx[0].limit - 1);
        rt2x00pci_register_write(rt2x00dev, RX_DRX_IDX, 0);
 
-       /*
-        * Enable global DMA configuration
-        */
-       rt2x00pci_register_read(rt2x00dev, WPDMA_GLO_CFG, &reg);
-       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_TX_DMA, 0);
-       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_ENABLE_RX_DMA, 0);
-       rt2x00_set_field32(&reg, WPDMA_GLO_CFG_TX_WRITEBACK_DONE, 1);
-       rt2x00pci_register_write(rt2x00dev, WPDMA_GLO_CFG, reg);
+       rt2800_disable_wpdma(rt2x00dev);
 
        rt2x00pci_register_write(rt2x00dev, DELAY_INT_CFG, 0);
 
@@ -504,8 +506,10 @@ static int rt2800pci_enable_radio(struct rt2x00_dev *rt2x00dev)
 {
        int retval;
 
-       if (unlikely(rt2800_wait_wpdma_ready(rt2x00dev) ||
-                    rt2800pci_init_queues(rt2x00dev)))
+       /* Wait for DMA, ignore error until we initialize queues. */
+       rt2800_wait_wpdma_ready(rt2x00dev);
+
+       if (unlikely(rt2800pci_init_queues(rt2x00dev)))
                return -EIO;
 
        retval = rt2800_enable_radio(rt2x00dev);
@@ -1184,7 +1188,9 @@ static DEFINE_PCI_DEVICE_TABLE(rt2800pci_device_table) = {
        { PCI_DEVICE(0x1814, 0x3593) },
 #endif
 #ifdef CONFIG_RT2800PCI_RT53XX
+       { PCI_DEVICE(0x1814, 0x5362) },
        { PCI_DEVICE(0x1814, 0x5390) },
+       { PCI_DEVICE(0x1814, 0x5392) },
        { PCI_DEVICE(0x1814, 0x539a) },
        { PCI_DEVICE(0x1814, 0x539f) },
 #endif
index 90cc5e77265058cfa894cdc5111e34ee542774a2..dd87d41ac936bcf9093fcc21f0b545e40a4a5715 100644 (file)
@@ -391,9 +391,10 @@ void rt2x00lib_txdone(struct queue_entry *entry,
                tx_info->flags |= IEEE80211_TX_STAT_AMPDU;
                tx_info->status.ampdu_len = 1;
                tx_info->status.ampdu_ack_len = success ? 1 : 0;
-
-               if (!success)
-                       tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
+               /*
+                * TODO: Need to tear down BA session here
+                * if not successful.
+                */
        }
 
        if (rate_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
index e0c6d117429d85c85439b76f41c72ead820cf906..ee22bd74579d7326373af68f6f3c0a4a879e3010 100644 (file)
@@ -3092,15 +3092,4 @@ static struct pci_driver rt61pci_driver = {
        .resume         = rt2x00pci_resume,
 };
 
-static int __init rt61pci_init(void)
-{
-       return pci_register_driver(&rt61pci_driver);
-}
-
-static void __exit rt61pci_exit(void)
-{
-       pci_unregister_driver(&rt61pci_driver);
-}
-
-module_init(rt61pci_init);
-module_exit(rt61pci_exit);
+module_pci_driver(rt61pci_driver);
index e477a964081df9d9148b3fab2492d818e473340d..155136691a384271c09875348ef9fdf34467c8a7 100644 (file)
@@ -2412,6 +2412,7 @@ static struct usb_device_id rt73usb_device_table[] = {
        { USB_DEVICE(0x0b05, 0x1723) },
        { USB_DEVICE(0x0b05, 0x1724) },
        /* Belkin */
+       { USB_DEVICE(0x050d, 0x7050) }, /* FCC ID: K7SF5D7050B ver. 3.x */
        { USB_DEVICE(0x050d, 0x705a) },
        { USB_DEVICE(0x050d, 0x905b) },
        { USB_DEVICE(0x050d, 0x905c) },
index 2f14a5fb0cbb97007880b4cbf76fba2449500ac1..2bebcb71a1e946c122f26ceb293f306904256ac9 100644 (file)
@@ -1173,15 +1173,4 @@ static struct pci_driver rtl8180_driver = {
 #endif /* CONFIG_PM */
 };
 
-static int __init rtl8180_init(void)
-{
-       return pci_register_driver(&rtl8180_driver);
-}
-
-static void __exit rtl8180_exit(void)
-{
-       pci_unregister_driver(&rtl8180_driver);
-}
-
-module_init(rtl8180_init);
-module_exit(rtl8180_exit);
+module_pci_driver(rtl8180_driver);
index cf53ac9d6f23f2787561883f15985a974abb7f8d..d8114962b0c9abc426d2f30aaf7311e57cc3726f 100644 (file)
@@ -294,6 +294,7 @@ static void rtl8187_tx(struct ieee80211_hw *dev, struct sk_buff *skb)
                hdr->retry = cpu_to_le32((info->control.rates[0].count - 1) << 8);
                hdr->tx_duration =
                        ieee80211_generic_frame_duration(dev, priv->vif,
+                                                        info->band,
                                                         skb->len, txrate);
                buf = hdr;
 
index 288b035a3579b06b2dfba78c17369416b4ab2a44..81d0c9b343282086667dd08069a18a9b5a9d497f 100644 (file)
@@ -34,6 +34,7 @@
 #include "ps.h"
 #include "efuse.h"
 #include <linux/export.h>
+#include <linux/kmemleak.h>
 
 static const u16 pcibridge_vendors[PCI_BRIDGE_VENDOR_MAX] = {
        PCI_VENDOR_ID_INTEL,
@@ -1099,6 +1100,7 @@ static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw)
                        u32 bufferaddress;
                        if (!skb)
                                return 0;
+                       kmemleak_not_leak(skb);
                        entry = &rtlpci->rx_ring[rx_queue_idx].desc[i];
 
                        /*skb->dev = dev; */
index c20b3c30f62ed7bfdeef57cebef888228ec07d9f..692c8ef5ee89f90615ed2c0b55c6d0f2368ddd62 100644 (file)
@@ -34,6 +34,7 @@
 #include "../rtl8192ce/def.h"
 #include "fw_common.h"
 #include <linux/export.h>
+#include <linux/kmemleak.h>
 
 static void _rtl92c_enable_fw_download(struct ieee80211_hw *hw, bool enable)
 {
@@ -776,6 +777,8 @@ void rtl92c_set_fw_rsvdpagepkt(struct ieee80211_hw *hw, bool dl_finished)
        skb = dev_alloc_skb(totalpacketlen);
        if (!skb)
                return;
+       kmemleak_not_leak(skb);
+
        memcpy((u8 *) skb_put(skb, totalpacketlen),
               &reserved_page_packet, totalpacketlen);
 
index 2c3b73366cd2e2928423c1f600d7106966bd34c4..3aa927f8b9b93bfbf0b12d9d0194966cd24900c8 100644 (file)
@@ -389,21 +389,4 @@ static struct pci_driver rtl92ce_driver = {
        .driver.pm = &rtlwifi_pm_ops,
 };
 
-static int __init rtl92ce_module_init(void)
-{
-       int ret;
-
-       ret = pci_register_driver(&rtl92ce_driver);
-       if (ret)
-               RT_ASSERT(false, "No device found\n");
-
-       return ret;
-}
-
-static void __exit rtl92ce_module_exit(void)
-{
-       pci_unregister_driver(&rtl92ce_driver);
-}
-
-module_init(rtl92ce_module_init);
-module_exit(rtl92ce_module_exit);
+module_pci_driver(rtl92ce_driver);
index 82c85286ab2e25852eb7e45f878fc7b783e07f97..7737fb0c6661ac3031bdee7fb8922593dd76dd2b 100644 (file)
@@ -338,6 +338,7 @@ static struct usb_device_id rtl8192c_usb_ids[] = {
        {RTL_USB_DEVICE(0x2019, 0x1201, rtl92cu_hal_cfg)}, /*Planex-Vencer*/
 
        /****** 8192CU ********/
+       {RTL_USB_DEVICE(0x050d, 0x1004, rtl92cu_hal_cfg)}, /*Belcom-SurfN300*/
        {RTL_USB_DEVICE(0x050d, 0x2102, rtl92cu_hal_cfg)}, /*Belcom-Sercomm*/
        {RTL_USB_DEVICE(0x050d, 0x2103, rtl92cu_hal_cfg)}, /*Belcom-Edimax*/
        {RTL_USB_DEVICE(0x0586, 0x341f, rtl92cu_hal_cfg)}, /*Zyxel -Abocom*/
index eafdf76ed64db95c42972e7fb725ad4b7a4f3a18..939c905f547fd179c8e1af49b266893bdbc14694 100644 (file)
@@ -151,9 +151,6 @@ enum version_8192d {
 
 /* for 92D */
 #define CHIP_92D_SINGLEPHY             BIT(9)
-#define C_CUT_VERSION                  BIT(13)
-#define D_CUT_VERSION                  ((BIT(12)|BIT(13)))
-#define E_CUT_VERSION                  BIT(14)
 
 /* Chip specific */
 #define CHIP_BONDING_IDENTIFIER(_value)        (((_value)>>22)&0x3)
@@ -173,7 +170,10 @@ enum version_8192d {
 #define RF_TYPE_1T2R                   BIT(4)
 #define RF_TYPE_2T2R                   BIT(5)
 #define CHIP_VENDOR_UMC                        BIT(7)
-#define B_CUT_VERSION                  BIT(12)
+#define CHIP_92D_B_CUT                 BIT(12)
+#define CHIP_92D_C_CUT                 BIT(13)
+#define CHIP_92D_D_CUT                 (BIT(13)|BIT(12))
+#define CHIP_92D_E_CUT                 BIT(14)
 
 /* MASK */
 #define IC_TYPE_MASK                   (BIT(0)|BIT(1)|BIT(2))
@@ -205,15 +205,13 @@ enum version_8192d {
                                         CHIP_92D) ? true : false)
 #define IS_92D_C_CUT(version)          ((IS_92D(version)) ?            \
                                 ((GET_CVID_CUT_VERSION(version) ==     \
-                                0x2000) ? true : false) : false)
+                                CHIP_92D_C_CUT) ? true : false) : false)
 #define IS_92D_D_CUT(version)                  ((IS_92D(version)) ?    \
                                 ((GET_CVID_CUT_VERSION(version) ==     \
-                                0x3000) ? true : false) : false)
+                                CHIP_92D_D_CUT) ? true : false) : false)
 #define IS_92D_E_CUT(version)          ((IS_92D(version)) ?            \
                                 ((GET_CVID_CUT_VERSION(version) ==     \
-                                0x4000) ? true : false) : false)
-#define CHIP_92D_C_CUT                 BIT(10)
-#define CHIP_92D_D_CUT                 BIT(11)
+                                CHIP_92D_E_CUT) ? true : false) : false)
 
 enum rf_optype {
        RF_OP_BY_SW_3WIRE = 0,
index 7ac9b8cb2cedbbf2e8421a9e3a838fc02ba8f0f5..b338d526c42278e5aa3ff97960b76ac5c43f3022 100644 (file)
@@ -1743,6 +1743,10 @@ static void _rtl92de_efuse_update_chip_version(struct ieee80211_hw *hw)
                chipver |= CHIP_92D_D_CUT;
                RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "D-CUT!!!\n");
                break;
+       case 0xCC33:
+               chipver |= CHIP_92D_E_CUT;
+               RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "E-CUT!!!\n");
+               break;
        default:
                chipver |= CHIP_92D_D_CUT;
                RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "Unknown CUT!\n");
index f1b36005c6a2c9496bdce302e17571a144cf2393..730bcc91952948160a0b50976b90f75e7c6bcc11 100644 (file)
@@ -450,21 +450,4 @@ static struct pci_driver rtl92se_driver = {
        .driver.pm = &rtlwifi_pm_ops,
 };
 
-static int __init rtl92se_module_init(void)
-{
-       int ret = 0;
-
-       ret = pci_register_driver(&rtl92se_driver);
-       if (ret)
-               RT_ASSERT(false, "No device found\n");
-
-       return ret;
-}
-
-static void __exit rtl92se_module_exit(void)
-{
-       pci_unregister_driver(&rtl92se_driver);
-}
-
-module_init(rtl92se_module_init);
-module_exit(rtl92se_module_exit);
+module_pci_driver(rtl92se_driver);
diff --git a/drivers/net/wireless/ti/Kconfig b/drivers/net/wireless/ti/Kconfig
new file mode 100644 (file)
index 0000000..1a72932
--- /dev/null
@@ -0,0 +1,14 @@
+menuconfig WL_TI
+       bool "TI Wireless LAN support"
+       ---help---
+         This section contains support for all the wireless drivers
+         for Texas Instruments WLAN chips, such as wl1251 and the wl12xx
+         family.
+
+if WL_TI
+source "drivers/net/wireless/ti/wl1251/Kconfig"
+source "drivers/net/wireless/ti/wl12xx/Kconfig"
+
+# keep last for automatic dependencies
+source "drivers/net/wireless/ti/wlcore/Kconfig"
+endif # WL_TI
diff --git a/drivers/net/wireless/ti/Makefile b/drivers/net/wireless/ti/Makefile
new file mode 100644 (file)
index 0000000..0a56562
--- /dev/null
@@ -0,0 +1,4 @@
+obj-$(CONFIG_WLCORE)                   += wlcore/
+obj-$(CONFIG_WL12XX)                   += wl12xx/
+obj-$(CONFIG_WL12XX_PLATFORM_DATA)     += wlcore/
+obj-$(CONFIG_WL1251)                   += wl1251/
diff --git a/drivers/net/wireless/ti/wl1251/Kconfig b/drivers/net/wireless/ti/wl1251/Kconfig
new file mode 100644 (file)
index 0000000..1fb6584
--- /dev/null
@@ -0,0 +1,33 @@
+menuconfig WL1251
+       tristate "TI wl1251 driver support"
+       depends on MAC80211 && EXPERIMENTAL && GENERIC_HARDIRQS
+       select FW_LOADER
+       select CRC7
+       ---help---
+         This will enable TI wl1251 driver support. The drivers make
+         use of the mac80211 stack.
+
+         If you choose to build a module, it'll be called wl1251. Say
+         N if unsure.
+
+config WL1251_SPI
+       tristate "TI wl1251 SPI support"
+       depends on WL1251 && SPI_MASTER
+       ---help---
+         This module adds support for the SPI interface of adapters using
+         TI wl1251 chipset.  Select this if your platform is using
+         the SPI bus.
+
+         If you choose to build a module, it'll be called wl1251_spi.
+         Say N if unsure.
+
+config WL1251_SDIO
+       tristate "TI wl1251 SDIO support"
+       depends on WL1251 && MMC
+       ---help---
+         This module adds support for the SDIO interface of adapters using
+         TI wl1251 chipset.  Select this if your platform is using
+         the SDIO bus.
+
+         If you choose to build a module, it'll be called
+         wl1251_sdio. Say N if unsure.
diff --git a/drivers/net/wireless/ti/wl1251/Makefile b/drivers/net/wireless/ti/wl1251/Makefile
new file mode 100644 (file)
index 0000000..a5c6328
--- /dev/null
@@ -0,0 +1,10 @@
+wl1251-objs            = main.o event.o tx.o rx.o ps.o cmd.o \
+                         acx.o boot.o init.o debugfs.o io.o
+wl1251_spi-objs                += spi.o
+wl1251_sdio-objs       += sdio.o
+
+obj-$(CONFIG_WL1251)           += wl1251.o
+obj-$(CONFIG_WL1251_SPI)       += wl1251_spi.o
+obj-$(CONFIG_WL1251_SDIO)      += wl1251_sdio.o
+
+ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/ti/wl1251/acx.c b/drivers/net/wireless/ti/wl1251/acx.c
new file mode 100644 (file)
index 0000000..ad87a1a
--- /dev/null
@@ -0,0 +1,1097 @@
+#include "acx.h"
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/crc7.h>
+
+#include "wl1251.h"
+#include "reg.h"
+#include "cmd.h"
+#include "ps.h"
+
+int wl1251_acx_frame_rates(struct wl1251 *wl, u8 ctrl_rate, u8 ctrl_mod,
+                          u8 mgt_rate, u8 mgt_mod)
+{
+       struct acx_fw_gen_frame_rates *rates;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx frame rates");
+
+       rates = kzalloc(sizeof(*rates), GFP_KERNEL);
+       if (!rates) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       rates->tx_ctrl_frame_rate = ctrl_rate;
+       rates->tx_ctrl_frame_mod = ctrl_mod;
+       rates->tx_mgt_frame_rate = mgt_rate;
+       rates->tx_mgt_frame_mod = mgt_mod;
+
+       ret = wl1251_cmd_configure(wl, ACX_FW_GEN_FRAME_RATES,
+                                  rates, sizeof(*rates));
+       if (ret < 0) {
+               wl1251_error("Failed to set FW rates and modulation");
+               goto out;
+       }
+
+out:
+       kfree(rates);
+       return ret;
+}
+
+
+int wl1251_acx_station_id(struct wl1251 *wl)
+{
+       struct acx_dot11_station_id *mac;
+       int ret, i;
+
+       wl1251_debug(DEBUG_ACX, "acx dot11_station_id");
+
+       mac = kzalloc(sizeof(*mac), GFP_KERNEL);
+       if (!mac) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       for (i = 0; i < ETH_ALEN; i++)
+               mac->mac[i] = wl->mac_addr[ETH_ALEN - 1 - i];
+
+       ret = wl1251_cmd_configure(wl, DOT11_STATION_ID, mac, sizeof(*mac));
+       if (ret < 0)
+               goto out;
+
+out:
+       kfree(mac);
+       return ret;
+}
+
+int wl1251_acx_default_key(struct wl1251 *wl, u8 key_id)
+{
+       struct acx_dot11_default_key *default_key;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx dot11_default_key (%d)", key_id);
+
+       default_key = kzalloc(sizeof(*default_key), GFP_KERNEL);
+       if (!default_key) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       default_key->id = key_id;
+
+       ret = wl1251_cmd_configure(wl, DOT11_DEFAULT_KEY,
+                                  default_key, sizeof(*default_key));
+       if (ret < 0) {
+               wl1251_error("Couldn't set default key");
+               goto out;
+       }
+
+       wl->default_key = key_id;
+
+out:
+       kfree(default_key);
+       return ret;
+}
+
+int wl1251_acx_wake_up_conditions(struct wl1251 *wl, u8 wake_up_event,
+                                 u8 listen_interval)
+{
+       struct acx_wake_up_condition *wake_up;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx wake up conditions");
+
+       wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
+       if (!wake_up) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wake_up->wake_up_event = wake_up_event;
+       wake_up->listen_interval = listen_interval;
+
+       ret = wl1251_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
+                                  wake_up, sizeof(*wake_up));
+       if (ret < 0) {
+               wl1251_warning("could not set wake up conditions: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(wake_up);
+       return ret;
+}
+
+int wl1251_acx_sleep_auth(struct wl1251 *wl, u8 sleep_auth)
+{
+       struct acx_sleep_auth *auth;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx sleep auth");
+
+       auth = kzalloc(sizeof(*auth), GFP_KERNEL);
+       if (!auth) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       auth->sleep_auth = sleep_auth;
+
+       ret = wl1251_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
+
+out:
+       kfree(auth);
+       return ret;
+}
+
+int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len)
+{
+       struct acx_revision *rev;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx fw rev");
+
+       rev = kzalloc(sizeof(*rev), GFP_KERNEL);
+       if (!rev) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ret = wl1251_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
+       if (ret < 0) {
+               wl1251_warning("ACX_FW_REV interrogate failed");
+               goto out;
+       }
+
+       /* be careful with the buffer sizes */
+       strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
+
+       /*
+        * if the firmware version string is exactly
+        * sizeof(rev->fw_version) long or fw_len is less than
+        * sizeof(rev->fw_version) it won't be null terminated
+        */
+       buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
+
+out:
+       kfree(rev);
+       return ret;
+}
+
+int wl1251_acx_tx_power(struct wl1251 *wl, int power)
+{
+       struct acx_current_tx_power *acx;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
+
+       if (power < 0 || power > 25)
+               return -EINVAL;
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->current_tx_power = power * 10;
+
+       ret = wl1251_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1251_warning("configure of tx power failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1251_acx_feature_cfg(struct wl1251 *wl)
+{
+       struct acx_feature_config *feature;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx feature cfg");
+
+       feature = kzalloc(sizeof(*feature), GFP_KERNEL);
+       if (!feature) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
+       feature->data_flow_options = 0;
+       feature->options = 0;
+
+       ret = wl1251_cmd_configure(wl, ACX_FEATURE_CFG,
+                                  feature, sizeof(*feature));
+       if (ret < 0) {
+               wl1251_error("Couldn't set HW encryption");
+               goto out;
+       }
+
+out:
+       kfree(feature);
+       return ret;
+}
+
+int wl1251_acx_mem_map(struct wl1251 *wl, struct acx_header *mem_map,
+                      size_t len)
+{
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx mem map");
+
+       ret = wl1251_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1251_acx_data_path_params(struct wl1251 *wl,
+                               struct acx_data_path_params_resp *resp)
+{
+       struct acx_data_path_params *params;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx data path params");
+
+       params = kzalloc(sizeof(*params), GFP_KERNEL);
+       if (!params) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       params->rx_packet_ring_chunk_size = DP_RX_PACKET_RING_CHUNK_SIZE;
+       params->tx_packet_ring_chunk_size = DP_TX_PACKET_RING_CHUNK_SIZE;
+
+       params->rx_packet_ring_chunk_num = DP_RX_PACKET_RING_CHUNK_NUM;
+       params->tx_packet_ring_chunk_num = DP_TX_PACKET_RING_CHUNK_NUM;
+
+       params->tx_complete_threshold = 1;
+
+       params->tx_complete_ring_depth = FW_TX_CMPLT_BLOCK_SIZE;
+
+       params->tx_complete_timeout = DP_TX_COMPLETE_TIME_OUT;
+
+       ret = wl1251_cmd_configure(wl, ACX_DATA_PATH_PARAMS,
+                                  params, sizeof(*params));
+       if (ret < 0)
+               goto out;
+
+       /* FIXME: shouldn't this be ACX_DATA_PATH_RESP_PARAMS? */
+       ret = wl1251_cmd_interrogate(wl, ACX_DATA_PATH_PARAMS,
+                                    resp, sizeof(*resp));
+
+       if (ret < 0) {
+               wl1251_warning("failed to read data path parameters: %d", ret);
+               goto out;
+       } else if (resp->header.cmd.status != CMD_STATUS_SUCCESS) {
+               wl1251_warning("data path parameter acx status failed");
+               ret = -EIO;
+               goto out;
+       }
+
+out:
+       kfree(params);
+       return ret;
+}
+
+int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time)
+{
+       struct acx_rx_msdu_lifetime *acx;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx rx msdu life time");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->lifetime = life_time;
+       ret = wl1251_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
+                                  acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1251_warning("failed to set rx msdu life time: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter)
+{
+       struct acx_rx_config *rx_config;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx rx config");
+
+       rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
+       if (!rx_config) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       rx_config->config_options = config;
+       rx_config->filter_options = filter;
+
+       ret = wl1251_cmd_configure(wl, ACX_RX_CFG,
+                                  rx_config, sizeof(*rx_config));
+       if (ret < 0) {
+               wl1251_warning("failed to set rx config: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(rx_config);
+       return ret;
+}
+
+int wl1251_acx_pd_threshold(struct wl1251 *wl)
+{
+       struct acx_packet_detection *pd;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx data pd threshold");
+
+       pd = kzalloc(sizeof(*pd), GFP_KERNEL);
+       if (!pd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* FIXME: threshold value not set */
+
+       ret = wl1251_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
+       if (ret < 0) {
+               wl1251_warning("failed to set pd threshold: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(pd);
+       return ret;
+}
+
+int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time)
+{
+       struct acx_slot *slot;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx slot");
+
+       slot = kzalloc(sizeof(*slot), GFP_KERNEL);
+       if (!slot) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       slot->wone_index = STATION_WONE_INDEX;
+       slot->slot_time = slot_time;
+
+       ret = wl1251_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
+       if (ret < 0) {
+               wl1251_warning("failed to set slot time: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(slot);
+       return ret;
+}
+
+int wl1251_acx_group_address_tbl(struct wl1251 *wl)
+{
+       struct acx_dot11_grp_addr_tbl *acx;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx group address tbl");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* MAC filtering */
+       acx->enabled = 0;
+       acx->num_groups = 0;
+       memset(acx->mac_table, 0, ADDRESS_GROUP_MAX_LEN);
+
+       ret = wl1251_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
+                                  acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1251_warning("failed to set group addr table: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1251_acx_service_period_timeout(struct wl1251 *wl)
+{
+       struct acx_rx_timeout *rx_timeout;
+       int ret;
+
+       rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
+       if (!rx_timeout) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wl1251_debug(DEBUG_ACX, "acx service period timeout");
+
+       rx_timeout->ps_poll_timeout = RX_TIMEOUT_PS_POLL_DEF;
+       rx_timeout->upsd_timeout = RX_TIMEOUT_UPSD_DEF;
+
+       ret = wl1251_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
+                                  rx_timeout, sizeof(*rx_timeout));
+       if (ret < 0) {
+               wl1251_warning("failed to set service period timeout: %d",
+                              ret);
+               goto out;
+       }
+
+out:
+       kfree(rx_timeout);
+       return ret;
+}
+
+int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold)
+{
+       struct acx_rts_threshold *rts;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx rts threshold");
+
+       rts = kzalloc(sizeof(*rts), GFP_KERNEL);
+       if (!rts) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       rts->threshold = rts_threshold;
+
+       ret = wl1251_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
+       if (ret < 0) {
+               wl1251_warning("failed to set rts threshold: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(rts);
+       return ret;
+}
+
+int wl1251_acx_beacon_filter_opt(struct wl1251 *wl, bool enable_filter)
+{
+       struct acx_beacon_filter_option *beacon_filter;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx beacon filter opt");
+
+       beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
+       if (!beacon_filter) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       beacon_filter->enable = enable_filter;
+       beacon_filter->max_num_beacons = 0;
+
+       ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
+                                  beacon_filter, sizeof(*beacon_filter));
+       if (ret < 0) {
+               wl1251_warning("failed to set beacon filter opt: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(beacon_filter);
+       return ret;
+}
+
+int wl1251_acx_beacon_filter_table(struct wl1251 *wl)
+{
+       struct acx_beacon_filter_ie_table *ie_table;
+       int idx = 0;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx beacon filter table");
+
+       ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
+       if (!ie_table) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* configure default beacon pass-through rules */
+       ie_table->num_ie = 1;
+       ie_table->table[idx++] = BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN;
+       ie_table->table[idx++] = BEACON_RULE_PASS_ON_APPEARANCE;
+
+       ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
+                                  ie_table, sizeof(*ie_table));
+       if (ret < 0) {
+               wl1251_warning("failed to set beacon filter table: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(ie_table);
+       return ret;
+}
+
+int wl1251_acx_conn_monit_params(struct wl1251 *wl)
+{
+       struct acx_conn_monit_params *acx;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx connection monitor parameters");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->synch_fail_thold = SYNCH_FAIL_DEFAULT_THRESHOLD;
+       acx->bss_lose_timeout = NO_BEACON_DEFAULT_TIMEOUT;
+
+       ret = wl1251_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
+                                  acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1251_warning("failed to set connection monitor "
+                              "parameters: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1251_acx_sg_enable(struct wl1251 *wl)
+{
+       struct acx_bt_wlan_coex *pta;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx sg enable");
+
+       pta = kzalloc(sizeof(*pta), GFP_KERNEL);
+       if (!pta) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       pta->enable = SG_ENABLE;
+
+       ret = wl1251_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
+       if (ret < 0) {
+               wl1251_warning("failed to set softgemini enable: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(pta);
+       return ret;
+}
+
+int wl1251_acx_sg_cfg(struct wl1251 *wl)
+{
+       struct acx_bt_wlan_coex_param *param;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx sg cfg");
+
+       param = kzalloc(sizeof(*param), GFP_KERNEL);
+       if (!param) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* BT-WLAN coext parameters */
+       param->min_rate = RATE_INDEX_24MBPS;
+       param->bt_hp_max_time = PTA_BT_HP_MAXTIME_DEF;
+       param->wlan_hp_max_time = PTA_WLAN_HP_MAX_TIME_DEF;
+       param->sense_disable_timer = PTA_SENSE_DISABLE_TIMER_DEF;
+       param->rx_time_bt_hp = PTA_PROTECTIVE_RX_TIME_DEF;
+       param->tx_time_bt_hp = PTA_PROTECTIVE_TX_TIME_DEF;
+       param->rx_time_bt_hp_fast = PTA_PROTECTIVE_RX_TIME_FAST_DEF;
+       param->tx_time_bt_hp_fast = PTA_PROTECTIVE_TX_TIME_FAST_DEF;
+       param->wlan_cycle_fast = PTA_CYCLE_TIME_FAST_DEF;
+       param->bt_anti_starvation_period = PTA_ANTI_STARVE_PERIOD_DEF;
+       param->next_bt_lp_packet = PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF;
+       param->wake_up_beacon = PTA_TIME_BEFORE_BEACON_DEF;
+       param->hp_dm_max_guard_time = PTA_HPDM_MAX_TIME_DEF;
+       param->next_wlan_packet = PTA_TIME_OUT_NEXT_WLAN_DEF;
+       param->antenna_type = PTA_ANTENNA_TYPE_DEF;
+       param->signal_type = PTA_SIGNALING_TYPE_DEF;
+       param->afh_leverage_on = PTA_AFH_LEVERAGE_ON_DEF;
+       param->quiet_cycle_num = PTA_NUMBER_QUIET_CYCLE_DEF;
+       param->max_cts = PTA_MAX_NUM_CTS_DEF;
+       param->wlan_packets_num = PTA_NUMBER_OF_WLAN_PACKETS_DEF;
+       param->bt_packets_num = PTA_NUMBER_OF_BT_PACKETS_DEF;
+       param->missed_rx_avalanche = PTA_RX_FOR_AVALANCHE_DEF;
+       param->wlan_elp_hp = PTA_ELP_HP_DEF;
+       param->bt_anti_starvation_cycles = PTA_ANTI_STARVE_NUM_CYCLE_DEF;
+       param->ack_mode_dual_ant = PTA_ACK_MODE_DEF;
+       param->pa_sd_enable = PTA_ALLOW_PA_SD_DEF;
+       param->pta_auto_mode_enable = PTA_AUTO_MODE_NO_CTS_DEF;
+       param->bt_hp_respected_num = PTA_BT_HP_RESPECTED_DEF;
+
+       ret = wl1251_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
+       if (ret < 0) {
+               wl1251_warning("failed to set sg config: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(param);
+       return ret;
+}
+
+int wl1251_acx_cca_threshold(struct wl1251 *wl)
+{
+       struct acx_energy_detection *detection;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx cca threshold");
+
+       detection = kzalloc(sizeof(*detection), GFP_KERNEL);
+       if (!detection) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       detection->rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D;
+       detection->tx_energy_detection = 0;
+
+       ret = wl1251_cmd_configure(wl, ACX_CCA_THRESHOLD,
+                                  detection, sizeof(*detection));
+       if (ret < 0)
+               wl1251_warning("failed to set cca threshold: %d", ret);
+
+out:
+       kfree(detection);
+       return ret;
+}
+
+int wl1251_acx_bcn_dtim_options(struct wl1251 *wl)
+{
+       struct acx_beacon_broadcast *bb;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx bcn dtim options");
+
+       bb = kzalloc(sizeof(*bb), GFP_KERNEL);
+       if (!bb) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
+       bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
+       bb->rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE;
+       bb->ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF;
+
+       ret = wl1251_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
+       if (ret < 0) {
+               wl1251_warning("failed to set rx config: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(bb);
+       return ret;
+}
+
+int wl1251_acx_aid(struct wl1251 *wl, u16 aid)
+{
+       struct acx_aid *acx_aid;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx aid");
+
+       acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
+       if (!acx_aid) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx_aid->aid = aid;
+
+       ret = wl1251_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
+       if (ret < 0) {
+               wl1251_warning("failed to set aid: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx_aid);
+       return ret;
+}
+
+int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask)
+{
+       struct acx_event_mask *mask;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx event mbox mask");
+
+       mask = kzalloc(sizeof(*mask), GFP_KERNEL);
+       if (!mask) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* high event mask is unused */
+       mask->high_event_mask = 0xffffffff;
+
+       mask->event_mask = event_mask;
+
+       ret = wl1251_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
+                                  mask, sizeof(*mask));
+       if (ret < 0) {
+               wl1251_warning("failed to set acx_event_mbox_mask: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(mask);
+       return ret;
+}
+
+int wl1251_acx_low_rssi(struct wl1251 *wl, s8 threshold, u8 weight,
+                       u8 depth, enum wl1251_acx_low_rssi_type type)
+{
+       struct acx_low_rssi *rssi;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx low rssi");
+
+       rssi = kzalloc(sizeof(*rssi), GFP_KERNEL);
+       if (!rssi)
+               return -ENOMEM;
+
+       rssi->threshold = threshold;
+       rssi->weight = weight;
+       rssi->depth = depth;
+       rssi->type = type;
+
+       ret = wl1251_cmd_configure(wl, ACX_LOW_RSSI, rssi, sizeof(*rssi));
+       if (ret < 0)
+               wl1251_warning("failed to set low rssi threshold: %d", ret);
+
+       kfree(rssi);
+       return ret;
+}
+
+int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble)
+{
+       struct acx_preamble *acx;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx_set_preamble");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->preamble = preamble;
+
+       ret = wl1251_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1251_warning("Setting of preamble failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1251_acx_cts_protect(struct wl1251 *wl,
+                          enum acx_ctsprotect_type ctsprotect)
+{
+       struct acx_ctsprotect *acx;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx_set_ctsprotect");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->ctsprotect = ctsprotect;
+
+       ret = wl1251_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1251_warning("Setting of ctsprotect failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime)
+{
+       struct acx_tsf_info *tsf_info;
+       int ret;
+
+       tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
+       if (!tsf_info) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ret = wl1251_cmd_interrogate(wl, ACX_TSF_INFO,
+                                    tsf_info, sizeof(*tsf_info));
+       if (ret < 0) {
+               wl1251_warning("ACX_FW_REV interrogate failed");
+               goto out;
+       }
+
+       *mactime = tsf_info->current_tsf_lsb |
+               (tsf_info->current_tsf_msb << 31);
+
+out:
+       kfree(tsf_info);
+       return ret;
+}
+
+int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats)
+{
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx statistics");
+
+       ret = wl1251_cmd_interrogate(wl, ACX_STATISTICS, stats,
+                                    sizeof(*stats));
+       if (ret < 0) {
+               wl1251_warning("acx statistics failed: %d", ret);
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
+int wl1251_acx_rate_policies(struct wl1251 *wl)
+{
+       struct acx_rate_policy *acx;
+       int ret = 0;
+
+       wl1251_debug(DEBUG_ACX, "acx rate policies");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* configure one default (one-size-fits-all) rate class */
+       acx->rate_class_cnt = 1;
+       acx->rate_class[0].enabled_rates = ACX_RATE_MASK_UNSPECIFIED;
+       acx->rate_class[0].short_retry_limit = ACX_RATE_RETRY_LIMIT;
+       acx->rate_class[0].long_retry_limit = ACX_RATE_RETRY_LIMIT;
+       acx->rate_class[0].aflags = 0;
+
+       ret = wl1251_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1251_warning("Setting of rate policies failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1251_acx_mem_cfg(struct wl1251 *wl)
+{
+       struct wl1251_acx_config_memory *mem_conf;
+       int ret, i;
+
+       wl1251_debug(DEBUG_ACX, "acx mem cfg");
+
+       mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
+       if (!mem_conf) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* memory config */
+       mem_conf->mem_config.num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
+       mem_conf->mem_config.rx_mem_block_num = 35;
+       mem_conf->mem_config.tx_min_mem_block_num = 64;
+       mem_conf->mem_config.num_tx_queues = MAX_TX_QUEUES;
+       mem_conf->mem_config.host_if_options = HOSTIF_PKT_RING;
+       mem_conf->mem_config.num_ssid_profiles = 1;
+       mem_conf->mem_config.debug_buffer_size =
+               cpu_to_le16(TRACE_BUFFER_MAX_SIZE);
+
+       /* RX queue config */
+       mem_conf->rx_queue_config.dma_address = 0;
+       mem_conf->rx_queue_config.num_descs = ACX_RX_DESC_DEF;
+       mem_conf->rx_queue_config.priority = DEFAULT_RXQ_PRIORITY;
+       mem_conf->rx_queue_config.type = DEFAULT_RXQ_TYPE;
+
+       /* TX queue config */
+       for (i = 0; i < MAX_TX_QUEUES; i++) {
+               mem_conf->tx_queue_config[i].num_descs = ACX_TX_DESC_DEF;
+               mem_conf->tx_queue_config[i].attributes = i;
+       }
+
+       ret = wl1251_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
+                                  sizeof(*mem_conf));
+       if (ret < 0) {
+               wl1251_warning("wl1251 mem config failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(mem_conf);
+       return ret;
+}
+
+int wl1251_acx_wr_tbtt_and_dtim(struct wl1251 *wl, u16 tbtt, u8 dtim)
+{
+       struct wl1251_acx_wr_tbtt_and_dtim *acx;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx tbtt and dtim");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->tbtt = tbtt;
+       acx->dtim = dtim;
+
+       ret = wl1251_cmd_configure(wl, ACX_WR_TBTT_AND_DTIM,
+                                  acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1251_warning("failed to set tbtt and dtim: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1251_acx_bet_enable(struct wl1251 *wl, enum wl1251_acx_bet_mode mode,
+                         u8 max_consecutive)
+{
+       struct wl1251_acx_bet_enable *acx;
+       int ret;
+
+       wl1251_debug(DEBUG_ACX, "acx bet enable");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->enable = mode;
+       acx->max_consecutive = max_consecutive;
+
+       ret = wl1251_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1251_warning("wl1251 acx bet enable failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1251_acx_ac_cfg(struct wl1251 *wl, u8 ac, u8 cw_min, u16 cw_max,
+                     u8 aifs, u16 txop)
+{
+       struct wl1251_acx_ac_cfg *acx;
+       int ret = 0;
+
+       wl1251_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
+                    "aifs %d txop %d", ac, cw_min, cw_max, aifs, txop);
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->ac = ac;
+       acx->cw_min = cw_min;
+       acx->cw_max = cw_max;
+       acx->aifsn = aifs;
+       acx->txop_limit = txop;
+
+       ret = wl1251_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1251_warning("acx ac cfg failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1251_acx_tid_cfg(struct wl1251 *wl, u8 queue,
+                      enum wl1251_acx_channel_type type,
+                      u8 tsid, enum wl1251_acx_ps_scheme ps_scheme,
+                      enum wl1251_acx_ack_policy ack_policy)
+{
+       struct wl1251_acx_tid_cfg *acx;
+       int ret = 0;
+
+       wl1251_debug(DEBUG_ACX, "acx tid cfg %d type %d tsid %d "
+                    "ps_scheme %d ack_policy %d", queue, type, tsid,
+                    ps_scheme, ack_policy);
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->queue = queue;
+       acx->type = type;
+       acx->tsid = tsid;
+       acx->ps_scheme = ps_scheme;
+       acx->ack_policy = ack_policy;
+
+       ret = wl1251_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1251_warning("acx tid cfg failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
diff --git a/drivers/net/wireless/ti/wl1251/acx.h b/drivers/net/wireless/ti/wl1251/acx.h
new file mode 100644 (file)
index 0000000..c2ba100
--- /dev/null
@@ -0,0 +1,1483 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (c) 1998-2007 Texas Instruments Incorporated
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL1251_ACX_H__
+#define __WL1251_ACX_H__
+
+#include "wl1251.h"
+#include "cmd.h"
+
+/* Target's information element */
+struct acx_header {
+       struct wl1251_cmd_header cmd;
+
+       /* acx (or information element) header */
+       u16 id;
+
+       /* payload length (not including headers */
+       u16 len;
+} __packed;
+
+struct acx_error_counter {
+       struct acx_header header;
+
+       /* The number of PLCP errors since the last time this */
+       /* information element was interrogated. This field is */
+       /* automatically cleared when it is interrogated.*/
+       u32 PLCP_error;
+
+       /* The number of FCS errors since the last time this */
+       /* information element was interrogated. This field is */
+       /* automatically cleared when it is interrogated.*/
+       u32 FCS_error;
+
+       /* The number of MPDUs without PLCP header errors received*/
+       /* since the last time this information element was interrogated. */
+       /* This field is automatically cleared when it is interrogated.*/
+       u32 valid_frame;
+
+       /* the number of missed sequence numbers in the squentially */
+       /* values of frames seq numbers */
+       u32 seq_num_miss;
+} __packed;
+
+struct acx_revision {
+       struct acx_header header;
+
+       /*
+        * The WiLink firmware version, an ASCII string x.x.x.x,
+        * that uniquely identifies the current firmware.
+        * The left most digit is incremented each time a
+        * significant change is made to the firmware, such as
+        * code redesign or new platform support.
+        * The second digit is incremented when major enhancements
+        * are added or major fixes are made.
+        * The third digit is incremented for each GA release.
+        * The fourth digit is incremented for each build.
+        * The first two digits identify a firmware release version,
+        * in other words, a unique set of features.
+        * The first three digits identify a GA release.
+        */
+       char fw_version[20];
+
+       /*
+        * This 4 byte field specifies the WiLink hardware version.
+        * bits 0  - 15: Reserved.
+        * bits 16 - 23: Version ID - The WiLink version ID
+        *              (1 = first spin, 2 = second spin, and so on).
+        * bits 24 - 31: Chip ID - The WiLink chip ID.
+        */
+       u32 hw_version;
+} __packed;
+
+enum wl1251_psm_mode {
+       /* Active mode */
+       WL1251_PSM_CAM = 0,
+
+       /* Power save mode */
+       WL1251_PSM_PS = 1,
+
+       /* Extreme low power */
+       WL1251_PSM_ELP = 2,
+};
+
+struct acx_sleep_auth {
+       struct acx_header header;
+
+       /* The sleep level authorization of the device. */
+       /* 0 - Always active*/
+       /* 1 - Power down mode: light / fast sleep*/
+       /* 2 - ELP mode: Deep / Max sleep*/
+       u8  sleep_auth;
+       u8  padding[3];
+} __packed;
+
+enum {
+       HOSTIF_PCI_MASTER_HOST_INDIRECT,
+       HOSTIF_PCI_MASTER_HOST_DIRECT,
+       HOSTIF_SLAVE,
+       HOSTIF_PKT_RING,
+       HOSTIF_DONTCARE = 0xFF
+};
+
+#define DEFAULT_UCAST_PRIORITY          0
+#define DEFAULT_RX_Q_PRIORITY           0
+#define DEFAULT_NUM_STATIONS            1
+#define DEFAULT_RXQ_PRIORITY            0 /* low 0 .. 15 high  */
+#define DEFAULT_RXQ_TYPE                0x07    /* All frames, Data/Ctrl/Mgmt */
+#define TRACE_BUFFER_MAX_SIZE           256
+
+#define  DP_RX_PACKET_RING_CHUNK_SIZE 1600
+#define  DP_TX_PACKET_RING_CHUNK_SIZE 1600
+#define  DP_RX_PACKET_RING_CHUNK_NUM 2
+#define  DP_TX_PACKET_RING_CHUNK_NUM 2
+#define  DP_TX_COMPLETE_TIME_OUT 20
+#define  FW_TX_CMPLT_BLOCK_SIZE 16
+
+struct acx_data_path_params {
+       struct acx_header header;
+
+       u16 rx_packet_ring_chunk_size;
+       u16 tx_packet_ring_chunk_size;
+
+       u8 rx_packet_ring_chunk_num;
+       u8 tx_packet_ring_chunk_num;
+
+       /*
+        * Maximum number of packets that can be gathered
+        * in the TX complete ring before an interrupt
+        * is generated.
+        */
+       u8 tx_complete_threshold;
+
+       /* Number of pending TX complete entries in cyclic ring.*/
+       u8 tx_complete_ring_depth;
+
+       /*
+        * Max num microseconds since a packet enters the TX
+        * complete ring until an interrupt is generated.
+        */
+       u32 tx_complete_timeout;
+} __packed;
+
+
+struct acx_data_path_params_resp {
+       struct acx_header header;
+
+       u16 rx_packet_ring_chunk_size;
+       u16 tx_packet_ring_chunk_size;
+
+       u8 rx_packet_ring_chunk_num;
+       u8 tx_packet_ring_chunk_num;
+
+       u8 pad[2];
+
+       u32 rx_packet_ring_addr;
+       u32 tx_packet_ring_addr;
+
+       u32 rx_control_addr;
+       u32 tx_control_addr;
+
+       u32 tx_complete_addr;
+} __packed;
+
+#define TX_MSDU_LIFETIME_MIN       0
+#define TX_MSDU_LIFETIME_MAX       3000
+#define TX_MSDU_LIFETIME_DEF       512
+#define RX_MSDU_LIFETIME_MIN       0
+#define RX_MSDU_LIFETIME_MAX       0xFFFFFFFF
+#define RX_MSDU_LIFETIME_DEF       512000
+
+struct acx_rx_msdu_lifetime {
+       struct acx_header header;
+
+       /*
+        * The maximum amount of time, in TU, before the
+        * firmware discards the MSDU.
+        */
+       u32 lifetime;
+} __packed;
+
+/*
+ * RX Config Options Table
+ * Bit         Definition
+ * ===         ==========
+ * 31:14               Reserved
+ * 13          Copy RX Status - when set, write three receive status words
+ *             to top of rx'd MPDUs.
+ *             When cleared, do not write three status words (added rev 1.5)
+ * 12          Reserved
+ * 11          RX Complete upon FCS error - when set, give rx complete
+ *             interrupt for FCS errors, after the rx filtering, e.g. unicast
+ *             frames not to us with FCS error will not generate an interrupt.
+ * 10          SSID Filter Enable - When set, the WiLink discards all beacon,
+ *             probe request, and probe response frames with an SSID that does
+ *             not match the SSID specified by the host in the START/JOIN
+ *             command.
+ *             When clear, the WiLink receives frames with any SSID.
+ * 9           Broadcast Filter Enable - When set, the WiLink discards all
+ *             broadcast frames. When clear, the WiLink receives all received
+ *             broadcast frames.
+ * 8:6         Reserved
+ * 5           BSSID Filter Enable - When set, the WiLink discards any frames
+ *             with a BSSID that does not match the BSSID specified by the
+ *             host.
+ *             When clear, the WiLink receives frames from any BSSID.
+ * 4           MAC Addr Filter - When set, the WiLink discards any frames
+ *             with a destination address that does not match the MAC address
+ *             of the adaptor.
+ *             When clear, the WiLink receives frames destined to any MAC
+ *             address.
+ * 3           Promiscuous - When set, the WiLink receives all valid frames
+ *             (i.e., all frames that pass the FCS check).
+ *             When clear, only frames that pass the other filters specified
+ *             are received.
+ * 2           FCS - When set, the WiLink includes the FCS with the received
+ *             frame.
+ *             When cleared, the FCS is discarded.
+ * 1           PLCP header - When set, write all data from baseband to frame
+ *             buffer including PHY header.
+ * 0           Reserved - Always equal to 0.
+ *
+ * RX Filter Options Table
+ * Bit         Definition
+ * ===         ==========
+ * 31:12               Reserved - Always equal to 0.
+ * 11          Association - When set, the WiLink receives all association
+ *             related frames (association request/response, reassocation
+ *             request/response, and disassociation). When clear, these frames
+ *             are discarded.
+ * 10          Auth/De auth - When set, the WiLink receives all authentication
+ *             and de-authentication frames. When clear, these frames are
+ *             discarded.
+ * 9           Beacon - When set, the WiLink receives all beacon frames.
+ *             When clear, these frames are discarded.
+ * 8           Contention Free - When set, the WiLink receives all contention
+ *             free frames.
+ *             When clear, these frames are discarded.
+ * 7           Control - When set, the WiLink receives all control frames.
+ *             When clear, these frames are discarded.
+ * 6           Data - When set, the WiLink receives all data frames.
+ *             When clear, these frames are discarded.
+ * 5           FCS Error - When set, the WiLink receives frames that have FCS
+ *             errors.
+ *             When clear, these frames are discarded.
+ * 4           Management - When set, the WiLink receives all management
+ *             frames.
+ *             When clear, these frames are discarded.
+ * 3           Probe Request - When set, the WiLink receives all probe request
+ *             frames.
+ *             When clear, these frames are discarded.
+ * 2           Probe Response - When set, the WiLink receives all probe
+ *             response frames.
+ *             When clear, these frames are discarded.
+ * 1           RTS/CTS/ACK - When set, the WiLink receives all RTS, CTS and ACK
+ *             frames.
+ *             When clear, these frames are discarded.
+ * 0           Rsvd Type/Sub Type - When set, the WiLink receives all frames
+ *             that have reserved frame types and sub types as defined by the
+ *             802.11 specification.
+ *             When clear, these frames are discarded.
+ */
+struct acx_rx_config {
+       struct acx_header header;
+
+       u32 config_options;
+       u32 filter_options;
+} __packed;
+
+enum {
+       QOS_AC_BE = 0,
+       QOS_AC_BK,
+       QOS_AC_VI,
+       QOS_AC_VO,
+       QOS_HIGHEST_AC_INDEX = QOS_AC_VO,
+};
+
+#define MAX_NUM_OF_AC             (QOS_HIGHEST_AC_INDEX+1)
+#define FIRST_AC_INDEX            QOS_AC_BE
+#define MAX_NUM_OF_802_1d_TAGS    8
+#define AC_PARAMS_MAX_TSID        15
+#define MAX_APSD_CONF             0xffff
+
+#define  QOS_TX_HIGH_MIN      (0)
+#define  QOS_TX_HIGH_MAX      (100)
+
+#define  QOS_TX_HIGH_BK_DEF   (25)
+#define  QOS_TX_HIGH_BE_DEF   (35)
+#define  QOS_TX_HIGH_VI_DEF   (35)
+#define  QOS_TX_HIGH_VO_DEF   (35)
+
+#define  QOS_TX_LOW_BK_DEF    (15)
+#define  QOS_TX_LOW_BE_DEF    (25)
+#define  QOS_TX_LOW_VI_DEF    (25)
+#define  QOS_TX_LOW_VO_DEF    (25)
+
+struct acx_tx_queue_qos_config {
+       struct acx_header header;
+
+       u8 qid;
+       u8 pad[3];
+
+       /* Max number of blocks allowd in the queue */
+       u16 high_threshold;
+
+       /* Lowest memory blocks guaranteed for this queue */
+       u16 low_threshold;
+} __packed;
+
+struct acx_packet_detection {
+       struct acx_header header;
+
+       u32 threshold;
+} __packed;
+
+
+enum acx_slot_type {
+       SLOT_TIME_LONG = 0,
+       SLOT_TIME_SHORT = 1,
+       DEFAULT_SLOT_TIME = SLOT_TIME_SHORT,
+       MAX_SLOT_TIMES = 0xFF
+};
+
+#define STATION_WONE_INDEX 0
+
+struct acx_slot {
+       struct acx_header header;
+
+       u8 wone_index; /* Reserved */
+       u8 slot_time;
+       u8 reserved[6];
+} __packed;
+
+
+#define ADDRESS_GROUP_MAX      (8)
+#define ADDRESS_GROUP_MAX_LEN  (ETH_ALEN * ADDRESS_GROUP_MAX)
+
+struct acx_dot11_grp_addr_tbl {
+       struct acx_header header;
+
+       u8 enabled;
+       u8 num_groups;
+       u8 pad[2];
+       u8 mac_table[ADDRESS_GROUP_MAX_LEN];
+} __packed;
+
+
+#define  RX_TIMEOUT_PS_POLL_MIN    0
+#define  RX_TIMEOUT_PS_POLL_MAX    (200000)
+#define  RX_TIMEOUT_PS_POLL_DEF    (15)
+#define  RX_TIMEOUT_UPSD_MIN       0
+#define  RX_TIMEOUT_UPSD_MAX       (200000)
+#define  RX_TIMEOUT_UPSD_DEF       (15)
+
+struct acx_rx_timeout {
+       struct acx_header header;
+
+       /*
+        * The longest time the STA will wait to receive
+        * traffic from the AP after a PS-poll has been
+        * transmitted.
+        */
+       u16 ps_poll_timeout;
+
+       /*
+        * The longest time the STA will wait to receive
+        * traffic from the AP after a frame has been sent
+        * from an UPSD enabled queue.
+        */
+       u16 upsd_timeout;
+} __packed;
+
+#define RTS_THRESHOLD_MIN              0
+#define RTS_THRESHOLD_MAX              4096
+#define RTS_THRESHOLD_DEF              2347
+
+struct acx_rts_threshold {
+       struct acx_header header;
+
+       u16 threshold;
+       u8 pad[2];
+} __packed;
+
+enum wl1251_acx_low_rssi_type {
+       /*
+        * The event is a "Level" indication which keeps triggering
+        * as long as the average RSSI is below the threshold.
+        */
+       WL1251_ACX_LOW_RSSI_TYPE_LEVEL = 0,
+
+       /*
+        * The event is an "Edge" indication which triggers
+        * only when the RSSI threshold is crossed from above.
+        */
+       WL1251_ACX_LOW_RSSI_TYPE_EDGE = 1,
+};
+
+struct acx_low_rssi {
+       struct acx_header header;
+
+       /*
+        * The threshold (in dBm) below (or above after low rssi
+        * indication) which the firmware generates an interrupt to the
+        * host. This parameter is signed.
+        */
+       s8 threshold;
+
+       /*
+        * The weight of the current RSSI sample, before adding the new
+        * sample, that is used to calculate the average RSSI.
+        */
+       u8 weight;
+
+       /*
+        * The number of Beacons/Probe response frames that will be
+        * received before issuing the Low or Regained RSSI event.
+        */
+       u8 depth;
+
+       /*
+        * Configures how the Low RSSI Event is triggered. Refer to
+        * enum wl1251_acx_low_rssi_type for more.
+        */
+       u8 type;
+} __packed;
+
+struct acx_beacon_filter_option {
+       struct acx_header header;
+
+       u8 enable;
+
+       /*
+        * The number of beacons without the unicast TIM
+        * bit set that the firmware buffers before
+        * signaling the host about ready frames.
+        * When set to 0 and the filter is enabled, beacons
+        * without the unicast TIM bit set are dropped.
+        */
+       u8 max_num_beacons;
+       u8 pad[2];
+} __packed;
+
+/*
+ * ACXBeaconFilterEntry (not 221)
+ * Byte Offset     Size (Bytes)    Definition
+ * ===========     ============    ==========
+ * 0                           1               IE identifier
+ * 1               1               Treatment bit mask
+ *
+ * ACXBeaconFilterEntry (221)
+ * Byte Offset     Size (Bytes)    Definition
+ * ===========     ============    ==========
+ * 0               1               IE identifier
+ * 1               1               Treatment bit mask
+ * 2               3               OUI
+ * 5               1               Type
+ * 6               2               Version
+ *
+ *
+ * Treatment bit mask - The information element handling:
+ * bit 0 - The information element is compared and transferred
+ * in case of change.
+ * bit 1 - The information element is transferred to the host
+ * with each appearance or disappearance.
+ * Note that both bits can be set at the same time.
+ */
+#define        BEACON_FILTER_TABLE_MAX_IE_NUM                 (32)
+#define BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM (6)
+#define BEACON_FILTER_TABLE_IE_ENTRY_SIZE             (2)
+#define BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE (6)
+#define BEACON_FILTER_TABLE_MAX_SIZE ((BEACON_FILTER_TABLE_MAX_IE_NUM * \
+                           BEACON_FILTER_TABLE_IE_ENTRY_SIZE) + \
+                          (BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM * \
+                           BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE))
+
+#define BEACON_RULE_PASS_ON_CHANGE                     BIT(0)
+#define BEACON_RULE_PASS_ON_APPEARANCE                 BIT(1)
+
+#define BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN         (37)
+
+struct acx_beacon_filter_ie_table {
+       struct acx_header header;
+
+       u8 num_ie;
+       u8 pad[3];
+       u8 table[BEACON_FILTER_TABLE_MAX_SIZE];
+} __packed;
+
+#define SYNCH_FAIL_DEFAULT_THRESHOLD    10     /* number of beacons */
+#define NO_BEACON_DEFAULT_TIMEOUT       (500) /* in microseconds */
+
+struct acx_conn_monit_params {
+       struct acx_header header;
+
+       u32 synch_fail_thold; /* number of beacons missed */
+       u32 bss_lose_timeout; /* number of TU's from synch fail */
+} __packed;
+
+enum {
+       SG_ENABLE = 0,
+       SG_DISABLE,
+       SG_SENSE_NO_ACTIVITY,
+       SG_SENSE_ACTIVE
+};
+
+struct acx_bt_wlan_coex {
+       struct acx_header header;
+
+       /*
+        * 0 -> PTA enabled
+        * 1 -> PTA disabled
+        * 2 -> sense no active mode, i.e.
+        *      an interrupt is sent upon
+        *      BT activity.
+        * 3 -> PTA is switched on in response
+        *      to the interrupt sending.
+        */
+       u8 enable;
+       u8 pad[3];
+} __packed;
+
+#define PTA_ANTENNA_TYPE_DEF             (0)
+#define PTA_BT_HP_MAXTIME_DEF            (2000)
+#define PTA_WLAN_HP_MAX_TIME_DEF         (5000)
+#define PTA_SENSE_DISABLE_TIMER_DEF      (1350)
+#define PTA_PROTECTIVE_RX_TIME_DEF       (1500)
+#define PTA_PROTECTIVE_TX_TIME_DEF       (1500)
+#define PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF (3000)
+#define PTA_SIGNALING_TYPE_DEF           (1)
+#define PTA_AFH_LEVERAGE_ON_DEF                  (0)
+#define PTA_NUMBER_QUIET_CYCLE_DEF       (0)
+#define PTA_MAX_NUM_CTS_DEF              (3)
+#define PTA_NUMBER_OF_WLAN_PACKETS_DEF   (2)
+#define PTA_NUMBER_OF_BT_PACKETS_DEF     (2)
+#define PTA_PROTECTIVE_RX_TIME_FAST_DEF          (1500)
+#define PTA_PROTECTIVE_TX_TIME_FAST_DEF          (3000)
+#define PTA_CYCLE_TIME_FAST_DEF                  (8700)
+#define PTA_RX_FOR_AVALANCHE_DEF         (5)
+#define PTA_ELP_HP_DEF                   (0)
+#define PTA_ANTI_STARVE_PERIOD_DEF       (500)
+#define PTA_ANTI_STARVE_NUM_CYCLE_DEF    (4)
+#define PTA_ALLOW_PA_SD_DEF              (1)
+#define PTA_TIME_BEFORE_BEACON_DEF       (6300)
+#define PTA_HPDM_MAX_TIME_DEF            (1600)
+#define PTA_TIME_OUT_NEXT_WLAN_DEF       (2550)
+#define PTA_AUTO_MODE_NO_CTS_DEF         (0)
+#define PTA_BT_HP_RESPECTED_DEF                  (3)
+#define PTA_WLAN_RX_MIN_RATE_DEF         (24)
+#define PTA_ACK_MODE_DEF                 (1)
+
+struct acx_bt_wlan_coex_param {
+       struct acx_header header;
+
+       /*
+        * The minimum rate of a received WLAN packet in the STA,
+        * during protective mode, of which a new BT-HP request
+        * during this Rx will always be respected and gain the antenna.
+        */
+       u32 min_rate;
+
+       /* Max time the BT HP will be respected. */
+       u16 bt_hp_max_time;
+
+       /* Max time the WLAN HP will be respected. */
+       u16 wlan_hp_max_time;
+
+       /*
+        * The time between the last BT activity
+        * and the moment when the sense mode returns
+        * to SENSE_INACTIVE.
+        */
+       u16 sense_disable_timer;
+
+       /* Time before the next BT HP instance */
+       u16 rx_time_bt_hp;
+       u16 tx_time_bt_hp;
+
+       /* range: 10-20000    default: 1500 */
+       u16 rx_time_bt_hp_fast;
+       u16 tx_time_bt_hp_fast;
+
+       /* range: 2000-65535  default: 8700 */
+       u16 wlan_cycle_fast;
+
+       /* range: 0 - 15000 (Msec) default: 1000 */
+       u16 bt_anti_starvation_period;
+
+       /* range 400-10000(Usec) default: 3000 */
+       u16 next_bt_lp_packet;
+
+       /* Deafult: worst case for BT DH5 traffic */
+       u16 wake_up_beacon;
+
+       /* range: 0-50000(Usec) default: 1050 */
+       u16 hp_dm_max_guard_time;
+
+       /*
+        * This is to prevent both BT & WLAN antenna
+        * starvation.
+        * Range: 100-50000(Usec) default:2550
+        */
+       u16 next_wlan_packet;
+
+       /* 0 -> shared antenna */
+       u8 antenna_type;
+
+       /*
+        * 0 -> TI legacy
+        * 1 -> Palau
+        */
+       u8 signal_type;
+
+       /*
+        * BT AFH status
+        * 0 -> no AFH
+        * 1 -> from dedicated GPIO
+        * 2 -> AFH on (from host)
+        */
+       u8 afh_leverage_on;
+
+       /*
+        * The number of cycles during which no
+        * TX will be sent after 1 cycle of RX
+        * transaction in protective mode
+        */
+       u8 quiet_cycle_num;
+
+       /*
+        * The maximum number of CTSs that will
+        * be sent for receiving RX packet in
+        * protective mode
+        */
+       u8 max_cts;
+
+       /*
+        * The number of WLAN packets
+        * transferred in common mode before
+        * switching to BT.
+        */
+       u8 wlan_packets_num;
+
+       /*
+        * The number of BT packets
+        * transferred in common mode before
+        * switching to WLAN.
+        */
+       u8 bt_packets_num;
+
+       /* range: 1-255  default: 5 */
+       u8 missed_rx_avalanche;
+
+       /* range: 0-1    default: 1 */
+       u8 wlan_elp_hp;
+
+       /* range: 0 - 15  default: 4 */
+       u8 bt_anti_starvation_cycles;
+
+       u8 ack_mode_dual_ant;
+
+       /*
+        * Allow PA_SD assertion/de-assertion
+        * during enabled BT activity.
+        */
+       u8 pa_sd_enable;
+
+       /*
+        * Enable/Disable PTA in auto mode:
+        * Support Both Active & P.S modes
+        */
+       u8 pta_auto_mode_enable;
+
+       /* range: 0 - 20  default: 1 */
+       u8 bt_hp_respected_num;
+} __packed;
+
+#define CCA_THRSH_ENABLE_ENERGY_D       0x140A
+#define CCA_THRSH_DISABLE_ENERGY_D      0xFFEF
+
+struct acx_energy_detection {
+       struct acx_header header;
+
+       /* The RX Clear Channel Assessment threshold in the PHY */
+       u16 rx_cca_threshold;
+       u8 tx_energy_detection;
+       u8 pad;
+} __packed;
+
+#define BCN_RX_TIMEOUT_DEF_VALUE        10000
+#define BROADCAST_RX_TIMEOUT_DEF_VALUE  20000
+#define RX_BROADCAST_IN_PS_DEF_VALUE    1
+#define CONSECUTIVE_PS_POLL_FAILURE_DEF 4
+
+struct acx_beacon_broadcast {
+       struct acx_header header;
+
+       u16 beacon_rx_timeout;
+       u16 broadcast_timeout;
+
+       /* Enables receiving of broadcast packets in PS mode */
+       u8 rx_broadcast_in_ps;
+
+       /* Consecutive PS Poll failures before updating the host */
+       u8 ps_poll_threshold;
+       u8 pad[2];
+} __packed;
+
+struct acx_event_mask {
+       struct acx_header header;
+
+       u32 event_mask;
+       u32 high_event_mask; /* Unused */
+} __packed;
+
+#define CFG_RX_FCS             BIT(2)
+#define CFG_RX_ALL_GOOD                BIT(3)
+#define CFG_UNI_FILTER_EN      BIT(4)
+#define CFG_BSSID_FILTER_EN    BIT(5)
+#define CFG_MC_FILTER_EN       BIT(6)
+#define CFG_MC_ADDR0_EN                BIT(7)
+#define CFG_MC_ADDR1_EN                BIT(8)
+#define CFG_BC_REJECT_EN       BIT(9)
+#define CFG_SSID_FILTER_EN     BIT(10)
+#define CFG_RX_INT_FCS_ERROR   BIT(11)
+#define CFG_RX_INT_ENCRYPTED   BIT(12)
+#define CFG_RX_WR_RX_STATUS    BIT(13)
+#define CFG_RX_FILTER_NULTI    BIT(14)
+#define CFG_RX_RESERVE         BIT(15)
+#define CFG_RX_TIMESTAMP_TSF   BIT(16)
+
+#define CFG_RX_RSV_EN          BIT(0)
+#define CFG_RX_RCTS_ACK                BIT(1)
+#define CFG_RX_PRSP_EN         BIT(2)
+#define CFG_RX_PREQ_EN         BIT(3)
+#define CFG_RX_MGMT_EN         BIT(4)
+#define CFG_RX_FCS_ERROR       BIT(5)
+#define CFG_RX_DATA_EN         BIT(6)
+#define CFG_RX_CTL_EN          BIT(7)
+#define CFG_RX_CF_EN           BIT(8)
+#define CFG_RX_BCN_EN          BIT(9)
+#define CFG_RX_AUTH_EN         BIT(10)
+#define CFG_RX_ASSOC_EN                BIT(11)
+
+#define SCAN_PASSIVE           BIT(0)
+#define SCAN_5GHZ_BAND         BIT(1)
+#define SCAN_TRIGGERED         BIT(2)
+#define SCAN_PRIORITY_HIGH     BIT(3)
+
+struct acx_fw_gen_frame_rates {
+       struct acx_header header;
+
+       u8 tx_ctrl_frame_rate; /* RATE_* */
+       u8 tx_ctrl_frame_mod; /* CCK_* or PBCC_* */
+       u8 tx_mgt_frame_rate;
+       u8 tx_mgt_frame_mod;
+} __packed;
+
+/* STA MAC */
+struct acx_dot11_station_id {
+       struct acx_header header;
+
+       u8 mac[ETH_ALEN];
+       u8 pad[2];
+} __packed;
+
+struct acx_feature_config {
+       struct acx_header header;
+
+       u32 options;
+       u32 data_flow_options;
+} __packed;
+
+struct acx_current_tx_power {
+       struct acx_header header;
+
+       u8  current_tx_power;
+       u8  padding[3];
+} __packed;
+
+struct acx_dot11_default_key {
+       struct acx_header header;
+
+       u8 id;
+       u8 pad[3];
+} __packed;
+
+struct acx_tsf_info {
+       struct acx_header header;
+
+       u32 current_tsf_msb;
+       u32 current_tsf_lsb;
+       u32 last_TBTT_msb;
+       u32 last_TBTT_lsb;
+       u8 last_dtim_count;
+       u8 pad[3];
+} __packed;
+
+enum acx_wake_up_event {
+       WAKE_UP_EVENT_BEACON_BITMAP     = 0x01, /* Wake on every Beacon*/
+       WAKE_UP_EVENT_DTIM_BITMAP       = 0x02, /* Wake on every DTIM*/
+       WAKE_UP_EVENT_N_DTIM_BITMAP     = 0x04, /* Wake on every Nth DTIM */
+       WAKE_UP_EVENT_N_BEACONS_BITMAP  = 0x08, /* Wake on every Nth Beacon */
+       WAKE_UP_EVENT_BITS_MASK         = 0x0F
+};
+
+struct acx_wake_up_condition {
+       struct acx_header header;
+
+       u8 wake_up_event; /* Only one bit can be set */
+       u8 listen_interval;
+       u8 pad[2];
+} __packed;
+
+struct acx_aid {
+       struct acx_header header;
+
+       /*
+        * To be set when associated with an AP.
+        */
+       u16 aid;
+       u8 pad[2];
+} __packed;
+
+enum acx_preamble_type {
+       ACX_PREAMBLE_LONG = 0,
+       ACX_PREAMBLE_SHORT = 1
+};
+
+struct acx_preamble {
+       struct acx_header header;
+
+       /*
+        * When set, the WiLink transmits the frames with a short preamble and
+        * when cleared, the WiLink transmits the frames with a long preamble.
+        */
+       u8 preamble;
+       u8 padding[3];
+} __packed;
+
+enum acx_ctsprotect_type {
+       CTSPROTECT_DISABLE = 0,
+       CTSPROTECT_ENABLE = 1
+};
+
+struct acx_ctsprotect {
+       struct acx_header header;
+       u8 ctsprotect;
+       u8 padding[3];
+} __packed;
+
+struct acx_tx_statistics {
+       u32 internal_desc_overflow;
+}  __packed;
+
+struct acx_rx_statistics {
+       u32 out_of_mem;
+       u32 hdr_overflow;
+       u32 hw_stuck;
+       u32 dropped;
+       u32 fcs_err;
+       u32 xfr_hint_trig;
+       u32 path_reset;
+       u32 reset_counter;
+} __packed;
+
+struct acx_dma_statistics {
+       u32 rx_requested;
+       u32 rx_errors;
+       u32 tx_requested;
+       u32 tx_errors;
+}  __packed;
+
+struct acx_isr_statistics {
+       /* host command complete */
+       u32 cmd_cmplt;
+
+       /* fiqisr() */
+       u32 fiqs;
+
+       /* (INT_STS_ND & INT_TRIG_RX_HEADER) */
+       u32 rx_headers;
+
+       /* (INT_STS_ND & INT_TRIG_RX_CMPLT) */
+       u32 rx_completes;
+
+       /* (INT_STS_ND & INT_TRIG_NO_RX_BUF) */
+       u32 rx_mem_overflow;
+
+       /* (INT_STS_ND & INT_TRIG_S_RX_RDY) */
+       u32 rx_rdys;
+
+       /* irqisr() */
+       u32 irqs;
+
+       /* (INT_STS_ND & INT_TRIG_TX_PROC) */
+       u32 tx_procs;
+
+       /* (INT_STS_ND & INT_TRIG_DECRYPT_DONE) */
+       u32 decrypt_done;
+
+       /* (INT_STS_ND & INT_TRIG_DMA0) */
+       u32 dma0_done;
+
+       /* (INT_STS_ND & INT_TRIG_DMA1) */
+       u32 dma1_done;
+
+       /* (INT_STS_ND & INT_TRIG_TX_EXC_CMPLT) */
+       u32 tx_exch_complete;
+
+       /* (INT_STS_ND & INT_TRIG_COMMAND) */
+       u32 commands;
+
+       /* (INT_STS_ND & INT_TRIG_RX_PROC) */
+       u32 rx_procs;
+
+       /* (INT_STS_ND & INT_TRIG_PM_802) */
+       u32 hw_pm_mode_changes;
+
+       /* (INT_STS_ND & INT_TRIG_ACKNOWLEDGE) */
+       u32 host_acknowledges;
+
+       /* (INT_STS_ND & INT_TRIG_PM_PCI) */
+       u32 pci_pm;
+
+       /* (INT_STS_ND & INT_TRIG_ACM_WAKEUP) */
+       u32 wakeups;
+
+       /* (INT_STS_ND & INT_TRIG_LOW_RSSI) */
+       u32 low_rssi;
+} __packed;
+
+struct acx_wep_statistics {
+       /* WEP address keys configured */
+       u32 addr_key_count;
+
+       /* default keys configured */
+       u32 default_key_count;
+
+       u32 reserved;
+
+       /* number of times that WEP key not found on lookup */
+       u32 key_not_found;
+
+       /* number of times that WEP key decryption failed */
+       u32 decrypt_fail;
+
+       /* WEP packets decrypted */
+       u32 packets;
+
+       /* WEP decrypt interrupts */
+       u32 interrupt;
+} __packed;
+
+#define ACX_MISSED_BEACONS_SPREAD 10
+
+struct acx_pwr_statistics {
+       /* the amount of enters into power save mode (both PD & ELP) */
+       u32 ps_enter;
+
+       /* the amount of enters into ELP mode */
+       u32 elp_enter;
+
+       /* the amount of missing beacon interrupts to the host */
+       u32 missing_bcns;
+
+       /* the amount of wake on host-access times */
+       u32 wake_on_host;
+
+       /* the amount of wake on timer-expire */
+       u32 wake_on_timer_exp;
+
+       /* the number of packets that were transmitted with PS bit set */
+       u32 tx_with_ps;
+
+       /* the number of packets that were transmitted with PS bit clear */
+       u32 tx_without_ps;
+
+       /* the number of received beacons */
+       u32 rcvd_beacons;
+
+       /* the number of entering into PowerOn (power save off) */
+       u32 power_save_off;
+
+       /* the number of entries into power save mode */
+       u16 enable_ps;
+
+       /*
+        * the number of exits from power save, not including failed PS
+        * transitions
+        */
+       u16 disable_ps;
+
+       /*
+        * the number of times the TSF counter was adjusted because
+        * of drift
+        */
+       u32 fix_tsf_ps;
+
+       /* Gives statistics about the spread continuous missed beacons.
+        * The 16 LSB are dedicated for the PS mode.
+        * The 16 MSB are dedicated for the PS mode.
+        * cont_miss_bcns_spread[0] - single missed beacon.
+        * cont_miss_bcns_spread[1] - two continuous missed beacons.
+        * cont_miss_bcns_spread[2] - three continuous missed beacons.
+        * ...
+        * cont_miss_bcns_spread[9] - ten and more continuous missed beacons.
+       */
+       u32 cont_miss_bcns_spread[ACX_MISSED_BEACONS_SPREAD];
+
+       /* the number of beacons in awake mode */
+       u32 rcvd_awake_beacons;
+} __packed;
+
+struct acx_mic_statistics {
+       u32 rx_pkts;
+       u32 calc_failure;
+} __packed;
+
+struct acx_aes_statistics {
+       u32 encrypt_fail;
+       u32 decrypt_fail;
+       u32 encrypt_packets;
+       u32 decrypt_packets;
+       u32 encrypt_interrupt;
+       u32 decrypt_interrupt;
+} __packed;
+
+struct acx_event_statistics {
+       u32 heart_beat;
+       u32 calibration;
+       u32 rx_mismatch;
+       u32 rx_mem_empty;
+       u32 rx_pool;
+       u32 oom_late;
+       u32 phy_transmit_error;
+       u32 tx_stuck;
+} __packed;
+
+struct acx_ps_statistics {
+       u32 pspoll_timeouts;
+       u32 upsd_timeouts;
+       u32 upsd_max_sptime;
+       u32 upsd_max_apturn;
+       u32 pspoll_max_apturn;
+       u32 pspoll_utilization;
+       u32 upsd_utilization;
+} __packed;
+
+struct acx_rxpipe_statistics {
+       u32 rx_prep_beacon_drop;
+       u32 descr_host_int_trig_rx_data;
+       u32 beacon_buffer_thres_host_int_trig_rx_data;
+       u32 missed_beacon_host_int_trig_rx_data;
+       u32 tx_xfr_host_int_trig_rx_data;
+} __packed;
+
+struct acx_statistics {
+       struct acx_header header;
+
+       struct acx_tx_statistics tx;
+       struct acx_rx_statistics rx;
+       struct acx_dma_statistics dma;
+       struct acx_isr_statistics isr;
+       struct acx_wep_statistics wep;
+       struct acx_pwr_statistics pwr;
+       struct acx_aes_statistics aes;
+       struct acx_mic_statistics mic;
+       struct acx_event_statistics event;
+       struct acx_ps_statistics ps;
+       struct acx_rxpipe_statistics rxpipe;
+} __packed;
+
+#define ACX_MAX_RATE_CLASSES       8
+#define ACX_RATE_MASK_UNSPECIFIED  0
+#define ACX_RATE_RETRY_LIMIT      10
+
+struct acx_rate_class {
+       u32 enabled_rates;
+       u8 short_retry_limit;
+       u8 long_retry_limit;
+       u8 aflags;
+       u8 reserved;
+} __packed;
+
+struct acx_rate_policy {
+       struct acx_header header;
+
+       u32 rate_class_cnt;
+       struct acx_rate_class rate_class[ACX_MAX_RATE_CLASSES];
+} __packed;
+
+struct wl1251_acx_memory {
+       __le16 num_stations; /* number of STAs to be supported. */
+       u16 reserved_1;
+
+       /*
+        * Nmber of memory buffers for the RX mem pool.
+        * The actual number may be less if there are
+        * not enough blocks left for the minimum num
+        * of TX ones.
+        */
+       u8 rx_mem_block_num;
+       u8 reserved_2;
+       u8 num_tx_queues; /* From 1 to 16 */
+       u8 host_if_options; /* HOST_IF* */
+       u8 tx_min_mem_block_num;
+       u8 num_ssid_profiles;
+       __le16 debug_buffer_size;
+} __packed;
+
+
+#define ACX_RX_DESC_MIN                1
+#define ACX_RX_DESC_MAX                127
+#define ACX_RX_DESC_DEF                32
+struct wl1251_acx_rx_queue_config {
+       u8 num_descs;
+       u8 pad;
+       u8 type;
+       u8 priority;
+       __le32 dma_address;
+} __packed;
+
+#define ACX_TX_DESC_MIN                1
+#define ACX_TX_DESC_MAX                127
+#define ACX_TX_DESC_DEF                16
+struct wl1251_acx_tx_queue_config {
+    u8 num_descs;
+    u8 pad[2];
+    u8 attributes;
+} __packed;
+
+#define MAX_TX_QUEUE_CONFIGS 5
+#define MAX_TX_QUEUES 4
+struct wl1251_acx_config_memory {
+       struct acx_header header;
+
+       struct wl1251_acx_memory mem_config;
+       struct wl1251_acx_rx_queue_config rx_queue_config;
+       struct wl1251_acx_tx_queue_config tx_queue_config[MAX_TX_QUEUE_CONFIGS];
+} __packed;
+
+struct wl1251_acx_mem_map {
+       struct acx_header header;
+
+       void *code_start;
+       void *code_end;
+
+       void *wep_defkey_start;
+       void *wep_defkey_end;
+
+       void *sta_table_start;
+       void *sta_table_end;
+
+       void *packet_template_start;
+       void *packet_template_end;
+
+       void *queue_memory_start;
+       void *queue_memory_end;
+
+       void *packet_memory_pool_start;
+       void *packet_memory_pool_end;
+
+       void *debug_buffer1_start;
+       void *debug_buffer1_end;
+
+       void *debug_buffer2_start;
+       void *debug_buffer2_end;
+
+       /* Number of blocks FW allocated for TX packets */
+       u32 num_tx_mem_blocks;
+
+       /* Number of blocks FW allocated for RX packets */
+       u32 num_rx_mem_blocks;
+} __packed;
+
+
+struct wl1251_acx_wr_tbtt_and_dtim {
+
+       struct acx_header header;
+
+       /* Time in TUs between two consecutive beacons */
+       u16 tbtt;
+
+       /*
+        * DTIM period
+        * For BSS: Number of TBTTs in a DTIM period (range: 1-10)
+        * For IBSS: value shall be set to 1
+       */
+       u8  dtim;
+       u8  padding;
+} __packed;
+
+enum wl1251_acx_bet_mode {
+       WL1251_ACX_BET_DISABLE = 0,
+       WL1251_ACX_BET_ENABLE = 1,
+};
+
+struct wl1251_acx_bet_enable {
+       struct acx_header header;
+
+       /*
+        * Specifies if beacon early termination procedure is enabled or
+        * disabled, see enum wl1251_acx_bet_mode.
+        */
+       u8 enable;
+
+       /*
+        * Specifies the maximum number of consecutive beacons that may be
+        * early terminated. After this number is reached at least one full
+        * beacon must be correctly received in FW before beacon ET
+        * resumes. Range 0 - 255.
+        */
+       u8 max_consecutive;
+
+       u8 padding[2];
+} __packed;
+
+struct wl1251_acx_ac_cfg {
+       struct acx_header header;
+
+       /*
+        * Access Category - The TX queue's access category
+        * (refer to AccessCategory_enum)
+        */
+       u8 ac;
+
+       /*
+        * The contention window minimum size (in slots) for
+        * the access class.
+        */
+       u8 cw_min;
+
+       /*
+        * The contention window maximum size (in slots) for
+        * the access class.
+        */
+       u16 cw_max;
+
+       /* The AIF value (in slots) for the access class. */
+       u8 aifsn;
+
+       u8 reserved;
+
+       /* The TX Op Limit (in microseconds) for the access class. */
+       u16 txop_limit;
+} __packed;
+
+
+enum wl1251_acx_channel_type {
+       CHANNEL_TYPE_DCF        = 0,
+       CHANNEL_TYPE_EDCF       = 1,
+       CHANNEL_TYPE_HCCA       = 2,
+};
+
+enum wl1251_acx_ps_scheme {
+       /* regular ps: simple sending of packets */
+       WL1251_ACX_PS_SCHEME_LEGACY     = 0,
+
+       /* sending a packet triggers a unscheduled apsd downstream */
+       WL1251_ACX_PS_SCHEME_UPSD_TRIGGER       = 1,
+
+       /* a pspoll packet will be sent before every data packet */
+       WL1251_ACX_PS_SCHEME_LEGACY_PSPOLL      = 2,
+
+       /* scheduled apsd mode */
+       WL1251_ACX_PS_SCHEME_SAPSD              = 3,
+};
+
+enum wl1251_acx_ack_policy {
+       WL1251_ACX_ACK_POLICY_LEGACY    = 0,
+       WL1251_ACX_ACK_POLICY_NO_ACK    = 1,
+       WL1251_ACX_ACK_POLICY_BLOCK     = 2,
+};
+
+struct wl1251_acx_tid_cfg {
+       struct acx_header header;
+
+       /* tx queue id number (0-7) */
+       u8 queue;
+
+       /* channel access type for the queue, enum wl1251_acx_channel_type */
+       u8 type;
+
+       /* EDCA: ac index (0-3), HCCA: traffic stream id (8-15) */
+       u8 tsid;
+
+       /* ps scheme of the specified queue, enum wl1251_acx_ps_scheme */
+       u8 ps_scheme;
+
+       /* the tx queue ack policy, enum wl1251_acx_ack_policy */
+       u8 ack_policy;
+
+       u8 padding[3];
+
+       /* not supported */
+       u32 apsdconf[2];
+} __packed;
+
+/*************************************************************************
+
+    Host Interrupt Register (WiLink -> Host)
+
+**************************************************************************/
+
+/* RX packet is ready in Xfer buffer #0 */
+#define WL1251_ACX_INTR_RX0_DATA      BIT(0)
+
+/* TX result(s) are in the TX complete buffer */
+#define WL1251_ACX_INTR_TX_RESULT      BIT(1)
+
+/* OBSOLETE */
+#define WL1251_ACX_INTR_TX_XFR         BIT(2)
+
+/* RX packet is ready in Xfer buffer #1 */
+#define WL1251_ACX_INTR_RX1_DATA       BIT(3)
+
+/* Event was entered to Event MBOX #A */
+#define WL1251_ACX_INTR_EVENT_A                BIT(4)
+
+/* Event was entered to Event MBOX #B */
+#define WL1251_ACX_INTR_EVENT_B                BIT(5)
+
+/* OBSOLETE */
+#define WL1251_ACX_INTR_WAKE_ON_HOST   BIT(6)
+
+/* Trace message on MBOX #A */
+#define WL1251_ACX_INTR_TRACE_A                BIT(7)
+
+/* Trace message on MBOX #B */
+#define WL1251_ACX_INTR_TRACE_B                BIT(8)
+
+/* Command processing completion */
+#define WL1251_ACX_INTR_CMD_COMPLETE   BIT(9)
+
+/* Init sequence is done */
+#define WL1251_ACX_INTR_INIT_COMPLETE  BIT(14)
+
+#define WL1251_ACX_INTR_ALL           0xFFFFFFFF
+
+enum {
+       ACX_WAKE_UP_CONDITIONS      = 0x0002,
+       ACX_MEM_CFG                 = 0x0003,
+       ACX_SLOT                    = 0x0004,
+       ACX_QUEUE_HEAD              = 0x0005, /* for MASTER mode only */
+       ACX_AC_CFG                  = 0x0007,
+       ACX_MEM_MAP                 = 0x0008,
+       ACX_AID                     = 0x000A,
+       ACX_RADIO_PARAM             = 0x000B, /* Not used */
+       ACX_CFG                     = 0x000C, /* Not used */
+       ACX_FW_REV                  = 0x000D,
+       ACX_MEDIUM_USAGE            = 0x000F,
+       ACX_RX_CFG                  = 0x0010,
+       ACX_TX_QUEUE_CFG            = 0x0011, /* FIXME: only used by wl1251 */
+       ACX_BSS_IN_PS               = 0x0012, /* for AP only */
+       ACX_STATISTICS              = 0x0013, /* Debug API */
+       ACX_FEATURE_CFG             = 0x0015,
+       ACX_MISC_CFG                = 0x0017, /* Not used */
+       ACX_TID_CFG                 = 0x001A,
+       ACX_BEACON_FILTER_OPT       = 0x001F,
+       ACX_LOW_RSSI                = 0x0020,
+       ACX_NOISE_HIST              = 0x0021,
+       ACX_HDK_VERSION             = 0x0022, /* ??? */
+       ACX_PD_THRESHOLD            = 0x0023,
+       ACX_DATA_PATH_PARAMS        = 0x0024, /* WO */
+       ACX_DATA_PATH_RESP_PARAMS   = 0x0024, /* RO */
+       ACX_CCA_THRESHOLD           = 0x0025,
+       ACX_EVENT_MBOX_MASK         = 0x0026,
+#ifdef FW_RUNNING_AS_AP
+       ACX_DTIM_PERIOD             = 0x0027, /* for AP only */
+#else
+       ACX_WR_TBTT_AND_DTIM        = 0x0027, /* STA only */
+#endif
+       ACX_ACI_OPTION_CFG          = 0x0029, /* OBSOLETE (for 1251)*/
+       ACX_GPIO_CFG                = 0x002A, /* Not used */
+       ACX_GPIO_SET                = 0x002B, /* Not used */
+       ACX_PM_CFG                  = 0x002C, /* To Be Documented */
+       ACX_CONN_MONIT_PARAMS       = 0x002D,
+       ACX_AVERAGE_RSSI            = 0x002E, /* Not used */
+       ACX_CONS_TX_FAILURE         = 0x002F,
+       ACX_BCN_DTIM_OPTIONS        = 0x0031,
+       ACX_SG_ENABLE               = 0x0032,
+       ACX_SG_CFG                  = 0x0033,
+       ACX_ANTENNA_DIVERSITY_CFG   = 0x0035, /* To Be Documented */
+       ACX_LOW_SNR                 = 0x0037, /* To Be Documented */
+       ACX_BEACON_FILTER_TABLE     = 0x0038,
+       ACX_ARP_IP_FILTER           = 0x0039,
+       ACX_ROAMING_STATISTICS_TBL  = 0x003B,
+       ACX_RATE_POLICY             = 0x003D,
+       ACX_CTS_PROTECTION          = 0x003E,
+       ACX_SLEEP_AUTH              = 0x003F,
+       ACX_PREAMBLE_TYPE           = 0x0040,
+       ACX_ERROR_CNT               = 0x0041,
+       ACX_FW_GEN_FRAME_RATES      = 0x0042,
+       ACX_IBSS_FILTER             = 0x0044,
+       ACX_SERVICE_PERIOD_TIMEOUT  = 0x0045,
+       ACX_TSF_INFO                = 0x0046,
+       ACX_CONFIG_PS_WMM           = 0x0049,
+       ACX_ENABLE_RX_DATA_FILTER   = 0x004A,
+       ACX_SET_RX_DATA_FILTER      = 0x004B,
+       ACX_GET_DATA_FILTER_STATISTICS = 0x004C,
+       ACX_POWER_LEVEL_TABLE       = 0x004D,
+       ACX_BET_ENABLE              = 0x0050,
+       DOT11_STATION_ID            = 0x1001,
+       DOT11_RX_MSDU_LIFE_TIME     = 0x1004,
+       DOT11_CUR_TX_PWR            = 0x100D,
+       DOT11_DEFAULT_KEY           = 0x1010,
+       DOT11_RX_DOT11_MODE         = 0x1012,
+       DOT11_RTS_THRESHOLD         = 0x1013,
+       DOT11_GROUP_ADDRESS_TBL     = 0x1014,
+
+       MAX_DOT11_IE = DOT11_GROUP_ADDRESS_TBL,
+
+       MAX_IE = 0xFFFF
+};
+
+
+int wl1251_acx_frame_rates(struct wl1251 *wl, u8 ctrl_rate, u8 ctrl_mod,
+                          u8 mgt_rate, u8 mgt_mod);
+int wl1251_acx_station_id(struct wl1251 *wl);
+int wl1251_acx_default_key(struct wl1251 *wl, u8 key_id);
+int wl1251_acx_wake_up_conditions(struct wl1251 *wl, u8 wake_up_event,
+                                 u8 listen_interval);
+int wl1251_acx_sleep_auth(struct wl1251 *wl, u8 sleep_auth);
+int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len);
+int wl1251_acx_tx_power(struct wl1251 *wl, int power);
+int wl1251_acx_feature_cfg(struct wl1251 *wl);
+int wl1251_acx_mem_map(struct wl1251 *wl,
+                      struct acx_header *mem_map, size_t len);
+int wl1251_acx_data_path_params(struct wl1251 *wl,
+                               struct acx_data_path_params_resp *data_path);
+int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time);
+int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter);
+int wl1251_acx_pd_threshold(struct wl1251 *wl);
+int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time);
+int wl1251_acx_group_address_tbl(struct wl1251 *wl);
+int wl1251_acx_service_period_timeout(struct wl1251 *wl);
+int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold);
+int wl1251_acx_beacon_filter_opt(struct wl1251 *wl, bool enable_filter);
+int wl1251_acx_beacon_filter_table(struct wl1251 *wl);
+int wl1251_acx_conn_monit_params(struct wl1251 *wl);
+int wl1251_acx_sg_enable(struct wl1251 *wl);
+int wl1251_acx_sg_cfg(struct wl1251 *wl);
+int wl1251_acx_cca_threshold(struct wl1251 *wl);
+int wl1251_acx_bcn_dtim_options(struct wl1251 *wl);
+int wl1251_acx_aid(struct wl1251 *wl, u16 aid);
+int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask);
+int wl1251_acx_low_rssi(struct wl1251 *wl, s8 threshold, u8 weight,
+                       u8 depth, enum wl1251_acx_low_rssi_type type);
+int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble);
+int wl1251_acx_cts_protect(struct wl1251 *wl,
+                           enum acx_ctsprotect_type ctsprotect);
+int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats);
+int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime);
+int wl1251_acx_rate_policies(struct wl1251 *wl);
+int wl1251_acx_mem_cfg(struct wl1251 *wl);
+int wl1251_acx_wr_tbtt_and_dtim(struct wl1251 *wl, u16 tbtt, u8 dtim);
+int wl1251_acx_bet_enable(struct wl1251 *wl, enum wl1251_acx_bet_mode mode,
+                         u8 max_consecutive);
+int wl1251_acx_ac_cfg(struct wl1251 *wl, u8 ac, u8 cw_min, u16 cw_max,
+                     u8 aifs, u16 txop);
+int wl1251_acx_tid_cfg(struct wl1251 *wl, u8 queue,
+                      enum wl1251_acx_channel_type type,
+                      u8 tsid, enum wl1251_acx_ps_scheme ps_scheme,
+                      enum wl1251_acx_ack_policy ack_policy);
+
+#endif /* __WL1251_ACX_H__ */
diff --git a/drivers/net/wireless/ti/wl1251/boot.c b/drivers/net/wireless/ti/wl1251/boot.c
new file mode 100644 (file)
index 0000000..a2e5241
--- /dev/null
@@ -0,0 +1,554 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/slab.h>
+
+#include "reg.h"
+#include "boot.h"
+#include "io.h"
+#include "spi.h"
+#include "event.h"
+#include "acx.h"
+
+void wl1251_boot_target_enable_interrupts(struct wl1251 *wl)
+{
+       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
+       wl1251_reg_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
+}
+
+int wl1251_boot_soft_reset(struct wl1251 *wl)
+{
+       unsigned long timeout;
+       u32 boot_data;
+
+       /* perform soft reset */
+       wl1251_reg_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
+
+       /* SOFT_RESET is self clearing */
+       timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
+       while (1) {
+               boot_data = wl1251_reg_read32(wl, ACX_REG_SLV_SOFT_RESET);
+               wl1251_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
+               if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
+                       break;
+
+               if (time_after(jiffies, timeout)) {
+                       /* 1.2 check pWhalBus->uSelfClearTime if the
+                        * timeout was reached */
+                       wl1251_error("soft reset timeout");
+                       return -1;
+               }
+
+               udelay(SOFT_RESET_STALL_TIME);
+       }
+
+       /* disable Rx/Tx */
+       wl1251_reg_write32(wl, ENABLE, 0x0);
+
+       /* disable auto calibration on start*/
+       wl1251_reg_write32(wl, SPARE_A2, 0xffff);
+
+       return 0;
+}
+
+int wl1251_boot_init_seq(struct wl1251 *wl)
+{
+       u32 scr_pad6, init_data, tmp, elp_cmd, ref_freq;
+
+       /*
+        * col #1: INTEGER_DIVIDER
+        * col #2: FRACTIONAL_DIVIDER
+        * col #3: ATTN_BB
+        * col #4: ALPHA_BB
+        * col #5: STOP_TIME_BB
+        * col #6: BB_PLL_LOOP_FILTER
+        */
+       static const u32 LUT[REF_FREQ_NUM][LUT_PARAM_NUM] = {
+
+               {   83, 87381,  0xB, 5, 0xF00,  3}, /* REF_FREQ_19_2*/
+               {   61, 141154, 0xB, 5, 0x1450, 2}, /* REF_FREQ_26_0*/
+               {   41, 174763, 0xC, 6, 0x2D00, 1}, /* REF_FREQ_38_4*/
+               {   40, 0,      0xC, 6, 0x2EE0, 1}, /* REF_FREQ_40_0*/
+               {   47, 162280, 0xC, 6, 0x2760, 1}  /* REF_FREQ_33_6        */
+       };
+
+       /* read NVS params */
+       scr_pad6 = wl1251_reg_read32(wl, SCR_PAD6);
+       wl1251_debug(DEBUG_BOOT, "scr_pad6 0x%x", scr_pad6);
+
+       /* read ELP_CMD */
+       elp_cmd = wl1251_reg_read32(wl, ELP_CMD);
+       wl1251_debug(DEBUG_BOOT, "elp_cmd 0x%x", elp_cmd);
+
+       /* set the BB calibration time to be 300 usec (PLL_CAL_TIME) */
+       ref_freq = scr_pad6 & 0x000000FF;
+       wl1251_debug(DEBUG_BOOT, "ref_freq 0x%x", ref_freq);
+
+       wl1251_reg_write32(wl, PLL_CAL_TIME, 0x9);
+
+       /*
+        * PG 1.2: set the clock buffer time to be 210 usec (CLK_BUF_TIME)
+        */
+       wl1251_reg_write32(wl, CLK_BUF_TIME, 0x6);
+
+       /*
+        * set the clock detect feature to work in the restart wu procedure
+        * (ELP_CFG_MODE[14]) and Select the clock source type
+        * (ELP_CFG_MODE[13:12])
+        */
+       tmp = ((scr_pad6 & 0x0000FF00) << 4) | 0x00004000;
+       wl1251_reg_write32(wl, ELP_CFG_MODE, tmp);
+
+       /* PG 1.2: enable the BB PLL fix. Enable the PLL_LIMP_CLK_EN_CMD */
+       elp_cmd |= 0x00000040;
+       wl1251_reg_write32(wl, ELP_CMD, elp_cmd);
+
+       /* PG 1.2: Set the BB PLL stable time to be 1000usec
+        * (PLL_STABLE_TIME) */
+       wl1251_reg_write32(wl, CFG_PLL_SYNC_CNT, 0x20);
+
+       /* PG 1.2: read clock request time */
+       init_data = wl1251_reg_read32(wl, CLK_REQ_TIME);
+
+       /*
+        * PG 1.2: set the clock request time to be ref_clk_settling_time -
+        * 1ms = 4ms
+        */
+       if (init_data > 0x21)
+               tmp = init_data - 0x21;
+       else
+               tmp = 0;
+       wl1251_reg_write32(wl, CLK_REQ_TIME, tmp);
+
+       /* set BB PLL configurations in RF AFE */
+       wl1251_reg_write32(wl, 0x003058cc, 0x4B5);
+
+       /* set RF_AFE_REG_5 */
+       wl1251_reg_write32(wl, 0x003058d4, 0x50);
+
+       /* set RF_AFE_CTRL_REG_2 */
+       wl1251_reg_write32(wl, 0x00305948, 0x11c001);
+
+       /*
+        * change RF PLL and BB PLL divider for VCO clock and adjust VCO
+        * bais current(RF_AFE_REG_13)
+        */
+       wl1251_reg_write32(wl, 0x003058f4, 0x1e);
+
+       /* set BB PLL configurations */
+       tmp = LUT[ref_freq][LUT_PARAM_INTEGER_DIVIDER] | 0x00017000;
+       wl1251_reg_write32(wl, 0x00305840, tmp);
+
+       /* set fractional divider according to Appendix C-BB PLL
+        * Calculations
+        */
+       tmp = LUT[ref_freq][LUT_PARAM_FRACTIONAL_DIVIDER];
+       wl1251_reg_write32(wl, 0x00305844, tmp);
+
+       /* set the initial data for the sigma delta */
+       wl1251_reg_write32(wl, 0x00305848, 0x3039);
+
+       /*
+        * set the accumulator attenuation value, calibration loop1
+        * (alpha), calibration loop2 (beta), calibration loop3 (gamma) and
+        * the VCO gain
+        */
+       tmp = (LUT[ref_freq][LUT_PARAM_ATTN_BB] << 16) |
+               (LUT[ref_freq][LUT_PARAM_ALPHA_BB] << 12) | 0x1;
+       wl1251_reg_write32(wl, 0x00305854, tmp);
+
+       /*
+        * set the calibration stop time after holdoff time expires and set
+        * settling time HOLD_OFF_TIME_BB
+        */
+       tmp = LUT[ref_freq][LUT_PARAM_STOP_TIME_BB] | 0x000A0000;
+       wl1251_reg_write32(wl, 0x00305858, tmp);
+
+       /*
+        * set BB PLL Loop filter capacitor3- BB_C3[2:0] and set BB PLL
+        * constant leakage current to linearize PFD to 0uA -
+        * BB_ILOOPF[7:3]
+        */
+       tmp = LUT[ref_freq][LUT_PARAM_BB_PLL_LOOP_FILTER] | 0x00000030;
+       wl1251_reg_write32(wl, 0x003058f8, tmp);
+
+       /*
+        * set regulator output voltage for n divider to
+        * 1.35-BB_REFDIV[1:0], set charge pump current- BB_CPGAIN[4:2],
+        * set BB PLL Loop filter capacitor2- BB_C2[7:5], set gain of BB
+        * PLL auto-call to normal mode- BB_CALGAIN_3DB[8]
+        */
+       wl1251_reg_write32(wl, 0x003058f0, 0x29);
+
+       /* enable restart wakeup sequence (ELP_CMD[0]) */
+       wl1251_reg_write32(wl, ELP_CMD, elp_cmd | 0x1);
+
+       /* restart sequence completed */
+       udelay(2000);
+
+       return 0;
+}
+
+static void wl1251_boot_set_ecpu_ctrl(struct wl1251 *wl, u32 flag)
+{
+       u32 cpu_ctrl;
+
+       /* 10.5.0 run the firmware (I) */
+       cpu_ctrl = wl1251_reg_read32(wl, ACX_REG_ECPU_CONTROL);
+
+       /* 10.5.1 run the firmware (II) */
+       cpu_ctrl &= ~flag;
+       wl1251_reg_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl);
+}
+
+int wl1251_boot_run_firmware(struct wl1251 *wl)
+{
+       int loop, ret;
+       u32 chip_id, acx_intr;
+
+       wl1251_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
+
+       chip_id = wl1251_reg_read32(wl, CHIP_ID_B);
+
+       wl1251_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
+
+       if (chip_id != wl->chip_id) {
+               wl1251_error("chip id doesn't match after firmware boot");
+               return -EIO;
+       }
+
+       /* wait for init to complete */
+       loop = 0;
+       while (loop++ < INIT_LOOP) {
+               udelay(INIT_LOOP_DELAY);
+               acx_intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
+
+               if (acx_intr == 0xffffffff) {
+                       wl1251_error("error reading hardware complete "
+                                    "init indication");
+                       return -EIO;
+               }
+               /* check that ACX_INTR_INIT_COMPLETE is enabled */
+               else if (acx_intr & WL1251_ACX_INTR_INIT_COMPLETE) {
+                       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
+                                          WL1251_ACX_INTR_INIT_COMPLETE);
+                       break;
+               }
+       }
+
+       if (loop > INIT_LOOP) {
+               wl1251_error("timeout waiting for the hardware to "
+                            "complete initialization");
+               return -EIO;
+       }
+
+       /* get hardware config command mail box */
+       wl->cmd_box_addr = wl1251_reg_read32(wl, REG_COMMAND_MAILBOX_PTR);
+
+       /* get hardware config event mail box */
+       wl->event_box_addr = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
+
+       /* set the working partition to its "running" mode offset */
+       wl1251_set_partition(wl, WL1251_PART_WORK_MEM_START,
+                            WL1251_PART_WORK_MEM_SIZE,
+                            WL1251_PART_WORK_REG_START,
+                            WL1251_PART_WORK_REG_SIZE);
+
+       wl1251_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
+                    wl->cmd_box_addr, wl->event_box_addr);
+
+       wl1251_acx_fw_version(wl, wl->fw_ver, sizeof(wl->fw_ver));
+
+       /*
+        * in case of full asynchronous mode the firmware event must be
+        * ready to receive event from the command mailbox
+        */
+
+       /* enable gpio interrupts */
+       wl1251_enable_interrupts(wl);
+
+       /* Enable target's interrupts */
+       wl->intr_mask = WL1251_ACX_INTR_RX0_DATA |
+               WL1251_ACX_INTR_RX1_DATA |
+               WL1251_ACX_INTR_TX_RESULT |
+               WL1251_ACX_INTR_EVENT_A |
+               WL1251_ACX_INTR_EVENT_B |
+               WL1251_ACX_INTR_INIT_COMPLETE;
+       wl1251_boot_target_enable_interrupts(wl);
+
+       wl->event_mask = SCAN_COMPLETE_EVENT_ID | BSS_LOSE_EVENT_ID |
+               SYNCHRONIZATION_TIMEOUT_EVENT_ID |
+               ROAMING_TRIGGER_LOW_RSSI_EVENT_ID |
+               ROAMING_TRIGGER_REGAINED_RSSI_EVENT_ID |
+               REGAINED_BSS_EVENT_ID | BT_PTA_SENSE_EVENT_ID |
+               BT_PTA_PREDICTION_EVENT_ID | JOIN_EVENT_COMPLETE_ID;
+
+       ret = wl1251_event_unmask(wl);
+       if (ret < 0) {
+               wl1251_error("EVENT mask setting failed");
+               return ret;
+       }
+
+       wl1251_event_mbox_config(wl);
+
+       /* firmware startup completed */
+       return 0;
+}
+
+static int wl1251_boot_upload_firmware(struct wl1251 *wl)
+{
+       int addr, chunk_num, partition_limit;
+       size_t fw_data_len, len;
+       u8 *p, *buf;
+
+       /* whal_FwCtrl_LoadFwImageSm() */
+
+       wl1251_debug(DEBUG_BOOT, "chip id before fw upload: 0x%x",
+                    wl1251_reg_read32(wl, CHIP_ID_B));
+
+       /* 10.0 check firmware length and set partition */
+       fw_data_len =  (wl->fw[4] << 24) | (wl->fw[5] << 16) |
+               (wl->fw[6] << 8) | (wl->fw[7]);
+
+       wl1251_debug(DEBUG_BOOT, "fw_data_len %zu chunk_size %d", fw_data_len,
+               CHUNK_SIZE);
+
+       if ((fw_data_len % 4) != 0) {
+               wl1251_error("firmware length not multiple of four");
+               return -EIO;
+       }
+
+       buf = kmalloc(CHUNK_SIZE, GFP_KERNEL);
+       if (!buf) {
+               wl1251_error("allocation for firmware upload chunk failed");
+               return -ENOMEM;
+       }
+
+       wl1251_set_partition(wl, WL1251_PART_DOWN_MEM_START,
+                            WL1251_PART_DOWN_MEM_SIZE,
+                            WL1251_PART_DOWN_REG_START,
+                            WL1251_PART_DOWN_REG_SIZE);
+
+       /* 10.1 set partition limit and chunk num */
+       chunk_num = 0;
+       partition_limit = WL1251_PART_DOWN_MEM_SIZE;
+
+       while (chunk_num < fw_data_len / CHUNK_SIZE) {
+               /* 10.2 update partition, if needed */
+               addr = WL1251_PART_DOWN_MEM_START +
+                       (chunk_num + 2) * CHUNK_SIZE;
+               if (addr > partition_limit) {
+                       addr = WL1251_PART_DOWN_MEM_START +
+                               chunk_num * CHUNK_SIZE;
+                       partition_limit = chunk_num * CHUNK_SIZE +
+                               WL1251_PART_DOWN_MEM_SIZE;
+                       wl1251_set_partition(wl,
+                                            addr,
+                                            WL1251_PART_DOWN_MEM_SIZE,
+                                            WL1251_PART_DOWN_REG_START,
+                                            WL1251_PART_DOWN_REG_SIZE);
+               }
+
+               /* 10.3 upload the chunk */
+               addr = WL1251_PART_DOWN_MEM_START + chunk_num * CHUNK_SIZE;
+               p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
+               wl1251_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
+                            p, addr);
+
+               /* need to copy the chunk for dma */
+               len = CHUNK_SIZE;
+               memcpy(buf, p, len);
+               wl1251_mem_write(wl, addr, buf, len);
+
+               chunk_num++;
+       }
+
+       /* 10.4 upload the last chunk */
+       addr = WL1251_PART_DOWN_MEM_START + chunk_num * CHUNK_SIZE;
+       p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
+
+       /* need to copy the chunk for dma */
+       len = fw_data_len % CHUNK_SIZE;
+       memcpy(buf, p, len);
+
+       wl1251_debug(DEBUG_BOOT, "uploading fw last chunk (%zu B) 0x%p to 0x%x",
+                    len, p, addr);
+       wl1251_mem_write(wl, addr, buf, len);
+
+       kfree(buf);
+
+       return 0;
+}
+
+static int wl1251_boot_upload_nvs(struct wl1251 *wl)
+{
+       size_t nvs_len, nvs_bytes_written, burst_len;
+       int nvs_start, i;
+       u32 dest_addr, val;
+       u8 *nvs_ptr, *nvs;
+
+       nvs = wl->nvs;
+       if (nvs == NULL)
+               return -ENODEV;
+
+       nvs_ptr = nvs;
+
+       nvs_len = wl->nvs_len;
+       nvs_start = wl->fw_len;
+
+       /*
+        * Layout before the actual NVS tables:
+        * 1 byte : burst length.
+        * 2 bytes: destination address.
+        * n bytes: data to burst copy.
+        *
+        * This is ended by a 0 length, then the NVS tables.
+        */
+
+       while (nvs_ptr[0]) {
+               burst_len = nvs_ptr[0];
+               dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
+
+               /* We move our pointer to the data */
+               nvs_ptr += 3;
+
+               for (i = 0; i < burst_len; i++) {
+                       val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
+                              | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
+
+                       wl1251_debug(DEBUG_BOOT,
+                                    "nvs burst write 0x%x: 0x%x",
+                                    dest_addr, val);
+                       wl1251_mem_write32(wl, dest_addr, val);
+
+                       nvs_ptr += 4;
+                       dest_addr += 4;
+               }
+       }
+
+       /*
+        * We've reached the first zero length, the first NVS table
+        * is 7 bytes further.
+        */
+       nvs_ptr += 7;
+       nvs_len -= nvs_ptr - nvs;
+       nvs_len = ALIGN(nvs_len, 4);
+
+       /* Now we must set the partition correctly */
+       wl1251_set_partition(wl, nvs_start,
+                            WL1251_PART_DOWN_MEM_SIZE,
+                            WL1251_PART_DOWN_REG_START,
+                            WL1251_PART_DOWN_REG_SIZE);
+
+       /* And finally we upload the NVS tables */
+       nvs_bytes_written = 0;
+       while (nvs_bytes_written < nvs_len) {
+               val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
+                      | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
+
+               wl1251_debug(DEBUG_BOOT,
+                            "nvs write table 0x%x: 0x%x",
+                            nvs_start, val);
+               wl1251_mem_write32(wl, nvs_start, val);
+
+               nvs_ptr += 4;
+               nvs_bytes_written += 4;
+               nvs_start += 4;
+       }
+
+       return 0;
+}
+
+int wl1251_boot(struct wl1251 *wl)
+{
+       int ret = 0, minor_minor_e2_ver;
+       u32 tmp, boot_data;
+
+       /* halt embedded ARM CPU while loading firmware */
+       wl1251_reg_write32(wl, ACX_REG_ECPU_CONTROL, ECPU_CONTROL_HALT);
+
+       ret = wl1251_boot_soft_reset(wl);
+       if (ret < 0)
+               goto out;
+
+       /* 2. start processing NVS file */
+       if (wl->use_eeprom) {
+               wl1251_reg_write32(wl, ACX_REG_EE_START, START_EEPROM_MGR);
+               /* Wait for EEPROM NVS burst read to complete */
+               msleep(40);
+               wl1251_reg_write32(wl, ACX_EEPROMLESS_IND_REG, USE_EEPROM);
+       } else {
+               ret = wl1251_boot_upload_nvs(wl);
+               if (ret < 0)
+                       goto out;
+
+               /* write firmware's last address (ie. it's length) to
+                * ACX_EEPROMLESS_IND_REG */
+               wl1251_reg_write32(wl, ACX_EEPROMLESS_IND_REG, wl->fw_len);
+       }
+
+       /* 6. read the EEPROM parameters */
+       tmp = wl1251_reg_read32(wl, SCR_PAD2);
+
+       /* 7. read bootdata */
+       wl->boot_attr.radio_type = (tmp & 0x0000FF00) >> 8;
+       wl->boot_attr.major = (tmp & 0x00FF0000) >> 16;
+       tmp = wl1251_reg_read32(wl, SCR_PAD3);
+
+       /* 8. check bootdata and call restart sequence */
+       wl->boot_attr.minor = (tmp & 0x00FF0000) >> 16;
+       minor_minor_e2_ver = (tmp & 0xFF000000) >> 24;
+
+       wl1251_debug(DEBUG_BOOT, "radioType 0x%x majorE2Ver 0x%x "
+                    "minorE2Ver 0x%x minor_minor_e2_ver 0x%x",
+                    wl->boot_attr.radio_type, wl->boot_attr.major,
+                    wl->boot_attr.minor, minor_minor_e2_ver);
+
+       ret = wl1251_boot_init_seq(wl);
+       if (ret < 0)
+               goto out;
+
+       /* 9. NVS processing done */
+       boot_data = wl1251_reg_read32(wl, ACX_REG_ECPU_CONTROL);
+
+       wl1251_debug(DEBUG_BOOT, "halt boot_data 0x%x", boot_data);
+
+       /* 10. check that ECPU_CONTROL_HALT bits are set in
+        * pWhalBus->uBootData and start uploading firmware
+        */
+       if ((boot_data & ECPU_CONTROL_HALT) == 0) {
+               wl1251_error("boot failed, ECPU_CONTROL_HALT not set");
+               ret = -EIO;
+               goto out;
+       }
+
+       ret = wl1251_boot_upload_firmware(wl);
+       if (ret < 0)
+               goto out;
+
+       /* 10.5 start firmware */
+       ret = wl1251_boot_run_firmware(wl);
+       if (ret < 0)
+               goto out;
+
+out:
+       return ret;
+}
diff --git a/drivers/net/wireless/ti/wl1251/boot.h b/drivers/net/wireless/ti/wl1251/boot.h
new file mode 100644 (file)
index 0000000..7661bc5
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __BOOT_H__
+#define __BOOT_H__
+
+#include "wl1251.h"
+
+int wl1251_boot_soft_reset(struct wl1251 *wl);
+int wl1251_boot_init_seq(struct wl1251 *wl);
+int wl1251_boot_run_firmware(struct wl1251 *wl);
+void wl1251_boot_target_enable_interrupts(struct wl1251 *wl);
+int wl1251_boot(struct wl1251 *wl);
+
+/* number of times we try to read the INIT interrupt */
+#define INIT_LOOP 20000
+
+/* delay between retries */
+#define INIT_LOOP_DELAY 50
+
+#endif
diff --git a/drivers/net/wireless/ti/wl1251/cmd.c b/drivers/net/wireless/ti/wl1251/cmd.c
new file mode 100644 (file)
index 0000000..d14d69d
--- /dev/null
@@ -0,0 +1,496 @@
+#include "cmd.h"
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/crc7.h>
+
+#include "wl1251.h"
+#include "reg.h"
+#include "io.h"
+#include "ps.h"
+#include "acx.h"
+
+/**
+ * send command to firmware
+ *
+ * @wl: wl struct
+ * @id: command id
+ * @buf: buffer containing the command, must work with dma
+ * @len: length of the buffer
+ */
+int wl1251_cmd_send(struct wl1251 *wl, u16 id, void *buf, size_t len)
+{
+       struct wl1251_cmd_header *cmd;
+       unsigned long timeout;
+       u32 intr;
+       int ret = 0;
+
+       cmd = buf;
+       cmd->id = id;
+       cmd->status = 0;
+
+       WARN_ON(len % 4 != 0);
+
+       wl1251_mem_write(wl, wl->cmd_box_addr, buf, len);
+
+       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
+
+       timeout = jiffies + msecs_to_jiffies(WL1251_COMMAND_TIMEOUT);
+
+       intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
+       while (!(intr & WL1251_ACX_INTR_CMD_COMPLETE)) {
+               if (time_after(jiffies, timeout)) {
+                       wl1251_error("command complete timeout");
+                       ret = -ETIMEDOUT;
+                       goto out;
+               }
+
+               msleep(1);
+
+               intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
+       }
+
+       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
+                          WL1251_ACX_INTR_CMD_COMPLETE);
+
+out:
+       return ret;
+}
+
+/**
+ * send test command to firmware
+ *
+ * @wl: wl struct
+ * @buf: buffer containing the command, with all headers, must work with dma
+ * @len: length of the buffer
+ * @answer: is answer needed
+ */
+int wl1251_cmd_test(struct wl1251 *wl, void *buf, size_t buf_len, u8 answer)
+{
+       int ret;
+
+       wl1251_debug(DEBUG_CMD, "cmd test");
+
+       ret = wl1251_cmd_send(wl, CMD_TEST, buf, buf_len);
+
+       if (ret < 0) {
+               wl1251_warning("TEST command failed");
+               return ret;
+       }
+
+       if (answer) {
+               struct wl1251_command *cmd_answer;
+
+               /*
+                * The test command got in, we can read the answer.
+                * The answer would be a wl1251_command, where the
+                * parameter array contains the actual answer.
+                */
+               wl1251_mem_read(wl, wl->cmd_box_addr, buf, buf_len);
+
+               cmd_answer = buf;
+
+               if (cmd_answer->header.status != CMD_STATUS_SUCCESS)
+                       wl1251_error("TEST command answer error: %d",
+                                    cmd_answer->header.status);
+       }
+
+       return 0;
+}
+
+/**
+ * read acx from firmware
+ *
+ * @wl: wl struct
+ * @id: acx id
+ * @buf: buffer for the response, including all headers, must work with dma
+ * @len: length of buf
+ */
+int wl1251_cmd_interrogate(struct wl1251 *wl, u16 id, void *buf, size_t len)
+{
+       struct acx_header *acx = buf;
+       int ret;
+
+       wl1251_debug(DEBUG_CMD, "cmd interrogate");
+
+       acx->id = id;
+
+       /* payload length, does not include any headers */
+       acx->len = len - sizeof(*acx);
+
+       ret = wl1251_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1251_error("INTERROGATE command failed");
+               goto out;
+       }
+
+       /* the interrogate command got in, we can read the answer */
+       wl1251_mem_read(wl, wl->cmd_box_addr, buf, len);
+
+       acx = buf;
+       if (acx->cmd.status != CMD_STATUS_SUCCESS)
+               wl1251_error("INTERROGATE command error: %d",
+                            acx->cmd.status);
+
+out:
+       return ret;
+}
+
+/**
+ * write acx value to firmware
+ *
+ * @wl: wl struct
+ * @id: acx id
+ * @buf: buffer containing acx, including all headers, must work with dma
+ * @len: length of buf
+ */
+int wl1251_cmd_configure(struct wl1251 *wl, u16 id, void *buf, size_t len)
+{
+       struct acx_header *acx = buf;
+       int ret;
+
+       wl1251_debug(DEBUG_CMD, "cmd configure");
+
+       acx->id = id;
+
+       /* payload length, does not include any headers */
+       acx->len = len - sizeof(*acx);
+
+       ret = wl1251_cmd_send(wl, CMD_CONFIGURE, acx, len);
+       if (ret < 0) {
+               wl1251_warning("CONFIGURE command NOK");
+               return ret;
+       }
+
+       return 0;
+}
+
+int wl1251_cmd_vbm(struct wl1251 *wl, u8 identity,
+                  void *bitmap, u16 bitmap_len, u8 bitmap_control)
+{
+       struct wl1251_cmd_vbm_update *vbm;
+       int ret;
+
+       wl1251_debug(DEBUG_CMD, "cmd vbm");
+
+       vbm = kzalloc(sizeof(*vbm), GFP_KERNEL);
+       if (!vbm) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* Count and period will be filled by the target */
+       vbm->tim.bitmap_ctrl = bitmap_control;
+       if (bitmap_len > PARTIAL_VBM_MAX) {
+               wl1251_warning("cmd vbm len is %d B, truncating to %d",
+                              bitmap_len, PARTIAL_VBM_MAX);
+               bitmap_len = PARTIAL_VBM_MAX;
+       }
+       memcpy(vbm->tim.pvb_field, bitmap, bitmap_len);
+       vbm->tim.identity = identity;
+       vbm->tim.length = bitmap_len + 3;
+
+       vbm->len = cpu_to_le16(bitmap_len + 5);
+
+       ret = wl1251_cmd_send(wl, CMD_VBM, vbm, sizeof(*vbm));
+       if (ret < 0) {
+               wl1251_error("VBM command failed");
+               goto out;
+       }
+
+out:
+       kfree(vbm);
+       return ret;
+}
+
+int wl1251_cmd_data_path(struct wl1251 *wl, u8 channel, bool enable)
+{
+       struct cmd_enabledisable_path *cmd;
+       int ret;
+       u16 cmd_rx, cmd_tx;
+
+       wl1251_debug(DEBUG_CMD, "cmd data path");
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       cmd->channel = channel;
+
+       if (enable) {
+               cmd_rx = CMD_ENABLE_RX;
+               cmd_tx = CMD_ENABLE_TX;
+       } else {
+               cmd_rx = CMD_DISABLE_RX;
+               cmd_tx = CMD_DISABLE_TX;
+       }
+
+       ret = wl1251_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd));
+       if (ret < 0) {
+               wl1251_error("rx %s cmd for channel %d failed",
+                            enable ? "start" : "stop", channel);
+               goto out;
+       }
+
+       wl1251_debug(DEBUG_BOOT, "rx %s cmd channel %d",
+                    enable ? "start" : "stop", channel);
+
+       ret = wl1251_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd));
+       if (ret < 0) {
+               wl1251_error("tx %s cmd for channel %d failed",
+                            enable ? "start" : "stop", channel);
+               goto out;
+       }
+
+       wl1251_debug(DEBUG_BOOT, "tx %s cmd channel %d",
+                    enable ? "start" : "stop", channel);
+
+out:
+       kfree(cmd);
+       return ret;
+}
+
+int wl1251_cmd_join(struct wl1251 *wl, u8 bss_type, u8 channel,
+                   u16 beacon_interval, u8 dtim_interval)
+{
+       struct cmd_join *join;
+       int ret, i;
+       u8 *bssid;
+
+       join = kzalloc(sizeof(*join), GFP_KERNEL);
+       if (!join) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wl1251_debug(DEBUG_CMD, "cmd join%s ch %d %d/%d",
+                    bss_type == BSS_TYPE_IBSS ? " ibss" : "",
+                    channel, beacon_interval, dtim_interval);
+
+       /* Reverse order BSSID */
+       bssid = (u8 *) &join->bssid_lsb;
+       for (i = 0; i < ETH_ALEN; i++)
+               bssid[i] = wl->bssid[ETH_ALEN - i - 1];
+
+       join->rx_config_options = wl->rx_config;
+       join->rx_filter_options = wl->rx_filter;
+
+       /*
+        * FIXME: disable temporarily all filters because after commit
+        * 9cef8737 "mac80211: fix managed mode BSSID handling" broke
+        * association. The filter logic needs to be implemented properly
+        * and once that is done, this hack can be removed.
+        */
+       join->rx_config_options = 0;
+       join->rx_filter_options = WL1251_DEFAULT_RX_FILTER;
+
+       join->basic_rate_set = RATE_MASK_1MBPS | RATE_MASK_2MBPS |
+               RATE_MASK_5_5MBPS | RATE_MASK_11MBPS;
+
+       join->beacon_interval = beacon_interval;
+       join->dtim_interval = dtim_interval;
+       join->bss_type = bss_type;
+       join->channel = channel;
+       join->ctrl = JOIN_CMD_CTRL_TX_FLUSH;
+
+       ret = wl1251_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join));
+       if (ret < 0) {
+               wl1251_error("failed to initiate cmd join");
+               goto out;
+       }
+
+out:
+       kfree(join);
+       return ret;
+}
+
+int wl1251_cmd_ps_mode(struct wl1251 *wl, u8 ps_mode)
+{
+       struct wl1251_cmd_ps_params *ps_params = NULL;
+       int ret = 0;
+
+       wl1251_debug(DEBUG_CMD, "cmd set ps mode");
+
+       ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
+       if (!ps_params) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ps_params->ps_mode = ps_mode;
+       ps_params->send_null_data = 1;
+       ps_params->retries = 5;
+       ps_params->hang_over_period = 128;
+       ps_params->null_data_rate = 1; /* 1 Mbps */
+
+       ret = wl1251_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
+                             sizeof(*ps_params));
+       if (ret < 0) {
+               wl1251_error("cmd set_ps_mode failed");
+               goto out;
+       }
+
+out:
+       kfree(ps_params);
+       return ret;
+}
+
+int wl1251_cmd_read_memory(struct wl1251 *wl, u32 addr, void *answer,
+                          size_t len)
+{
+       struct cmd_read_write_memory *cmd;
+       int ret = 0;
+
+       wl1251_debug(DEBUG_CMD, "cmd read memory");
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       WARN_ON(len > MAX_READ_SIZE);
+       len = min_t(size_t, len, MAX_READ_SIZE);
+
+       cmd->addr = addr;
+       cmd->size = len;
+
+       ret = wl1251_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd));
+       if (ret < 0) {
+               wl1251_error("read memory command failed: %d", ret);
+               goto out;
+       }
+
+       /* the read command got in, we can now read the answer */
+       wl1251_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd));
+
+       if (cmd->header.status != CMD_STATUS_SUCCESS)
+               wl1251_error("error in read command result: %d",
+                            cmd->header.status);
+
+       memcpy(answer, cmd->value, len);
+
+out:
+       kfree(cmd);
+       return ret;
+}
+
+int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id,
+                           void *buf, size_t buf_len)
+{
+       struct wl1251_cmd_packet_template *cmd;
+       size_t cmd_len;
+       int ret = 0;
+
+       wl1251_debug(DEBUG_CMD, "cmd template %d", cmd_id);
+
+       WARN_ON(buf_len > WL1251_MAX_TEMPLATE_SIZE);
+       buf_len = min_t(size_t, buf_len, WL1251_MAX_TEMPLATE_SIZE);
+       cmd_len = ALIGN(sizeof(*cmd) + buf_len, 4);
+
+       cmd = kzalloc(cmd_len, GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       cmd->size = cpu_to_le16(buf_len);
+
+       if (buf)
+               memcpy(cmd->data, buf, buf_len);
+
+       ret = wl1251_cmd_send(wl, cmd_id, cmd, cmd_len);
+       if (ret < 0) {
+               wl1251_warning("cmd set_template failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(cmd);
+       return ret;
+}
+
+int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len,
+                   struct ieee80211_channel *channels[],
+                   unsigned int n_channels, unsigned int n_probes)
+{
+       struct wl1251_cmd_scan *cmd;
+       int i, ret = 0;
+
+       wl1251_debug(DEBUG_CMD, "cmd scan");
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd)
+               return -ENOMEM;
+
+       cmd->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
+       cmd->params.rx_filter_options = cpu_to_le32(CFG_RX_PRSP_EN |
+                                                   CFG_RX_MGMT_EN |
+                                                   CFG_RX_BCN_EN);
+       cmd->params.scan_options = 0;
+       cmd->params.num_channels = n_channels;
+       cmd->params.num_probe_requests = n_probes;
+       cmd->params.tx_rate = cpu_to_le16(1 << 1); /* 2 Mbps */
+       cmd->params.tid_trigger = 0;
+
+       for (i = 0; i < n_channels; i++) {
+               cmd->channels[i].min_duration =
+                       cpu_to_le32(WL1251_SCAN_MIN_DURATION);
+               cmd->channels[i].max_duration =
+                       cpu_to_le32(WL1251_SCAN_MAX_DURATION);
+               memset(&cmd->channels[i].bssid_lsb, 0xff, 4);
+               memset(&cmd->channels[i].bssid_msb, 0xff, 2);
+               cmd->channels[i].early_termination = 0;
+               cmd->channels[i].tx_power_att = 0;
+               cmd->channels[i].channel = channels[i]->hw_value;
+       }
+
+       cmd->params.ssid_len = ssid_len;
+       if (ssid)
+               memcpy(cmd->params.ssid, ssid, ssid_len);
+
+       ret = wl1251_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd));
+       if (ret < 0) {
+               wl1251_error("cmd scan failed: %d", ret);
+               goto out;
+       }
+
+       wl1251_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd));
+
+       if (cmd->header.status != CMD_STATUS_SUCCESS) {
+               wl1251_error("cmd scan status wasn't success: %d",
+                            cmd->header.status);
+               ret = -EIO;
+               goto out;
+       }
+
+out:
+       kfree(cmd);
+       return ret;
+}
+
+int wl1251_cmd_trigger_scan_to(struct wl1251 *wl, u32 timeout)
+{
+       struct wl1251_cmd_trigger_scan_to *cmd;
+       int ret;
+
+       wl1251_debug(DEBUG_CMD, "cmd trigger scan to");
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd)
+               return -ENOMEM;
+
+       cmd->timeout = timeout;
+
+       ret = wl1251_cmd_send(wl, CMD_TRIGGER_SCAN_TO, cmd, sizeof(*cmd));
+       if (ret < 0) {
+               wl1251_error("cmd trigger scan to failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(cmd);
+       return ret;
+}
diff --git a/drivers/net/wireless/ti/wl1251/cmd.h b/drivers/net/wireless/ti/wl1251/cmd.h
new file mode 100644 (file)
index 0000000..ee4f2b3
--- /dev/null
@@ -0,0 +1,415 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (c) 1998-2007 Texas Instruments Incorporated
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL1251_CMD_H__
+#define __WL1251_CMD_H__
+
+#include "wl1251.h"
+
+#include <net/cfg80211.h>
+
+struct acx_header;
+
+int wl1251_cmd_send(struct wl1251 *wl, u16 type, void *buf, size_t buf_len);
+int wl1251_cmd_test(struct wl1251 *wl, void *buf, size_t buf_len, u8 answer);
+int wl1251_cmd_interrogate(struct wl1251 *wl, u16 id, void *buf, size_t len);
+int wl1251_cmd_configure(struct wl1251 *wl, u16 id, void *buf, size_t len);
+int wl1251_cmd_vbm(struct wl1251 *wl, u8 identity,
+                  void *bitmap, u16 bitmap_len, u8 bitmap_control);
+int wl1251_cmd_data_path(struct wl1251 *wl, u8 channel, bool enable);
+int wl1251_cmd_join(struct wl1251 *wl, u8 bss_type, u8 channel,
+                   u16 beacon_interval, u8 dtim_interval);
+int wl1251_cmd_ps_mode(struct wl1251 *wl, u8 ps_mode);
+int wl1251_cmd_read_memory(struct wl1251 *wl, u32 addr, void *answer,
+                          size_t len);
+int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id,
+                           void *buf, size_t buf_len);
+int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len,
+                   struct ieee80211_channel *channels[],
+                   unsigned int n_channels, unsigned int n_probes);
+int wl1251_cmd_trigger_scan_to(struct wl1251 *wl, u32 timeout);
+
+/* unit ms */
+#define WL1251_COMMAND_TIMEOUT 2000
+
+enum wl1251_commands {
+       CMD_RESET           = 0,
+       CMD_INTERROGATE     = 1,    /*use this to read information elements*/
+       CMD_CONFIGURE       = 2,    /*use this to write information elements*/
+       CMD_ENABLE_RX       = 3,
+       CMD_ENABLE_TX       = 4,
+       CMD_DISABLE_RX      = 5,
+       CMD_DISABLE_TX      = 6,
+       CMD_SCAN            = 8,
+       CMD_STOP_SCAN       = 9,
+       CMD_VBM             = 10,
+       CMD_START_JOIN      = 11,
+       CMD_SET_KEYS        = 12,
+       CMD_READ_MEMORY     = 13,
+       CMD_WRITE_MEMORY    = 14,
+       CMD_BEACON          = 19,
+       CMD_PROBE_RESP      = 20,
+       CMD_NULL_DATA       = 21,
+       CMD_PROBE_REQ       = 22,
+       CMD_TEST            = 23,
+       CMD_RADIO_CALIBRATE     = 25,   /* OBSOLETE */
+       CMD_ENABLE_RX_PATH      = 27,   /* OBSOLETE */
+       CMD_NOISE_HIST      = 28,
+       CMD_RX_RESET        = 29,
+       CMD_PS_POLL         = 30,
+       CMD_QOS_NULL_DATA   = 31,
+       CMD_LNA_CONTROL     = 32,
+       CMD_SET_BCN_MODE    = 33,
+       CMD_MEASUREMENT      = 34,
+       CMD_STOP_MEASUREMENT = 35,
+       CMD_DISCONNECT       = 36,
+       CMD_SET_PS_MODE      = 37,
+       CMD_CHANNEL_SWITCH   = 38,
+       CMD_STOP_CHANNEL_SWICTH = 39,
+       CMD_AP_DISCOVERY     = 40,
+       CMD_STOP_AP_DISCOVERY = 41,
+       CMD_SPS_SCAN = 42,
+       CMD_STOP_SPS_SCAN = 43,
+       CMD_HEALTH_CHECK     = 45,
+       CMD_DEBUG            = 46,
+       CMD_TRIGGER_SCAN_TO  = 47,
+
+       NUM_COMMANDS,
+       MAX_COMMAND_ID = 0xFFFF,
+};
+
+#define MAX_CMD_PARAMS 572
+
+struct wl1251_cmd_header {
+       u16 id;
+       u16 status;
+       /* payload */
+       u8 data[0];
+} __packed;
+
+struct  wl1251_command {
+       struct wl1251_cmd_header header;
+       u8  parameters[MAX_CMD_PARAMS];
+} __packed;
+
+enum {
+       CMD_MAILBOX_IDLE                        =  0,
+       CMD_STATUS_SUCCESS                      =  1,
+       CMD_STATUS_UNKNOWN_CMD                  =  2,
+       CMD_STATUS_UNKNOWN_IE                   =  3,
+       CMD_STATUS_REJECT_MEAS_SG_ACTIVE        = 11,
+       CMD_STATUS_RX_BUSY                      = 13,
+       CMD_STATUS_INVALID_PARAM                = 14,
+       CMD_STATUS_TEMPLATE_TOO_LARGE           = 15,
+       CMD_STATUS_OUT_OF_MEMORY                = 16,
+       CMD_STATUS_STA_TABLE_FULL               = 17,
+       CMD_STATUS_RADIO_ERROR                  = 18,
+       CMD_STATUS_WRONG_NESTING                = 19,
+       CMD_STATUS_TIMEOUT                      = 21, /* Driver internal use.*/
+       CMD_STATUS_FW_RESET                     = 22, /* Driver internal use.*/
+       MAX_COMMAND_STATUS                      = 0xff
+};
+
+
+/*
+ * CMD_READ_MEMORY
+ *
+ * The host issues this command to read the WiLink device memory/registers.
+ *
+ * Note: The Base Band address has special handling (16 bits registers and
+ * addresses). For more information, see the hardware specification.
+ */
+/*
+ * CMD_WRITE_MEMORY
+ *
+ * The host issues this command to write the WiLink device memory/registers.
+ *
+ * The Base Band address has special handling (16 bits registers and
+ * addresses). For more information, see the hardware specification.
+ */
+#define MAX_READ_SIZE 256
+
+struct cmd_read_write_memory {
+       struct wl1251_cmd_header header;
+
+       /* The address of the memory to read from or write to.*/
+       u32 addr;
+
+       /* The amount of data in bytes to read from or write to the WiLink
+        * device.*/
+       u32 size;
+
+       /* The actual value read from or written to the Wilink. The source
+          of this field is the Host in WRITE command or the Wilink in READ
+          command. */
+       u8 value[MAX_READ_SIZE];
+} __packed;
+
+#define CMDMBOX_HEADER_LEN 4
+#define CMDMBOX_INFO_ELEM_HEADER_LEN 4
+
+#define WL1251_SCAN_MIN_DURATION 30000
+#define WL1251_SCAN_MAX_DURATION 60000
+
+#define WL1251_SCAN_NUM_PROBES 3
+
+struct wl1251_scan_parameters {
+       __le32 rx_config_options;
+       __le32 rx_filter_options;
+
+       /*
+        * Scan options:
+        * bit 0: When this bit is set, passive scan.
+        * bit 1: Band, when this bit is set we scan
+        * in the 5Ghz band.
+        * bit 2: voice mode, 0 for normal scan.
+        * bit 3: scan priority, 1 for high priority.
+        */
+       __le16 scan_options;
+
+       /* Number of channels to scan */
+       u8 num_channels;
+
+       /* Number opf probe requests to send, per channel */
+       u8 num_probe_requests;
+
+       /* Rate and modulation for probe requests */
+       __le16 tx_rate;
+
+       u8 tid_trigger;
+       u8 ssid_len;
+       u8 ssid[32];
+
+} __packed;
+
+struct wl1251_scan_ch_parameters {
+       __le32 min_duration; /* in TU */
+       __le32 max_duration; /* in TU */
+       u32 bssid_lsb;
+       u16 bssid_msb;
+
+       /*
+        * bits 0-3: Early termination count.
+        * bits 4-5: Early termination condition.
+        */
+       u8 early_termination;
+
+       u8 tx_power_att;
+       u8 channel;
+       u8 pad[3];
+} __packed;
+
+/* SCAN parameters */
+#define SCAN_MAX_NUM_OF_CHANNELS 16
+
+struct wl1251_cmd_scan {
+       struct wl1251_cmd_header header;
+
+       struct wl1251_scan_parameters params;
+       struct wl1251_scan_ch_parameters channels[SCAN_MAX_NUM_OF_CHANNELS];
+} __packed;
+
+enum {
+       BSS_TYPE_IBSS = 0,
+       BSS_TYPE_STA_BSS = 2,
+       BSS_TYPE_AP_BSS = 3,
+       MAX_BSS_TYPE = 0xFF
+};
+
+#define JOIN_CMD_CTRL_TX_FLUSH             0x80 /* Firmware flushes all Tx */
+#define JOIN_CMD_CTRL_EARLY_WAKEUP_ENABLE  0x01 /* Early wakeup time */
+
+
+struct cmd_join {
+       struct wl1251_cmd_header header;
+
+       u32 bssid_lsb;
+       u16 bssid_msb;
+       u16 beacon_interval; /* in TBTTs */
+       u32 rx_config_options;
+       u32 rx_filter_options;
+
+       /*
+        * The target uses this field to determine the rate at
+        * which to transmit control frame responses (such as
+        * ACK or CTS frames).
+        */
+       u16 basic_rate_set;
+       u8 dtim_interval;
+       u8 tx_ctrl_frame_rate; /* OBSOLETE */
+       u8 tx_ctrl_frame_mod;  /* OBSOLETE */
+       /*
+        * bits 0-2: This bitwise field specifies the type
+        * of BSS to start or join (BSS_TYPE_*).
+        * bit 4: Band - The radio band in which to join
+        * or start.
+        *  0 - 2.4GHz band
+        *  1 - 5GHz band
+        * bits 3, 5-7: Reserved
+        */
+       u8 bss_type;
+       u8 channel;
+       u8 ssid_len;
+       u8 ssid[IEEE80211_MAX_SSID_LEN];
+       u8 ctrl; /* JOIN_CMD_CTRL_* */
+       u8 tx_mgt_frame_rate; /* OBSOLETE */
+       u8 tx_mgt_frame_mod;  /* OBSOLETE */
+       u8 reserved;
+} __packed;
+
+struct cmd_enabledisable_path {
+       struct wl1251_cmd_header header;
+
+       u8 channel;
+       u8 padding[3];
+} __packed;
+
+#define WL1251_MAX_TEMPLATE_SIZE 300
+
+struct wl1251_cmd_packet_template {
+       struct wl1251_cmd_header header;
+
+       __le16 size;
+       u8 data[0];
+} __packed;
+
+#define TIM_ELE_ID    5
+#define PARTIAL_VBM_MAX    251
+
+struct wl1251_tim {
+       u8 identity;
+       u8 length;
+       u8 dtim_count;
+       u8 dtim_period;
+       u8 bitmap_ctrl;
+       u8 pvb_field[PARTIAL_VBM_MAX]; /* Partial Virtual Bitmap */
+} __packed;
+
+/* Virtual Bit Map update */
+struct wl1251_cmd_vbm_update {
+       struct wl1251_cmd_header header;
+       __le16 len;
+       u8  padding[2];
+       struct wl1251_tim tim;
+} __packed;
+
+enum wl1251_cmd_ps_mode {
+       CHIP_ACTIVE_MODE,
+       CHIP_POWER_SAVE_MODE
+};
+
+struct wl1251_cmd_ps_params {
+       struct wl1251_cmd_header header;
+
+       u8 ps_mode; /* STATION_* */
+       u8 send_null_data; /* Do we have to send NULL data packet ? */
+       u8 retries; /* Number of retires for the initial NULL data packet */
+
+        /*
+         * TUs during which the target stays awake after switching
+         * to power save mode.
+         */
+       u8 hang_over_period;
+       u16 null_data_rate;
+       u8 pad[2];
+} __packed;
+
+struct wl1251_cmd_trigger_scan_to {
+       struct wl1251_cmd_header header;
+
+       u32 timeout;
+} __packed;
+
+/* HW encryption keys */
+#define NUM_ACCESS_CATEGORIES_COPY 4
+#define MAX_KEY_SIZE 32
+
+/* When set, disable HW encryption */
+#define DF_ENCRYPTION_DISABLE      0x01
+/* When set, disable HW decryption */
+#define DF_SNIFF_MODE_ENABLE       0x80
+
+enum wl1251_cmd_key_action {
+       KEY_ADD_OR_REPLACE = 1,
+       KEY_REMOVE         = 2,
+       KEY_SET_ID         = 3,
+       MAX_KEY_ACTION     = 0xffff,
+};
+
+enum wl1251_cmd_key_type {
+       KEY_WEP_DEFAULT       = 0,
+       KEY_WEP_ADDR          = 1,
+       KEY_AES_GROUP         = 4,
+       KEY_AES_PAIRWISE      = 5,
+       KEY_WEP_GROUP         = 6,
+       KEY_TKIP_MIC_GROUP    = 10,
+       KEY_TKIP_MIC_PAIRWISE = 11,
+};
+
+/*
+ *
+ * key_type_e   key size    key format
+ * ----------   ---------   ----------
+ * 0x00         5, 13, 29   Key data
+ * 0x01         5, 13, 29   Key data
+ * 0x04         16          16 bytes of key data
+ * 0x05         16          16 bytes of key data
+ * 0x0a         32          16 bytes of TKIP key data
+ *                          8 bytes of RX MIC key data
+ *                          8 bytes of TX MIC key data
+ * 0x0b         32          16 bytes of TKIP key data
+ *                          8 bytes of RX MIC key data
+ *                          8 bytes of TX MIC key data
+ *
+ */
+
+struct wl1251_cmd_set_keys {
+       struct wl1251_cmd_header header;
+
+       /* Ignored for default WEP key */
+       u8 addr[ETH_ALEN];
+
+       /* key_action_e */
+       u16 key_action;
+
+       u16 reserved_1;
+
+       /* key size in bytes */
+       u8 key_size;
+
+       /* key_type_e */
+       u8 key_type;
+       u8 ssid_profile;
+
+       /*
+        * TKIP, AES: frame's key id field.
+        * For WEP default key: key id;
+        */
+       u8 id;
+       u8 reserved_2[6];
+       u8 key[MAX_KEY_SIZE];
+       u16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY];
+       u32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY];
+} __packed;
+
+
+#endif /* __WL1251_CMD_H__ */
diff --git a/drivers/net/wireless/ti/wl1251/debugfs.c b/drivers/net/wireless/ti/wl1251/debugfs.c
new file mode 100644 (file)
index 0000000..448da1f
--- /dev/null
@@ -0,0 +1,539 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "debugfs.h"
+
+#include <linux/skbuff.h>
+#include <linux/slab.h>
+
+#include "wl1251.h"
+#include "acx.h"
+#include "ps.h"
+
+/* ms */
+#define WL1251_DEBUGFS_STATS_LIFETIME 1000
+
+/* debugfs macros idea from mac80211 */
+
+#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...)             \
+static ssize_t name## _read(struct file *file, char __user *userbuf,   \
+                           size_t count, loff_t *ppos)                 \
+{                                                                      \
+       struct wl1251 *wl = file->private_data;                         \
+       char buf[buflen];                                               \
+       int res;                                                        \
+                                                                       \
+       res = scnprintf(buf, buflen, fmt "\n", ##value);                \
+       return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
+}                                                                      \
+                                                                       \
+static const struct file_operations name## _ops = {                    \
+       .read = name## _read,                                           \
+       .open = simple_open,                                            \
+       .llseek = generic_file_llseek,                                  \
+};
+
+#define DEBUGFS_ADD(name, parent)                                      \
+       wl->debugfs.name = debugfs_create_file(#name, 0400, parent,     \
+                                              wl, &name## _ops);       \
+       if (IS_ERR(wl->debugfs.name)) {                                 \
+               ret = PTR_ERR(wl->debugfs.name);                        \
+               wl->debugfs.name = NULL;                                \
+               goto out;                                               \
+       }
+
+#define DEBUGFS_DEL(name)                                              \
+       do {                                                            \
+               debugfs_remove(wl->debugfs.name);                       \
+               wl->debugfs.name = NULL;                                \
+       } while (0)
+
+#define DEBUGFS_FWSTATS_FILE(sub, name, buflen, fmt)                   \
+static ssize_t sub## _ ##name## _read(struct file *file,               \
+                                     char __user *userbuf,             \
+                                     size_t count, loff_t *ppos)       \
+{                                                                      \
+       struct wl1251 *wl = file->private_data;                         \
+       char buf[buflen];                                               \
+       int res;                                                        \
+                                                                       \
+       wl1251_debugfs_update_stats(wl);                                \
+                                                                       \
+       res = scnprintf(buf, buflen, fmt "\n",                          \
+                       wl->stats.fw_stats->sub.name);                  \
+       return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
+}                                                                      \
+                                                                       \
+static const struct file_operations sub## _ ##name## _ops = {          \
+       .read = sub## _ ##name## _read,                                 \
+       .open = simple_open,                                            \
+       .llseek = generic_file_llseek,                                  \
+};
+
+#define DEBUGFS_FWSTATS_ADD(sub, name)                         \
+       DEBUGFS_ADD(sub## _ ##name, wl->debugfs.fw_statistics)
+
+#define DEBUGFS_FWSTATS_DEL(sub, name)                         \
+       DEBUGFS_DEL(sub## _ ##name)
+
+static void wl1251_debugfs_update_stats(struct wl1251 *wl)
+{
+       int ret;
+
+       mutex_lock(&wl->mutex);
+
+       ret = wl1251_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       if (wl->state == WL1251_STATE_ON &&
+           time_after(jiffies, wl->stats.fw_stats_update +
+                      msecs_to_jiffies(WL1251_DEBUGFS_STATS_LIFETIME))) {
+               wl1251_acx_statistics(wl, wl->stats.fw_stats);
+               wl->stats.fw_stats_update = jiffies;
+       }
+
+       wl1251_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, 20, "%u");
+
+DEBUGFS_FWSTATS_FILE(rx, out_of_mem, 20, "%u");
+DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, 20, "%u");
+DEBUGFS_FWSTATS_FILE(rx, hw_stuck, 20, "%u");
+DEBUGFS_FWSTATS_FILE(rx, dropped, 20, "%u");
+DEBUGFS_FWSTATS_FILE(rx, fcs_err, 20, "%u");
+DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, 20, "%u");
+DEBUGFS_FWSTATS_FILE(rx, path_reset, 20, "%u");
+DEBUGFS_FWSTATS_FILE(rx, reset_counter, 20, "%u");
+
+DEBUGFS_FWSTATS_FILE(dma, rx_requested, 20, "%u");
+DEBUGFS_FWSTATS_FILE(dma, rx_errors, 20, "%u");
+DEBUGFS_FWSTATS_FILE(dma, tx_requested, 20, "%u");
+DEBUGFS_FWSTATS_FILE(dma, tx_errors, 20, "%u");
+
+DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, fiqs, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, rx_headers, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, rx_rdys, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, irqs, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, tx_procs, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, decrypt_done, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, dma0_done, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, dma1_done, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, commands, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, rx_procs, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, pci_pm, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, wakeups, 20, "%u");
+DEBUGFS_FWSTATS_FILE(isr, low_rssi, 20, "%u");
+
+DEBUGFS_FWSTATS_FILE(wep, addr_key_count, 20, "%u");
+DEBUGFS_FWSTATS_FILE(wep, default_key_count, 20, "%u");
+/* skipping wep.reserved */
+DEBUGFS_FWSTATS_FILE(wep, key_not_found, 20, "%u");
+DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, 20, "%u");
+DEBUGFS_FWSTATS_FILE(wep, packets, 20, "%u");
+DEBUGFS_FWSTATS_FILE(wep, interrupt, 20, "%u");
+
+DEBUGFS_FWSTATS_FILE(pwr, ps_enter, 20, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, elp_enter, 20, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, 20, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, 20, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, 20, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, 20, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, 20, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, 20, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, power_save_off, 20, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, enable_ps, 20, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, disable_ps, 20, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, 20, "%u");
+/* skipping cont_miss_bcns_spread for now */
+DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, 20, "%u");
+
+DEBUGFS_FWSTATS_FILE(mic, rx_pkts, 20, "%u");
+DEBUGFS_FWSTATS_FILE(mic, calc_failure, 20, "%u");
+
+DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, 20, "%u");
+DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, 20, "%u");
+DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, 20, "%u");
+DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, 20, "%u");
+DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, 20, "%u");
+DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, 20, "%u");
+
+DEBUGFS_FWSTATS_FILE(event, heart_beat, 20, "%u");
+DEBUGFS_FWSTATS_FILE(event, calibration, 20, "%u");
+DEBUGFS_FWSTATS_FILE(event, rx_mismatch, 20, "%u");
+DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, 20, "%u");
+DEBUGFS_FWSTATS_FILE(event, rx_pool, 20, "%u");
+DEBUGFS_FWSTATS_FILE(event, oom_late, 20, "%u");
+DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, 20, "%u");
+DEBUGFS_FWSTATS_FILE(event, tx_stuck, 20, "%u");
+
+DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, 20, "%u");
+DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, 20, "%u");
+DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, 20, "%u");
+DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, 20, "%u");
+DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, 20, "%u");
+DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, 20, "%u");
+DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, 20, "%u");
+
+DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, 20, "%u");
+DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, 20, "%u");
+DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data,
+                    20, "%u");
+DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, 20, "%u");
+DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, 20, "%u");
+
+DEBUGFS_READONLY_FILE(retry_count, 20, "%u", wl->stats.retry_count);
+DEBUGFS_READONLY_FILE(excessive_retries, 20, "%u",
+                     wl->stats.excessive_retries);
+
+static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
+                                size_t count, loff_t *ppos)
+{
+       struct wl1251 *wl = file->private_data;
+       u32 queue_len;
+       char buf[20];
+       int res;
+
+       queue_len = skb_queue_len(&wl->tx_queue);
+
+       res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
+       return simple_read_from_buffer(userbuf, count, ppos, buf, res);
+}
+
+static const struct file_operations tx_queue_len_ops = {
+       .read = tx_queue_len_read,
+       .open = simple_open,
+       .llseek = generic_file_llseek,
+};
+
+static ssize_t tx_queue_status_read(struct file *file, char __user *userbuf,
+                                   size_t count, loff_t *ppos)
+{
+       struct wl1251 *wl = file->private_data;
+       char buf[3], status;
+       int len;
+
+       if (wl->tx_queue_stopped)
+               status = 's';
+       else
+               status = 'r';
+
+       len = scnprintf(buf, sizeof(buf), "%c\n", status);
+       return simple_read_from_buffer(userbuf, count, ppos, buf, len);
+}
+
+static const struct file_operations tx_queue_status_ops = {
+       .read = tx_queue_status_read,
+       .open = simple_open,
+       .llseek = generic_file_llseek,
+};
+
+static void wl1251_debugfs_delete_files(struct wl1251 *wl)
+{
+       DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow);
+
+       DEBUGFS_FWSTATS_DEL(rx, out_of_mem);
+       DEBUGFS_FWSTATS_DEL(rx, hdr_overflow);
+       DEBUGFS_FWSTATS_DEL(rx, hw_stuck);
+       DEBUGFS_FWSTATS_DEL(rx, dropped);
+       DEBUGFS_FWSTATS_DEL(rx, fcs_err);
+       DEBUGFS_FWSTATS_DEL(rx, xfr_hint_trig);
+       DEBUGFS_FWSTATS_DEL(rx, path_reset);
+       DEBUGFS_FWSTATS_DEL(rx, reset_counter);
+
+       DEBUGFS_FWSTATS_DEL(dma, rx_requested);
+       DEBUGFS_FWSTATS_DEL(dma, rx_errors);
+       DEBUGFS_FWSTATS_DEL(dma, tx_requested);
+       DEBUGFS_FWSTATS_DEL(dma, tx_errors);
+
+       DEBUGFS_FWSTATS_DEL(isr, cmd_cmplt);
+       DEBUGFS_FWSTATS_DEL(isr, fiqs);
+       DEBUGFS_FWSTATS_DEL(isr, rx_headers);
+       DEBUGFS_FWSTATS_DEL(isr, rx_mem_overflow);
+       DEBUGFS_FWSTATS_DEL(isr, rx_rdys);
+       DEBUGFS_FWSTATS_DEL(isr, irqs);
+       DEBUGFS_FWSTATS_DEL(isr, tx_procs);
+       DEBUGFS_FWSTATS_DEL(isr, decrypt_done);
+       DEBUGFS_FWSTATS_DEL(isr, dma0_done);
+       DEBUGFS_FWSTATS_DEL(isr, dma1_done);
+       DEBUGFS_FWSTATS_DEL(isr, tx_exch_complete);
+       DEBUGFS_FWSTATS_DEL(isr, commands);
+       DEBUGFS_FWSTATS_DEL(isr, rx_procs);
+       DEBUGFS_FWSTATS_DEL(isr, hw_pm_mode_changes);
+       DEBUGFS_FWSTATS_DEL(isr, host_acknowledges);
+       DEBUGFS_FWSTATS_DEL(isr, pci_pm);
+       DEBUGFS_FWSTATS_DEL(isr, wakeups);
+       DEBUGFS_FWSTATS_DEL(isr, low_rssi);
+
+       DEBUGFS_FWSTATS_DEL(wep, addr_key_count);
+       DEBUGFS_FWSTATS_DEL(wep, default_key_count);
+       /* skipping wep.reserved */
+       DEBUGFS_FWSTATS_DEL(wep, key_not_found);
+       DEBUGFS_FWSTATS_DEL(wep, decrypt_fail);
+       DEBUGFS_FWSTATS_DEL(wep, packets);
+       DEBUGFS_FWSTATS_DEL(wep, interrupt);
+
+       DEBUGFS_FWSTATS_DEL(pwr, ps_enter);
+       DEBUGFS_FWSTATS_DEL(pwr, elp_enter);
+       DEBUGFS_FWSTATS_DEL(pwr, missing_bcns);
+       DEBUGFS_FWSTATS_DEL(pwr, wake_on_host);
+       DEBUGFS_FWSTATS_DEL(pwr, wake_on_timer_exp);
+       DEBUGFS_FWSTATS_DEL(pwr, tx_with_ps);
+       DEBUGFS_FWSTATS_DEL(pwr, tx_without_ps);
+       DEBUGFS_FWSTATS_DEL(pwr, rcvd_beacons);
+       DEBUGFS_FWSTATS_DEL(pwr, power_save_off);
+       DEBUGFS_FWSTATS_DEL(pwr, enable_ps);
+       DEBUGFS_FWSTATS_DEL(pwr, disable_ps);
+       DEBUGFS_FWSTATS_DEL(pwr, fix_tsf_ps);
+       /* skipping cont_miss_bcns_spread for now */
+       DEBUGFS_FWSTATS_DEL(pwr, rcvd_awake_beacons);
+
+       DEBUGFS_FWSTATS_DEL(mic, rx_pkts);
+       DEBUGFS_FWSTATS_DEL(mic, calc_failure);
+
+       DEBUGFS_FWSTATS_DEL(aes, encrypt_fail);
+       DEBUGFS_FWSTATS_DEL(aes, decrypt_fail);
+       DEBUGFS_FWSTATS_DEL(aes, encrypt_packets);
+       DEBUGFS_FWSTATS_DEL(aes, decrypt_packets);
+       DEBUGFS_FWSTATS_DEL(aes, encrypt_interrupt);
+       DEBUGFS_FWSTATS_DEL(aes, decrypt_interrupt);
+
+       DEBUGFS_FWSTATS_DEL(event, heart_beat);
+       DEBUGFS_FWSTATS_DEL(event, calibration);
+       DEBUGFS_FWSTATS_DEL(event, rx_mismatch);
+       DEBUGFS_FWSTATS_DEL(event, rx_mem_empty);
+       DEBUGFS_FWSTATS_DEL(event, rx_pool);
+       DEBUGFS_FWSTATS_DEL(event, oom_late);
+       DEBUGFS_FWSTATS_DEL(event, phy_transmit_error);
+       DEBUGFS_FWSTATS_DEL(event, tx_stuck);
+
+       DEBUGFS_FWSTATS_DEL(ps, pspoll_timeouts);
+       DEBUGFS_FWSTATS_DEL(ps, upsd_timeouts);
+       DEBUGFS_FWSTATS_DEL(ps, upsd_max_sptime);
+       DEBUGFS_FWSTATS_DEL(ps, upsd_max_apturn);
+       DEBUGFS_FWSTATS_DEL(ps, pspoll_max_apturn);
+       DEBUGFS_FWSTATS_DEL(ps, pspoll_utilization);
+       DEBUGFS_FWSTATS_DEL(ps, upsd_utilization);
+
+       DEBUGFS_FWSTATS_DEL(rxpipe, rx_prep_beacon_drop);
+       DEBUGFS_FWSTATS_DEL(rxpipe, descr_host_int_trig_rx_data);
+       DEBUGFS_FWSTATS_DEL(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
+       DEBUGFS_FWSTATS_DEL(rxpipe, missed_beacon_host_int_trig_rx_data);
+       DEBUGFS_FWSTATS_DEL(rxpipe, tx_xfr_host_int_trig_rx_data);
+
+       DEBUGFS_DEL(tx_queue_len);
+       DEBUGFS_DEL(tx_queue_status);
+       DEBUGFS_DEL(retry_count);
+       DEBUGFS_DEL(excessive_retries);
+}
+
+static int wl1251_debugfs_add_files(struct wl1251 *wl)
+{
+       int ret = 0;
+
+       DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
+
+       DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
+       DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
+       DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
+       DEBUGFS_FWSTATS_ADD(rx, dropped);
+       DEBUGFS_FWSTATS_ADD(rx, fcs_err);
+       DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
+       DEBUGFS_FWSTATS_ADD(rx, path_reset);
+       DEBUGFS_FWSTATS_ADD(rx, reset_counter);
+
+       DEBUGFS_FWSTATS_ADD(dma, rx_requested);
+       DEBUGFS_FWSTATS_ADD(dma, rx_errors);
+       DEBUGFS_FWSTATS_ADD(dma, tx_requested);
+       DEBUGFS_FWSTATS_ADD(dma, tx_errors);
+
+       DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
+       DEBUGFS_FWSTATS_ADD(isr, fiqs);
+       DEBUGFS_FWSTATS_ADD(isr, rx_headers);
+       DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
+       DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
+       DEBUGFS_FWSTATS_ADD(isr, irqs);
+       DEBUGFS_FWSTATS_ADD(isr, tx_procs);
+       DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
+       DEBUGFS_FWSTATS_ADD(isr, dma0_done);
+       DEBUGFS_FWSTATS_ADD(isr, dma1_done);
+       DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
+       DEBUGFS_FWSTATS_ADD(isr, commands);
+       DEBUGFS_FWSTATS_ADD(isr, rx_procs);
+       DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
+       DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
+       DEBUGFS_FWSTATS_ADD(isr, pci_pm);
+       DEBUGFS_FWSTATS_ADD(isr, wakeups);
+       DEBUGFS_FWSTATS_ADD(isr, low_rssi);
+
+       DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
+       DEBUGFS_FWSTATS_ADD(wep, default_key_count);
+       /* skipping wep.reserved */
+       DEBUGFS_FWSTATS_ADD(wep, key_not_found);
+       DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
+       DEBUGFS_FWSTATS_ADD(wep, packets);
+       DEBUGFS_FWSTATS_ADD(wep, interrupt);
+
+       DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
+       DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
+       DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
+       DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
+       DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
+       DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
+       DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
+       DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
+       DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
+       DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
+       DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
+       DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
+       /* skipping cont_miss_bcns_spread for now */
+       DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
+
+       DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
+       DEBUGFS_FWSTATS_ADD(mic, calc_failure);
+
+       DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
+       DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
+       DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
+       DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
+       DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
+       DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
+
+       DEBUGFS_FWSTATS_ADD(event, heart_beat);
+       DEBUGFS_FWSTATS_ADD(event, calibration);
+       DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
+       DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
+       DEBUGFS_FWSTATS_ADD(event, rx_pool);
+       DEBUGFS_FWSTATS_ADD(event, oom_late);
+       DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
+       DEBUGFS_FWSTATS_ADD(event, tx_stuck);
+
+       DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
+       DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
+       DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
+       DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
+       DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
+       DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
+       DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
+
+       DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
+       DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
+       DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
+       DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
+       DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
+
+       DEBUGFS_ADD(tx_queue_len, wl->debugfs.rootdir);
+       DEBUGFS_ADD(tx_queue_status, wl->debugfs.rootdir);
+       DEBUGFS_ADD(retry_count, wl->debugfs.rootdir);
+       DEBUGFS_ADD(excessive_retries, wl->debugfs.rootdir);
+
+out:
+       if (ret < 0)
+               wl1251_debugfs_delete_files(wl);
+
+       return ret;
+}
+
+void wl1251_debugfs_reset(struct wl1251 *wl)
+{
+       if (wl->stats.fw_stats != NULL)
+               memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
+       wl->stats.retry_count = 0;
+       wl->stats.excessive_retries = 0;
+}
+
+int wl1251_debugfs_init(struct wl1251 *wl)
+{
+       int ret;
+
+       wl->debugfs.rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
+
+       if (IS_ERR(wl->debugfs.rootdir)) {
+               ret = PTR_ERR(wl->debugfs.rootdir);
+               wl->debugfs.rootdir = NULL;
+               goto err;
+       }
+
+       wl->debugfs.fw_statistics = debugfs_create_dir("fw-statistics",
+                                                      wl->debugfs.rootdir);
+
+       if (IS_ERR(wl->debugfs.fw_statistics)) {
+               ret = PTR_ERR(wl->debugfs.fw_statistics);
+               wl->debugfs.fw_statistics = NULL;
+               goto err_root;
+       }
+
+       wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
+                                     GFP_KERNEL);
+
+       if (!wl->stats.fw_stats) {
+               ret = -ENOMEM;
+               goto err_fw;
+       }
+
+       wl->stats.fw_stats_update = jiffies;
+
+       ret = wl1251_debugfs_add_files(wl);
+
+       if (ret < 0)
+               goto err_file;
+
+       return 0;
+
+err_file:
+       kfree(wl->stats.fw_stats);
+       wl->stats.fw_stats = NULL;
+
+err_fw:
+       debugfs_remove(wl->debugfs.fw_statistics);
+       wl->debugfs.fw_statistics = NULL;
+
+err_root:
+       debugfs_remove(wl->debugfs.rootdir);
+       wl->debugfs.rootdir = NULL;
+
+err:
+       return ret;
+}
+
+void wl1251_debugfs_exit(struct wl1251 *wl)
+{
+       wl1251_debugfs_delete_files(wl);
+
+       kfree(wl->stats.fw_stats);
+       wl->stats.fw_stats = NULL;
+
+       debugfs_remove(wl->debugfs.fw_statistics);
+       wl->debugfs.fw_statistics = NULL;
+
+       debugfs_remove(wl->debugfs.rootdir);
+       wl->debugfs.rootdir = NULL;
+
+}
diff --git a/drivers/net/wireless/ti/wl1251/debugfs.h b/drivers/net/wireless/ti/wl1251/debugfs.h
new file mode 100644 (file)
index 0000000..b3417c0
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef WL1251_DEBUGFS_H
+#define WL1251_DEBUGFS_H
+
+#include "wl1251.h"
+
+int wl1251_debugfs_init(struct wl1251 *wl);
+void wl1251_debugfs_exit(struct wl1251 *wl);
+void wl1251_debugfs_reset(struct wl1251 *wl);
+
+#endif /* WL1251_DEBUGFS_H */
diff --git a/drivers/net/wireless/ti/wl1251/event.c b/drivers/net/wireless/ti/wl1251/event.c
new file mode 100644 (file)
index 0000000..9f15cca
--- /dev/null
@@ -0,0 +1,188 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (c) 1998-2007 Texas Instruments Incorporated
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "wl1251.h"
+#include "reg.h"
+#include "io.h"
+#include "event.h"
+#include "ps.h"
+
+static int wl1251_event_scan_complete(struct wl1251 *wl,
+                                     struct event_mailbox *mbox)
+{
+       wl1251_debug(DEBUG_EVENT, "status: 0x%x, channels: %d",
+                    mbox->scheduled_scan_status,
+                    mbox->scheduled_scan_channels);
+
+       if (wl->scanning) {
+               ieee80211_scan_completed(wl->hw, false);
+               wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan completed");
+               wl->scanning = false;
+       }
+
+       return 0;
+}
+
+static void wl1251_event_mbox_dump(struct event_mailbox *mbox)
+{
+       wl1251_debug(DEBUG_EVENT, "MBOX DUMP:");
+       wl1251_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
+       wl1251_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
+}
+
+static int wl1251_event_process(struct wl1251 *wl, struct event_mailbox *mbox)
+{
+       int ret;
+       u32 vector;
+
+       wl1251_event_mbox_dump(mbox);
+
+       vector = mbox->events_vector & ~(mbox->events_mask);
+       wl1251_debug(DEBUG_EVENT, "vector: 0x%x", vector);
+
+       if (vector & SCAN_COMPLETE_EVENT_ID) {
+               ret = wl1251_event_scan_complete(wl, mbox);
+               if (ret < 0)
+                       return ret;
+       }
+
+       if (vector & BSS_LOSE_EVENT_ID) {
+               wl1251_debug(DEBUG_EVENT, "BSS_LOSE_EVENT");
+
+               if (wl->psm_requested &&
+                   wl->station_mode != STATION_ACTIVE_MODE) {
+                       ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
+                       if (ret < 0)
+                               return ret;
+               }
+       }
+
+       if (vector & SYNCHRONIZATION_TIMEOUT_EVENT_ID &&
+           wl->station_mode != STATION_ACTIVE_MODE) {
+               wl1251_debug(DEBUG_EVENT, "SYNCHRONIZATION_TIMEOUT_EVENT");
+
+               /* indicate to the stack, that beacons have been lost */
+               ieee80211_beacon_loss(wl->vif);
+       }
+
+       if (vector & REGAINED_BSS_EVENT_ID) {
+               if (wl->psm_requested) {
+                       ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
+                       if (ret < 0)
+                               return ret;
+               }
+       }
+
+       if (wl->vif && wl->rssi_thold) {
+               if (vector & ROAMING_TRIGGER_LOW_RSSI_EVENT_ID) {
+                       wl1251_debug(DEBUG_EVENT,
+                                    "ROAMING_TRIGGER_LOW_RSSI_EVENT");
+                       ieee80211_cqm_rssi_notify(wl->vif,
+                               NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
+                               GFP_KERNEL);
+               }
+
+               if (vector & ROAMING_TRIGGER_REGAINED_RSSI_EVENT_ID) {
+                       wl1251_debug(DEBUG_EVENT,
+                                    "ROAMING_TRIGGER_REGAINED_RSSI_EVENT");
+                       ieee80211_cqm_rssi_notify(wl->vif,
+                               NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
+                               GFP_KERNEL);
+               }
+       }
+
+       return 0;
+}
+
+/*
+ * Poll the mailbox event field until any of the bits in the mask is set or a
+ * timeout occurs (WL1251_EVENT_TIMEOUT in msecs)
+ */
+int wl1251_event_wait(struct wl1251 *wl, u32 mask, int timeout_ms)
+{
+       u32 events_vector, event;
+       unsigned long timeout;
+
+       timeout = jiffies + msecs_to_jiffies(timeout_ms);
+
+       do {
+               if (time_after(jiffies, timeout))
+                       return -ETIMEDOUT;
+
+               msleep(1);
+
+               /* read from both event fields */
+               wl1251_mem_read(wl, wl->mbox_ptr[0], &events_vector,
+                               sizeof(events_vector));
+               event = events_vector & mask;
+               wl1251_mem_read(wl, wl->mbox_ptr[1], &events_vector,
+                               sizeof(events_vector));
+               event |= events_vector & mask;
+       } while (!event);
+
+       return 0;
+}
+
+int wl1251_event_unmask(struct wl1251 *wl)
+{
+       int ret;
+
+       ret = wl1251_acx_event_mbox_mask(wl, ~(wl->event_mask));
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+void wl1251_event_mbox_config(struct wl1251 *wl)
+{
+       wl->mbox_ptr[0] = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
+       wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
+
+       wl1251_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
+                    wl->mbox_ptr[0], wl->mbox_ptr[1]);
+}
+
+int wl1251_event_handle(struct wl1251 *wl, u8 mbox_num)
+{
+       struct event_mailbox mbox;
+       int ret;
+
+       wl1251_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
+
+       if (mbox_num > 1)
+               return -EINVAL;
+
+       /* first we read the mbox descriptor */
+       wl1251_mem_read(wl, wl->mbox_ptr[mbox_num], &mbox,
+                           sizeof(struct event_mailbox));
+
+       /* process the descriptor */
+       ret = wl1251_event_process(wl, &mbox);
+       if (ret < 0)
+               return ret;
+
+       /* then we let the firmware know it can go on...*/
+       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
+
+       return 0;
+}
diff --git a/drivers/net/wireless/ti/wl1251/event.h b/drivers/net/wireless/ti/wl1251/event.h
new file mode 100644 (file)
index 0000000..30eb5d1
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (c) 1998-2007 Texas Instruments Incorporated
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL1251_EVENT_H__
+#define __WL1251_EVENT_H__
+
+/*
+ * Mbox events
+ *
+ * The event mechanism is based on a pair of event buffers (buffers A and
+ * B) at fixed locations in the target's memory. The host processes one
+ * buffer while the other buffer continues to collect events. If the host
+ * is not processing events, an interrupt is issued to signal that a buffer
+ * is ready. Once the host is done with processing events from one buffer,
+ * it signals the target (with an ACK interrupt) that the event buffer is
+ * free.
+ */
+
+enum {
+       RESERVED1_EVENT_ID                       = BIT(0),
+       RESERVED2_EVENT_ID                       = BIT(1),
+       MEASUREMENT_START_EVENT_ID               = BIT(2),
+       SCAN_COMPLETE_EVENT_ID                   = BIT(3),
+       CALIBRATION_COMPLETE_EVENT_ID            = BIT(4),
+       ROAMING_TRIGGER_LOW_RSSI_EVENT_ID        = BIT(5),
+       PS_REPORT_EVENT_ID                       = BIT(6),
+       SYNCHRONIZATION_TIMEOUT_EVENT_ID         = BIT(7),
+       HEALTH_REPORT_EVENT_ID                   = BIT(8),
+       ACI_DETECTION_EVENT_ID                   = BIT(9),
+       DEBUG_REPORT_EVENT_ID                    = BIT(10),
+       MAC_STATUS_EVENT_ID                      = BIT(11),
+       DISCONNECT_EVENT_COMPLETE_ID             = BIT(12),
+       JOIN_EVENT_COMPLETE_ID                   = BIT(13),
+       CHANNEL_SWITCH_COMPLETE_EVENT_ID         = BIT(14),
+       BSS_LOSE_EVENT_ID                        = BIT(15),
+       ROAMING_TRIGGER_MAX_TX_RETRY_EVENT_ID    = BIT(16),
+       MEASUREMENT_COMPLETE_EVENT_ID            = BIT(17),
+       AP_DISCOVERY_COMPLETE_EVENT_ID           = BIT(18),
+       SCHEDULED_SCAN_COMPLETE_EVENT_ID         = BIT(19),
+       PSPOLL_DELIVERY_FAILURE_EVENT_ID         = BIT(20),
+       RESET_BSS_EVENT_ID                       = BIT(21),
+       REGAINED_BSS_EVENT_ID                    = BIT(22),
+       ROAMING_TRIGGER_REGAINED_RSSI_EVENT_ID   = BIT(23),
+       ROAMING_TRIGGER_LOW_SNR_EVENT_ID         = BIT(24),
+       ROAMING_TRIGGER_REGAINED_SNR_EVENT_ID    = BIT(25),
+
+       DBG_EVENT_ID                             = BIT(26),
+       BT_PTA_SENSE_EVENT_ID                    = BIT(27),
+       BT_PTA_PREDICTION_EVENT_ID               = BIT(28),
+       BT_PTA_AVALANCHE_EVENT_ID                = BIT(29),
+
+       PLT_RX_CALIBRATION_COMPLETE_EVENT_ID     = BIT(30),
+
+       EVENT_MBOX_ALL_EVENT_ID                  = 0x7fffffff,
+};
+
+struct event_debug_report {
+       u8 debug_event_id;
+       u8 num_params;
+       u16 pad;
+       u32 report_1;
+       u32 report_2;
+       u32 report_3;
+} __packed;
+
+struct event_mailbox {
+       u32 events_vector;
+       u32 events_mask;
+       u32 reserved_1;
+       u32 reserved_2;
+
+       char average_rssi_level;
+       u8 ps_status;
+       u8 channel_switch_status;
+       u8 scheduled_scan_status;
+
+       /* Channels scanned by the scheduled scan */
+       u16 scheduled_scan_channels;
+
+       /* If bit 0 is set -> target's fatal error */
+       u16 health_report;
+       u16 bad_fft_counter;
+       u8 bt_pta_sense_info;
+       u8 bt_pta_protective_info;
+       u32 reserved;
+       u32 debug_report[2];
+
+       /* Number of FCS errors since last event */
+       u32 fcs_err_counter;
+
+       struct event_debug_report report;
+       u8 average_snr_level;
+       u8 padding[19];
+} __packed;
+
+int wl1251_event_unmask(struct wl1251 *wl);
+void wl1251_event_mbox_config(struct wl1251 *wl);
+int wl1251_event_handle(struct wl1251 *wl, u8 mbox);
+int wl1251_event_wait(struct wl1251 *wl, u32 mask, int timeout_ms);
+
+#endif
diff --git a/drivers/net/wireless/ti/wl1251/init.c b/drivers/net/wireless/ti/wl1251/init.c
new file mode 100644 (file)
index 0000000..89b43d3
--- /dev/null
@@ -0,0 +1,423 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+
+#include "init.h"
+#include "wl12xx_80211.h"
+#include "acx.h"
+#include "cmd.h"
+#include "reg.h"
+
+int wl1251_hw_init_hwenc_config(struct wl1251 *wl)
+{
+       int ret;
+
+       ret = wl1251_acx_feature_cfg(wl);
+       if (ret < 0) {
+               wl1251_warning("couldn't set feature config");
+               return ret;
+       }
+
+       ret = wl1251_acx_default_key(wl, wl->default_key);
+       if (ret < 0) {
+               wl1251_warning("couldn't set default key");
+               return ret;
+       }
+
+       return 0;
+}
+
+int wl1251_hw_init_templates_config(struct wl1251 *wl)
+{
+       int ret;
+       u8 partial_vbm[PARTIAL_VBM_MAX];
+
+       /* send empty templates for fw memory reservation */
+       ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, NULL,
+                                     sizeof(struct wl12xx_probe_req_template));
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA, NULL,
+                                     sizeof(struct wl12xx_null_data_template));
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_cmd_template_set(wl, CMD_PS_POLL, NULL,
+                                     sizeof(struct wl12xx_ps_poll_template));
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, NULL,
+                                     sizeof
+                                     (struct wl12xx_qos_null_data_template));
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, NULL,
+                                     sizeof
+                                     (struct wl12xx_probe_resp_template));
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_cmd_template_set(wl, CMD_BEACON, NULL,
+                                     sizeof
+                                     (struct wl12xx_beacon_template));
+       if (ret < 0)
+               return ret;
+
+       /* tim templates, first reserve space then allocate an empty one */
+       memset(partial_vbm, 0, PARTIAL_VBM_MAX);
+       ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, PARTIAL_VBM_MAX, 0);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, 1, 0);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter)
+{
+       int ret;
+
+       ret = wl1251_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_acx_rx_config(wl, config, filter);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1251_hw_init_phy_config(struct wl1251 *wl)
+{
+       int ret;
+
+       ret = wl1251_acx_pd_threshold(wl);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_acx_slot(wl, DEFAULT_SLOT_TIME);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_acx_group_address_tbl(wl);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_acx_service_period_timeout(wl);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1251_hw_init_beacon_filter(struct wl1251 *wl)
+{
+       int ret;
+
+       /* disable beacon filtering at this stage */
+       ret = wl1251_acx_beacon_filter_opt(wl, false);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_acx_beacon_filter_table(wl);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1251_hw_init_pta(struct wl1251 *wl)
+{
+       int ret;
+
+       ret = wl1251_acx_sg_enable(wl);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_acx_sg_cfg(wl);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1251_hw_init_energy_detection(struct wl1251 *wl)
+{
+       int ret;
+
+       ret = wl1251_acx_cca_threshold(wl);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl)
+{
+       int ret;
+
+       ret = wl1251_acx_bcn_dtim_options(wl);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1251_hw_init_power_auth(struct wl1251 *wl)
+{
+       return wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
+}
+
+int wl1251_hw_init_mem_config(struct wl1251 *wl)
+{
+       int ret;
+
+       ret = wl1251_acx_mem_cfg(wl);
+       if (ret < 0)
+               return ret;
+
+       wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map),
+                                         GFP_KERNEL);
+       if (!wl->target_mem_map) {
+               wl1251_error("couldn't allocate target memory map");
+               return -ENOMEM;
+       }
+
+       /* we now ask for the firmware built memory map */
+       ret = wl1251_acx_mem_map(wl, wl->target_mem_map,
+                                sizeof(struct wl1251_acx_mem_map));
+       if (ret < 0) {
+               wl1251_error("couldn't retrieve firmware memory map");
+               kfree(wl->target_mem_map);
+               wl->target_mem_map = NULL;
+               return ret;
+       }
+
+       return 0;
+}
+
+static int wl1251_hw_init_txq_fill(u8 qid,
+                                  struct acx_tx_queue_qos_config *config,
+                                  u32 num_blocks)
+{
+       config->qid = qid;
+
+       switch (qid) {
+       case QOS_AC_BE:
+               config->high_threshold =
+                       (QOS_TX_HIGH_BE_DEF * num_blocks) / 100;
+               config->low_threshold =
+                       (QOS_TX_LOW_BE_DEF * num_blocks) / 100;
+               break;
+       case QOS_AC_BK:
+               config->high_threshold =
+                       (QOS_TX_HIGH_BK_DEF * num_blocks) / 100;
+               config->low_threshold =
+                       (QOS_TX_LOW_BK_DEF * num_blocks) / 100;
+               break;
+       case QOS_AC_VI:
+               config->high_threshold =
+                       (QOS_TX_HIGH_VI_DEF * num_blocks) / 100;
+               config->low_threshold =
+                       (QOS_TX_LOW_VI_DEF * num_blocks) / 100;
+               break;
+       case QOS_AC_VO:
+               config->high_threshold =
+                       (QOS_TX_HIGH_VO_DEF * num_blocks) / 100;
+               config->low_threshold =
+                       (QOS_TX_LOW_VO_DEF * num_blocks) / 100;
+               break;
+       default:
+               wl1251_error("Invalid TX queue id: %d", qid);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int wl1251_hw_init_tx_queue_config(struct wl1251 *wl)
+{
+       struct acx_tx_queue_qos_config *config;
+       struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map;
+       int ret, i;
+
+       wl1251_debug(DEBUG_ACX, "acx tx queue config");
+
+       config = kzalloc(sizeof(*config), GFP_KERNEL);
+       if (!config) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       for (i = 0; i < MAX_NUM_OF_AC; i++) {
+               ret = wl1251_hw_init_txq_fill(i, config,
+                                             wl_mem_map->num_tx_mem_blocks);
+               if (ret < 0)
+                       goto out;
+
+               ret = wl1251_cmd_configure(wl, ACX_TX_QUEUE_CFG,
+                                          config, sizeof(*config));
+               if (ret < 0)
+                       goto out;
+       }
+
+       wl1251_acx_ac_cfg(wl, AC_BE, CWMIN_BE, CWMAX_BE, AIFS_DIFS, TXOP_BE);
+       wl1251_acx_ac_cfg(wl, AC_BK, CWMIN_BK, CWMAX_BK, AIFS_DIFS, TXOP_BK);
+       wl1251_acx_ac_cfg(wl, AC_VI, CWMIN_VI, CWMAX_VI, AIFS_DIFS, TXOP_VI);
+       wl1251_acx_ac_cfg(wl, AC_VO, CWMIN_VO, CWMAX_VO, AIFS_DIFS, TXOP_VO);
+
+out:
+       kfree(config);
+       return ret;
+}
+
+static int wl1251_hw_init_data_path_config(struct wl1251 *wl)
+{
+       int ret;
+
+       /* asking for the data path parameters */
+       wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
+                               GFP_KERNEL);
+       if (!wl->data_path) {
+               wl1251_error("Couldnt allocate data path parameters");
+               return -ENOMEM;
+       }
+
+       ret = wl1251_acx_data_path_params(wl, wl->data_path);
+       if (ret < 0) {
+               kfree(wl->data_path);
+               wl->data_path = NULL;
+               return ret;
+       }
+
+       return 0;
+}
+
+
+int wl1251_hw_init(struct wl1251 *wl)
+{
+       struct wl1251_acx_mem_map *wl_mem_map;
+       int ret;
+
+       ret = wl1251_hw_init_hwenc_config(wl);
+       if (ret < 0)
+               return ret;
+
+       /* Template settings */
+       ret = wl1251_hw_init_templates_config(wl);
+       if (ret < 0)
+               return ret;
+
+       /* Default memory configuration */
+       ret = wl1251_hw_init_mem_config(wl);
+       if (ret < 0)
+               return ret;
+
+       /* Default data path configuration  */
+       ret = wl1251_hw_init_data_path_config(wl);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       /* RX config */
+       ret = wl1251_hw_init_rx_config(wl,
+                                      RX_CFG_PROMISCUOUS | RX_CFG_TSF,
+                                      RX_FILTER_OPTION_DEF);
+       /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
+          RX_FILTER_OPTION_FILTER_ALL); */
+       if (ret < 0)
+               goto out_free_data_path;
+
+       /* TX queues config */
+       ret = wl1251_hw_init_tx_queue_config(wl);
+       if (ret < 0)
+               goto out_free_data_path;
+
+       /* PHY layer config */
+       ret = wl1251_hw_init_phy_config(wl);
+       if (ret < 0)
+               goto out_free_data_path;
+
+       /* Initialize connection monitoring thresholds */
+       ret = wl1251_acx_conn_monit_params(wl);
+       if (ret < 0)
+               goto out_free_data_path;
+
+       /* Beacon filtering */
+       ret = wl1251_hw_init_beacon_filter(wl);
+       if (ret < 0)
+               goto out_free_data_path;
+
+       /* Bluetooth WLAN coexistence */
+       ret = wl1251_hw_init_pta(wl);
+       if (ret < 0)
+               goto out_free_data_path;
+
+       /* Energy detection */
+       ret = wl1251_hw_init_energy_detection(wl);
+       if (ret < 0)
+               goto out_free_data_path;
+
+       /* Beacons and boradcast settings */
+       ret = wl1251_hw_init_beacon_broadcast(wl);
+       if (ret < 0)
+               goto out_free_data_path;
+
+       /* Enable data path */
+       ret = wl1251_cmd_data_path(wl, wl->channel, 1);
+       if (ret < 0)
+               goto out_free_data_path;
+
+       /* Default power state */
+       ret = wl1251_hw_init_power_auth(wl);
+       if (ret < 0)
+               goto out_free_data_path;
+
+       wl_mem_map = wl->target_mem_map;
+       wl1251_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
+                   wl_mem_map->num_tx_mem_blocks,
+                   wl->data_path->tx_control_addr,
+                   wl_mem_map->num_rx_mem_blocks,
+                   wl->data_path->rx_control_addr);
+
+       return 0;
+
+ out_free_data_path:
+       kfree(wl->data_path);
+
+ out_free_memmap:
+       kfree(wl->target_mem_map);
+
+       return ret;
+}
diff --git a/drivers/net/wireless/ti/wl1251/init.h b/drivers/net/wireless/ti/wl1251/init.h
new file mode 100644 (file)
index 0000000..543f175
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL1251_INIT_H__
+#define __WL1251_INIT_H__
+
+#include "wl1251.h"
+
+enum {
+       /* best effort/legacy */
+       AC_BE = 0,
+
+       /* background */
+       AC_BK = 1,
+
+       /* video */
+       AC_VI = 2,
+
+       /* voice */
+       AC_VO = 3,
+
+       /* broadcast dummy access category */
+       AC_BCAST = 4,
+
+       NUM_ACCESS_CATEGORIES = 4
+};
+
+/* following are defult values for the IE fields*/
+#define CWMIN_BK  15
+#define CWMIN_BE  15
+#define CWMIN_VI  7
+#define CWMIN_VO  3
+#define CWMAX_BK  1023
+#define CWMAX_BE  63
+#define CWMAX_VI  15
+#define CWMAX_VO  7
+
+/* slot number setting to start transmission at PIFS interval */
+#define AIFS_PIFS 1
+
+/*
+ * slot number setting to start transmission at DIFS interval - normal DCF
+ * access
+ */
+#define AIFS_DIFS 2
+
+#define AIFSN_BK  7
+#define AIFSN_BE  3
+#define AIFSN_VI  AIFS_PIFS
+#define AIFSN_VO  AIFS_PIFS
+#define TXOP_BK   0
+#define TXOP_BE   0
+#define TXOP_VI   3008
+#define TXOP_VO   1504
+
+int wl1251_hw_init_hwenc_config(struct wl1251 *wl);
+int wl1251_hw_init_templates_config(struct wl1251 *wl);
+int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter);
+int wl1251_hw_init_phy_config(struct wl1251 *wl);
+int wl1251_hw_init_beacon_filter(struct wl1251 *wl);
+int wl1251_hw_init_pta(struct wl1251 *wl);
+int wl1251_hw_init_energy_detection(struct wl1251 *wl);
+int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl);
+int wl1251_hw_init_power_auth(struct wl1251 *wl);
+int wl1251_hw_init_mem_config(struct wl1251 *wl);
+int wl1251_hw_init(struct wl1251 *wl);
+
+#endif
diff --git a/drivers/net/wireless/ti/wl1251/io.c b/drivers/net/wireless/ti/wl1251/io.c
new file mode 100644 (file)
index 0000000..cdcadbf
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+ * This file is part of wl12xx
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "wl1251.h"
+#include "reg.h"
+#include "io.h"
+
+/* FIXME: this is static data nowadays and the table can be removed */
+static enum wl12xx_acx_int_reg wl1251_io_reg_table[ACX_REG_TABLE_LEN] = {
+       [ACX_REG_INTERRUPT_TRIG]     = (REGISTERS_BASE + 0x0474),
+       [ACX_REG_INTERRUPT_TRIG_H]   = (REGISTERS_BASE + 0x0478),
+       [ACX_REG_INTERRUPT_MASK]     = (REGISTERS_BASE + 0x0494),
+       [ACX_REG_HINT_MASK_SET]      = (REGISTERS_BASE + 0x0498),
+       [ACX_REG_HINT_MASK_CLR]      = (REGISTERS_BASE + 0x049C),
+       [ACX_REG_INTERRUPT_NO_CLEAR] = (REGISTERS_BASE + 0x04B0),
+       [ACX_REG_INTERRUPT_CLEAR]    = (REGISTERS_BASE + 0x04A4),
+       [ACX_REG_INTERRUPT_ACK]      = (REGISTERS_BASE + 0x04A8),
+       [ACX_REG_SLV_SOFT_RESET]     = (REGISTERS_BASE + 0x0000),
+       [ACX_REG_EE_START]           = (REGISTERS_BASE + 0x080C),
+       [ACX_REG_ECPU_CONTROL]       = (REGISTERS_BASE + 0x0804)
+};
+
+static int wl1251_translate_reg_addr(struct wl1251 *wl, int addr)
+{
+       /* If the address is lower than REGISTERS_BASE, it means that this is
+        * a chip-specific register address, so look it up in the registers
+        * table */
+       if (addr < REGISTERS_BASE) {
+               /* Make sure we don't go over the table */
+               if (addr >= ACX_REG_TABLE_LEN) {
+                       wl1251_error("address out of range (%d)", addr);
+                       return -EINVAL;
+               }
+               addr = wl1251_io_reg_table[addr];
+       }
+
+       return addr - wl->physical_reg_addr + wl->virtual_reg_addr;
+}
+
+static int wl1251_translate_mem_addr(struct wl1251 *wl, int addr)
+{
+       return addr - wl->physical_mem_addr + wl->virtual_mem_addr;
+}
+
+void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len)
+{
+       int physical;
+
+       physical = wl1251_translate_mem_addr(wl, addr);
+
+       wl->if_ops->read(wl, physical, buf, len);
+}
+
+void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len)
+{
+       int physical;
+
+       physical = wl1251_translate_mem_addr(wl, addr);
+
+       wl->if_ops->write(wl, physical, buf, len);
+}
+
+u32 wl1251_mem_read32(struct wl1251 *wl, int addr)
+{
+       return wl1251_read32(wl, wl1251_translate_mem_addr(wl, addr));
+}
+
+void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val)
+{
+       wl1251_write32(wl, wl1251_translate_mem_addr(wl, addr), val);
+}
+
+u32 wl1251_reg_read32(struct wl1251 *wl, int addr)
+{
+       return wl1251_read32(wl, wl1251_translate_reg_addr(wl, addr));
+}
+
+void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val)
+{
+       wl1251_write32(wl, wl1251_translate_reg_addr(wl, addr), val);
+}
+
+/* Set the partitions to access the chip addresses.
+ *
+ * There are two VIRTUAL partitions (the memory partition and the
+ * registers partition), which are mapped to two different areas of the
+ * PHYSICAL (hardware) memory.  This function also makes other checks to
+ * ensure that the partitions are not overlapping.  In the diagram below, the
+ * memory partition comes before the register partition, but the opposite is
+ * also supported.
+ *
+ *                               PHYSICAL address
+ *                                     space
+ *
+ *                                    |    |
+ *                                 ...+----+--> mem_start
+ *          VIRTUAL address     ...   |    |
+ *               space       ...      |    | [PART_0]
+ *                        ...         |    |
+ * 0x00000000 <--+----+...         ...+----+--> mem_start + mem_size
+ *               |    |         ...   |    |
+ *               |MEM |      ...      |    |
+ *               |    |   ...         |    |
+ *  part_size <--+----+...            |    | {unused area)
+ *               |    |   ...         |    |
+ *               |REG |      ...      |    |
+ *  part_size    |    |         ...   |    |
+ *      +     <--+----+...         ...+----+--> reg_start
+ *  reg_size              ...         |    |
+ *                           ...      |    | [PART_1]
+ *                              ...   |    |
+ *                                 ...+----+--> reg_start + reg_size
+ *                                    |    |
+ *
+ */
+void wl1251_set_partition(struct wl1251 *wl,
+                         u32 mem_start, u32 mem_size,
+                         u32 reg_start, u32 reg_size)
+{
+       struct wl1251_partition partition[2];
+
+       wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
+                    mem_start, mem_size);
+       wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
+                    reg_start, reg_size);
+
+       /* Make sure that the two partitions together don't exceed the
+        * address range */
+       if ((mem_size + reg_size) > HW_ACCESS_MEMORY_MAX_RANGE) {
+               wl1251_debug(DEBUG_SPI, "Total size exceeds maximum virtual"
+                            " address range.  Truncating partition[0].");
+               mem_size = HW_ACCESS_MEMORY_MAX_RANGE - reg_size;
+               wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
+                            mem_start, mem_size);
+               wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
+                            reg_start, reg_size);
+       }
+
+       if ((mem_start < reg_start) &&
+           ((mem_start + mem_size) > reg_start)) {
+               /* Guarantee that the memory partition doesn't overlap the
+                * registers partition */
+               wl1251_debug(DEBUG_SPI, "End of partition[0] is "
+                            "overlapping partition[1].  Adjusted.");
+               mem_size = reg_start - mem_start;
+               wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
+                            mem_start, mem_size);
+               wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
+                            reg_start, reg_size);
+       } else if ((reg_start < mem_start) &&
+                  ((reg_start + reg_size) > mem_start)) {
+               /* Guarantee that the register partition doesn't overlap the
+                * memory partition */
+               wl1251_debug(DEBUG_SPI, "End of partition[1] is"
+                            " overlapping partition[0].  Adjusted.");
+               reg_size = mem_start - reg_start;
+               wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
+                            mem_start, mem_size);
+               wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
+                            reg_start, reg_size);
+       }
+
+       partition[0].start = mem_start;
+       partition[0].size  = mem_size;
+       partition[1].start = reg_start;
+       partition[1].size  = reg_size;
+
+       wl->physical_mem_addr = mem_start;
+       wl->physical_reg_addr = reg_start;
+
+       wl->virtual_mem_addr = 0;
+       wl->virtual_reg_addr = mem_size;
+
+       wl->if_ops->write(wl, HW_ACCESS_PART0_SIZE_ADDR, partition,
+               sizeof(partition));
+}
diff --git a/drivers/net/wireless/ti/wl1251/io.h b/drivers/net/wireless/ti/wl1251/io.h
new file mode 100644 (file)
index 0000000..d382877
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * This file is part of wl12xx
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#ifndef __WL1251_IO_H__
+#define __WL1251_IO_H__
+
+#include "wl1251.h"
+
+#define HW_ACCESS_MEMORY_MAX_RANGE             0x1FFC0
+
+#define HW_ACCESS_PART0_SIZE_ADDR           0x1FFC0
+#define HW_ACCESS_PART0_START_ADDR          0x1FFC4
+#define HW_ACCESS_PART1_SIZE_ADDR           0x1FFC8
+#define HW_ACCESS_PART1_START_ADDR          0x1FFCC
+
+#define HW_ACCESS_REGISTER_SIZE             4
+
+#define HW_ACCESS_PRAM_MAX_RANGE               0x3c000
+
+static inline u32 wl1251_read32(struct wl1251 *wl, int addr)
+{
+       wl->if_ops->read(wl, addr, &wl->buffer_32, sizeof(wl->buffer_32));
+
+       return le32_to_cpu(wl->buffer_32);
+}
+
+static inline void wl1251_write32(struct wl1251 *wl, int addr, u32 val)
+{
+       wl->buffer_32 = cpu_to_le32(val);
+       wl->if_ops->write(wl, addr, &wl->buffer_32, sizeof(wl->buffer_32));
+}
+
+static inline u32 wl1251_read_elp(struct wl1251 *wl, int addr)
+{
+       u32 response;
+
+       if (wl->if_ops->read_elp)
+               wl->if_ops->read_elp(wl, addr, &response);
+       else
+               wl->if_ops->read(wl, addr, &response, sizeof(u32));
+
+       return response;
+}
+
+static inline void wl1251_write_elp(struct wl1251 *wl, int addr, u32 val)
+{
+       if (wl->if_ops->write_elp)
+               wl->if_ops->write_elp(wl, addr, val);
+       else
+               wl->if_ops->write(wl, addr, &val, sizeof(u32));
+}
+
+/* Memory target IO, address is translated to partition 0 */
+void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len);
+void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len);
+u32 wl1251_mem_read32(struct wl1251 *wl, int addr);
+void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val);
+/* Registers IO */
+u32 wl1251_reg_read32(struct wl1251 *wl, int addr);
+void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val);
+
+void wl1251_set_partition(struct wl1251 *wl,
+                         u32 part_start, u32 part_size,
+                         u32 reg_start,  u32 reg_size);
+
+#endif
diff --git a/drivers/net/wireless/ti/wl1251/main.c b/drivers/net/wireless/ti/wl1251/main.c
new file mode 100644 (file)
index 0000000..41302c7
--- /dev/null
@@ -0,0 +1,1471 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/firmware.h>
+#include <linux/delay.h>
+#include <linux/irq.h>
+#include <linux/crc32.h>
+#include <linux/etherdevice.h>
+#include <linux/vmalloc.h>
+#include <linux/slab.h>
+
+#include "wl1251.h"
+#include "wl12xx_80211.h"
+#include "reg.h"
+#include "io.h"
+#include "cmd.h"
+#include "event.h"
+#include "tx.h"
+#include "rx.h"
+#include "ps.h"
+#include "init.h"
+#include "debugfs.h"
+#include "boot.h"
+
+void wl1251_enable_interrupts(struct wl1251 *wl)
+{
+       wl->if_ops->enable_irq(wl);
+}
+
+void wl1251_disable_interrupts(struct wl1251 *wl)
+{
+       wl->if_ops->disable_irq(wl);
+}
+
+static int wl1251_power_off(struct wl1251 *wl)
+{
+       return wl->if_ops->power(wl, false);
+}
+
+static int wl1251_power_on(struct wl1251 *wl)
+{
+       return wl->if_ops->power(wl, true);
+}
+
+static int wl1251_fetch_firmware(struct wl1251 *wl)
+{
+       const struct firmware *fw;
+       struct device *dev = wiphy_dev(wl->hw->wiphy);
+       int ret;
+
+       ret = request_firmware(&fw, WL1251_FW_NAME, dev);
+
+       if (ret < 0) {
+               wl1251_error("could not get firmware: %d", ret);
+               return ret;
+       }
+
+       if (fw->size % 4) {
+               wl1251_error("firmware size is not multiple of 32 bits: %zu",
+                            fw->size);
+               ret = -EILSEQ;
+               goto out;
+       }
+
+       wl->fw_len = fw->size;
+       wl->fw = vmalloc(wl->fw_len);
+
+       if (!wl->fw) {
+               wl1251_error("could not allocate memory for the firmware");
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       memcpy(wl->fw, fw->data, wl->fw_len);
+
+       ret = 0;
+
+out:
+       release_firmware(fw);
+
+       return ret;
+}
+
+static int wl1251_fetch_nvs(struct wl1251 *wl)
+{
+       const struct firmware *fw;
+       struct device *dev = wiphy_dev(wl->hw->wiphy);
+       int ret;
+
+       ret = request_firmware(&fw, WL1251_NVS_NAME, dev);
+
+       if (ret < 0) {
+               wl1251_error("could not get nvs file: %d", ret);
+               return ret;
+       }
+
+       if (fw->size % 4) {
+               wl1251_error("nvs size is not multiple of 32 bits: %zu",
+                            fw->size);
+               ret = -EILSEQ;
+               goto out;
+       }
+
+       wl->nvs_len = fw->size;
+       wl->nvs = kmemdup(fw->data, wl->nvs_len, GFP_KERNEL);
+
+       if (!wl->nvs) {
+               wl1251_error("could not allocate memory for the nvs file");
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ret = 0;
+
+out:
+       release_firmware(fw);
+
+       return ret;
+}
+
+static void wl1251_fw_wakeup(struct wl1251 *wl)
+{
+       u32 elp_reg;
+
+       elp_reg = ELPCTRL_WAKE_UP;
+       wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
+       elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
+
+       if (!(elp_reg & ELPCTRL_WLAN_READY))
+               wl1251_warning("WLAN not ready");
+}
+
+static int wl1251_chip_wakeup(struct wl1251 *wl)
+{
+       int ret;
+
+       ret = wl1251_power_on(wl);
+       if (ret < 0)
+               return ret;
+
+       msleep(WL1251_POWER_ON_SLEEP);
+       wl->if_ops->reset(wl);
+
+       /* We don't need a real memory partition here, because we only want
+        * to use the registers at this point. */
+       wl1251_set_partition(wl,
+                            0x00000000,
+                            0x00000000,
+                            REGISTERS_BASE,
+                            REGISTERS_DOWN_SIZE);
+
+       /* ELP module wake up */
+       wl1251_fw_wakeup(wl);
+
+       /* whal_FwCtrl_BootSm() */
+
+       /* 0. read chip id from CHIP_ID */
+       wl->chip_id = wl1251_reg_read32(wl, CHIP_ID_B);
+
+       /* 1. check if chip id is valid */
+
+       switch (wl->chip_id) {
+       case CHIP_ID_1251_PG12:
+               wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)",
+                            wl->chip_id);
+               break;
+       case CHIP_ID_1251_PG11:
+               wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG11)",
+                            wl->chip_id);
+               break;
+       case CHIP_ID_1251_PG10:
+       default:
+               wl1251_error("unsupported chip id: 0x%x", wl->chip_id);
+               ret = -ENODEV;
+               goto out;
+       }
+
+       if (wl->fw == NULL) {
+               ret = wl1251_fetch_firmware(wl);
+               if (ret < 0)
+                       goto out;
+       }
+
+       if (wl->nvs == NULL && !wl->use_eeprom) {
+               /* No NVS from netlink, try to get it from the filesystem */
+               ret = wl1251_fetch_nvs(wl);
+               if (ret < 0)
+                       goto out;
+       }
+
+out:
+       return ret;
+}
+
+#define WL1251_IRQ_LOOP_COUNT 10
+static void wl1251_irq_work(struct work_struct *work)
+{
+       u32 intr, ctr = WL1251_IRQ_LOOP_COUNT;
+       struct wl1251 *wl =
+               container_of(work, struct wl1251, irq_work);
+       int ret;
+
+       mutex_lock(&wl->mutex);
+
+       wl1251_debug(DEBUG_IRQ, "IRQ work");
+
+       if (wl->state == WL1251_STATE_OFF)
+               goto out;
+
+       ret = wl1251_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1251_ACX_INTR_ALL);
+
+       intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
+       wl1251_debug(DEBUG_IRQ, "intr: 0x%x", intr);
+
+       do {
+               if (wl->data_path) {
+                       wl->rx_counter = wl1251_mem_read32(
+                               wl, wl->data_path->rx_control_addr);
+
+                       /* We handle a frmware bug here */
+                       switch ((wl->rx_counter - wl->rx_handled) & 0xf) {
+                       case 0:
+                               wl1251_debug(DEBUG_IRQ,
+                                            "RX: FW and host in sync");
+                               intr &= ~WL1251_ACX_INTR_RX0_DATA;
+                               intr &= ~WL1251_ACX_INTR_RX1_DATA;
+                               break;
+                       case 1:
+                               wl1251_debug(DEBUG_IRQ, "RX: FW +1");
+                               intr |= WL1251_ACX_INTR_RX0_DATA;
+                               intr &= ~WL1251_ACX_INTR_RX1_DATA;
+                               break;
+                       case 2:
+                               wl1251_debug(DEBUG_IRQ, "RX: FW +2");
+                               intr |= WL1251_ACX_INTR_RX0_DATA;
+                               intr |= WL1251_ACX_INTR_RX1_DATA;
+                               break;
+                       default:
+                               wl1251_warning(
+                                       "RX: FW and host out of sync: %d",
+                                       wl->rx_counter - wl->rx_handled);
+                               break;
+                       }
+
+                       wl->rx_handled = wl->rx_counter;
+
+                       wl1251_debug(DEBUG_IRQ, "RX counter: %d",
+                                    wl->rx_counter);
+               }
+
+               intr &= wl->intr_mask;
+
+               if (intr == 0) {
+                       wl1251_debug(DEBUG_IRQ, "INTR is 0");
+                       goto out_sleep;
+               }
+
+               if (intr & WL1251_ACX_INTR_RX0_DATA) {
+                       wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX0_DATA");
+                       wl1251_rx(wl);
+               }
+
+               if (intr & WL1251_ACX_INTR_RX1_DATA) {
+                       wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX1_DATA");
+                       wl1251_rx(wl);
+               }
+
+               if (intr & WL1251_ACX_INTR_TX_RESULT) {
+                       wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_TX_RESULT");
+                       wl1251_tx_complete(wl);
+               }
+
+               if (intr & WL1251_ACX_INTR_EVENT_A) {
+                       wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT_A");
+                       wl1251_event_handle(wl, 0);
+               }
+
+               if (intr & WL1251_ACX_INTR_EVENT_B) {
+                       wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT_B");
+                       wl1251_event_handle(wl, 1);
+               }
+
+               if (intr & WL1251_ACX_INTR_INIT_COMPLETE)
+                       wl1251_debug(DEBUG_IRQ,
+                                    "WL1251_ACX_INTR_INIT_COMPLETE");
+
+               if (--ctr == 0)
+                       break;
+
+               intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
+       } while (intr);
+
+out_sleep:
+       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
+       wl1251_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+static int wl1251_join(struct wl1251 *wl, u8 bss_type, u8 channel,
+                      u16 beacon_interval, u8 dtim_period)
+{
+       int ret;
+
+       ret = wl1251_acx_frame_rates(wl, DEFAULT_HW_GEN_TX_RATE,
+                                    DEFAULT_HW_GEN_MODULATION_TYPE,
+                                    wl->tx_mgmt_frm_rate,
+                                    wl->tx_mgmt_frm_mod);
+       if (ret < 0)
+               goto out;
+
+
+       ret = wl1251_cmd_join(wl, bss_type, channel, beacon_interval,
+                             dtim_period);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1251_event_wait(wl, JOIN_EVENT_COMPLETE_ID, 100);
+       if (ret < 0)
+               wl1251_warning("join timeout");
+
+out:
+       return ret;
+}
+
+static void wl1251_filter_work(struct work_struct *work)
+{
+       struct wl1251 *wl =
+               container_of(work, struct wl1251, filter_work);
+       int ret;
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->state == WL1251_STATE_OFF)
+               goto out;
+
+       ret = wl1251_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1251_join(wl, wl->bss_type, wl->channel, wl->beacon_int,
+                         wl->dtim_period);
+       if (ret < 0)
+               goto out_sleep;
+
+out_sleep:
+       wl1251_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+static void wl1251_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+       struct wl1251 *wl = hw->priv;
+       unsigned long flags;
+
+       skb_queue_tail(&wl->tx_queue, skb);
+
+       /*
+        * The chip specific setup must run before the first TX packet -
+        * before that, the tx_work will not be initialized!
+        */
+
+       ieee80211_queue_work(wl->hw, &wl->tx_work);
+
+       /*
+        * The workqueue is slow to process the tx_queue and we need stop
+        * the queue here, otherwise the queue will get too long.
+        */
+       if (skb_queue_len(&wl->tx_queue) >= WL1251_TX_QUEUE_HIGH_WATERMARK) {
+               wl1251_debug(DEBUG_TX, "op_tx: tx_queue full, stop queues");
+
+               spin_lock_irqsave(&wl->wl_lock, flags);
+               ieee80211_stop_queues(wl->hw);
+               wl->tx_queue_stopped = true;
+               spin_unlock_irqrestore(&wl->wl_lock, flags);
+       }
+}
+
+static int wl1251_op_start(struct ieee80211_hw *hw)
+{
+       struct wl1251 *wl = hw->priv;
+       struct wiphy *wiphy = hw->wiphy;
+       int ret = 0;
+
+       wl1251_debug(DEBUG_MAC80211, "mac80211 start");
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->state != WL1251_STATE_OFF) {
+               wl1251_error("cannot start because not in off state: %d",
+                            wl->state);
+               ret = -EBUSY;
+               goto out;
+       }
+
+       ret = wl1251_chip_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1251_boot(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1251_hw_init(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1251_acx_station_id(wl);
+       if (ret < 0)
+               goto out;
+
+       wl->state = WL1251_STATE_ON;
+
+       wl1251_info("firmware booted (%s)", wl->fw_ver);
+
+       /* update hw/fw version info in wiphy struct */
+       wiphy->hw_version = wl->chip_id;
+       strncpy(wiphy->fw_version, wl->fw_ver, sizeof(wiphy->fw_version));
+
+out:
+       if (ret < 0)
+               wl1251_power_off(wl);
+
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+static void wl1251_op_stop(struct ieee80211_hw *hw)
+{
+       struct wl1251 *wl = hw->priv;
+
+       wl1251_info("down");
+
+       wl1251_debug(DEBUG_MAC80211, "mac80211 stop");
+
+       mutex_lock(&wl->mutex);
+
+       WARN_ON(wl->state != WL1251_STATE_ON);
+
+       if (wl->scanning) {
+               ieee80211_scan_completed(wl->hw, true);
+               wl->scanning = false;
+       }
+
+       wl->state = WL1251_STATE_OFF;
+
+       wl1251_disable_interrupts(wl);
+
+       mutex_unlock(&wl->mutex);
+
+       cancel_work_sync(&wl->irq_work);
+       cancel_work_sync(&wl->tx_work);
+       cancel_work_sync(&wl->filter_work);
+
+       mutex_lock(&wl->mutex);
+
+       /* let's notify MAC80211 about the remaining pending TX frames */
+       wl1251_tx_flush(wl);
+       wl1251_power_off(wl);
+
+       memset(wl->bssid, 0, ETH_ALEN);
+       wl->listen_int = 1;
+       wl->bss_type = MAX_BSS_TYPE;
+
+       wl->data_in_count = 0;
+       wl->rx_counter = 0;
+       wl->rx_handled = 0;
+       wl->rx_current_buffer = 0;
+       wl->rx_last_id = 0;
+       wl->next_tx_complete = 0;
+       wl->elp = false;
+       wl->station_mode = STATION_ACTIVE_MODE;
+       wl->tx_queue_stopped = false;
+       wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
+       wl->rssi_thold = 0;
+       wl->channel = WL1251_DEFAULT_CHANNEL;
+
+       wl1251_debugfs_reset(wl);
+
+       mutex_unlock(&wl->mutex);
+}
+
+static int wl1251_op_add_interface(struct ieee80211_hw *hw,
+                                  struct ieee80211_vif *vif)
+{
+       struct wl1251 *wl = hw->priv;
+       int ret = 0;
+
+       vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
+                            IEEE80211_VIF_SUPPORTS_CQM_RSSI;
+
+       wl1251_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
+                    vif->type, vif->addr);
+
+       mutex_lock(&wl->mutex);
+       if (wl->vif) {
+               ret = -EBUSY;
+               goto out;
+       }
+
+       wl->vif = vif;
+
+       switch (vif->type) {
+       case NL80211_IFTYPE_STATION:
+               wl->bss_type = BSS_TYPE_STA_BSS;
+               break;
+       case NL80211_IFTYPE_ADHOC:
+               wl->bss_type = BSS_TYPE_IBSS;
+               break;
+       default:
+               ret = -EOPNOTSUPP;
+               goto out;
+       }
+
+       if (memcmp(wl->mac_addr, vif->addr, ETH_ALEN)) {
+               memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
+               SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
+               ret = wl1251_acx_station_id(wl);
+               if (ret < 0)
+                       goto out;
+       }
+
+out:
+       mutex_unlock(&wl->mutex);
+       return ret;
+}
+
+static void wl1251_op_remove_interface(struct ieee80211_hw *hw,
+                                        struct ieee80211_vif *vif)
+{
+       struct wl1251 *wl = hw->priv;
+
+       mutex_lock(&wl->mutex);
+       wl1251_debug(DEBUG_MAC80211, "mac80211 remove interface");
+       wl->vif = NULL;
+       mutex_unlock(&wl->mutex);
+}
+
+static int wl1251_build_qos_null_data(struct wl1251 *wl)
+{
+       struct ieee80211_qos_hdr template;
+
+       memset(&template, 0, sizeof(template));
+
+       memcpy(template.addr1, wl->bssid, ETH_ALEN);
+       memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
+       memcpy(template.addr3, wl->bssid, ETH_ALEN);
+
+       template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
+                                            IEEE80211_STYPE_QOS_NULLFUNC |
+                                            IEEE80211_FCTL_TODS);
+
+       /* FIXME: not sure what priority to use here */
+       template.qos_ctrl = cpu_to_le16(0);
+
+       return wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, &template,
+                                      sizeof(template));
+}
+
+static int wl1251_op_config(struct ieee80211_hw *hw, u32 changed)
+{
+       struct wl1251 *wl = hw->priv;
+       struct ieee80211_conf *conf = &hw->conf;
+       int channel, ret = 0;
+
+       channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
+
+       wl1251_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
+                    channel,
+                    conf->flags & IEEE80211_CONF_PS ? "on" : "off",
+                    conf->power_level);
+
+       mutex_lock(&wl->mutex);
+
+       ret = wl1251_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       if (channel != wl->channel) {
+               wl->channel = channel;
+
+               ret = wl1251_join(wl, wl->bss_type, wl->channel,
+                                 wl->beacon_int, wl->dtim_period);
+               if (ret < 0)
+                       goto out_sleep;
+       }
+
+       if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
+               wl1251_debug(DEBUG_PSM, "psm enabled");
+
+               wl->psm_requested = true;
+
+               wl->dtim_period = conf->ps_dtim_period;
+
+               ret = wl1251_acx_wr_tbtt_and_dtim(wl, wl->beacon_int,
+                                                 wl->dtim_period);
+
+               /*
+                * mac80211 enables PSM only if we're already associated.
+                */
+               ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
+               if (ret < 0)
+                       goto out_sleep;
+       } else if (!(conf->flags & IEEE80211_CONF_PS) &&
+                  wl->psm_requested) {
+               wl1251_debug(DEBUG_PSM, "psm disabled");
+
+               wl->psm_requested = false;
+
+               if (wl->station_mode != STATION_ACTIVE_MODE) {
+                       ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
+                       if (ret < 0)
+                               goto out_sleep;
+               }
+       }
+
+       if (changed & IEEE80211_CONF_CHANGE_IDLE) {
+               if (conf->flags & IEEE80211_CONF_IDLE) {
+                       ret = wl1251_ps_set_mode(wl, STATION_IDLE);
+                       if (ret < 0)
+                               goto out_sleep;
+               } else {
+                       ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
+                       if (ret < 0)
+                               goto out_sleep;
+                       ret = wl1251_join(wl, wl->bss_type, wl->channel,
+                                         wl->beacon_int, wl->dtim_period);
+                       if (ret < 0)
+                               goto out_sleep;
+               }
+       }
+
+       if (conf->power_level != wl->power_level) {
+               ret = wl1251_acx_tx_power(wl, conf->power_level);
+               if (ret < 0)
+                       goto out_sleep;
+
+               wl->power_level = conf->power_level;
+       }
+
+out_sleep:
+       wl1251_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+#define WL1251_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
+                                 FIF_ALLMULTI | \
+                                 FIF_FCSFAIL | \
+                                 FIF_BCN_PRBRESP_PROMISC | \
+                                 FIF_CONTROL | \
+                                 FIF_OTHER_BSS)
+
+static void wl1251_op_configure_filter(struct ieee80211_hw *hw,
+                                      unsigned int changed,
+                                      unsigned int *total,u64 multicast)
+{
+       struct wl1251 *wl = hw->priv;
+
+       wl1251_debug(DEBUG_MAC80211, "mac80211 configure filter");
+
+       *total &= WL1251_SUPPORTED_FILTERS;
+       changed &= WL1251_SUPPORTED_FILTERS;
+
+       if (changed == 0)
+               /* no filters which we support changed */
+               return;
+
+       /* FIXME: wl->rx_config and wl->rx_filter are not protected */
+
+       wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
+       wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
+
+       if (*total & FIF_PROMISC_IN_BSS) {
+               wl->rx_config |= CFG_BSSID_FILTER_EN;
+               wl->rx_config |= CFG_RX_ALL_GOOD;
+       }
+       if (*total & FIF_ALLMULTI)
+               /*
+                * CFG_MC_FILTER_EN in rx_config needs to be 0 to receive
+                * all multicast frames
+                */
+               wl->rx_config &= ~CFG_MC_FILTER_EN;
+       if (*total & FIF_FCSFAIL)
+               wl->rx_filter |= CFG_RX_FCS_ERROR;
+       if (*total & FIF_BCN_PRBRESP_PROMISC) {
+               wl->rx_config &= ~CFG_BSSID_FILTER_EN;
+               wl->rx_config &= ~CFG_SSID_FILTER_EN;
+       }
+       if (*total & FIF_CONTROL)
+               wl->rx_filter |= CFG_RX_CTL_EN;
+       if (*total & FIF_OTHER_BSS)
+               wl->rx_filter &= ~CFG_BSSID_FILTER_EN;
+
+       /*
+        * FIXME: workqueues need to be properly cancelled on stop(), for
+        * now let's just disable changing the filter settings. They will
+        * be updated any on config().
+        */
+       /* schedule_work(&wl->filter_work); */
+}
+
+/* HW encryption */
+static int wl1251_set_key_type(struct wl1251 *wl,
+                              struct wl1251_cmd_set_keys *key,
+                              enum set_key_cmd cmd,
+                              struct ieee80211_key_conf *mac80211_key,
+                              const u8 *addr)
+{
+       switch (mac80211_key->cipher) {
+       case WLAN_CIPHER_SUITE_WEP40:
+       case WLAN_CIPHER_SUITE_WEP104:
+               if (is_broadcast_ether_addr(addr))
+                       key->key_type = KEY_WEP_DEFAULT;
+               else
+                       key->key_type = KEY_WEP_ADDR;
+
+               mac80211_key->hw_key_idx = mac80211_key->keyidx;
+               break;
+       case WLAN_CIPHER_SUITE_TKIP:
+               if (is_broadcast_ether_addr(addr))
+                       key->key_type = KEY_TKIP_MIC_GROUP;
+               else
+                       key->key_type = KEY_TKIP_MIC_PAIRWISE;
+
+               mac80211_key->hw_key_idx = mac80211_key->keyidx;
+               break;
+       case WLAN_CIPHER_SUITE_CCMP:
+               if (is_broadcast_ether_addr(addr))
+                       key->key_type = KEY_AES_GROUP;
+               else
+                       key->key_type = KEY_AES_PAIRWISE;
+               mac80211_key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
+               break;
+       default:
+               wl1251_error("Unknown key cipher 0x%x", mac80211_key->cipher);
+               return -EOPNOTSUPP;
+       }
+
+       return 0;
+}
+
+static int wl1251_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
+                            struct ieee80211_vif *vif,
+                            struct ieee80211_sta *sta,
+                            struct ieee80211_key_conf *key)
+{
+       struct wl1251 *wl = hw->priv;
+       struct wl1251_cmd_set_keys *wl_cmd;
+       const u8 *addr;
+       int ret;
+
+       static const u8 bcast_addr[ETH_ALEN] =
+               { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+
+       wl1251_debug(DEBUG_MAC80211, "mac80211 set key");
+
+       wl_cmd = kzalloc(sizeof(*wl_cmd), GFP_KERNEL);
+       if (!wl_cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       addr = sta ? sta->addr : bcast_addr;
+
+       wl1251_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
+       wl1251_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
+       wl1251_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
+                    key->cipher, key->keyidx, key->keylen, key->flags);
+       wl1251_dump(DEBUG_CRYPT, "KEY: ", key->key, key->keylen);
+
+       if (is_zero_ether_addr(addr)) {
+               /* We dont support TX only encryption */
+               ret = -EOPNOTSUPP;
+               goto out;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       ret = wl1251_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out_unlock;
+
+       switch (cmd) {
+       case SET_KEY:
+               wl_cmd->key_action = KEY_ADD_OR_REPLACE;
+               break;
+       case DISABLE_KEY:
+               wl_cmd->key_action = KEY_REMOVE;
+               break;
+       default:
+               wl1251_error("Unsupported key cmd 0x%x", cmd);
+               break;
+       }
+
+       ret = wl1251_set_key_type(wl, wl_cmd, cmd, key, addr);
+       if (ret < 0) {
+               wl1251_error("Set KEY type failed");
+               goto out_sleep;
+       }
+
+       if (wl_cmd->key_type != KEY_WEP_DEFAULT)
+               memcpy(wl_cmd->addr, addr, ETH_ALEN);
+
+       if ((wl_cmd->key_type == KEY_TKIP_MIC_GROUP) ||
+           (wl_cmd->key_type == KEY_TKIP_MIC_PAIRWISE)) {
+               /*
+                * We get the key in the following form:
+                * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
+                * but the target is expecting:
+                * TKIP - RX MIC - TX MIC
+                */
+               memcpy(wl_cmd->key, key->key, 16);
+               memcpy(wl_cmd->key + 16, key->key + 24, 8);
+               memcpy(wl_cmd->key + 24, key->key + 16, 8);
+
+       } else {
+               memcpy(wl_cmd->key, key->key, key->keylen);
+       }
+       wl_cmd->key_size = key->keylen;
+
+       wl_cmd->id = key->keyidx;
+       wl_cmd->ssid_profile = 0;
+
+       wl1251_dump(DEBUG_CRYPT, "TARGET KEY: ", wl_cmd, sizeof(*wl_cmd));
+
+       ret = wl1251_cmd_send(wl, CMD_SET_KEYS, wl_cmd, sizeof(*wl_cmd));
+       if (ret < 0) {
+               wl1251_warning("could not set keys");
+               goto out_sleep;
+       }
+
+out_sleep:
+       wl1251_ps_elp_sleep(wl);
+
+out_unlock:
+       mutex_unlock(&wl->mutex);
+
+out:
+       kfree(wl_cmd);
+
+       return ret;
+}
+
+static int wl1251_op_hw_scan(struct ieee80211_hw *hw,
+                            struct ieee80211_vif *vif,
+                            struct cfg80211_scan_request *req)
+{
+       struct wl1251 *wl = hw->priv;
+       struct sk_buff *skb;
+       size_t ssid_len = 0;
+       u8 *ssid = NULL;
+       int ret;
+
+       wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan");
+
+       if (req->n_ssids) {
+               ssid = req->ssids[0].ssid;
+               ssid_len = req->ssids[0].ssid_len;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->scanning) {
+               wl1251_debug(DEBUG_SCAN, "scan already in progress");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = wl1251_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
+                                    req->ie, req->ie_len);
+       if (!skb) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, skb->data,
+                                     skb->len);
+       dev_kfree_skb(skb);
+       if (ret < 0)
+               goto out_sleep;
+
+       ret = wl1251_cmd_trigger_scan_to(wl, 0);
+       if (ret < 0)
+               goto out_sleep;
+
+       wl->scanning = true;
+
+       ret = wl1251_cmd_scan(wl, ssid, ssid_len, req->channels,
+                             req->n_channels, WL1251_SCAN_NUM_PROBES);
+       if (ret < 0) {
+               wl->scanning = false;
+               goto out_sleep;
+       }
+
+out_sleep:
+       wl1251_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+static int wl1251_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
+{
+       struct wl1251 *wl = hw->priv;
+       int ret;
+
+       mutex_lock(&wl->mutex);
+
+       ret = wl1251_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1251_acx_rts_threshold(wl, (u16) value);
+       if (ret < 0)
+               wl1251_warning("wl1251_op_set_rts_threshold failed: %d", ret);
+
+       wl1251_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
+                                      struct ieee80211_vif *vif,
+                                      struct ieee80211_bss_conf *bss_conf,
+                                      u32 changed)
+{
+       struct wl1251 *wl = hw->priv;
+       struct sk_buff *beacon, *skb;
+       int ret;
+
+       wl1251_debug(DEBUG_MAC80211, "mac80211 bss info changed");
+
+       mutex_lock(&wl->mutex);
+
+       ret = wl1251_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       if (changed & BSS_CHANGED_CQM) {
+               ret = wl1251_acx_low_rssi(wl, bss_conf->cqm_rssi_thold,
+                                         WL1251_DEFAULT_LOW_RSSI_WEIGHT,
+                                         WL1251_DEFAULT_LOW_RSSI_DEPTH,
+                                         WL1251_ACX_LOW_RSSI_TYPE_EDGE);
+               if (ret < 0)
+                       goto out;
+               wl->rssi_thold = bss_conf->cqm_rssi_thold;
+       }
+
+       if (changed & BSS_CHANGED_BSSID) {
+               memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
+
+               skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
+               if (!skb)
+                       goto out_sleep;
+
+               ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA,
+                                             skb->data, skb->len);
+               dev_kfree_skb(skb);
+               if (ret < 0)
+                       goto out_sleep;
+
+               ret = wl1251_build_qos_null_data(wl);
+               if (ret < 0)
+                       goto out;
+
+               if (wl->bss_type != BSS_TYPE_IBSS) {
+                       ret = wl1251_join(wl, wl->bss_type, wl->channel,
+                                         wl->beacon_int, wl->dtim_period);
+                       if (ret < 0)
+                               goto out_sleep;
+               }
+       }
+
+       if (changed & BSS_CHANGED_ASSOC) {
+               if (bss_conf->assoc) {
+                       wl->beacon_int = bss_conf->beacon_int;
+
+                       skb = ieee80211_pspoll_get(wl->hw, wl->vif);
+                       if (!skb)
+                               goto out_sleep;
+
+                       ret = wl1251_cmd_template_set(wl, CMD_PS_POLL,
+                                                     skb->data,
+                                                     skb->len);
+                       dev_kfree_skb(skb);
+                       if (ret < 0)
+                               goto out_sleep;
+
+                       ret = wl1251_acx_aid(wl, bss_conf->aid);
+                       if (ret < 0)
+                               goto out_sleep;
+               } else {
+                       /* use defaults when not associated */
+                       wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
+                       wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD;
+               }
+       }
+       if (changed & BSS_CHANGED_ERP_SLOT) {
+               if (bss_conf->use_short_slot)
+                       ret = wl1251_acx_slot(wl, SLOT_TIME_SHORT);
+               else
+                       ret = wl1251_acx_slot(wl, SLOT_TIME_LONG);
+               if (ret < 0) {
+                       wl1251_warning("Set slot time failed %d", ret);
+                       goto out_sleep;
+               }
+       }
+
+       if (changed & BSS_CHANGED_ERP_PREAMBLE) {
+               if (bss_conf->use_short_preamble)
+                       wl1251_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
+               else
+                       wl1251_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
+       }
+
+       if (changed & BSS_CHANGED_ERP_CTS_PROT) {
+               if (bss_conf->use_cts_prot)
+                       ret = wl1251_acx_cts_protect(wl, CTSPROTECT_ENABLE);
+               else
+                       ret = wl1251_acx_cts_protect(wl, CTSPROTECT_DISABLE);
+               if (ret < 0) {
+                       wl1251_warning("Set ctsprotect failed %d", ret);
+                       goto out_sleep;
+               }
+       }
+
+       if (changed & BSS_CHANGED_BEACON) {
+               beacon = ieee80211_beacon_get(hw, vif);
+               if (!beacon)
+                       goto out_sleep;
+
+               ret = wl1251_cmd_template_set(wl, CMD_BEACON, beacon->data,
+                                             beacon->len);
+
+               if (ret < 0) {
+                       dev_kfree_skb(beacon);
+                       goto out_sleep;
+               }
+
+               ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
+                                             beacon->len);
+
+               dev_kfree_skb(beacon);
+
+               if (ret < 0)
+                       goto out_sleep;
+
+               ret = wl1251_join(wl, wl->bss_type, wl->beacon_int,
+                                 wl->channel, wl->dtim_period);
+
+               if (ret < 0)
+                       goto out_sleep;
+       }
+
+out_sleep:
+       wl1251_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+
+/* can't be const, mac80211 writes to this */
+static struct ieee80211_rate wl1251_rates[] = {
+       { .bitrate = 10,
+         .hw_value = 0x1,
+         .hw_value_short = 0x1, },
+       { .bitrate = 20,
+         .hw_value = 0x2,
+         .hw_value_short = 0x2,
+         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+       { .bitrate = 55,
+         .hw_value = 0x4,
+         .hw_value_short = 0x4,
+         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+       { .bitrate = 110,
+         .hw_value = 0x20,
+         .hw_value_short = 0x20,
+         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+       { .bitrate = 60,
+         .hw_value = 0x8,
+         .hw_value_short = 0x8, },
+       { .bitrate = 90,
+         .hw_value = 0x10,
+         .hw_value_short = 0x10, },
+       { .bitrate = 120,
+         .hw_value = 0x40,
+         .hw_value_short = 0x40, },
+       { .bitrate = 180,
+         .hw_value = 0x80,
+         .hw_value_short = 0x80, },
+       { .bitrate = 240,
+         .hw_value = 0x200,
+         .hw_value_short = 0x200, },
+       { .bitrate = 360,
+        .hw_value = 0x400,
+        .hw_value_short = 0x400, },
+       { .bitrate = 480,
+         .hw_value = 0x800,
+         .hw_value_short = 0x800, },
+       { .bitrate = 540,
+         .hw_value = 0x1000,
+         .hw_value_short = 0x1000, },
+};
+
+/* can't be const, mac80211 writes to this */
+static struct ieee80211_channel wl1251_channels[] = {
+       { .hw_value = 1, .center_freq = 2412},
+       { .hw_value = 2, .center_freq = 2417},
+       { .hw_value = 3, .center_freq = 2422},
+       { .hw_value = 4, .center_freq = 2427},
+       { .hw_value = 5, .center_freq = 2432},
+       { .hw_value = 6, .center_freq = 2437},
+       { .hw_value = 7, .center_freq = 2442},
+       { .hw_value = 8, .center_freq = 2447},
+       { .hw_value = 9, .center_freq = 2452},
+       { .hw_value = 10, .center_freq = 2457},
+       { .hw_value = 11, .center_freq = 2462},
+       { .hw_value = 12, .center_freq = 2467},
+       { .hw_value = 13, .center_freq = 2472},
+};
+
+static int wl1251_op_conf_tx(struct ieee80211_hw *hw,
+                            struct ieee80211_vif *vif, u16 queue,
+                            const struct ieee80211_tx_queue_params *params)
+{
+       enum wl1251_acx_ps_scheme ps_scheme;
+       struct wl1251 *wl = hw->priv;
+       int ret;
+
+       mutex_lock(&wl->mutex);
+
+       wl1251_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
+
+       ret = wl1251_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       /* mac80211 uses units of 32 usec */
+       ret = wl1251_acx_ac_cfg(wl, wl1251_tx_get_queue(queue),
+                               params->cw_min, params->cw_max,
+                               params->aifs, params->txop * 32);
+       if (ret < 0)
+               goto out_sleep;
+
+       if (params->uapsd)
+               ps_scheme = WL1251_ACX_PS_SCHEME_UPSD_TRIGGER;
+       else
+               ps_scheme = WL1251_ACX_PS_SCHEME_LEGACY;
+
+       ret = wl1251_acx_tid_cfg(wl, wl1251_tx_get_queue(queue),
+                                CHANNEL_TYPE_EDCF,
+                                wl1251_tx_get_queue(queue), ps_scheme,
+                                WL1251_ACX_ACK_POLICY_LEGACY);
+       if (ret < 0)
+               goto out_sleep;
+
+out_sleep:
+       wl1251_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+static int wl1251_op_get_survey(struct ieee80211_hw *hw, int idx,
+                               struct survey_info *survey)
+{
+       struct wl1251 *wl = hw->priv;
+       struct ieee80211_conf *conf = &hw->conf;
+       if (idx != 0)
+               return -ENOENT;
+       survey->channel = conf->channel;
+       survey->filled = SURVEY_INFO_NOISE_DBM;
+       survey->noise = wl->noise;
+       return 0;
+}
+
+/* can't be const, mac80211 writes to this */
+static struct ieee80211_supported_band wl1251_band_2ghz = {
+       .channels = wl1251_channels,
+       .n_channels = ARRAY_SIZE(wl1251_channels),
+       .bitrates = wl1251_rates,
+       .n_bitrates = ARRAY_SIZE(wl1251_rates),
+};
+
+static const struct ieee80211_ops wl1251_ops = {
+       .start = wl1251_op_start,
+       .stop = wl1251_op_stop,
+       .add_interface = wl1251_op_add_interface,
+       .remove_interface = wl1251_op_remove_interface,
+       .config = wl1251_op_config,
+       .configure_filter = wl1251_op_configure_filter,
+       .tx = wl1251_op_tx,
+       .set_key = wl1251_op_set_key,
+       .hw_scan = wl1251_op_hw_scan,
+       .bss_info_changed = wl1251_op_bss_info_changed,
+       .set_rts_threshold = wl1251_op_set_rts_threshold,
+       .conf_tx = wl1251_op_conf_tx,
+       .get_survey = wl1251_op_get_survey,
+};
+
+static int wl1251_read_eeprom_byte(struct wl1251 *wl, off_t offset, u8 *data)
+{
+       unsigned long timeout;
+
+       wl1251_reg_write32(wl, EE_ADDR, offset);
+       wl1251_reg_write32(wl, EE_CTL, EE_CTL_READ);
+
+       /* EE_CTL_READ clears when data is ready */
+       timeout = jiffies + msecs_to_jiffies(100);
+       while (1) {
+               if (!(wl1251_reg_read32(wl, EE_CTL) & EE_CTL_READ))
+                       break;
+
+               if (time_after(jiffies, timeout))
+                       return -ETIMEDOUT;
+
+               msleep(1);
+       }
+
+       *data = wl1251_reg_read32(wl, EE_DATA);
+       return 0;
+}
+
+static int wl1251_read_eeprom(struct wl1251 *wl, off_t offset,
+                             u8 *data, size_t len)
+{
+       size_t i;
+       int ret;
+
+       wl1251_reg_write32(wl, EE_START, 0);
+
+       for (i = 0; i < len; i++) {
+               ret = wl1251_read_eeprom_byte(wl, offset + i, &data[i]);
+               if (ret < 0)
+                       return ret;
+       }
+
+       return 0;
+}
+
+static int wl1251_read_eeprom_mac(struct wl1251 *wl)
+{
+       u8 mac[ETH_ALEN];
+       int i, ret;
+
+       wl1251_set_partition(wl, 0, 0, REGISTERS_BASE, REGISTERS_DOWN_SIZE);
+
+       ret = wl1251_read_eeprom(wl, 0x1c, mac, sizeof(mac));
+       if (ret < 0) {
+               wl1251_warning("failed to read MAC address from EEPROM");
+               return ret;
+       }
+
+       /* MAC is stored in reverse order */
+       for (i = 0; i < ETH_ALEN; i++)
+               wl->mac_addr[i] = mac[ETH_ALEN - i - 1];
+
+       return 0;
+}
+
+static int wl1251_register_hw(struct wl1251 *wl)
+{
+       int ret;
+
+       if (wl->mac80211_registered)
+               return 0;
+
+       SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
+
+       ret = ieee80211_register_hw(wl->hw);
+       if (ret < 0) {
+               wl1251_error("unable to register mac80211 hw: %d", ret);
+               return ret;
+       }
+
+       wl->mac80211_registered = true;
+
+       wl1251_notice("loaded");
+
+       return 0;
+}
+
+int wl1251_init_ieee80211(struct wl1251 *wl)
+{
+       int ret;
+
+       /* The tx descriptor buffer and the TKIP space */
+       wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
+               + WL1251_TKIP_IV_SPACE;
+
+       /* unit us */
+       /* FIXME: find a proper value */
+       wl->hw->channel_change_time = 10000;
+
+       wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
+               IEEE80211_HW_SUPPORTS_PS |
+               IEEE80211_HW_SUPPORTS_UAPSD;
+
+       wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
+                                        BIT(NL80211_IFTYPE_ADHOC);
+       wl->hw->wiphy->max_scan_ssids = 1;
+       wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1251_band_2ghz;
+
+       wl->hw->queues = 4;
+
+       if (wl->use_eeprom)
+               wl1251_read_eeprom_mac(wl);
+
+       ret = wl1251_register_hw(wl);
+       if (ret)
+               goto out;
+
+       wl1251_debugfs_init(wl);
+       wl1251_notice("initialized");
+
+       ret = 0;
+
+out:
+       return ret;
+}
+EXPORT_SYMBOL_GPL(wl1251_init_ieee80211);
+
+struct ieee80211_hw *wl1251_alloc_hw(void)
+{
+       struct ieee80211_hw *hw;
+       struct wl1251 *wl;
+       int i;
+       static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
+
+       hw = ieee80211_alloc_hw(sizeof(*wl), &wl1251_ops);
+       if (!hw) {
+               wl1251_error("could not alloc ieee80211_hw");
+               return ERR_PTR(-ENOMEM);
+       }
+
+       wl = hw->priv;
+       memset(wl, 0, sizeof(*wl));
+
+       wl->hw = hw;
+
+       wl->data_in_count = 0;
+
+       skb_queue_head_init(&wl->tx_queue);
+
+       INIT_WORK(&wl->filter_work, wl1251_filter_work);
+       INIT_DELAYED_WORK(&wl->elp_work, wl1251_elp_work);
+       wl->channel = WL1251_DEFAULT_CHANNEL;
+       wl->scanning = false;
+       wl->default_key = 0;
+       wl->listen_int = 1;
+       wl->rx_counter = 0;
+       wl->rx_handled = 0;
+       wl->rx_current_buffer = 0;
+       wl->rx_last_id = 0;
+       wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
+       wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
+       wl->elp = false;
+       wl->station_mode = STATION_ACTIVE_MODE;
+       wl->psm_requested = false;
+       wl->tx_queue_stopped = false;
+       wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
+       wl->rssi_thold = 0;
+       wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
+       wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD;
+       wl->vif = NULL;
+
+       for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
+               wl->tx_frames[i] = NULL;
+
+       wl->next_tx_complete = 0;
+
+       INIT_WORK(&wl->irq_work, wl1251_irq_work);
+       INIT_WORK(&wl->tx_work, wl1251_tx_work);
+
+       /*
+        * In case our MAC address is not correctly set,
+        * we use a random but Nokia MAC.
+        */
+       memcpy(wl->mac_addr, nokia_oui, 3);
+       get_random_bytes(wl->mac_addr + 3, 3);
+
+       wl->state = WL1251_STATE_OFF;
+       mutex_init(&wl->mutex);
+
+       wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE;
+       wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE;
+
+       wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
+       if (!wl->rx_descriptor) {
+               wl1251_error("could not allocate memory for rx descriptor");
+               ieee80211_free_hw(hw);
+               return ERR_PTR(-ENOMEM);
+       }
+
+       return hw;
+}
+EXPORT_SYMBOL_GPL(wl1251_alloc_hw);
+
+int wl1251_free_hw(struct wl1251 *wl)
+{
+       ieee80211_unregister_hw(wl->hw);
+
+       wl1251_debugfs_exit(wl);
+
+       kfree(wl->target_mem_map);
+       kfree(wl->data_path);
+       vfree(wl->fw);
+       wl->fw = NULL;
+       kfree(wl->nvs);
+       wl->nvs = NULL;
+
+       kfree(wl->rx_descriptor);
+       wl->rx_descriptor = NULL;
+
+       ieee80211_free_hw(wl->hw);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wl1251_free_hw);
+
+MODULE_DESCRIPTION("TI wl1251 Wireles LAN Driver Core");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Kalle Valo <kvalo@adurom.com>");
+MODULE_FIRMWARE(WL1251_FW_NAME);
diff --git a/drivers/net/wireless/ti/wl1251/ps.c b/drivers/net/wireless/ti/wl1251/ps.c
new file mode 100644 (file)
index 0000000..db719f7
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "reg.h"
+#include "ps.h"
+#include "cmd.h"
+#include "io.h"
+
+/* in ms */
+#define WL1251_WAKEUP_TIMEOUT 100
+
+void wl1251_elp_work(struct work_struct *work)
+{
+       struct delayed_work *dwork;
+       struct wl1251 *wl;
+
+       dwork = container_of(work, struct delayed_work, work);
+       wl = container_of(dwork, struct wl1251, elp_work);
+
+       wl1251_debug(DEBUG_PSM, "elp work");
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->elp || wl->station_mode == STATION_ACTIVE_MODE)
+               goto out;
+
+       wl1251_debug(DEBUG_PSM, "chip to elp");
+       wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
+       wl->elp = true;
+
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+#define ELP_ENTRY_DELAY  5
+
+/* Routines to toggle sleep mode while in ELP */
+void wl1251_ps_elp_sleep(struct wl1251 *wl)
+{
+       unsigned long delay;
+
+       if (wl->station_mode != STATION_ACTIVE_MODE) {
+               delay = msecs_to_jiffies(ELP_ENTRY_DELAY);
+               ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, delay);
+       }
+}
+
+int wl1251_ps_elp_wakeup(struct wl1251 *wl)
+{
+       unsigned long timeout, start;
+       u32 elp_reg;
+
+       if (delayed_work_pending(&wl->elp_work))
+               cancel_delayed_work(&wl->elp_work);
+
+       if (!wl->elp)
+               return 0;
+
+       wl1251_debug(DEBUG_PSM, "waking up chip from elp");
+
+       start = jiffies;
+       timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT);
+
+       wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
+
+       elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
+
+       /*
+        * FIXME: we should wait for irq from chip but, as a temporary
+        * solution to simplify locking, let's poll instead
+        */
+       while (!(elp_reg & ELPCTRL_WLAN_READY)) {
+               if (time_after(jiffies, timeout)) {
+                       wl1251_error("elp wakeup timeout");
+                       return -ETIMEDOUT;
+               }
+               msleep(1);
+               elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
+       }
+
+       wl1251_debug(DEBUG_PSM, "wakeup time: %u ms",
+                    jiffies_to_msecs(jiffies - start));
+
+       wl->elp = false;
+
+       return 0;
+}
+
+int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_station_mode mode)
+{
+       int ret;
+
+       switch (mode) {
+       case STATION_POWER_SAVE_MODE:
+               wl1251_debug(DEBUG_PSM, "entering psm");
+
+               /* enable beacon filtering */
+               ret = wl1251_acx_beacon_filter_opt(wl, true);
+               if (ret < 0)
+                       return ret;
+
+               ret = wl1251_acx_wake_up_conditions(wl,
+                                                   WAKE_UP_EVENT_DTIM_BITMAP,
+                                                   wl->listen_int);
+               if (ret < 0)
+                       return ret;
+
+               ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_ENABLE,
+                                           WL1251_DEFAULT_BET_CONSECUTIVE);
+               if (ret < 0)
+                       return ret;
+
+               ret = wl1251_cmd_ps_mode(wl, CHIP_POWER_SAVE_MODE);
+               if (ret < 0)
+                       return ret;
+
+               ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
+               if (ret < 0)
+                       return ret;
+               break;
+       case STATION_IDLE:
+               wl1251_debug(DEBUG_PSM, "entering idle");
+
+               ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
+               if (ret < 0)
+                       return ret;
+
+               ret = wl1251_cmd_template_set(wl, CMD_DISCONNECT, NULL, 0);
+               if (ret < 0)
+                       return ret;
+               break;
+       case STATION_ACTIVE_MODE:
+       default:
+               wl1251_debug(DEBUG_PSM, "leaving psm");
+
+               ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
+               if (ret < 0)
+                       return ret;
+
+               /* disable BET */
+               ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_DISABLE,
+                                           WL1251_DEFAULT_BET_CONSECUTIVE);
+               if (ret < 0)
+                       return ret;
+
+               /* disable beacon filtering */
+               ret = wl1251_acx_beacon_filter_opt(wl, false);
+               if (ret < 0)
+                       return ret;
+
+               ret = wl1251_acx_wake_up_conditions(wl,
+                                                   WAKE_UP_EVENT_DTIM_BITMAP,
+                                                   wl->listen_int);
+               if (ret < 0)
+                       return ret;
+
+               ret = wl1251_cmd_ps_mode(wl, CHIP_ACTIVE_MODE);
+               if (ret < 0)
+                       return ret;
+
+               break;
+       }
+       wl->station_mode = mode;
+
+       return ret;
+}
+
diff --git a/drivers/net/wireless/ti/wl1251/ps.h b/drivers/net/wireless/ti/wl1251/ps.h
new file mode 100644 (file)
index 0000000..75efad2
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (c) 1998-2007 Texas Instruments Incorporated
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL1251_PS_H__
+#define __WL1251_PS_H__
+
+#include "wl1251.h"
+#include "acx.h"
+
+int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_station_mode mode);
+void wl1251_ps_elp_sleep(struct wl1251 *wl);
+int wl1251_ps_elp_wakeup(struct wl1251 *wl);
+void wl1251_elp_work(struct work_struct *work);
+
+
+#endif /* __WL1251_PS_H__ */
diff --git a/drivers/net/wireless/ti/wl1251/reg.h b/drivers/net/wireless/ti/wl1251/reg.h
new file mode 100644 (file)
index 0000000..a580901
--- /dev/null
@@ -0,0 +1,655 @@
+/*
+ * This file is part of wl12xx
+ *
+ * Copyright (c) 1998-2007 Texas Instruments Incorporated
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __REG_H__
+#define __REG_H__
+
+#include <linux/bitops.h>
+
+#define REGISTERS_BASE 0x00300000
+#define DRPW_BASE      0x00310000
+
+#define REGISTERS_DOWN_SIZE 0x00008800
+#define REGISTERS_WORK_SIZE 0x0000b000
+
+#define HW_ACCESS_ELP_CTRL_REG_ADDR         0x1FFFC
+
+/* ELP register commands */
+#define ELPCTRL_WAKE_UP             0x1
+#define ELPCTRL_WAKE_UP_WLAN_READY  0x5
+#define ELPCTRL_SLEEP               0x0
+/* ELP WLAN_READY bit */
+#define ELPCTRL_WLAN_READY          0x2
+
+/* Device Configuration registers*/
+#define SOR_CFG                        (REGISTERS_BASE + 0x0800)
+#define ECPU_CTRL                      (REGISTERS_BASE + 0x0804)
+#define HI_CFG                         (REGISTERS_BASE + 0x0808)
+
+/* EEPROM registers */
+#define EE_START                       (REGISTERS_BASE + 0x080C)
+#define EE_CTL                         (REGISTERS_BASE + 0x2000)
+#define EE_DATA                        (REGISTERS_BASE + 0x2004)
+#define EE_ADDR                        (REGISTERS_BASE + 0x2008)
+
+#define EE_CTL_READ                   2
+
+#define CHIP_ID_B                      (REGISTERS_BASE + 0x5674)
+
+#define CHIP_ID_1251_PG10                 (0x7010101)
+#define CHIP_ID_1251_PG11                 (0x7020101)
+#define CHIP_ID_1251_PG12                 (0x7030101)
+
+#define ENABLE                         (REGISTERS_BASE + 0x5450)
+
+/* Power Management registers */
+#define ELP_CFG_MODE                   (REGISTERS_BASE + 0x5804)
+#define ELP_CMD                        (REGISTERS_BASE + 0x5808)
+#define PLL_CAL_TIME                   (REGISTERS_BASE + 0x5810)
+#define CLK_REQ_TIME                   (REGISTERS_BASE + 0x5814)
+#define CLK_BUF_TIME                   (REGISTERS_BASE + 0x5818)
+
+#define CFG_PLL_SYNC_CNT               (REGISTERS_BASE + 0x5820)
+
+/* Scratch Pad registers*/
+#define SCR_PAD0                       (REGISTERS_BASE + 0x5608)
+#define SCR_PAD1                       (REGISTERS_BASE + 0x560C)
+#define SCR_PAD2                       (REGISTERS_BASE + 0x5610)
+#define SCR_PAD3                       (REGISTERS_BASE + 0x5614)
+#define SCR_PAD4                       (REGISTERS_BASE + 0x5618)
+#define SCR_PAD4_SET                   (REGISTERS_BASE + 0x561C)
+#define SCR_PAD4_CLR                   (REGISTERS_BASE + 0x5620)
+#define SCR_PAD5                       (REGISTERS_BASE + 0x5624)
+#define SCR_PAD5_SET                   (REGISTERS_BASE + 0x5628)
+#define SCR_PAD5_CLR                   (REGISTERS_BASE + 0x562C)
+#define SCR_PAD6                       (REGISTERS_BASE + 0x5630)
+#define SCR_PAD7                       (REGISTERS_BASE + 0x5634)
+#define SCR_PAD8                       (REGISTERS_BASE + 0x5638)
+#define SCR_PAD9                       (REGISTERS_BASE + 0x563C)
+
+/* Spare registers*/
+#define SPARE_A1                       (REGISTERS_BASE + 0x0994)
+#define SPARE_A2                       (REGISTERS_BASE + 0x0998)
+#define SPARE_A3                       (REGISTERS_BASE + 0x099C)
+#define SPARE_A4                       (REGISTERS_BASE + 0x09A0)
+#define SPARE_A5                       (REGISTERS_BASE + 0x09A4)
+#define SPARE_A6                       (REGISTERS_BASE + 0x09A8)
+#define SPARE_A7                       (REGISTERS_BASE + 0x09AC)
+#define SPARE_A8                       (REGISTERS_BASE + 0x09B0)
+#define SPARE_B1                       (REGISTERS_BASE + 0x5420)
+#define SPARE_B2                       (REGISTERS_BASE + 0x5424)
+#define SPARE_B3                       (REGISTERS_BASE + 0x5428)
+#define SPARE_B4                       (REGISTERS_BASE + 0x542C)
+#define SPARE_B5                       (REGISTERS_BASE + 0x5430)
+#define SPARE_B6                       (REGISTERS_BASE + 0x5434)
+#define SPARE_B7                       (REGISTERS_BASE + 0x5438)
+#define SPARE_B8                       (REGISTERS_BASE + 0x543C)
+
+enum wl12xx_acx_int_reg {
+       ACX_REG_INTERRUPT_TRIG,
+       ACX_REG_INTERRUPT_TRIG_H,
+
+/*=============================================
+  Host Interrupt Mask Register - 32bit (RW)
+  ------------------------------------------
+  Setting a bit in this register masks the
+  corresponding interrupt to the host.
+  0 - RX0              - Rx first dubble buffer Data Interrupt
+  1 - TXD              - Tx Data Interrupt
+  2 - TXXFR            - Tx Transfer Interrupt
+  3 - RX1              - Rx second dubble buffer Data Interrupt
+  4 - RXXFR            - Rx Transfer Interrupt
+  5 - EVENT_A  - Event Mailbox interrupt
+  6 - EVENT_B  - Event Mailbox interrupt
+  7 - WNONHST  - Wake On Host Interrupt
+  8 - TRACE_A  - Debug Trace interrupt
+  9 - TRACE_B  - Debug Trace interrupt
+ 10 - CDCMP            - Command Complete Interrupt
+ 11 -
+ 12 -
+ 13 -
+ 14 - ICOMP            - Initialization Complete Interrupt
+ 16 - SG SE            - Soft Gemini - Sense enable interrupt
+ 17 - SG SD            - Soft Gemini - Sense disable interrupt
+ 18 -                  -
+ 19 -                  -
+ 20 -                  -
+ 21-                   -
+ Default: 0x0001
+*==============================================*/
+       ACX_REG_INTERRUPT_MASK,
+
+/*=============================================
+  Host Interrupt Mask Set 16bit, (Write only)
+  ------------------------------------------
+ Setting a bit in this register sets
+ the corresponding bin in ACX_HINT_MASK register
+ without effecting the mask
+ state of other bits (0 = no effect).
+==============================================*/
+       ACX_REG_HINT_MASK_SET,
+
+/*=============================================
+  Host Interrupt Mask Clear 16bit,(Write only)
+  ------------------------------------------
+ Setting a bit in this register clears
+ the corresponding bin in ACX_HINT_MASK register
+ without effecting the mask
+ state of other bits (0 = no effect).
+=============================================*/
+       ACX_REG_HINT_MASK_CLR,
+
+/*=============================================
+  Host Interrupt Status Nondestructive Read
+  16bit,(Read only)
+  ------------------------------------------
+ The host can read this register to determine
+ which interrupts are active.
+ Reading this register doesn't
+ effect its content.
+=============================================*/
+       ACX_REG_INTERRUPT_NO_CLEAR,
+
+/*=============================================
+  Host Interrupt Status Clear on Read  Register
+  16bit,(Read only)
+  ------------------------------------------
+ The host can read this register to determine
+ which interrupts are active.
+ Reading this register clears it,
+ thus making all interrupts inactive.
+==============================================*/
+       ACX_REG_INTERRUPT_CLEAR,
+
+/*=============================================
+  Host Interrupt Acknowledge Register
+  16bit,(Write only)
+  ------------------------------------------
+ The host can set individual bits in this
+ register to clear (acknowledge) the corresp.
+ interrupt status bits in the HINT_STS_CLR and
+ HINT_STS_ND registers, thus making the
+ assotiated interrupt inactive. (0-no effect)
+==============================================*/
+       ACX_REG_INTERRUPT_ACK,
+
+/*===============================================
+   Host Software Reset - 32bit RW
+ ------------------------------------------
+    [31:1] Reserved
+    0  SOFT_RESET Soft Reset  - When this bit is set,
+    it holds the Wlan hardware in a soft reset state.
+    This reset disables all MAC and baseband processor
+    clocks except the CardBus/PCI interface clock.
+    It also initializes all MAC state machines except
+    the host interface. It does not reload the
+    contents of the EEPROM. When this bit is cleared
+    (not self-clearing), the Wlan hardware
+    exits the software reset state.
+===============================================*/
+       ACX_REG_SLV_SOFT_RESET,
+
+/*===============================================
+ EEPROM Burst Read Start  - 32bit RW
+ ------------------------------------------
+ [31:1] Reserved
+ 0  ACX_EE_START -  EEPROM Burst Read Start 0
+ Setting this bit starts a burst read from
+ the external EEPROM.
+ If this bit is set (after reset) before an EEPROM read/write,
+ the burst read starts at EEPROM address 0.
+ Otherwise, it starts at the address
+ following the address of the previous access.
+ TheWlan hardware hardware clears this bit automatically.
+
+ Default: 0x00000000
+*================================================*/
+       ACX_REG_EE_START,
+
+/* Embedded ARM CPU Control */
+
+/*===============================================
+ Halt eCPU   - 32bit RW
+ ------------------------------------------
+ 0 HALT_ECPU Halt Embedded CPU - This bit is the
+ compliment of bit 1 (MDATA2) in the SOR_CFG register.
+ During a hardware reset, this bit holds
+ the inverse of MDATA2.
+ When downloading firmware from the host,
+ set this bit (pull down MDATA2).
+ The host clears this bit after downloading the firmware into
+ zero-wait-state SSRAM.
+ When loading firmware from Flash, clear this bit (pull up MDATA2)
+ so that the eCPU can run the bootloader code in Flash
+ HALT_ECPU eCPU State
+ --------------------
+ 1 halt eCPU
+ 0 enable eCPU
+ ===============================================*/
+       ACX_REG_ECPU_CONTROL,
+
+       ACX_REG_TABLE_LEN
+};
+
+#define ACX_SLV_SOFT_RESET_BIT   BIT(0)
+#define ACX_REG_EEPROM_START_BIT BIT(0)
+
+/* Command/Information Mailbox Pointers */
+
+/*===============================================
+  Command Mailbox Pointer - 32bit RW
+ ------------------------------------------
+ This register holds the start address of
+ the command mailbox located in the Wlan hardware memory.
+ The host must read this pointer after a reset to
+ find the location of the command mailbox.
+ The Wlan hardware initializes the command mailbox
+ pointer with the default address of the command mailbox.
+ The command mailbox pointer is not valid until after
+ the host receives the Init Complete interrupt from
+ the Wlan hardware.
+ ===============================================*/
+#define REG_COMMAND_MAILBOX_PTR                                (SCR_PAD0)
+
+/*===============================================
+  Information Mailbox Pointer - 32bit RW
+ ------------------------------------------
+ This register holds the start address of
+ the information mailbox located in the Wlan hardware memory.
+ The host must read this pointer after a reset to find
+ the location of the information mailbox.
+ The Wlan hardware initializes the information mailbox pointer
+ with the default address of the information mailbox.
+ The information mailbox pointer is not valid
+ until after the host receives the Init Complete interrupt from
+ the Wlan hardware.
+ ===============================================*/
+#define REG_EVENT_MAILBOX_PTR                          (SCR_PAD1)
+
+
+/* Misc */
+
+#define REG_ENABLE_TX_RX                               (ENABLE)
+/*
+ * Rx configuration (filter) information element
+ * ---------------------------------------------
+ */
+#define REG_RX_CONFIG                          (RX_CFG)
+#define REG_RX_FILTER                          (RX_FILTER_CFG)
+
+
+#define RX_CFG_ENABLE_PHY_HEADER_PLCP   0x0002
+
+/* promiscuous - receives all valid frames */
+#define RX_CFG_PROMISCUOUS              0x0008
+
+/* receives frames from any BSSID */
+#define RX_CFG_BSSID                    0x0020
+
+/* receives frames destined to any MAC address */
+#define RX_CFG_MAC                      0x0010
+
+#define RX_CFG_ENABLE_ONLY_MY_DEST_MAC  0x0010
+#define RX_CFG_ENABLE_ANY_DEST_MAC      0x0000
+#define RX_CFG_ENABLE_ONLY_MY_BSSID     0x0020
+#define RX_CFG_ENABLE_ANY_BSSID                 0x0000
+
+/* discards all broadcast frames */
+#define RX_CFG_DISABLE_BCAST            0x0200
+
+#define RX_CFG_ENABLE_ONLY_MY_SSID      0x0400
+#define RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR 0x0800
+#define RX_CFG_COPY_RX_STATUS           0x2000
+#define RX_CFG_TSF                      0x10000
+
+#define RX_CONFIG_OPTION_ANY_DST_MY_BSS         (RX_CFG_ENABLE_ANY_DEST_MAC | \
+                                         RX_CFG_ENABLE_ONLY_MY_BSSID)
+
+#define RX_CONFIG_OPTION_MY_DST_ANY_BSS         (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\
+                                         | RX_CFG_ENABLE_ANY_BSSID)
+
+#define RX_CONFIG_OPTION_ANY_DST_ANY_BSS (RX_CFG_ENABLE_ANY_DEST_MAC | \
+                                         RX_CFG_ENABLE_ANY_BSSID)
+
+#define RX_CONFIG_OPTION_MY_DST_MY_BSS  (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\
+                                         | RX_CFG_ENABLE_ONLY_MY_BSSID)
+
+#define RX_CONFIG_OPTION_FOR_SCAN  (RX_CFG_ENABLE_PHY_HEADER_PLCP \
+                                   | RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR \
+                                   | RX_CFG_COPY_RX_STATUS | RX_CFG_TSF)
+
+#define RX_CONFIG_OPTION_FOR_MEASUREMENT (RX_CFG_ENABLE_ANY_DEST_MAC)
+
+#define RX_CONFIG_OPTION_FOR_JOIN       (RX_CFG_ENABLE_ONLY_MY_BSSID | \
+                                         RX_CFG_ENABLE_ONLY_MY_DEST_MAC)
+
+#define RX_CONFIG_OPTION_FOR_IBSS_JOIN   (RX_CFG_ENABLE_ONLY_MY_SSID | \
+                                         RX_CFG_ENABLE_ONLY_MY_DEST_MAC)
+
+#define RX_FILTER_OPTION_DEF         (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\
+                                      | CFG_RX_CTL_EN | CFG_RX_BCN_EN\
+                                      | CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
+
+#define RX_FILTER_OPTION_FILTER_ALL     0
+
+#define RX_FILTER_OPTION_DEF_PRSP_BCN  (CFG_RX_PRSP_EN | CFG_RX_MGMT_EN\
+                                       | CFG_RX_RCTS_ACK | CFG_RX_BCN_EN)
+
+#define RX_FILTER_OPTION_JOIN       (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\
+                                     | CFG_RX_BCN_EN | CFG_RX_AUTH_EN\
+                                     | CFG_RX_ASSOC_EN | CFG_RX_RCTS_ACK\
+                                     | CFG_RX_PRSP_EN)
+
+
+/*===============================================
+ EEPROM Read/Write Request 32bit RW
+ ------------------------------------------
+ 1 EE_READ - EEPROM Read Request 1 - Setting this bit
+ loads a single byte of data into the EE_DATA
+ register from the EEPROM location specified in
+ the EE_ADDR register.
+ The Wlan hardware hardware clears this bit automatically.
+ EE_DATA is valid when this bit is cleared.
+
+ 0 EE_WRITE  - EEPROM Write Request  - Setting this bit
+ writes a single byte of data from the EE_DATA register into the
+ EEPROM location specified in the EE_ADDR register.
+ The Wlan hardware hardware clears this bit automatically.
+*===============================================*/
+#define EE_CTL                              (REGISTERS_BASE + 0x2000)
+#define ACX_EE_CTL_REG                      EE_CTL
+#define EE_WRITE                            0x00000001ul
+#define EE_READ                             0x00000002ul
+
+/*===============================================
+  EEPROM Address  - 32bit RW
+  ------------------------------------------
+  This register specifies the address
+  within the EEPROM from/to which to read/write data.
+  ===============================================*/
+#define EE_ADDR                             (REGISTERS_BASE + 0x2008)
+#define ACX_EE_ADDR_REG                     EE_ADDR
+
+/*===============================================
+  EEPROM Data  - 32bit RW
+  ------------------------------------------
+  This register either holds the read 8 bits of
+  data from the EEPROM or the write data
+  to be written to the EEPROM.
+  ===============================================*/
+#define EE_DATA                             (REGISTERS_BASE + 0x2004)
+#define ACX_EE_DATA_REG                     EE_DATA
+
+#define EEPROM_ACCESS_TO                    10000   /* timeout counter */
+#define START_EEPROM_MGR                    0x00000001
+
+/*===============================================
+  EEPROM Base Address  - 32bit RW
+  ------------------------------------------
+  This register holds the upper nine bits
+  [23:15] of the 24-bit Wlan hardware memory
+  address for burst reads from EEPROM accesses.
+  The EEPROM provides the lower 15 bits of this address.
+  The MSB of the address from the EEPROM is ignored.
+  ===============================================*/
+#define ACX_EE_CFG                          EE_CFG
+
+/*===============================================
+  GPIO Output Values  -32bit, RW
+  ------------------------------------------
+  [31:16]  Reserved
+  [15: 0]  Specify the output values (at the output driver inputs) for
+  GPIO[15:0], respectively.
+  ===============================================*/
+#define ACX_GPIO_OUT_REG            GPIO_OUT
+#define ACX_MAX_GPIO_LINES          15
+
+/*===============================================
+  Contention window  -32bit, RW
+  ------------------------------------------
+  [31:26]  Reserved
+  [25:16]  Max (0x3ff)
+  [15:07]  Reserved
+  [06:00]  Current contention window value - default is 0x1F
+  ===============================================*/
+#define ACX_CONT_WIND_CFG_REG    CONT_WIND_CFG
+#define ACX_CONT_WIND_MIN_MASK   0x0000007f
+#define ACX_CONT_WIND_MAX        0x03ff0000
+
+/*===============================================
+  HI_CFG Interface Configuration Register Values
+  ------------------------------------------
+  ===============================================*/
+#define HI_CFG_UART_ENABLE          0x00000004
+#define HI_CFG_RST232_ENABLE        0x00000008
+#define HI_CFG_CLOCK_REQ_SELECT     0x00000010
+#define HI_CFG_HOST_INT_ENABLE      0x00000020
+#define HI_CFG_VLYNQ_OUTPUT_ENABLE  0x00000040
+#define HI_CFG_HOST_INT_ACTIVE_LOW  0x00000080
+#define HI_CFG_UART_TX_OUT_GPIO_15  0x00000100
+#define HI_CFG_UART_TX_OUT_GPIO_14  0x00000200
+#define HI_CFG_UART_TX_OUT_GPIO_7   0x00000400
+
+/*
+ * NOTE: USE_ACTIVE_HIGH compilation flag should be defined in makefile
+ *       for platforms using active high interrupt level
+ */
+#ifdef USE_ACTIVE_HIGH
+#define HI_CFG_DEF_VAL              \
+       (HI_CFG_UART_ENABLE |        \
+       HI_CFG_RST232_ENABLE |      \
+       HI_CFG_CLOCK_REQ_SELECT |   \
+       HI_CFG_HOST_INT_ENABLE)
+#else
+#define HI_CFG_DEF_VAL              \
+       (HI_CFG_UART_ENABLE |        \
+       HI_CFG_RST232_ENABLE |      \
+       HI_CFG_CLOCK_REQ_SELECT |   \
+       HI_CFG_HOST_INT_ENABLE)
+
+#endif
+
+#define REF_FREQ_19_2                       0
+#define REF_FREQ_26_0                       1
+#define REF_FREQ_38_4                       2
+#define REF_FREQ_40_0                       3
+#define REF_FREQ_33_6                       4
+#define REF_FREQ_NUM                        5
+
+#define LUT_PARAM_INTEGER_DIVIDER           0
+#define LUT_PARAM_FRACTIONAL_DIVIDER        1
+#define LUT_PARAM_ATTN_BB                   2
+#define LUT_PARAM_ALPHA_BB                  3
+#define LUT_PARAM_STOP_TIME_BB              4
+#define LUT_PARAM_BB_PLL_LOOP_FILTER        5
+#define LUT_PARAM_NUM                       6
+
+#define ACX_EEPROMLESS_IND_REG              (SCR_PAD4)
+#define USE_EEPROM                          0
+#define SOFT_RESET_MAX_TIME                 1000000
+#define SOFT_RESET_STALL_TIME               1000
+#define NVS_DATA_BUNDARY_ALIGNMENT          4
+
+
+/* Firmware image load chunk size */
+#define CHUNK_SIZE          512
+
+/* Firmware image header size */
+#define FW_HDR_SIZE 8
+
+#define ECPU_CONTROL_HALT                                      0x00000101
+
+
+/******************************************************************************
+
+    CHANNELS, BAND & REG DOMAINS definitions
+
+******************************************************************************/
+
+
+enum {
+       RADIO_BAND_2_4GHZ = 0,  /* 2.4 Ghz band */
+       RADIO_BAND_5GHZ = 1,    /* 5 Ghz band */
+       RADIO_BAND_JAPAN_4_9_GHZ = 2,
+       DEFAULT_BAND = RADIO_BAND_2_4GHZ,
+       INVALID_BAND = 0xFE,
+       MAX_RADIO_BANDS = 0xFF
+};
+
+enum {
+       NO_RATE      = 0,
+       RATE_1MBPS   = 0x0A,
+       RATE_2MBPS   = 0x14,
+       RATE_5_5MBPS = 0x37,
+       RATE_6MBPS   = 0x0B,
+       RATE_9MBPS   = 0x0F,
+       RATE_11MBPS  = 0x6E,
+       RATE_12MBPS  = 0x0A,
+       RATE_18MBPS  = 0x0E,
+       RATE_22MBPS  = 0xDC,
+       RATE_24MBPS  = 0x09,
+       RATE_36MBPS  = 0x0D,
+       RATE_48MBPS  = 0x08,
+       RATE_54MBPS  = 0x0C
+};
+
+enum {
+       RATE_INDEX_1MBPS   =  0,
+       RATE_INDEX_2MBPS   =  1,
+       RATE_INDEX_5_5MBPS =  2,
+       RATE_INDEX_6MBPS   =  3,
+       RATE_INDEX_9MBPS   =  4,
+       RATE_INDEX_11MBPS  =  5,
+       RATE_INDEX_12MBPS  =  6,
+       RATE_INDEX_18MBPS  =  7,
+       RATE_INDEX_22MBPS  =  8,
+       RATE_INDEX_24MBPS  =  9,
+       RATE_INDEX_36MBPS  =  10,
+       RATE_INDEX_48MBPS  =  11,
+       RATE_INDEX_54MBPS  =  12,
+       RATE_INDEX_MAX     =  RATE_INDEX_54MBPS,
+       MAX_RATE_INDEX,
+       INVALID_RATE_INDEX = MAX_RATE_INDEX,
+       RATE_INDEX_ENUM_MAX_SIZE = 0x7FFFFFFF
+};
+
+enum {
+       RATE_MASK_1MBPS = 0x1,
+       RATE_MASK_2MBPS = 0x2,
+       RATE_MASK_5_5MBPS = 0x4,
+       RATE_MASK_11MBPS = 0x20,
+};
+
+#define SHORT_PREAMBLE_BIT   BIT(0) /* CCK or Barker depending on the rate */
+#define OFDM_RATE_BIT        BIT(6)
+#define PBCC_RATE_BIT        BIT(7)
+
+enum {
+       CCK_LONG = 0,
+       CCK_SHORT = SHORT_PREAMBLE_BIT,
+       PBCC_LONG = PBCC_RATE_BIT,
+       PBCC_SHORT = PBCC_RATE_BIT | SHORT_PREAMBLE_BIT,
+       OFDM = OFDM_RATE_BIT
+};
+
+/******************************************************************************
+
+Transmit-Descriptor RATE-SET field definitions...
+
+Define a new "Rate-Set" for TX path that incorporates the
+Rate & Modulation info into a single 16-bit field.
+
+TxdRateSet_t:
+b15   - Indicates Preamble type (1=SHORT, 0=LONG).
+       Notes:
+       Must be LONG (0) for 1Mbps rate.
+       Does not apply (set to 0) for RevG-OFDM rates.
+b14   - Indicates PBCC encoding (1=PBCC, 0=not).
+       Notes:
+       Does not apply (set to 0) for rates 1 and 2 Mbps.
+       Does not apply (set to 0) for RevG-OFDM rates.
+b13    - Unused (set to 0).
+b12-b0 - Supported Rate indicator bits as defined below.
+
+******************************************************************************/
+
+
+/*************************************************************************
+
+    Interrupt Trigger Register (Host -> WiLink)
+
+**************************************************************************/
+
+/* Hardware to Embedded CPU Interrupts - first 32-bit register set */
+
+/*
+ * Host Command Interrupt. Setting this bit masks
+ * the interrupt that the host issues to inform
+ * the FW that it has sent a command
+ * to the Wlan hardware Command Mailbox.
+ */
+#define INTR_TRIG_CMD       BIT(0)
+
+/*
+ * Host Event Acknowlegde Interrupt. The host
+ * sets this bit to acknowledge that it received
+ * the unsolicited information from the event
+ * mailbox.
+ */
+#define INTR_TRIG_EVENT_ACK BIT(1)
+
+/*
+ * The host sets this bit to inform the Wlan
+ * FW that a TX packet is in the XFER
+ * Buffer #0.
+ */
+#define INTR_TRIG_TX_PROC0 BIT(2)
+
+/*
+ * The host sets this bit to inform the FW
+ * that it read a packet from RX XFER
+ * Buffer #0.
+ */
+#define INTR_TRIG_RX_PROC0 BIT(3)
+
+#define INTR_TRIG_DEBUG_ACK BIT(4)
+
+#define INTR_TRIG_STATE_CHANGED BIT(5)
+
+
+/* Hardware to Embedded CPU Interrupts - second 32-bit register set */
+
+/*
+ * The host sets this bit to inform the FW
+ * that it read a packet from RX XFER
+ * Buffer #1.
+ */
+#define INTR_TRIG_RX_PROC1 BIT(17)
+
+/*
+ * The host sets this bit to inform the Wlan
+ * hardware that a TX packet is in the XFER
+ * Buffer #1.
+ */
+#define INTR_TRIG_TX_PROC1 BIT(18)
+
+#endif
diff --git a/drivers/net/wireless/ti/wl1251/rx.c b/drivers/net/wireless/ti/wl1251/rx.c
new file mode 100644 (file)
index 0000000..6af3526
--- /dev/null
@@ -0,0 +1,235 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (c) 1998-2007 Texas Instruments Incorporated
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/skbuff.h>
+#include <linux/gfp.h>
+#include <net/mac80211.h>
+
+#include "wl1251.h"
+#include "reg.h"
+#include "io.h"
+#include "rx.h"
+#include "cmd.h"
+#include "acx.h"
+
+static void wl1251_rx_header(struct wl1251 *wl,
+                            struct wl1251_rx_descriptor *desc)
+{
+       u32 rx_packet_ring_addr;
+
+       rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr;
+       if (wl->rx_current_buffer)
+               rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
+
+       wl1251_mem_read(wl, rx_packet_ring_addr, desc, sizeof(*desc));
+}
+
+static void wl1251_rx_status(struct wl1251 *wl,
+                            struct wl1251_rx_descriptor *desc,
+                            struct ieee80211_rx_status *status,
+                            u8 beacon)
+{
+       u64 mactime;
+       int ret;
+
+       memset(status, 0, sizeof(struct ieee80211_rx_status));
+
+       status->band = IEEE80211_BAND_2GHZ;
+       status->mactime = desc->timestamp;
+
+       /*
+        * The rx status timestamp is a 32 bits value while the TSF is a
+        * 64 bits one.
+        * For IBSS merging, TSF is mandatory, so we have to get it
+        * somehow, so we ask for ACX_TSF_INFO.
+        * That could be moved to the get_tsf() hook, but unfortunately,
+        * this one must be atomic, while our SPI routines can sleep.
+        */
+       if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) {
+               ret = wl1251_acx_tsf_info(wl, &mactime);
+               if (ret == 0)
+                       status->mactime = mactime;
+       }
+
+       status->signal = desc->rssi;
+
+       /*
+        * FIXME: guessing that snr needs to be divided by two, otherwise
+        * the values don't make any sense
+        */
+       wl->noise = desc->rssi - desc->snr / 2;
+
+       status->freq = ieee80211_channel_to_frequency(desc->channel,
+                                                     status->band);
+
+       status->flag |= RX_FLAG_MACTIME_MPDU;
+
+       if (desc->flags & RX_DESC_ENCRYPTION_MASK) {
+               status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
+
+               if (likely(!(desc->flags & RX_DESC_DECRYPT_FAIL)))
+                       status->flag |= RX_FLAG_DECRYPTED;
+
+               if (unlikely(desc->flags & RX_DESC_MIC_FAIL))
+                       status->flag |= RX_FLAG_MMIC_ERROR;
+       }
+
+       if (unlikely(!(desc->flags & RX_DESC_VALID_FCS)))
+               status->flag |= RX_FLAG_FAILED_FCS_CRC;
+
+       switch (desc->rate) {
+               /* skip 1 and 12 Mbps because they have same value 0x0a */
+       case RATE_2MBPS:
+               status->rate_idx = 1;
+               break;
+       case RATE_5_5MBPS:
+               status->rate_idx = 2;
+               break;
+       case RATE_11MBPS:
+               status->rate_idx = 3;
+               break;
+       case RATE_6MBPS:
+               status->rate_idx = 4;
+               break;
+       case RATE_9MBPS:
+               status->rate_idx = 5;
+               break;
+       case RATE_18MBPS:
+               status->rate_idx = 7;
+               break;
+       case RATE_24MBPS:
+               status->rate_idx = 8;
+               break;
+       case RATE_36MBPS:
+               status->rate_idx = 9;
+               break;
+       case RATE_48MBPS:
+               status->rate_idx = 10;
+               break;
+       case RATE_54MBPS:
+               status->rate_idx = 11;
+               break;
+       }
+
+       /* for 1 and 12 Mbps we have to check the modulation */
+       if (desc->rate == RATE_1MBPS) {
+               if (!(desc->mod_pre & OFDM_RATE_BIT))
+                       /* CCK -> RATE_1MBPS */
+                       status->rate_idx = 0;
+               else
+                       /* OFDM -> RATE_12MBPS */
+                       status->rate_idx = 6;
+       }
+
+       if (desc->mod_pre & SHORT_PREAMBLE_BIT)
+               status->flag |= RX_FLAG_SHORTPRE;
+}
+
+static void wl1251_rx_body(struct wl1251 *wl,
+                          struct wl1251_rx_descriptor *desc)
+{
+       struct sk_buff *skb;
+       struct ieee80211_rx_status status;
+       u8 *rx_buffer, beacon = 0;
+       u16 length, *fc;
+       u32 curr_id, last_id_inc, rx_packet_ring_addr;
+
+       length = WL1251_RX_ALIGN(desc->length  - PLCP_HEADER_LENGTH);
+       curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT;
+       last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1);
+
+       if (last_id_inc != curr_id) {
+               wl1251_warning("curr ID:%d, last ID inc:%d",
+                              curr_id, last_id_inc);
+               wl->rx_last_id = curr_id;
+       } else {
+               wl->rx_last_id = last_id_inc;
+       }
+
+       rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr +
+               sizeof(struct wl1251_rx_descriptor) + 20;
+       if (wl->rx_current_buffer)
+               rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
+
+       skb = __dev_alloc_skb(length, GFP_KERNEL);
+       if (!skb) {
+               wl1251_error("Couldn't allocate RX frame");
+               return;
+       }
+
+       rx_buffer = skb_put(skb, length);
+       wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
+
+       /* The actual length doesn't include the target's alignment */
+       skb->len = desc->length  - PLCP_HEADER_LENGTH;
+
+       fc = (u16 *)skb->data;
+
+       if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
+               beacon = 1;
+
+       wl1251_rx_status(wl, desc, &status, beacon);
+
+       wl1251_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
+                    beacon ? "beacon" : "");
+
+       memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
+       ieee80211_rx_ni(wl->hw, skb);
+}
+
+static void wl1251_rx_ack(struct wl1251 *wl)
+{
+       u32 data, addr;
+
+       if (wl->rx_current_buffer) {
+               addr = ACX_REG_INTERRUPT_TRIG_H;
+               data = INTR_TRIG_RX_PROC1;
+       } else {
+               addr = ACX_REG_INTERRUPT_TRIG;
+               data = INTR_TRIG_RX_PROC0;
+       }
+
+       wl1251_reg_write32(wl, addr, data);
+
+       /* Toggle buffer ring */
+       wl->rx_current_buffer = !wl->rx_current_buffer;
+}
+
+
+void wl1251_rx(struct wl1251 *wl)
+{
+       struct wl1251_rx_descriptor *rx_desc;
+
+       if (wl->state != WL1251_STATE_ON)
+               return;
+
+       rx_desc = wl->rx_descriptor;
+
+       /* We first read the frame's header */
+       wl1251_rx_header(wl, rx_desc);
+
+       /* Now we can read the body */
+       wl1251_rx_body(wl, rx_desc);
+
+       /* Finally, we need to ACK the RX */
+       wl1251_rx_ack(wl);
+}
diff --git a/drivers/net/wireless/ti/wl1251/rx.h b/drivers/net/wireless/ti/wl1251/rx.h
new file mode 100644 (file)
index 0000000..4448f63
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (c) 1998-2007 Texas Instruments Incorporated
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL1251_RX_H__
+#define __WL1251_RX_H__
+
+#include <linux/bitops.h>
+
+#include "wl1251.h"
+
+/*
+ * RX PATH
+ *
+ * The Rx path uses a double buffer and an rx_contro structure, each located
+ * at a fixed address in the device memory. The host keeps track of which
+ * buffer is available and alternates between them on a per packet basis.
+ * The size of each of the two buffers is large enough to hold the longest
+ * 802.3 packet.
+ * The RX path goes like that:
+ * 1) The target generates an interrupt each time a new packet is received.
+ *   There are 2 RX interrupts, one for each buffer.
+ * 2) The host reads the received packet from one of the double buffers.
+ * 3) The host triggers a target interrupt.
+ * 4) The target prepares the next RX packet.
+ */
+
+#define WL1251_RX_MAX_RSSI -30
+#define WL1251_RX_MIN_RSSI -95
+
+#define WL1251_RX_ALIGN_TO 4
+#define WL1251_RX_ALIGN(len) (((len) + WL1251_RX_ALIGN_TO - 1) & \
+                            ~(WL1251_RX_ALIGN_TO - 1))
+
+#define SHORT_PREAMBLE_BIT   BIT(0)
+#define OFDM_RATE_BIT        BIT(6)
+#define PBCC_RATE_BIT        BIT(7)
+
+#define PLCP_HEADER_LENGTH 8
+#define RX_DESC_PACKETID_SHIFT 11
+#define RX_MAX_PACKET_ID 3
+
+#define RX_DESC_VALID_FCS         0x0001
+#define RX_DESC_MATCH_RXADDR1     0x0002
+#define RX_DESC_MCAST             0x0004
+#define RX_DESC_STAINTIM          0x0008
+#define RX_DESC_VIRTUAL_BM        0x0010
+#define RX_DESC_BCAST             0x0020
+#define RX_DESC_MATCH_SSID        0x0040
+#define RX_DESC_MATCH_BSSID       0x0080
+#define RX_DESC_ENCRYPTION_MASK   0x0300
+#define RX_DESC_MEASURMENT        0x0400
+#define RX_DESC_SEQNUM_MASK       0x1800
+#define        RX_DESC_MIC_FAIL          0x2000
+#define        RX_DESC_DECRYPT_FAIL      0x4000
+
+struct wl1251_rx_descriptor {
+       u32 timestamp; /* In microseconds */
+       u16 length; /* Paylod length, including headers */
+       u16 flags;
+
+       /*
+        * 0 - 802.11
+        * 1 - 802.3
+        * 2 - IP
+        * 3 - Raw Codec
+        */
+       u8 type;
+
+       /*
+        * Received Rate:
+        * 0x0A - 1MBPS
+        * 0x14 - 2MBPS
+        * 0x37 - 5_5MBPS
+        * 0x0B - 6MBPS
+        * 0x0F - 9MBPS
+        * 0x6E - 11MBPS
+        * 0x0A - 12MBPS
+        * 0x0E - 18MBPS
+        * 0xDC - 22MBPS
+        * 0x09 - 24MBPS
+        * 0x0D - 36MBPS
+        * 0x08 - 48MBPS
+        * 0x0C - 54MBPS
+        */
+       u8 rate;
+
+       u8 mod_pre; /* Modulation and preamble */
+       u8 channel;
+
+       /*
+        * 0 - 2.4 Ghz
+        * 1 - 5 Ghz
+        */
+       u8 band;
+
+       s8 rssi; /* in dB */
+       u8 rcpi; /* in dB */
+       u8 snr; /* in dB */
+} __packed;
+
+void wl1251_rx(struct wl1251 *wl);
+
+#endif
diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
new file mode 100644 (file)
index 0000000..f786942
--- /dev/null
@@ -0,0 +1,374 @@
+/*
+ * wl12xx SDIO routines
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ * Copyright (C) 2005 Texas Instruments Incorporated
+ * Copyright (C) 2008 Google Inc
+ * Copyright (C) 2009 Bob Copeland (me@bobcopeland.com)
+ */
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/mod_devicetable.h>
+#include <linux/mmc/sdio_func.h>
+#include <linux/mmc/sdio_ids.h>
+#include <linux/platform_device.h>
+#include <linux/wl12xx.h>
+#include <linux/irq.h>
+#include <linux/pm_runtime.h>
+
+#include "wl1251.h"
+
+#ifndef SDIO_VENDOR_ID_TI
+#define SDIO_VENDOR_ID_TI              0x104c
+#endif
+
+#ifndef SDIO_DEVICE_ID_TI_WL1251
+#define SDIO_DEVICE_ID_TI_WL1251       0x9066
+#endif
+
+struct wl1251_sdio {
+       struct sdio_func *func;
+       u32 elp_val;
+};
+
+static struct sdio_func *wl_to_func(struct wl1251 *wl)
+{
+       struct wl1251_sdio *wl_sdio = wl->if_priv;
+       return wl_sdio->func;
+}
+
+static void wl1251_sdio_interrupt(struct sdio_func *func)
+{
+       struct wl1251 *wl = sdio_get_drvdata(func);
+
+       wl1251_debug(DEBUG_IRQ, "IRQ");
+
+       /* FIXME should be synchronous for sdio */
+       ieee80211_queue_work(wl->hw, &wl->irq_work);
+}
+
+static const struct sdio_device_id wl1251_devices[] = {
+       { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1251) },
+       {}
+};
+MODULE_DEVICE_TABLE(sdio, wl1251_devices);
+
+
+static void wl1251_sdio_read(struct wl1251 *wl, int addr,
+                            void *buf, size_t len)
+{
+       int ret;
+       struct sdio_func *func = wl_to_func(wl);
+
+       sdio_claim_host(func);
+       ret = sdio_memcpy_fromio(func, buf, addr, len);
+       if (ret)
+               wl1251_error("sdio read failed (%d)", ret);
+       sdio_release_host(func);
+}
+
+static void wl1251_sdio_write(struct wl1251 *wl, int addr,
+                             void *buf, size_t len)
+{
+       int ret;
+       struct sdio_func *func = wl_to_func(wl);
+
+       sdio_claim_host(func);
+       ret = sdio_memcpy_toio(func, addr, buf, len);
+       if (ret)
+               wl1251_error("sdio write failed (%d)", ret);
+       sdio_release_host(func);
+}
+
+static void wl1251_sdio_read_elp(struct wl1251 *wl, int addr, u32 *val)
+{
+       int ret = 0;
+       struct wl1251_sdio *wl_sdio = wl->if_priv;
+       struct sdio_func *func = wl_sdio->func;
+
+       /*
+        * The hardware only supports RAW (read after write) access for
+        * reading, regular sdio_readb won't work here (it interprets
+        * the unused bits of CMD52 as write data even if we send read
+        * request).
+        */
+       sdio_claim_host(func);
+       *val = sdio_writeb_readb(func, wl_sdio->elp_val, addr, &ret);
+       sdio_release_host(func);
+
+       if (ret)
+               wl1251_error("sdio_readb failed (%d)", ret);
+}
+
+static void wl1251_sdio_write_elp(struct wl1251 *wl, int addr, u32 val)
+{
+       int ret = 0;
+       struct wl1251_sdio *wl_sdio = wl->if_priv;
+       struct sdio_func *func = wl_sdio->func;
+
+       sdio_claim_host(func);
+       sdio_writeb(func, val, addr, &ret);
+       sdio_release_host(func);
+
+       if (ret)
+               wl1251_error("sdio_writeb failed (%d)", ret);
+       else
+               wl_sdio->elp_val = val;
+}
+
+static void wl1251_sdio_reset(struct wl1251 *wl)
+{
+}
+
+static void wl1251_sdio_enable_irq(struct wl1251 *wl)
+{
+       struct sdio_func *func = wl_to_func(wl);
+
+       sdio_claim_host(func);
+       sdio_claim_irq(func, wl1251_sdio_interrupt);
+       sdio_release_host(func);
+}
+
+static void wl1251_sdio_disable_irq(struct wl1251 *wl)
+{
+       struct sdio_func *func = wl_to_func(wl);
+
+       sdio_claim_host(func);
+       sdio_release_irq(func);
+       sdio_release_host(func);
+}
+
+/* Interrupts when using dedicated WLAN_IRQ pin */
+static irqreturn_t wl1251_line_irq(int irq, void *cookie)
+{
+       struct wl1251 *wl = cookie;
+
+       ieee80211_queue_work(wl->hw, &wl->irq_work);
+
+       return IRQ_HANDLED;
+}
+
+static void wl1251_enable_line_irq(struct wl1251 *wl)
+{
+       return enable_irq(wl->irq);
+}
+
+static void wl1251_disable_line_irq(struct wl1251 *wl)
+{
+       return disable_irq(wl->irq);
+}
+
+static int wl1251_sdio_set_power(struct wl1251 *wl, bool enable)
+{
+       struct sdio_func *func = wl_to_func(wl);
+       int ret;
+
+       if (enable) {
+               /*
+                * Power is controlled by runtime PM, but we still call board
+                * callback in case it wants to do any additional setup,
+                * for example enabling clock buffer for the module.
+                */
+               if (wl->set_power)
+                       wl->set_power(true);
+
+               ret = pm_runtime_get_sync(&func->dev);
+               if (ret < 0)
+                       goto out;
+
+               sdio_claim_host(func);
+               sdio_enable_func(func);
+               sdio_release_host(func);
+       } else {
+               sdio_claim_host(func);
+               sdio_disable_func(func);
+               sdio_release_host(func);
+
+               ret = pm_runtime_put_sync(&func->dev);
+               if (ret < 0)
+                       goto out;
+
+               if (wl->set_power)
+                       wl->set_power(false);
+       }
+
+out:
+       return ret;
+}
+
+static struct wl1251_if_operations wl1251_sdio_ops = {
+       .read = wl1251_sdio_read,
+       .write = wl1251_sdio_write,
+       .write_elp = wl1251_sdio_write_elp,
+       .read_elp = wl1251_sdio_read_elp,
+       .reset = wl1251_sdio_reset,
+       .power = wl1251_sdio_set_power,
+};
+
+static int wl1251_sdio_probe(struct sdio_func *func,
+                            const struct sdio_device_id *id)
+{
+       int ret;
+       struct wl1251 *wl;
+       struct ieee80211_hw *hw;
+       struct wl1251_sdio *wl_sdio;
+       const struct wl12xx_platform_data *wl12xx_board_data;
+
+       hw = wl1251_alloc_hw();
+       if (IS_ERR(hw))
+               return PTR_ERR(hw);
+
+       wl = hw->priv;
+
+       wl_sdio = kzalloc(sizeof(*wl_sdio), GFP_KERNEL);
+       if (wl_sdio == NULL) {
+               ret = -ENOMEM;
+               goto out_free_hw;
+       }
+
+       sdio_claim_host(func);
+       ret = sdio_enable_func(func);
+       if (ret)
+               goto release;
+
+       sdio_set_block_size(func, 512);
+       sdio_release_host(func);
+
+       SET_IEEE80211_DEV(hw, &func->dev);
+       wl_sdio->func = func;
+       wl->if_priv = wl_sdio;
+       wl->if_ops = &wl1251_sdio_ops;
+
+       wl12xx_board_data = wl12xx_get_platform_data();
+       if (!IS_ERR(wl12xx_board_data)) {
+               wl->set_power = wl12xx_board_data->set_power;
+               wl->irq = wl12xx_board_data->irq;
+               wl->use_eeprom = wl12xx_board_data->use_eeprom;
+       }
+
+       if (wl->irq) {
+               ret = request_irq(wl->irq, wl1251_line_irq, 0, "wl1251", wl);
+               if (ret < 0) {
+                       wl1251_error("request_irq() failed: %d", ret);
+                       goto disable;
+               }
+
+               irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
+               disable_irq(wl->irq);
+
+               wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
+               wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
+
+               wl1251_info("using dedicated interrupt line");
+       } else {
+               wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
+               wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
+
+               wl1251_info("using SDIO interrupt");
+       }
+
+       ret = wl1251_init_ieee80211(wl);
+       if (ret)
+               goto out_free_irq;
+
+       sdio_set_drvdata(func, wl);
+
+       /* Tell PM core that we don't need the card to be powered now */
+       pm_runtime_put_noidle(&func->dev);
+
+       return ret;
+
+out_free_irq:
+       if (wl->irq)
+               free_irq(wl->irq, wl);
+disable:
+       sdio_claim_host(func);
+       sdio_disable_func(func);
+release:
+       sdio_release_host(func);
+       kfree(wl_sdio);
+out_free_hw:
+       wl1251_free_hw(wl);
+       return ret;
+}
+
+static void __devexit wl1251_sdio_remove(struct sdio_func *func)
+{
+       struct wl1251 *wl = sdio_get_drvdata(func);
+       struct wl1251_sdio *wl_sdio = wl->if_priv;
+
+       /* Undo decrement done above in wl1251_probe */
+       pm_runtime_get_noresume(&func->dev);
+
+       if (wl->irq)
+               free_irq(wl->irq, wl);
+       kfree(wl_sdio);
+       wl1251_free_hw(wl);
+
+       sdio_claim_host(func);
+       sdio_release_irq(func);
+       sdio_disable_func(func);
+       sdio_release_host(func);
+}
+
+static int wl1251_suspend(struct device *dev)
+{
+       /*
+        * Tell MMC/SDIO core it's OK to power down the card
+        * (if it isn't already), but not to remove it completely.
+        */
+       return 0;
+}
+
+static int wl1251_resume(struct device *dev)
+{
+       return 0;
+}
+
+static const struct dev_pm_ops wl1251_sdio_pm_ops = {
+       .suspend        = wl1251_suspend,
+       .resume         = wl1251_resume,
+};
+
+static struct sdio_driver wl1251_sdio_driver = {
+       .name           = "wl1251_sdio",
+       .id_table       = wl1251_devices,
+       .probe          = wl1251_sdio_probe,
+       .remove         = __devexit_p(wl1251_sdio_remove),
+       .drv.pm         = &wl1251_sdio_pm_ops,
+};
+
+static int __init wl1251_sdio_init(void)
+{
+       int err;
+
+       err = sdio_register_driver(&wl1251_sdio_driver);
+       if (err)
+               wl1251_error("failed to register sdio driver: %d", err);
+       return err;
+}
+
+static void __exit wl1251_sdio_exit(void)
+{
+       sdio_unregister_driver(&wl1251_sdio_driver);
+       wl1251_notice("unloaded");
+}
+
+module_init(wl1251_sdio_init);
+module_exit(wl1251_sdio_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Kalle Valo <kvalo@adurom.com>");
diff --git a/drivers/net/wireless/ti/wl1251/spi.c b/drivers/net/wireless/ti/wl1251/spi.c
new file mode 100644 (file)
index 0000000..6248c35
--- /dev/null
@@ -0,0 +1,355 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/crc7.h>
+#include <linux/spi/spi.h>
+#include <linux/wl12xx.h>
+
+#include "wl1251.h"
+#include "reg.h"
+#include "spi.h"
+
+static irqreturn_t wl1251_irq(int irq, void *cookie)
+{
+       struct wl1251 *wl;
+
+       wl1251_debug(DEBUG_IRQ, "IRQ");
+
+       wl = cookie;
+
+       ieee80211_queue_work(wl->hw, &wl->irq_work);
+
+       return IRQ_HANDLED;
+}
+
+static struct spi_device *wl_to_spi(struct wl1251 *wl)
+{
+       return wl->if_priv;
+}
+
+static void wl1251_spi_reset(struct wl1251 *wl)
+{
+       u8 *cmd;
+       struct spi_transfer t;
+       struct spi_message m;
+
+       cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
+       if (!cmd) {
+               wl1251_error("could not allocate cmd for spi reset");
+               return;
+       }
+
+       memset(&t, 0, sizeof(t));
+       spi_message_init(&m);
+
+       memset(cmd, 0xff, WSPI_INIT_CMD_LEN);
+
+       t.tx_buf = cmd;
+       t.len = WSPI_INIT_CMD_LEN;
+       spi_message_add_tail(&t, &m);
+
+       spi_sync(wl_to_spi(wl), &m);
+
+       wl1251_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
+}
+
+static void wl1251_spi_wake(struct wl1251 *wl)
+{
+       u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
+       struct spi_transfer t;
+       struct spi_message m;
+
+       cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
+       if (!cmd) {
+               wl1251_error("could not allocate cmd for spi init");
+               return;
+       }
+
+       memset(crc, 0, sizeof(crc));
+       memset(&t, 0, sizeof(t));
+       spi_message_init(&m);
+
+       /*
+        * Set WSPI_INIT_COMMAND
+        * the data is being send from the MSB to LSB
+        */
+       cmd[2] = 0xff;
+       cmd[3] = 0xff;
+       cmd[1] = WSPI_INIT_CMD_START | WSPI_INIT_CMD_TX;
+       cmd[0] = 0;
+       cmd[7] = 0;
+       cmd[6] |= HW_ACCESS_WSPI_INIT_CMD_MASK << 3;
+       cmd[6] |= HW_ACCESS_WSPI_FIXED_BUSY_LEN & WSPI_INIT_CMD_FIXEDBUSY_LEN;
+
+       if (HW_ACCESS_WSPI_FIXED_BUSY_LEN == 0)
+               cmd[5] |=  WSPI_INIT_CMD_DIS_FIXEDBUSY;
+       else
+               cmd[5] |= WSPI_INIT_CMD_EN_FIXEDBUSY;
+
+       cmd[5] |= WSPI_INIT_CMD_IOD | WSPI_INIT_CMD_IP | WSPI_INIT_CMD_CS
+               | WSPI_INIT_CMD_WSPI | WSPI_INIT_CMD_WS;
+
+       crc[0] = cmd[1];
+       crc[1] = cmd[0];
+       crc[2] = cmd[7];
+       crc[3] = cmd[6];
+       crc[4] = cmd[5];
+
+       cmd[4] |= crc7(0, crc, WSPI_INIT_CMD_CRC_LEN) << 1;
+       cmd[4] |= WSPI_INIT_CMD_END;
+
+       t.tx_buf = cmd;
+       t.len = WSPI_INIT_CMD_LEN;
+       spi_message_add_tail(&t, &m);
+
+       spi_sync(wl_to_spi(wl), &m);
+
+       wl1251_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
+}
+
+static void wl1251_spi_reset_wake(struct wl1251 *wl)
+{
+       wl1251_spi_reset(wl);
+       wl1251_spi_wake(wl);
+}
+
+static void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf,
+                           size_t len)
+{
+       struct spi_transfer t[3];
+       struct spi_message m;
+       u8 *busy_buf;
+       u32 *cmd;
+
+       cmd = &wl->buffer_cmd;
+       busy_buf = wl->buffer_busyword;
+
+       *cmd = 0;
+       *cmd |= WSPI_CMD_READ;
+       *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
+       *cmd |= addr & WSPI_CMD_BYTE_ADDR;
+
+       spi_message_init(&m);
+       memset(t, 0, sizeof(t));
+
+       t[0].tx_buf = cmd;
+       t[0].len = 4;
+       spi_message_add_tail(&t[0], &m);
+
+       /* Busy and non busy words read */
+       t[1].rx_buf = busy_buf;
+       t[1].len = WL1251_BUSY_WORD_LEN;
+       spi_message_add_tail(&t[1], &m);
+
+       t[2].rx_buf = buf;
+       t[2].len = len;
+       spi_message_add_tail(&t[2], &m);
+
+       spi_sync(wl_to_spi(wl), &m);
+
+       /* FIXME: check busy words */
+
+       wl1251_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd));
+       wl1251_dump(DEBUG_SPI, "spi_read buf <- ", buf, len);
+}
+
+static void wl1251_spi_write(struct wl1251 *wl, int addr, void *buf,
+                            size_t len)
+{
+       struct spi_transfer t[2];
+       struct spi_message m;
+       u32 *cmd;
+
+       cmd = &wl->buffer_cmd;
+
+       *cmd = 0;
+       *cmd |= WSPI_CMD_WRITE;
+       *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
+       *cmd |= addr & WSPI_CMD_BYTE_ADDR;
+
+       spi_message_init(&m);
+       memset(t, 0, sizeof(t));
+
+       t[0].tx_buf = cmd;
+       t[0].len = sizeof(*cmd);
+       spi_message_add_tail(&t[0], &m);
+
+       t[1].tx_buf = buf;
+       t[1].len = len;
+       spi_message_add_tail(&t[1], &m);
+
+       spi_sync(wl_to_spi(wl), &m);
+
+       wl1251_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd));
+       wl1251_dump(DEBUG_SPI, "spi_write buf -> ", buf, len);
+}
+
+static void wl1251_spi_enable_irq(struct wl1251 *wl)
+{
+       return enable_irq(wl->irq);
+}
+
+static void wl1251_spi_disable_irq(struct wl1251 *wl)
+{
+       return disable_irq(wl->irq);
+}
+
+static int wl1251_spi_set_power(struct wl1251 *wl, bool enable)
+{
+       if (wl->set_power)
+               wl->set_power(enable);
+
+       return 0;
+}
+
+static const struct wl1251_if_operations wl1251_spi_ops = {
+       .read = wl1251_spi_read,
+       .write = wl1251_spi_write,
+       .reset = wl1251_spi_reset_wake,
+       .enable_irq = wl1251_spi_enable_irq,
+       .disable_irq = wl1251_spi_disable_irq,
+       .power = wl1251_spi_set_power,
+};
+
+static int __devinit wl1251_spi_probe(struct spi_device *spi)
+{
+       struct wl12xx_platform_data *pdata;
+       struct ieee80211_hw *hw;
+       struct wl1251 *wl;
+       int ret;
+
+       pdata = spi->dev.platform_data;
+       if (!pdata) {
+               wl1251_error("no platform data");
+               return -ENODEV;
+       }
+
+       hw = wl1251_alloc_hw();
+       if (IS_ERR(hw))
+               return PTR_ERR(hw);
+
+       wl = hw->priv;
+
+       SET_IEEE80211_DEV(hw, &spi->dev);
+       dev_set_drvdata(&spi->dev, wl);
+       wl->if_priv = spi;
+       wl->if_ops = &wl1251_spi_ops;
+
+       /* This is the only SPI value that we need to set here, the rest
+        * comes from the board-peripherals file */
+       spi->bits_per_word = 32;
+
+       ret = spi_setup(spi);
+       if (ret < 0) {
+               wl1251_error("spi_setup failed");
+               goto out_free;
+       }
+
+       wl->set_power = pdata->set_power;
+       if (!wl->set_power) {
+               wl1251_error("set power function missing in platform data");
+               return -ENODEV;
+       }
+
+       wl->irq = spi->irq;
+       if (wl->irq < 0) {
+               wl1251_error("irq missing in platform data");
+               return -ENODEV;
+       }
+
+       wl->use_eeprom = pdata->use_eeprom;
+
+       ret = request_irq(wl->irq, wl1251_irq, 0, DRIVER_NAME, wl);
+       if (ret < 0) {
+               wl1251_error("request_irq() failed: %d", ret);
+               goto out_free;
+       }
+
+       irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
+
+       disable_irq(wl->irq);
+
+       ret = wl1251_init_ieee80211(wl);
+       if (ret)
+               goto out_irq;
+
+       return 0;
+
+ out_irq:
+       free_irq(wl->irq, wl);
+
+ out_free:
+       ieee80211_free_hw(hw);
+
+       return ret;
+}
+
+static int __devexit wl1251_spi_remove(struct spi_device *spi)
+{
+       struct wl1251 *wl = dev_get_drvdata(&spi->dev);
+
+       free_irq(wl->irq, wl);
+       wl1251_free_hw(wl);
+
+       return 0;
+}
+
+static struct spi_driver wl1251_spi_driver = {
+       .driver = {
+               .name           = DRIVER_NAME,
+               .owner          = THIS_MODULE,
+       },
+
+       .probe          = wl1251_spi_probe,
+       .remove         = __devexit_p(wl1251_spi_remove),
+};
+
+static int __init wl1251_spi_init(void)
+{
+       int ret;
+
+       ret = spi_register_driver(&wl1251_spi_driver);
+       if (ret < 0) {
+               wl1251_error("failed to register spi driver: %d", ret);
+               goto out;
+       }
+
+out:
+       return ret;
+}
+
+static void __exit wl1251_spi_exit(void)
+{
+       spi_unregister_driver(&wl1251_spi_driver);
+
+       wl1251_notice("unloaded");
+}
+
+module_init(wl1251_spi_init);
+module_exit(wl1251_spi_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Kalle Valo <kvalo@adurom.com>");
+MODULE_ALIAS("spi:wl1251");
diff --git a/drivers/net/wireless/ti/wl1251/spi.h b/drivers/net/wireless/ti/wl1251/spi.h
new file mode 100644 (file)
index 0000000..16d5069
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (c) 1998-2007 Texas Instruments Incorporated
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL1251_SPI_H__
+#define __WL1251_SPI_H__
+
+#include "cmd.h"
+#include "acx.h"
+#include "reg.h"
+
+#define WSPI_CMD_READ                 0x40000000
+#define WSPI_CMD_WRITE                0x00000000
+#define WSPI_CMD_FIXED                0x20000000
+#define WSPI_CMD_BYTE_LENGTH          0x1FFE0000
+#define WSPI_CMD_BYTE_LENGTH_OFFSET   17
+#define WSPI_CMD_BYTE_ADDR            0x0001FFFF
+
+#define WSPI_INIT_CMD_CRC_LEN       5
+
+#define WSPI_INIT_CMD_START         0x00
+#define WSPI_INIT_CMD_TX            0x40
+/* the extra bypass bit is sampled by the TNET as '1' */
+#define WSPI_INIT_CMD_BYPASS_BIT    0x80
+#define WSPI_INIT_CMD_FIXEDBUSY_LEN 0x07
+#define WSPI_INIT_CMD_EN_FIXEDBUSY  0x80
+#define WSPI_INIT_CMD_DIS_FIXEDBUSY 0x00
+#define WSPI_INIT_CMD_IOD           0x40
+#define WSPI_INIT_CMD_IP            0x20
+#define WSPI_INIT_CMD_CS            0x10
+#define WSPI_INIT_CMD_WS            0x08
+#define WSPI_INIT_CMD_WSPI          0x01
+#define WSPI_INIT_CMD_END           0x01
+
+#define WSPI_INIT_CMD_LEN           8
+
+#define HW_ACCESS_WSPI_FIXED_BUSY_LEN \
+               ((WL1251_BUSY_WORD_LEN - 4) / sizeof(u32))
+#define HW_ACCESS_WSPI_INIT_CMD_MASK  0
+
+#endif /* __WL1251_SPI_H__ */
diff --git a/drivers/net/wireless/ti/wl1251/tx.c b/drivers/net/wireless/ti/wl1251/tx.c
new file mode 100644 (file)
index 0000000..28121c5
--- /dev/null
@@ -0,0 +1,560 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (c) 1998-2007 Texas Instruments Incorporated
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+
+#include "wl1251.h"
+#include "reg.h"
+#include "tx.h"
+#include "ps.h"
+#include "io.h"
+
+static bool wl1251_tx_double_buffer_busy(struct wl1251 *wl, u32 data_out_count)
+{
+       int used, data_in_count;
+
+       data_in_count = wl->data_in_count;
+
+       if (data_in_count < data_out_count)
+               /* data_in_count has wrapped */
+               data_in_count += TX_STATUS_DATA_OUT_COUNT_MASK + 1;
+
+       used = data_in_count - data_out_count;
+
+       WARN_ON(used < 0);
+       WARN_ON(used > DP_TX_PACKET_RING_CHUNK_NUM);
+
+       if (used >= DP_TX_PACKET_RING_CHUNK_NUM)
+               return true;
+       else
+               return false;
+}
+
+static int wl1251_tx_path_status(struct wl1251 *wl)
+{
+       u32 status, addr, data_out_count;
+       bool busy;
+
+       addr = wl->data_path->tx_control_addr;
+       status = wl1251_mem_read32(wl, addr);
+       data_out_count = status & TX_STATUS_DATA_OUT_COUNT_MASK;
+       busy = wl1251_tx_double_buffer_busy(wl, data_out_count);
+
+       if (busy)
+               return -EBUSY;
+
+       return 0;
+}
+
+static int wl1251_tx_id(struct wl1251 *wl, struct sk_buff *skb)
+{
+       int i;
+
+       for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
+               if (wl->tx_frames[i] == NULL) {
+                       wl->tx_frames[i] = skb;
+                       return i;
+               }
+
+       return -EBUSY;
+}
+
+static void wl1251_tx_control(struct tx_double_buffer_desc *tx_hdr,
+                             struct ieee80211_tx_info *control, u16 fc)
+{
+       *(u16 *)&tx_hdr->control = 0;
+
+       tx_hdr->control.rate_policy = 0;
+
+       /* 802.11 packets */
+       tx_hdr->control.packet_type = 0;
+
+       if (control->flags & IEEE80211_TX_CTL_NO_ACK)
+               tx_hdr->control.ack_policy = 1;
+
+       tx_hdr->control.tx_complete = 1;
+
+       if ((fc & IEEE80211_FTYPE_DATA) &&
+           ((fc & IEEE80211_STYPE_QOS_DATA) ||
+            (fc & IEEE80211_STYPE_QOS_NULLFUNC)))
+               tx_hdr->control.qos = 1;
+}
+
+/* RSN + MIC = 8 + 8 = 16 bytes (worst case - AES). */
+#define MAX_MSDU_SECURITY_LENGTH      16
+#define MAX_MPDU_SECURITY_LENGTH      16
+#define WLAN_QOS_HDR_LEN              26
+#define MAX_MPDU_HEADER_AND_SECURITY  (MAX_MPDU_SECURITY_LENGTH + \
+                                      WLAN_QOS_HDR_LEN)
+#define HW_BLOCK_SIZE                 252
+static void wl1251_tx_frag_block_num(struct tx_double_buffer_desc *tx_hdr)
+{
+       u16 payload_len, frag_threshold, mem_blocks;
+       u16 num_mpdus, mem_blocks_per_frag;
+
+       frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
+       tx_hdr->frag_threshold = cpu_to_le16(frag_threshold);
+
+       payload_len = le16_to_cpu(tx_hdr->length) + MAX_MSDU_SECURITY_LENGTH;
+
+       if (payload_len > frag_threshold) {
+               mem_blocks_per_frag =
+                       ((frag_threshold + MAX_MPDU_HEADER_AND_SECURITY) /
+                        HW_BLOCK_SIZE) + 1;
+               num_mpdus = payload_len / frag_threshold;
+               mem_blocks = num_mpdus * mem_blocks_per_frag;
+               payload_len -= num_mpdus * frag_threshold;
+               num_mpdus++;
+
+       } else {
+               mem_blocks_per_frag = 0;
+               mem_blocks = 0;
+               num_mpdus = 1;
+       }
+
+       mem_blocks += (payload_len / HW_BLOCK_SIZE) + 1;
+
+       if (num_mpdus > 1)
+               mem_blocks += min(num_mpdus, mem_blocks_per_frag);
+
+       tx_hdr->num_mem_blocks = mem_blocks;
+}
+
+static int wl1251_tx_fill_hdr(struct wl1251 *wl, struct sk_buff *skb,
+                             struct ieee80211_tx_info *control)
+{
+       struct tx_double_buffer_desc *tx_hdr;
+       struct ieee80211_rate *rate;
+       int id;
+       u16 fc;
+
+       if (!skb)
+               return -EINVAL;
+
+       id = wl1251_tx_id(wl, skb);
+       if (id < 0)
+               return id;
+
+       fc = *(u16 *)skb->data;
+       tx_hdr = (struct tx_double_buffer_desc *) skb_push(skb,
+                                                          sizeof(*tx_hdr));
+
+       tx_hdr->length = cpu_to_le16(skb->len - sizeof(*tx_hdr));
+       rate = ieee80211_get_tx_rate(wl->hw, control);
+       tx_hdr->rate = cpu_to_le16(rate->hw_value);
+       tx_hdr->expiry_time = cpu_to_le32(1 << 16);
+       tx_hdr->id = id;
+
+       tx_hdr->xmit_queue = wl1251_tx_get_queue(skb_get_queue_mapping(skb));
+
+       wl1251_tx_control(tx_hdr, control, fc);
+       wl1251_tx_frag_block_num(tx_hdr);
+
+       return 0;
+}
+
+/* We copy the packet to the target */
+static int wl1251_tx_send_packet(struct wl1251 *wl, struct sk_buff *skb,
+                                struct ieee80211_tx_info *control)
+{
+       struct tx_double_buffer_desc *tx_hdr;
+       int len;
+       u32 addr;
+
+       if (!skb)
+               return -EINVAL;
+
+       tx_hdr = (struct tx_double_buffer_desc *) skb->data;
+
+       if (control->control.hw_key &&
+           control->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
+               int hdrlen;
+               __le16 fc;
+               u16 length;
+               u8 *pos;
+
+               fc = *(__le16 *)(skb->data + sizeof(*tx_hdr));
+               length = le16_to_cpu(tx_hdr->length) + WL1251_TKIP_IV_SPACE;
+               tx_hdr->length = cpu_to_le16(length);
+
+               hdrlen = ieee80211_hdrlen(fc);
+
+               pos = skb_push(skb, WL1251_TKIP_IV_SPACE);
+               memmove(pos, pos + WL1251_TKIP_IV_SPACE,
+                       sizeof(*tx_hdr) + hdrlen);
+       }
+
+       /* Revisit. This is a workaround for getting non-aligned packets.
+          This happens at least with EAPOL packets from the user space.
+          Our DMA requires packets to be aligned on a 4-byte boundary.
+       */
+       if (unlikely((long)skb->data & 0x03)) {
+               int offset = (4 - (long)skb->data) & 0x03;
+               wl1251_debug(DEBUG_TX, "skb offset %d", offset);
+
+               /* check whether the current skb can be used */
+               if (skb_cloned(skb) || (skb_tailroom(skb) < offset)) {
+                       struct sk_buff *newskb = skb_copy_expand(skb, 0, 3,
+                                                                GFP_KERNEL);
+
+                       if (unlikely(newskb == NULL)) {
+                               wl1251_error("Can't allocate skb!");
+                               return -EINVAL;
+                       }
+
+                       tx_hdr = (struct tx_double_buffer_desc *) newskb->data;
+
+                       dev_kfree_skb_any(skb);
+                       wl->tx_frames[tx_hdr->id] = skb = newskb;
+
+                       offset = (4 - (long)skb->data) & 0x03;
+                       wl1251_debug(DEBUG_TX, "new skb offset %d", offset);
+               }
+
+               /* align the buffer on a 4-byte boundary */
+               if (offset) {
+                       unsigned char *src = skb->data;
+                       skb_reserve(skb, offset);
+                       memmove(skb->data, src, skb->len);
+                       tx_hdr = (struct tx_double_buffer_desc *) skb->data;
+               }
+       }
+
+       /* Our skb->data at this point includes the HW header */
+       len = WL1251_TX_ALIGN(skb->len);
+
+       if (wl->data_in_count & 0x1)
+               addr = wl->data_path->tx_packet_ring_addr +
+                       wl->data_path->tx_packet_ring_chunk_size;
+       else
+               addr = wl->data_path->tx_packet_ring_addr;
+
+       wl1251_mem_write(wl, addr, skb->data, len);
+
+       wl1251_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u rate 0x%x "
+                    "queue %d", tx_hdr->id, skb, tx_hdr->length,
+                    tx_hdr->rate, tx_hdr->xmit_queue);
+
+       return 0;
+}
+
+static void wl1251_tx_trigger(struct wl1251 *wl)
+{
+       u32 data, addr;
+
+       if (wl->data_in_count & 0x1) {
+               addr = ACX_REG_INTERRUPT_TRIG_H;
+               data = INTR_TRIG_TX_PROC1;
+       } else {
+               addr = ACX_REG_INTERRUPT_TRIG;
+               data = INTR_TRIG_TX_PROC0;
+       }
+
+       wl1251_reg_write32(wl, addr, data);
+
+       /* Bumping data in */
+       wl->data_in_count = (wl->data_in_count + 1) &
+               TX_STATUS_DATA_OUT_COUNT_MASK;
+}
+
+/* caller must hold wl->mutex */
+static int wl1251_tx_frame(struct wl1251 *wl, struct sk_buff *skb)
+{
+       struct ieee80211_tx_info *info;
+       int ret = 0;
+       u8 idx;
+
+       info = IEEE80211_SKB_CB(skb);
+
+       if (info->control.hw_key) {
+               idx = info->control.hw_key->hw_key_idx;
+               if (unlikely(wl->default_key != idx)) {
+                       ret = wl1251_acx_default_key(wl, idx);
+                       if (ret < 0)
+                               return ret;
+               }
+       }
+
+       ret = wl1251_tx_path_status(wl);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_tx_fill_hdr(wl, skb, info);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1251_tx_send_packet(wl, skb, info);
+       if (ret < 0)
+               return ret;
+
+       wl1251_tx_trigger(wl);
+
+       return ret;
+}
+
+void wl1251_tx_work(struct work_struct *work)
+{
+       struct wl1251 *wl = container_of(work, struct wl1251, tx_work);
+       struct sk_buff *skb;
+       bool woken_up = false;
+       int ret;
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1251_STATE_OFF))
+               goto out;
+
+       while ((skb = skb_dequeue(&wl->tx_queue))) {
+               if (!woken_up) {
+                       ret = wl1251_ps_elp_wakeup(wl);
+                       if (ret < 0)
+                               goto out;
+                       woken_up = true;
+               }
+
+               ret = wl1251_tx_frame(wl, skb);
+               if (ret == -EBUSY) {
+                       skb_queue_head(&wl->tx_queue, skb);
+                       goto out;
+               } else if (ret < 0) {
+                       dev_kfree_skb(skb);
+                       goto out;
+               }
+       }
+
+out:
+       if (woken_up)
+               wl1251_ps_elp_sleep(wl);
+
+       mutex_unlock(&wl->mutex);
+}
+
+static const char *wl1251_tx_parse_status(u8 status)
+{
+       /* 8 bit status field, one character per bit plus null */
+       static char buf[9];
+       int i = 0;
+
+       memset(buf, 0, sizeof(buf));
+
+       if (status & TX_DMA_ERROR)
+               buf[i++] = 'm';
+       if (status & TX_DISABLED)
+               buf[i++] = 'd';
+       if (status & TX_RETRY_EXCEEDED)
+               buf[i++] = 'r';
+       if (status & TX_TIMEOUT)
+               buf[i++] = 't';
+       if (status & TX_KEY_NOT_FOUND)
+               buf[i++] = 'k';
+       if (status & TX_ENCRYPT_FAIL)
+               buf[i++] = 'e';
+       if (status & TX_UNAVAILABLE_PRIORITY)
+               buf[i++] = 'p';
+
+       /* bit 0 is unused apparently */
+
+       return buf;
+}
+
+static void wl1251_tx_packet_cb(struct wl1251 *wl,
+                               struct tx_result *result)
+{
+       struct ieee80211_tx_info *info;
+       struct sk_buff *skb;
+       int hdrlen;
+       u8 *frame;
+
+       skb = wl->tx_frames[result->id];
+       if (skb == NULL) {
+               wl1251_error("SKB for packet %d is NULL", result->id);
+               return;
+       }
+
+       info = IEEE80211_SKB_CB(skb);
+
+       if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
+           (result->status == TX_SUCCESS))
+               info->flags |= IEEE80211_TX_STAT_ACK;
+
+       info->status.rates[0].count = result->ack_failures + 1;
+       wl->stats.retry_count += result->ack_failures;
+
+       /*
+        * We have to remove our private TX header before pushing
+        * the skb back to mac80211.
+        */
+       frame = skb_pull(skb, sizeof(struct tx_double_buffer_desc));
+       if (info->control.hw_key &&
+           info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
+               hdrlen = ieee80211_get_hdrlen_from_skb(skb);
+               memmove(frame + WL1251_TKIP_IV_SPACE, frame, hdrlen);
+               skb_pull(skb, WL1251_TKIP_IV_SPACE);
+       }
+
+       wl1251_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
+                    " status 0x%x (%s)",
+                    result->id, skb, result->ack_failures, result->rate,
+                    result->status, wl1251_tx_parse_status(result->status));
+
+
+       ieee80211_tx_status(wl->hw, skb);
+
+       wl->tx_frames[result->id] = NULL;
+}
+
+/* Called upon reception of a TX complete interrupt */
+void wl1251_tx_complete(struct wl1251 *wl)
+{
+       int i, result_index, num_complete = 0, queue_len;
+       struct tx_result result[FW_TX_CMPLT_BLOCK_SIZE], *result_ptr;
+       unsigned long flags;
+
+       if (unlikely(wl->state != WL1251_STATE_ON))
+               return;
+
+       /* First we read the result */
+       wl1251_mem_read(wl, wl->data_path->tx_complete_addr,
+                           result, sizeof(result));
+
+       result_index = wl->next_tx_complete;
+
+       for (i = 0; i < ARRAY_SIZE(result); i++) {
+               result_ptr = &result[result_index];
+
+               if (result_ptr->done_1 == 1 &&
+                   result_ptr->done_2 == 1) {
+                       wl1251_tx_packet_cb(wl, result_ptr);
+
+                       result_ptr->done_1 = 0;
+                       result_ptr->done_2 = 0;
+
+                       result_index = (result_index + 1) &
+                               (FW_TX_CMPLT_BLOCK_SIZE - 1);
+                       num_complete++;
+               } else {
+                       break;
+               }
+       }
+
+       queue_len = skb_queue_len(&wl->tx_queue);
+
+       if ((num_complete > 0) && (queue_len > 0)) {
+               /* firmware buffer has space, reschedule tx_work */
+               wl1251_debug(DEBUG_TX, "tx_complete: reschedule tx_work");
+               ieee80211_queue_work(wl->hw, &wl->tx_work);
+       }
+
+       if (wl->tx_queue_stopped &&
+           queue_len <= WL1251_TX_QUEUE_LOW_WATERMARK) {
+               /* tx_queue has space, restart queues */
+               wl1251_debug(DEBUG_TX, "tx_complete: waking queues");
+               spin_lock_irqsave(&wl->wl_lock, flags);
+               ieee80211_wake_queues(wl->hw);
+               wl->tx_queue_stopped = false;
+               spin_unlock_irqrestore(&wl->wl_lock, flags);
+       }
+
+       /* Every completed frame needs to be acknowledged */
+       if (num_complete) {
+               /*
+                * If we've wrapped, we have to clear
+                * the results in 2 steps.
+                */
+               if (result_index > wl->next_tx_complete) {
+                       /* Only 1 write is needed */
+                       wl1251_mem_write(wl,
+                                        wl->data_path->tx_complete_addr +
+                                        (wl->next_tx_complete *
+                                         sizeof(struct tx_result)),
+                                        &result[wl->next_tx_complete],
+                                        num_complete *
+                                        sizeof(struct tx_result));
+
+
+               } else if (result_index < wl->next_tx_complete) {
+                       /* 2 writes are needed */
+                       wl1251_mem_write(wl,
+                                        wl->data_path->tx_complete_addr +
+                                        (wl->next_tx_complete *
+                                         sizeof(struct tx_result)),
+                                        &result[wl->next_tx_complete],
+                                        (FW_TX_CMPLT_BLOCK_SIZE -
+                                         wl->next_tx_complete) *
+                                        sizeof(struct tx_result));
+
+                       wl1251_mem_write(wl,
+                                        wl->data_path->tx_complete_addr,
+                                        result,
+                                        (num_complete -
+                                         FW_TX_CMPLT_BLOCK_SIZE +
+                                         wl->next_tx_complete) *
+                                        sizeof(struct tx_result));
+
+               } else {
+                       /* We have to write the whole array */
+                       wl1251_mem_write(wl,
+                                        wl->data_path->tx_complete_addr,
+                                        result,
+                                        FW_TX_CMPLT_BLOCK_SIZE *
+                                        sizeof(struct tx_result));
+               }
+
+       }
+
+       wl->next_tx_complete = result_index;
+}
+
+/* caller must hold wl->mutex */
+void wl1251_tx_flush(struct wl1251 *wl)
+{
+       int i;
+       struct sk_buff *skb;
+       struct ieee80211_tx_info *info;
+
+       /* TX failure */
+/*     control->flags = 0; FIXME */
+
+       while ((skb = skb_dequeue(&wl->tx_queue))) {
+               info = IEEE80211_SKB_CB(skb);
+
+               wl1251_debug(DEBUG_TX, "flushing skb 0x%p", skb);
+
+               if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS))
+                               continue;
+
+               ieee80211_tx_status(wl->hw, skb);
+       }
+
+       for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
+               if (wl->tx_frames[i] != NULL) {
+                       skb = wl->tx_frames[i];
+                       info = IEEE80211_SKB_CB(skb);
+
+                       if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS))
+                               continue;
+
+                       ieee80211_tx_status(wl->hw, skb);
+                       wl->tx_frames[i] = NULL;
+               }
+}
diff --git a/drivers/net/wireless/ti/wl1251/tx.h b/drivers/net/wireless/ti/wl1251/tx.h
new file mode 100644 (file)
index 0000000..81338d3
--- /dev/null
@@ -0,0 +1,231 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (c) 1998-2007 Texas Instruments Incorporated
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL1251_TX_H__
+#define __WL1251_TX_H__
+
+#include <linux/bitops.h>
+#include "acx.h"
+
+/*
+ *
+ * TX PATH
+ *
+ * The Tx path uses a double buffer and a tx_control structure, each located
+ * at a fixed address in the device's memory. On startup, the host retrieves
+ * the pointers to these addresses. A double buffer allows for continuous data
+ * flow towards the device. The host keeps track of which buffer is available
+ * and alternates between these two buffers on a per packet basis.
+ *
+ * The size of each of the two buffers is large enough to hold the longest
+ * 802.3 packet - maximum size Ethernet packet + header + descriptor.
+ * TX complete indication will be received a-synchronously in a TX done cyclic
+ * buffer which is composed of 16 tx_result descriptors structures and is used
+ * in a cyclic manner.
+ *
+ * The TX (HOST) procedure is as follows:
+ * 1. Read the Tx path status, that will give the data_out_count.
+ * 2. goto 1, if not possible.
+ *    i.e. if data_in_count - data_out_count >= HwBuffer size (2 for double
+ *    buffer).
+ * 3. Copy the packet (preceded by double_buffer_desc), if possible.
+ *    i.e. if data_in_count - data_out_count < HwBuffer size (2 for double
+ *    buffer).
+ * 4. increment data_in_count.
+ * 5. Inform the firmware by generating a firmware internal interrupt.
+ * 6. FW will increment data_out_count after it reads the buffer.
+ *
+ * The TX Complete procedure:
+ * 1. To get a TX complete indication the host enables the tx_complete flag in
+ *    the TX descriptor Structure.
+ * 2. For each packet with a Tx Complete field set, the firmware adds the
+ *    transmit results to the cyclic buffer (txDoneRing) and sets both done_1
+ *    and done_2 to 1 to indicate driver ownership.
+ * 3. The firmware sends a Tx Complete interrupt to the host to trigger the
+ *    host to process the new data. Note: interrupt will be send per packet if
+ *    TX complete indication was requested in tx_control or per crossing
+ *    aggregation threshold.
+ * 4. After receiving the Tx Complete interrupt, the host reads the
+ *    TxDescriptorDone information in a cyclic manner and clears both done_1
+ *    and done_2 fields.
+ *
+ */
+
+#define TX_COMPLETE_REQUIRED_BIT       0x80
+#define TX_STATUS_DATA_OUT_COUNT_MASK   0xf
+
+#define WL1251_TX_ALIGN_TO 4
+#define WL1251_TX_ALIGN(len) (((len) + WL1251_TX_ALIGN_TO - 1) & \
+                            ~(WL1251_TX_ALIGN_TO - 1))
+#define WL1251_TKIP_IV_SPACE 4
+
+struct tx_control {
+       /* Rate Policy (class) index */
+       unsigned rate_policy:3;
+
+       /* When set, no ack policy is expected */
+       unsigned ack_policy:1;
+
+       /*
+        * Packet type:
+        * 0 -> 802.11
+        * 1 -> 802.3
+        * 2 -> IP
+        * 3 -> raw codec
+        */
+       unsigned packet_type:2;
+
+       /* If set, this is a QoS-Null or QoS-Data frame */
+       unsigned qos:1;
+
+       /*
+        * If set, the target triggers the tx complete INT
+        * upon frame sending completion.
+        */
+       unsigned tx_complete:1;
+
+       /* 2 bytes padding before packet header */
+       unsigned xfer_pad:1;
+
+       unsigned reserved:7;
+} __packed;
+
+
+struct tx_double_buffer_desc {
+       /* Length of payload, including headers. */
+       __le16 length;
+
+       /*
+        * A bit mask that specifies the initial rate to be used
+        * Possible values are:
+        * 0x0001 - 1Mbits
+        * 0x0002 - 2Mbits
+        * 0x0004 - 5.5Mbits
+        * 0x0008 - 6Mbits
+        * 0x0010 - 9Mbits
+        * 0x0020 - 11Mbits
+        * 0x0040 - 12Mbits
+        * 0x0080 - 18Mbits
+        * 0x0100 - 22Mbits
+        * 0x0200 - 24Mbits
+        * 0x0400 - 36Mbits
+        * 0x0800 - 48Mbits
+        * 0x1000 - 54Mbits
+        */
+       __le16 rate;
+
+       /* Time in us that a packet can spend in the target */
+       __le32 expiry_time;
+
+       /* index of the TX queue used for this packet */
+       u8 xmit_queue;
+
+       /* Used to identify a packet */
+       u8 id;
+
+       struct tx_control control;
+
+       /*
+        * The FW should cut the packet into fragments
+        * of this size.
+        */
+       __le16 frag_threshold;
+
+       /* Numbers of HW queue blocks to be allocated */
+       u8 num_mem_blocks;
+
+       u8 reserved;
+} __packed;
+
+enum {
+       TX_SUCCESS              = 0,
+       TX_DMA_ERROR            = BIT(7),
+       TX_DISABLED             = BIT(6),
+       TX_RETRY_EXCEEDED       = BIT(5),
+       TX_TIMEOUT              = BIT(4),
+       TX_KEY_NOT_FOUND        = BIT(3),
+       TX_ENCRYPT_FAIL         = BIT(2),
+       TX_UNAVAILABLE_PRIORITY = BIT(1),
+};
+
+struct tx_result {
+       /*
+        * Ownership synchronization between the host and
+        * the firmware. If done_1 and done_2 are cleared,
+        * owned by the FW (no info ready).
+        */
+       u8 done_1;
+
+       /* same as double_buffer_desc->id */
+       u8 id;
+
+       /*
+        * Total air access duration consumed by this
+        * packet, including all retries and overheads.
+        */
+       u16 medium_usage;
+
+       /* Total media delay (from 1st EDCA AIFS counter until TX Complete). */
+       u32 medium_delay;
+
+       /* Time between host xfer and tx complete */
+       u32 fw_hnadling_time;
+
+       /* The LS-byte of the last TKIP sequence number. */
+       u8 lsb_seq_num;
+
+       /* Retry count */
+       u8 ack_failures;
+
+       /* At which rate we got a ACK */
+       u16 rate;
+
+       u16 reserved;
+
+       /* TX_* */
+       u8 status;
+
+       /* See done_1 */
+       u8 done_2;
+} __packed;
+
+static inline int wl1251_tx_get_queue(int queue)
+{
+       switch (queue) {
+       case 0:
+               return QOS_AC_VO;
+       case 1:
+               return QOS_AC_VI;
+       case 2:
+               return QOS_AC_BE;
+       case 3:
+               return QOS_AC_BK;
+       default:
+               return QOS_AC_BE;
+       }
+}
+
+void wl1251_tx_work(struct work_struct *work);
+void wl1251_tx_complete(struct wl1251 *wl);
+void wl1251_tx_flush(struct wl1251 *wl);
+
+#endif
diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
new file mode 100644 (file)
index 0000000..9d8f581
--- /dev/null
@@ -0,0 +1,446 @@
+/*
+ * This file is part of wl1251
+ *
+ * Copyright (c) 1998-2007 Texas Instruments Incorporated
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL1251_H__
+#define __WL1251_H__
+
+#include <linux/mutex.h>
+#include <linux/list.h>
+#include <linux/bitops.h>
+#include <net/mac80211.h>
+
+#define DRIVER_NAME "wl1251"
+#define DRIVER_PREFIX DRIVER_NAME ": "
+
+enum {
+       DEBUG_NONE      = 0,
+       DEBUG_IRQ       = BIT(0),
+       DEBUG_SPI       = BIT(1),
+       DEBUG_BOOT      = BIT(2),
+       DEBUG_MAILBOX   = BIT(3),
+       DEBUG_NETLINK   = BIT(4),
+       DEBUG_EVENT     = BIT(5),
+       DEBUG_TX        = BIT(6),
+       DEBUG_RX        = BIT(7),
+       DEBUG_SCAN      = BIT(8),
+       DEBUG_CRYPT     = BIT(9),
+       DEBUG_PSM       = BIT(10),
+       DEBUG_MAC80211  = BIT(11),
+       DEBUG_CMD       = BIT(12),
+       DEBUG_ACX       = BIT(13),
+       DEBUG_ALL       = ~0,
+};
+
+#define DEBUG_LEVEL (DEBUG_NONE)
+
+#define DEBUG_DUMP_LIMIT 1024
+
+#define wl1251_error(fmt, arg...) \
+       printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
+
+#define wl1251_warning(fmt, arg...) \
+       printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
+
+#define wl1251_notice(fmt, arg...) \
+       printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
+
+#define wl1251_info(fmt, arg...) \
+       printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
+
+#define wl1251_debug(level, fmt, arg...) \
+       do { \
+               if (level & DEBUG_LEVEL) \
+                       printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
+       } while (0)
+
+#define wl1251_dump(level, prefix, buf, len)   \
+       do { \
+               if (level & DEBUG_LEVEL) \
+                       print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
+                                      DUMP_PREFIX_OFFSET, 16, 1,       \
+                                      buf,                             \
+                                      min_t(size_t, len, DEBUG_DUMP_LIMIT), \
+                                      0);                              \
+       } while (0)
+
+#define wl1251_dump_ascii(level, prefix, buf, len)     \
+       do { \
+               if (level & DEBUG_LEVEL) \
+                       print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
+                                      DUMP_PREFIX_OFFSET, 16, 1,       \
+                                      buf,                             \
+                                      min_t(size_t, len, DEBUG_DUMP_LIMIT), \
+                                      true);                           \
+       } while (0)
+
+#define WL1251_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN |  \
+                                 CFG_BSSID_FILTER_EN)
+
+#define WL1251_DEFAULT_RX_FILTER (CFG_RX_PRSP_EN |  \
+                                 CFG_RX_MGMT_EN |  \
+                                 CFG_RX_DATA_EN |  \
+                                 CFG_RX_CTL_EN |   \
+                                 CFG_RX_BCN_EN |   \
+                                 CFG_RX_AUTH_EN |  \
+                                 CFG_RX_ASSOC_EN)
+
+#define WL1251_BUSY_WORD_LEN 8
+
+struct boot_attr {
+       u32 radio_type;
+       u8 mac_clock;
+       u8 arm_clock;
+       int firmware_debug;
+       u32 minor;
+       u32 major;
+       u32 bugfix;
+};
+
+enum wl1251_state {
+       WL1251_STATE_OFF,
+       WL1251_STATE_ON,
+       WL1251_STATE_PLT,
+};
+
+enum wl1251_partition_type {
+       PART_DOWN,
+       PART_WORK,
+       PART_DRPW,
+
+       PART_TABLE_LEN
+};
+
+enum wl1251_station_mode {
+       STATION_ACTIVE_MODE,
+       STATION_POWER_SAVE_MODE,
+       STATION_IDLE,
+};
+
+struct wl1251_partition {
+       u32 size;
+       u32 start;
+};
+
+struct wl1251_partition_set {
+       struct wl1251_partition mem;
+       struct wl1251_partition reg;
+};
+
+struct wl1251;
+
+struct wl1251_stats {
+       struct acx_statistics *fw_stats;
+       unsigned long fw_stats_update;
+
+       unsigned int retry_count;
+       unsigned int excessive_retries;
+};
+
+struct wl1251_debugfs {
+       struct dentry *rootdir;
+       struct dentry *fw_statistics;
+
+       struct dentry *tx_internal_desc_overflow;
+
+       struct dentry *rx_out_of_mem;
+       struct dentry *rx_hdr_overflow;
+       struct dentry *rx_hw_stuck;
+       struct dentry *rx_dropped;
+       struct dentry *rx_fcs_err;
+       struct dentry *rx_xfr_hint_trig;
+       struct dentry *rx_path_reset;
+       struct dentry *rx_reset_counter;
+
+       struct dentry *dma_rx_requested;
+       struct dentry *dma_rx_errors;
+       struct dentry *dma_tx_requested;
+       struct dentry *dma_tx_errors;
+
+       struct dentry *isr_cmd_cmplt;
+       struct dentry *isr_fiqs;
+       struct dentry *isr_rx_headers;
+       struct dentry *isr_rx_mem_overflow;
+       struct dentry *isr_rx_rdys;
+       struct dentry *isr_irqs;
+       struct dentry *isr_tx_procs;
+       struct dentry *isr_decrypt_done;
+       struct dentry *isr_dma0_done;
+       struct dentry *isr_dma1_done;
+       struct dentry *isr_tx_exch_complete;
+       struct dentry *isr_commands;
+       struct dentry *isr_rx_procs;
+       struct dentry *isr_hw_pm_mode_changes;
+       struct dentry *isr_host_acknowledges;
+       struct dentry *isr_pci_pm;
+       struct dentry *isr_wakeups;
+       struct dentry *isr_low_rssi;
+
+       struct dentry *wep_addr_key_count;
+       struct dentry *wep_default_key_count;
+       /* skipping wep.reserved */
+       struct dentry *wep_key_not_found;
+       struct dentry *wep_decrypt_fail;
+       struct dentry *wep_packets;
+       struct dentry *wep_interrupt;
+
+       struct dentry *pwr_ps_enter;
+       struct dentry *pwr_elp_enter;
+       struct dentry *pwr_missing_bcns;
+       struct dentry *pwr_wake_on_host;
+       struct dentry *pwr_wake_on_timer_exp;
+       struct dentry *pwr_tx_with_ps;
+       struct dentry *pwr_tx_without_ps;
+       struct dentry *pwr_rcvd_beacons;
+       struct dentry *pwr_power_save_off;
+       struct dentry *pwr_enable_ps;
+       struct dentry *pwr_disable_ps;
+       struct dentry *pwr_fix_tsf_ps;
+       /* skipping cont_miss_bcns_spread for now */
+       struct dentry *pwr_rcvd_awake_beacons;
+
+       struct dentry *mic_rx_pkts;
+       struct dentry *mic_calc_failure;
+
+       struct dentry *aes_encrypt_fail;
+       struct dentry *aes_decrypt_fail;
+       struct dentry *aes_encrypt_packets;
+       struct dentry *aes_decrypt_packets;
+       struct dentry *aes_encrypt_interrupt;
+       struct dentry *aes_decrypt_interrupt;
+
+       struct dentry *event_heart_beat;
+       struct dentry *event_calibration;
+       struct dentry *event_rx_mismatch;
+       struct dentry *event_rx_mem_empty;
+       struct dentry *event_rx_pool;
+       struct dentry *event_oom_late;
+       struct dentry *event_phy_transmit_error;
+       struct dentry *event_tx_stuck;
+
+       struct dentry *ps_pspoll_timeouts;
+       struct dentry *ps_upsd_timeouts;
+       struct dentry *ps_upsd_max_sptime;
+       struct dentry *ps_upsd_max_apturn;
+       struct dentry *ps_pspoll_max_apturn;
+       struct dentry *ps_pspoll_utilization;
+       struct dentry *ps_upsd_utilization;
+
+       struct dentry *rxpipe_rx_prep_beacon_drop;
+       struct dentry *rxpipe_descr_host_int_trig_rx_data;
+       struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
+       struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
+       struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
+
+       struct dentry *tx_queue_len;
+       struct dentry *tx_queue_status;
+
+       struct dentry *retry_count;
+       struct dentry *excessive_retries;
+};
+
+struct wl1251_if_operations {
+       void (*read)(struct wl1251 *wl, int addr, void *buf, size_t len);
+       void (*write)(struct wl1251 *wl, int addr, void *buf, size_t len);
+       void (*read_elp)(struct wl1251 *wl, int addr, u32 *val);
+       void (*write_elp)(struct wl1251 *wl, int addr, u32 val);
+       int  (*power)(struct wl1251 *wl, bool enable);
+       void (*reset)(struct wl1251 *wl);
+       void (*enable_irq)(struct wl1251 *wl);
+       void (*disable_irq)(struct wl1251 *wl);
+};
+
+struct wl1251 {
+       struct ieee80211_hw *hw;
+       bool mac80211_registered;
+
+       void *if_priv;
+       const struct wl1251_if_operations *if_ops;
+
+       void (*set_power)(bool enable);
+       int irq;
+       bool use_eeprom;
+
+       spinlock_t wl_lock;
+
+       enum wl1251_state state;
+       struct mutex mutex;
+
+       int physical_mem_addr;
+       int physical_reg_addr;
+       int virtual_mem_addr;
+       int virtual_reg_addr;
+
+       int cmd_box_addr;
+       int event_box_addr;
+       struct boot_attr boot_attr;
+
+       u8 *fw;
+       size_t fw_len;
+       u8 *nvs;
+       size_t nvs_len;
+
+       u8 bssid[ETH_ALEN];
+       u8 mac_addr[ETH_ALEN];
+       u8 bss_type;
+       u8 listen_int;
+       int channel;
+
+       void *target_mem_map;
+       struct acx_data_path_params_resp *data_path;
+
+       /* Number of TX packets transferred to the FW, modulo 16 */
+       u32 data_in_count;
+
+       /* Frames scheduled for transmission, not handled yet */
+       struct sk_buff_head tx_queue;
+       bool tx_queue_stopped;
+
+       struct work_struct tx_work;
+       struct work_struct filter_work;
+
+       /* Pending TX frames */
+       struct sk_buff *tx_frames[16];
+
+       /*
+        * Index pointing to the next TX complete entry
+        * in the cyclic XT complete array we get from
+        * the FW.
+        */
+       u32 next_tx_complete;
+
+       /* FW Rx counter */
+       u32 rx_counter;
+
+       /* Rx frames handled */
+       u32 rx_handled;
+
+       /* Current double buffer */
+       u32 rx_current_buffer;
+       u32 rx_last_id;
+
+       /* The target interrupt mask */
+       u32 intr_mask;
+       struct work_struct irq_work;
+
+       /* The mbox event mask */
+       u32 event_mask;
+
+       /* Mailbox pointers */
+       u32 mbox_ptr[2];
+
+       /* Are we currently scanning */
+       bool scanning;
+
+       /* Default key (for WEP) */
+       u32 default_key;
+
+       unsigned int tx_mgmt_frm_rate;
+       unsigned int tx_mgmt_frm_mod;
+
+       unsigned int rx_config;
+       unsigned int rx_filter;
+
+       /* is firmware in elp mode */
+       bool elp;
+
+       struct delayed_work elp_work;
+
+       enum wl1251_station_mode station_mode;
+
+       /* PSM mode requested */
+       bool psm_requested;
+
+       u16 beacon_int;
+       u8 dtim_period;
+
+       /* in dBm */
+       int power_level;
+
+       int rssi_thold;
+
+       struct wl1251_stats stats;
+       struct wl1251_debugfs debugfs;
+
+       __le32 buffer_32;
+       u32 buffer_cmd;
+       u8 buffer_busyword[WL1251_BUSY_WORD_LEN];
+       struct wl1251_rx_descriptor *rx_descriptor;
+
+       struct ieee80211_vif *vif;
+
+       u32 chip_id;
+       char fw_ver[21];
+
+       /* Most recently reported noise in dBm */
+       s8 noise;
+};
+
+int wl1251_plt_start(struct wl1251 *wl);
+int wl1251_plt_stop(struct wl1251 *wl);
+
+struct ieee80211_hw *wl1251_alloc_hw(void);
+int wl1251_free_hw(struct wl1251 *wl);
+int wl1251_init_ieee80211(struct wl1251 *wl);
+void wl1251_enable_interrupts(struct wl1251 *wl);
+void wl1251_disable_interrupts(struct wl1251 *wl);
+
+#define DEFAULT_HW_GEN_MODULATION_TYPE    CCK_LONG /* Long Preamble */
+#define DEFAULT_HW_GEN_TX_RATE          RATE_2MBPS
+#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
+
+#define WL1251_DEFAULT_POWER_LEVEL 20
+
+#define WL1251_TX_QUEUE_LOW_WATERMARK  10
+#define WL1251_TX_QUEUE_HIGH_WATERMARK 25
+
+#define WL1251_DEFAULT_BEACON_INT 100
+#define WL1251_DEFAULT_DTIM_PERIOD 1
+
+#define WL1251_DEFAULT_CHANNEL 0
+
+#define WL1251_DEFAULT_BET_CONSECUTIVE 10
+
+#define CHIP_ID_1251_PG10                 (0x7010101)
+#define CHIP_ID_1251_PG11                 (0x7020101)
+#define CHIP_ID_1251_PG12                 (0x7030101)
+#define CHIP_ID_1271_PG10                 (0x4030101)
+#define CHIP_ID_1271_PG20                 (0x4030111)
+
+#define WL1251_FW_NAME "wl1251-fw.bin"
+#define WL1251_NVS_NAME "wl1251-nvs.bin"
+
+#define WL1251_POWER_ON_SLEEP 10 /* in milliseconds */
+
+#define WL1251_PART_DOWN_MEM_START     0x0
+#define WL1251_PART_DOWN_MEM_SIZE      0x16800
+#define WL1251_PART_DOWN_REG_START     REGISTERS_BASE
+#define WL1251_PART_DOWN_REG_SIZE      REGISTERS_DOWN_SIZE
+
+#define WL1251_PART_WORK_MEM_START     0x28000
+#define WL1251_PART_WORK_MEM_SIZE      0x14000
+#define WL1251_PART_WORK_REG_START     REGISTERS_BASE
+#define WL1251_PART_WORK_REG_SIZE      REGISTERS_WORK_SIZE
+
+#define WL1251_DEFAULT_LOW_RSSI_WEIGHT          10
+#define WL1251_DEFAULT_LOW_RSSI_DEPTH           10
+
+#endif
diff --git a/drivers/net/wireless/ti/wl1251/wl12xx_80211.h b/drivers/net/wireless/ti/wl1251/wl12xx_80211.h
new file mode 100644 (file)
index 0000000..04ed514
--- /dev/null
@@ -0,0 +1,155 @@
+#ifndef __WL12XX_80211_H__
+#define __WL12XX_80211_H__
+
+#include <linux/if_ether.h>    /* ETH_ALEN */
+
+/* RATES */
+#define IEEE80211_CCK_RATE_1MB                 0x02
+#define IEEE80211_CCK_RATE_2MB                 0x04
+#define IEEE80211_CCK_RATE_5MB                 0x0B
+#define IEEE80211_CCK_RATE_11MB                        0x16
+#define IEEE80211_OFDM_RATE_6MB                        0x0C
+#define IEEE80211_OFDM_RATE_9MB                        0x12
+#define IEEE80211_OFDM_RATE_12MB               0x18
+#define IEEE80211_OFDM_RATE_18MB               0x24
+#define IEEE80211_OFDM_RATE_24MB               0x30
+#define IEEE80211_OFDM_RATE_36MB               0x48
+#define IEEE80211_OFDM_RATE_48MB               0x60
+#define IEEE80211_OFDM_RATE_54MB               0x6C
+#define IEEE80211_BASIC_RATE_MASK              0x80
+
+#define IEEE80211_CCK_RATE_1MB_MASK            (1<<0)
+#define IEEE80211_CCK_RATE_2MB_MASK            (1<<1)
+#define IEEE80211_CCK_RATE_5MB_MASK            (1<<2)
+#define IEEE80211_CCK_RATE_11MB_MASK           (1<<3)
+#define IEEE80211_OFDM_RATE_6MB_MASK           (1<<4)
+#define IEEE80211_OFDM_RATE_9MB_MASK           (1<<5)
+#define IEEE80211_OFDM_RATE_12MB_MASK          (1<<6)
+#define IEEE80211_OFDM_RATE_18MB_MASK          (1<<7)
+#define IEEE80211_OFDM_RATE_24MB_MASK          (1<<8)
+#define IEEE80211_OFDM_RATE_36MB_MASK          (1<<9)
+#define IEEE80211_OFDM_RATE_48MB_MASK          (1<<10)
+#define IEEE80211_OFDM_RATE_54MB_MASK          (1<<11)
+
+#define IEEE80211_CCK_RATES_MASK         0x0000000F
+#define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
+       IEEE80211_CCK_RATE_2MB_MASK)
+#define IEEE80211_CCK_DEFAULT_RATES_MASK (IEEE80211_CCK_BASIC_RATES_MASK | \
+       IEEE80211_CCK_RATE_5MB_MASK | \
+       IEEE80211_CCK_RATE_11MB_MASK)
+
+#define IEEE80211_OFDM_RATES_MASK        0x00000FF0
+#define IEEE80211_OFDM_BASIC_RATES_MASK          (IEEE80211_OFDM_RATE_6MB_MASK | \
+       IEEE80211_OFDM_RATE_12MB_MASK | \
+       IEEE80211_OFDM_RATE_24MB_MASK)
+#define IEEE80211_OFDM_DEFAULT_RATES_MASK (IEEE80211_OFDM_BASIC_RATES_MASK | \
+       IEEE80211_OFDM_RATE_9MB_MASK  | \
+       IEEE80211_OFDM_RATE_18MB_MASK | \
+       IEEE80211_OFDM_RATE_36MB_MASK | \
+       IEEE80211_OFDM_RATE_48MB_MASK | \
+       IEEE80211_OFDM_RATE_54MB_MASK)
+#define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
+                                     IEEE80211_CCK_DEFAULT_RATES_MASK)
+
+
+/* This really should be 8, but not for our firmware */
+#define MAX_SUPPORTED_RATES 32
+#define MAX_COUNTRY_TRIPLETS 32
+
+/* Headers */
+struct ieee80211_header {
+       __le16 frame_ctl;
+       __le16 duration_id;
+       u8 da[ETH_ALEN];
+       u8 sa[ETH_ALEN];
+       u8 bssid[ETH_ALEN];
+       __le16 seq_ctl;
+       u8 payload[0];
+} __packed;
+
+struct wl12xx_ie_header {
+       u8 id;
+       u8 len;
+} __packed;
+
+/* IEs */
+
+struct wl12xx_ie_ssid {
+       struct wl12xx_ie_header header;
+       char ssid[IEEE80211_MAX_SSID_LEN];
+} __packed;
+
+struct wl12xx_ie_rates {
+       struct wl12xx_ie_header header;
+       u8 rates[MAX_SUPPORTED_RATES];
+} __packed;
+
+struct wl12xx_ie_ds_params {
+       struct wl12xx_ie_header header;
+       u8 channel;
+} __packed;
+
+struct country_triplet {
+       u8 channel;
+       u8 num_channels;
+       u8 max_tx_power;
+} __packed;
+
+struct wl12xx_ie_country {
+       struct wl12xx_ie_header header;
+       u8 country_string[IEEE80211_COUNTRY_STRING_LEN];
+       struct country_triplet triplets[MAX_COUNTRY_TRIPLETS];
+} __packed;
+
+
+/* Templates */
+
+struct wl12xx_beacon_template {
+       struct ieee80211_header header;
+       __le32 time_stamp[2];
+       __le16 beacon_interval;
+       __le16 capability;
+       struct wl12xx_ie_ssid ssid;
+       struct wl12xx_ie_rates rates;
+       struct wl12xx_ie_rates ext_rates;
+       struct wl12xx_ie_ds_params ds_params;
+       struct wl12xx_ie_country country;
+} __packed;
+
+struct wl12xx_null_data_template {
+       struct ieee80211_header header;
+} __packed;
+
+struct wl12xx_ps_poll_template {
+       __le16 fc;
+       __le16 aid;
+       u8 bssid[ETH_ALEN];
+       u8 ta[ETH_ALEN];
+} __packed;
+
+struct wl12xx_qos_null_data_template {
+       struct ieee80211_header header;
+       __le16 qos_ctl;
+} __packed;
+
+struct wl12xx_probe_req_template {
+       struct ieee80211_header header;
+       struct wl12xx_ie_ssid ssid;
+       struct wl12xx_ie_rates rates;
+       struct wl12xx_ie_rates ext_rates;
+} __packed;
+
+
+struct wl12xx_probe_resp_template {
+       struct ieee80211_header header;
+       __le32 time_stamp[2];
+       __le16 beacon_interval;
+       __le16 capability;
+       struct wl12xx_ie_ssid ssid;
+       struct wl12xx_ie_rates rates;
+       struct wl12xx_ie_rates ext_rates;
+       struct wl12xx_ie_ds_params ds_params;
+       struct wl12xx_ie_country country;
+} __packed;
+
+#endif
diff --git a/drivers/net/wireless/ti/wl12xx/Kconfig b/drivers/net/wireless/ti/wl12xx/Kconfig
new file mode 100644 (file)
index 0000000..5b92329
--- /dev/null
@@ -0,0 +1,8 @@
+config WL12XX
+       tristate "TI wl12xx support"
+       select WLCORE
+       ---help---
+         This module adds support for wireless adapters based on TI wl1271,
+         wl1273, wl1281 and wl1283 chipsets. This module does *not* include
+         support for wl1251.  For wl1251 support, use the separate homonymous
+          driver instead.
diff --git a/drivers/net/wireless/ti/wl12xx/Makefile b/drivers/net/wireless/ti/wl12xx/Makefile
new file mode 100644 (file)
index 0000000..87f64b1
--- /dev/null
@@ -0,0 +1,3 @@
+wl12xx-objs    = main.o cmd.o acx.o
+
+obj-$(CONFIG_WL12XX)           += wl12xx.o
diff --git a/drivers/net/wireless/ti/wl12xx/acx.c b/drivers/net/wireless/ti/wl12xx/acx.c
new file mode 100644 (file)
index 0000000..bea06b2
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * This file is part of wl12xx
+ *
+ * Copyright (C) 2008-2009 Nokia Corporation
+ * Copyright (C) 2011 Texas Instruments Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "../wlcore/cmd.h"
+#include "../wlcore/debug.h"
+#include "../wlcore/acx.h"
+
+#include "acx.h"
+
+int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap)
+{
+       struct wl1271_acx_host_config_bitmap *bitmap_conf;
+       int ret;
+
+       bitmap_conf = kzalloc(sizeof(*bitmap_conf), GFP_KERNEL);
+       if (!bitmap_conf) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       bitmap_conf->host_cfg_bitmap = cpu_to_le32(host_cfg_bitmap);
+
+       ret = wl1271_cmd_configure(wl, ACX_HOST_IF_CFG_BITMAP,
+                                  bitmap_conf, sizeof(*bitmap_conf));
+       if (ret < 0) {
+               wl1271_warning("wl1271 bitmap config opt failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(bitmap_conf);
+
+       return ret;
+}
diff --git a/drivers/net/wireless/ti/wl12xx/acx.h b/drivers/net/wireless/ti/wl12xx/acx.h
new file mode 100644 (file)
index 0000000..d1f5aba
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * This file is part of wl12xx
+ *
+ * Copyright (C) 1998-2009, 2011 Texas Instruments. All rights reserved.
+ * Copyright (C) 2008-2010 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL12XX_ACX_H__
+#define __WL12XX_ACX_H__
+
+#include "../wlcore/wlcore.h"
+
+struct wl1271_acx_host_config_bitmap {
+       struct acx_header header;
+
+       __le32 host_cfg_bitmap;
+} __packed;
+
+int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap);
+
+#endif /* __WL12XX_ACX_H__ */
diff --git a/drivers/net/wireless/ti/wl12xx/cmd.c b/drivers/net/wireless/ti/wl12xx/cmd.c
new file mode 100644 (file)
index 0000000..8ffaeb5
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+ * This file is part of wl12xx
+ *
+ * Copyright (C) 2009-2010 Nokia Corporation
+ * Copyright (C) 2011 Texas Instruments Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "../wlcore/cmd.h"
+#include "../wlcore/debug.h"
+
+#include "wl12xx.h"
+#include "cmd.h"
+
+int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
+{
+       struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
+       struct wl12xx_priv *priv = wl->priv;
+       struct wl12xx_conf_rf *rf = &priv->conf.rf;
+       int ret;
+
+       if (!wl->nvs)
+               return -ENODEV;
+
+       ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
+       if (!ext_radio_parms)
+               return -ENOMEM;
+
+       ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
+
+       memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
+              rf->tx_per_channel_power_compensation_2,
+              CONF_TX_PWR_COMPENSATION_LEN_2);
+       memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
+              rf->tx_per_channel_power_compensation_5,
+              CONF_TX_PWR_COMPENSATION_LEN_5);
+
+       wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
+                   ext_radio_parms, sizeof(*ext_radio_parms));
+
+       ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
+       if (ret < 0)
+               wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
+
+       kfree(ext_radio_parms);
+       return ret;
+}
+
+int wl1271_cmd_general_parms(struct wl1271 *wl)
+{
+       struct wl1271_general_parms_cmd *gen_parms;
+       struct wl1271_ini_general_params *gp =
+               &((struct wl1271_nvs_file *)wl->nvs)->general_params;
+       bool answer = false;
+       int ret;
+
+       if (!wl->nvs)
+               return -ENODEV;
+
+       if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
+               wl1271_warning("FEM index from INI out of bounds");
+               return -EINVAL;
+       }
+
+       gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
+       if (!gen_parms)
+               return -ENOMEM;
+
+       gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
+
+       memcpy(&gen_parms->general_params, gp, sizeof(*gp));
+
+       if (gp->tx_bip_fem_auto_detect)
+               answer = true;
+
+       /* Override the REF CLK from the NVS with the one from platform data */
+       gen_parms->general_params.ref_clock = wl->ref_clock;
+
+       ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
+       if (ret < 0) {
+               wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
+               goto out;
+       }
+
+       gp->tx_bip_fem_manufacturer =
+               gen_parms->general_params.tx_bip_fem_manufacturer;
+
+       if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
+               wl1271_warning("FEM index from FW out of bounds");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
+                    answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
+
+out:
+       kfree(gen_parms);
+       return ret;
+}
+
+int wl128x_cmd_general_parms(struct wl1271 *wl)
+{
+       struct wl128x_general_parms_cmd *gen_parms;
+       struct wl128x_ini_general_params *gp =
+               &((struct wl128x_nvs_file *)wl->nvs)->general_params;
+       bool answer = false;
+       int ret;
+
+       if (!wl->nvs)
+               return -ENODEV;
+
+       if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
+               wl1271_warning("FEM index from ini out of bounds");
+               return -EINVAL;
+       }
+
+       gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
+       if (!gen_parms)
+               return -ENOMEM;
+
+       gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
+
+       memcpy(&gen_parms->general_params, gp, sizeof(*gp));
+
+       if (gp->tx_bip_fem_auto_detect)
+               answer = true;
+
+       /* Replace REF and TCXO CLKs with the ones from platform data */
+       gen_parms->general_params.ref_clock = wl->ref_clock;
+       gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock;
+
+       ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
+       if (ret < 0) {
+               wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
+               goto out;
+       }
+
+       gp->tx_bip_fem_manufacturer =
+               gen_parms->general_params.tx_bip_fem_manufacturer;
+
+       if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
+               wl1271_warning("FEM index from FW out of bounds");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
+                    answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
+
+out:
+       kfree(gen_parms);
+       return ret;
+}
+
+int wl1271_cmd_radio_parms(struct wl1271 *wl)
+{
+       struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs;
+       struct wl1271_radio_parms_cmd *radio_parms;
+       struct wl1271_ini_general_params *gp = &nvs->general_params;
+       int ret;
+
+       if (!wl->nvs)
+               return -ENODEV;
+
+       radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
+       if (!radio_parms)
+               return -ENOMEM;
+
+       radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
+
+       /* 2.4GHz parameters */
+       memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
+              sizeof(struct wl1271_ini_band_params_2));
+       memcpy(&radio_parms->dyn_params_2,
+              &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
+              sizeof(struct wl1271_ini_fem_params_2));
+
+       /* 5GHz parameters */
+       memcpy(&radio_parms->static_params_5,
+              &nvs->stat_radio_params_5,
+              sizeof(struct wl1271_ini_band_params_5));
+       memcpy(&radio_parms->dyn_params_5,
+              &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
+              sizeof(struct wl1271_ini_fem_params_5));
+
+       wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
+                   radio_parms, sizeof(*radio_parms));
+
+       ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
+       if (ret < 0)
+               wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
+
+       kfree(radio_parms);
+       return ret;
+}
+
+int wl128x_cmd_radio_parms(struct wl1271 *wl)
+{
+       struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
+       struct wl128x_radio_parms_cmd *radio_parms;
+       struct wl128x_ini_general_params *gp = &nvs->general_params;
+       int ret;
+
+       if (!wl->nvs)
+               return -ENODEV;
+
+       radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
+       if (!radio_parms)
+               return -ENOMEM;
+
+       radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
+
+       /* 2.4GHz parameters */
+       memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
+              sizeof(struct wl128x_ini_band_params_2));
+       memcpy(&radio_parms->dyn_params_2,
+              &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
+              sizeof(struct wl128x_ini_fem_params_2));
+
+       /* 5GHz parameters */
+       memcpy(&radio_parms->static_params_5,
+              &nvs->stat_radio_params_5,
+              sizeof(struct wl128x_ini_band_params_5));
+       memcpy(&radio_parms->dyn_params_5,
+              &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
+              sizeof(struct wl128x_ini_fem_params_5));
+
+       radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options;
+
+       wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
+                   radio_parms, sizeof(*radio_parms));
+
+       ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
+       if (ret < 0)
+               wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
+
+       kfree(radio_parms);
+       return ret;
+}
diff --git a/drivers/net/wireless/ti/wl12xx/cmd.h b/drivers/net/wireless/ti/wl12xx/cmd.h
new file mode 100644 (file)
index 0000000..140a0e8
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * This file is part of wl12xx
+ *
+ * Copyright (C) 1998-2009, 2011 Texas Instruments. All rights reserved.
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL12XX_CMD_H__
+#define __WL12XX_CMD_H__
+
+#include "conf.h"
+
+#define TEST_CMD_INI_FILE_RADIO_PARAM       0x19
+#define TEST_CMD_INI_FILE_GENERAL_PARAM     0x1E
+
+struct wl1271_general_parms_cmd {
+       struct wl1271_cmd_header header;
+
+       struct wl1271_cmd_test_header test;
+
+       struct wl1271_ini_general_params general_params;
+
+       u8 sr_debug_table[WL1271_INI_MAX_SMART_REFLEX_PARAM];
+       u8 sr_sen_n_p;
+       u8 sr_sen_n_p_gain;
+       u8 sr_sen_nrn;
+       u8 sr_sen_prn;
+       u8 padding[3];
+} __packed;
+
+struct wl128x_general_parms_cmd {
+       struct wl1271_cmd_header header;
+
+       struct wl1271_cmd_test_header test;
+
+       struct wl128x_ini_general_params general_params;
+
+       u8 sr_debug_table[WL1271_INI_MAX_SMART_REFLEX_PARAM];
+       u8 sr_sen_n_p;
+       u8 sr_sen_n_p_gain;
+       u8 sr_sen_nrn;
+       u8 sr_sen_prn;
+       u8 padding[3];
+} __packed;
+
+struct wl1271_radio_parms_cmd {
+       struct wl1271_cmd_header header;
+
+       struct wl1271_cmd_test_header test;
+
+       /* Static radio parameters */
+       struct wl1271_ini_band_params_2 static_params_2;
+       struct wl1271_ini_band_params_5 static_params_5;
+
+       /* Dynamic radio parameters */
+       struct wl1271_ini_fem_params_2 dyn_params_2;
+       u8 padding2;
+       struct wl1271_ini_fem_params_5 dyn_params_5;
+       u8 padding3[2];
+} __packed;
+
+struct wl128x_radio_parms_cmd {
+       struct wl1271_cmd_header header;
+
+       struct wl1271_cmd_test_header test;
+
+       /* Static radio parameters */
+       struct wl128x_ini_band_params_2 static_params_2;
+       struct wl128x_ini_band_params_5 static_params_5;
+
+       u8 fem_vendor_and_options;
+
+       /* Dynamic radio parameters */
+       struct wl128x_ini_fem_params_2 dyn_params_2;
+       u8 padding2;
+       struct wl128x_ini_fem_params_5 dyn_params_5;
+} __packed;
+
+#define TEST_CMD_INI_FILE_RF_EXTENDED_PARAM 0x26
+
+struct wl1271_ext_radio_parms_cmd {
+       struct wl1271_cmd_header header;
+
+       struct wl1271_cmd_test_header test;
+
+       u8 tx_per_channel_power_compensation_2[CONF_TX_PWR_COMPENSATION_LEN_2];
+       u8 tx_per_channel_power_compensation_5[CONF_TX_PWR_COMPENSATION_LEN_5];
+       u8 padding[3];
+} __packed;
+
+int wl1271_cmd_general_parms(struct wl1271 *wl);
+int wl128x_cmd_general_parms(struct wl1271 *wl);
+int wl1271_cmd_radio_parms(struct wl1271 *wl);
+int wl128x_cmd_radio_parms(struct wl1271 *wl);
+int wl1271_cmd_ext_radio_parms(struct wl1271 *wl);
+
+#endif /* __WL12XX_CMD_H__ */
diff --git a/drivers/net/wireless/ti/wl12xx/conf.h b/drivers/net/wireless/ti/wl12xx/conf.h
new file mode 100644 (file)
index 0000000..75e2989
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * This file is part of wl12xx
+ *
+ * Copyright (C) 2011 Texas Instruments Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL12XX_CONF_H__
+#define __WL12XX_CONF_H__
+
+/* these are number of channels on the band divided by two, rounded up */
+#define CONF_TX_PWR_COMPENSATION_LEN_2 7
+#define CONF_TX_PWR_COMPENSATION_LEN_5 18
+
+struct wl12xx_conf_rf {
+       /*
+        * Per channel power compensation for 2.4GHz
+        *
+        * Range: s8
+        */
+       u8 tx_per_channel_power_compensation_2[CONF_TX_PWR_COMPENSATION_LEN_2];
+
+       /*
+        * Per channel power compensation for 5GHz
+        *
+        * Range: s8
+        */
+       u8 tx_per_channel_power_compensation_5[CONF_TX_PWR_COMPENSATION_LEN_5];
+};
+
+struct wl12xx_priv_conf {
+       struct wl12xx_conf_rf rf;
+       struct conf_memory_settings mem_wl127x;
+};
+
+#endif /* __WL12XX_CONF_H__ */
diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
new file mode 100644 (file)
index 0000000..d7dd3de
--- /dev/null
@@ -0,0 +1,1388 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2008-2010 Nokia Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+#include <linux/err.h>
+
+#include <linux/wl12xx.h>
+
+#include "../wlcore/wlcore.h"
+#include "../wlcore/debug.h"
+#include "../wlcore/io.h"
+#include "../wlcore/acx.h"
+#include "../wlcore/tx.h"
+#include "../wlcore/rx.h"
+#include "../wlcore/io.h"
+#include "../wlcore/boot.h"
+
+#include "wl12xx.h"
+#include "reg.h"
+#include "cmd.h"
+#include "acx.h"
+
+static struct wlcore_conf wl12xx_conf = {
+       .sg = {
+               .params = {
+                       [CONF_SG_ACL_BT_MASTER_MIN_BR] = 10,
+                       [CONF_SG_ACL_BT_MASTER_MAX_BR] = 180,
+                       [CONF_SG_ACL_BT_SLAVE_MIN_BR] = 10,
+                       [CONF_SG_ACL_BT_SLAVE_MAX_BR] = 180,
+                       [CONF_SG_ACL_BT_MASTER_MIN_EDR] = 10,
+                       [CONF_SG_ACL_BT_MASTER_MAX_EDR] = 80,
+                       [CONF_SG_ACL_BT_SLAVE_MIN_EDR] = 10,
+                       [CONF_SG_ACL_BT_SLAVE_MAX_EDR] = 80,
+                       [CONF_SG_ACL_WLAN_PS_MASTER_BR] = 8,
+                       [CONF_SG_ACL_WLAN_PS_SLAVE_BR] = 8,
+                       [CONF_SG_ACL_WLAN_PS_MASTER_EDR] = 20,
+                       [CONF_SG_ACL_WLAN_PS_SLAVE_EDR] = 20,
+                       [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR] = 20,
+                       [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR] = 35,
+                       [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR] = 16,
+                       [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR] = 35,
+                       [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR] = 32,
+                       [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR] = 50,
+                       [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR] = 28,
+                       [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR] = 50,
+                       [CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR] = 10,
+                       [CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR] = 20,
+                       [CONF_SG_ACL_PASSIVE_SCAN_BT_BR] = 75,
+                       [CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR] = 15,
+                       [CONF_SG_ACL_PASSIVE_SCAN_BT_EDR] = 27,
+                       [CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR] = 17,
+                       /* active scan params */
+                       [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
+                       [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
+                       [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
+                       /* passive scan params */
+                       [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR] = 800,
+                       [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR] = 200,
+                       [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
+                       /* passive scan in dual antenna params */
+                       [CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN] = 0,
+                       [CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN] = 0,
+                       [CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN] = 0,
+                       /* general params */
+                       [CONF_SG_STA_FORCE_PS_IN_BT_SCO] = 1,
+                       [CONF_SG_ANTENNA_CONFIGURATION] = 0,
+                       [CONF_SG_BEACON_MISS_PERCENT] = 60,
+                       [CONF_SG_DHCP_TIME] = 5000,
+                       [CONF_SG_RXT] = 1200,
+                       [CONF_SG_TXT] = 1000,
+                       [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
+                       [CONF_SG_GENERAL_USAGE_BIT_MAP] = 3,
+                       [CONF_SG_HV3_MAX_SERVED] = 6,
+                       [CONF_SG_PS_POLL_TIMEOUT] = 10,
+                       [CONF_SG_UPSD_TIMEOUT] = 10,
+                       [CONF_SG_CONSECUTIVE_CTS_THRESHOLD] = 2,
+                       [CONF_SG_STA_RX_WINDOW_AFTER_DTIM] = 5,
+                       [CONF_SG_STA_CONNECTION_PROTECTION_TIME] = 30,
+                       /* AP params */
+                       [CONF_AP_BEACON_MISS_TX] = 3,
+                       [CONF_AP_RX_WINDOW_AFTER_BEACON] = 10,
+                       [CONF_AP_BEACON_WINDOW_INTERVAL] = 2,
+                       [CONF_AP_CONNECTION_PROTECTION_TIME] = 0,
+                       [CONF_AP_BT_ACL_VAL_BT_SERVE_TIME] = 25,
+                       [CONF_AP_BT_ACL_VAL_WL_SERVE_TIME] = 25,
+                       /* CTS Diluting params */
+                       [CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH] = 0,
+                       [CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER] = 0,
+               },
+               .state = CONF_SG_PROTECTIVE,
+       },
+       .rx = {
+               .rx_msdu_life_time           = 512000,
+               .packet_detection_threshold  = 0,
+               .ps_poll_timeout             = 15,
+               .upsd_timeout                = 15,
+               .rts_threshold               = IEEE80211_MAX_RTS_THRESHOLD,
+               .rx_cca_threshold            = 0,
+               .irq_blk_threshold           = 0xFFFF,
+               .irq_pkt_threshold           = 0,
+               .irq_timeout                 = 600,
+               .queue_type                  = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
+       },
+       .tx = {
+               .tx_energy_detection         = 0,
+               .sta_rc_conf                 = {
+                       .enabled_rates       = 0,
+                       .short_retry_limit   = 10,
+                       .long_retry_limit    = 10,
+                       .aflags              = 0,
+               },
+               .ac_conf_count               = 4,
+               .ac_conf                     = {
+                       [CONF_TX_AC_BE] = {
+                               .ac          = CONF_TX_AC_BE,
+                               .cw_min      = 15,
+                               .cw_max      = 63,
+                               .aifsn       = 3,
+                               .tx_op_limit = 0,
+                       },
+                       [CONF_TX_AC_BK] = {
+                               .ac          = CONF_TX_AC_BK,
+                               .cw_min      = 15,
+                               .cw_max      = 63,
+                               .aifsn       = 7,
+                               .tx_op_limit = 0,
+                       },
+                       [CONF_TX_AC_VI] = {
+                               .ac          = CONF_TX_AC_VI,
+                               .cw_min      = 15,
+                               .cw_max      = 63,
+                               .aifsn       = CONF_TX_AIFS_PIFS,
+                               .tx_op_limit = 3008,
+                       },
+                       [CONF_TX_AC_VO] = {
+                               .ac          = CONF_TX_AC_VO,
+                               .cw_min      = 15,
+                               .cw_max      = 63,
+                               .aifsn       = CONF_TX_AIFS_PIFS,
+                               .tx_op_limit = 1504,
+                       },
+               },
+               .max_tx_retries = 100,
+               .ap_aging_period = 300,
+               .tid_conf_count = 4,
+               .tid_conf = {
+                       [CONF_TX_AC_BE] = {
+                               .queue_id    = CONF_TX_AC_BE,
+                               .channel_type = CONF_CHANNEL_TYPE_EDCF,
+                               .tsid        = CONF_TX_AC_BE,
+                               .ps_scheme   = CONF_PS_SCHEME_LEGACY,
+                               .ack_policy  = CONF_ACK_POLICY_LEGACY,
+                               .apsd_conf   = {0, 0},
+                       },
+                       [CONF_TX_AC_BK] = {
+                               .queue_id    = CONF_TX_AC_BK,
+                               .channel_type = CONF_CHANNEL_TYPE_EDCF,
+                               .tsid        = CONF_TX_AC_BK,
+                               .ps_scheme   = CONF_PS_SCHEME_LEGACY,
+                               .ack_policy  = CONF_ACK_POLICY_LEGACY,
+                               .apsd_conf   = {0, 0},
+                       },
+                       [CONF_TX_AC_VI] = {
+                               .queue_id    = CONF_TX_AC_VI,
+                               .channel_type = CONF_CHANNEL_TYPE_EDCF,
+                               .tsid        = CONF_TX_AC_VI,
+                               .ps_scheme   = CONF_PS_SCHEME_LEGACY,
+                               .ack_policy  = CONF_ACK_POLICY_LEGACY,
+                               .apsd_conf   = {0, 0},
+                       },
+                       [CONF_TX_AC_VO] = {
+                               .queue_id    = CONF_TX_AC_VO,
+                               .channel_type = CONF_CHANNEL_TYPE_EDCF,
+                               .tsid        = CONF_TX_AC_VO,
+                               .ps_scheme   = CONF_PS_SCHEME_LEGACY,
+                               .ack_policy  = CONF_ACK_POLICY_LEGACY,
+                               .apsd_conf   = {0, 0},
+                       },
+               },
+               .frag_threshold              = IEEE80211_MAX_FRAG_THRESHOLD,
+               .tx_compl_timeout            = 700,
+               .tx_compl_threshold          = 4,
+               .basic_rate                  = CONF_HW_BIT_RATE_1MBPS,
+               .basic_rate_5                = CONF_HW_BIT_RATE_6MBPS,
+               .tmpl_short_retry_limit      = 10,
+               .tmpl_long_retry_limit       = 10,
+               .tx_watchdog_timeout         = 5000,
+       },
+       .conn = {
+               .wake_up_event               = CONF_WAKE_UP_EVENT_DTIM,
+               .listen_interval             = 1,
+               .suspend_wake_up_event       = CONF_WAKE_UP_EVENT_N_DTIM,
+               .suspend_listen_interval     = 3,
+               .bcn_filt_mode               = CONF_BCN_FILT_MODE_ENABLED,
+               .bcn_filt_ie_count           = 2,
+               .bcn_filt_ie = {
+                       [0] = {
+                               .ie          = WLAN_EID_CHANNEL_SWITCH,
+                               .rule        = CONF_BCN_RULE_PASS_ON_APPEARANCE,
+                       },
+                       [1] = {
+                               .ie          = WLAN_EID_HT_OPERATION,
+                               .rule        = CONF_BCN_RULE_PASS_ON_CHANGE,
+                       },
+               },
+               .synch_fail_thold            = 10,
+               .bss_lose_timeout            = 100,
+               .beacon_rx_timeout           = 10000,
+               .broadcast_timeout           = 20000,
+               .rx_broadcast_in_ps          = 1,
+               .ps_poll_threshold           = 10,
+               .bet_enable                  = CONF_BET_MODE_ENABLE,
+               .bet_max_consecutive         = 50,
+               .psm_entry_retries           = 8,
+               .psm_exit_retries            = 16,
+               .psm_entry_nullfunc_retries  = 3,
+               .dynamic_ps_timeout          = 40,
+               .forced_ps                   = false,
+               .keep_alive_interval         = 55000,
+               .max_listen_interval         = 20,
+       },
+       .itrim = {
+               .enable = false,
+               .timeout = 50000,
+       },
+       .pm_config = {
+               .host_clk_settling_time = 5000,
+               .host_fast_wakeup_support = false
+       },
+       .roam_trigger = {
+               .trigger_pacing               = 1,
+               .avg_weight_rssi_beacon       = 20,
+               .avg_weight_rssi_data         = 10,
+               .avg_weight_snr_beacon        = 20,
+               .avg_weight_snr_data          = 10,
+       },
+       .scan = {
+               .min_dwell_time_active        = 7500,
+               .max_dwell_time_active        = 30000,
+               .min_dwell_time_passive       = 100000,
+               .max_dwell_time_passive       = 100000,
+               .num_probe_reqs               = 2,
+               .split_scan_timeout           = 50000,
+       },
+       .sched_scan = {
+               /*
+                * Values are in TU/1000 but since sched scan FW command
+                * params are in TUs rounding up may occur.
+                */
+               .base_dwell_time                = 7500,
+               .max_dwell_time_delta           = 22500,
+               /* based on 250bits per probe @1Mbps */
+               .dwell_time_delta_per_probe     = 2000,
+               /* based on 250bits per probe @6Mbps (plus a bit more) */
+               .dwell_time_delta_per_probe_5   = 350,
+               .dwell_time_passive             = 100000,
+               .dwell_time_dfs                 = 150000,
+               .num_probe_reqs                 = 2,
+               .rssi_threshold                 = -90,
+               .snr_threshold                  = 0,
+       },
+       .ht = {
+               .rx_ba_win_size = 8,
+               .tx_ba_win_size = 64,
+               .inactivity_timeout = 10000,
+               .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP,
+       },
+       /*
+        * Memory config for wl127x chips is given in the
+        * wl12xx_default_priv_conf struct. The below configuration is
+        * for wl128x chips.
+        */
+       .mem = {
+               .num_stations                 = 1,
+               .ssid_profiles                = 1,
+               .rx_block_num                 = 40,
+               .tx_min_block_num             = 40,
+               .dynamic_memory               = 1,
+               .min_req_tx_blocks            = 45,
+               .min_req_rx_blocks            = 22,
+               .tx_min                       = 27,
+       },
+       .fm_coex = {
+               .enable                       = true,
+               .swallow_period               = 5,
+               .n_divider_fref_set_1         = 0xff,       /* default */
+               .n_divider_fref_set_2         = 12,
+               .m_divider_fref_set_1         = 148,
+               .m_divider_fref_set_2         = 0xffff,     /* default */
+               .coex_pll_stabilization_time  = 0xffffffff, /* default */
+               .ldo_stabilization_time       = 0xffff,     /* default */
+               .fm_disturbed_band_margin     = 0xff,       /* default */
+               .swallow_clk_diff             = 0xff,       /* default */
+       },
+       .rx_streaming = {
+               .duration                      = 150,
+               .queues                        = 0x1,
+               .interval                      = 20,
+               .always                        = 0,
+       },
+       .fwlog = {
+               .mode                         = WL12XX_FWLOG_ON_DEMAND,
+               .mem_blocks                   = 2,
+               .severity                     = 0,
+               .timestamp                    = WL12XX_FWLOG_TIMESTAMP_DISABLED,
+               .output                       = WL12XX_FWLOG_OUTPUT_HOST,
+               .threshold                    = 0,
+       },
+       .rate = {
+               .rate_retry_score = 32000,
+               .per_add = 8192,
+               .per_th1 = 2048,
+               .per_th2 = 4096,
+               .max_per = 8100,
+               .inverse_curiosity_factor = 5,
+               .tx_fail_low_th = 4,
+               .tx_fail_high_th = 10,
+               .per_alpha_shift = 4,
+               .per_add_shift = 13,
+               .per_beta1_shift = 10,
+               .per_beta2_shift = 8,
+               .rate_check_up = 2,
+               .rate_check_down = 12,
+               .rate_retry_policy = {
+                       0x00, 0x00, 0x00, 0x00, 0x00,
+                       0x00, 0x00, 0x00, 0x00, 0x00,
+                       0x00, 0x00, 0x00,
+               },
+       },
+       .hangover = {
+               .recover_time               = 0,
+               .hangover_period            = 20,
+               .dynamic_mode               = 1,
+               .early_termination_mode     = 1,
+               .max_period                 = 20,
+               .min_period                 = 1,
+               .increase_delta             = 1,
+               .decrease_delta             = 2,
+               .quiet_time                 = 4,
+               .increase_time              = 1,
+               .window_size                = 16,
+       },
+};
+
+static struct wl12xx_priv_conf wl12xx_default_priv_conf = {
+       .rf = {
+               .tx_per_channel_power_compensation_2 = {
+                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               },
+               .tx_per_channel_power_compensation_5 = {
+                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               },
+       },
+       .mem_wl127x = {
+               .num_stations                 = 1,
+               .ssid_profiles                = 1,
+               .rx_block_num                 = 70,
+               .tx_min_block_num             = 40,
+               .dynamic_memory               = 1,
+               .min_req_tx_blocks            = 100,
+               .min_req_rx_blocks            = 22,
+               .tx_min                       = 27,
+       },
+
+};
+
+#define WL12XX_TX_HW_BLOCK_SPARE_DEFAULT        1
+#define WL12XX_TX_HW_BLOCK_GEM_SPARE            2
+#define WL12XX_TX_HW_BLOCK_SIZE                 252
+
+static const u8 wl12xx_rate_to_idx_2ghz[] = {
+       /* MCS rates are used only with 11n */
+       7,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS7_SGI */
+       7,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS7 */
+       6,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS6 */
+       5,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS5 */
+       4,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS4 */
+       3,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS3 */
+       2,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS2 */
+       1,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS1 */
+       0,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS0 */
+
+       11,                            /* WL12XX_CONF_HW_RXTX_RATE_54   */
+       10,                            /* WL12XX_CONF_HW_RXTX_RATE_48   */
+       9,                             /* WL12XX_CONF_HW_RXTX_RATE_36   */
+       8,                             /* WL12XX_CONF_HW_RXTX_RATE_24   */
+
+       /* TI-specific rate */
+       CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_22   */
+
+       7,                             /* WL12XX_CONF_HW_RXTX_RATE_18   */
+       6,                             /* WL12XX_CONF_HW_RXTX_RATE_12   */
+       3,                             /* WL12XX_CONF_HW_RXTX_RATE_11   */
+       5,                             /* WL12XX_CONF_HW_RXTX_RATE_9    */
+       4,                             /* WL12XX_CONF_HW_RXTX_RATE_6    */
+       2,                             /* WL12XX_CONF_HW_RXTX_RATE_5_5  */
+       1,                             /* WL12XX_CONF_HW_RXTX_RATE_2    */
+       0                              /* WL12XX_CONF_HW_RXTX_RATE_1    */
+};
+
+static const u8 wl12xx_rate_to_idx_5ghz[] = {
+       /* MCS rates are used only with 11n */
+       7,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS7_SGI */
+       7,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS7 */
+       6,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS6 */
+       5,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS5 */
+       4,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS4 */
+       3,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS3 */
+       2,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS2 */
+       1,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS1 */
+       0,                             /* WL12XX_CONF_HW_RXTX_RATE_MCS0 */
+
+       7,                             /* WL12XX_CONF_HW_RXTX_RATE_54   */
+       6,                             /* WL12XX_CONF_HW_RXTX_RATE_48   */
+       5,                             /* WL12XX_CONF_HW_RXTX_RATE_36   */
+       4,                             /* WL12XX_CONF_HW_RXTX_RATE_24   */
+
+       /* TI-specific rate */
+       CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_22   */
+
+       3,                             /* WL12XX_CONF_HW_RXTX_RATE_18   */
+       2,                             /* WL12XX_CONF_HW_RXTX_RATE_12   */
+       CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_11   */
+       1,                             /* WL12XX_CONF_HW_RXTX_RATE_9    */
+       0,                             /* WL12XX_CONF_HW_RXTX_RATE_6    */
+       CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_5_5  */
+       CONF_HW_RXTX_RATE_UNSUPPORTED, /* WL12XX_CONF_HW_RXTX_RATE_2    */
+       CONF_HW_RXTX_RATE_UNSUPPORTED  /* WL12XX_CONF_HW_RXTX_RATE_1    */
+};
+
+static const u8 *wl12xx_band_rate_to_idx[] = {
+       [IEEE80211_BAND_2GHZ] = wl12xx_rate_to_idx_2ghz,
+       [IEEE80211_BAND_5GHZ] = wl12xx_rate_to_idx_5ghz
+};
+
+enum wl12xx_hw_rates {
+       WL12XX_CONF_HW_RXTX_RATE_MCS7_SGI = 0,
+       WL12XX_CONF_HW_RXTX_RATE_MCS7,
+       WL12XX_CONF_HW_RXTX_RATE_MCS6,
+       WL12XX_CONF_HW_RXTX_RATE_MCS5,
+       WL12XX_CONF_HW_RXTX_RATE_MCS4,
+       WL12XX_CONF_HW_RXTX_RATE_MCS3,
+       WL12XX_CONF_HW_RXTX_RATE_MCS2,
+       WL12XX_CONF_HW_RXTX_RATE_MCS1,
+       WL12XX_CONF_HW_RXTX_RATE_MCS0,
+       WL12XX_CONF_HW_RXTX_RATE_54,
+       WL12XX_CONF_HW_RXTX_RATE_48,
+       WL12XX_CONF_HW_RXTX_RATE_36,
+       WL12XX_CONF_HW_RXTX_RATE_24,
+       WL12XX_CONF_HW_RXTX_RATE_22,
+       WL12XX_CONF_HW_RXTX_RATE_18,
+       WL12XX_CONF_HW_RXTX_RATE_12,
+       WL12XX_CONF_HW_RXTX_RATE_11,
+       WL12XX_CONF_HW_RXTX_RATE_9,
+       WL12XX_CONF_HW_RXTX_RATE_6,
+       WL12XX_CONF_HW_RXTX_RATE_5_5,
+       WL12XX_CONF_HW_RXTX_RATE_2,
+       WL12XX_CONF_HW_RXTX_RATE_1,
+       WL12XX_CONF_HW_RXTX_RATE_MAX,
+};
+
+static struct wlcore_partition_set wl12xx_ptable[PART_TABLE_LEN] = {
+       [PART_DOWN] = {
+               .mem = {
+                       .start = 0x00000000,
+                       .size  = 0x000177c0
+               },
+               .reg = {
+                       .start = REGISTERS_BASE,
+                       .size  = 0x00008800
+               },
+               .mem2 = {
+                       .start = 0x00000000,
+                       .size  = 0x00000000
+               },
+               .mem3 = {
+                       .start = 0x00000000,
+                       .size  = 0x00000000
+               },
+       },
+
+       [PART_BOOT] = { /* in wl12xx we can use a mix of work and down
+                        * partition here */
+               .mem = {
+                       .start = 0x00040000,
+                       .size  = 0x00014fc0
+               },
+               .reg = {
+                       .start = REGISTERS_BASE,
+                       .size  = 0x00008800
+               },
+               .mem2 = {
+                       .start = 0x00000000,
+                       .size  = 0x00000000
+               },
+               .mem3 = {
+                       .start = 0x00000000,
+                       .size  = 0x00000000
+               },
+       },
+
+       [PART_WORK] = {
+               .mem = {
+                       .start = 0x00040000,
+                       .size  = 0x00014fc0
+               },
+               .reg = {
+                       .start = REGISTERS_BASE,
+                       .size  = 0x0000a000
+               },
+               .mem2 = {
+                       .start = 0x003004f8,
+                       .size  = 0x00000004
+               },
+               .mem3 = {
+                       .start = 0x00040404,
+                       .size  = 0x00000000
+               },
+       },
+
+       [PART_DRPW] = {
+               .mem = {
+                       .start = 0x00040000,
+                       .size  = 0x00014fc0
+               },
+               .reg = {
+                       .start = DRPW_BASE,
+                       .size  = 0x00006000
+               },
+               .mem2 = {
+                       .start = 0x00000000,
+                       .size  = 0x00000000
+               },
+               .mem3 = {
+                       .start = 0x00000000,
+                       .size  = 0x00000000
+               }
+       }
+};
+
+static const int wl12xx_rtable[REG_TABLE_LEN] = {
+       [REG_ECPU_CONTROL]              = WL12XX_REG_ECPU_CONTROL,
+       [REG_INTERRUPT_NO_CLEAR]        = WL12XX_REG_INTERRUPT_NO_CLEAR,
+       [REG_INTERRUPT_ACK]             = WL12XX_REG_INTERRUPT_ACK,
+       [REG_COMMAND_MAILBOX_PTR]       = WL12XX_REG_COMMAND_MAILBOX_PTR,
+       [REG_EVENT_MAILBOX_PTR]         = WL12XX_REG_EVENT_MAILBOX_PTR,
+       [REG_INTERRUPT_TRIG]            = WL12XX_REG_INTERRUPT_TRIG,
+       [REG_INTERRUPT_MASK]            = WL12XX_REG_INTERRUPT_MASK,
+       [REG_PC_ON_RECOVERY]            = WL12XX_SCR_PAD4,
+       [REG_CHIP_ID_B]                 = WL12XX_CHIP_ID_B,
+       [REG_CMD_MBOX_ADDRESS]          = WL12XX_CMD_MBOX_ADDRESS,
+
+       /* data access memory addresses, used with partition translation */
+       [REG_SLV_MEM_DATA]              = WL1271_SLV_MEM_DATA,
+       [REG_SLV_REG_DATA]              = WL1271_SLV_REG_DATA,
+
+       /* raw data access memory addresses */
+       [REG_RAW_FW_STATUS_ADDR]        = FW_STATUS_ADDR,
+};
+
+/* TODO: maybe move to a new header file? */
+#define WL127X_FW_NAME_MULTI   "ti-connectivity/wl127x-fw-4-mr.bin"
+#define WL127X_FW_NAME_SINGLE  "ti-connectivity/wl127x-fw-4-sr.bin"
+#define WL127X_PLT_FW_NAME     "ti-connectivity/wl127x-fw-4-plt.bin"
+
+#define WL128X_FW_NAME_MULTI   "ti-connectivity/wl128x-fw-4-mr.bin"
+#define WL128X_FW_NAME_SINGLE  "ti-connectivity/wl128x-fw-4-sr.bin"
+#define WL128X_PLT_FW_NAME     "ti-connectivity/wl128x-fw-4-plt.bin"
+
+static void wl127x_prepare_read(struct wl1271 *wl, u32 rx_desc, u32 len)
+{
+       if (wl->chip.id != CHIP_ID_1283_PG20) {
+               struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
+               struct wl1271_rx_mem_pool_addr rx_mem_addr;
+
+               /*
+                * Choose the block we want to read
+                * For aggregated packets, only the first memory block
+                * should be retrieved. The FW takes care of the rest.
+                */
+               u32 mem_block = rx_desc & RX_MEM_BLOCK_MASK;
+
+               rx_mem_addr.addr = (mem_block << 8) +
+                       le32_to_cpu(wl_mem_map->packet_memory_pool_start);
+
+               rx_mem_addr.addr_extra = rx_mem_addr.addr + 4;
+
+               wl1271_write(wl, WL1271_SLV_REG_DATA,
+                            &rx_mem_addr, sizeof(rx_mem_addr), false);
+       }
+}
+
+static int wl12xx_identify_chip(struct wl1271 *wl)
+{
+       int ret = 0;
+
+       switch (wl->chip.id) {
+       case CHIP_ID_1271_PG10:
+               wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
+                              wl->chip.id);
+
+               /* clear the alignment quirk, since we don't support it */
+               wl->quirks &= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN;
+
+               wl->quirks |= WLCORE_QUIRK_LEGACY_NVS;
+               wl->sr_fw_name = WL127X_FW_NAME_SINGLE;
+               wl->mr_fw_name = WL127X_FW_NAME_MULTI;
+               memcpy(&wl->conf.mem, &wl12xx_default_priv_conf.mem_wl127x,
+                      sizeof(wl->conf.mem));
+
+               /* read data preparation is only needed by wl127x */
+               wl->ops->prepare_read = wl127x_prepare_read;
+
+               break;
+
+       case CHIP_ID_1271_PG20:
+               wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
+                            wl->chip.id);
+
+               /* clear the alignment quirk, since we don't support it */
+               wl->quirks &= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN;
+
+               wl->quirks |= WLCORE_QUIRK_LEGACY_NVS;
+               wl->plt_fw_name = WL127X_PLT_FW_NAME;
+               wl->sr_fw_name = WL127X_FW_NAME_SINGLE;
+               wl->mr_fw_name = WL127X_FW_NAME_MULTI;
+               memcpy(&wl->conf.mem, &wl12xx_default_priv_conf.mem_wl127x,
+                      sizeof(wl->conf.mem));
+
+               /* read data preparation is only needed by wl127x */
+               wl->ops->prepare_read = wl127x_prepare_read;
+
+               break;
+
+       case CHIP_ID_1283_PG20:
+               wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
+                            wl->chip.id);
+               wl->plt_fw_name = WL128X_PLT_FW_NAME;
+               wl->sr_fw_name = WL128X_FW_NAME_SINGLE;
+               wl->mr_fw_name = WL128X_FW_NAME_MULTI;
+               break;
+       case CHIP_ID_1283_PG10:
+       default:
+               wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
+               ret = -ENODEV;
+               goto out;
+       }
+
+out:
+       return ret;
+}
+
+static void wl12xx_top_reg_write(struct wl1271 *wl, int addr, u16 val)
+{
+       /* write address >> 1 + 0x30000 to OCP_POR_CTR */
+       addr = (addr >> 1) + 0x30000;
+       wl1271_write32(wl, WL12XX_OCP_POR_CTR, addr);
+
+       /* write value to OCP_POR_WDATA */
+       wl1271_write32(wl, WL12XX_OCP_DATA_WRITE, val);
+
+       /* write 1 to OCP_CMD */
+       wl1271_write32(wl, WL12XX_OCP_CMD, OCP_CMD_WRITE);
+}
+
+static u16 wl12xx_top_reg_read(struct wl1271 *wl, int addr)
+{
+       u32 val;
+       int timeout = OCP_CMD_LOOP;
+
+       /* write address >> 1 + 0x30000 to OCP_POR_CTR */
+       addr = (addr >> 1) + 0x30000;
+       wl1271_write32(wl, WL12XX_OCP_POR_CTR, addr);
+
+       /* write 2 to OCP_CMD */
+       wl1271_write32(wl, WL12XX_OCP_CMD, OCP_CMD_READ);
+
+       /* poll for data ready */
+       do {
+               val = wl1271_read32(wl, WL12XX_OCP_DATA_READ);
+       } while (!(val & OCP_READY_MASK) && --timeout);
+
+       if (!timeout) {
+               wl1271_warning("Top register access timed out.");
+               return 0xffff;
+       }
+
+       /* check data status and return if OK */
+       if ((val & OCP_STATUS_MASK) == OCP_STATUS_OK)
+               return val & 0xffff;
+       else {
+               wl1271_warning("Top register access returned error.");
+               return 0xffff;
+       }
+}
+
+static int wl128x_switch_tcxo_to_fref(struct wl1271 *wl)
+{
+       u16 spare_reg;
+
+       /* Mask bits [2] & [8:4] in the sys_clk_cfg register */
+       spare_reg = wl12xx_top_reg_read(wl, WL_SPARE_REG);
+       if (spare_reg == 0xFFFF)
+               return -EFAULT;
+       spare_reg |= (BIT(3) | BIT(5) | BIT(6));
+       wl12xx_top_reg_write(wl, WL_SPARE_REG, spare_reg);
+
+       /* Enable FREF_CLK_REQ & mux MCS and coex PLLs to FREF */
+       wl12xx_top_reg_write(wl, SYS_CLK_CFG_REG,
+                            WL_CLK_REQ_TYPE_PG2 | MCS_PLL_CLK_SEL_FREF);
+
+       /* Delay execution for 15msec, to let the HW settle */
+       mdelay(15);
+
+       return 0;
+}
+
+static bool wl128x_is_tcxo_valid(struct wl1271 *wl)
+{
+       u16 tcxo_detection;
+
+       tcxo_detection = wl12xx_top_reg_read(wl, TCXO_CLK_DETECT_REG);
+       if (tcxo_detection & TCXO_DET_FAILED)
+               return false;
+
+       return true;
+}
+
+static bool wl128x_is_fref_valid(struct wl1271 *wl)
+{
+       u16 fref_detection;
+
+       fref_detection = wl12xx_top_reg_read(wl, FREF_CLK_DETECT_REG);
+       if (fref_detection & FREF_CLK_DETECT_FAIL)
+               return false;
+
+       return true;
+}
+
+static int wl128x_manually_configure_mcs_pll(struct wl1271 *wl)
+{
+       wl12xx_top_reg_write(wl, MCS_PLL_M_REG, MCS_PLL_M_REG_VAL);
+       wl12xx_top_reg_write(wl, MCS_PLL_N_REG, MCS_PLL_N_REG_VAL);
+       wl12xx_top_reg_write(wl, MCS_PLL_CONFIG_REG, MCS_PLL_CONFIG_REG_VAL);
+
+       return 0;
+}
+
+static int wl128x_configure_mcs_pll(struct wl1271 *wl, int clk)
+{
+       u16 spare_reg;
+       u16 pll_config;
+       u8 input_freq;
+
+       /* Mask bits [3:1] in the sys_clk_cfg register */
+       spare_reg = wl12xx_top_reg_read(wl, WL_SPARE_REG);
+       if (spare_reg == 0xFFFF)
+               return -EFAULT;
+       spare_reg |= BIT(2);
+       wl12xx_top_reg_write(wl, WL_SPARE_REG, spare_reg);
+
+       /* Handle special cases of the TCXO clock */
+       if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_8 ||
+           wl->tcxo_clock == WL12XX_TCXOCLOCK_33_6)
+               return wl128x_manually_configure_mcs_pll(wl);
+
+       /* Set the input frequency according to the selected clock source */
+       input_freq = (clk & 1) + 1;
+
+       pll_config = wl12xx_top_reg_read(wl, MCS_PLL_CONFIG_REG);
+       if (pll_config == 0xFFFF)
+               return -EFAULT;
+       pll_config |= (input_freq << MCS_SEL_IN_FREQ_SHIFT);
+       pll_config |= MCS_PLL_ENABLE_HP;
+       wl12xx_top_reg_write(wl, MCS_PLL_CONFIG_REG, pll_config);
+
+       return 0;
+}
+
+/*
+ * WL128x has two clocks input - TCXO and FREF.
+ * TCXO is the main clock of the device, while FREF is used to sync
+ * between the GPS and the cellular modem.
+ * In cases where TCXO is 32.736MHz or 16.368MHz, the FREF will be used
+ * as the WLAN/BT main clock.
+ */
+static int wl128x_boot_clk(struct wl1271 *wl, int *selected_clock)
+{
+       u16 sys_clk_cfg;
+
+       /* For XTAL-only modes, FREF will be used after switching from TCXO */
+       if (wl->ref_clock == WL12XX_REFCLOCK_26_XTAL ||
+           wl->ref_clock == WL12XX_REFCLOCK_38_XTAL) {
+               if (!wl128x_switch_tcxo_to_fref(wl))
+                       return -EINVAL;
+               goto fref_clk;
+       }
+
+       /* Query the HW, to determine which clock source we should use */
+       sys_clk_cfg = wl12xx_top_reg_read(wl, SYS_CLK_CFG_REG);
+       if (sys_clk_cfg == 0xFFFF)
+               return -EINVAL;
+       if (sys_clk_cfg & PRCM_CM_EN_MUX_WLAN_FREF)
+               goto fref_clk;
+
+       /* If TCXO is either 32.736MHz or 16.368MHz, switch to FREF */
+       if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_368 ||
+           wl->tcxo_clock == WL12XX_TCXOCLOCK_32_736) {
+               if (!wl128x_switch_tcxo_to_fref(wl))
+                       return -EINVAL;
+               goto fref_clk;
+       }
+
+       /* TCXO clock is selected */
+       if (!wl128x_is_tcxo_valid(wl))
+               return -EINVAL;
+       *selected_clock = wl->tcxo_clock;
+       goto config_mcs_pll;
+
+fref_clk:
+       /* FREF clock is selected */
+       if (!wl128x_is_fref_valid(wl))
+               return -EINVAL;
+       *selected_clock = wl->ref_clock;
+
+config_mcs_pll:
+       return wl128x_configure_mcs_pll(wl, *selected_clock);
+}
+
+static int wl127x_boot_clk(struct wl1271 *wl)
+{
+       u32 pause;
+       u32 clk;
+
+       if (WL127X_PG_GET_MAJOR(wl->hw_pg_ver) < 3)
+               wl->quirks |= WLCORE_QUIRK_END_OF_TRANSACTION;
+
+       if (wl->ref_clock == CONF_REF_CLK_19_2_E ||
+           wl->ref_clock == CONF_REF_CLK_38_4_E ||
+           wl->ref_clock == CONF_REF_CLK_38_4_M_XTAL)
+               /* ref clk: 19.2/38.4/38.4-XTAL */
+               clk = 0x3;
+       else if (wl->ref_clock == CONF_REF_CLK_26_E ||
+                wl->ref_clock == CONF_REF_CLK_52_E)
+               /* ref clk: 26/52 */
+               clk = 0x5;
+       else
+               return -EINVAL;
+
+       if (wl->ref_clock != CONF_REF_CLK_19_2_E) {
+               u16 val;
+               /* Set clock type (open drain) */
+               val = wl12xx_top_reg_read(wl, OCP_REG_CLK_TYPE);
+               val &= FREF_CLK_TYPE_BITS;
+               wl12xx_top_reg_write(wl, OCP_REG_CLK_TYPE, val);
+
+               /* Set clock pull mode (no pull) */
+               val = wl12xx_top_reg_read(wl, OCP_REG_CLK_PULL);
+               val |= NO_PULL;
+               wl12xx_top_reg_write(wl, OCP_REG_CLK_PULL, val);
+       } else {
+               u16 val;
+               /* Set clock polarity */
+               val = wl12xx_top_reg_read(wl, OCP_REG_CLK_POLARITY);
+               val &= FREF_CLK_POLARITY_BITS;
+               val |= CLK_REQ_OUTN_SEL;
+               wl12xx_top_reg_write(wl, OCP_REG_CLK_POLARITY, val);
+       }
+
+       wl1271_write32(wl, WL12XX_PLL_PARAMETERS, clk);
+
+       pause = wl1271_read32(wl, WL12XX_PLL_PARAMETERS);
+
+       wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause);
+
+       pause &= ~(WU_COUNTER_PAUSE_VAL);
+       pause |= WU_COUNTER_PAUSE_VAL;
+       wl1271_write32(wl, WL12XX_WU_COUNTER_PAUSE, pause);
+
+       return 0;
+}
+
+static int wl1271_boot_soft_reset(struct wl1271 *wl)
+{
+       unsigned long timeout;
+       u32 boot_data;
+
+       /* perform soft reset */
+       wl1271_write32(wl, WL12XX_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
+
+       /* SOFT_RESET is self clearing */
+       timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
+       while (1) {
+               boot_data = wl1271_read32(wl, WL12XX_SLV_SOFT_RESET);
+               wl1271_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
+               if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
+                       break;
+
+               if (time_after(jiffies, timeout)) {
+                       /* 1.2 check pWhalBus->uSelfClearTime if the
+                        * timeout was reached */
+                       wl1271_error("soft reset timeout");
+                       return -1;
+               }
+
+               udelay(SOFT_RESET_STALL_TIME);
+       }
+
+       /* disable Rx/Tx */
+       wl1271_write32(wl, WL12XX_ENABLE, 0x0);
+
+       /* disable auto calibration on start*/
+       wl1271_write32(wl, WL12XX_SPARE_A2, 0xffff);
+
+       return 0;
+}
+
+static int wl12xx_pre_boot(struct wl1271 *wl)
+{
+       int ret = 0;
+       u32 clk;
+       int selected_clock = -1;
+
+       if (wl->chip.id == CHIP_ID_1283_PG20) {
+               ret = wl128x_boot_clk(wl, &selected_clock);
+               if (ret < 0)
+                       goto out;
+       } else {
+               ret = wl127x_boot_clk(wl);
+               if (ret < 0)
+                       goto out;
+       }
+
+       /* Continue the ELP wake up sequence */
+       wl1271_write32(wl, WL12XX_WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
+       udelay(500);
+
+       wlcore_set_partition(wl, &wl->ptable[PART_DRPW]);
+
+       /* Read-modify-write DRPW_SCRATCH_START register (see next state)
+          to be used by DRPw FW. The RTRIM value will be added by the FW
+          before taking DRPw out of reset */
+
+       clk = wl1271_read32(wl, WL12XX_DRPW_SCRATCH_START);
+
+       wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk);
+
+       if (wl->chip.id == CHIP_ID_1283_PG20)
+               clk |= ((selected_clock & 0x3) << 1) << 4;
+       else
+               clk |= (wl->ref_clock << 1) << 4;
+
+       wl1271_write32(wl, WL12XX_DRPW_SCRATCH_START, clk);
+
+       wlcore_set_partition(wl, &wl->ptable[PART_WORK]);
+
+       /* Disable interrupts */
+       wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
+
+       ret = wl1271_boot_soft_reset(wl);
+       if (ret < 0)
+               goto out;
+
+out:
+       return ret;
+}
+
+static void wl12xx_pre_upload(struct wl1271 *wl)
+{
+       u32 tmp;
+
+       /* write firmware's last address (ie. it's length) to
+        * ACX_EEPROMLESS_IND_REG */
+       wl1271_debug(DEBUG_BOOT, "ACX_EEPROMLESS_IND_REG");
+
+       wl1271_write32(wl, WL12XX_EEPROMLESS_IND, WL12XX_EEPROMLESS_IND);
+
+       tmp = wlcore_read_reg(wl, REG_CHIP_ID_B);
+
+       wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp);
+
+       /* 6. read the EEPROM parameters */
+       tmp = wl1271_read32(wl, WL12XX_SCR_PAD2);
+
+       /* WL1271: The reference driver skips steps 7 to 10 (jumps directly
+        * to upload_fw) */
+
+       if (wl->chip.id == CHIP_ID_1283_PG20)
+               wl12xx_top_reg_write(wl, SDIO_IO_DS, HCI_IO_DS_6MA);
+}
+
+static void wl12xx_enable_interrupts(struct wl1271 *wl)
+{
+       u32 polarity;
+
+       polarity = wl12xx_top_reg_read(wl, OCP_REG_POLARITY);
+
+       /* We use HIGH polarity, so unset the LOW bit */
+       polarity &= ~POLARITY_LOW;
+       wl12xx_top_reg_write(wl, OCP_REG_POLARITY, polarity);
+
+       wlcore_write_reg(wl, REG_INTERRUPT_MASK, WL1271_ACX_ALL_EVENTS_VECTOR);
+
+       wlcore_enable_interrupts(wl);
+       wlcore_write_reg(wl, REG_INTERRUPT_MASK,
+                        WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
+
+       wl1271_write32(wl, WL12XX_HI_CFG, HI_CFG_DEF_VAL);
+}
+
+static int wl12xx_boot(struct wl1271 *wl)
+{
+       int ret;
+
+       ret = wl12xx_pre_boot(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wlcore_boot_upload_nvs(wl);
+       if (ret < 0)
+               goto out;
+
+       wl12xx_pre_upload(wl);
+
+       ret = wlcore_boot_upload_firmware(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wlcore_boot_run_firmware(wl);
+       if (ret < 0)
+               goto out;
+
+       wl12xx_enable_interrupts(wl);
+
+out:
+       return ret;
+}
+
+static void wl12xx_trigger_cmd(struct wl1271 *wl, int cmd_box_addr,
+                              void *buf, size_t len)
+{
+       wl1271_write(wl, cmd_box_addr, buf, len, false);
+       wlcore_write_reg(wl, REG_INTERRUPT_TRIG, WL12XX_INTR_TRIG_CMD);
+}
+
+static void wl12xx_ack_event(struct wl1271 *wl)
+{
+       wlcore_write_reg(wl, REG_INTERRUPT_TRIG, WL12XX_INTR_TRIG_EVENT_ACK);
+}
+
+static u32 wl12xx_calc_tx_blocks(struct wl1271 *wl, u32 len, u32 spare_blks)
+{
+       u32 blk_size = WL12XX_TX_HW_BLOCK_SIZE;
+       u32 align_len = wlcore_calc_packet_alignment(wl, len);
+
+       return (align_len + blk_size - 1) / blk_size + spare_blks;
+}
+
+static void
+wl12xx_set_tx_desc_blocks(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
+                         u32 blks, u32 spare_blks)
+{
+       if (wl->chip.id == CHIP_ID_1283_PG20) {
+               desc->wl128x_mem.total_mem_blocks = blks;
+       } else {
+               desc->wl127x_mem.extra_blocks = spare_blks;
+               desc->wl127x_mem.total_mem_blocks = blks;
+       }
+}
+
+static void
+wl12xx_set_tx_desc_data_len(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
+                           struct sk_buff *skb)
+{
+       u32 aligned_len = wlcore_calc_packet_alignment(wl, skb->len);
+
+       if (wl->chip.id == CHIP_ID_1283_PG20) {
+               desc->wl128x_mem.extra_bytes = aligned_len - skb->len;
+               desc->length = cpu_to_le16(aligned_len >> 2);
+
+               wl1271_debug(DEBUG_TX,
+                            "tx_fill_hdr: hlid: %d len: %d life: %d mem: %d extra: %d",
+                            desc->hlid,
+                            le16_to_cpu(desc->length),
+                            le16_to_cpu(desc->life_time),
+                            desc->wl128x_mem.total_mem_blocks,
+                            desc->wl128x_mem.extra_bytes);
+       } else {
+               /* calculate number of padding bytes */
+               int pad = aligned_len - skb->len;
+               desc->tx_attr |=
+                       cpu_to_le16(pad << TX_HW_ATTR_OFST_LAST_WORD_PAD);
+
+               /* Store the aligned length in terms of words */
+               desc->length = cpu_to_le16(aligned_len >> 2);
+
+               wl1271_debug(DEBUG_TX,
+                            "tx_fill_hdr: pad: %d hlid: %d len: %d life: %d mem: %d",
+                            pad, desc->hlid,
+                            le16_to_cpu(desc->length),
+                            le16_to_cpu(desc->life_time),
+                            desc->wl127x_mem.total_mem_blocks);
+       }
+}
+
+static enum wl_rx_buf_align
+wl12xx_get_rx_buf_align(struct wl1271 *wl, u32 rx_desc)
+{
+       if (rx_desc & RX_BUF_UNALIGNED_PAYLOAD)
+               return WLCORE_RX_BUF_UNALIGNED;
+
+       return WLCORE_RX_BUF_ALIGNED;
+}
+
+static u32 wl12xx_get_rx_packet_len(struct wl1271 *wl, void *rx_data,
+                                   u32 data_len)
+{
+       struct wl1271_rx_descriptor *desc = rx_data;
+
+       /* invalid packet */
+       if (data_len < sizeof(*desc) ||
+           data_len < sizeof(*desc) + desc->pad_len)
+               return 0;
+
+       return data_len - sizeof(*desc) - desc->pad_len;
+}
+
+static void wl12xx_tx_delayed_compl(struct wl1271 *wl)
+{
+       if (wl->fw_status->tx_results_counter == (wl->tx_results_count & 0xff))
+               return;
+
+       wl1271_tx_complete(wl);
+}
+
+static int wl12xx_hw_init(struct wl1271 *wl)
+{
+       int ret;
+
+       if (wl->chip.id == CHIP_ID_1283_PG20) {
+               u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
+
+               ret = wl128x_cmd_general_parms(wl);
+               if (ret < 0)
+                       goto out;
+               ret = wl128x_cmd_radio_parms(wl);
+               if (ret < 0)
+                       goto out;
+
+               if (wl->quirks & WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN)
+                       /* Enable SDIO padding */
+                       host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
+
+               /* Must be before wl1271_acx_init_mem_config() */
+               ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
+               if (ret < 0)
+                       goto out;
+       } else {
+               ret = wl1271_cmd_general_parms(wl);
+               if (ret < 0)
+                       goto out;
+               ret = wl1271_cmd_radio_parms(wl);
+               if (ret < 0)
+                       goto out;
+               ret = wl1271_cmd_ext_radio_parms(wl);
+               if (ret < 0)
+                       goto out;
+       }
+out:
+       return ret;
+}
+
+static u32 wl12xx_sta_get_ap_rate_mask(struct wl1271 *wl,
+                                      struct wl12xx_vif *wlvif)
+{
+       return wlvif->rate_set;
+}
+
+static int wl12xx_identify_fw(struct wl1271 *wl)
+{
+       unsigned int *fw_ver = wl->chip.fw_ver;
+
+       /* Only new station firmwares support routing fw logs to the host */
+       if ((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_STA) &&
+           (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_FWLOG_STA_MIN))
+               wl->quirks |= WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED;
+
+       /* This feature is not yet supported for AP mode */
+       if (fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_AP)
+               wl->quirks |= WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED;
+
+       return 0;
+}
+
+static void wl12xx_conf_init(struct wl1271 *wl)
+{
+       struct wl12xx_priv *priv = wl->priv;
+
+       /* apply driver default configuration */
+       memcpy(&wl->conf, &wl12xx_conf, sizeof(wl12xx_conf));
+
+       /* apply default private configuration */
+       memcpy(&priv->conf, &wl12xx_default_priv_conf, sizeof(priv->conf));
+}
+
+static bool wl12xx_mac_in_fuse(struct wl1271 *wl)
+{
+       bool supported = false;
+       u8 major, minor;
+
+       if (wl->chip.id == CHIP_ID_1283_PG20) {
+               major = WL128X_PG_GET_MAJOR(wl->hw_pg_ver);
+               minor = WL128X_PG_GET_MINOR(wl->hw_pg_ver);
+
+               /* in wl128x we have the MAC address if the PG is >= (2, 1) */
+               if (major > 2 || (major == 2 && minor >= 1))
+                       supported = true;
+       } else {
+               major = WL127X_PG_GET_MAJOR(wl->hw_pg_ver);
+               minor = WL127X_PG_GET_MINOR(wl->hw_pg_ver);
+
+               /* in wl127x we have the MAC address if the PG is >= (3, 1) */
+               if (major == 3 && minor >= 1)
+                       supported = true;
+       }
+
+       wl1271_debug(DEBUG_PROBE,
+                    "PG Ver major = %d minor = %d, MAC %s present",
+                    major, minor, supported ? "is" : "is not");
+
+       return supported;
+}
+
+static void wl12xx_get_fuse_mac(struct wl1271 *wl)
+{
+       u32 mac1, mac2;
+
+       wlcore_set_partition(wl, &wl->ptable[PART_DRPW]);
+
+       mac1 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_1);
+       mac2 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_2);
+
+       /* these are the two parts of the BD_ADDR */
+       wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
+               ((mac1 & 0xff000000) >> 24);
+       wl->fuse_nic_addr = mac1 & 0xffffff;
+
+       wlcore_set_partition(wl, &wl->ptable[PART_DOWN]);
+}
+
+static s8 wl12xx_get_pg_ver(struct wl1271 *wl)
+{
+       u32 die_info;
+
+       if (wl->chip.id == CHIP_ID_1283_PG20)
+               die_info = wl12xx_top_reg_read(wl, WL128X_REG_FUSE_DATA_2_1);
+       else
+               die_info = wl12xx_top_reg_read(wl, WL127X_REG_FUSE_DATA_2_1);
+
+       return (s8) (die_info & PG_VER_MASK) >> PG_VER_OFFSET;
+}
+
+static void wl12xx_get_mac(struct wl1271 *wl)
+{
+       if (wl12xx_mac_in_fuse(wl))
+               wl12xx_get_fuse_mac(wl);
+}
+
+static struct wlcore_ops wl12xx_ops = {
+       .identify_chip          = wl12xx_identify_chip,
+       .identify_fw            = wl12xx_identify_fw,
+       .boot                   = wl12xx_boot,
+       .trigger_cmd            = wl12xx_trigger_cmd,
+       .ack_event              = wl12xx_ack_event,
+       .calc_tx_blocks         = wl12xx_calc_tx_blocks,
+       .set_tx_desc_blocks     = wl12xx_set_tx_desc_blocks,
+       .set_tx_desc_data_len   = wl12xx_set_tx_desc_data_len,
+       .get_rx_buf_align       = wl12xx_get_rx_buf_align,
+       .get_rx_packet_len      = wl12xx_get_rx_packet_len,
+       .tx_immediate_compl     = NULL,
+       .tx_delayed_compl       = wl12xx_tx_delayed_compl,
+       .hw_init                = wl12xx_hw_init,
+       .init_vif               = NULL,
+       .sta_get_ap_rate_mask   = wl12xx_sta_get_ap_rate_mask,
+       .get_pg_ver             = wl12xx_get_pg_ver,
+       .get_mac                = wl12xx_get_mac,
+};
+
+static struct ieee80211_sta_ht_cap wl12xx_ht_cap = {
+       .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 |
+              (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT),
+       .ht_supported = true,
+       .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K,
+       .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8,
+       .mcs = {
+               .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
+               .rx_highest = cpu_to_le16(72),
+               .tx_params = IEEE80211_HT_MCS_TX_DEFINED,
+               },
+};
+
+static int __devinit wl12xx_probe(struct platform_device *pdev)
+{
+       struct wl1271 *wl;
+       struct ieee80211_hw *hw;
+       struct wl12xx_priv *priv;
+
+       hw = wlcore_alloc_hw(sizeof(*priv));
+       if (IS_ERR(hw)) {
+               wl1271_error("can't allocate hw");
+               return PTR_ERR(hw);
+       }
+
+       wl = hw->priv;
+       wl->ops = &wl12xx_ops;
+       wl->ptable = wl12xx_ptable;
+       wl->rtable = wl12xx_rtable;
+       wl->num_tx_desc = 16;
+       wl->normal_tx_spare = WL12XX_TX_HW_BLOCK_SPARE_DEFAULT;
+       wl->gem_tx_spare = WL12XX_TX_HW_BLOCK_GEM_SPARE;
+       wl->band_rate_to_idx = wl12xx_band_rate_to_idx;
+       wl->hw_tx_rate_tbl_size = WL12XX_CONF_HW_RXTX_RATE_MAX;
+       wl->hw_min_ht_rate = WL12XX_CONF_HW_RXTX_RATE_MCS0;
+       wl->fw_status_priv_len = 0;
+       memcpy(&wl->ht_cap, &wl12xx_ht_cap, sizeof(wl12xx_ht_cap));
+       wl12xx_conf_init(wl);
+
+       return wlcore_probe(wl, pdev);
+}
+
+static const struct platform_device_id wl12xx_id_table[] __devinitconst = {
+       { "wl12xx", 0 },
+       {  } /* Terminating Entry */
+};
+MODULE_DEVICE_TABLE(platform, wl12xx_id_table);
+
+static struct platform_driver wl12xx_driver = {
+       .probe          = wl12xx_probe,
+       .remove         = __devexit_p(wlcore_remove),
+       .id_table       = wl12xx_id_table,
+       .driver = {
+               .name   = "wl12xx_driver",
+               .owner  = THIS_MODULE,
+       }
+};
+
+static int __init wl12xx_init(void)
+{
+       return platform_driver_register(&wl12xx_driver);
+}
+module_init(wl12xx_init);
+
+static void __exit wl12xx_exit(void)
+{
+       platform_driver_unregister(&wl12xx_driver);
+}
+module_exit(wl12xx_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
+MODULE_FIRMWARE(WL127X_FW_NAME_SINGLE);
+MODULE_FIRMWARE(WL127X_FW_NAME_MULTI);
+MODULE_FIRMWARE(WL127X_PLT_FW_NAME);
+MODULE_FIRMWARE(WL128X_FW_NAME_SINGLE);
+MODULE_FIRMWARE(WL128X_FW_NAME_MULTI);
+MODULE_FIRMWARE(WL128X_PLT_FW_NAME);
diff --git a/drivers/net/wireless/ti/wl12xx/reg.h b/drivers/net/wireless/ti/wl12xx/reg.h
new file mode 100644 (file)
index 0000000..79ede02
--- /dev/null
@@ -0,0 +1,556 @@
+/*
+ * This file is part of wl12xx
+ *
+ * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __REG_H__
+#define __REG_H__
+
+#include <linux/bitops.h>
+
+#define REGISTERS_BASE 0x00300000
+#define DRPW_BASE      0x00310000
+
+#define REGISTERS_DOWN_SIZE 0x00008800
+#define REGISTERS_WORK_SIZE 0x0000b000
+
+#define FW_STATUS_ADDR                      (0x14FC0 + 0xA000)
+
+/*===============================================
+   Host Software Reset - 32bit RW
+ ------------------------------------------
+    [31:1] Reserved
+    0  SOFT_RESET Soft Reset  - When this bit is set,
+    it holds the Wlan hardware in a soft reset state.
+    This reset disables all MAC and baseband processor
+    clocks except the CardBus/PCI interface clock.
+    It also initializes all MAC state machines except
+    the host interface. It does not reload the
+    contents of the EEPROM. When this bit is cleared
+    (not self-clearing), the Wlan hardware
+    exits the software reset state.
+===============================================*/
+#define WL12XX_SLV_SOFT_RESET          (REGISTERS_BASE + 0x0000)
+
+#define WL1271_SLV_REG_DATA            (REGISTERS_BASE + 0x0008)
+#define WL1271_SLV_REG_ADATA           (REGISTERS_BASE + 0x000c)
+#define WL1271_SLV_MEM_DATA            (REGISTERS_BASE + 0x0018)
+
+#define WL12XX_REG_INTERRUPT_TRIG         (REGISTERS_BASE + 0x0474)
+#define WL12XX_REG_INTERRUPT_TRIG_H       (REGISTERS_BASE + 0x0478)
+
+/*=============================================
+  Host Interrupt Mask Register - 32bit (RW)
+  ------------------------------------------
+  Setting a bit in this register masks the
+  corresponding interrupt to the host.
+  0 - RX0              - Rx first dubble buffer Data Interrupt
+  1 - TXD              - Tx Data Interrupt
+  2 - TXXFR            - Tx Transfer Interrupt
+  3 - RX1              - Rx second dubble buffer Data Interrupt
+  4 - RXXFR            - Rx Transfer Interrupt
+  5 - EVENT_A  - Event Mailbox interrupt
+  6 - EVENT_B  - Event Mailbox interrupt
+  7 - WNONHST  - Wake On Host Interrupt
+  8 - TRACE_A  - Debug Trace interrupt
+  9 - TRACE_B  - Debug Trace interrupt
+ 10 - CDCMP            - Command Complete Interrupt
+ 11 -
+ 12 -
+ 13 -
+ 14 - ICOMP            - Initialization Complete Interrupt
+ 16 - SG SE            - Soft Gemini - Sense enable interrupt
+ 17 - SG SD            - Soft Gemini - Sense disable interrupt
+ 18 -                  -
+ 19 -                  -
+ 20 -                  -
+ 21-                   -
+ Default: 0x0001
+*==============================================*/
+#define WL12XX_REG_INTERRUPT_MASK         (REGISTERS_BASE + 0x04DC)
+
+/*=============================================
+  Host Interrupt Mask Set 16bit, (Write only)
+  ------------------------------------------
+ Setting a bit in this register sets
+ the corresponding bin in ACX_HINT_MASK register
+ without effecting the mask
+ state of other bits (0 = no effect).
+==============================================*/
+#define ACX_REG_HINT_MASK_SET          (REGISTERS_BASE + 0x04E0)
+
+/*=============================================
+  Host Interrupt Mask Clear 16bit,(Write only)
+  ------------------------------------------
+ Setting a bit in this register clears
+ the corresponding bin in ACX_HINT_MASK register
+ without effecting the mask
+ state of other bits (0 = no effect).
+=============================================*/
+#define ACX_REG_HINT_MASK_CLR          (REGISTERS_BASE + 0x04E4)
+
+/*=============================================
+  Host Interrupt Status Nondestructive Read
+  16bit,(Read only)
+  ------------------------------------------
+ The host can read this register to determine
+ which interrupts are active.
+ Reading this register doesn't
+ effect its content.
+=============================================*/
+#define WL12XX_REG_INTERRUPT_NO_CLEAR     (REGISTERS_BASE + 0x04E8)
+
+/*=============================================
+  Host Interrupt Status Clear on Read  Register
+  16bit,(Read only)
+  ------------------------------------------
+ The host can read this register to determine
+ which interrupts are active.
+ Reading this register clears it,
+ thus making all interrupts inactive.
+==============================================*/
+#define ACX_REG_INTERRUPT_CLEAR        (REGISTERS_BASE + 0x04F8)
+
+/*=============================================
+  Host Interrupt Acknowledge Register
+  16bit,(Write only)
+  ------------------------------------------
+ The host can set individual bits in this
+ register to clear (acknowledge) the corresp.
+ interrupt status bits in the HINT_STS_CLR and
+ HINT_STS_ND registers, thus making the
+ assotiated interrupt inactive. (0-no effect)
+==============================================*/
+#define WL12XX_REG_INTERRUPT_ACK          (REGISTERS_BASE + 0x04F0)
+
+#define WL12XX_REG_RX_DRIVER_COUNTER   (REGISTERS_BASE + 0x0538)
+
+/* Device Configuration registers*/
+#define SOR_CFG                        (REGISTERS_BASE + 0x0800)
+
+/* Embedded ARM CPU Control */
+
+/*===============================================
+ Halt eCPU   - 32bit RW
+ ------------------------------------------
+ 0 HALT_ECPU Halt Embedded CPU - This bit is the
+ compliment of bit 1 (MDATA2) in the SOR_CFG register.
+ During a hardware reset, this bit holds
+ the inverse of MDATA2.
+ When downloading firmware from the host,
+ set this bit (pull down MDATA2).
+ The host clears this bit after downloading the firmware into
+ zero-wait-state SSRAM.
+ When loading firmware from Flash, clear this bit (pull up MDATA2)
+ so that the eCPU can run the bootloader code in Flash
+ HALT_ECPU eCPU State
+ --------------------
+ 1 halt eCPU
+ 0 enable eCPU
+ ===============================================*/
+#define WL12XX_REG_ECPU_CONTROL           (REGISTERS_BASE + 0x0804)
+
+#define WL12XX_HI_CFG                  (REGISTERS_BASE + 0x0808)
+
+/*===============================================
+ EEPROM Burst Read Start  - 32bit RW
+ ------------------------------------------
+ [31:1] Reserved
+ 0  ACX_EE_START -  EEPROM Burst Read Start 0
+ Setting this bit starts a burst read from
+ the external EEPROM.
+ If this bit is set (after reset) before an EEPROM read/write,
+ the burst read starts at EEPROM address 0.
+ Otherwise, it starts at the address
+ following the address of the previous access.
+ TheWlan hardware hardware clears this bit automatically.
+
+ Default: 0x00000000
+*================================================*/
+#define ACX_REG_EE_START               (REGISTERS_BASE + 0x080C)
+
+#define WL12XX_OCP_POR_CTR             (REGISTERS_BASE + 0x09B4)
+#define WL12XX_OCP_DATA_WRITE          (REGISTERS_BASE + 0x09B8)
+#define WL12XX_OCP_DATA_READ           (REGISTERS_BASE + 0x09BC)
+#define WL12XX_OCP_CMD                 (REGISTERS_BASE + 0x09C0)
+
+#define WL12XX_HOST_WR_ACCESS          (REGISTERS_BASE + 0x09F8)
+
+#define WL12XX_CHIP_ID_B               (REGISTERS_BASE + 0x5674)
+
+#define WL12XX_ENABLE                  (REGISTERS_BASE + 0x5450)
+
+/* Power Management registers */
+#define WL12XX_ELP_CFG_MODE            (REGISTERS_BASE + 0x5804)
+#define WL12XX_ELP_CMD                 (REGISTERS_BASE + 0x5808)
+#define WL12XX_PLL_CAL_TIME            (REGISTERS_BASE + 0x5810)
+#define WL12XX_CLK_REQ_TIME            (REGISTERS_BASE + 0x5814)
+#define WL12XX_CLK_BUF_TIME            (REGISTERS_BASE + 0x5818)
+
+#define WL12XX_CFG_PLL_SYNC_CNT                (REGISTERS_BASE + 0x5820)
+
+/* Scratch Pad registers*/
+#define WL12XX_SCR_PAD0                        (REGISTERS_BASE + 0x5608)
+#define WL12XX_SCR_PAD1                        (REGISTERS_BASE + 0x560C)
+#define WL12XX_SCR_PAD2                        (REGISTERS_BASE + 0x5610)
+#define WL12XX_SCR_PAD3                        (REGISTERS_BASE + 0x5614)
+#define WL12XX_SCR_PAD4                        (REGISTERS_BASE + 0x5618)
+#define WL12XX_SCR_PAD4_SET            (REGISTERS_BASE + 0x561C)
+#define WL12XX_SCR_PAD4_CLR            (REGISTERS_BASE + 0x5620)
+#define WL12XX_SCR_PAD5                        (REGISTERS_BASE + 0x5624)
+#define WL12XX_SCR_PAD5_SET            (REGISTERS_BASE + 0x5628)
+#define WL12XX_SCR_PAD5_CLR            (REGISTERS_BASE + 0x562C)
+#define WL12XX_SCR_PAD6                        (REGISTERS_BASE + 0x5630)
+#define WL12XX_SCR_PAD7                        (REGISTERS_BASE + 0x5634)
+#define WL12XX_SCR_PAD8                        (REGISTERS_BASE + 0x5638)
+#define WL12XX_SCR_PAD9                        (REGISTERS_BASE + 0x563C)
+
+/* Spare registers*/
+#define WL12XX_SPARE_A1                        (REGISTERS_BASE + 0x0994)
+#define WL12XX_SPARE_A2                        (REGISTERS_BASE + 0x0998)
+#define WL12XX_SPARE_A3                        (REGISTERS_BASE + 0x099C)
+#define WL12XX_SPARE_A4                        (REGISTERS_BASE + 0x09A0)
+#define WL12XX_SPARE_A5                        (REGISTERS_BASE + 0x09A4)
+#define WL12XX_SPARE_A6                        (REGISTERS_BASE + 0x09A8)
+#define WL12XX_SPARE_A7                        (REGISTERS_BASE + 0x09AC)
+#define WL12XX_SPARE_A8                        (REGISTERS_BASE + 0x09B0)
+#define WL12XX_SPARE_B1                        (REGISTERS_BASE + 0x5420)
+#define WL12XX_SPARE_B2                        (REGISTERS_BASE + 0x5424)
+#define WL12XX_SPARE_B3                        (REGISTERS_BASE + 0x5428)
+#define WL12XX_SPARE_B4                        (REGISTERS_BASE + 0x542C)
+#define WL12XX_SPARE_B5                        (REGISTERS_BASE + 0x5430)
+#define WL12XX_SPARE_B6                        (REGISTERS_BASE + 0x5434)
+#define WL12XX_SPARE_B7                        (REGISTERS_BASE + 0x5438)
+#define WL12XX_SPARE_B8                        (REGISTERS_BASE + 0x543C)
+
+#define WL12XX_PLL_PARAMETERS          (REGISTERS_BASE + 0x6040)
+#define WL12XX_WU_COUNTER_PAUSE                (REGISTERS_BASE + 0x6008)
+#define WL12XX_WELP_ARM_COMMAND                (REGISTERS_BASE + 0x6100)
+#define WL12XX_DRPW_SCRATCH_START      (DRPW_BASE + 0x002C)
+
+#define WL12XX_CMD_MBOX_ADDRESS                0x407B4
+
+#define ACX_REG_EEPROM_START_BIT BIT(1)
+
+/* Command/Information Mailbox Pointers */
+
+/*===============================================
+  Command Mailbox Pointer - 32bit RW
+ ------------------------------------------
+ This register holds the start address of
+ the command mailbox located in the Wlan hardware memory.
+ The host must read this pointer after a reset to
+ find the location of the command mailbox.
+ The Wlan hardware initializes the command mailbox
+ pointer with the default address of the command mailbox.
+ The command mailbox pointer is not valid until after
+ the host receives the Init Complete interrupt from
+ the Wlan hardware.
+ ===============================================*/
+#define WL12XX_REG_COMMAND_MAILBOX_PTR         (WL12XX_SCR_PAD0)
+
+/*===============================================
+  Information Mailbox Pointer - 32bit RW
+ ------------------------------------------
+ This register holds the start address of
+ the information mailbox located in the Wlan hardware memory.
+ The host must read this pointer after a reset to find
+ the location of the information mailbox.
+ The Wlan hardware initializes the information mailbox pointer
+ with the default address of the information mailbox.
+ The information mailbox pointer is not valid
+ until after the host receives the Init Complete interrupt from
+ the Wlan hardware.
+ ===============================================*/
+#define WL12XX_REG_EVENT_MAILBOX_PTR           (WL12XX_SCR_PAD1)
+
+/*===============================================
+ EEPROM Read/Write Request 32bit RW
+ ------------------------------------------
+ 1 EE_READ - EEPROM Read Request 1 - Setting this bit
+ loads a single byte of data into the EE_DATA
+ register from the EEPROM location specified in
+ the EE_ADDR register.
+ The Wlan hardware hardware clears this bit automatically.
+ EE_DATA is valid when this bit is cleared.
+
+ 0 EE_WRITE  - EEPROM Write Request  - Setting this bit
+ writes a single byte of data from the EE_DATA register into the
+ EEPROM location specified in the EE_ADDR register.
+ The Wlan hardware hardware clears this bit automatically.
+*===============================================*/
+#define ACX_EE_CTL_REG                      EE_CTL
+#define EE_WRITE                            0x00000001ul
+#define EE_READ                             0x00000002ul
+
+/*===============================================
+  EEPROM Address  - 32bit RW
+  ------------------------------------------
+  This register specifies the address
+  within the EEPROM from/to which to read/write data.
+  ===============================================*/
+#define ACX_EE_ADDR_REG                     EE_ADDR
+
+/*===============================================
+  EEPROM Data  - 32bit RW
+  ------------------------------------------
+  This register either holds the read 8 bits of
+  data from the EEPROM or the write data
+  to be written to the EEPROM.
+  ===============================================*/
+#define ACX_EE_DATA_REG                     EE_DATA
+
+/*===============================================
+  EEPROM Base Address  - 32bit RW
+  ------------------------------------------
+  This register holds the upper nine bits
+  [23:15] of the 24-bit Wlan hardware memory
+  address for burst reads from EEPROM accesses.
+  The EEPROM provides the lower 15 bits of this address.
+  The MSB of the address from the EEPROM is ignored.
+  ===============================================*/
+#define ACX_EE_CFG                          EE_CFG
+
+/*===============================================
+  GPIO Output Values  -32bit, RW
+  ------------------------------------------
+  [31:16]  Reserved
+  [15: 0]  Specify the output values (at the output driver inputs) for
+  GPIO[15:0], respectively.
+  ===============================================*/
+#define ACX_GPIO_OUT_REG            GPIO_OUT
+#define ACX_MAX_GPIO_LINES          15
+
+/*===============================================
+  Contention window  -32bit, RW
+  ------------------------------------------
+  [31:26]  Reserved
+  [25:16]  Max (0x3ff)
+  [15:07]  Reserved
+  [06:00]  Current contention window value - default is 0x1F
+  ===============================================*/
+#define ACX_CONT_WIND_CFG_REG    CONT_WIND_CFG
+#define ACX_CONT_WIND_MIN_MASK   0x0000007f
+#define ACX_CONT_WIND_MAX        0x03ff0000
+
+#define REF_FREQ_19_2                       0
+#define REF_FREQ_26_0                       1
+#define REF_FREQ_38_4                       2
+#define REF_FREQ_40_0                       3
+#define REF_FREQ_33_6                       4
+#define REF_FREQ_NUM                        5
+
+#define LUT_PARAM_INTEGER_DIVIDER           0
+#define LUT_PARAM_FRACTIONAL_DIVIDER        1
+#define LUT_PARAM_ATTN_BB                   2
+#define LUT_PARAM_ALPHA_BB                  3
+#define LUT_PARAM_STOP_TIME_BB              4
+#define LUT_PARAM_BB_PLL_LOOP_FILTER        5
+#define LUT_PARAM_NUM                       6
+
+#define WL12XX_EEPROMLESS_IND          (WL12XX_SCR_PAD4)
+#define USE_EEPROM                          0
+#define NVS_DATA_BUNDARY_ALIGNMENT          4
+
+/* Firmware image header size */
+#define FW_HDR_SIZE 8
+
+/******************************************************************************
+
+    CHANNELS, BAND & REG DOMAINS definitions
+
+******************************************************************************/
+
+#define SHORT_PREAMBLE_BIT   BIT(0) /* CCK or Barker depending on the rate */
+#define OFDM_RATE_BIT        BIT(6)
+#define PBCC_RATE_BIT        BIT(7)
+
+enum {
+       CCK_LONG = 0,
+       CCK_SHORT = SHORT_PREAMBLE_BIT,
+       PBCC_LONG = PBCC_RATE_BIT,
+       PBCC_SHORT = PBCC_RATE_BIT | SHORT_PREAMBLE_BIT,
+       OFDM = OFDM_RATE_BIT
+};
+
+/******************************************************************************
+
+Transmit-Descriptor RATE-SET field definitions...
+
+Define a new "Rate-Set" for TX path that incorporates the
+Rate & Modulation info into a single 16-bit field.
+
+TxdRateSet_t:
+b15   - Indicates Preamble type (1=SHORT, 0=LONG).
+       Notes:
+       Must be LONG (0) for 1Mbps rate.
+       Does not apply (set to 0) for RevG-OFDM rates.
+b14   - Indicates PBCC encoding (1=PBCC, 0=not).
+       Notes:
+       Does not apply (set to 0) for rates 1 and 2 Mbps.
+       Does not apply (set to 0) for RevG-OFDM rates.
+b13    - Unused (set to 0).
+b12-b0 - Supported Rate indicator bits as defined below.
+
+******************************************************************************/
+
+#define OCP_CMD_LOOP           32
+#define OCP_CMD_WRITE          0x1
+#define OCP_CMD_READ           0x2
+#define OCP_READY_MASK         BIT(18)
+#define OCP_STATUS_MASK                (BIT(16) | BIT(17))
+#define OCP_STATUS_NO_RESP     0x00000
+#define OCP_STATUS_OK          0x10000
+#define OCP_STATUS_REQ_FAILED  0x20000
+#define OCP_STATUS_RESP_ERROR  0x30000
+
+#define OCP_REG_POLARITY     0x0064
+#define OCP_REG_CLK_TYPE     0x0448
+#define OCP_REG_CLK_POLARITY 0x0cb2
+#define OCP_REG_CLK_PULL     0x0cb4
+
+#define POLARITY_LOW         BIT(1)
+#define NO_PULL              (BIT(14) | BIT(15))
+
+#define FREF_CLK_TYPE_BITS     0xfffffe7f
+#define CLK_REQ_PRCM           0x100
+#define FREF_CLK_POLARITY_BITS 0xfffff8ff
+#define CLK_REQ_OUTN_SEL       0x700
+
+#define WU_COUNTER_PAUSE_VAL 0x3FF
+
+/* PLL configuration algorithm for wl128x */
+#define SYS_CLK_CFG_REG              0x2200
+/* Bit[0]   -  0-TCXO,  1-FREF */
+#define MCS_PLL_CLK_SEL_FREF         BIT(0)
+/* Bit[3:2] - 01-TCXO, 10-FREF */
+#define WL_CLK_REQ_TYPE_FREF         BIT(3)
+#define WL_CLK_REQ_TYPE_PG2          (BIT(3) | BIT(2))
+/* Bit[4]   -  0-TCXO,  1-FREF */
+#define PRCM_CM_EN_MUX_WLAN_FREF     BIT(4)
+
+#define TCXO_ILOAD_INT_REG           0x2264
+#define TCXO_CLK_DETECT_REG          0x2266
+
+#define TCXO_DET_FAILED              BIT(4)
+
+#define FREF_ILOAD_INT_REG           0x2084
+#define FREF_CLK_DETECT_REG          0x2086
+#define FREF_CLK_DETECT_FAIL         BIT(4)
+
+/* Use this reg for masking during driver access */
+#define WL_SPARE_REG                 0x2320
+#define WL_SPARE_VAL                 BIT(2)
+/* Bit[6:5:3] -  mask wl write SYS_CLK_CFG[8:5:2:4] */
+#define WL_SPARE_MASK_8526           (BIT(6) | BIT(5) | BIT(3))
+
+#define PLL_LOCK_COUNTERS_REG        0xD8C
+#define PLL_LOCK_COUNTERS_COEX       0x0F
+#define PLL_LOCK_COUNTERS_MCS        0xF0
+#define MCS_PLL_OVERRIDE_REG         0xD90
+#define MCS_PLL_CONFIG_REG           0xD92
+#define MCS_SEL_IN_FREQ_MASK         0x0070
+#define MCS_SEL_IN_FREQ_SHIFT        4
+#define MCS_PLL_CONFIG_REG_VAL       0x73
+#define MCS_PLL_ENABLE_HP            (BIT(0) | BIT(1))
+
+#define MCS_PLL_M_REG                0xD94
+#define MCS_PLL_N_REG                0xD96
+#define MCS_PLL_M_REG_VAL            0xC8
+#define MCS_PLL_N_REG_VAL            0x07
+
+#define SDIO_IO_DS                   0xd14
+
+/* SDIO/wSPI DS configuration values */
+enum {
+       HCI_IO_DS_8MA = 0,
+       HCI_IO_DS_4MA = 1, /* default */
+       HCI_IO_DS_6MA = 2,
+       HCI_IO_DS_2MA = 3,
+};
+
+/* end PLL configuration algorithm for wl128x */
+
+/*
+ * Host Command Interrupt. Setting this bit masks
+ * the interrupt that the host issues to inform
+ * the FW that it has sent a command
+ * to the Wlan hardware Command Mailbox.
+ */
+#define WL12XX_INTR_TRIG_CMD           BIT(0)
+
+/*
+ * Host Event Acknowlegde Interrupt. The host
+ * sets this bit to acknowledge that it received
+ * the unsolicited information from the event
+ * mailbox.
+ */
+#define WL12XX_INTR_TRIG_EVENT_ACK     BIT(1)
+
+/*===============================================
+  HI_CFG Interface Configuration Register Values
+  ------------------------------------------
+  ===============================================*/
+#define HI_CFG_UART_ENABLE          0x00000004
+#define HI_CFG_RST232_ENABLE        0x00000008
+#define HI_CFG_CLOCK_REQ_SELECT     0x00000010
+#define HI_CFG_HOST_INT_ENABLE      0x00000020
+#define HI_CFG_VLYNQ_OUTPUT_ENABLE  0x00000040
+#define HI_CFG_HOST_INT_ACTIVE_LOW  0x00000080
+#define HI_CFG_UART_TX_OUT_GPIO_15  0x00000100
+#define HI_CFG_UART_TX_OUT_GPIO_14  0x00000200
+#define HI_CFG_UART_TX_OUT_GPIO_7   0x00000400
+
+#define HI_CFG_DEF_VAL              \
+       (HI_CFG_UART_ENABLE |        \
+       HI_CFG_RST232_ENABLE |      \
+       HI_CFG_CLOCK_REQ_SELECT |   \
+       HI_CFG_HOST_INT_ENABLE)
+
+#define WL127X_REG_FUSE_DATA_2_1       0x050a
+#define WL128X_REG_FUSE_DATA_2_1       0x2152
+#define PG_VER_MASK                    0x3c
+#define PG_VER_OFFSET                  2
+
+#define WL127X_PG_MAJOR_VER_MASK       0x3
+#define WL127X_PG_MAJOR_VER_OFFSET     0x0
+#define WL127X_PG_MINOR_VER_MASK       0xc
+#define WL127X_PG_MINOR_VER_OFFSET     0x2
+
+#define WL128X_PG_MAJOR_VER_MASK       0xc
+#define WL128X_PG_MAJOR_VER_OFFSET     0x2
+#define WL128X_PG_MINOR_VER_MASK       0x3
+#define WL128X_PG_MINOR_VER_OFFSET     0x0
+
+#define WL127X_PG_GET_MAJOR(pg_ver) ((pg_ver & WL127X_PG_MAJOR_VER_MASK) >> \
+                                    WL127X_PG_MAJOR_VER_OFFSET)
+#define WL127X_PG_GET_MINOR(pg_ver) ((pg_ver & WL127X_PG_MINOR_VER_MASK) >> \
+                                    WL127X_PG_MINOR_VER_OFFSET)
+#define WL128X_PG_GET_MAJOR(pg_ver) ((pg_ver & WL128X_PG_MAJOR_VER_MASK) >> \
+                                    WL128X_PG_MAJOR_VER_OFFSET)
+#define WL128X_PG_GET_MINOR(pg_ver) ((pg_ver & WL128X_PG_MINOR_VER_MASK) >> \
+                                    WL128X_PG_MINOR_VER_OFFSET)
+
+#define WL12XX_REG_FUSE_BD_ADDR_1      0x00310eb4
+#define WL12XX_REG_FUSE_BD_ADDR_2      0x00310eb8
+
+#endif
diff --git a/drivers/net/wireless/ti/wl12xx/wl12xx.h b/drivers/net/wireless/ti/wl12xx/wl12xx.h
new file mode 100644 (file)
index 0000000..74cd332
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * This file is part of wl12xx
+ *
+ * Copyright (C) 2011 Texas Instruments Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL12XX_PRIV_H__
+#define __WL12XX_PRIV_H__
+
+#include "conf.h"
+
+struct wl12xx_priv {
+       struct wl12xx_priv_conf conf;
+};
+
+#endif /* __WL12XX_PRIV_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/Kconfig b/drivers/net/wireless/ti/wlcore/Kconfig
new file mode 100644 (file)
index 0000000..9d04c38
--- /dev/null
@@ -0,0 +1,41 @@
+config WLCORE
+       tristate "TI wlcore support"
+       depends on WL_TI && GENERIC_HARDIRQS
+       depends on INET
+       select FW_LOADER
+       ---help---
+         This module contains the main code for TI WLAN chips.  It abstracts
+         hardware-specific differences among different chipset families.
+         Each chipset family needs to implement its own lower-level module
+         that will depend on this module for the common code.
+
+         If you choose to build a module, it will be called wlcore. Say N if
+         unsure.
+
+config WLCORE_SPI
+       tristate "TI wlcore SPI support"
+       depends on WLCORE && SPI_MASTER
+       select CRC7
+       ---help---
+         This module adds support for the SPI interface of adapters using
+         TI WLAN chipsets.  Select this if your platform is using
+         the SPI bus.
+
+         If you choose to build a module, it'll be called wlcore_spi.
+         Say N if unsure.
+
+config WLCORE_SDIO
+       tristate "TI wlcore SDIO support"
+       depends on WLCORE && MMC
+       ---help---
+         This module adds support for the SDIO interface of adapters using
+         TI WLAN chipsets.  Select this if your platform is using
+         the SDIO bus.
+
+         If you choose to build a module, it'll be called wlcore_sdio.
+         Say N if unsure.
+
+config WL12XX_PLATFORM_DATA
+       bool
+       depends on WLCORE_SDIO != n || WL1251_SDIO != n
+       default y
diff --git a/drivers/net/wireless/ti/wlcore/Makefile b/drivers/net/wireless/ti/wlcore/Makefile
new file mode 100644 (file)
index 0000000..d9fba9e
--- /dev/null
@@ -0,0 +1,15 @@
+wlcore-objs            = main.o cmd.o io.o event.o tx.o rx.o ps.o acx.o \
+                         boot.o init.o debugfs.o scan.o
+
+wlcore_spi-objs        = spi.o
+wlcore_sdio-objs       = sdio.o
+
+wlcore-$(CONFIG_NL80211_TESTMODE)      += testmode.o
+obj-$(CONFIG_WLCORE)                   += wlcore.o
+obj-$(CONFIG_WLCORE_SPI)               += wlcore_spi.o
+obj-$(CONFIG_WLCORE_SDIO)              += wlcore_sdio.o
+
+# small builtin driver bit
+obj-$(CONFIG_WL12XX_PLATFORM_DATA)     += wl12xx_platform_data.o
+
+ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/ti/wlcore/acx.c b/drivers/net/wireless/ti/wlcore/acx.c
new file mode 100644 (file)
index 0000000..5912541
--- /dev/null
@@ -0,0 +1,1716 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "acx.h"
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+#include <linux/slab.h>
+
+#include "wlcore.h"
+#include "debug.h"
+#include "wl12xx_80211.h"
+#include "ps.h"
+#include "hw_ops.h"
+
+int wl1271_acx_wake_up_conditions(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                                 u8 wake_up_event, u8 listen_interval)
+{
+       struct acx_wake_up_condition *wake_up;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx wake up conditions (wake_up_event %d listen_interval %d)",
+                    wake_up_event, listen_interval);
+
+       wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
+       if (!wake_up) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wake_up->role_id = wlvif->role_id;
+       wake_up->wake_up_event = wake_up_event;
+       wake_up->listen_interval = listen_interval;
+
+       ret = wl1271_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
+                                  wake_up, sizeof(*wake_up));
+       if (ret < 0) {
+               wl1271_warning("could not set wake up conditions: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(wake_up);
+       return ret;
+}
+
+int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth)
+{
+       struct acx_sleep_auth *auth;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx sleep auth");
+
+       auth = kzalloc(sizeof(*auth), GFP_KERNEL);
+       if (!auth) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       auth->sleep_auth = sleep_auth;
+
+       ret = wl1271_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
+
+out:
+       kfree(auth);
+       return ret;
+}
+
+int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                       int power)
+{
+       struct acx_current_tx_power *acx;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr %d", power);
+
+       if (power < 0 || power > 25)
+               return -EINVAL;
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->role_id = wlvif->role_id;
+       acx->current_tx_power = power * 10;
+
+       ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("configure of tx power failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_feature_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       struct acx_feature_config *feature;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx feature cfg");
+
+       feature = kzalloc(sizeof(*feature), GFP_KERNEL);
+       if (!feature) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
+       feature->role_id = wlvif->role_id;
+       feature->data_flow_options = 0;
+       feature->options = 0;
+
+       ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
+                                  feature, sizeof(*feature));
+       if (ret < 0) {
+               wl1271_error("Couldnt set HW encryption");
+               goto out;
+       }
+
+out:
+       kfree(feature);
+       return ret;
+}
+
+int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
+                      size_t len)
+{
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx mem map");
+
+       ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
+{
+       struct acx_rx_msdu_lifetime *acx;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
+       ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
+                                  acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("failed to set rx msdu life time: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_slot(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                   enum acx_slot_type slot_time)
+{
+       struct acx_slot *slot;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx slot");
+
+       slot = kzalloc(sizeof(*slot), GFP_KERNEL);
+       if (!slot) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       slot->role_id = wlvif->role_id;
+       slot->wone_index = STATION_WONE_INDEX;
+       slot->slot_time = slot_time;
+
+       ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
+       if (ret < 0) {
+               wl1271_warning("failed to set slot time: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(slot);
+       return ret;
+}
+
+int wl1271_acx_group_address_tbl(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                                bool enable, void *mc_list, u32 mc_list_len)
+{
+       struct acx_dot11_grp_addr_tbl *acx;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx group address tbl");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* MAC filtering */
+       acx->role_id = wlvif->role_id;
+       acx->enabled = enable;
+       acx->num_groups = mc_list_len;
+       memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
+
+       ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
+                                  acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("failed to set group addr table: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_service_period_timeout(struct wl1271 *wl,
+                                     struct wl12xx_vif *wlvif)
+{
+       struct acx_rx_timeout *rx_timeout;
+       int ret;
+
+       rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
+       if (!rx_timeout) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wl1271_debug(DEBUG_ACX, "acx service period timeout");
+
+       rx_timeout->role_id = wlvif->role_id;
+       rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
+       rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
+
+       ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
+                                  rx_timeout, sizeof(*rx_timeout));
+       if (ret < 0) {
+               wl1271_warning("failed to set service period timeout: %d",
+                              ret);
+               goto out;
+       }
+
+out:
+       kfree(rx_timeout);
+       return ret;
+}
+
+int wl1271_acx_rts_threshold(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                            u32 rts_threshold)
+{
+       struct acx_rts_threshold *rts;
+       int ret;
+
+       /*
+        * If the RTS threshold is not configured or out of range, use the
+        * default value.
+        */
+       if (rts_threshold > IEEE80211_MAX_RTS_THRESHOLD)
+               rts_threshold = wl->conf.rx.rts_threshold;
+
+       wl1271_debug(DEBUG_ACX, "acx rts threshold: %d", rts_threshold);
+
+       rts = kzalloc(sizeof(*rts), GFP_KERNEL);
+       if (!rts) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       rts->role_id = wlvif->role_id;
+       rts->threshold = cpu_to_le16((u16)rts_threshold);
+
+       ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
+       if (ret < 0) {
+               wl1271_warning("failed to set rts threshold: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(rts);
+       return ret;
+}
+
+int wl1271_acx_dco_itrim_params(struct wl1271 *wl)
+{
+       struct acx_dco_itrim_params *dco;
+       struct conf_itrim_settings *c = &wl->conf.itrim;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx dco itrim parameters");
+
+       dco = kzalloc(sizeof(*dco), GFP_KERNEL);
+       if (!dco) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       dco->enable = c->enable;
+       dco->timeout = cpu_to_le32(c->timeout);
+
+       ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS,
+                                  dco, sizeof(*dco));
+       if (ret < 0) {
+               wl1271_warning("failed to set dco itrim parameters: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(dco);
+       return ret;
+}
+
+int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                                bool enable_filter)
+{
+       struct acx_beacon_filter_option *beacon_filter = NULL;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
+
+       if (enable_filter &&
+           wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
+               goto out;
+
+       beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
+       if (!beacon_filter) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       beacon_filter->role_id = wlvif->role_id;
+       beacon_filter->enable = enable_filter;
+
+       /*
+        * When set to zero, and the filter is enabled, beacons
+        * without the unicast TIM bit set are dropped.
+        */
+       beacon_filter->max_num_beacons = 0;
+
+       ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
+                                  beacon_filter, sizeof(*beacon_filter));
+       if (ret < 0) {
+               wl1271_warning("failed to set beacon filter opt: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(beacon_filter);
+       return ret;
+}
+
+int wl1271_acx_beacon_filter_table(struct wl1271 *wl,
+                                  struct wl12xx_vif *wlvif)
+{
+       struct acx_beacon_filter_ie_table *ie_table;
+       int i, idx = 0;
+       int ret;
+       bool vendor_spec = false;
+
+       wl1271_debug(DEBUG_ACX, "acx beacon filter table");
+
+       ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
+       if (!ie_table) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* configure default beacon pass-through rules */
+       ie_table->role_id = wlvif->role_id;
+       ie_table->num_ie = 0;
+       for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
+               struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
+               ie_table->table[idx++] = r->ie;
+               ie_table->table[idx++] = r->rule;
+
+               if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
+                       /* only one vendor specific ie allowed */
+                       if (vendor_spec)
+                               continue;
+
+                       /* for vendor specific rules configure the
+                          additional fields */
+                       memcpy(&(ie_table->table[idx]), r->oui,
+                              CONF_BCN_IE_OUI_LEN);
+                       idx += CONF_BCN_IE_OUI_LEN;
+                       ie_table->table[idx++] = r->type;
+                       memcpy(&(ie_table->table[idx]), r->version,
+                              CONF_BCN_IE_VER_LEN);
+                       idx += CONF_BCN_IE_VER_LEN;
+                       vendor_spec = true;
+               }
+
+               ie_table->num_ie++;
+       }
+
+       ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
+                                  ie_table, sizeof(*ie_table));
+       if (ret < 0) {
+               wl1271_warning("failed to set beacon filter table: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(ie_table);
+       return ret;
+}
+
+#define ACX_CONN_MONIT_DISABLE_VALUE  0xffffffff
+
+int wl1271_acx_conn_monit_params(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                                bool enable)
+{
+       struct acx_conn_monit_params *acx;
+       u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE;
+       u32 timeout = ACX_CONN_MONIT_DISABLE_VALUE;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx connection monitor parameters: %s",
+                    enable ? "enabled" : "disabled");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       if (enable) {
+               threshold = wl->conf.conn.synch_fail_thold;
+               timeout = wl->conf.conn.bss_lose_timeout;
+       }
+
+       acx->role_id = wlvif->role_id;
+       acx->synch_fail_thold = cpu_to_le32(threshold);
+       acx->bss_lose_timeout = cpu_to_le32(timeout);
+
+       ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
+                                  acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("failed to set connection monitor "
+                              "parameters: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+
+int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable)
+{
+       struct acx_bt_wlan_coex *pta;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx sg enable");
+
+       pta = kzalloc(sizeof(*pta), GFP_KERNEL);
+       if (!pta) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       if (enable)
+               pta->enable = wl->conf.sg.state;
+       else
+               pta->enable = CONF_SG_DISABLE;
+
+       ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
+       if (ret < 0) {
+               wl1271_warning("failed to set softgemini enable: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(pta);
+       return ret;
+}
+
+int wl12xx_acx_sg_cfg(struct wl1271 *wl)
+{
+       struct acx_bt_wlan_coex_param *param;
+       struct conf_sg_settings *c = &wl->conf.sg;
+       int i, ret;
+
+       wl1271_debug(DEBUG_ACX, "acx sg cfg");
+
+       param = kzalloc(sizeof(*param), GFP_KERNEL);
+       if (!param) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* BT-WLAN coext parameters */
+       for (i = 0; i < CONF_SG_PARAMS_MAX; i++)
+               param->params[i] = cpu_to_le32(c->params[i]);
+       param->param_idx = CONF_SG_PARAMS_ALL;
+
+       ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
+       if (ret < 0) {
+               wl1271_warning("failed to set sg config: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(param);
+       return ret;
+}
+
+int wl1271_acx_cca_threshold(struct wl1271 *wl)
+{
+       struct acx_energy_detection *detection;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx cca threshold");
+
+       detection = kzalloc(sizeof(*detection), GFP_KERNEL);
+       if (!detection) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
+       detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
+
+       ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
+                                  detection, sizeof(*detection));
+       if (ret < 0)
+               wl1271_warning("failed to set cca threshold: %d", ret);
+
+out:
+       kfree(detection);
+       return ret;
+}
+
+int wl1271_acx_bcn_dtim_options(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       struct acx_beacon_broadcast *bb;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
+
+       bb = kzalloc(sizeof(*bb), GFP_KERNEL);
+       if (!bb) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       bb->role_id = wlvif->role_id;
+       bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
+       bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
+       bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
+       bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
+
+       ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
+       if (ret < 0) {
+               wl1271_warning("failed to set rx config: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(bb);
+       return ret;
+}
+
+int wl1271_acx_aid(struct wl1271 *wl, struct wl12xx_vif *wlvif, u16 aid)
+{
+       struct acx_aid *acx_aid;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx aid");
+
+       acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
+       if (!acx_aid) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx_aid->role_id = wlvif->role_id;
+       acx_aid->aid = cpu_to_le16(aid);
+
+       ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
+       if (ret < 0) {
+               wl1271_warning("failed to set aid: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx_aid);
+       return ret;
+}
+
+int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
+{
+       struct acx_event_mask *mask;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx event mbox mask");
+
+       mask = kzalloc(sizeof(*mask), GFP_KERNEL);
+       if (!mask) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* high event mask is unused */
+       mask->high_event_mask = cpu_to_le32(0xffffffff);
+       mask->event_mask = cpu_to_le32(event_mask);
+
+       ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
+                                  mask, sizeof(*mask));
+       if (ret < 0) {
+               wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(mask);
+       return ret;
+}
+
+int wl1271_acx_set_preamble(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                           enum acx_preamble_type preamble)
+{
+       struct acx_preamble *acx;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx_set_preamble");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->role_id = wlvif->role_id;
+       acx->preamble = preamble;
+
+       ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("Setting of preamble failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                          enum acx_ctsprotect_type ctsprotect)
+{
+       struct acx_ctsprotect *acx;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->role_id = wlvif->role_id;
+       acx->ctsprotect = ctsprotect;
+
+       ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("Setting of ctsprotect failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
+{
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx statistics");
+
+       ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
+                                    sizeof(*stats));
+       if (ret < 0) {
+               wl1271_warning("acx statistics failed: %d", ret);
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
+int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       struct acx_rate_policy *acx;
+       struct conf_tx_rate_class *c = &wl->conf.tx.sta_rc_conf;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx rate policies");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wl1271_debug(DEBUG_ACX, "basic_rate: 0x%x, full_rate: 0x%x",
+               wlvif->basic_rate, wlvif->rate_set);
+
+       /* configure one basic rate class */
+       acx->rate_policy_idx = cpu_to_le32(wlvif->sta.basic_rate_idx);
+       acx->rate_policy.enabled_rates = cpu_to_le32(wlvif->basic_rate);
+       acx->rate_policy.short_retry_limit = c->short_retry_limit;
+       acx->rate_policy.long_retry_limit = c->long_retry_limit;
+       acx->rate_policy.aflags = c->aflags;
+
+       ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("Setting of rate policies failed: %d", ret);
+               goto out;
+       }
+
+       /* configure one AP supported rate class */
+       acx->rate_policy_idx = cpu_to_le32(wlvif->sta.ap_rate_idx);
+
+       /* the AP policy is HW specific */
+       acx->rate_policy.enabled_rates =
+               cpu_to_le32(wlcore_hw_sta_get_ap_rate_mask(wl, wlvif));
+       acx->rate_policy.short_retry_limit = c->short_retry_limit;
+       acx->rate_policy.long_retry_limit = c->long_retry_limit;
+       acx->rate_policy.aflags = c->aflags;
+
+       ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("Setting of rate policies failed: %d", ret);
+               goto out;
+       }
+
+       /*
+        * configure one rate class for basic p2p operations.
+        * (p2p packets should always go out with OFDM rates, even
+        * if we are currently connected to 11b AP)
+        */
+       acx->rate_policy_idx = cpu_to_le32(wlvif->sta.p2p_rate_idx);
+       acx->rate_policy.enabled_rates =
+                               cpu_to_le32(CONF_TX_RATE_MASK_BASIC_P2P);
+       acx->rate_policy.short_retry_limit = c->short_retry_limit;
+       acx->rate_policy.long_retry_limit = c->long_retry_limit;
+       acx->rate_policy.aflags = c->aflags;
+
+       ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("Setting of rate policies failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
+                     u8 idx)
+{
+       struct acx_rate_policy *acx;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx ap rate policy %d rates 0x%x",
+                    idx, c->enabled_rates);
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->rate_policy.enabled_rates = cpu_to_le32(c->enabled_rates);
+       acx->rate_policy.short_retry_limit = c->short_retry_limit;
+       acx->rate_policy.long_retry_limit = c->long_retry_limit;
+       acx->rate_policy.aflags = c->aflags;
+
+       acx->rate_policy_idx = cpu_to_le32(idx);
+
+       ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("Setting of ap rate policy failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_ac_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                     u8 ac, u8 cw_min, u16 cw_max, u8 aifsn, u16 txop)
+{
+       struct acx_ac_cfg *acx;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
+                    "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop);
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->role_id = wlvif->role_id;
+       acx->ac = ac;
+       acx->cw_min = cw_min;
+       acx->cw_max = cpu_to_le16(cw_max);
+       acx->aifsn = aifsn;
+       acx->tx_op_limit = cpu_to_le16(txop);
+
+       ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx ac cfg failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_tid_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                      u8 queue_id, u8 channel_type,
+                      u8 tsid, u8 ps_scheme, u8 ack_policy,
+                      u32 apsd_conf0, u32 apsd_conf1)
+{
+       struct acx_tid_config *acx;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx tid config");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->role_id = wlvif->role_id;
+       acx->queue_id = queue_id;
+       acx->channel_type = channel_type;
+       acx->tsid = tsid;
+       acx->ps_scheme = ps_scheme;
+       acx->ack_policy = ack_policy;
+       acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
+       acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
+
+       ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("Setting of tid config failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold)
+{
+       struct acx_frag_threshold *acx;
+       int ret = 0;
+
+       /*
+        * If the fragmentation is not configured or out of range, use the
+        * default value.
+        */
+       if (frag_threshold > IEEE80211_MAX_FRAG_THRESHOLD)
+               frag_threshold = wl->conf.tx.frag_threshold;
+
+       wl1271_debug(DEBUG_ACX, "acx frag threshold: %d", frag_threshold);
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->frag_threshold = cpu_to_le16((u16)frag_threshold);
+       ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("Setting of frag threshold failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_tx_config_options(struct wl1271 *wl)
+{
+       struct acx_tx_config_options *acx;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx tx config options");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
+       acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
+       ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("Setting of tx options failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl12xx_acx_mem_cfg(struct wl1271 *wl)
+{
+       struct wl12xx_acx_config_memory *mem_conf;
+       struct conf_memory_settings *mem;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
+
+       mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
+       if (!mem_conf) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       mem = &wl->conf.mem;
+
+       /* memory config */
+       mem_conf->num_stations = mem->num_stations;
+       mem_conf->rx_mem_block_num = mem->rx_block_num;
+       mem_conf->tx_min_mem_block_num = mem->tx_min_block_num;
+       mem_conf->num_ssid_profiles = mem->ssid_profiles;
+       mem_conf->total_tx_descriptors = cpu_to_le32(wl->num_tx_desc);
+       mem_conf->dyn_mem_enable = mem->dynamic_memory;
+       mem_conf->tx_free_req = mem->min_req_tx_blocks;
+       mem_conf->rx_free_req = mem->min_req_rx_blocks;
+       mem_conf->tx_min = mem->tx_min;
+       mem_conf->fwlog_blocks = wl->conf.fwlog.mem_blocks;
+
+       ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
+                                  sizeof(*mem_conf));
+       if (ret < 0) {
+               wl1271_warning("wl1271 mem config failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(mem_conf);
+       return ret;
+}
+
+int wl1271_acx_init_mem_config(struct wl1271 *wl)
+{
+       int ret;
+
+       wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
+                                    GFP_KERNEL);
+       if (!wl->target_mem_map) {
+               wl1271_error("couldn't allocate target memory map");
+               return -ENOMEM;
+       }
+
+       /* we now ask for the firmware built memory map */
+       ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
+                                sizeof(struct wl1271_acx_mem_map));
+       if (ret < 0) {
+               wl1271_error("couldn't retrieve firmware memory map");
+               kfree(wl->target_mem_map);
+               wl->target_mem_map = NULL;
+               return ret;
+       }
+
+       /* initialize TX block book keeping */
+       wl->tx_blocks_available =
+               le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
+       wl1271_debug(DEBUG_TX, "available tx blocks: %d",
+                    wl->tx_blocks_available);
+
+       return 0;
+}
+
+int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
+{
+       struct wl1271_acx_rx_config_opt *rx_conf;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
+
+       rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
+       if (!rx_conf) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
+       rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
+       rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
+       rx_conf->queue_type = wl->conf.rx.queue_type;
+
+       ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
+                                  sizeof(*rx_conf));
+       if (ret < 0) {
+               wl1271_warning("wl1271 rx config opt failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(rx_conf);
+       return ret;
+}
+
+int wl1271_acx_bet_enable(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                         bool enable)
+{
+       struct wl1271_acx_bet_enable *acx = NULL;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx bet enable");
+
+       if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
+               goto out;
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->role_id = wlvif->role_id;
+       acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
+       acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
+
+       ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx bet enable failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_arp_ip_filter(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                            u8 enable, __be32 address)
+{
+       struct wl1271_acx_arp_filter *acx;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->role_id = wlvif->role_id;
+       acx->version = ACX_IPV4_VERSION;
+       acx->enable = enable;
+
+       if (enable)
+               memcpy(acx->address, &address, ACX_IPV4_ADDR_SIZE);
+
+       ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
+                                  acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("failed to set arp ip filter: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_pm_config(struct wl1271 *wl)
+{
+       struct wl1271_acx_pm_config *acx = NULL;
+       struct  conf_pm_config_settings *c = &wl->conf.pm_config;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx pm config");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
+       acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
+
+       ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx pm config failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                              bool enable)
+{
+       struct wl1271_acx_keep_alive_mode *acx = NULL;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx keep alive mode: %d", enable);
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->role_id = wlvif->role_id;
+       acx->enabled = enable;
+
+       ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx keep alive mode failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_keep_alive_config(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                                u8 index, u8 tpl_valid)
+{
+       struct wl1271_acx_keep_alive_config *acx = NULL;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx keep alive config");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->role_id = wlvif->role_id;
+       acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval);
+       acx->index = index;
+       acx->tpl_validation = tpl_valid;
+       acx->trigger = ACX_KEEP_ALIVE_NO_TX;
+
+       ret = wl1271_cmd_configure(wl, ACX_SET_KEEP_ALIVE_CONFIG,
+                                  acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx keep alive config failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                               bool enable, s16 thold, u8 hyst)
+{
+       struct wl1271_acx_rssi_snr_trigger *acx = NULL;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx rssi snr trigger");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wlvif->last_rssi_event = -1;
+
+       acx->role_id = wlvif->role_id;
+       acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing);
+       acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON;
+       acx->type = WL1271_ACX_TRIG_TYPE_EDGE;
+       if (enable)
+               acx->enable = WL1271_ACX_TRIG_ENABLE;
+       else
+               acx->enable = WL1271_ACX_TRIG_DISABLE;
+
+       acx->index = WL1271_ACX_TRIG_IDX_RSSI;
+       acx->dir = WL1271_ACX_TRIG_DIR_BIDIR;
+       acx->threshold = cpu_to_le16(thold);
+       acx->hysteresis = hyst;
+
+       ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_TRIGGER, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx rssi snr trigger setting failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl,
+                                   struct wl12xx_vif *wlvif)
+{
+       struct wl1271_acx_rssi_snr_avg_weights *acx = NULL;
+       struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx rssi snr avg weights");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->role_id = wlvif->role_id;
+       acx->rssi_beacon = c->avg_weight_rssi_beacon;
+       acx->rssi_data = c->avg_weight_rssi_data;
+       acx->snr_beacon = c->avg_weight_snr_beacon;
+       acx->snr_data = c->avg_weight_snr_data;
+
+       ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_WEIGHTS, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx rssi snr trigger weights failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
+                                   struct ieee80211_sta_ht_cap *ht_cap,
+                                   bool allow_ht_operation, u8 hlid)
+{
+       struct wl1271_acx_ht_capabilities *acx;
+       int ret = 0;
+       u32 ht_capabilites = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx ht capabilities setting "
+                    "sta supp: %d sta cap: %d", ht_cap->ht_supported,
+                    ht_cap->cap);
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       if (allow_ht_operation && ht_cap->ht_supported) {
+               /* no need to translate capabilities - use the spec values */
+               ht_capabilites = ht_cap->cap;
+
+               /*
+                * this bit is not employed by the spec but only by FW to
+                * indicate peer HT support
+                */
+               ht_capabilites |= WL12XX_HT_CAP_HT_OPERATION;
+
+               /* get data from A-MPDU parameters field */
+               acx->ampdu_max_length = ht_cap->ampdu_factor;
+               acx->ampdu_min_spacing = ht_cap->ampdu_density;
+       }
+
+       acx->hlid = hlid;
+       acx->ht_capabilites = cpu_to_le32(ht_capabilites);
+
+       ret = wl1271_cmd_configure(wl, ACX_PEER_HT_CAP, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx ht capabilities setting failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_set_ht_information(struct wl1271 *wl,
+                                  struct wl12xx_vif *wlvif,
+                                  u16 ht_operation_mode)
+{
+       struct wl1271_acx_ht_information *acx;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx ht information setting");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->role_id = wlvif->role_id;
+       acx->ht_protection =
+               (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION);
+       acx->rifs_mode = 0;
+       acx->gf_protection =
+               !!(ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
+       acx->ht_tx_burst_limit = 0;
+       acx->dual_cts_protection = 0;
+
+       ret = wl1271_cmd_configure(wl, ACX_HT_BSS_OPERATION, acx, sizeof(*acx));
+
+       if (ret < 0) {
+               wl1271_warning("acx ht information setting failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+/* Configure BA session initiator/receiver parameters setting in the FW. */
+int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl,
+                                      struct wl12xx_vif *wlvif)
+{
+       struct wl1271_acx_ba_initiator_policy *acx;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx ba initiator policy");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* set for the current role */
+       acx->role_id = wlvif->role_id;
+       acx->tid_bitmap = wl->conf.ht.tx_ba_tid_bitmap;
+       acx->win_size = wl->conf.ht.tx_ba_win_size;
+       acx->inactivity_timeout = wl->conf.ht.inactivity_timeout;
+
+       ret = wl1271_cmd_configure(wl,
+                                  ACX_BA_SESSION_INIT_POLICY,
+                                  acx,
+                                  sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx ba initiator policy failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+/* setup BA session receiver setting in the FW. */
+int wl12xx_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index,
+                                      u16 ssn, bool enable, u8 peer_hlid)
+{
+       struct wl1271_acx_ba_receiver_setup *acx;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx ba receiver session setting");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->hlid = peer_hlid;
+       acx->tid = tid_index;
+       acx->enable = enable;
+       acx->win_size = wl->conf.ht.rx_ba_win_size;
+       acx->ssn = ssn;
+
+       ret = wl1271_cmd_configure(wl, ACX_BA_SESSION_RX_SETUP, acx,
+                                  sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx ba receiver session failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl12xx_acx_tsf_info(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                       u64 *mactime)
+{
+       struct wl12xx_acx_fw_tsf_information *tsf_info;
+       int ret;
+
+       tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
+       if (!tsf_info) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       tsf_info->role_id = wlvif->role_id;
+
+       ret = wl1271_cmd_interrogate(wl, ACX_TSF_INFO,
+                                    tsf_info, sizeof(*tsf_info));
+       if (ret < 0) {
+               wl1271_warning("acx tsf info interrogate failed");
+               goto out;
+       }
+
+       *mactime = le32_to_cpu(tsf_info->current_tsf_low) |
+               ((u64) le32_to_cpu(tsf_info->current_tsf_high) << 32);
+
+out:
+       kfree(tsf_info);
+       return ret;
+}
+
+int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                              bool enable)
+{
+       struct wl1271_acx_ps_rx_streaming *rx_streaming;
+       u32 conf_queues, enable_queues;
+       int i, ret = 0;
+
+       wl1271_debug(DEBUG_ACX, "acx ps rx streaming");
+
+       rx_streaming = kzalloc(sizeof(*rx_streaming), GFP_KERNEL);
+       if (!rx_streaming) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       conf_queues = wl->conf.rx_streaming.queues;
+       if (enable)
+               enable_queues = conf_queues;
+       else
+               enable_queues = 0;
+
+       for (i = 0; i < 8; i++) {
+               /*
+                * Skip non-changed queues, to avoid redundant acxs.
+                * this check assumes conf.rx_streaming.queues can't
+                * be changed while rx_streaming is enabled.
+                */
+               if (!(conf_queues & BIT(i)))
+                       continue;
+
+               rx_streaming->role_id = wlvif->role_id;
+               rx_streaming->tid = i;
+               rx_streaming->enable = enable_queues & BIT(i);
+               rx_streaming->period = wl->conf.rx_streaming.interval;
+               rx_streaming->timeout = wl->conf.rx_streaming.interval;
+
+               ret = wl1271_cmd_configure(wl, ACX_PS_RX_STREAMING,
+                                          rx_streaming,
+                                          sizeof(*rx_streaming));
+               if (ret < 0) {
+                       wl1271_warning("acx ps rx streaming failed: %d", ret);
+                       goto out;
+               }
+       }
+out:
+       kfree(rx_streaming);
+       return ret;
+}
+
+int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       struct wl1271_acx_ap_max_tx_retry *acx = NULL;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx ap max tx retry");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx)
+               return -ENOMEM;
+
+       acx->role_id = wlvif->role_id;
+       acx->max_tx_retry = cpu_to_le16(wl->conf.tx.max_tx_retries);
+
+       ret = wl1271_cmd_configure(wl, ACX_MAX_TX_FAILURE, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx ap max tx retry failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl12xx_acx_config_ps(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       struct wl1271_acx_config_ps *config_ps;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx config ps");
+
+       config_ps = kzalloc(sizeof(*config_ps), GFP_KERNEL);
+       if (!config_ps) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       config_ps->exit_retries = wl->conf.conn.psm_exit_retries;
+       config_ps->enter_retries = wl->conf.conn.psm_entry_retries;
+       config_ps->null_data_rate = cpu_to_le32(wlvif->basic_rate);
+
+       ret = wl1271_cmd_configure(wl, ACX_CONFIG_PS, config_ps,
+                                  sizeof(*config_ps));
+
+       if (ret < 0) {
+               wl1271_warning("acx config ps failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(config_ps);
+       return ret;
+}
+
+int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr)
+{
+       struct wl1271_acx_inconnection_sta *acx = NULL;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx set inconnaction sta %pM", addr);
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx)
+               return -ENOMEM;
+
+       memcpy(acx->addr, addr, ETH_ALEN);
+
+       ret = wl1271_cmd_configure(wl, ACX_UPDATE_INCONNECTION_STA_LIST,
+                                  acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx set inconnaction sta failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl1271_acx_fm_coex(struct wl1271 *wl)
+{
+       struct wl1271_acx_fm_coex *acx;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx fm coex setting");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->enable = wl->conf.fm_coex.enable;
+       acx->swallow_period = wl->conf.fm_coex.swallow_period;
+       acx->n_divider_fref_set_1 = wl->conf.fm_coex.n_divider_fref_set_1;
+       acx->n_divider_fref_set_2 = wl->conf.fm_coex.n_divider_fref_set_2;
+       acx->m_divider_fref_set_1 =
+               cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_1);
+       acx->m_divider_fref_set_2 =
+               cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_2);
+       acx->coex_pll_stabilization_time =
+               cpu_to_le32(wl->conf.fm_coex.coex_pll_stabilization_time);
+       acx->ldo_stabilization_time =
+               cpu_to_le16(wl->conf.fm_coex.ldo_stabilization_time);
+       acx->fm_disturbed_band_margin =
+               wl->conf.fm_coex.fm_disturbed_band_margin;
+       acx->swallow_clk_diff = wl->conf.fm_coex.swallow_clk_diff;
+
+       ret = wl1271_cmd_configure(wl, ACX_FM_COEX_CFG, acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx fm coex setting failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl12xx_acx_set_rate_mgmt_params(struct wl1271 *wl)
+{
+       struct wl12xx_acx_set_rate_mgmt_params *acx = NULL;
+       struct conf_rate_policy_settings *conf = &wl->conf.rate;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx set rate mgmt params");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx)
+               return -ENOMEM;
+
+       acx->index = ACX_RATE_MGMT_ALL_PARAMS;
+       acx->rate_retry_score = cpu_to_le16(conf->rate_retry_score);
+       acx->per_add = cpu_to_le16(conf->per_add);
+       acx->per_th1 = cpu_to_le16(conf->per_th1);
+       acx->per_th2 = cpu_to_le16(conf->per_th2);
+       acx->max_per = cpu_to_le16(conf->max_per);
+       acx->inverse_curiosity_factor = conf->inverse_curiosity_factor;
+       acx->tx_fail_low_th = conf->tx_fail_low_th;
+       acx->tx_fail_high_th = conf->tx_fail_high_th;
+       acx->per_alpha_shift = conf->per_alpha_shift;
+       acx->per_add_shift = conf->per_add_shift;
+       acx->per_beta1_shift = conf->per_beta1_shift;
+       acx->per_beta2_shift = conf->per_beta2_shift;
+       acx->rate_check_up = conf->rate_check_up;
+       acx->rate_check_down = conf->rate_check_down;
+       memcpy(acx->rate_retry_policy, conf->rate_retry_policy,
+              sizeof(acx->rate_retry_policy));
+
+       ret = wl1271_cmd_configure(wl, ACX_SET_RATE_MGMT_PARAMS,
+                                  acx, sizeof(*acx));
+       if (ret < 0) {
+               wl1271_warning("acx set rate mgmt params failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+}
+
+int wl12xx_acx_config_hangover(struct wl1271 *wl)
+{
+       struct wl12xx_acx_config_hangover *acx;
+       struct conf_hangover_settings *conf = &wl->conf.hangover;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "acx config hangover");
+
+       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
+       if (!acx) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       acx->recover_time = cpu_to_le32(conf->recover_time);
+       acx->hangover_period = conf->hangover_period;
+       acx->dynamic_mode = conf->dynamic_mode;
+       acx->early_termination_mode = conf->early_termination_mode;
+       acx->max_period = conf->max_period;
+       acx->min_period = conf->min_period;
+       acx->increase_delta = conf->increase_delta;
+       acx->decrease_delta = conf->decrease_delta;
+       acx->quiet_time = conf->quiet_time;
+       acx->increase_time = conf->increase_time;
+       acx->window_size = acx->window_size;
+
+       ret = wl1271_cmd_configure(wl, ACX_CONFIG_HANGOVER, acx,
+                                  sizeof(*acx));
+
+       if (ret < 0) {
+               wl1271_warning("acx config hangover failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(acx);
+       return ret;
+
+}
diff --git a/drivers/net/wireless/ti/wlcore/acx.h b/drivers/net/wireless/ti/wlcore/acx.h
new file mode 100644 (file)
index 0000000..b2f8883
--- /dev/null
@@ -0,0 +1,1308 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
+ * Copyright (C) 2008-2010 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __ACX_H__
+#define __ACX_H__
+
+#include "wlcore.h"
+#include "cmd.h"
+
+/*************************************************************************
+
+    Host Interrupt Register (WiLink -> Host)
+
+**************************************************************************/
+/* HW Initiated interrupt Watchdog timer expiration */
+#define WL1271_ACX_INTR_WATCHDOG           BIT(0)
+/* Init sequence is done (masked interrupt, detection through polling only ) */
+#define WL1271_ACX_INTR_INIT_COMPLETE      BIT(1)
+/* Event was entered to Event MBOX #A*/
+#define WL1271_ACX_INTR_EVENT_A            BIT(2)
+/* Event was entered to Event MBOX #B*/
+#define WL1271_ACX_INTR_EVENT_B            BIT(3)
+/* Command processing completion*/
+#define WL1271_ACX_INTR_CMD_COMPLETE       BIT(4)
+/* Signaling the host on HW wakeup */
+#define WL1271_ACX_INTR_HW_AVAILABLE       BIT(5)
+/* The MISC bit is used for aggregation of RX, TxComplete and TX rate update */
+#define WL1271_ACX_INTR_DATA               BIT(6)
+/* Trace message on MBOX #A */
+#define WL1271_ACX_INTR_TRACE_A            BIT(7)
+/* Trace message on MBOX #B */
+#define WL1271_ACX_INTR_TRACE_B            BIT(8)
+
+#define WL1271_ACX_INTR_ALL               0xFFFFFFFF
+#define WL1271_ACX_ALL_EVENTS_VECTOR       (WL1271_ACX_INTR_WATCHDOG      | \
+                                           WL1271_ACX_INTR_INIT_COMPLETE | \
+                                           WL1271_ACX_INTR_EVENT_A       | \
+                                           WL1271_ACX_INTR_EVENT_B       | \
+                                           WL1271_ACX_INTR_CMD_COMPLETE  | \
+                                           WL1271_ACX_INTR_HW_AVAILABLE  | \
+                                           WL1271_ACX_INTR_DATA)
+
+#define WL1271_INTR_MASK                   (WL1271_ACX_INTR_WATCHDOG     | \
+                                           WL1271_ACX_INTR_EVENT_A      | \
+                                           WL1271_ACX_INTR_EVENT_B      | \
+                                           WL1271_ACX_INTR_HW_AVAILABLE | \
+                                           WL1271_ACX_INTR_DATA)
+
+/* Target's information element */
+struct acx_header {
+       struct wl1271_cmd_header cmd;
+
+       /* acx (or information element) header */
+       __le16 id;
+
+       /* payload length (not including headers */
+       __le16 len;
+} __packed;
+
+struct acx_error_counter {
+       struct acx_header header;
+
+       /* The number of PLCP errors since the last time this */
+       /* information element was interrogated. This field is */
+       /* automatically cleared when it is interrogated.*/
+       __le32 PLCP_error;
+
+       /* The number of FCS errors since the last time this */
+       /* information element was interrogated. This field is */
+       /* automatically cleared when it is interrogated.*/
+       __le32 FCS_error;
+
+       /* The number of MPDUs without PLCP header errors received*/
+       /* since the last time this information element was interrogated. */
+       /* This field is automatically cleared when it is interrogated.*/
+       __le32 valid_frame;
+
+       /* the number of missed sequence numbers in the squentially */
+       /* values of frames seq numbers */
+       __le32 seq_num_miss;
+} __packed;
+
+enum wl12xx_role {
+       WL1271_ROLE_STA = 0,
+       WL1271_ROLE_IBSS,
+       WL1271_ROLE_AP,
+       WL1271_ROLE_DEVICE,
+       WL1271_ROLE_P2P_CL,
+       WL1271_ROLE_P2P_GO,
+
+       WL12XX_INVALID_ROLE_TYPE = 0xff
+};
+
+enum wl1271_psm_mode {
+       /* Active mode */
+       WL1271_PSM_CAM = 0,
+
+       /* Power save mode */
+       WL1271_PSM_PS = 1,
+
+       /* Extreme low power */
+       WL1271_PSM_ELP = 2,
+};
+
+struct acx_sleep_auth {
+       struct acx_header header;
+
+       /* The sleep level authorization of the device. */
+       /* 0 - Always active*/
+       /* 1 - Power down mode: light / fast sleep*/
+       /* 2 - ELP mode: Deep / Max sleep*/
+       u8  sleep_auth;
+       u8  padding[3];
+} __packed;
+
+enum {
+       HOSTIF_PCI_MASTER_HOST_INDIRECT,
+       HOSTIF_PCI_MASTER_HOST_DIRECT,
+       HOSTIF_SLAVE,
+       HOSTIF_PKT_RING,
+       HOSTIF_DONTCARE = 0xFF
+};
+
+#define DEFAULT_UCAST_PRIORITY          0
+#define DEFAULT_RX_Q_PRIORITY           0
+#define DEFAULT_RXQ_PRIORITY            0 /* low 0 .. 15 high  */
+#define DEFAULT_RXQ_TYPE                0x07    /* All frames, Data/Ctrl/Mgmt */
+#define TRACE_BUFFER_MAX_SIZE           256
+
+#define  DP_RX_PACKET_RING_CHUNK_SIZE 1600
+#define  DP_TX_PACKET_RING_CHUNK_SIZE 1600
+#define  DP_RX_PACKET_RING_CHUNK_NUM 2
+#define  DP_TX_PACKET_RING_CHUNK_NUM 2
+#define  DP_TX_COMPLETE_TIME_OUT 20
+
+#define TX_MSDU_LIFETIME_MIN       0
+#define TX_MSDU_LIFETIME_MAX       3000
+#define TX_MSDU_LIFETIME_DEF       512
+#define RX_MSDU_LIFETIME_MIN       0
+#define RX_MSDU_LIFETIME_MAX       0xFFFFFFFF
+#define RX_MSDU_LIFETIME_DEF       512000
+
+struct acx_rx_msdu_lifetime {
+       struct acx_header header;
+
+       /*
+        * The maximum amount of time, in TU, before the
+        * firmware discards the MSDU.
+        */
+       __le32 lifetime;
+} __packed;
+
+enum acx_slot_type {
+       SLOT_TIME_LONG = 0,
+       SLOT_TIME_SHORT = 1,
+       DEFAULT_SLOT_TIME = SLOT_TIME_SHORT,
+       MAX_SLOT_TIMES = 0xFF
+};
+
+#define STATION_WONE_INDEX 0
+
+struct acx_slot {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 wone_index; /* Reserved */
+       u8 slot_time;
+       u8 reserved[5];
+} __packed;
+
+
+#define ACX_MC_ADDRESS_GROUP_MAX       (8)
+#define ADDRESS_GROUP_MAX_LEN          (ETH_ALEN * ACX_MC_ADDRESS_GROUP_MAX)
+
+struct acx_dot11_grp_addr_tbl {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 enabled;
+       u8 num_groups;
+       u8 pad[1];
+       u8 mac_table[ADDRESS_GROUP_MAX_LEN];
+} __packed;
+
+struct acx_rx_timeout {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 reserved;
+       __le16 ps_poll_timeout;
+       __le16 upsd_timeout;
+       u8 padding[2];
+} __packed;
+
+struct acx_rts_threshold {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 reserved;
+       __le16 threshold;
+} __packed;
+
+struct acx_beacon_filter_option {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 enable;
+       /*
+        * The number of beacons without the unicast TIM
+        * bit set that the firmware buffers before
+        * signaling the host about ready frames.
+        * When set to 0 and the filter is enabled, beacons
+        * without the unicast TIM bit set are dropped.
+        */
+       u8 max_num_beacons;
+       u8 pad[1];
+} __packed;
+
+/*
+ * ACXBeaconFilterEntry (not 221)
+ * Byte Offset     Size (Bytes)    Definition
+ * ===========     ============    ==========
+ * 0               1               IE identifier
+ * 1               1               Treatment bit mask
+ *
+ * ACXBeaconFilterEntry (221)
+ * Byte Offset     Size (Bytes)    Definition
+ * ===========     ============    ==========
+ * 0               1               IE identifier
+ * 1               1               Treatment bit mask
+ * 2               3               OUI
+ * 5               1               Type
+ * 6               2               Version
+ *
+ *
+ * Treatment bit mask - The information element handling:
+ * bit 0 - The information element is compared and transferred
+ * in case of change.
+ * bit 1 - The information element is transferred to the host
+ * with each appearance or disappearance.
+ * Note that both bits can be set at the same time.
+ */
+#define        BEACON_FILTER_TABLE_MAX_IE_NUM                 (32)
+#define BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM (6)
+#define BEACON_FILTER_TABLE_IE_ENTRY_SIZE             (2)
+#define BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE (6)
+#define BEACON_FILTER_TABLE_MAX_SIZE ((BEACON_FILTER_TABLE_MAX_IE_NUM * \
+                           BEACON_FILTER_TABLE_IE_ENTRY_SIZE) + \
+                          (BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM * \
+                           BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE))
+
+struct acx_beacon_filter_ie_table {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 num_ie;
+       u8 pad[2];
+       u8 table[BEACON_FILTER_TABLE_MAX_SIZE];
+} __packed;
+
+struct acx_conn_monit_params {
+       struct acx_header header;
+
+          u8 role_id;
+          u8 padding[3];
+       __le32 synch_fail_thold; /* number of beacons missed */
+       __le32 bss_lose_timeout; /* number of TU's from synch fail */
+} __packed;
+
+struct acx_bt_wlan_coex {
+       struct acx_header header;
+
+       u8 enable;
+       u8 pad[3];
+} __packed;
+
+struct acx_bt_wlan_coex_param {
+       struct acx_header header;
+
+       __le32 params[CONF_SG_PARAMS_MAX];
+       u8 param_idx;
+       u8 padding[3];
+} __packed;
+
+struct acx_dco_itrim_params {
+       struct acx_header header;
+
+       u8 enable;
+       u8 padding[3];
+       __le32 timeout;
+} __packed;
+
+struct acx_energy_detection {
+       struct acx_header header;
+
+       /* The RX Clear Channel Assessment threshold in the PHY */
+       __le16 rx_cca_threshold;
+       u8 tx_energy_detection;
+       u8 pad;
+} __packed;
+
+struct acx_beacon_broadcast {
+       struct acx_header header;
+
+       u8 role_id;
+       /* Enables receiving of broadcast packets in PS mode */
+       u8 rx_broadcast_in_ps;
+
+       __le16 beacon_rx_timeout;
+       __le16 broadcast_timeout;
+
+       /* Consecutive PS Poll failures before updating the host */
+       u8 ps_poll_threshold;
+       u8 pad[1];
+} __packed;
+
+struct acx_event_mask {
+       struct acx_header header;
+
+       __le32 event_mask;
+       __le32 high_event_mask; /* Unused */
+} __packed;
+
+#define SCAN_PASSIVE           BIT(0)
+#define SCAN_5GHZ_BAND         BIT(1)
+#define SCAN_TRIGGERED         BIT(2)
+#define SCAN_PRIORITY_HIGH     BIT(3)
+
+/* When set, disable HW encryption */
+#define DF_ENCRYPTION_DISABLE      0x01
+#define DF_SNIFF_MODE_ENABLE       0x80
+
+struct acx_feature_config {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 padding[3];
+       __le32 options;
+       __le32 data_flow_options;
+} __packed;
+
+struct acx_current_tx_power {
+       struct acx_header header;
+
+       u8  role_id;
+       u8  current_tx_power;
+       u8  padding[2];
+} __packed;
+
+struct acx_wake_up_condition {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 wake_up_event; /* Only one bit can be set */
+       u8 listen_interval;
+       u8 pad[1];
+} __packed;
+
+struct acx_aid {
+       struct acx_header header;
+
+       /*
+        * To be set when associated with an AP.
+        */
+       u8 role_id;
+       u8 reserved;
+       __le16 aid;
+} __packed;
+
+enum acx_preamble_type {
+       ACX_PREAMBLE_LONG = 0,
+       ACX_PREAMBLE_SHORT = 1
+};
+
+struct acx_preamble {
+       struct acx_header header;
+
+       /*
+        * When set, the WiLink transmits the frames with a short preamble and
+        * when cleared, the WiLink transmits the frames with a long preamble.
+        */
+       u8 role_id;
+       u8 preamble;
+       u8 padding[2];
+} __packed;
+
+enum acx_ctsprotect_type {
+       CTSPROTECT_DISABLE = 0,
+       CTSPROTECT_ENABLE = 1
+};
+
+struct acx_ctsprotect {
+       struct acx_header header;
+       u8 role_id;
+       u8 ctsprotect;
+       u8 padding[2];
+} __packed;
+
+struct acx_tx_statistics {
+       __le32 internal_desc_overflow;
+}  __packed;
+
+struct acx_rx_statistics {
+       __le32 out_of_mem;
+       __le32 hdr_overflow;
+       __le32 hw_stuck;
+       __le32 dropped;
+       __le32 fcs_err;
+       __le32 xfr_hint_trig;
+       __le32 path_reset;
+       __le32 reset_counter;
+} __packed;
+
+struct acx_dma_statistics {
+       __le32 rx_requested;
+       __le32 rx_errors;
+       __le32 tx_requested;
+       __le32 tx_errors;
+}  __packed;
+
+struct acx_isr_statistics {
+       /* host command complete */
+       __le32 cmd_cmplt;
+
+       /* fiqisr() */
+       __le32 fiqs;
+
+       /* (INT_STS_ND & INT_TRIG_RX_HEADER) */
+       __le32 rx_headers;
+
+       /* (INT_STS_ND & INT_TRIG_RX_CMPLT) */
+       __le32 rx_completes;
+
+       /* (INT_STS_ND & INT_TRIG_NO_RX_BUF) */
+       __le32 rx_mem_overflow;
+
+       /* (INT_STS_ND & INT_TRIG_S_RX_RDY) */
+       __le32 rx_rdys;
+
+       /* irqisr() */
+       __le32 irqs;
+
+       /* (INT_STS_ND & INT_TRIG_TX_PROC) */
+       __le32 tx_procs;
+
+       /* (INT_STS_ND & INT_TRIG_DECRYPT_DONE) */
+       __le32 decrypt_done;
+
+       /* (INT_STS_ND & INT_TRIG_DMA0) */
+       __le32 dma0_done;
+
+       /* (INT_STS_ND & INT_TRIG_DMA1) */
+       __le32 dma1_done;
+
+       /* (INT_STS_ND & INT_TRIG_TX_EXC_CMPLT) */
+       __le32 tx_exch_complete;
+
+       /* (INT_STS_ND & INT_TRIG_COMMAND) */
+       __le32 commands;
+
+       /* (INT_STS_ND & INT_TRIG_RX_PROC) */
+       __le32 rx_procs;
+
+       /* (INT_STS_ND & INT_TRIG_PM_802) */
+       __le32 hw_pm_mode_changes;
+
+       /* (INT_STS_ND & INT_TRIG_ACKNOWLEDGE) */
+       __le32 host_acknowledges;
+
+       /* (INT_STS_ND & INT_TRIG_PM_PCI) */
+       __le32 pci_pm;
+
+       /* (INT_STS_ND & INT_TRIG_ACM_WAKEUP) */
+       __le32 wakeups;
+
+       /* (INT_STS_ND & INT_TRIG_LOW_RSSI) */
+       __le32 low_rssi;
+} __packed;
+
+struct acx_wep_statistics {
+       /* WEP address keys configured */
+       __le32 addr_key_count;
+
+       /* default keys configured */
+       __le32 default_key_count;
+
+       __le32 reserved;
+
+       /* number of times that WEP key not found on lookup */
+       __le32 key_not_found;
+
+       /* number of times that WEP key decryption failed */
+       __le32 decrypt_fail;
+
+       /* WEP packets decrypted */
+       __le32 packets;
+
+       /* WEP decrypt interrupts */
+       __le32 interrupt;
+} __packed;
+
+#define ACX_MISSED_BEACONS_SPREAD 10
+
+struct acx_pwr_statistics {
+       /* the amount of enters into power save mode (both PD & ELP) */
+       __le32 ps_enter;
+
+       /* the amount of enters into ELP mode */
+       __le32 elp_enter;
+
+       /* the amount of missing beacon interrupts to the host */
+       __le32 missing_bcns;
+
+       /* the amount of wake on host-access times */
+       __le32 wake_on_host;
+
+       /* the amount of wake on timer-expire */
+       __le32 wake_on_timer_exp;
+
+       /* the number of packets that were transmitted with PS bit set */
+       __le32 tx_with_ps;
+
+       /* the number of packets that were transmitted with PS bit clear */
+       __le32 tx_without_ps;
+
+       /* the number of received beacons */
+       __le32 rcvd_beacons;
+
+       /* the number of entering into PowerOn (power save off) */
+       __le32 power_save_off;
+
+       /* the number of entries into power save mode */
+       __le16 enable_ps;
+
+       /*
+        * the number of exits from power save, not including failed PS
+        * transitions
+        */
+       __le16 disable_ps;
+
+       /*
+        * the number of times the TSF counter was adjusted because
+        * of drift
+        */
+       __le32 fix_tsf_ps;
+
+       /* Gives statistics about the spread continuous missed beacons.
+        * The 16 LSB are dedicated for the PS mode.
+        * The 16 MSB are dedicated for the PS mode.
+        * cont_miss_bcns_spread[0] - single missed beacon.
+        * cont_miss_bcns_spread[1] - two continuous missed beacons.
+        * cont_miss_bcns_spread[2] - three continuous missed beacons.
+        * ...
+        * cont_miss_bcns_spread[9] - ten and more continuous missed beacons.
+       */
+       __le32 cont_miss_bcns_spread[ACX_MISSED_BEACONS_SPREAD];
+
+       /* the number of beacons in awake mode */
+       __le32 rcvd_awake_beacons;
+} __packed;
+
+struct acx_mic_statistics {
+       __le32 rx_pkts;
+       __le32 calc_failure;
+} __packed;
+
+struct acx_aes_statistics {
+       __le32 encrypt_fail;
+       __le32 decrypt_fail;
+       __le32 encrypt_packets;
+       __le32 decrypt_packets;
+       __le32 encrypt_interrupt;
+       __le32 decrypt_interrupt;
+} __packed;
+
+struct acx_event_statistics {
+       __le32 heart_beat;
+       __le32 calibration;
+       __le32 rx_mismatch;
+       __le32 rx_mem_empty;
+       __le32 rx_pool;
+       __le32 oom_late;
+       __le32 phy_transmit_error;
+       __le32 tx_stuck;
+} __packed;
+
+struct acx_ps_statistics {
+       __le32 pspoll_timeouts;
+       __le32 upsd_timeouts;
+       __le32 upsd_max_sptime;
+       __le32 upsd_max_apturn;
+       __le32 pspoll_max_apturn;
+       __le32 pspoll_utilization;
+       __le32 upsd_utilization;
+} __packed;
+
+struct acx_rxpipe_statistics {
+       __le32 rx_prep_beacon_drop;
+       __le32 descr_host_int_trig_rx_data;
+       __le32 beacon_buffer_thres_host_int_trig_rx_data;
+       __le32 missed_beacon_host_int_trig_rx_data;
+       __le32 tx_xfr_host_int_trig_rx_data;
+} __packed;
+
+struct acx_statistics {
+       struct acx_header header;
+
+       struct acx_tx_statistics tx;
+       struct acx_rx_statistics rx;
+       struct acx_dma_statistics dma;
+       struct acx_isr_statistics isr;
+       struct acx_wep_statistics wep;
+       struct acx_pwr_statistics pwr;
+       struct acx_aes_statistics aes;
+       struct acx_mic_statistics mic;
+       struct acx_event_statistics event;
+       struct acx_ps_statistics ps;
+       struct acx_rxpipe_statistics rxpipe;
+} __packed;
+
+struct acx_rate_class {
+       __le32 enabled_rates;
+       u8 short_retry_limit;
+       u8 long_retry_limit;
+       u8 aflags;
+       u8 reserved;
+};
+
+struct acx_rate_policy {
+       struct acx_header header;
+
+       __le32 rate_policy_idx;
+       struct acx_rate_class rate_policy;
+} __packed;
+
+struct acx_ac_cfg {
+       struct acx_header header;
+       u8 role_id;
+       u8 ac;
+       u8 aifsn;
+       u8 cw_min;
+       __le16 cw_max;
+       __le16 tx_op_limit;
+} __packed;
+
+struct acx_tid_config {
+       struct acx_header header;
+       u8 role_id;
+       u8 queue_id;
+       u8 channel_type;
+       u8 tsid;
+       u8 ps_scheme;
+       u8 ack_policy;
+       u8 padding[2];
+       __le32 apsd_conf[2];
+} __packed;
+
+struct acx_frag_threshold {
+       struct acx_header header;
+       __le16 frag_threshold;
+       u8 padding[2];
+} __packed;
+
+struct acx_tx_config_options {
+       struct acx_header header;
+       __le16 tx_compl_timeout;     /* msec */
+       __le16 tx_compl_threshold;   /* number of packets */
+} __packed;
+
+struct wl12xx_acx_config_memory {
+       struct acx_header header;
+
+       u8 rx_mem_block_num;
+       u8 tx_min_mem_block_num;
+       u8 num_stations;
+       u8 num_ssid_profiles;
+       __le32 total_tx_descriptors;
+       u8 dyn_mem_enable;
+       u8 tx_free_req;
+       u8 rx_free_req;
+       u8 tx_min;
+       u8 fwlog_blocks;
+       u8 padding[3];
+} __packed;
+
+struct wl1271_acx_mem_map {
+       struct acx_header header;
+
+       __le32 code_start;
+       __le32 code_end;
+
+       __le32 wep_defkey_start;
+       __le32 wep_defkey_end;
+
+       __le32 sta_table_start;
+       __le32 sta_table_end;
+
+       __le32 packet_template_start;
+       __le32 packet_template_end;
+
+       /* Address of the TX result interface (control block) */
+       __le32 tx_result;
+       __le32 tx_result_queue_start;
+
+       __le32 queue_memory_start;
+       __le32 queue_memory_end;
+
+       __le32 packet_memory_pool_start;
+       __le32 packet_memory_pool_end;
+
+       __le32 debug_buffer1_start;
+       __le32 debug_buffer1_end;
+
+       __le32 debug_buffer2_start;
+       __le32 debug_buffer2_end;
+
+       /* Number of blocks FW allocated for TX packets */
+       __le32 num_tx_mem_blocks;
+
+       /* Number of blocks FW allocated for RX packets */
+       __le32 num_rx_mem_blocks;
+
+       /* the following 4 fields are valid in SLAVE mode only */
+       u8 *tx_cbuf;
+       u8 *rx_cbuf;
+       __le32 rx_ctrl;
+       __le32 tx_ctrl;
+} __packed;
+
+struct wl1271_acx_rx_config_opt {
+       struct acx_header header;
+
+       __le16 mblk_threshold;
+       __le16 threshold;
+       __le16 timeout;
+       u8 queue_type;
+       u8 reserved;
+} __packed;
+
+
+struct wl1271_acx_bet_enable {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 enable;
+       u8 max_consecutive;
+       u8 padding[1];
+} __packed;
+
+#define ACX_IPV4_VERSION 4
+#define ACX_IPV6_VERSION 6
+#define ACX_IPV4_ADDR_SIZE 4
+
+/* bitmap of enabled arp_filter features */
+#define ACX_ARP_FILTER_ARP_FILTERING   BIT(0)
+#define ACX_ARP_FILTER_AUTO_ARP                BIT(1)
+
+struct wl1271_acx_arp_filter {
+       struct acx_header header;
+       u8 role_id;
+       u8 version;         /* ACX_IPV4_VERSION, ACX_IPV6_VERSION */
+       u8 enable;          /* bitmap of enabled ARP filtering features */
+       u8 padding[1];
+       u8 address[16];     /* The configured device IP address - all ARP
+                              requests directed to this IP address will pass
+                              through. For IPv4, the first four bytes are
+                              used. */
+} __packed;
+
+struct wl1271_acx_pm_config {
+       struct acx_header header;
+
+       __le32 host_clk_settling_time;
+       u8 host_fast_wakeup_support;
+       u8 padding[3];
+} __packed;
+
+struct wl1271_acx_keep_alive_mode {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 enabled;
+       u8 padding[2];
+} __packed;
+
+enum {
+       ACX_KEEP_ALIVE_NO_TX = 0,
+       ACX_KEEP_ALIVE_PERIOD_ONLY
+};
+
+enum {
+       ACX_KEEP_ALIVE_TPL_INVALID = 0,
+       ACX_KEEP_ALIVE_TPL_VALID
+};
+
+struct wl1271_acx_keep_alive_config {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 index;
+       u8 tpl_validation;
+       u8 trigger;
+       __le32 period;
+} __packed;
+
+/* TODO: maybe this needs to be moved somewhere else? */
+#define HOST_IF_CFG_RX_FIFO_ENABLE     BIT(0)
+#define HOST_IF_CFG_TX_EXTRA_BLKS_SWAP BIT(1)
+#define HOST_IF_CFG_TX_PAD_TO_SDIO_BLK BIT(3)
+
+enum {
+       WL1271_ACX_TRIG_TYPE_LEVEL = 0,
+       WL1271_ACX_TRIG_TYPE_EDGE,
+};
+
+enum {
+       WL1271_ACX_TRIG_DIR_LOW = 0,
+       WL1271_ACX_TRIG_DIR_HIGH,
+       WL1271_ACX_TRIG_DIR_BIDIR,
+};
+
+enum {
+       WL1271_ACX_TRIG_ENABLE = 1,
+       WL1271_ACX_TRIG_DISABLE,
+};
+
+enum {
+       WL1271_ACX_TRIG_METRIC_RSSI_BEACON = 0,
+       WL1271_ACX_TRIG_METRIC_RSSI_DATA,
+       WL1271_ACX_TRIG_METRIC_SNR_BEACON,
+       WL1271_ACX_TRIG_METRIC_SNR_DATA,
+};
+
+enum {
+       WL1271_ACX_TRIG_IDX_RSSI = 0,
+       WL1271_ACX_TRIG_COUNT = 8,
+};
+
+struct wl1271_acx_rssi_snr_trigger {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 metric;
+       u8 type;
+       u8 dir;
+       __le16 threshold;
+       __le16 pacing; /* 0 - 60000 ms */
+       u8 hysteresis;
+       u8 index;
+       u8 enable;
+       u8 padding[1];
+};
+
+struct wl1271_acx_rssi_snr_avg_weights {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 padding[3];
+       u8 rssi_beacon;
+       u8 rssi_data;
+       u8 snr_beacon;
+       u8 snr_data;
+};
+
+
+/* special capability bit (not employed by the 802.11n spec) */
+#define WL12XX_HT_CAP_HT_OPERATION BIT(16)
+
+/*
+ * ACX_PEER_HT_CAP
+ * Configure HT capabilities - declare the capabilities of the peer
+ * we are connected to.
+ */
+struct wl1271_acx_ht_capabilities {
+       struct acx_header header;
+
+       /* bitmask of capability bits supported by the peer */
+       __le32 ht_capabilites;
+
+       /* Indicates to which link these capabilities apply. */
+       u8 hlid;
+
+       /*
+        * This the maximum A-MPDU length supported by the AP. The FW may not
+        * exceed this length when sending A-MPDUs
+        */
+       u8 ampdu_max_length;
+
+       /* This is the minimal spacing required when sending A-MPDUs to the AP*/
+       u8 ampdu_min_spacing;
+
+       u8 padding;
+} __packed;
+
+/*
+ * ACX_HT_BSS_OPERATION
+ * Configure HT capabilities - AP rules for behavior in the BSS.
+ */
+struct wl1271_acx_ht_information {
+       struct acx_header header;
+
+       u8 role_id;
+
+       /* Values: 0 - RIFS not allowed, 1 - RIFS allowed */
+       u8 rifs_mode;
+
+       /* Values: 0 - 3 like in spec */
+       u8 ht_protection;
+
+       /* Values: 0 - GF protection not required, 1 - GF protection required */
+       u8 gf_protection;
+
+       /*Values: 0 - TX Burst limit not required, 1 - TX Burst Limit required*/
+       u8 ht_tx_burst_limit;
+
+       /*
+        * Values: 0 - Dual CTS protection not required,
+        *         1 - Dual CTS Protection required
+        * Note: When this value is set to 1 FW will protect all TXOP with RTS
+        * frame and will not use CTS-to-self regardless of the value of the
+        * ACX_CTS_PROTECTION information element
+        */
+       u8 dual_cts_protection;
+
+       u8 padding[2];
+} __packed;
+
+#define RX_BA_MAX_SESSIONS 2
+
+struct wl1271_acx_ba_initiator_policy {
+       struct acx_header header;
+
+       /* Specifies role Id, Range 0-7, 0xFF means ANY role. */
+       u8 role_id;
+
+       /*
+        * Per TID setting for allowing TX BA. Set a bit to 1 to allow
+        * TX BA sessions for the corresponding TID.
+        */
+       u8 tid_bitmap;
+
+       /* Windows size in number of packets */
+       u8 win_size;
+
+       u8 padding1[1];
+
+       /* As initiator inactivity timeout in time units(TU) of 1024us */
+       u16 inactivity_timeout;
+
+       u8 padding[2];
+} __packed;
+
+struct wl1271_acx_ba_receiver_setup {
+       struct acx_header header;
+
+       /* Specifies link id, range 0-31 */
+       u8 hlid;
+
+       u8 tid;
+
+       u8 enable;
+
+       /* Windows size in number of packets */
+       u8 win_size;
+
+       /* BA session starting sequence number.  RANGE 0-FFF */
+       u16 ssn;
+
+       u8 padding[2];
+} __packed;
+
+struct wl12xx_acx_fw_tsf_information {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 padding1[3];
+       __le32 current_tsf_high;
+       __le32 current_tsf_low;
+       __le32 last_bttt_high;
+       __le32 last_tbtt_low;
+       u8 last_dtim_count;
+       u8 padding2[3];
+} __packed;
+
+struct wl1271_acx_ps_rx_streaming {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 tid;
+       u8 enable;
+
+       /* interval between triggers (10-100 msec) */
+       u8 period;
+
+       /* timeout before first trigger (0-200 msec) */
+       u8 timeout;
+       u8 padding[3];
+} __packed;
+
+struct wl1271_acx_ap_max_tx_retry {
+       struct acx_header header;
+
+       u8 role_id;
+       u8 padding_1;
+
+       /*
+        * the number of frames transmission failures before
+        * issuing the aging event.
+        */
+       __le16 max_tx_retry;
+} __packed;
+
+struct wl1271_acx_config_ps {
+       struct acx_header header;
+
+       u8 exit_retries;
+       u8 enter_retries;
+       u8 padding[2];
+       __le32 null_data_rate;
+} __packed;
+
+struct wl1271_acx_inconnection_sta {
+       struct acx_header header;
+
+       u8 addr[ETH_ALEN];
+       u8 padding1[2];
+} __packed;
+
+/*
+ * ACX_FM_COEX_CFG
+ * set the FM co-existence parameters.
+ */
+struct wl1271_acx_fm_coex {
+       struct acx_header header;
+       /* enable(1) / disable(0) the FM Coex feature */
+       u8 enable;
+       /*
+        * Swallow period used in COEX PLL swallowing mechanism.
+        * 0xFF = use FW default
+        */
+       u8 swallow_period;
+       /*
+        * The N divider used in COEX PLL swallowing mechanism for Fref of
+        * 38.4/19.2 Mhz. 0xFF = use FW default
+        */
+       u8 n_divider_fref_set_1;
+       /*
+        * The N divider used in COEX PLL swallowing mechanism for Fref of
+        * 26/52 Mhz. 0xFF = use FW default
+        */
+       u8 n_divider_fref_set_2;
+       /*
+        * The M divider used in COEX PLL swallowing mechanism for Fref of
+        * 38.4/19.2 Mhz. 0xFFFF = use FW default
+        */
+       __le16 m_divider_fref_set_1;
+       /*
+        * The M divider used in COEX PLL swallowing mechanism for Fref of
+        * 26/52 Mhz. 0xFFFF = use FW default
+        */
+       __le16 m_divider_fref_set_2;
+       /*
+        * The time duration in uSec required for COEX PLL to stabilize.
+        * 0xFFFFFFFF = use FW default
+        */
+       __le32 coex_pll_stabilization_time;
+       /*
+        * The time duration in uSec required for LDO to stabilize.
+        * 0xFFFFFFFF = use FW default
+        */
+       __le16 ldo_stabilization_time;
+       /*
+        * The disturbed frequency band margin around the disturbed frequency
+        * center (single sided).
+        * For example, if 2 is configured, the following channels will be
+        * considered disturbed channel:
+        *   80 +- 0.1 MHz, 91 +- 0.1 MHz, 98 +- 0.1 MHz, 102 +- 0.1 MH
+        * 0xFF = use FW default
+        */
+       u8 fm_disturbed_band_margin;
+       /*
+        * The swallow clock difference of the swallowing mechanism.
+        * 0xFF = use FW default
+        */
+       u8 swallow_clk_diff;
+} __packed;
+
+#define ACX_RATE_MGMT_ALL_PARAMS 0xff
+struct wl12xx_acx_set_rate_mgmt_params {
+       struct acx_header header;
+
+       u8 index; /* 0xff to configure all params */
+       u8 padding1;
+       __le16 rate_retry_score;
+       __le16 per_add;
+       __le16 per_th1;
+       __le16 per_th2;
+       __le16 max_per;
+       u8 inverse_curiosity_factor;
+       u8 tx_fail_low_th;
+       u8 tx_fail_high_th;
+       u8 per_alpha_shift;
+       u8 per_add_shift;
+       u8 per_beta1_shift;
+       u8 per_beta2_shift;
+       u8 rate_check_up;
+       u8 rate_check_down;
+       u8 rate_retry_policy[ACX_RATE_MGMT_NUM_OF_RATES];
+       u8 padding2[2];
+} __packed;
+
+struct wl12xx_acx_config_hangover {
+       struct acx_header header;
+
+       __le32 recover_time;
+       u8 hangover_period;
+       u8 dynamic_mode;
+       u8 early_termination_mode;
+       u8 max_period;
+       u8 min_period;
+       u8 increase_delta;
+       u8 decrease_delta;
+       u8 quiet_time;
+       u8 increase_time;
+       u8 window_size;
+       u8 padding[2];
+} __packed;
+
+enum {
+       ACX_WAKE_UP_CONDITIONS           = 0x0000,
+       ACX_MEM_CFG                      = 0x0001,
+       ACX_SLOT                         = 0x0002,
+       ACX_AC_CFG                       = 0x0003,
+       ACX_MEM_MAP                      = 0x0004,
+       ACX_AID                          = 0x0005,
+       ACX_MEDIUM_USAGE                 = 0x0006,
+       ACX_STATISTICS                   = 0x0007,
+       ACX_PWR_CONSUMPTION_STATISTICS   = 0x0008,
+       ACX_TID_CFG                      = 0x0009,
+       ACX_PS_RX_STREAMING              = 0x000A,
+       ACX_BEACON_FILTER_OPT            = 0x000B,
+       ACX_NOISE_HIST                   = 0x000C,
+       ACX_HDK_VERSION                  = 0x000D,
+       ACX_PD_THRESHOLD                 = 0x000E,
+       ACX_TX_CONFIG_OPT                = 0x000F,
+       ACX_CCA_THRESHOLD                = 0x0010,
+       ACX_EVENT_MBOX_MASK              = 0x0011,
+       ACX_CONN_MONIT_PARAMS            = 0x0012,
+       ACX_DISABLE_BROADCASTS           = 0x0013,
+       ACX_BCN_DTIM_OPTIONS             = 0x0014,
+       ACX_SG_ENABLE                    = 0x0015,
+       ACX_SG_CFG                       = 0x0016,
+       ACX_FM_COEX_CFG                  = 0x0017,
+       ACX_BEACON_FILTER_TABLE          = 0x0018,
+       ACX_ARP_IP_FILTER                = 0x0019,
+       ACX_ROAMING_STATISTICS_TBL       = 0x001A,
+       ACX_RATE_POLICY                  = 0x001B,
+       ACX_CTS_PROTECTION               = 0x001C,
+       ACX_SLEEP_AUTH                   = 0x001D,
+       ACX_PREAMBLE_TYPE                = 0x001E,
+       ACX_ERROR_CNT                    = 0x001F,
+       ACX_IBSS_FILTER                  = 0x0020,
+       ACX_SERVICE_PERIOD_TIMEOUT       = 0x0021,
+       ACX_TSF_INFO                     = 0x0022,
+       ACX_CONFIG_PS_WMM                = 0x0023,
+       ACX_ENABLE_RX_DATA_FILTER        = 0x0024,
+       ACX_SET_RX_DATA_FILTER           = 0x0025,
+       ACX_GET_DATA_FILTER_STATISTICS   = 0x0026,
+       ACX_RX_CONFIG_OPT                = 0x0027,
+       ACX_FRAG_CFG                     = 0x0028,
+       ACX_BET_ENABLE                   = 0x0029,
+       ACX_RSSI_SNR_TRIGGER             = 0x002A,
+       ACX_RSSI_SNR_WEIGHTS             = 0x002B,
+       ACX_KEEP_ALIVE_MODE              = 0x002C,
+       ACX_SET_KEEP_ALIVE_CONFIG        = 0x002D,
+       ACX_BA_SESSION_INIT_POLICY       = 0x002E,
+       ACX_BA_SESSION_RX_SETUP          = 0x002F,
+       ACX_PEER_HT_CAP                  = 0x0030,
+       ACX_HT_BSS_OPERATION             = 0x0031,
+       ACX_COEX_ACTIVITY                = 0x0032,
+       ACX_BURST_MODE                   = 0x0033,
+       ACX_SET_RATE_MGMT_PARAMS         = 0x0034,
+       ACX_GET_RATE_MGMT_PARAMS         = 0x0035,
+       ACX_SET_RATE_ADAPT_PARAMS        = 0x0036,
+       ACX_SET_DCO_ITRIM_PARAMS         = 0x0037,
+       ACX_GEN_FW_CMD                   = 0x0038,
+       ACX_HOST_IF_CFG_BITMAP           = 0x0039,
+       ACX_MAX_TX_FAILURE               = 0x003A,
+       ACX_UPDATE_INCONNECTION_STA_LIST = 0x003B,
+       DOT11_RX_MSDU_LIFE_TIME          = 0x003C,
+       DOT11_CUR_TX_PWR                 = 0x003D,
+       DOT11_RTS_THRESHOLD              = 0x003E,
+       DOT11_GROUP_ADDRESS_TBL          = 0x003F,
+       ACX_PM_CONFIG                    = 0x0040,
+       ACX_CONFIG_PS                    = 0x0041,
+       ACX_CONFIG_HANGOVER              = 0x0042,
+       ACX_FEATURE_CFG                  = 0x0043,
+       ACX_PROTECTION_CFG               = 0x0044,
+};
+
+
+int wl1271_acx_wake_up_conditions(struct wl1271 *wl,
+                                 struct wl12xx_vif *wlvif,
+                                 u8 wake_up_event, u8 listen_interval);
+int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth);
+int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                       int power);
+int wl1271_acx_feature_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl1271_acx_mem_map(struct wl1271 *wl,
+                      struct acx_header *mem_map, size_t len);
+int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl);
+int wl1271_acx_slot(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                   enum acx_slot_type slot_time);
+int wl1271_acx_group_address_tbl(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                                bool enable, void *mc_list, u32 mc_list_len);
+int wl1271_acx_service_period_timeout(struct wl1271 *wl,
+                                     struct wl12xx_vif *wlvif);
+int wl1271_acx_rts_threshold(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                            u32 rts_threshold);
+int wl1271_acx_dco_itrim_params(struct wl1271 *wl);
+int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                                bool enable_filter);
+int wl1271_acx_beacon_filter_table(struct wl1271 *wl,
+                                  struct wl12xx_vif *wlvif);
+int wl1271_acx_conn_monit_params(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                                bool enable);
+int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable);
+int wl12xx_acx_sg_cfg(struct wl1271 *wl);
+int wl1271_acx_cca_threshold(struct wl1271 *wl);
+int wl1271_acx_bcn_dtim_options(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl1271_acx_aid(struct wl1271 *wl, struct wl12xx_vif *wlvif, u16 aid);
+int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask);
+int wl1271_acx_set_preamble(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                           enum acx_preamble_type preamble);
+int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                          enum acx_ctsprotect_type ctsprotect);
+int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats);
+int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
+                     u8 idx);
+int wl1271_acx_ac_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                     u8 ac, u8 cw_min, u16 cw_max, u8 aifsn, u16 txop);
+int wl1271_acx_tid_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                      u8 queue_id, u8 channel_type,
+                      u8 tsid, u8 ps_scheme, u8 ack_policy,
+                      u32 apsd_conf0, u32 apsd_conf1);
+int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold);
+int wl1271_acx_tx_config_options(struct wl1271 *wl);
+int wl12xx_acx_mem_cfg(struct wl1271 *wl);
+int wl1271_acx_init_mem_config(struct wl1271 *wl);
+int wl1271_acx_init_rx_interrupt(struct wl1271 *wl);
+int wl1271_acx_smart_reflex(struct wl1271 *wl);
+int wl1271_acx_bet_enable(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                         bool enable);
+int wl1271_acx_arp_ip_filter(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                            u8 enable, __be32 address);
+int wl1271_acx_pm_config(struct wl1271 *wl);
+int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *vif,
+                              bool enable);
+int wl1271_acx_keep_alive_config(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                                u8 index, u8 tpl_valid);
+int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                               bool enable, s16 thold, u8 hyst);
+int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl,
+                                   struct wl12xx_vif *wlvif);
+int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
+                                   struct ieee80211_sta_ht_cap *ht_cap,
+                                   bool allow_ht_operation, u8 hlid);
+int wl1271_acx_set_ht_information(struct wl1271 *wl,
+                                  struct wl12xx_vif *wlvif,
+                                  u16 ht_operation_mode);
+int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl,
+                                      struct wl12xx_vif *wlvif);
+int wl12xx_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index,
+                                      u16 ssn, bool enable, u8 peer_hlid);
+int wl12xx_acx_tsf_info(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                       u64 *mactime);
+int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                              bool enable);
+int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl12xx_acx_config_ps(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr);
+int wl1271_acx_fm_coex(struct wl1271 *wl);
+int wl12xx_acx_set_rate_mgmt_params(struct wl1271 *wl);
+int wl12xx_acx_config_hangover(struct wl1271 *wl);
+
+#endif /* __WL1271_ACX_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/boot.c b/drivers/net/wireless/ti/wlcore/boot.c
new file mode 100644 (file)
index 0000000..3a2207d
--- /dev/null
@@ -0,0 +1,443 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2008-2010 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/slab.h>
+#include <linux/wl12xx.h>
+#include <linux/export.h>
+
+#include "debug.h"
+#include "acx.h"
+#include "boot.h"
+#include "io.h"
+#include "event.h"
+#include "rx.h"
+#include "hw_ops.h"
+
+static void wl1271_boot_set_ecpu_ctrl(struct wl1271 *wl, u32 flag)
+{
+       u32 cpu_ctrl;
+
+       /* 10.5.0 run the firmware (I) */
+       cpu_ctrl = wlcore_read_reg(wl, REG_ECPU_CONTROL);
+
+       /* 10.5.1 run the firmware (II) */
+       cpu_ctrl |= flag;
+       wlcore_write_reg(wl, REG_ECPU_CONTROL, cpu_ctrl);
+}
+
+static int wlcore_parse_fw_ver(struct wl1271 *wl)
+{
+       int ret;
+
+       ret = sscanf(wl->chip.fw_ver_str + 4, "%u.%u.%u.%u.%u",
+                    &wl->chip.fw_ver[0], &wl->chip.fw_ver[1],
+                    &wl->chip.fw_ver[2], &wl->chip.fw_ver[3],
+                    &wl->chip.fw_ver[4]);
+
+       if (ret != 5) {
+               wl1271_warning("fw version incorrect value");
+               memset(wl->chip.fw_ver, 0, sizeof(wl->chip.fw_ver));
+               return -EINVAL;
+       }
+
+       ret = wlcore_identify_fw(wl);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static int wlcore_boot_fw_version(struct wl1271 *wl)
+{
+       struct wl1271_static_data *static_data;
+       int ret;
+
+       static_data = kmalloc(sizeof(*static_data), GFP_DMA);
+       if (!static_data) {
+               wl1271_error("Couldn't allocate memory for static data!");
+               return -ENOMEM;
+       }
+
+       wl1271_read(wl, wl->cmd_box_addr, static_data, sizeof(*static_data),
+                   false);
+
+       strncpy(wl->chip.fw_ver_str, static_data->fw_version,
+               sizeof(wl->chip.fw_ver_str));
+
+       kfree(static_data);
+
+       /* make sure the string is NULL-terminated */
+       wl->chip.fw_ver_str[sizeof(wl->chip.fw_ver_str) - 1] = '\0';
+
+       ret = wlcore_parse_fw_ver(wl);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
+                                            size_t fw_data_len, u32 dest)
+{
+       struct wlcore_partition_set partition;
+       int addr, chunk_num, partition_limit;
+       u8 *p, *chunk;
+
+       /* whal_FwCtrl_LoadFwImageSm() */
+
+       wl1271_debug(DEBUG_BOOT, "starting firmware upload");
+
+       wl1271_debug(DEBUG_BOOT, "fw_data_len %zd chunk_size %d",
+                    fw_data_len, CHUNK_SIZE);
+
+       if ((fw_data_len % 4) != 0) {
+               wl1271_error("firmware length not multiple of four");
+               return -EIO;
+       }
+
+       chunk = kmalloc(CHUNK_SIZE, GFP_KERNEL);
+       if (!chunk) {
+               wl1271_error("allocation for firmware upload chunk failed");
+               return -ENOMEM;
+       }
+
+       memcpy(&partition, &wl->ptable[PART_DOWN], sizeof(partition));
+       partition.mem.start = dest;
+       wlcore_set_partition(wl, &partition);
+
+       /* 10.1 set partition limit and chunk num */
+       chunk_num = 0;
+       partition_limit = wl->ptable[PART_DOWN].mem.size;
+
+       while (chunk_num < fw_data_len / CHUNK_SIZE) {
+               /* 10.2 update partition, if needed */
+               addr = dest + (chunk_num + 2) * CHUNK_SIZE;
+               if (addr > partition_limit) {
+                       addr = dest + chunk_num * CHUNK_SIZE;
+                       partition_limit = chunk_num * CHUNK_SIZE +
+                               wl->ptable[PART_DOWN].mem.size;
+                       partition.mem.start = addr;
+                       wlcore_set_partition(wl, &partition);
+               }
+
+               /* 10.3 upload the chunk */
+               addr = dest + chunk_num * CHUNK_SIZE;
+               p = buf + chunk_num * CHUNK_SIZE;
+               memcpy(chunk, p, CHUNK_SIZE);
+               wl1271_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
+                            p, addr);
+               wl1271_write(wl, addr, chunk, CHUNK_SIZE, false);
+
+               chunk_num++;
+       }
+
+       /* 10.4 upload the last chunk */
+       addr = dest + chunk_num * CHUNK_SIZE;
+       p = buf + chunk_num * CHUNK_SIZE;
+       memcpy(chunk, p, fw_data_len % CHUNK_SIZE);
+       wl1271_debug(DEBUG_BOOT, "uploading fw last chunk (%zd B) 0x%p to 0x%x",
+                    fw_data_len % CHUNK_SIZE, p, addr);
+       wl1271_write(wl, addr, chunk, fw_data_len % CHUNK_SIZE, false);
+
+       kfree(chunk);
+       return 0;
+}
+
+int wlcore_boot_upload_firmware(struct wl1271 *wl)
+{
+       u32 chunks, addr, len;
+       int ret = 0;
+       u8 *fw;
+
+       fw = wl->fw;
+       chunks = be32_to_cpup((__be32 *) fw);
+       fw += sizeof(u32);
+
+       wl1271_debug(DEBUG_BOOT, "firmware chunks to be uploaded: %u", chunks);
+
+       while (chunks--) {
+               addr = be32_to_cpup((__be32 *) fw);
+               fw += sizeof(u32);
+               len = be32_to_cpup((__be32 *) fw);
+               fw += sizeof(u32);
+
+               if (len > 300000) {
+                       wl1271_info("firmware chunk too long: %u", len);
+                       return -EINVAL;
+               }
+               wl1271_debug(DEBUG_BOOT, "chunk %d addr 0x%x len %u",
+                            chunks, addr, len);
+               ret = wl1271_boot_upload_firmware_chunk(wl, fw, len, addr);
+               if (ret != 0)
+                       break;
+               fw += len;
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(wlcore_boot_upload_firmware);
+
+int wlcore_boot_upload_nvs(struct wl1271 *wl)
+{
+       size_t nvs_len, burst_len;
+       int i;
+       u32 dest_addr, val;
+       u8 *nvs_ptr, *nvs_aligned;
+
+       if (wl->nvs == NULL)
+               return -ENODEV;
+
+       if (wl->quirks & WLCORE_QUIRK_LEGACY_NVS) {
+               struct wl1271_nvs_file *nvs =
+                       (struct wl1271_nvs_file *)wl->nvs;
+               /*
+                * FIXME: the LEGACY NVS image support (NVS's missing the 5GHz
+                * band configurations) can be removed when those NVS files stop
+                * floating around.
+                */
+               if (wl->nvs_len == sizeof(struct wl1271_nvs_file) ||
+                   wl->nvs_len == WL1271_INI_LEGACY_NVS_FILE_SIZE) {
+                       if (nvs->general_params.dual_mode_select)
+                               wl->enable_11a = true;
+               }
+
+               if (wl->nvs_len != sizeof(struct wl1271_nvs_file) &&
+                   (wl->nvs_len != WL1271_INI_LEGACY_NVS_FILE_SIZE ||
+                    wl->enable_11a)) {
+                       wl1271_error("nvs size is not as expected: %zu != %zu",
+                               wl->nvs_len, sizeof(struct wl1271_nvs_file));
+                       kfree(wl->nvs);
+                       wl->nvs = NULL;
+                       wl->nvs_len = 0;
+                       return -EILSEQ;
+               }
+
+               /* only the first part of the NVS needs to be uploaded */
+               nvs_len = sizeof(nvs->nvs);
+               nvs_ptr = (u8 *) nvs->nvs;
+       } else {
+               struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
+
+               if (wl->nvs_len == sizeof(struct wl128x_nvs_file)) {
+                       if (nvs->general_params.dual_mode_select)
+                               wl->enable_11a = true;
+               } else {
+                       wl1271_error("nvs size is not as expected: %zu != %zu",
+                                    wl->nvs_len,
+                                    sizeof(struct wl128x_nvs_file));
+                       kfree(wl->nvs);
+                       wl->nvs = NULL;
+                       wl->nvs_len = 0;
+                       return -EILSEQ;
+               }
+
+               /* only the first part of the NVS needs to be uploaded */
+               nvs_len = sizeof(nvs->nvs);
+               nvs_ptr = (u8 *)nvs->nvs;
+       }
+
+       /* update current MAC address to NVS */
+       nvs_ptr[11] = wl->addresses[0].addr[0];
+       nvs_ptr[10] = wl->addresses[0].addr[1];
+       nvs_ptr[6] = wl->addresses[0].addr[2];
+       nvs_ptr[5] = wl->addresses[0].addr[3];
+       nvs_ptr[4] = wl->addresses[0].addr[4];
+       nvs_ptr[3] = wl->addresses[0].addr[5];
+
+       /*
+        * Layout before the actual NVS tables:
+        * 1 byte : burst length.
+        * 2 bytes: destination address.
+        * n bytes: data to burst copy.
+        *
+        * This is ended by a 0 length, then the NVS tables.
+        */
+
+       /* FIXME: Do we need to check here whether the LSB is 1? */
+       while (nvs_ptr[0]) {
+               burst_len = nvs_ptr[0];
+               dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
+
+               /*
+                * Due to our new wl1271_translate_reg_addr function,
+                * we need to add the register partition start address
+                * to the destination
+                */
+               dest_addr += wl->curr_part.reg.start;
+
+               /* We move our pointer to the data */
+               nvs_ptr += 3;
+
+               for (i = 0; i < burst_len; i++) {
+                       if (nvs_ptr + 3 >= (u8 *) wl->nvs + nvs_len)
+                               goto out_badnvs;
+
+                       val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
+                              | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
+
+                       wl1271_debug(DEBUG_BOOT,
+                                    "nvs burst write 0x%x: 0x%x",
+                                    dest_addr, val);
+                       wl1271_write32(wl, dest_addr, val);
+
+                       nvs_ptr += 4;
+                       dest_addr += 4;
+               }
+
+               if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
+                       goto out_badnvs;
+       }
+
+       /*
+        * We've reached the first zero length, the first NVS table
+        * is located at an aligned offset which is at least 7 bytes further.
+        * NOTE: The wl->nvs->nvs element must be first, in order to
+        * simplify the casting, we assume it is at the beginning of
+        * the wl->nvs structure.
+        */
+       nvs_ptr = (u8 *)wl->nvs +
+                       ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4);
+
+       if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
+               goto out_badnvs;
+
+       nvs_len -= nvs_ptr - (u8 *)wl->nvs;
+
+       /* Now we must set the partition correctly */
+       wlcore_set_partition(wl, &wl->ptable[PART_WORK]);
+
+       /* Copy the NVS tables to a new block to ensure alignment */
+       nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL);
+       if (!nvs_aligned)
+               return -ENOMEM;
+
+       /* And finally we upload the NVS tables */
+       wlcore_write_data(wl, REG_CMD_MBOX_ADDRESS,
+                         nvs_aligned, nvs_len, false);
+
+       kfree(nvs_aligned);
+       return 0;
+
+out_badnvs:
+       wl1271_error("nvs data is malformed");
+       return -EILSEQ;
+}
+EXPORT_SYMBOL_GPL(wlcore_boot_upload_nvs);
+
+int wlcore_boot_run_firmware(struct wl1271 *wl)
+{
+       int loop, ret;
+       u32 chip_id, intr;
+
+       /* Make sure we have the boot partition */
+       wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
+
+       wl1271_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
+
+       chip_id = wlcore_read_reg(wl, REG_CHIP_ID_B);
+
+       wl1271_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
+
+       if (chip_id != wl->chip.id) {
+               wl1271_error("chip id doesn't match after firmware boot");
+               return -EIO;
+       }
+
+       /* wait for init to complete */
+       loop = 0;
+       while (loop++ < INIT_LOOP) {
+               udelay(INIT_LOOP_DELAY);
+               intr = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR);
+
+               if (intr == 0xffffffff) {
+                       wl1271_error("error reading hardware complete "
+                                    "init indication");
+                       return -EIO;
+               }
+               /* check that ACX_INTR_INIT_COMPLETE is enabled */
+               else if (intr & WL1271_ACX_INTR_INIT_COMPLETE) {
+                       wlcore_write_reg(wl, REG_INTERRUPT_ACK,
+                                        WL1271_ACX_INTR_INIT_COMPLETE);
+                       break;
+               }
+       }
+
+       if (loop > INIT_LOOP) {
+               wl1271_error("timeout waiting for the hardware to "
+                            "complete initialization");
+               return -EIO;
+       }
+
+       /* get hardware config command mail box */
+       wl->cmd_box_addr = wlcore_read_reg(wl, REG_COMMAND_MAILBOX_PTR);
+
+       wl1271_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x", wl->cmd_box_addr);
+
+       /* get hardware config event mail box */
+       wl->mbox_ptr[0] = wlcore_read_reg(wl, REG_EVENT_MAILBOX_PTR);
+       wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
+
+       wl1271_debug(DEBUG_MAILBOX, "MBOX ptrs: 0x%x 0x%x",
+                    wl->mbox_ptr[0], wl->mbox_ptr[1]);
+
+       ret = wlcore_boot_fw_version(wl);
+       if (ret < 0) {
+               wl1271_error("couldn't boot firmware");
+               return ret;
+       }
+
+       /*
+        * in case of full asynchronous mode the firmware event must be
+        * ready to receive event from the command mailbox
+        */
+
+       /* unmask required mbox events  */
+       wl->event_mask = BSS_LOSE_EVENT_ID |
+               SCAN_COMPLETE_EVENT_ID |
+               ROLE_STOP_COMPLETE_EVENT_ID |
+               RSSI_SNR_TRIGGER_0_EVENT_ID |
+               PSPOLL_DELIVERY_FAILURE_EVENT_ID |
+               SOFT_GEMINI_SENSE_EVENT_ID |
+               PERIODIC_SCAN_REPORT_EVENT_ID |
+               PERIODIC_SCAN_COMPLETE_EVENT_ID |
+               DUMMY_PACKET_EVENT_ID |
+               PEER_REMOVE_COMPLETE_EVENT_ID |
+               BA_SESSION_RX_CONSTRAINT_EVENT_ID |
+               REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID |
+               INACTIVE_STA_EVENT_ID |
+               MAX_TX_RETRY_EVENT_ID |
+               CHANNEL_SWITCH_COMPLETE_EVENT_ID;
+
+       ret = wl1271_event_unmask(wl);
+       if (ret < 0) {
+               wl1271_error("EVENT mask setting failed");
+               return ret;
+       }
+
+       /* set the working partition to its "running" mode offset */
+       wlcore_set_partition(wl, &wl->ptable[PART_WORK]);
+
+       /* firmware startup completed */
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wlcore_boot_run_firmware);
diff --git a/drivers/net/wireless/ti/wlcore/boot.h b/drivers/net/wireless/ti/wlcore/boot.h
new file mode 100644 (file)
index 0000000..094981d
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __BOOT_H__
+#define __BOOT_H__
+
+#include "wlcore.h"
+
+int wlcore_boot_upload_firmware(struct wl1271 *wl);
+int wlcore_boot_upload_nvs(struct wl1271 *wl);
+int wlcore_boot_run_firmware(struct wl1271 *wl);
+
+#define WL1271_NO_SUBBANDS 8
+#define WL1271_NO_POWER_LEVELS 4
+#define WL1271_FW_VERSION_MAX_LEN 20
+
+struct wl1271_static_data {
+       u8 mac_address[ETH_ALEN];
+       u8 padding[2];
+       u8 fw_version[WL1271_FW_VERSION_MAX_LEN];
+       u32 hw_version;
+       u8 tx_power_table[WL1271_NO_SUBBANDS][WL1271_NO_POWER_LEVELS];
+};
+
+/* number of times we try to read the INIT interrupt */
+#define INIT_LOOP 20000
+
+/* delay between retries */
+#define INIT_LOOP_DELAY 50
+
+#define WU_COUNTER_PAUSE_VAL 0x3FF
+#define WELP_ARM_COMMAND_VAL 0x4
+
+#endif
diff --git a/drivers/net/wireless/ti/wlcore/cmd.c b/drivers/net/wireless/ti/wlcore/cmd.c
new file mode 100644 (file)
index 0000000..5c4716c
--- /dev/null
@@ -0,0 +1,1728 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2009-2010 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+#include <linux/etherdevice.h>
+#include <linux/ieee80211.h>
+#include <linux/slab.h>
+
+#include "wlcore.h"
+#include "debug.h"
+#include "io.h"
+#include "acx.h"
+#include "wl12xx_80211.h"
+#include "cmd.h"
+#include "event.h"
+#include "tx.h"
+
+#define WL1271_CMD_FAST_POLL_COUNT       50
+
+/*
+ * send command to firmware
+ *
+ * @wl: wl struct
+ * @id: command id
+ * @buf: buffer containing the command, must work with dma
+ * @len: length of the buffer
+ */
+int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
+                   size_t res_len)
+{
+       struct wl1271_cmd_header *cmd;
+       unsigned long timeout;
+       u32 intr;
+       int ret = 0;
+       u16 status;
+       u16 poll_count = 0;
+
+       cmd = buf;
+       cmd->id = cpu_to_le16(id);
+       cmd->status = 0;
+
+       WARN_ON(len % 4 != 0);
+       WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
+
+       wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
+
+       /*
+        * TODO: we just need this because one bit is in a different
+        * place.  Is there any better way?
+        */
+       wl->ops->trigger_cmd(wl, wl->cmd_box_addr, buf, len);
+
+       timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
+
+       intr = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR);
+       while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
+               if (time_after(jiffies, timeout)) {
+                       wl1271_error("command complete timeout");
+                       ret = -ETIMEDOUT;
+                       goto fail;
+               }
+
+               poll_count++;
+               if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
+                       udelay(10);
+               else
+                       msleep(1);
+
+               intr = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR);
+       }
+
+       /* read back the status code of the command */
+       if (res_len == 0)
+               res_len = sizeof(struct wl1271_cmd_header);
+       wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
+
+       status = le16_to_cpu(cmd->status);
+       if (status != CMD_STATUS_SUCCESS) {
+               wl1271_error("command execute failure %d", status);
+               ret = -EIO;
+               goto fail;
+       }
+
+       wlcore_write_reg(wl, REG_INTERRUPT_ACK, WL1271_ACX_INTR_CMD_COMPLETE);
+       return 0;
+
+fail:
+       WARN_ON(1);
+       wl12xx_queue_recovery_work(wl);
+       return ret;
+}
+
+/*
+ * Poll the mailbox event field until any of the bits in the mask is set or a
+ * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
+ */
+static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
+{
+       u32 *events_vector;
+       u32 event;
+       unsigned long timeout;
+       int ret = 0;
+
+       events_vector = kmalloc(sizeof(*events_vector), GFP_DMA);
+
+       timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
+
+       do {
+               if (time_after(jiffies, timeout)) {
+                       wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
+                                    (int)mask);
+                       ret = -ETIMEDOUT;
+                       goto out;
+               }
+
+               msleep(1);
+
+               /* read from both event fields */
+               wl1271_read(wl, wl->mbox_ptr[0], events_vector,
+                           sizeof(*events_vector), false);
+               event = *events_vector & mask;
+               wl1271_read(wl, wl->mbox_ptr[1], events_vector,
+                           sizeof(*events_vector), false);
+               event |= *events_vector & mask;
+       } while (!event);
+
+out:
+       kfree(events_vector);
+       return ret;
+}
+
+static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
+{
+       int ret;
+
+       ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
+       if (ret != 0) {
+               wl12xx_queue_recovery_work(wl);
+               return ret;
+       }
+
+       return 0;
+}
+
+int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
+                          u8 *role_id)
+{
+       struct wl12xx_cmd_role_enable *cmd;
+       int ret;
+
+       wl1271_debug(DEBUG_CMD, "cmd role enable");
+
+       if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID))
+               return -EBUSY;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* get role id */
+       cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES);
+       if (cmd->role_id >= WL12XX_MAX_ROLES) {
+               ret = -EBUSY;
+               goto out_free;
+       }
+
+       memcpy(cmd->mac_address, addr, ETH_ALEN);
+       cmd->role_type = role_type;
+
+       ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to initiate cmd role enable");
+               goto out_free;
+       }
+
+       __set_bit(cmd->role_id, wl->roles_map);
+       *role_id = cmd->role_id;
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id)
+{
+       struct wl12xx_cmd_role_disable *cmd;
+       int ret;
+
+       wl1271_debug(DEBUG_CMD, "cmd role disable");
+
+       if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID))
+               return -ENOENT;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+       cmd->role_id = *role_id;
+
+       ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to initiate cmd role disable");
+               goto out_free;
+       }
+
+       __clear_bit(*role_id, wl->roles_map);
+       *role_id = WL12XX_INVALID_ROLE_ID;
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
+{
+       unsigned long flags;
+       u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
+       if (link >= WL12XX_MAX_LINKS)
+               return -EBUSY;
+
+       /* these bits are used by op_tx */
+       spin_lock_irqsave(&wl->wl_lock, flags);
+       __set_bit(link, wl->links_map);
+       __set_bit(link, wlvif->links_map);
+       spin_unlock_irqrestore(&wl->wl_lock, flags);
+       *hlid = link;
+       return 0;
+}
+
+void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
+{
+       unsigned long flags;
+
+       if (*hlid == WL12XX_INVALID_LINK_ID)
+               return;
+
+       /* these bits are used by op_tx */
+       spin_lock_irqsave(&wl->wl_lock, flags);
+       __clear_bit(*hlid, wl->links_map);
+       __clear_bit(*hlid, wlvif->links_map);
+       spin_unlock_irqrestore(&wl->wl_lock, flags);
+
+       /*
+        * At this point op_tx() will not add more packets to the queues. We
+        * can purge them.
+        */
+       wl1271_tx_reset_link_queues(wl, *hlid);
+
+       *hlid = WL12XX_INVALID_LINK_ID;
+}
+
+static int wl12xx_get_new_session_id(struct wl1271 *wl,
+                                    struct wl12xx_vif *wlvif)
+{
+       if (wlvif->session_counter >= SESSION_COUNTER_MAX)
+               wlvif->session_counter = 0;
+
+       wlvif->session_counter++;
+
+       return wlvif->session_counter;
+}
+
+static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
+                                    struct wl12xx_vif *wlvif)
+{
+       struct wl12xx_cmd_role_start *cmd;
+       int ret;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
+
+       cmd->role_id = wlvif->dev_role_id;
+       if (wlvif->band == IEEE80211_BAND_5GHZ)
+               cmd->band = WLCORE_BAND_5GHZ;
+       cmd->channel = wlvif->channel;
+
+       if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
+               ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
+               if (ret)
+                       goto out_free;
+       }
+       cmd->device.hlid = wlvif->dev_hlid;
+       cmd->device.session = wl12xx_get_new_session_id(wl, wlvif);
+
+       wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
+                    cmd->role_id, cmd->device.hlid, cmd->device.session);
+
+       ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to initiate cmd role enable");
+               goto err_hlid;
+       }
+
+       goto out_free;
+
+err_hlid:
+       /* clear links on error */
+       wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
+                                   struct wl12xx_vif *wlvif)
+{
+       struct wl12xx_cmd_role_stop *cmd;
+       int ret;
+
+       if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
+               return -EINVAL;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wl1271_debug(DEBUG_CMD, "cmd role stop dev");
+
+       cmd->role_id = wlvif->dev_role_id;
+       cmd->disc_type = DISCONNECT_IMMEDIATE;
+       cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
+
+       ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to initiate cmd role stop");
+               goto out_free;
+       }
+
+       ret = wl1271_cmd_wait_for_event(wl, ROLE_STOP_COMPLETE_EVENT_ID);
+       if (ret < 0) {
+               wl1271_error("cmd role stop dev event completion error");
+               goto out_free;
+       }
+
+       wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+       struct wl12xx_cmd_role_start *cmd;
+       int ret;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
+
+       cmd->role_id = wlvif->role_id;
+       if (wlvif->band == IEEE80211_BAND_5GHZ)
+               cmd->band = WLCORE_BAND_5GHZ;
+       cmd->channel = wlvif->channel;
+       cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
+       cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
+       cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
+       cmd->sta.ssid_len = wlvif->ssid_len;
+       memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
+       memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
+       cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
+
+       if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
+               ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
+               if (ret)
+                       goto out_free;
+       }
+       cmd->sta.hlid = wlvif->sta.hlid;
+       cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
+       cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
+
+       wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
+                    "basic_rate_set: 0x%x, remote_rates: 0x%x",
+                    wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
+                    wlvif->basic_rate_set, wlvif->rate_set);
+
+       ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to initiate cmd role start sta");
+               goto err_hlid;
+       }
+
+       goto out_free;
+
+err_hlid:
+       /* clear links on error. */
+       wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+/* use this function to stop ibss as well */
+int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       struct wl12xx_cmd_role_stop *cmd;
+       int ret;
+
+       if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
+               return -EINVAL;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
+
+       cmd->role_id = wlvif->role_id;
+       cmd->disc_type = DISCONNECT_IMMEDIATE;
+       cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
+
+       ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to initiate cmd role stop sta");
+               goto out_free;
+       }
+
+       wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       struct wl12xx_cmd_role_start *cmd;
+       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+       struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
+       int ret;
+
+       wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
+
+       /* trying to use hidden SSID with an old hostapd version */
+       if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
+               wl1271_error("got a null SSID from beacon/bss");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
+       if (ret < 0)
+               goto out_free;
+
+       ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
+       if (ret < 0)
+               goto out_free_global;
+
+       cmd->role_id = wlvif->role_id;
+       cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
+       cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
+       cmd->ap.global_hlid = wlvif->ap.global_hlid;
+       cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
+       cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
+       cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
+       cmd->ap.dtim_interval = bss_conf->dtim_period;
+       cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
+       /* FIXME: Change when adding DFS */
+       cmd->ap.reset_tsf = 1;  /* By default reset AP TSF */
+       cmd->channel = wlvif->channel;
+
+       if (!bss_conf->hidden_ssid) {
+               /* take the SSID from the beacon for backward compatibility */
+               cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
+               cmd->ap.ssid_len = wlvif->ssid_len;
+               memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
+       } else {
+               cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
+               cmd->ap.ssid_len = bss_conf->ssid_len;
+               memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
+       }
+
+       cmd->ap.local_rates = cpu_to_le32(0xffffffff);
+
+       switch (wlvif->band) {
+       case IEEE80211_BAND_2GHZ:
+               cmd->band = WLCORE_BAND_2_4GHZ;
+               break;
+       case IEEE80211_BAND_5GHZ:
+               cmd->band = WLCORE_BAND_5GHZ;
+               break;
+       default:
+               wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
+               cmd->band = WLCORE_BAND_2_4GHZ;
+               break;
+       }
+
+       ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to initiate cmd role start ap");
+               goto out_free_bcast;
+       }
+
+       goto out_free;
+
+out_free_bcast:
+       wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
+
+out_free_global:
+       wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       struct wl12xx_cmd_role_stop *cmd;
+       int ret;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
+
+       cmd->role_id = wlvif->role_id;
+
+       ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to initiate cmd role stop ap");
+               goto out_free;
+       }
+
+       wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
+       wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+       struct wl12xx_cmd_role_start *cmd;
+       struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
+       int ret;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
+
+       cmd->role_id = wlvif->role_id;
+       if (wlvif->band == IEEE80211_BAND_5GHZ)
+               cmd->band = WLCORE_BAND_5GHZ;
+       cmd->channel = wlvif->channel;
+       cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
+       cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
+       cmd->ibss.dtim_interval = bss_conf->dtim_period;
+       cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
+       cmd->ibss.ssid_len = wlvif->ssid_len;
+       memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
+       memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
+       cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
+
+       if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
+               ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
+               if (ret)
+                       goto out_free;
+       }
+       cmd->ibss.hlid = wlvif->sta.hlid;
+       cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
+
+       wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
+                    "basic_rate_set: 0x%x, remote_rates: 0x%x",
+                    wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
+                    wlvif->basic_rate_set, wlvif->rate_set);
+
+       wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
+                    vif->bss_conf.bssid);
+
+       ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to initiate cmd role enable");
+               goto err_hlid;
+       }
+
+       goto out_free;
+
+err_hlid:
+       /* clear links on error. */
+       wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+
+/**
+ * send test command to firmware
+ *
+ * @wl: wl struct
+ * @buf: buffer containing the command, with all headers, must work with dma
+ * @len: length of the buffer
+ * @answer: is answer needed
+ */
+int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
+{
+       int ret;
+       size_t res_len = 0;
+
+       wl1271_debug(DEBUG_CMD, "cmd test");
+
+       if (answer)
+               res_len = buf_len;
+
+       ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
+
+       if (ret < 0) {
+               wl1271_warning("TEST command failed");
+               return ret;
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(wl1271_cmd_test);
+
+/**
+ * read acx from firmware
+ *
+ * @wl: wl struct
+ * @id: acx id
+ * @buf: buffer for the response, including all headers, must work with dma
+ * @len: length of buf
+ */
+int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
+{
+       struct acx_header *acx = buf;
+       int ret;
+
+       wl1271_debug(DEBUG_CMD, "cmd interrogate");
+
+       acx->id = cpu_to_le16(id);
+
+       /* payload length, does not include any headers */
+       acx->len = cpu_to_le16(len - sizeof(*acx));
+
+       ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
+       if (ret < 0)
+               wl1271_error("INTERROGATE command failed");
+
+       return ret;
+}
+
+/**
+ * write acx value to firmware
+ *
+ * @wl: wl struct
+ * @id: acx id
+ * @buf: buffer containing acx, including all headers, must work with dma
+ * @len: length of buf
+ */
+int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
+{
+       struct acx_header *acx = buf;
+       int ret;
+
+       wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
+
+       acx->id = cpu_to_le16(id);
+
+       /* payload length, does not include any headers */
+       acx->len = cpu_to_le16(len - sizeof(*acx));
+
+       ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
+       if (ret < 0) {
+               wl1271_warning("CONFIGURE command NOK");
+               return ret;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wl1271_cmd_configure);
+
+int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
+{
+       struct cmd_enabledisable_path *cmd;
+       int ret;
+       u16 cmd_rx, cmd_tx;
+
+       wl1271_debug(DEBUG_CMD, "cmd data path");
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* the channel here is only used for calibration, so hardcoded to 1 */
+       cmd->channel = 1;
+
+       if (enable) {
+               cmd_rx = CMD_ENABLE_RX;
+               cmd_tx = CMD_ENABLE_TX;
+       } else {
+               cmd_rx = CMD_DISABLE_RX;
+               cmd_tx = CMD_DISABLE_TX;
+       }
+
+       ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("rx %s cmd for channel %d failed",
+                            enable ? "start" : "stop", cmd->channel);
+               goto out;
+       }
+
+       wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
+                    enable ? "start" : "stop", cmd->channel);
+
+       ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("tx %s cmd for channel %d failed",
+                            enable ? "start" : "stop", cmd->channel);
+               goto out;
+       }
+
+       wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
+                    enable ? "start" : "stop", cmd->channel);
+
+out:
+       kfree(cmd);
+       return ret;
+}
+
+int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                      u8 ps_mode, u16 auto_ps_timeout)
+{
+       struct wl1271_cmd_ps_params *ps_params = NULL;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_CMD, "cmd set ps mode");
+
+       ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
+       if (!ps_params) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ps_params->role_id = wlvif->role_id;
+       ps_params->ps_mode = ps_mode;
+       ps_params->auto_ps_timeout = auto_ps_timeout;
+
+       ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
+                             sizeof(*ps_params), 0);
+       if (ret < 0) {
+               wl1271_error("cmd set_ps_mode failed");
+               goto out;
+       }
+
+out:
+       kfree(ps_params);
+       return ret;
+}
+
+int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
+                           u16 template_id, void *buf, size_t buf_len,
+                           int index, u32 rates)
+{
+       struct wl1271_cmd_template_set *cmd;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)",
+                    template_id, role_id);
+
+       WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
+       buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       /* during initialization wlvif is NULL */
+       cmd->role_id = role_id;
+       cmd->len = cpu_to_le16(buf_len);
+       cmd->template_type = template_id;
+       cmd->enabled_rates = cpu_to_le32(rates);
+       cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
+       cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
+       cmd->index = index;
+
+       if (buf)
+               memcpy(cmd->template_data, buf, buf_len);
+
+       ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_warning("cmd set_template failed: %d", ret);
+               goto out_free;
+       }
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       struct sk_buff *skb = NULL;
+       int size;
+       void *ptr;
+       int ret = -ENOMEM;
+
+
+       if (wlvif->bss_type == BSS_TYPE_IBSS) {
+               size = sizeof(struct wl12xx_null_data_template);
+               ptr = NULL;
+       } else {
+               skb = ieee80211_nullfunc_get(wl->hw,
+                                            wl12xx_wlvif_to_vif(wlvif));
+               if (!skb)
+                       goto out;
+               size = skb->len;
+               ptr = skb->data;
+       }
+
+       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
+                                     CMD_TEMPL_NULL_DATA, ptr, size, 0,
+                                     wlvif->basic_rate);
+
+out:
+       dev_kfree_skb(skb);
+       if (ret)
+               wl1271_warning("cmd buld null data failed %d", ret);
+
+       return ret;
+
+}
+
+int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
+                                  struct wl12xx_vif *wlvif)
+{
+       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+       struct sk_buff *skb = NULL;
+       int ret = -ENOMEM;
+
+       skb = ieee80211_nullfunc_get(wl->hw, vif);
+       if (!skb)
+               goto out;
+
+       ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV,
+                                     skb->data, skb->len,
+                                     CMD_TEMPL_KLV_IDX_NULL_DATA,
+                                     wlvif->basic_rate);
+
+out:
+       dev_kfree_skb(skb);
+       if (ret)
+               wl1271_warning("cmd build klv null data failed %d", ret);
+
+       return ret;
+
+}
+
+int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                            u16 aid)
+{
+       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+       struct sk_buff *skb;
+       int ret = 0;
+
+       skb = ieee80211_pspoll_get(wl->hw, vif);
+       if (!skb)
+               goto out;
+
+       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
+                                     CMD_TEMPL_PS_POLL, skb->data,
+                                     skb->len, 0, wlvif->basic_rate_set);
+
+out:
+       dev_kfree_skb(skb);
+       return ret;
+}
+
+int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                              u8 role_id, u8 band,
+                              const u8 *ssid, size_t ssid_len,
+                              const u8 *ie, size_t ie_len)
+{
+       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+       struct sk_buff *skb;
+       int ret;
+       u32 rate;
+
+       skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
+                                    ie, ie_len);
+       if (!skb) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
+
+       rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
+       if (band == IEEE80211_BAND_2GHZ)
+               ret = wl1271_cmd_template_set(wl, role_id,
+                                             CMD_TEMPL_CFG_PROBE_REQ_2_4,
+                                             skb->data, skb->len, 0, rate);
+       else
+               ret = wl1271_cmd_template_set(wl, role_id,
+                                             CMD_TEMPL_CFG_PROBE_REQ_5,
+                                             skb->data, skb->len, 0, rate);
+
+out:
+       dev_kfree_skb(skb);
+       return ret;
+}
+
+struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
+                                             struct wl12xx_vif *wlvif,
+                                             struct sk_buff *skb)
+{
+       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+       int ret;
+       u32 rate;
+
+       if (!skb)
+               skb = ieee80211_ap_probereq_get(wl->hw, vif);
+       if (!skb)
+               goto out;
+
+       wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
+
+       rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
+       if (wlvif->band == IEEE80211_BAND_2GHZ)
+               ret = wl1271_cmd_template_set(wl, wlvif->role_id,
+                                             CMD_TEMPL_CFG_PROBE_REQ_2_4,
+                                             skb->data, skb->len, 0, rate);
+       else
+               ret = wl1271_cmd_template_set(wl, wlvif->role_id,
+                                             CMD_TEMPL_CFG_PROBE_REQ_5,
+                                             skb->data, skb->len, 0, rate);
+
+       if (ret < 0)
+               wl1271_error("Unable to set ap probe request template.");
+
+out:
+       return skb;
+}
+
+int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       int ret, extra;
+       u16 fc;
+       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+       struct sk_buff *skb;
+       struct wl12xx_arp_rsp_template *tmpl;
+       struct ieee80211_hdr_3addr *hdr;
+       struct arphdr *arp_hdr;
+
+       skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) +
+                           WL1271_EXTRA_SPACE_MAX);
+       if (!skb) {
+               wl1271_error("failed to allocate buffer for arp rsp template");
+               return -ENOMEM;
+       }
+
+       skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX);
+
+       tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl));
+       memset(tmpl, 0, sizeof(tmpl));
+
+       /* llc layer */
+       memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header));
+       tmpl->llc_type = cpu_to_be16(ETH_P_ARP);
+
+       /* arp header */
+       arp_hdr = &tmpl->arp_hdr;
+       arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
+       arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
+       arp_hdr->ar_hln = ETH_ALEN;
+       arp_hdr->ar_pln = 4;
+       arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
+
+       /* arp payload */
+       memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN);
+       tmpl->sender_ip = wlvif->ip_addr;
+
+       /* encryption space */
+       switch (wlvif->encryption_type) {
+       case KEY_TKIP:
+               extra = WL1271_EXTRA_SPACE_TKIP;
+               break;
+       case KEY_AES:
+               extra = WL1271_EXTRA_SPACE_AES;
+               break;
+       case KEY_NONE:
+       case KEY_WEP:
+       case KEY_GEM:
+               extra = 0;
+               break;
+       default:
+               wl1271_warning("Unknown encryption type: %d",
+                              wlvif->encryption_type);
+               ret = -EINVAL;
+               goto out;
+       }
+
+       if (extra) {
+               u8 *space = skb_push(skb, extra);
+               memset(space, 0, extra);
+       }
+
+       /* QoS header - BE */
+       if (wlvif->sta.qos)
+               memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16));
+
+       /* mac80211 header */
+       hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr));
+       memset(hdr, 0, sizeof(hdr));
+       fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS;
+       if (wlvif->sta.qos)
+               fc |= IEEE80211_STYPE_QOS_DATA;
+       else
+               fc |= IEEE80211_STYPE_DATA;
+       if (wlvif->encryption_type != KEY_NONE)
+               fc |= IEEE80211_FCTL_PROTECTED;
+
+       hdr->frame_control = cpu_to_le16(fc);
+       memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
+       memcpy(hdr->addr2, vif->addr, ETH_ALEN);
+       memset(hdr->addr3, 0xff, ETH_ALEN);
+
+       ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP,
+                                     skb->data, skb->len, 0,
+                                     wlvif->basic_rate);
+out:
+       dev_kfree_skb(skb);
+       return ret;
+}
+
+int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       struct ieee80211_qos_hdr template;
+
+       memset(&template, 0, sizeof(template));
+
+       memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
+       memcpy(template.addr2, vif->addr, ETH_ALEN);
+       memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
+
+       template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
+                                            IEEE80211_STYPE_QOS_NULLFUNC |
+                                            IEEE80211_FCTL_TODS);
+
+       /* FIXME: not sure what priority to use here */
+       template.qos_ctrl = cpu_to_le16(0);
+
+       return wl1271_cmd_template_set(wl, wlvif->role_id,
+                                      CMD_TEMPL_QOS_NULL_DATA, &template,
+                                      sizeof(template), 0,
+                                      wlvif->basic_rate);
+}
+
+int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
+{
+       struct wl1271_cmd_set_keys *cmd;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       cmd->hlid = hlid;
+       cmd->key_id = id;
+       cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
+       cmd->key_action = cpu_to_le16(KEY_SET_ID);
+       cmd->key_type = KEY_WEP;
+
+       ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_warning("cmd set_default_wep_key failed: %d", ret);
+               goto out;
+       }
+
+out:
+       kfree(cmd);
+
+       return ret;
+}
+
+int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                      u16 action, u8 id, u8 key_type,
+                      u8 key_size, const u8 *key, const u8 *addr,
+                      u32 tx_seq_32, u16 tx_seq_16)
+{
+       struct wl1271_cmd_set_keys *cmd;
+       int ret = 0;
+
+       /* hlid might have already been deleted */
+       if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
+               return 0;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       cmd->hlid = wlvif->sta.hlid;
+
+       if (key_type == KEY_WEP)
+               cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
+       else if (is_broadcast_ether_addr(addr))
+               cmd->lid_key_type = BROADCAST_LID_TYPE;
+       else
+               cmd->lid_key_type = UNICAST_LID_TYPE;
+
+       cmd->key_action = cpu_to_le16(action);
+       cmd->key_size = key_size;
+       cmd->key_type = key_type;
+
+       cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
+       cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
+
+       cmd->key_id = id;
+
+       if (key_type == KEY_TKIP) {
+               /*
+                * We get the key in the following form:
+                * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
+                * but the target is expecting:
+                * TKIP - RX MIC - TX MIC
+                */
+               memcpy(cmd->key, key, 16);
+               memcpy(cmd->key + 16, key + 24, 8);
+               memcpy(cmd->key + 24, key + 16, 8);
+
+       } else {
+               memcpy(cmd->key, key, key_size);
+       }
+
+       wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
+
+       ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_warning("could not set keys");
+       goto out;
+       }
+
+out:
+       kfree(cmd);
+
+       return ret;
+}
+
+/*
+ * TODO: merge with sta/ibss into 1 set_key function.
+ * note there are slight diffs
+ */
+int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                         u16 action, u8 id, u8 key_type,
+                         u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
+                         u16 tx_seq_16)
+{
+       struct wl1271_cmd_set_keys *cmd;
+       int ret = 0;
+       u8 lid_type;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd)
+               return -ENOMEM;
+
+       if (hlid == wlvif->ap.bcast_hlid) {
+               if (key_type == KEY_WEP)
+                       lid_type = WEP_DEFAULT_LID_TYPE;
+               else
+                       lid_type = BROADCAST_LID_TYPE;
+       } else {
+               lid_type = UNICAST_LID_TYPE;
+       }
+
+       wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
+                    " hlid: %d", (int)action, (int)id, (int)lid_type,
+                    (int)key_type, (int)hlid);
+
+       cmd->lid_key_type = lid_type;
+       cmd->hlid = hlid;
+       cmd->key_action = cpu_to_le16(action);
+       cmd->key_size = key_size;
+       cmd->key_type = key_type;
+       cmd->key_id = id;
+       cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
+       cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
+
+       if (key_type == KEY_TKIP) {
+               /*
+                * We get the key in the following form:
+                * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
+                * but the target is expecting:
+                * TKIP - RX MIC - TX MIC
+                */
+               memcpy(cmd->key, key, 16);
+               memcpy(cmd->key + 16, key + 24, 8);
+               memcpy(cmd->key + 24, key + 16, 8);
+       } else {
+               memcpy(cmd->key, key, key_size);
+       }
+
+       wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
+
+       ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_warning("could not set ap keys");
+               goto out;
+       }
+
+out:
+       kfree(cmd);
+       return ret;
+}
+
+int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid)
+{
+       struct wl12xx_cmd_set_peer_state *cmd;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid);
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       cmd->hlid = hlid;
+       cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
+
+       ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to send set peer state command");
+               goto out_free;
+       }
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                       struct ieee80211_sta *sta, u8 hlid)
+{
+       struct wl12xx_cmd_add_peer *cmd;
+       int i, ret;
+       u32 sta_rates;
+
+       wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       memcpy(cmd->addr, sta->addr, ETH_ALEN);
+       cmd->bss_index = WL1271_AP_BSS_INDEX;
+       cmd->aid = sta->aid;
+       cmd->hlid = hlid;
+       cmd->sp_len = sta->max_sp;
+       cmd->wmm = sta->wme ? 1 : 0;
+
+       for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
+               if (sta->wme && (sta->uapsd_queues & BIT(i)))
+                       cmd->psd_type[i] = WL1271_PSD_UPSD_TRIGGER;
+               else
+                       cmd->psd_type[i] = WL1271_PSD_LEGACY;
+
+       sta_rates = sta->supp_rates[wlvif->band];
+       if (sta->ht_cap.ht_supported)
+               sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET;
+
+       cmd->supported_rates =
+               cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
+                                                       wlvif->band));
+
+       wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
+                    cmd->supported_rates, sta->uapsd_queues);
+
+       ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to initiate cmd add peer");
+               goto out_free;
+       }
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
+{
+       struct wl12xx_cmd_remove_peer *cmd;
+       int ret;
+
+       wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       cmd->hlid = hlid;
+       /* We never send a deauth, mac80211 is in charge of this */
+       cmd->reason_opcode = 0;
+       cmd->send_deauth_flag = 0;
+
+       ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to initiate cmd remove peer");
+               goto out_free;
+       }
+
+       /*
+        * We are ok with a timeout here. The event is sometimes not sent
+        * due to a firmware bug.
+        */
+       wl1271_cmd_wait_for_event_or_timeout(wl,
+                                            PEER_REMOVE_COMPLETE_EVENT_ID);
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
+{
+       struct wl12xx_cmd_config_fwlog *cmd;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       cmd->logger_mode = wl->conf.fwlog.mode;
+       cmd->log_severity = wl->conf.fwlog.severity;
+       cmd->timestamp = wl->conf.fwlog.timestamp;
+       cmd->output = wl->conf.fwlog.output;
+       cmd->threshold = wl->conf.fwlog.threshold;
+
+       ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to send config firmware logger command");
+               goto out_free;
+       }
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
+{
+       struct wl12xx_cmd_start_fwlog *cmd;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to send start firmware logger command");
+               goto out_free;
+       }
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
+{
+       struct wl12xx_cmd_stop_fwlog *cmd;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to send stop firmware logger command");
+               goto out_free;
+       }
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                         u8 role_id)
+{
+       struct wl12xx_cmd_roc *cmd;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
+
+       if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
+               return -EINVAL;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       cmd->role_id = role_id;
+       cmd->channel = wlvif->channel;
+       switch (wlvif->band) {
+       case IEEE80211_BAND_2GHZ:
+               cmd->band = WLCORE_BAND_2_4GHZ;
+               break;
+       case IEEE80211_BAND_5GHZ:
+               cmd->band = WLCORE_BAND_5GHZ;
+               break;
+       default:
+               wl1271_error("roc - unknown band: %d", (int)wlvif->band);
+               ret = -EINVAL;
+               goto out_free;
+       }
+
+
+       ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to send ROC command");
+               goto out_free;
+       }
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
+{
+       struct wl12xx_cmd_croc *cmd;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+       cmd->role_id = role_id;
+
+       ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
+                             sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to send ROC command");
+               goto out_free;
+       }
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
+{
+       int ret = 0;
+
+       if (WARN_ON(test_bit(role_id, wl->roc_map)))
+               return 0;
+
+       ret = wl12xx_cmd_roc(wl, wlvif, role_id);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_cmd_wait_for_event(wl,
+                                       REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
+       if (ret < 0) {
+               wl1271_error("cmd roc event completion error");
+               goto out;
+       }
+
+       __set_bit(role_id, wl->roc_map);
+out:
+       return ret;
+}
+
+int wl12xx_croc(struct wl1271 *wl, u8 role_id)
+{
+       int ret = 0;
+
+       if (WARN_ON(!test_bit(role_id, wl->roc_map)))
+               return 0;
+
+       ret = wl12xx_cmd_croc(wl, role_id);
+       if (ret < 0)
+               goto out;
+
+       __clear_bit(role_id, wl->roc_map);
+
+       /*
+        * Rearm the tx watchdog when removing the last ROC. This prevents
+        * recoveries due to just finished ROCs - when Tx hasn't yet had
+        * a chance to get out.
+        */
+       if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES)
+               wl12xx_rearm_tx_watchdog_locked(wl);
+out:
+       return ret;
+}
+
+int wl12xx_cmd_channel_switch(struct wl1271 *wl,
+                             struct wl12xx_vif *wlvif,
+                             struct ieee80211_channel_switch *ch_switch)
+{
+       struct wl12xx_cmd_channel_switch *cmd;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "cmd channel switch");
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       cmd->role_id = wlvif->role_id;
+       cmd->channel = ch_switch->channel->hw_value;
+       cmd->switch_time = ch_switch->count;
+       cmd->stop_tx = ch_switch->block_tx;
+
+       /* FIXME: control from mac80211 in the future */
+       cmd->post_switch_tx_disable = 0;  /* Enable TX on the target channel */
+
+       ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to send channel switch command");
+               goto out_free;
+       }
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl)
+{
+       struct wl12xx_cmd_stop_channel_switch *cmd;
+       int ret;
+
+       wl1271_debug(DEBUG_ACX, "cmd stop channel switch");
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("failed to stop channel switch command");
+               goto out_free;
+       }
+
+out_free:
+       kfree(cmd);
+
+out:
+       return ret;
+}
+
+/* start dev role and roc on its channel */
+int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       int ret;
+
+       if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
+                     wlvif->bss_type == BSS_TYPE_IBSS)))
+               return -EINVAL;
+
+       ret = wl12xx_cmd_role_start_dev(wl, wlvif);
+       if (ret < 0)
+               goto out;
+
+       ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id);
+       if (ret < 0)
+               goto out_stop;
+
+       return 0;
+
+out_stop:
+       wl12xx_cmd_role_stop_dev(wl, wlvif);
+out:
+       return ret;
+}
+
+/* croc dev hlid, and stop the role */
+int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       int ret;
+
+       if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
+                     wlvif->bss_type == BSS_TYPE_IBSS)))
+               return -EINVAL;
+
+       /* flush all pending packets */
+       wl1271_tx_work_locked(wl);
+
+       if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
+               ret = wl12xx_croc(wl, wlvif->dev_role_id);
+               if (ret < 0)
+                       goto out;
+       }
+
+       ret = wl12xx_cmd_role_stop_dev(wl, wlvif);
+       if (ret < 0)
+               goto out;
+out:
+       return ret;
+}
diff --git a/drivers/net/wireless/ti/wlcore/cmd.h b/drivers/net/wireless/ti/wlcore/cmd.h
new file mode 100644 (file)
index 0000000..a46ae07
--- /dev/null
@@ -0,0 +1,646 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __CMD_H__
+#define __CMD_H__
+
+#include "wlcore.h"
+
+struct acx_header;
+
+int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
+                   size_t res_len);
+int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
+                          u8 *role_id);
+int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id);
+int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer);
+int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len);
+int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len);
+int wl1271_cmd_data_path(struct wl1271 *wl, bool enable);
+int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                      u8 ps_mode, u16 auto_ps_timeout);
+int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
+                          size_t len);
+int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
+                           u16 template_id, void *buf, size_t buf_len,
+                           int index, u32 rates);
+int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                            u16 aid);
+int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                              u8 role_id, u8 band,
+                              const u8 *ssid, size_t ssid_len,
+                              const u8 *ie, size_t ie_len);
+struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
+                                             struct wl12xx_vif *wlvif,
+                                             struct sk_buff *skb);
+int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif);
+int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
+                                  struct wl12xx_vif *wlvif);
+int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid);
+int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                          u16 action, u8 id, u8 key_type,
+                          u8 key_size, const u8 *key, const u8 *addr,
+                          u32 tx_seq_32, u16 tx_seq_16);
+int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                         u16 action, u8 id, u8 key_type,
+                         u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
+                         u16 tx_seq_16);
+int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid);
+int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id);
+int wl12xx_croc(struct wl1271 *wl, u8 role_id);
+int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                       struct ieee80211_sta *sta, u8 hlid);
+int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid);
+int wl12xx_cmd_config_fwlog(struct wl1271 *wl);
+int wl12xx_cmd_start_fwlog(struct wl1271 *wl);
+int wl12xx_cmd_stop_fwlog(struct wl1271 *wl);
+int wl12xx_cmd_channel_switch(struct wl1271 *wl,
+                             struct wl12xx_vif *wlvif,
+                             struct ieee80211_channel_switch *ch_switch);
+int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl);
+int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                        u8 *hlid);
+void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid);
+
+enum wl1271_commands {
+       CMD_INTERROGATE = 1, /* use this to read information elements */
+       CMD_CONFIGURE   = 2, /* use this to write information elements */
+       CMD_ENABLE_RX   = 3,
+       CMD_ENABLE_TX   = 4,
+       CMD_DISABLE_RX  = 5,
+       CMD_DISABLE_TX  = 6,
+       CMD_SCAN        = 7,
+       CMD_STOP_SCAN   = 8,
+       CMD_SET_KEYS    = 9,
+       CMD_READ_MEMORY = 10,
+       CMD_WRITE_MEMORY        = 11,
+       CMD_SET_TEMPLATE        = 12,
+       CMD_TEST                = 13,
+       CMD_NOISE_HIST          = 14,
+       CMD_QUIET_ELEMENT_SET_STATE = 15,
+       CMD_SET_BCN_MODE        = 16,
+
+       CMD_MEASUREMENT         = 17,
+       CMD_STOP_MEASUREMENT    = 18,
+       CMD_SET_PS_MODE         = 19,
+       CMD_CHANNEL_SWITCH      = 20,
+       CMD_STOP_CHANNEL_SWICTH = 21,
+       CMD_AP_DISCOVERY        = 22,
+       CMD_STOP_AP_DISCOVERY   = 23,
+       CMD_HEALTH_CHECK        = 24,
+       CMD_DEBUG               = 25,
+       CMD_TRIGGER_SCAN_TO     = 26,
+       CMD_CONNECTION_SCAN_CFG = 27,
+       CMD_CONNECTION_SCAN_SSID_CFG    = 28,
+       CMD_START_PERIODIC_SCAN = 29,
+       CMD_STOP_PERIODIC_SCAN  = 30,
+       CMD_SET_PEER_STATE      = 31,
+       CMD_REMAIN_ON_CHANNEL   = 32,
+       CMD_CANCEL_REMAIN_ON_CHANNEL    = 33,
+       CMD_CONFIG_FWLOGGER             = 34,
+       CMD_START_FWLOGGER                      = 35,
+       CMD_STOP_FWLOGGER                       = 36,
+
+       /* Access point commands */
+       CMD_ADD_PEER            = 37,
+       CMD_REMOVE_PEER         = 38,
+
+       /* Role API */
+       CMD_ROLE_ENABLE         = 39,
+       CMD_ROLE_DISABLE        = 40,
+       CMD_ROLE_START          = 41,
+       CMD_ROLE_STOP           = 42,
+
+       /* DFS */
+       CMD_START_RADAR_DETECTION       = 43,
+       CMD_STOP_RADAR_DETECTION        = 44,
+
+       /* WIFI Direct */
+       CMD_WFD_START_DISCOVERY = 45,
+       CMD_WFD_STOP_DISCOVERY  = 46,
+       CMD_WFD_ATTRIBUTE_CONFIG        = 47,
+       CMD_NOP                 = 48,
+       CMD_LAST_COMMAND,
+
+       MAX_COMMAND_ID = 0xFFFF,
+};
+
+#define MAX_CMD_PARAMS 572
+
+enum {
+       CMD_TEMPL_KLV_IDX_NULL_DATA = 0,
+       CMD_TEMPL_KLV_IDX_MAX = 4
+};
+
+enum cmd_templ {
+       CMD_TEMPL_NULL_DATA = 0,
+       CMD_TEMPL_BEACON,
+       CMD_TEMPL_CFG_PROBE_REQ_2_4,
+       CMD_TEMPL_CFG_PROBE_REQ_5,
+       CMD_TEMPL_PROBE_RESPONSE,
+       CMD_TEMPL_QOS_NULL_DATA,
+       CMD_TEMPL_PS_POLL,
+       CMD_TEMPL_KLV,
+       CMD_TEMPL_DISCONNECT,
+       CMD_TEMPL_PROBE_REQ_2_4, /* for firmware internal use only */
+       CMD_TEMPL_PROBE_REQ_5,   /* for firmware internal use only */
+       CMD_TEMPL_BAR,           /* for firmware internal use only */
+       CMD_TEMPL_CTS,           /*
+                                 * For CTS-to-self (FastCTS) mechanism
+                                 * for BT/WLAN coexistence (SoftGemini). */
+       CMD_TEMPL_AP_BEACON,
+       CMD_TEMPL_AP_PROBE_RESPONSE,
+       CMD_TEMPL_ARP_RSP,
+       CMD_TEMPL_DEAUTH_AP,
+       CMD_TEMPL_TEMPORARY,
+       CMD_TEMPL_LINK_MEASUREMENT_REPORT,
+
+       CMD_TEMPL_MAX = 0xff
+};
+
+/* unit ms */
+#define WL1271_COMMAND_TIMEOUT     2000
+#define WL1271_CMD_TEMPL_DFLT_SIZE 252
+#define WL1271_CMD_TEMPL_MAX_SIZE  512
+#define WL1271_EVENT_TIMEOUT       750
+
+struct wl1271_cmd_header {
+       __le16 id;
+       __le16 status;
+       /* payload */
+       u8 data[0];
+} __packed;
+
+#define WL1271_CMD_MAX_PARAMS 572
+
+struct wl1271_command {
+       struct wl1271_cmd_header header;
+       u8  parameters[WL1271_CMD_MAX_PARAMS];
+} __packed;
+
+enum {
+       CMD_MAILBOX_IDLE                =  0,
+       CMD_STATUS_SUCCESS              =  1,
+       CMD_STATUS_UNKNOWN_CMD          =  2,
+       CMD_STATUS_UNKNOWN_IE           =  3,
+       CMD_STATUS_REJECT_MEAS_SG_ACTIVE        = 11,
+       CMD_STATUS_RX_BUSY              = 13,
+       CMD_STATUS_INVALID_PARAM                = 14,
+       CMD_STATUS_TEMPLATE_TOO_LARGE           = 15,
+       CMD_STATUS_OUT_OF_MEMORY                = 16,
+       CMD_STATUS_STA_TABLE_FULL               = 17,
+       CMD_STATUS_RADIO_ERROR          = 18,
+       CMD_STATUS_WRONG_NESTING                = 19,
+       CMD_STATUS_TIMEOUT              = 21, /* Driver internal use.*/
+       CMD_STATUS_FW_RESET             = 22, /* Driver internal use.*/
+       CMD_STATUS_TEMPLATE_OOM         = 23,
+       CMD_STATUS_NO_RX_BA_SESSION     = 24,
+       MAX_COMMAND_STATUS              = 0xff
+};
+
+#define CMDMBOX_HEADER_LEN 4
+#define CMDMBOX_INFO_ELEM_HEADER_LEN 4
+
+enum {
+       BSS_TYPE_IBSS = 0,
+       BSS_TYPE_STA_BSS = 2,
+       BSS_TYPE_AP_BSS = 3,
+       MAX_BSS_TYPE = 0xFF
+};
+
+#define WL1271_JOIN_CMD_CTRL_TX_FLUSH     0x80 /* Firmware flushes all Tx */
+#define WL1271_JOIN_CMD_TX_SESSION_OFFSET 1
+#define WL1271_JOIN_CMD_BSS_TYPE_5GHZ 0x10
+
+struct wl12xx_cmd_role_enable {
+       struct wl1271_cmd_header header;
+
+       u8 role_id;
+       u8 role_type;
+       u8 mac_address[ETH_ALEN];
+} __packed;
+
+struct wl12xx_cmd_role_disable {
+       struct wl1271_cmd_header header;
+
+       u8 role_id;
+       u8 padding[3];
+} __packed;
+
+enum wlcore_band {
+       WLCORE_BAND_2_4GHZ              = 0,
+       WLCORE_BAND_5GHZ                = 1,
+       WLCORE_BAND_JAPAN_4_9_GHZ       = 2,
+       WLCORE_BAND_DEFAULT             = WLCORE_BAND_2_4GHZ,
+       WLCORE_BAND_INVALID             = 0x7E,
+       WLCORE_BAND_MAX_RADIO           = 0x7F,
+};
+
+struct wl12xx_cmd_role_start {
+       struct wl1271_cmd_header header;
+
+       u8 role_id;
+       u8 band;
+       u8 channel;
+       u8 padding;
+
+       union {
+               struct {
+                       u8 hlid;
+                       u8 session;
+                       u8 padding_1[54];
+               } __packed device;
+               /* sta & p2p_cli use the same struct */
+               struct {
+                       u8 bssid[ETH_ALEN];
+                       u8 hlid; /* data hlid */
+                       u8 session;
+                       __le32 remote_rates; /* remote supported rates */
+
+                       /*
+                        * The target uses this field to determine the rate at
+                        * which to transmit control frame responses (such as
+                        * ACK or CTS frames).
+                        */
+                       __le32 basic_rate_set;
+                       __le32 local_rates; /* local supported rates */
+
+                       u8 ssid_type;
+                       u8 ssid_len;
+                       u8 ssid[IEEE80211_MAX_SSID_LEN];
+
+                       __le16 beacon_interval; /* in TBTTs */
+               } __packed sta;
+               struct {
+                       u8 bssid[ETH_ALEN];
+                       u8 hlid; /* data hlid */
+                       u8 dtim_interval;
+                       __le32 remote_rates; /* remote supported rates */
+
+                       __le32 basic_rate_set;
+                       __le32 local_rates; /* local supported rates */
+
+                       u8 ssid_type;
+                       u8 ssid_len;
+                       u8 ssid[IEEE80211_MAX_SSID_LEN];
+
+                       __le16 beacon_interval; /* in TBTTs */
+
+                       u8 padding_1[4];
+               } __packed ibss;
+               /* ap & p2p_go use the same struct */
+               struct {
+                       __le16 aging_period; /* in secs */
+                       u8 beacon_expiry; /* in ms */
+                       u8 bss_index;
+                       /* The host link id for the AP's global queue */
+                       u8 global_hlid;
+                       /* The host link id for the AP's broadcast queue */
+                       u8 broadcast_hlid;
+
+                       __le16 beacon_interval; /* in TBTTs */
+
+                       __le32 basic_rate_set;
+                       __le32 local_rates; /* local supported rates */
+
+                       u8 dtim_interval;
+
+                       u8 ssid_type;
+                       u8 ssid_len;
+                       u8 ssid[IEEE80211_MAX_SSID_LEN];
+
+                       u8 reset_tsf;
+
+                       u8 padding_1[4];
+               } __packed ap;
+       };
+} __packed;
+
+struct wl12xx_cmd_role_stop {
+       struct wl1271_cmd_header header;
+
+       u8 role_id;
+       u8 disc_type; /* only STA and P2P_CLI */
+       __le16 reason; /* only STA and P2P_CLI */
+} __packed;
+
+struct cmd_enabledisable_path {
+       struct wl1271_cmd_header header;
+
+       u8 channel;
+       u8 padding[3];
+} __packed;
+
+#define WL1271_RATE_AUTOMATIC  0
+
+struct wl1271_cmd_template_set {
+       struct wl1271_cmd_header header;
+
+       u8 role_id;
+       u8 template_type;
+       __le16 len;
+       u8 index;  /* relevant only for KLV_TEMPLATE type */
+       u8 padding[3];
+
+       __le32 enabled_rates;
+       u8 short_retry_limit;
+       u8 long_retry_limit;
+       u8 aflags;
+       u8 reserved;
+
+       u8 template_data[WL1271_CMD_TEMPL_MAX_SIZE];
+} __packed;
+
+#define TIM_ELE_ID    5
+#define PARTIAL_VBM_MAX    251
+
+struct wl1271_tim {
+       u8 identity;
+       u8 length;
+       u8 dtim_count;
+       u8 dtim_period;
+       u8 bitmap_ctrl;
+       u8 pvb_field[PARTIAL_VBM_MAX]; /* Partial Virtual Bitmap */
+} __packed;
+
+enum wl1271_cmd_ps_mode {
+       STATION_AUTO_PS_MODE,   /* Dynamic Power Save */
+       STATION_ACTIVE_MODE,
+       STATION_POWER_SAVE_MODE
+};
+
+struct wl1271_cmd_ps_params {
+       struct wl1271_cmd_header header;
+
+       u8 role_id;
+       u8 ps_mode; /* STATION_* */
+       u16 auto_ps_timeout;
+} __packed;
+
+/* HW encryption keys */
+#define NUM_ACCESS_CATEGORIES_COPY 4
+
+enum wl1271_cmd_key_action {
+       KEY_ADD_OR_REPLACE = 1,
+       KEY_REMOVE         = 2,
+       KEY_SET_ID         = 3,
+       MAX_KEY_ACTION     = 0xffff,
+};
+
+enum wl1271_cmd_lid_key_type {
+       UNICAST_LID_TYPE     = 0,
+       BROADCAST_LID_TYPE   = 1,
+       WEP_DEFAULT_LID_TYPE = 2
+};
+
+enum wl1271_cmd_key_type {
+       KEY_NONE = 0,
+       KEY_WEP  = 1,
+       KEY_TKIP = 2,
+       KEY_AES  = 3,
+       KEY_GEM  = 4,
+};
+
+struct wl1271_cmd_set_keys {
+       struct wl1271_cmd_header header;
+
+       /*
+        * Indicates whether the HLID is a unicast key set
+        * or broadcast key set. A special value 0xFF is
+        * used to indicate that the HLID is on WEP-default
+        * (multi-hlids). of type wl1271_cmd_lid_key_type.
+        */
+       u8 hlid;
+
+       /*
+        * In WEP-default network (hlid == 0xFF) used to
+        * indicate which network STA/IBSS/AP role should be
+        * changed
+        */
+       u8 lid_key_type;
+
+       /*
+        * Key ID - For TKIP and AES key types, this field
+        * indicates the value that should be inserted into
+        * the KeyID field of frames transmitted using this
+        * key entry. For broadcast keys the index use as a
+        * marker for TX/RX key.
+        * For WEP default network (HLID=0xFF), this field
+        * indicates the ID of the key to add or remove.
+        */
+       u8 key_id;
+       u8 reserved_1;
+
+       /* key_action_e */
+       __le16 key_action;
+
+       /* key size in bytes */
+       u8 key_size;
+
+       /* key_type_e */
+       u8 key_type;
+
+       /* This field holds the security key data to add to the STA table */
+       u8 key[MAX_KEY_SIZE];
+       __le16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY];
+       __le32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY];
+} __packed;
+
+struct wl1271_cmd_test_header {
+       u8 id;
+       u8 padding[3];
+} __packed;
+
+enum wl1271_channel_tune_bands {
+       WL1271_CHANNEL_TUNE_BAND_2_4,
+       WL1271_CHANNEL_TUNE_BAND_5,
+       WL1271_CHANNEL_TUNE_BAND_4_9
+};
+
+#define WL1271_PD_REFERENCE_POINT_BAND_B_G  0
+
+/*
+ * There are three types of disconnections:
+ *
+ * DISCONNECT_IMMEDIATE: the fw doesn't send any frames
+ * DISCONNECT_DEAUTH:    the fw generates a DEAUTH request with the reason
+ *                       we have passed
+ * DISCONNECT_DISASSOC:  the fw generates a DESASSOC request with the reason
+ *                       we have passed
+ */
+enum wl1271_disconnect_type {
+       DISCONNECT_IMMEDIATE,
+       DISCONNECT_DEAUTH,
+       DISCONNECT_DISASSOC
+};
+
+#define WL1271_CMD_STA_STATE_CONNECTED  1
+
+struct wl12xx_cmd_set_peer_state {
+       struct wl1271_cmd_header header;
+
+       u8 hlid;
+       u8 state;
+       u8 padding[2];
+} __packed;
+
+struct wl12xx_cmd_roc {
+       struct wl1271_cmd_header header;
+
+       u8 role_id;
+       u8 channel;
+       u8 band;
+       u8 padding;
+};
+
+struct wl12xx_cmd_croc {
+       struct wl1271_cmd_header header;
+
+       u8 role_id;
+       u8 padding[3];
+};
+
+enum wl12xx_ssid_type {
+       WL12XX_SSID_TYPE_PUBLIC = 0,
+       WL12XX_SSID_TYPE_HIDDEN = 1,
+       WL12XX_SSID_TYPE_ANY = 2,
+};
+
+enum wl1271_psd_type {
+       WL1271_PSD_LEGACY = 0,
+       WL1271_PSD_UPSD_TRIGGER = 1,
+       WL1271_PSD_LEGACY_PSPOLL = 2,
+       WL1271_PSD_SAPSD = 3
+};
+
+struct wl12xx_cmd_add_peer {
+       struct wl1271_cmd_header header;
+
+       u8 addr[ETH_ALEN];
+       u8 hlid;
+       u8 aid;
+       u8 psd_type[NUM_ACCESS_CATEGORIES_COPY];
+       __le32 supported_rates;
+       u8 bss_index;
+       u8 sp_len;
+       u8 wmm;
+       u8 padding1;
+} __packed;
+
+struct wl12xx_cmd_remove_peer {
+       struct wl1271_cmd_header header;
+
+       u8 hlid;
+       u8 reason_opcode;
+       u8 send_deauth_flag;
+       u8 padding1;
+} __packed;
+
+/*
+ * Continuous mode - packets are transferred to the host periodically
+ * via the data path.
+ * On demand - Log messages are stored in a cyclic buffer in the
+ * firmware, and only transferred to the host when explicitly requested
+ */
+enum wl12xx_fwlogger_log_mode {
+       WL12XX_FWLOG_CONTINUOUS,
+       WL12XX_FWLOG_ON_DEMAND
+};
+
+/* Include/exclude timestamps from the log messages */
+enum wl12xx_fwlogger_timestamp {
+       WL12XX_FWLOG_TIMESTAMP_DISABLED,
+       WL12XX_FWLOG_TIMESTAMP_ENABLED
+};
+
+/*
+ * Logs can be routed to the debug pinouts (where available), to the host bus
+ * (SDIO/SPI), or dropped
+ */
+enum wl12xx_fwlogger_output {
+       WL12XX_FWLOG_OUTPUT_NONE,
+       WL12XX_FWLOG_OUTPUT_DBG_PINS,
+       WL12XX_FWLOG_OUTPUT_HOST,
+};
+
+struct wl12xx_cmd_config_fwlog {
+       struct wl1271_cmd_header header;
+
+       /* See enum wl12xx_fwlogger_log_mode */
+       u8 logger_mode;
+
+       /* Minimum log level threshold */
+       u8 log_severity;
+
+       /* Include/exclude timestamps from the log messages */
+       u8 timestamp;
+
+       /* See enum wl1271_fwlogger_output */
+       u8 output;
+
+       /* Regulates the frequency of log messages */
+       u8 threshold;
+
+       u8 padding[3];
+} __packed;
+
+struct wl12xx_cmd_start_fwlog {
+       struct wl1271_cmd_header header;
+} __packed;
+
+struct wl12xx_cmd_stop_fwlog {
+       struct wl1271_cmd_header header;
+} __packed;
+
+struct wl12xx_cmd_channel_switch {
+       struct wl1271_cmd_header header;
+
+       u8 role_id;
+
+       /* The new serving channel */
+       u8 channel;
+       /* Relative time of the serving channel switch in TBTT units */
+       u8 switch_time;
+       /* Stop the role TX, should expect it after radar detection */
+       u8 stop_tx;
+       /* The target channel tx status 1-stopped 0-open*/
+       u8 post_switch_tx_disable;
+
+       u8 padding[3];
+} __packed;
+
+struct wl12xx_cmd_stop_channel_switch {
+       struct wl1271_cmd_header header;
+} __packed;
+
+#endif /* __WL1271_CMD_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/conf.h b/drivers/net/wireless/ti/wlcore/conf.h
new file mode 100644 (file)
index 0000000..fef0db4
--- /dev/null
@@ -0,0 +1,1274 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __CONF_H__
+#define __CONF_H__
+
+enum {
+       CONF_HW_BIT_RATE_1MBPS   = BIT(0),
+       CONF_HW_BIT_RATE_2MBPS   = BIT(1),
+       CONF_HW_BIT_RATE_5_5MBPS = BIT(2),
+       CONF_HW_BIT_RATE_6MBPS   = BIT(3),
+       CONF_HW_BIT_RATE_9MBPS   = BIT(4),
+       CONF_HW_BIT_RATE_11MBPS  = BIT(5),
+       CONF_HW_BIT_RATE_12MBPS  = BIT(6),
+       CONF_HW_BIT_RATE_18MBPS  = BIT(7),
+       CONF_HW_BIT_RATE_22MBPS  = BIT(8),
+       CONF_HW_BIT_RATE_24MBPS  = BIT(9),
+       CONF_HW_BIT_RATE_36MBPS  = BIT(10),
+       CONF_HW_BIT_RATE_48MBPS  = BIT(11),
+       CONF_HW_BIT_RATE_54MBPS  = BIT(12),
+       CONF_HW_BIT_RATE_MCS_0   = BIT(13),
+       CONF_HW_BIT_RATE_MCS_1   = BIT(14),
+       CONF_HW_BIT_RATE_MCS_2   = BIT(15),
+       CONF_HW_BIT_RATE_MCS_3   = BIT(16),
+       CONF_HW_BIT_RATE_MCS_4   = BIT(17),
+       CONF_HW_BIT_RATE_MCS_5   = BIT(18),
+       CONF_HW_BIT_RATE_MCS_6   = BIT(19),
+       CONF_HW_BIT_RATE_MCS_7   = BIT(20)
+};
+
+enum {
+       CONF_HW_RATE_INDEX_1MBPS   = 0,
+       CONF_HW_RATE_INDEX_2MBPS   = 1,
+       CONF_HW_RATE_INDEX_5_5MBPS = 2,
+       CONF_HW_RATE_INDEX_6MBPS   = 3,
+       CONF_HW_RATE_INDEX_9MBPS   = 4,
+       CONF_HW_RATE_INDEX_11MBPS  = 5,
+       CONF_HW_RATE_INDEX_12MBPS  = 6,
+       CONF_HW_RATE_INDEX_18MBPS  = 7,
+       CONF_HW_RATE_INDEX_22MBPS  = 8,
+       CONF_HW_RATE_INDEX_24MBPS  = 9,
+       CONF_HW_RATE_INDEX_36MBPS  = 10,
+       CONF_HW_RATE_INDEX_48MBPS  = 11,
+       CONF_HW_RATE_INDEX_54MBPS  = 12,
+       CONF_HW_RATE_INDEX_MAX     = CONF_HW_RATE_INDEX_54MBPS,
+};
+
+#define CONF_HW_RXTX_RATE_UNSUPPORTED 0xff
+
+enum {
+       CONF_SG_DISABLE = 0,
+       CONF_SG_PROTECTIVE,
+       CONF_SG_OPPORTUNISTIC
+};
+
+enum {
+       /*
+        * Configure the min and max time BT gains the antenna
+        * in WLAN / BT master basic rate
+        *
+        * Range: 0 - 255 (ms)
+        */
+       CONF_SG_ACL_BT_MASTER_MIN_BR = 0,
+       CONF_SG_ACL_BT_MASTER_MAX_BR,
+
+       /*
+        * Configure the min and max time BT gains the antenna
+        * in WLAN / BT slave basic rate
+        *
+        * Range: 0 - 255 (ms)
+        */
+       CONF_SG_ACL_BT_SLAVE_MIN_BR,
+       CONF_SG_ACL_BT_SLAVE_MAX_BR,
+
+       /*
+        * Configure the min and max time BT gains the antenna
+        * in WLAN / BT master EDR
+        *
+        * Range: 0 - 255 (ms)
+        */
+       CONF_SG_ACL_BT_MASTER_MIN_EDR,
+       CONF_SG_ACL_BT_MASTER_MAX_EDR,
+
+       /*
+        * Configure the min and max time BT gains the antenna
+        * in WLAN / BT slave EDR
+        *
+        * Range: 0 - 255 (ms)
+        */
+       CONF_SG_ACL_BT_SLAVE_MIN_EDR,
+       CONF_SG_ACL_BT_SLAVE_MAX_EDR,
+
+       /*
+        * The maximum time WLAN can gain the antenna
+        * in WLAN PSM / BT master/slave BR
+        *
+        * Range: 0 - 255 (ms)
+        */
+       CONF_SG_ACL_WLAN_PS_MASTER_BR,
+       CONF_SG_ACL_WLAN_PS_SLAVE_BR,
+
+       /*
+        * The maximum time WLAN can gain the antenna
+        * in WLAN PSM / BT master/slave EDR
+        *
+        * Range: 0 - 255 (ms)
+        */
+       CONF_SG_ACL_WLAN_PS_MASTER_EDR,
+       CONF_SG_ACL_WLAN_PS_SLAVE_EDR,
+
+       /* TODO: explain these values */
+       CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR,
+       CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR,
+       CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR,
+       CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR,
+       CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR,
+       CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR,
+       CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR,
+       CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR,
+
+       CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR,
+       CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR,
+       CONF_SG_ACL_PASSIVE_SCAN_BT_BR,
+       CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR,
+       CONF_SG_ACL_PASSIVE_SCAN_BT_EDR,
+       CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR,
+
+       /*
+        * Compensation percentage of probe requests when scan initiated
+        * during BT voice/ACL link.
+        *
+        * Range: 0 - 255 (%)
+        */
+       CONF_SG_AUTO_SCAN_PROBE_REQ,
+
+       /*
+        * Compensation percentage of probe requests when active scan initiated
+        * during BT voice
+        *
+        * Range: 0 - 255 (%)
+        */
+       CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3,
+
+       /*
+        * Compensation percentage of WLAN active scan window if initiated
+        * during BT A2DP
+        *
+        * Range: 0 - 1000 (%)
+        */
+       CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP,
+
+       /*
+        * Compensation percentage of WLAN passive scan window if initiated
+        * during BT A2DP BR
+        *
+        * Range: 0 - 1000 (%)
+        */
+       CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR,
+
+       /*
+        * Compensation percentage of WLAN passive scan window if initiated
+        * during BT A2DP EDR
+        *
+        * Range: 0 - 1000 (%)
+        */
+       CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR,
+
+       /*
+        * Compensation percentage of WLAN passive scan window if initiated
+        * during BT voice
+        *
+        * Range: 0 - 1000 (%)
+        */
+       CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3,
+
+       /* TODO: explain these values */
+       CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN,
+       CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN,
+       CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN,
+
+       /*
+        * Defines whether the SG will force WLAN host to enter/exit PSM
+        *
+        * Range: 1 - SG can force, 0 - host handles PSM
+        */
+       CONF_SG_STA_FORCE_PS_IN_BT_SCO,
+
+       /*
+        * Defines antenna configuration (single/dual antenna)
+        *
+        * Range: 0 - single antenna, 1 - dual antenna
+        */
+       CONF_SG_ANTENNA_CONFIGURATION,
+
+       /*
+        * The threshold (percent) of max consecutive beacon misses before
+        * increasing priority of beacon reception.
+        *
+        * Range: 0 - 100 (%)
+        */
+       CONF_SG_BEACON_MISS_PERCENT,
+
+       /*
+        * Protection time of the DHCP procedure.
+        *
+        * Range: 0 - 100000 (ms)
+        */
+       CONF_SG_DHCP_TIME,
+
+       /*
+        * RX guard time before the beginning of a new BT voice frame during
+        * which no new WLAN trigger frame is transmitted.
+        *
+        * Range: 0 - 100000 (us)
+        */
+       CONF_SG_RXT,
+
+       /*
+        * TX guard time before the beginning of a new BT voice frame during
+        * which no new WLAN frame is transmitted.
+        *
+        * Range: 0 - 100000 (us)
+        */
+
+       CONF_SG_TXT,
+
+       /*
+        * Enable adaptive RXT/TXT algorithm. If disabled, the host values
+        * will be utilized.
+        *
+        * Range: 0 - disable, 1 - enable
+        */
+       CONF_SG_ADAPTIVE_RXT_TXT,
+
+       /* TODO: explain this value */
+       CONF_SG_GENERAL_USAGE_BIT_MAP,
+
+       /*
+        * Number of consecutive BT voice frames not interrupted by WLAN
+        *
+        * Range: 0 - 100
+        */
+       CONF_SG_HV3_MAX_SERVED,
+
+       /*
+        * The used WLAN legacy service period during active BT ACL link
+        *
+        * Range: 0 - 255 (ms)
+        */
+       CONF_SG_PS_POLL_TIMEOUT,
+
+       /*
+        * The used WLAN UPSD service period during active BT ACL link
+        *
+        * Range: 0 - 255 (ms)
+        */
+       CONF_SG_UPSD_TIMEOUT,
+
+       CONF_SG_CONSECUTIVE_CTS_THRESHOLD,
+       CONF_SG_STA_RX_WINDOW_AFTER_DTIM,
+       CONF_SG_STA_CONNECTION_PROTECTION_TIME,
+
+       /* AP params */
+       CONF_AP_BEACON_MISS_TX,
+       CONF_AP_RX_WINDOW_AFTER_BEACON,
+       CONF_AP_BEACON_WINDOW_INTERVAL,
+       CONF_AP_CONNECTION_PROTECTION_TIME,
+       CONF_AP_BT_ACL_VAL_BT_SERVE_TIME,
+       CONF_AP_BT_ACL_VAL_WL_SERVE_TIME,
+
+       /* CTS Diluting params */
+       CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH,
+       CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER,
+
+       CONF_SG_TEMP_PARAM_1,
+       CONF_SG_TEMP_PARAM_2,
+       CONF_SG_TEMP_PARAM_3,
+       CONF_SG_TEMP_PARAM_4,
+       CONF_SG_TEMP_PARAM_5,
+       CONF_SG_TEMP_PARAM_6,
+       CONF_SG_TEMP_PARAM_7,
+       CONF_SG_TEMP_PARAM_8,
+       CONF_SG_TEMP_PARAM_9,
+       CONF_SG_TEMP_PARAM_10,
+
+       CONF_SG_PARAMS_MAX,
+       CONF_SG_PARAMS_ALL = 0xff
+};
+
+struct conf_sg_settings {
+       u32 params[CONF_SG_PARAMS_MAX];
+       u8 state;
+};
+
+enum conf_rx_queue_type {
+       CONF_RX_QUEUE_TYPE_LOW_PRIORITY,  /* All except the high priority */
+       CONF_RX_QUEUE_TYPE_HIGH_PRIORITY, /* Management and voice packets */
+};
+
+struct conf_rx_settings {
+       /*
+        * The maximum amount of time, in TU, before the
+        * firmware discards the MSDU.
+        *
+        * Range: 0 - 0xFFFFFFFF
+        */
+       u32 rx_msdu_life_time;
+
+       /*
+        * Packet detection threshold in the PHY.
+        *
+        * FIXME: details unknown.
+        */
+       u32 packet_detection_threshold;
+
+       /*
+        * The longest time the STA will wait to receive traffic from the AP
+        * after a PS-poll has been transmitted.
+        *
+        * Range: 0 - 200000
+        */
+       u16 ps_poll_timeout;
+       /*
+        * The longest time the STA will wait to receive traffic from the AP
+        * after a frame has been sent from an UPSD enabled queue.
+        *
+        * Range: 0 - 200000
+        */
+       u16 upsd_timeout;
+
+       /*
+        * The number of octets in an MPDU, below which an RTS/CTS
+        * handshake is not performed.
+        *
+        * Range: 0 - 4096
+        */
+       u16 rts_threshold;
+
+       /*
+        * The RX Clear Channel Assessment threshold in the PHY
+        * (the energy threshold).
+        *
+        * Range: ENABLE_ENERGY_D  == 0x140A
+        *        DISABLE_ENERGY_D == 0xFFEF
+        */
+       u16 rx_cca_threshold;
+
+       /*
+        * Occupied Rx mem-blocks number which requires interrupting the host
+        * (0 = no buffering, 0xffff = disabled).
+        *
+        * Range: u16
+        */
+       u16 irq_blk_threshold;
+
+       /*
+        * Rx packets number which requires interrupting the host
+        * (0 = no buffering).
+        *
+        * Range: u16
+        */
+       u16 irq_pkt_threshold;
+
+       /*
+        * Max time in msec the FW may delay RX-Complete interrupt.
+        *
+        * Range: 1 - 100
+        */
+       u16 irq_timeout;
+
+       /*
+        * The RX queue type.
+        *
+        * Range: RX_QUEUE_TYPE_RX_LOW_PRIORITY, RX_QUEUE_TYPE_RX_HIGH_PRIORITY,
+        */
+       u8 queue_type;
+};
+
+#define CONF_TX_MAX_RATE_CLASSES       10
+
+#define CONF_TX_RATE_MASK_UNSPECIFIED  0
+#define CONF_TX_RATE_MASK_BASIC        (CONF_HW_BIT_RATE_1MBPS | \
+                                       CONF_HW_BIT_RATE_2MBPS)
+#define CONF_TX_RATE_RETRY_LIMIT       10
+
+/* basic rates for p2p operations (probe req/resp, etc.) */
+#define CONF_TX_RATE_MASK_BASIC_P2P    (CONF_HW_BIT_RATE_6MBPS | \
+       CONF_HW_BIT_RATE_12MBPS | CONF_HW_BIT_RATE_24MBPS)
+
+/*
+ * Rates supported for data packets when operating as AP. Note the absence
+ * of the 22Mbps rate. There is a FW limitation on 12 rates so we must drop
+ * one. The rate dropped is not mandatory under any operating mode.
+ */
+#define CONF_TX_AP_ENABLED_RATES       (CONF_HW_BIT_RATE_1MBPS | \
+       CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS |      \
+       CONF_HW_BIT_RATE_6MBPS | CONF_HW_BIT_RATE_9MBPS |        \
+       CONF_HW_BIT_RATE_11MBPS | CONF_HW_BIT_RATE_12MBPS |      \
+       CONF_HW_BIT_RATE_18MBPS | CONF_HW_BIT_RATE_24MBPS |      \
+       CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS |      \
+       CONF_HW_BIT_RATE_54MBPS)
+
+#define CONF_TX_CCK_RATES  (CONF_HW_BIT_RATE_1MBPS |           \
+       CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS |     \
+       CONF_HW_BIT_RATE_11MBPS)
+
+#define CONF_TX_OFDM_RATES (CONF_HW_BIT_RATE_6MBPS |             \
+       CONF_HW_BIT_RATE_12MBPS | CONF_HW_BIT_RATE_24MBPS |      \
+       CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS |      \
+       CONF_HW_BIT_RATE_54MBPS)
+
+#define CONF_TX_MCS_RATES (CONF_HW_BIT_RATE_MCS_0 |              \
+       CONF_HW_BIT_RATE_MCS_1 | CONF_HW_BIT_RATE_MCS_2 |        \
+       CONF_HW_BIT_RATE_MCS_3 | CONF_HW_BIT_RATE_MCS_4 |        \
+       CONF_HW_BIT_RATE_MCS_5 | CONF_HW_BIT_RATE_MCS_6 |        \
+       CONF_HW_BIT_RATE_MCS_7)
+
+/*
+ * Default rates for management traffic when operating in AP mode. This
+ * should be configured according to the basic rate set of the AP
+ */
+#define CONF_TX_AP_DEFAULT_MGMT_RATES  (CONF_HW_BIT_RATE_1MBPS | \
+       CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS)
+
+/* default rates for working as IBSS (11b and OFDM) */
+#define CONF_TX_IBSS_DEFAULT_RATES  (CONF_HW_BIT_RATE_1MBPS |       \
+               CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS | \
+               CONF_HW_BIT_RATE_11MBPS | CONF_TX_OFDM_RATES);
+
+struct conf_tx_rate_class {
+
+       /*
+        * The rates enabled for this rate class.
+        *
+        * Range: CONF_HW_BIT_RATE_* bit mask
+        */
+       u32 enabled_rates;
+
+       /*
+        * The dot11 short retry limit used for TX retries.
+        *
+        * Range: u8
+        */
+       u8 short_retry_limit;
+
+       /*
+        * The dot11 long retry limit used for TX retries.
+        *
+        * Range: u8
+        */
+       u8 long_retry_limit;
+
+       /*
+        * Flags controlling the attributes of TX transmission.
+        *
+        * Range: bit 0: Truncate - when set, FW attempts to send a frame stop
+        *               when the total valid per-rate attempts have
+        *               been exhausted; otherwise transmissions
+        *               will continue at the lowest available rate
+        *               until the appropriate one of the
+        *               short_retry_limit, long_retry_limit,
+        *               dot11_max_transmit_msdu_life_time, or
+        *               max_tx_life_time, is exhausted.
+        *            1: Preamble Override - indicates if the preamble type
+        *               should be used in TX.
+        *            2: Preamble Type - the type of the preamble to be used by
+        *               the policy (0 - long preamble, 1 - short preamble.
+        */
+       u8 aflags;
+};
+
+#define CONF_TX_MAX_AC_COUNT 4
+
+/* Slot number setting to start transmission at PIFS interval */
+#define CONF_TX_AIFS_PIFS 1
+/* Slot number setting to start transmission at DIFS interval normal
+ * DCF access */
+#define CONF_TX_AIFS_DIFS 2
+
+
+enum conf_tx_ac {
+       CONF_TX_AC_BE = 0,         /* best effort / legacy */
+       CONF_TX_AC_BK = 1,         /* background */
+       CONF_TX_AC_VI = 2,         /* video */
+       CONF_TX_AC_VO = 3,         /* voice */
+       CONF_TX_AC_CTS2SELF = 4,   /* fictitious AC, follows AC_VO */
+       CONF_TX_AC_ANY_TID = 0x1f
+};
+
+struct conf_tx_ac_category {
+       /*
+        * The AC class identifier.
+        *
+        * Range: enum conf_tx_ac
+        */
+       u8 ac;
+
+       /*
+        * The contention window minimum size (in slots) for the access
+        * class.
+        *
+        * Range: u8
+        */
+       u8 cw_min;
+
+       /*
+        * The contention window maximum size (in slots) for the access
+        * class.
+        *
+        * Range: u8
+        */
+       u16 cw_max;
+
+       /*
+        * The AIF value (in slots) for the access class.
+        *
+        * Range: u8
+        */
+       u8 aifsn;
+
+       /*
+        * The TX Op Limit (in microseconds) for the access class.
+        *
+        * Range: u16
+        */
+       u16 tx_op_limit;
+};
+
+#define CONF_TX_MAX_TID_COUNT 8
+
+/* Allow TX BA on all TIDs but 6,7. These are currently reserved in the FW */
+#define CONF_TX_BA_ENABLED_TID_BITMAP 0x3F
+
+enum {
+       CONF_CHANNEL_TYPE_DCF = 0,   /* DC/LEGACY*/
+       CONF_CHANNEL_TYPE_EDCF = 1,  /* EDCA*/
+       CONF_CHANNEL_TYPE_HCCA = 2,  /* HCCA*/
+};
+
+enum {
+       CONF_PS_SCHEME_LEGACY = 0,
+       CONF_PS_SCHEME_UPSD_TRIGGER = 1,
+       CONF_PS_SCHEME_LEGACY_PSPOLL = 2,
+       CONF_PS_SCHEME_SAPSD = 3,
+};
+
+enum {
+       CONF_ACK_POLICY_LEGACY = 0,
+       CONF_ACK_POLICY_NO_ACK = 1,
+       CONF_ACK_POLICY_BLOCK = 2,
+};
+
+
+struct conf_tx_tid {
+       u8 queue_id;
+       u8 channel_type;
+       u8 tsid;
+       u8 ps_scheme;
+       u8 ack_policy;
+       u32 apsd_conf[2];
+};
+
+struct conf_tx_settings {
+       /*
+        * The TX ED value for TELEC Enable/Disable.
+        *
+        * Range: 0, 1
+        */
+       u8 tx_energy_detection;
+
+       /*
+        * Configuration for rate classes for TX (currently only one
+        * rate class supported). Used in non-AP mode.
+        */
+       struct conf_tx_rate_class sta_rc_conf;
+
+       /*
+        * Configuration for access categories for TX rate control.
+        */
+       u8 ac_conf_count;
+       struct conf_tx_ac_category ac_conf[CONF_TX_MAX_AC_COUNT];
+
+       /*
+        * AP-mode - allow this number of TX retries to a station before an
+        * event is triggered from FW.
+        * In AP-mode the hlids of unreachable stations are given in the
+        * "sta_tx_retry_exceeded" member in the event mailbox.
+        */
+       u8 max_tx_retries;
+
+       /*
+        * AP-mode - after this number of seconds a connected station is
+        * considered inactive.
+        */
+       u16 ap_aging_period;
+
+       /*
+        * Configuration for TID parameters.
+        */
+       u8 tid_conf_count;
+       struct conf_tx_tid tid_conf[CONF_TX_MAX_TID_COUNT];
+
+       /*
+        * The TX fragmentation threshold.
+        *
+        * Range: u16
+        */
+       u16 frag_threshold;
+
+       /*
+        * Max time in msec the FW may delay frame TX-Complete interrupt.
+        *
+        * Range: u16
+        */
+       u16 tx_compl_timeout;
+
+       /*
+        * Completed TX packet count which requires to issue the TX-Complete
+        * interrupt.
+        *
+        * Range: u16
+        */
+       u16 tx_compl_threshold;
+
+       /*
+        * The rate used for control messages and scanning on the 2.4GHz band
+        *
+        * Range: CONF_HW_BIT_RATE_* bit mask
+        */
+       u32 basic_rate;
+
+       /*
+        * The rate used for control messages and scanning on the 5GHz band
+        *
+        * Range: CONF_HW_BIT_RATE_* bit mask
+        */
+       u32 basic_rate_5;
+
+       /*
+        * TX retry limits for templates
+        */
+       u8 tmpl_short_retry_limit;
+       u8 tmpl_long_retry_limit;
+
+       /* Time in ms for Tx watchdog timer to expire */
+       u32 tx_watchdog_timeout;
+};
+
+enum {
+       CONF_WAKE_UP_EVENT_BEACON    = 0x01, /* Wake on every Beacon*/
+       CONF_WAKE_UP_EVENT_DTIM      = 0x02, /* Wake on every DTIM*/
+       CONF_WAKE_UP_EVENT_N_DTIM    = 0x04, /* Wake every Nth DTIM */
+       CONF_WAKE_UP_EVENT_N_BEACONS = 0x08, /* Wake every Nth beacon */
+       CONF_WAKE_UP_EVENT_BITS_MASK = 0x0F
+};
+
+#define CONF_MAX_BCN_FILT_IE_COUNT 32
+
+#define CONF_BCN_RULE_PASS_ON_CHANGE         BIT(0)
+#define CONF_BCN_RULE_PASS_ON_APPEARANCE     BIT(1)
+
+#define CONF_BCN_IE_OUI_LEN    3
+#define CONF_BCN_IE_VER_LEN    2
+
+struct conf_bcn_filt_rule {
+       /*
+        * IE number to which to associate a rule.
+        *
+        * Range: u8
+        */
+       u8 ie;
+
+       /*
+        * Rule to associate with the specific ie.
+        *
+        * Range: CONF_BCN_RULE_PASS_ON_*
+        */
+       u8 rule;
+
+       /*
+        * OUI for the vendor specifie IE (221)
+        */
+       u8 oui[CONF_BCN_IE_OUI_LEN];
+
+       /*
+        * Type for the vendor specifie IE (221)
+        */
+       u8 type;
+
+       /*
+        * Version for the vendor specifie IE (221)
+        */
+       u8 version[CONF_BCN_IE_VER_LEN];
+};
+
+#define CONF_MAX_RSSI_SNR_TRIGGERS 8
+
+enum {
+       CONF_TRIG_METRIC_RSSI_BEACON = 0,
+       CONF_TRIG_METRIC_RSSI_DATA,
+       CONF_TRIG_METRIC_SNR_BEACON,
+       CONF_TRIG_METRIC_SNR_DATA
+};
+
+enum {
+       CONF_TRIG_EVENT_TYPE_LEVEL = 0,
+       CONF_TRIG_EVENT_TYPE_EDGE
+};
+
+enum {
+       CONF_TRIG_EVENT_DIR_LOW = 0,
+       CONF_TRIG_EVENT_DIR_HIGH,
+       CONF_TRIG_EVENT_DIR_BIDIR
+};
+
+struct conf_sig_weights {
+
+       /*
+        * RSSI from beacons average weight.
+        *
+        * Range: u8
+        */
+       u8 rssi_bcn_avg_weight;
+
+       /*
+        * RSSI from data average weight.
+        *
+        * Range: u8
+        */
+       u8 rssi_pkt_avg_weight;
+
+       /*
+        * SNR from beacons average weight.
+        *
+        * Range: u8
+        */
+       u8 snr_bcn_avg_weight;
+
+       /*
+        * SNR from data average weight.
+        *
+        * Range: u8
+        */
+       u8 snr_pkt_avg_weight;
+};
+
+enum conf_bcn_filt_mode {
+       CONF_BCN_FILT_MODE_DISABLED = 0,
+       CONF_BCN_FILT_MODE_ENABLED = 1
+};
+
+enum conf_bet_mode {
+       CONF_BET_MODE_DISABLE = 0,
+       CONF_BET_MODE_ENABLE = 1,
+};
+
+struct conf_conn_settings {
+       /*
+        * Firmware wakeup conditions configuration. The host may set only
+        * one bit.
+        *
+        * Range: CONF_WAKE_UP_EVENT_*
+        */
+       u8 wake_up_event;
+
+       /*
+        * Listen interval for beacons or Dtims.
+        *
+        * Range: 0 for beacon and Dtim wakeup
+        *        1-10 for x Dtims
+        *        1-255 for x beacons
+        */
+       u8 listen_interval;
+
+       /*
+        * Firmware wakeup conditions during suspend
+        * Range: CONF_WAKE_UP_EVENT_*
+        */
+       u8 suspend_wake_up_event;
+
+       /*
+        * Listen interval during suspend.
+        * Currently will be in DTIMs (1-10)
+        *
+        */
+       u8 suspend_listen_interval;
+
+       /*
+        * Enable or disable the beacon filtering.
+        *
+        * Range: CONF_BCN_FILT_MODE_*
+        */
+       enum conf_bcn_filt_mode bcn_filt_mode;
+
+       /*
+        * Configure Beacon filter pass-thru rules.
+        */
+       u8 bcn_filt_ie_count;
+       struct conf_bcn_filt_rule bcn_filt_ie[CONF_MAX_BCN_FILT_IE_COUNT];
+
+       /*
+        * The number of consecutive beacons to lose, before the firmware
+        * becomes out of synch.
+        *
+        * Range: u32
+        */
+       u32 synch_fail_thold;
+
+       /*
+        * After out-of-synch, the number of TU's to wait without a further
+        * received beacon (or probe response) before issuing the BSS_EVENT_LOSE
+        * event.
+        *
+        * Range: u32
+        */
+       u32 bss_lose_timeout;
+
+       /*
+        * Beacon receive timeout.
+        *
+        * Range: u32
+        */
+       u32 beacon_rx_timeout;
+
+       /*
+        * Broadcast receive timeout.
+        *
+        * Range: u32
+        */
+       u32 broadcast_timeout;
+
+       /*
+        * Enable/disable reception of broadcast packets in power save mode
+        *
+        * Range: 1 - enable, 0 - disable
+        */
+       u8 rx_broadcast_in_ps;
+
+       /*
+        * Consecutive PS Poll failures before sending event to driver
+        *
+        * Range: u8
+        */
+       u8 ps_poll_threshold;
+
+       /*
+        * Configuration of signal average weights.
+        */
+       struct conf_sig_weights sig_weights;
+
+       /*
+        * Specifies if beacon early termination procedure is enabled or
+        * disabled.
+        *
+        * Range: CONF_BET_MODE_*
+        */
+       u8 bet_enable;
+
+       /*
+        * Specifies the maximum number of consecutive beacons that may be
+        * early terminated. After this number is reached at least one full
+        * beacon must be correctly received in FW before beacon ET
+        * resumes.
+        *
+        * Range 0 - 255
+        */
+       u8 bet_max_consecutive;
+
+       /*
+        * Specifies the maximum number of times to try PSM entry if it fails
+        * (if sending the appropriate null-func message fails.)
+        *
+        * Range 0 - 255
+        */
+       u8 psm_entry_retries;
+
+       /*
+        * Specifies the maximum number of times to try PSM exit if it fails
+        * (if sending the appropriate null-func message fails.)
+        *
+        * Range 0 - 255
+        */
+       u8 psm_exit_retries;
+
+       /*
+        * Specifies the maximum number of times to try transmit the PSM entry
+        * null-func frame for each PSM entry attempt
+        *
+        * Range 0 - 255
+        */
+       u8 psm_entry_nullfunc_retries;
+
+       /*
+        * Specifies the dynamic PS timeout in ms that will be used
+        * by the FW when in AUTO_PS mode
+        */
+       u16 dynamic_ps_timeout;
+
+       /*
+        * Specifies whether dynamic PS should be disabled and PSM forced.
+        * This is required for certain WiFi certification tests.
+        */
+       u8 forced_ps;
+
+       /*
+        *
+        * Specifies the interval of the connection keep-alive null-func
+        * frame in ms.
+        *
+        * Range: 1000 - 3600000
+        */
+       u32 keep_alive_interval;
+
+       /*
+        * Maximum listen interval supported by the driver in units of beacons.
+        *
+        * Range: u16
+        */
+       u8 max_listen_interval;
+};
+
+enum {
+       CONF_REF_CLK_19_2_E,
+       CONF_REF_CLK_26_E,
+       CONF_REF_CLK_38_4_E,
+       CONF_REF_CLK_52_E,
+       CONF_REF_CLK_38_4_M_XTAL,
+       CONF_REF_CLK_26_M_XTAL,
+};
+
+enum single_dual_band_enum {
+       CONF_SINGLE_BAND,
+       CONF_DUAL_BAND
+};
+
+#define CONF_RSSI_AND_PROCESS_COMPENSATION_SIZE 15
+#define CONF_NUMBER_OF_SUB_BANDS_5  7
+#define CONF_NUMBER_OF_RATE_GROUPS  6
+#define CONF_NUMBER_OF_CHANNELS_2_4 14
+#define CONF_NUMBER_OF_CHANNELS_5   35
+
+struct conf_itrim_settings {
+       /* enable dco itrim */
+       u8 enable;
+
+       /* moderation timeout in microsecs from the last TX */
+       u32 timeout;
+};
+
+struct conf_pm_config_settings {
+       /*
+        * Host clock settling time
+        *
+        * Range: 0 - 30000 us
+        */
+       u32 host_clk_settling_time;
+
+       /*
+        * Host fast wakeup support
+        *
+        * Range: true, false
+        */
+       bool host_fast_wakeup_support;
+};
+
+struct conf_roam_trigger_settings {
+       /*
+        * The minimum interval between two trigger events.
+        *
+        * Range: 0 - 60000 ms
+        */
+       u16 trigger_pacing;
+
+       /*
+        * The weight for rssi/beacon average calculation
+        *
+        * Range: 0 - 255
+        */
+       u8 avg_weight_rssi_beacon;
+
+       /*
+        * The weight for rssi/data frame average calculation
+        *
+        * Range: 0 - 255
+        */
+       u8 avg_weight_rssi_data;
+
+       /*
+        * The weight for snr/beacon average calculation
+        *
+        * Range: 0 - 255
+        */
+       u8 avg_weight_snr_beacon;
+
+       /*
+        * The weight for snr/data frame average calculation
+        *
+        * Range: 0 - 255
+        */
+       u8 avg_weight_snr_data;
+};
+
+struct conf_scan_settings {
+       /*
+        * The minimum time to wait on each channel for active scans
+        *
+        * Range: u32 tu/1000
+        */
+       u32 min_dwell_time_active;
+
+       /*
+        * The maximum time to wait on each channel for active scans
+        *
+        * Range: u32 tu/1000
+        */
+       u32 max_dwell_time_active;
+
+       /*
+        * The minimum time to wait on each channel for passive scans
+        *
+        * Range: u32 tu/1000
+        */
+       u32 min_dwell_time_passive;
+
+       /*
+        * The maximum time to wait on each channel for passive scans
+        *
+        * Range: u32 tu/1000
+        */
+       u32 max_dwell_time_passive;
+
+       /*
+        * Number of probe requests to transmit on each active scan channel
+        *
+        * Range: u8
+        */
+       u16 num_probe_reqs;
+
+       /*
+        * Scan trigger (split scan) timeout. The FW will split the scan
+        * operation into slices of the given time and allow the FW to schedule
+        * other tasks in between.
+        *
+        * Range: u32 Microsecs
+        */
+       u32 split_scan_timeout;
+};
+
+struct conf_sched_scan_settings {
+       /*
+        * The base time to wait on the channel for active scans (in TU/1000).
+        * The minimum dwell time is calculated according to this:
+        * min_dwell_time = base + num_of_probes_to_be_sent * delta_per_probe
+        * The maximum dwell time is calculated according to this:
+        * max_dwell_time = min_dwell_time + max_dwell_time_delta
+        */
+       u32 base_dwell_time;
+
+       /* The delta between the min dwell time and max dwell time for
+        * active scans (in TU/1000s). The max dwell time is used by the FW once
+        * traffic is detected on the channel.
+        */
+       u32 max_dwell_time_delta;
+
+       /* Delta added to min dwell time per each probe in 2.4 GHz (TU/1000) */
+       u32 dwell_time_delta_per_probe;
+
+       /* Delta added to min dwell time per each probe in 5 GHz (TU/1000) */
+       u32 dwell_time_delta_per_probe_5;
+
+       /* time to wait on the channel for passive scans (in TU/1000) */
+       u32 dwell_time_passive;
+
+       /* time to wait on the channel for DFS scans (in TU/1000) */
+       u32 dwell_time_dfs;
+
+       /* number of probe requests to send on each channel in active scans */
+       u8 num_probe_reqs;
+
+       /* RSSI threshold to be used for filtering */
+       s8 rssi_threshold;
+
+       /* SNR threshold to be used for filtering */
+       s8 snr_threshold;
+};
+
+struct conf_ht_setting {
+       u8 rx_ba_win_size;
+       u8 tx_ba_win_size;
+       u16 inactivity_timeout;
+
+       /* bitmap of enabled TIDs for TX BA sessions */
+       u8 tx_ba_tid_bitmap;
+};
+
+struct conf_memory_settings {
+       /* Number of stations supported in IBSS mode */
+       u8 num_stations;
+
+       /* Number of ssid profiles used in IBSS mode */
+       u8 ssid_profiles;
+
+       /* Number of memory buffers allocated to rx pool */
+       u8 rx_block_num;
+
+       /* Minimum number of blocks allocated to tx pool */
+       u8 tx_min_block_num;
+
+       /* Disable/Enable dynamic memory */
+       u8 dynamic_memory;
+
+       /*
+        * Minimum required free tx memory blocks in order to assure optimum
+        * performance
+        *
+        * Range: 0-120
+        */
+       u8 min_req_tx_blocks;
+
+       /*
+        * Minimum required free rx memory blocks in order to assure optimum
+        * performance
+        *
+        * Range: 0-120
+        */
+       u8 min_req_rx_blocks;
+
+       /*
+        * Minimum number of mem blocks (free+used) guaranteed for TX
+        *
+        * Range: 0-120
+        */
+       u8 tx_min;
+};
+
+struct conf_fm_coex {
+       u8 enable;
+       u8 swallow_period;
+       u8 n_divider_fref_set_1;
+       u8 n_divider_fref_set_2;
+       u16 m_divider_fref_set_1;
+       u16 m_divider_fref_set_2;
+       u32 coex_pll_stabilization_time;
+       u16 ldo_stabilization_time;
+       u8 fm_disturbed_band_margin;
+       u8 swallow_clk_diff;
+};
+
+struct conf_rx_streaming_settings {
+       /*
+        * RX Streaming duration (in msec) from last tx/rx
+        *
+        * Range: u32
+        */
+       u32 duration;
+
+       /*
+        * Bitmap of tids to be polled during RX streaming.
+        * (Note: it doesn't look like it really matters)
+        *
+        * Range: 0x1-0xff
+        */
+       u8 queues;
+
+       /*
+        * RX Streaming interval.
+        * (Note:this value is also used as the rx streaming timeout)
+        * Range: 0 (disabled), 10 - 100
+        */
+       u8 interval;
+
+       /*
+        * enable rx streaming also when there is no coex activity
+        */
+       u8 always;
+};
+
+struct conf_fwlog {
+       /* Continuous or on-demand */
+       u8 mode;
+
+       /*
+        * Number of memory blocks dedicated for the FW logger
+        *
+        * Range: 1-3, or 0 to disable the FW logger
+        */
+       u8 mem_blocks;
+
+       /* Minimum log level threshold */
+       u8 severity;
+
+       /* Include/exclude timestamps from the log messages */
+       u8 timestamp;
+
+       /* See enum wl1271_fwlogger_output */
+       u8 output;
+
+       /* Regulates the frequency of log messages */
+       u8 threshold;
+};
+
+#define ACX_RATE_MGMT_NUM_OF_RATES 13
+struct conf_rate_policy_settings {
+       u16 rate_retry_score;
+       u16 per_add;
+       u16 per_th1;
+       u16 per_th2;
+       u16 max_per;
+       u8 inverse_curiosity_factor;
+       u8 tx_fail_low_th;
+       u8 tx_fail_high_th;
+       u8 per_alpha_shift;
+       u8 per_add_shift;
+       u8 per_beta1_shift;
+       u8 per_beta2_shift;
+       u8 rate_check_up;
+       u8 rate_check_down;
+       u8 rate_retry_policy[ACX_RATE_MGMT_NUM_OF_RATES];
+};
+
+struct conf_hangover_settings {
+       u32 recover_time;
+       u8 hangover_period;
+       u8 dynamic_mode;
+       u8 early_termination_mode;
+       u8 max_period;
+       u8 min_period;
+       u8 increase_delta;
+       u8 decrease_delta;
+       u8 quiet_time;
+       u8 increase_time;
+       u8 window_size;
+};
+
+struct wlcore_conf {
+       struct conf_sg_settings sg;
+       struct conf_rx_settings rx;
+       struct conf_tx_settings tx;
+       struct conf_conn_settings conn;
+       struct conf_itrim_settings itrim;
+       struct conf_pm_config_settings pm_config;
+       struct conf_roam_trigger_settings roam_trigger;
+       struct conf_scan_settings scan;
+       struct conf_sched_scan_settings sched_scan;
+       struct conf_ht_setting ht;
+       struct conf_memory_settings mem;
+       struct conf_fm_coex fm_coex;
+       struct conf_rx_streaming_settings rx_streaming;
+       struct conf_fwlog fwlog;
+       struct conf_rate_policy_settings rate;
+       struct conf_hangover_settings hangover;
+};
+
+#endif
diff --git a/drivers/net/wireless/ti/wlcore/debug.h b/drivers/net/wireless/ti/wlcore/debug.h
new file mode 100644 (file)
index 0000000..6b800b3
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * This file is part of wl12xx
+ *
+ * Copyright (C) 2011 Texas Instruments. All rights reserved.
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <coelho@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __DEBUG_H__
+#define __DEBUG_H__
+
+#include <linux/bitops.h>
+#include <linux/printk.h>
+
+#define DRIVER_NAME "wl12xx"
+#define DRIVER_PREFIX DRIVER_NAME ": "
+
+enum {
+       DEBUG_NONE      = 0,
+       DEBUG_IRQ       = BIT(0),
+       DEBUG_SPI       = BIT(1),
+       DEBUG_BOOT      = BIT(2),
+       DEBUG_MAILBOX   = BIT(3),
+       DEBUG_TESTMODE  = BIT(4),
+       DEBUG_EVENT     = BIT(5),
+       DEBUG_TX        = BIT(6),
+       DEBUG_RX        = BIT(7),
+       DEBUG_SCAN      = BIT(8),
+       DEBUG_CRYPT     = BIT(9),
+       DEBUG_PSM       = BIT(10),
+       DEBUG_MAC80211  = BIT(11),
+       DEBUG_CMD       = BIT(12),
+       DEBUG_ACX       = BIT(13),
+       DEBUG_SDIO      = BIT(14),
+       DEBUG_FILTERS   = BIT(15),
+       DEBUG_ADHOC     = BIT(16),
+       DEBUG_AP        = BIT(17),
+       DEBUG_PROBE     = BIT(18),
+       DEBUG_IO        = BIT(19),
+       DEBUG_MASTER    = (DEBUG_ADHOC | DEBUG_AP),
+       DEBUG_ALL       = ~0,
+};
+
+extern u32 wl12xx_debug_level;
+
+#define DEBUG_DUMP_LIMIT 1024
+
+#define wl1271_error(fmt, arg...) \
+       pr_err(DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
+
+#define wl1271_warning(fmt, arg...) \
+       pr_warning(DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
+
+#define wl1271_notice(fmt, arg...) \
+       pr_info(DRIVER_PREFIX fmt "\n", ##arg)
+
+#define wl1271_info(fmt, arg...) \
+       pr_info(DRIVER_PREFIX fmt "\n", ##arg)
+
+#define wl1271_debug(level, fmt, arg...) \
+       do { \
+               if (level & wl12xx_debug_level) \
+                       pr_debug(DRIVER_PREFIX fmt "\n", ##arg); \
+       } while (0)
+
+/* TODO: use pr_debug_hex_dump when it becomes available */
+#define wl1271_dump(level, prefix, buf, len)   \
+       do { \
+               if (level & wl12xx_debug_level) \
+                       print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
+                                      DUMP_PREFIX_OFFSET, 16, 1,       \
+                                      buf,                             \
+                                      min_t(size_t, len, DEBUG_DUMP_LIMIT), \
+                                      0);                              \
+       } while (0)
+
+#define wl1271_dump_ascii(level, prefix, buf, len)     \
+       do { \
+               if (level & wl12xx_debug_level) \
+                       print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
+                                      DUMP_PREFIX_OFFSET, 16, 1,       \
+                                      buf,                             \
+                                      min_t(size_t, len, DEBUG_DUMP_LIMIT), \
+                                      true);                           \
+       } while (0)
+
+#endif /* __DEBUG_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/debugfs.c b/drivers/net/wireless/ti/wlcore/debugfs.c
new file mode 100644 (file)
index 0000000..d5aea1f
--- /dev/null
@@ -0,0 +1,1198 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "debugfs.h"
+
+#include <linux/skbuff.h>
+#include <linux/slab.h>
+
+#include "wlcore.h"
+#include "debug.h"
+#include "acx.h"
+#include "ps.h"
+#include "io.h"
+#include "tx.h"
+
+/* ms */
+#define WL1271_DEBUGFS_STATS_LIFETIME 1000
+
+/* debugfs macros idea from mac80211 */
+#define DEBUGFS_FORMAT_BUFFER_SIZE 100
+static int wl1271_format_buffer(char __user *userbuf, size_t count,
+                                   loff_t *ppos, char *fmt, ...)
+{
+       va_list args;
+       char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
+       int res;
+
+       va_start(args, fmt);
+       res = vscnprintf(buf, sizeof(buf), fmt, args);
+       va_end(args);
+
+       return simple_read_from_buffer(userbuf, count, ppos, buf, res);
+}
+
+#define DEBUGFS_READONLY_FILE(name, fmt, value...)                     \
+static ssize_t name## _read(struct file *file, char __user *userbuf,   \
+                           size_t count, loff_t *ppos)                 \
+{                                                                      \
+       struct wl1271 *wl = file->private_data;                         \
+       return wl1271_format_buffer(userbuf, count, ppos,               \
+                                   fmt "\n", ##value);                 \
+}                                                                      \
+                                                                       \
+static const struct file_operations name## _ops = {                    \
+       .read = name## _read,                                           \
+       .open = simple_open,                                            \
+       .llseek = generic_file_llseek,                                  \
+};
+
+#define DEBUGFS_ADD(name, parent)                                      \
+       entry = debugfs_create_file(#name, 0400, parent,                \
+                                   wl, &name## _ops);                  \
+       if (!entry || IS_ERR(entry))                                    \
+               goto err;                                               \
+
+#define DEBUGFS_ADD_PREFIX(prefix, name, parent)                       \
+       do {                                                            \
+               entry = debugfs_create_file(#name, 0400, parent,        \
+                                   wl, &prefix## _## name## _ops);     \
+               if (!entry || IS_ERR(entry))                            \
+                       goto err;                                       \
+       } while (0);
+
+#define DEBUGFS_FWSTATS_FILE(sub, name, fmt)                           \
+static ssize_t sub## _ ##name## _read(struct file *file,               \
+                                     char __user *userbuf,             \
+                                     size_t count, loff_t *ppos)       \
+{                                                                      \
+       struct wl1271 *wl = file->private_data;                         \
+                                                                       \
+       wl1271_debugfs_update_stats(wl);                                \
+                                                                       \
+       return wl1271_format_buffer(userbuf, count, ppos, fmt "\n",     \
+                                   wl->stats.fw_stats->sub.name);      \
+}                                                                      \
+                                                                       \
+static const struct file_operations sub## _ ##name## _ops = {          \
+       .read = sub## _ ##name## _read,                                 \
+       .open = simple_open,                                            \
+       .llseek = generic_file_llseek,                                  \
+};
+
+#define DEBUGFS_FWSTATS_ADD(sub, name)                         \
+       DEBUGFS_ADD(sub## _ ##name, stats)
+
+static void wl1271_debugfs_update_stats(struct wl1271 *wl)
+{
+       int ret;
+
+       mutex_lock(&wl->mutex);
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       if (wl->state == WL1271_STATE_ON && !wl->plt &&
+           time_after(jiffies, wl->stats.fw_stats_update +
+                      msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
+               wl1271_acx_statistics(wl, wl->stats.fw_stats);
+               wl->stats.fw_stats_update = jiffies;
+       }
+
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
+
+DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
+DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u");
+DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u");
+DEBUGFS_FWSTATS_FILE(rx, dropped, "%u");
+DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u");
+DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u");
+DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u");
+DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u");
+
+DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u");
+DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u");
+DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u");
+DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u");
+
+DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u");
+DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u");
+DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u");
+DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u");
+DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u");
+DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
+DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u");
+DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u");
+DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u");
+DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u");
+DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u");
+DEBUGFS_FWSTATS_FILE(isr, commands, "%u");
+DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u");
+DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u");
+DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u");
+DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u");
+DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u");
+DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u");
+
+DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
+DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
+/* skipping wep.reserved */
+DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u");
+DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u");
+DEBUGFS_FWSTATS_FILE(wep, packets, "%u");
+DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u");
+
+DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u");
+DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u");
+/* skipping cont_miss_bcns_spread for now */
+DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
+
+DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
+DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
+
+DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u");
+DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u");
+DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u");
+DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u");
+DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u");
+DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u");
+
+DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u");
+DEBUGFS_FWSTATS_FILE(event, calibration, "%u");
+DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u");
+DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u");
+DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u");
+DEBUGFS_FWSTATS_FILE(event, oom_late, "%u");
+DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u");
+DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u");
+
+DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u");
+DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u");
+DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u");
+DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u");
+DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u");
+DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u");
+DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u");
+
+DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u");
+DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u");
+DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u");
+DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u");
+DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u");
+
+DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
+DEBUGFS_READONLY_FILE(excessive_retries, "%u",
+                     wl->stats.excessive_retries);
+
+static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
+                                size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       u32 queue_len;
+       char buf[20];
+       int res;
+
+       queue_len = wl1271_tx_total_queue_count(wl);
+
+       res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
+       return simple_read_from_buffer(userbuf, count, ppos, buf, res);
+}
+
+static const struct file_operations tx_queue_len_ops = {
+       .read = tx_queue_len_read,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
+                         size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
+
+       int res;
+       char buf[10];
+
+       res = scnprintf(buf, sizeof(buf), "%d\n", state);
+
+       return simple_read_from_buffer(user_buf, count, ppos, buf, res);
+}
+
+static ssize_t gpio_power_write(struct file *file,
+                          const char __user *user_buf,
+                          size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       unsigned long value;
+       int ret;
+
+       ret = kstrtoul_from_user(user_buf, count, 10, &value);
+       if (ret < 0) {
+               wl1271_warning("illegal value in gpio_power");
+               return -EINVAL;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       if (value)
+               wl1271_power_on(wl);
+       else
+               wl1271_power_off(wl);
+
+       mutex_unlock(&wl->mutex);
+       return count;
+}
+
+static const struct file_operations gpio_power_ops = {
+       .read = gpio_power_read,
+       .write = gpio_power_write,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static ssize_t start_recovery_write(struct file *file,
+                                   const char __user *user_buf,
+                                   size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+
+       mutex_lock(&wl->mutex);
+       wl12xx_queue_recovery_work(wl);
+       mutex_unlock(&wl->mutex);
+
+       return count;
+}
+
+static const struct file_operations start_recovery_ops = {
+       .write = start_recovery_write,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static ssize_t dynamic_ps_timeout_read(struct file *file, char __user *user_buf,
+                         size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+
+       return wl1271_format_buffer(user_buf, count,
+                                   ppos, "%d\n",
+                                   wl->conf.conn.dynamic_ps_timeout);
+}
+
+static ssize_t dynamic_ps_timeout_write(struct file *file,
+                                   const char __user *user_buf,
+                                   size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       struct wl12xx_vif *wlvif;
+       unsigned long value;
+       int ret;
+
+       ret = kstrtoul_from_user(user_buf, count, 10, &value);
+       if (ret < 0) {
+               wl1271_warning("illegal value in dynamic_ps");
+               return -EINVAL;
+       }
+
+       if (value < 1 || value > 65535) {
+               wl1271_warning("dyanmic_ps_timeout is not in valid range");
+               return -ERANGE;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       wl->conf.conn.dynamic_ps_timeout = value;
+
+       if (wl->state == WL1271_STATE_OFF)
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       /* In case we're already in PSM, trigger it again to set new timeout
+        * immediately without waiting for re-association
+        */
+
+       wl12xx_for_each_wlvif_sta(wl, wlvif) {
+               if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
+                       wl1271_ps_set_mode(wl, wlvif, STATION_AUTO_PS_MODE);
+       }
+
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+       return count;
+}
+
+static const struct file_operations dynamic_ps_timeout_ops = {
+       .read = dynamic_ps_timeout_read,
+       .write = dynamic_ps_timeout_write,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static ssize_t forced_ps_read(struct file *file, char __user *user_buf,
+                         size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+
+       return wl1271_format_buffer(user_buf, count,
+                                   ppos, "%d\n",
+                                   wl->conf.conn.forced_ps);
+}
+
+static ssize_t forced_ps_write(struct file *file,
+                                   const char __user *user_buf,
+                                   size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       struct wl12xx_vif *wlvif;
+       unsigned long value;
+       int ret, ps_mode;
+
+       ret = kstrtoul_from_user(user_buf, count, 10, &value);
+       if (ret < 0) {
+               wl1271_warning("illegal value in forced_ps");
+               return -EINVAL;
+       }
+
+       if (value != 1 && value != 0) {
+               wl1271_warning("forced_ps should be either 0 or 1");
+               return -ERANGE;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->conf.conn.forced_ps == value)
+               goto out;
+
+       wl->conf.conn.forced_ps = value;
+
+       if (wl->state == WL1271_STATE_OFF)
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       /* In case we're already in PSM, trigger it again to switch mode
+        * immediately without waiting for re-association
+        */
+
+       ps_mode = value ? STATION_POWER_SAVE_MODE : STATION_AUTO_PS_MODE;
+
+       wl12xx_for_each_wlvif_sta(wl, wlvif) {
+               if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
+                       wl1271_ps_set_mode(wl, wlvif, ps_mode);
+       }
+
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+       return count;
+}
+
+static const struct file_operations forced_ps_ops = {
+       .read = forced_ps_read,
+       .write = forced_ps_write,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static ssize_t split_scan_timeout_read(struct file *file, char __user *user_buf,
+                         size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+
+       return wl1271_format_buffer(user_buf, count,
+                                   ppos, "%d\n",
+                                   wl->conf.scan.split_scan_timeout / 1000);
+}
+
+static ssize_t split_scan_timeout_write(struct file *file,
+                                   const char __user *user_buf,
+                                   size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       unsigned long value;
+       int ret;
+
+       ret = kstrtoul_from_user(user_buf, count, 10, &value);
+       if (ret < 0) {
+               wl1271_warning("illegal value in split_scan_timeout");
+               return -EINVAL;
+       }
+
+       if (value == 0)
+               wl1271_info("split scan will be disabled");
+
+       mutex_lock(&wl->mutex);
+
+       wl->conf.scan.split_scan_timeout = value * 1000;
+
+       mutex_unlock(&wl->mutex);
+       return count;
+}
+
+static const struct file_operations split_scan_timeout_ops = {
+       .read = split_scan_timeout_read,
+       .write = split_scan_timeout_write,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static ssize_t driver_state_read(struct file *file, char __user *user_buf,
+                                size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       int res = 0;
+       ssize_t ret;
+       char *buf;
+
+#define DRIVER_STATE_BUF_LEN 1024
+
+       buf = kmalloc(DRIVER_STATE_BUF_LEN, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
+       mutex_lock(&wl->mutex);
+
+#define DRIVER_STATE_PRINT(x, fmt)   \
+       (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\
+                         #x " = " fmt "\n", wl->x))
+
+#define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
+#define DRIVER_STATE_PRINT_INT(x)  DRIVER_STATE_PRINT(x, "%d")
+#define DRIVER_STATE_PRINT_STR(x)  DRIVER_STATE_PRINT(x, "%s")
+#define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
+#define DRIVER_STATE_PRINT_HEX(x)  DRIVER_STATE_PRINT(x, "0x%x")
+
+       DRIVER_STATE_PRINT_INT(tx_blocks_available);
+       DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
+       DRIVER_STATE_PRINT_INT(tx_allocated_pkts[0]);
+       DRIVER_STATE_PRINT_INT(tx_allocated_pkts[1]);
+       DRIVER_STATE_PRINT_INT(tx_allocated_pkts[2]);
+       DRIVER_STATE_PRINT_INT(tx_allocated_pkts[3]);
+       DRIVER_STATE_PRINT_INT(tx_frames_cnt);
+       DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
+       DRIVER_STATE_PRINT_INT(tx_queue_count[0]);
+       DRIVER_STATE_PRINT_INT(tx_queue_count[1]);
+       DRIVER_STATE_PRINT_INT(tx_queue_count[2]);
+       DRIVER_STATE_PRINT_INT(tx_queue_count[3]);
+       DRIVER_STATE_PRINT_INT(tx_packets_count);
+       DRIVER_STATE_PRINT_INT(tx_results_count);
+       DRIVER_STATE_PRINT_LHEX(flags);
+       DRIVER_STATE_PRINT_INT(tx_blocks_freed);
+       DRIVER_STATE_PRINT_INT(rx_counter);
+       DRIVER_STATE_PRINT_INT(state);
+       DRIVER_STATE_PRINT_INT(channel);
+       DRIVER_STATE_PRINT_INT(band);
+       DRIVER_STATE_PRINT_INT(power_level);
+       DRIVER_STATE_PRINT_INT(sg_enabled);
+       DRIVER_STATE_PRINT_INT(enable_11a);
+       DRIVER_STATE_PRINT_INT(noise);
+       DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
+       DRIVER_STATE_PRINT_LHEX(ap_ps_map);
+       DRIVER_STATE_PRINT_HEX(quirks);
+       DRIVER_STATE_PRINT_HEX(irq);
+       DRIVER_STATE_PRINT_HEX(ref_clock);
+       DRIVER_STATE_PRINT_HEX(tcxo_clock);
+       DRIVER_STATE_PRINT_HEX(hw_pg_ver);
+       DRIVER_STATE_PRINT_HEX(platform_quirks);
+       DRIVER_STATE_PRINT_HEX(chip.id);
+       DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
+       DRIVER_STATE_PRINT_INT(sched_scanning);
+
+#undef DRIVER_STATE_PRINT_INT
+#undef DRIVER_STATE_PRINT_LONG
+#undef DRIVER_STATE_PRINT_HEX
+#undef DRIVER_STATE_PRINT_LHEX
+#undef DRIVER_STATE_PRINT_STR
+#undef DRIVER_STATE_PRINT
+#undef DRIVER_STATE_BUF_LEN
+
+       mutex_unlock(&wl->mutex);
+
+       ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
+       kfree(buf);
+       return ret;
+}
+
+static const struct file_operations driver_state_ops = {
+       .read = driver_state_read,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static ssize_t vifs_state_read(struct file *file, char __user *user_buf,
+                                size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       struct wl12xx_vif *wlvif;
+       int ret, res = 0;
+       const int buf_size = 4096;
+       char *buf;
+       char tmp_buf[64];
+
+       buf = kzalloc(buf_size, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
+       mutex_lock(&wl->mutex);
+
+#define VIF_STATE_PRINT(x, fmt)                                \
+       (res += scnprintf(buf + res, buf_size - res,    \
+                         #x " = " fmt "\n", wlvif->x))
+
+#define VIF_STATE_PRINT_LONG(x)  VIF_STATE_PRINT(x, "%ld")
+#define VIF_STATE_PRINT_INT(x)   VIF_STATE_PRINT(x, "%d")
+#define VIF_STATE_PRINT_STR(x)   VIF_STATE_PRINT(x, "%s")
+#define VIF_STATE_PRINT_LHEX(x)  VIF_STATE_PRINT(x, "0x%lx")
+#define VIF_STATE_PRINT_LLHEX(x) VIF_STATE_PRINT(x, "0x%llx")
+#define VIF_STATE_PRINT_HEX(x)   VIF_STATE_PRINT(x, "0x%x")
+
+#define VIF_STATE_PRINT_NSTR(x, len)                           \
+       do {                                                    \
+               memset(tmp_buf, 0, sizeof(tmp_buf));            \
+               memcpy(tmp_buf, wlvif->x,                       \
+                      min_t(u8, len, sizeof(tmp_buf) - 1));    \
+               res += scnprintf(buf + res, buf_size - res,     \
+                                #x " = %s\n", tmp_buf);        \
+       } while (0)
+
+       wl12xx_for_each_wlvif(wl, wlvif) {
+               VIF_STATE_PRINT_INT(role_id);
+               VIF_STATE_PRINT_INT(bss_type);
+               VIF_STATE_PRINT_LHEX(flags);
+               VIF_STATE_PRINT_INT(p2p);
+               VIF_STATE_PRINT_INT(dev_role_id);
+               VIF_STATE_PRINT_INT(dev_hlid);
+
+               if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
+                   wlvif->bss_type == BSS_TYPE_IBSS) {
+                       VIF_STATE_PRINT_INT(sta.hlid);
+                       VIF_STATE_PRINT_INT(sta.ba_rx_bitmap);
+                       VIF_STATE_PRINT_INT(sta.basic_rate_idx);
+                       VIF_STATE_PRINT_INT(sta.ap_rate_idx);
+                       VIF_STATE_PRINT_INT(sta.p2p_rate_idx);
+                       VIF_STATE_PRINT_INT(sta.qos);
+               } else {
+                       VIF_STATE_PRINT_INT(ap.global_hlid);
+                       VIF_STATE_PRINT_INT(ap.bcast_hlid);
+                       VIF_STATE_PRINT_LHEX(ap.sta_hlid_map[0]);
+                       VIF_STATE_PRINT_INT(ap.mgmt_rate_idx);
+                       VIF_STATE_PRINT_INT(ap.bcast_rate_idx);
+                       VIF_STATE_PRINT_INT(ap.ucast_rate_idx[0]);
+                       VIF_STATE_PRINT_INT(ap.ucast_rate_idx[1]);
+                       VIF_STATE_PRINT_INT(ap.ucast_rate_idx[2]);
+                       VIF_STATE_PRINT_INT(ap.ucast_rate_idx[3]);
+               }
+               VIF_STATE_PRINT_INT(last_tx_hlid);
+               VIF_STATE_PRINT_LHEX(links_map[0]);
+               VIF_STATE_PRINT_NSTR(ssid, wlvif->ssid_len);
+               VIF_STATE_PRINT_INT(band);
+               VIF_STATE_PRINT_INT(channel);
+               VIF_STATE_PRINT_HEX(bitrate_masks[0]);
+               VIF_STATE_PRINT_HEX(bitrate_masks[1]);
+               VIF_STATE_PRINT_HEX(basic_rate_set);
+               VIF_STATE_PRINT_HEX(basic_rate);
+               VIF_STATE_PRINT_HEX(rate_set);
+               VIF_STATE_PRINT_INT(beacon_int);
+               VIF_STATE_PRINT_INT(default_key);
+               VIF_STATE_PRINT_INT(aid);
+               VIF_STATE_PRINT_INT(session_counter);
+               VIF_STATE_PRINT_INT(psm_entry_retry);
+               VIF_STATE_PRINT_INT(power_level);
+               VIF_STATE_PRINT_INT(rssi_thold);
+               VIF_STATE_PRINT_INT(last_rssi_event);
+               VIF_STATE_PRINT_INT(ba_support);
+               VIF_STATE_PRINT_INT(ba_allowed);
+               VIF_STATE_PRINT_INT(is_gem);
+               VIF_STATE_PRINT_LLHEX(tx_security_seq);
+               VIF_STATE_PRINT_INT(tx_security_last_seq_lsb);
+       }
+
+#undef VIF_STATE_PRINT_INT
+#undef VIF_STATE_PRINT_LONG
+#undef VIF_STATE_PRINT_HEX
+#undef VIF_STATE_PRINT_LHEX
+#undef VIF_STATE_PRINT_LLHEX
+#undef VIF_STATE_PRINT_STR
+#undef VIF_STATE_PRINT_NSTR
+#undef VIF_STATE_PRINT
+
+       mutex_unlock(&wl->mutex);
+
+       ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
+       kfree(buf);
+       return ret;
+}
+
+static const struct file_operations vifs_state_ops = {
+       .read = vifs_state_read,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
+                                 size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       u8 value;
+
+       if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
+           wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
+               value = wl->conf.conn.listen_interval;
+       else
+               value = 0;
+
+       return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
+}
+
+static ssize_t dtim_interval_write(struct file *file,
+                                  const char __user *user_buf,
+                                  size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       unsigned long value;
+       int ret;
+
+       ret = kstrtoul_from_user(user_buf, count, 10, &value);
+       if (ret < 0) {
+               wl1271_warning("illegal value for dtim_interval");
+               return -EINVAL;
+       }
+
+       if (value < 1 || value > 10) {
+               wl1271_warning("dtim value is not in valid range");
+               return -ERANGE;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       wl->conf.conn.listen_interval = value;
+       /* for some reason there are different event types for 1 and >1 */
+       if (value == 1)
+               wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
+       else
+               wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
+
+       /*
+        * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
+        * take effect on the next time we enter psm.
+        */
+       mutex_unlock(&wl->mutex);
+       return count;
+}
+
+static const struct file_operations dtim_interval_ops = {
+       .read = dtim_interval_read,
+       .write = dtim_interval_write,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+
+
+static ssize_t suspend_dtim_interval_read(struct file *file,
+                                         char __user *user_buf,
+                                         size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       u8 value;
+
+       if (wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
+           wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
+               value = wl->conf.conn.suspend_listen_interval;
+       else
+               value = 0;
+
+       return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
+}
+
+static ssize_t suspend_dtim_interval_write(struct file *file,
+                                          const char __user *user_buf,
+                                          size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       unsigned long value;
+       int ret;
+
+       ret = kstrtoul_from_user(user_buf, count, 10, &value);
+       if (ret < 0) {
+               wl1271_warning("illegal value for suspend_dtim_interval");
+               return -EINVAL;
+       }
+
+       if (value < 1 || value > 10) {
+               wl1271_warning("suspend_dtim value is not in valid range");
+               return -ERANGE;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       wl->conf.conn.suspend_listen_interval = value;
+       /* for some reason there are different event types for 1 and >1 */
+       if (value == 1)
+               wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
+       else
+               wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
+
+       mutex_unlock(&wl->mutex);
+       return count;
+}
+
+
+static const struct file_operations suspend_dtim_interval_ops = {
+       .read = suspend_dtim_interval_read,
+       .write = suspend_dtim_interval_write,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
+                                   size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       u8 value;
+
+       if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
+           wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
+               value = wl->conf.conn.listen_interval;
+       else
+               value = 0;
+
+       return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
+}
+
+static ssize_t beacon_interval_write(struct file *file,
+                                    const char __user *user_buf,
+                                    size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       unsigned long value;
+       int ret;
+
+       ret = kstrtoul_from_user(user_buf, count, 10, &value);
+       if (ret < 0) {
+               wl1271_warning("illegal value for beacon_interval");
+               return -EINVAL;
+       }
+
+       if (value < 1 || value > 255) {
+               wl1271_warning("beacon interval value is not in valid range");
+               return -ERANGE;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       wl->conf.conn.listen_interval = value;
+       /* for some reason there are different event types for 1 and >1 */
+       if (value == 1)
+               wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
+       else
+               wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
+
+       /*
+        * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
+        * take effect on the next time we enter psm.
+        */
+       mutex_unlock(&wl->mutex);
+       return count;
+}
+
+static const struct file_operations beacon_interval_ops = {
+       .read = beacon_interval_read,
+       .write = beacon_interval_write,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static ssize_t rx_streaming_interval_write(struct file *file,
+                          const char __user *user_buf,
+                          size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       struct wl12xx_vif *wlvif;
+       unsigned long value;
+       int ret;
+
+       ret = kstrtoul_from_user(user_buf, count, 10, &value);
+       if (ret < 0) {
+               wl1271_warning("illegal value in rx_streaming_interval!");
+               return -EINVAL;
+       }
+
+       /* valid values: 0, 10-100 */
+       if (value && (value < 10 || value > 100)) {
+               wl1271_warning("value is not in range!");
+               return -ERANGE;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       wl->conf.rx_streaming.interval = value;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       wl12xx_for_each_wlvif_sta(wl, wlvif) {
+               wl1271_recalc_rx_streaming(wl, wlvif);
+       }
+
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+       return count;
+}
+
+static ssize_t rx_streaming_interval_read(struct file *file,
+                           char __user *userbuf,
+                           size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       return wl1271_format_buffer(userbuf, count, ppos,
+                                   "%d\n", wl->conf.rx_streaming.interval);
+}
+
+static const struct file_operations rx_streaming_interval_ops = {
+       .read = rx_streaming_interval_read,
+       .write = rx_streaming_interval_write,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static ssize_t rx_streaming_always_write(struct file *file,
+                          const char __user *user_buf,
+                          size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       struct wl12xx_vif *wlvif;
+       unsigned long value;
+       int ret;
+
+       ret = kstrtoul_from_user(user_buf, count, 10, &value);
+       if (ret < 0) {
+               wl1271_warning("illegal value in rx_streaming_write!");
+               return -EINVAL;
+       }
+
+       /* valid values: 0, 10-100 */
+       if (!(value == 0 || value == 1)) {
+               wl1271_warning("value is not in valid!");
+               return -EINVAL;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       wl->conf.rx_streaming.always = value;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       wl12xx_for_each_wlvif_sta(wl, wlvif) {
+               wl1271_recalc_rx_streaming(wl, wlvif);
+       }
+
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+       return count;
+}
+
+static ssize_t rx_streaming_always_read(struct file *file,
+                           char __user *userbuf,
+                           size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       return wl1271_format_buffer(userbuf, count, ppos,
+                                   "%d\n", wl->conf.rx_streaming.always);
+}
+
+static const struct file_operations rx_streaming_always_ops = {
+       .read = rx_streaming_always_read,
+       .write = rx_streaming_always_write,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static ssize_t beacon_filtering_write(struct file *file,
+                                     const char __user *user_buf,
+                                     size_t count, loff_t *ppos)
+{
+       struct wl1271 *wl = file->private_data;
+       struct wl12xx_vif *wlvif;
+       char buf[10];
+       size_t len;
+       unsigned long value;
+       int ret;
+
+       len = min(count, sizeof(buf) - 1);
+       if (copy_from_user(buf, user_buf, len))
+               return -EFAULT;
+       buf[len] = '\0';
+
+       ret = kstrtoul(buf, 0, &value);
+       if (ret < 0) {
+               wl1271_warning("illegal value for beacon_filtering!");
+               return -EINVAL;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       wl12xx_for_each_wlvif(wl, wlvif) {
+               ret = wl1271_acx_beacon_filter_opt(wl, wlvif, !!value);
+       }
+
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+       return count;
+}
+
+static const struct file_operations beacon_filtering_ops = {
+       .write = beacon_filtering_write,
+       .open = simple_open,
+       .llseek = default_llseek,
+};
+
+static int wl1271_debugfs_add_files(struct wl1271 *wl,
+                                    struct dentry *rootdir)
+{
+       int ret = 0;
+       struct dentry *entry, *stats, *streaming;
+
+       stats = debugfs_create_dir("fw-statistics", rootdir);
+       if (!stats || IS_ERR(stats)) {
+               entry = stats;
+               goto err;
+       }
+
+       DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
+
+       DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
+       DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
+       DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
+       DEBUGFS_FWSTATS_ADD(rx, dropped);
+       DEBUGFS_FWSTATS_ADD(rx, fcs_err);
+       DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
+       DEBUGFS_FWSTATS_ADD(rx, path_reset);
+       DEBUGFS_FWSTATS_ADD(rx, reset_counter);
+
+       DEBUGFS_FWSTATS_ADD(dma, rx_requested);
+       DEBUGFS_FWSTATS_ADD(dma, rx_errors);
+       DEBUGFS_FWSTATS_ADD(dma, tx_requested);
+       DEBUGFS_FWSTATS_ADD(dma, tx_errors);
+
+       DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
+       DEBUGFS_FWSTATS_ADD(isr, fiqs);
+       DEBUGFS_FWSTATS_ADD(isr, rx_headers);
+       DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
+       DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
+       DEBUGFS_FWSTATS_ADD(isr, irqs);
+       DEBUGFS_FWSTATS_ADD(isr, tx_procs);
+       DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
+       DEBUGFS_FWSTATS_ADD(isr, dma0_done);
+       DEBUGFS_FWSTATS_ADD(isr, dma1_done);
+       DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
+       DEBUGFS_FWSTATS_ADD(isr, commands);
+       DEBUGFS_FWSTATS_ADD(isr, rx_procs);
+       DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
+       DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
+       DEBUGFS_FWSTATS_ADD(isr, pci_pm);
+       DEBUGFS_FWSTATS_ADD(isr, wakeups);
+       DEBUGFS_FWSTATS_ADD(isr, low_rssi);
+
+       DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
+       DEBUGFS_FWSTATS_ADD(wep, default_key_count);
+       /* skipping wep.reserved */
+       DEBUGFS_FWSTATS_ADD(wep, key_not_found);
+       DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
+       DEBUGFS_FWSTATS_ADD(wep, packets);
+       DEBUGFS_FWSTATS_ADD(wep, interrupt);
+
+       DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
+       DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
+       DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
+       DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
+       DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
+       DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
+       DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
+       DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
+       DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
+       DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
+       DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
+       DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
+       /* skipping cont_miss_bcns_spread for now */
+       DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
+
+       DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
+       DEBUGFS_FWSTATS_ADD(mic, calc_failure);
+
+       DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
+       DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
+       DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
+       DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
+       DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
+       DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
+
+       DEBUGFS_FWSTATS_ADD(event, heart_beat);
+       DEBUGFS_FWSTATS_ADD(event, calibration);
+       DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
+       DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
+       DEBUGFS_FWSTATS_ADD(event, rx_pool);
+       DEBUGFS_FWSTATS_ADD(event, oom_late);
+       DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
+       DEBUGFS_FWSTATS_ADD(event, tx_stuck);
+
+       DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
+       DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
+       DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
+       DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
+       DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
+       DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
+       DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
+
+       DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
+       DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
+       DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
+       DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
+       DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
+
+       DEBUGFS_ADD(tx_queue_len, rootdir);
+       DEBUGFS_ADD(retry_count, rootdir);
+       DEBUGFS_ADD(excessive_retries, rootdir);
+
+       DEBUGFS_ADD(gpio_power, rootdir);
+       DEBUGFS_ADD(start_recovery, rootdir);
+       DEBUGFS_ADD(driver_state, rootdir);
+       DEBUGFS_ADD(vifs_state, rootdir);
+       DEBUGFS_ADD(dtim_interval, rootdir);
+       DEBUGFS_ADD(suspend_dtim_interval, rootdir);
+       DEBUGFS_ADD(beacon_interval, rootdir);
+       DEBUGFS_ADD(beacon_filtering, rootdir);
+       DEBUGFS_ADD(dynamic_ps_timeout, rootdir);
+       DEBUGFS_ADD(forced_ps, rootdir);
+       DEBUGFS_ADD(split_scan_timeout, rootdir);
+
+       streaming = debugfs_create_dir("rx_streaming", rootdir);
+       if (!streaming || IS_ERR(streaming))
+               goto err;
+
+       DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming);
+       DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming);
+
+
+       return 0;
+
+err:
+       if (IS_ERR(entry))
+               ret = PTR_ERR(entry);
+       else
+               ret = -ENOMEM;
+
+       return ret;
+}
+
+void wl1271_debugfs_reset(struct wl1271 *wl)
+{
+       if (!wl->stats.fw_stats)
+               return;
+
+       memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
+       wl->stats.retry_count = 0;
+       wl->stats.excessive_retries = 0;
+}
+
+int wl1271_debugfs_init(struct wl1271 *wl)
+{
+       int ret;
+       struct dentry *rootdir;
+
+       rootdir = debugfs_create_dir(KBUILD_MODNAME,
+                                    wl->hw->wiphy->debugfsdir);
+
+       if (IS_ERR(rootdir)) {
+               ret = PTR_ERR(rootdir);
+               goto err;
+       }
+
+       wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
+                                     GFP_KERNEL);
+
+       if (!wl->stats.fw_stats) {
+               ret = -ENOMEM;
+               goto err_fw;
+       }
+
+       wl->stats.fw_stats_update = jiffies;
+
+       ret = wl1271_debugfs_add_files(wl, rootdir);
+
+       if (ret < 0)
+               goto err_file;
+
+       return 0;
+
+err_file:
+       kfree(wl->stats.fw_stats);
+       wl->stats.fw_stats = NULL;
+
+err_fw:
+       debugfs_remove_recursive(rootdir);
+
+err:
+       return ret;
+}
+
+void wl1271_debugfs_exit(struct wl1271 *wl)
+{
+       kfree(wl->stats.fw_stats);
+       wl->stats.fw_stats = NULL;
+}
diff --git a/drivers/net/wireless/ti/wlcore/debugfs.h b/drivers/net/wireless/ti/wlcore/debugfs.h
new file mode 100644 (file)
index 0000000..a8d3aef
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __DEBUGFS_H__
+#define __DEBUGFS_H__
+
+#include "wlcore.h"
+
+int wl1271_debugfs_init(struct wl1271 *wl);
+void wl1271_debugfs_exit(struct wl1271 *wl);
+void wl1271_debugfs_reset(struct wl1271 *wl);
+
+#endif /* WL1271_DEBUGFS_H */
diff --git a/drivers/net/wireless/ti/wlcore/event.c b/drivers/net/wireless/ti/wlcore/event.c
new file mode 100644 (file)
index 0000000..292632d
--- /dev/null
@@ -0,0 +1,306 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "wlcore.h"
+#include "debug.h"
+#include "io.h"
+#include "event.h"
+#include "ps.h"
+#include "scan.h"
+#include "wl12xx_80211.h"
+
+static void wl1271_event_rssi_trigger(struct wl1271 *wl,
+                                     struct wl12xx_vif *wlvif,
+                                     struct event_mailbox *mbox)
+{
+       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+       enum nl80211_cqm_rssi_threshold_event event;
+       s8 metric = mbox->rssi_snr_trigger_metric[0];
+
+       wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
+
+       if (metric <= wlvif->rssi_thold)
+               event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
+       else
+               event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
+
+       if (event != wlvif->last_rssi_event)
+               ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
+       wlvif->last_rssi_event = event;
+}
+
+static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+
+       if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
+               if (!wlvif->sta.ba_rx_bitmap)
+                       return;
+               ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
+                                            vif->bss_conf.bssid);
+       } else {
+               u8 hlid;
+               struct wl1271_link *lnk;
+               for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
+                                WL12XX_MAX_LINKS) {
+                       lnk = &wl->links[hlid];
+                       if (!lnk->ba_bitmap)
+                               continue;
+
+                       ieee80211_stop_rx_ba_session(vif,
+                                                    lnk->ba_bitmap,
+                                                    lnk->addr);
+               }
+       }
+}
+
+static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
+                                              u8 enable)
+{
+       struct wl12xx_vif *wlvif;
+
+       if (enable) {
+               set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
+       } else {
+               clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
+               wl12xx_for_each_wlvif_sta(wl, wlvif) {
+                       wl1271_recalc_rx_streaming(wl, wlvif);
+               }
+       }
+
+}
+
+static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
+{
+       wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
+       wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
+       wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
+}
+
+static int wl1271_event_process(struct wl1271 *wl)
+{
+       struct event_mailbox *mbox = wl->mbox;
+       struct ieee80211_vif *vif;
+       struct wl12xx_vif *wlvif;
+       u32 vector;
+       bool beacon_loss = false;
+       bool disconnect_sta = false;
+       unsigned long sta_bitmap = 0;
+
+       wl1271_event_mbox_dump(mbox);
+
+       vector = le32_to_cpu(mbox->events_vector);
+       vector &= ~(le32_to_cpu(mbox->events_mask));
+       wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
+
+       if (vector & SCAN_COMPLETE_EVENT_ID) {
+               wl1271_debug(DEBUG_EVENT, "status: 0x%x",
+                            mbox->scheduled_scan_status);
+
+               wl1271_scan_stm(wl, wl->scan_vif);
+       }
+
+       if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
+               wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
+                            "(status 0x%0x)", mbox->scheduled_scan_status);
+
+               wl1271_scan_sched_scan_results(wl);
+       }
+
+       if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) {
+               wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT "
+                            "(status 0x%0x)", mbox->scheduled_scan_status);
+               if (wl->sched_scanning) {
+                       ieee80211_sched_scan_stopped(wl->hw);
+                       wl->sched_scanning = false;
+               }
+       }
+
+       if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
+               wl12xx_event_soft_gemini_sense(wl,
+                                              mbox->soft_gemini_sense_info);
+
+       /*
+        * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
+        * filtering) is enabled. Without PSM, the stack will receive all
+        * beacons and can detect beacon loss by itself.
+        *
+        * As there's possibility that the driver disables PSM before receiving
+        * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
+        *
+        */
+       if (vector & BSS_LOSE_EVENT_ID) {
+               /* TODO: check for multi-role */
+               wl1271_info("Beacon loss detected.");
+
+               /* indicate to the stack, that beacons have been lost */
+               beacon_loss = true;
+       }
+
+       if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
+               /* TODO: check actual multi-role support */
+               wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
+               wl12xx_for_each_wlvif_sta(wl, wlvif) {
+                       wl1271_event_rssi_trigger(wl, wlvif, mbox);
+               }
+       }
+
+       if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
+               u8 role_id = mbox->role_id;
+               wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
+                            "ba_allowed = 0x%x, role_id=%d",
+                            mbox->rx_ba_allowed, role_id);
+
+               wl12xx_for_each_wlvif(wl, wlvif) {
+                       if (role_id != 0xff && role_id != wlvif->role_id)
+                               continue;
+
+                       wlvif->ba_allowed = !!mbox->rx_ba_allowed;
+                       if (!wlvif->ba_allowed)
+                               wl1271_stop_ba_event(wl, wlvif);
+               }
+       }
+
+       if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
+               wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
+                                         "status = 0x%x",
+                                         mbox->channel_switch_status);
+               /*
+                * That event uses for two cases:
+                * 1) channel switch complete with status=0
+                * 2) channel switch failed status=1
+                */
+
+               /* TODO: configure only the relevant vif */
+               wl12xx_for_each_wlvif_sta(wl, wlvif) {
+                       bool success;
+
+                       if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
+                                               &wlvif->flags))
+                               continue;
+
+                       success = mbox->channel_switch_status ? false : true;
+                       vif = wl12xx_wlvif_to_vif(wlvif);
+
+                       ieee80211_chswitch_done(vif, success);
+               }
+       }
+
+       if ((vector & DUMMY_PACKET_EVENT_ID)) {
+               wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
+               wl1271_tx_dummy_packet(wl);
+       }
+
+       /*
+        * "TX retries exceeded" has a different meaning according to mode.
+        * In AP mode the offending station is disconnected.
+        */
+       if (vector & MAX_TX_RETRY_EVENT_ID) {
+               wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
+               sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
+               disconnect_sta = true;
+       }
+
+       if (vector & INACTIVE_STA_EVENT_ID) {
+               wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
+               sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
+               disconnect_sta = true;
+       }
+
+       if (disconnect_sta) {
+               u32 num_packets = wl->conf.tx.max_tx_retries;
+               struct ieee80211_sta *sta;
+               const u8 *addr;
+               int h;
+
+               for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
+                       bool found = false;
+                       /* find the ap vif connected to this sta */
+                       wl12xx_for_each_wlvif_ap(wl, wlvif) {
+                               if (!test_bit(h, wlvif->ap.sta_hlid_map))
+                                       continue;
+                               found = true;
+                               break;
+                       }
+                       if (!found)
+                               continue;
+
+                       vif = wl12xx_wlvif_to_vif(wlvif);
+                       addr = wl->links[h].addr;
+
+                       rcu_read_lock();
+                       sta = ieee80211_find_sta(vif, addr);
+                       if (sta) {
+                               wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
+                               ieee80211_report_low_ack(sta, num_packets);
+                       }
+                       rcu_read_unlock();
+               }
+       }
+
+       if (beacon_loss)
+               wl12xx_for_each_wlvif_sta(wl, wlvif) {
+                       vif = wl12xx_wlvif_to_vif(wlvif);
+                       ieee80211_connection_loss(vif);
+               }
+
+       return 0;
+}
+
+int wl1271_event_unmask(struct wl1271 *wl)
+{
+       int ret;
+
+       ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
+{
+       int ret;
+
+       wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
+
+       if (mbox_num > 1)
+               return -EINVAL;
+
+       /* first we read the mbox descriptor */
+       wl1271_read(wl, wl->mbox_ptr[mbox_num], wl->mbox,
+                   sizeof(*wl->mbox), false);
+
+       /* process the descriptor */
+       ret = wl1271_event_process(wl);
+       if (ret < 0)
+               return ret;
+
+       /*
+        * TODO: we just need this because one bit is in a different
+        * place.  Is there any better way?
+        */
+       wl->ops->ack_event(wl);
+
+       return 0;
+}
diff --git a/drivers/net/wireless/ti/wlcore/event.h b/drivers/net/wireless/ti/wlcore/event.h
new file mode 100644 (file)
index 0000000..8adf18d
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __EVENT_H__
+#define __EVENT_H__
+
+/*
+ * Mbox events
+ *
+ * The event mechanism is based on a pair of event buffers (buffers A and
+ * B) at fixed locations in the target's memory. The host processes one
+ * buffer while the other buffer continues to collect events. If the host
+ * is not processing events, an interrupt is issued to signal that a buffer
+ * is ready. Once the host is done with processing events from one buffer,
+ * it signals the target (with an ACK interrupt) that the event buffer is
+ * free.
+ */
+
+enum {
+       RSSI_SNR_TRIGGER_0_EVENT_ID              = BIT(0),
+       RSSI_SNR_TRIGGER_1_EVENT_ID              = BIT(1),
+       RSSI_SNR_TRIGGER_2_EVENT_ID              = BIT(2),
+       RSSI_SNR_TRIGGER_3_EVENT_ID              = BIT(3),
+       RSSI_SNR_TRIGGER_4_EVENT_ID              = BIT(4),
+       RSSI_SNR_TRIGGER_5_EVENT_ID              = BIT(5),
+       RSSI_SNR_TRIGGER_6_EVENT_ID              = BIT(6),
+       RSSI_SNR_TRIGGER_7_EVENT_ID              = BIT(7),
+       MEASUREMENT_START_EVENT_ID               = BIT(8),
+       MEASUREMENT_COMPLETE_EVENT_ID            = BIT(9),
+       SCAN_COMPLETE_EVENT_ID                   = BIT(10),
+       WFD_DISCOVERY_COMPLETE_EVENT_ID          = BIT(11),
+       AP_DISCOVERY_COMPLETE_EVENT_ID           = BIT(12),
+       RESERVED1                                = BIT(13),
+       PSPOLL_DELIVERY_FAILURE_EVENT_ID         = BIT(14),
+       ROLE_STOP_COMPLETE_EVENT_ID              = BIT(15),
+       RADAR_DETECTED_EVENT_ID                  = BIT(16),
+       CHANNEL_SWITCH_COMPLETE_EVENT_ID         = BIT(17),
+       BSS_LOSE_EVENT_ID                        = BIT(18),
+       REGAINED_BSS_EVENT_ID                    = BIT(19),
+       MAX_TX_RETRY_EVENT_ID                    = BIT(20),
+       DUMMY_PACKET_EVENT_ID                    = BIT(21),
+       SOFT_GEMINI_SENSE_EVENT_ID               = BIT(22),
+       CHANGE_AUTO_MODE_TIMEOUT_EVENT_ID        = BIT(23),
+       SOFT_GEMINI_AVALANCHE_EVENT_ID           = BIT(24),
+       PLT_RX_CALIBRATION_COMPLETE_EVENT_ID     = BIT(25),
+       INACTIVE_STA_EVENT_ID                    = BIT(26),
+       PEER_REMOVE_COMPLETE_EVENT_ID            = BIT(27),
+       PERIODIC_SCAN_COMPLETE_EVENT_ID          = BIT(28),
+       PERIODIC_SCAN_REPORT_EVENT_ID            = BIT(29),
+       BA_SESSION_RX_CONSTRAINT_EVENT_ID        = BIT(30),
+       REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID      = BIT(31),
+       EVENT_MBOX_ALL_EVENT_ID                  = 0x7fffffff,
+};
+
+enum {
+       EVENT_ENTER_POWER_SAVE_FAIL = 0,
+       EVENT_ENTER_POWER_SAVE_SUCCESS,
+};
+
+#define NUM_OF_RSSI_SNR_TRIGGERS 8
+
+struct event_mailbox {
+       __le32 events_vector;
+       __le32 events_mask;
+       __le32 reserved_1;
+       __le32 reserved_2;
+
+       u8 number_of_scan_results;
+       u8 scan_tag;
+       u8 completed_scan_status;
+       u8 reserved_3;
+
+       u8 soft_gemini_sense_info;
+       u8 soft_gemini_protective_info;
+       s8 rssi_snr_trigger_metric[NUM_OF_RSSI_SNR_TRIGGERS];
+       u8 change_auto_mode_timeout;
+       u8 scheduled_scan_status;
+       u8 reserved4;
+       /* tuned channel (roc) */
+       u8 roc_channel;
+
+       __le16 hlid_removed_bitmap;
+
+       /* bitmap of aged stations (by HLID) */
+       __le16 sta_aging_status;
+
+       /* bitmap of stations (by HLID) which exceeded max tx retries */
+       __le16 sta_tx_retry_exceeded;
+
+       /* discovery completed results */
+       u8 discovery_tag;
+       u8 number_of_preq_results;
+       u8 number_of_prsp_results;
+       u8 reserved_5;
+
+       /* rx ba constraint */
+       u8 role_id; /* 0xFF means any role. */
+       u8 rx_ba_allowed;
+       u8 reserved_6[2];
+
+       /* Channel switch results */
+
+       u8 channel_switch_role_id;
+       u8 channel_switch_status;
+       u8 reserved_7[2];
+
+       u8 ps_poll_delivery_failure_role_ids;
+       u8 stopped_role_ids;
+       u8 started_role_ids;
+
+       u8 reserved_8[9];
+} __packed;
+
+struct wl1271;
+
+int wl1271_event_unmask(struct wl1271 *wl);
+int wl1271_event_handle(struct wl1271 *wl, u8 mbox);
+
+#endif
diff --git a/drivers/net/wireless/ti/wlcore/hw_ops.h b/drivers/net/wireless/ti/wlcore/hw_ops.h
new file mode 100644 (file)
index 0000000..9384b4d
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * This file is part of wlcore
+ *
+ * Copyright (C) 2011 Texas Instruments Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WLCORE_HW_OPS_H__
+#define __WLCORE_HW_OPS_H__
+
+#include "wlcore.h"
+#include "rx.h"
+
+static inline u32
+wlcore_hw_calc_tx_blocks(struct wl1271 *wl, u32 len, u32 spare_blks)
+{
+       if (!wl->ops->calc_tx_blocks)
+               BUG_ON(1);
+
+       return wl->ops->calc_tx_blocks(wl, len, spare_blks);
+}
+
+static inline void
+wlcore_hw_set_tx_desc_blocks(struct wl1271 *wl, struct wl1271_tx_hw_descr *desc,
+                            u32 blks, u32 spare_blks)
+{
+       if (!wl->ops->set_tx_desc_blocks)
+               BUG_ON(1);
+
+       return wl->ops->set_tx_desc_blocks(wl, desc, blks, spare_blks);
+}
+
+static inline void
+wlcore_hw_set_tx_desc_data_len(struct wl1271 *wl,
+                              struct wl1271_tx_hw_descr *desc,
+                              struct sk_buff *skb)
+{
+       if (!wl->ops->set_tx_desc_data_len)
+               BUG_ON(1);
+
+       wl->ops->set_tx_desc_data_len(wl, desc, skb);
+}
+
+static inline enum wl_rx_buf_align
+wlcore_hw_get_rx_buf_align(struct wl1271 *wl, u32 rx_desc)
+{
+
+       if (!wl->ops->get_rx_buf_align)
+               BUG_ON(1);
+
+       return wl->ops->get_rx_buf_align(wl, rx_desc);
+}
+
+static inline void
+wlcore_hw_prepare_read(struct wl1271 *wl, u32 rx_desc, u32 len)
+{
+       if (wl->ops->prepare_read)
+               wl->ops->prepare_read(wl, rx_desc, len);
+}
+
+static inline u32
+wlcore_hw_get_rx_packet_len(struct wl1271 *wl, void *rx_data, u32 data_len)
+{
+       if (!wl->ops->get_rx_packet_len)
+               BUG_ON(1);
+
+       return wl->ops->get_rx_packet_len(wl, rx_data, data_len);
+}
+
+static inline void wlcore_hw_tx_delayed_compl(struct wl1271 *wl)
+{
+       if (wl->ops->tx_delayed_compl)
+               wl->ops->tx_delayed_compl(wl);
+}
+
+static inline void wlcore_hw_tx_immediate_compl(struct wl1271 *wl)
+{
+       if (wl->ops->tx_immediate_compl)
+               wl->ops->tx_immediate_compl(wl);
+}
+
+static inline int
+wlcore_hw_init_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       if (wl->ops->init_vif)
+               return wl->ops->init_vif(wl, wlvif);
+
+       return 0;
+}
+
+static inline u32
+wlcore_hw_sta_get_ap_rate_mask(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       if (!wl->ops->sta_get_ap_rate_mask)
+               BUG_ON(1);
+
+       return wl->ops->sta_get_ap_rate_mask(wl, wlvif);
+}
+
+static inline int wlcore_identify_fw(struct wl1271 *wl)
+{
+       if (wl->ops->identify_fw)
+               return wl->ops->identify_fw(wl);
+
+       return 0;
+}
+
+#endif
diff --git a/drivers/net/wireless/ti/wlcore/ini.h b/drivers/net/wireless/ti/wlcore/ini.h
new file mode 100644 (file)
index 0000000..4cf9ecc
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2010 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __INI_H__
+#define __INI_H__
+
+#define GENERAL_SETTINGS_DRPW_LPD 0xc0
+#define SCRATCH_ENABLE_LPD        BIT(25)
+
+#define WL1271_INI_MAX_SMART_REFLEX_PARAM 16
+
+struct wl1271_ini_general_params {
+       u8 ref_clock;
+       u8 settling_time;
+       u8 clk_valid_on_wakeup;
+       u8 dc2dc_mode;
+       u8 dual_mode_select;
+       u8 tx_bip_fem_auto_detect;
+       u8 tx_bip_fem_manufacturer;
+       u8 general_settings;
+       u8 sr_state;
+       u8 srf1[WL1271_INI_MAX_SMART_REFLEX_PARAM];
+       u8 srf2[WL1271_INI_MAX_SMART_REFLEX_PARAM];
+       u8 srf3[WL1271_INI_MAX_SMART_REFLEX_PARAM];
+} __packed;
+
+#define WL128X_INI_MAX_SETTINGS_PARAM 4
+
+struct wl128x_ini_general_params {
+       u8 ref_clock;
+       u8 settling_time;
+       u8 clk_valid_on_wakeup;
+       u8 tcxo_ref_clock;
+       u8 tcxo_settling_time;
+       u8 tcxo_valid_on_wakeup;
+       u8 tcxo_ldo_voltage;
+       u8 xtal_itrim_val;
+       u8 platform_conf;
+       u8 dual_mode_select;
+       u8 tx_bip_fem_auto_detect;
+       u8 tx_bip_fem_manufacturer;
+       u8 general_settings[WL128X_INI_MAX_SETTINGS_PARAM];
+       u8 sr_state;
+       u8 srf1[WL1271_INI_MAX_SMART_REFLEX_PARAM];
+       u8 srf2[WL1271_INI_MAX_SMART_REFLEX_PARAM];
+       u8 srf3[WL1271_INI_MAX_SMART_REFLEX_PARAM];
+} __packed;
+
+#define WL1271_INI_RSSI_PROCESS_COMPENS_SIZE 15
+
+struct wl1271_ini_band_params_2 {
+       u8 rx_trace_insertion_loss;
+       u8 tx_trace_loss;
+       u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
+} __packed;
+
+#define WL1271_INI_CHANNEL_COUNT_2 14
+
+struct wl128x_ini_band_params_2 {
+       u8 rx_trace_insertion_loss;
+       u8 tx_trace_loss[WL1271_INI_CHANNEL_COUNT_2];
+       u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
+} __packed;
+
+#define WL1271_INI_RATE_GROUP_COUNT 6
+
+struct wl1271_ini_fem_params_2 {
+       __le16 tx_bip_ref_pd_voltage;
+       u8 tx_bip_ref_power;
+       u8 tx_bip_ref_offset;
+       u8 tx_per_rate_pwr_limits_normal[WL1271_INI_RATE_GROUP_COUNT];
+       u8 tx_per_rate_pwr_limits_degraded[WL1271_INI_RATE_GROUP_COUNT];
+       u8 tx_per_rate_pwr_limits_extreme[WL1271_INI_RATE_GROUP_COUNT];
+       u8 tx_per_chan_pwr_limits_11b[WL1271_INI_CHANNEL_COUNT_2];
+       u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_2];
+       u8 tx_pd_vs_rate_offsets[WL1271_INI_RATE_GROUP_COUNT];
+       u8 tx_ibias[WL1271_INI_RATE_GROUP_COUNT];
+       u8 rx_fem_insertion_loss;
+       u8 degraded_low_to_normal_thr;
+       u8 normal_to_degraded_high_thr;
+} __packed;
+
+#define WL128X_INI_RATE_GROUP_COUNT 7
+/* low and high temperatures */
+#define WL128X_INI_PD_VS_TEMPERATURE_RANGES 2
+
+struct wl128x_ini_fem_params_2 {
+       __le16 tx_bip_ref_pd_voltage;
+       u8 tx_bip_ref_power;
+       u8 tx_bip_ref_offset;
+       u8 tx_per_rate_pwr_limits_normal[WL128X_INI_RATE_GROUP_COUNT];
+       u8 tx_per_rate_pwr_limits_degraded[WL128X_INI_RATE_GROUP_COUNT];
+       u8 tx_per_rate_pwr_limits_extreme[WL128X_INI_RATE_GROUP_COUNT];
+       u8 tx_per_chan_pwr_limits_11b[WL1271_INI_CHANNEL_COUNT_2];
+       u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_2];
+       u8 tx_pd_vs_rate_offsets[WL128X_INI_RATE_GROUP_COUNT];
+       u8 tx_ibias[WL128X_INI_RATE_GROUP_COUNT + 1];
+       u8 tx_pd_vs_chan_offsets[WL1271_INI_CHANNEL_COUNT_2];
+       u8 tx_pd_vs_temperature[WL128X_INI_PD_VS_TEMPERATURE_RANGES];
+       u8 rx_fem_insertion_loss;
+       u8 degraded_low_to_normal_thr;
+       u8 normal_to_degraded_high_thr;
+} __packed;
+
+#define WL1271_INI_CHANNEL_COUNT_5 35
+#define WL1271_INI_SUB_BAND_COUNT_5 7
+
+struct wl1271_ini_band_params_5 {
+       u8 rx_trace_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
+       u8 tx_trace_loss[WL1271_INI_SUB_BAND_COUNT_5];
+       u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
+} __packed;
+
+struct wl128x_ini_band_params_5 {
+       u8 rx_trace_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
+       u8 tx_trace_loss[WL1271_INI_CHANNEL_COUNT_5];
+       u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
+} __packed;
+
+struct wl1271_ini_fem_params_5 {
+       __le16 tx_bip_ref_pd_voltage[WL1271_INI_SUB_BAND_COUNT_5];
+       u8 tx_bip_ref_power[WL1271_INI_SUB_BAND_COUNT_5];
+       u8 tx_bip_ref_offset[WL1271_INI_SUB_BAND_COUNT_5];
+       u8 tx_per_rate_pwr_limits_normal[WL1271_INI_RATE_GROUP_COUNT];
+       u8 tx_per_rate_pwr_limits_degraded[WL1271_INI_RATE_GROUP_COUNT];
+       u8 tx_per_rate_pwr_limits_extreme[WL1271_INI_RATE_GROUP_COUNT];
+       u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_5];
+       u8 tx_pd_vs_rate_offsets[WL1271_INI_RATE_GROUP_COUNT];
+       u8 tx_ibias[WL1271_INI_RATE_GROUP_COUNT];
+       u8 rx_fem_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
+       u8 degraded_low_to_normal_thr;
+       u8 normal_to_degraded_high_thr;
+} __packed;
+
+struct wl128x_ini_fem_params_5 {
+       __le16 tx_bip_ref_pd_voltage[WL1271_INI_SUB_BAND_COUNT_5];
+       u8 tx_bip_ref_power[WL1271_INI_SUB_BAND_COUNT_5];
+       u8 tx_bip_ref_offset[WL1271_INI_SUB_BAND_COUNT_5];
+       u8 tx_per_rate_pwr_limits_normal[WL128X_INI_RATE_GROUP_COUNT];
+       u8 tx_per_rate_pwr_limits_degraded[WL128X_INI_RATE_GROUP_COUNT];
+       u8 tx_per_rate_pwr_limits_extreme[WL128X_INI_RATE_GROUP_COUNT];
+       u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_5];
+       u8 tx_pd_vs_rate_offsets[WL128X_INI_RATE_GROUP_COUNT];
+       u8 tx_ibias[WL128X_INI_RATE_GROUP_COUNT];
+       u8 tx_pd_vs_chan_offsets[WL1271_INI_CHANNEL_COUNT_5];
+       u8 tx_pd_vs_temperature[WL1271_INI_SUB_BAND_COUNT_5 *
+               WL128X_INI_PD_VS_TEMPERATURE_RANGES];
+       u8 rx_fem_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
+       u8 degraded_low_to_normal_thr;
+       u8 normal_to_degraded_high_thr;
+} __packed;
+
+/* NVS data structure */
+#define WL1271_INI_NVS_SECTION_SIZE                 468
+#define WL1271_INI_FEM_MODULE_COUNT                  2
+
+#define WL1271_INI_LEGACY_NVS_FILE_SIZE              800
+
+struct wl1271_nvs_file {
+       /* NVS section - must be first! */
+       u8 nvs[WL1271_INI_NVS_SECTION_SIZE];
+
+       /* INI section */
+       struct wl1271_ini_general_params general_params;
+       u8 padding1;
+       struct wl1271_ini_band_params_2 stat_radio_params_2;
+       u8 padding2;
+       struct {
+               struct wl1271_ini_fem_params_2 params;
+               u8 padding;
+       } dyn_radio_params_2[WL1271_INI_FEM_MODULE_COUNT];
+       struct wl1271_ini_band_params_5 stat_radio_params_5;
+       u8 padding3;
+       struct {
+               struct wl1271_ini_fem_params_5 params;
+               u8 padding;
+       } dyn_radio_params_5[WL1271_INI_FEM_MODULE_COUNT];
+} __packed;
+
+struct wl128x_nvs_file {
+       /* NVS section - must be first! */
+       u8 nvs[WL1271_INI_NVS_SECTION_SIZE];
+
+       /* INI section */
+       struct wl128x_ini_general_params general_params;
+       u8 fem_vendor_and_options;
+       struct wl128x_ini_band_params_2 stat_radio_params_2;
+       u8 padding2;
+       struct {
+               struct wl128x_ini_fem_params_2 params;
+               u8 padding;
+       } dyn_radio_params_2[WL1271_INI_FEM_MODULE_COUNT];
+       struct wl128x_ini_band_params_5 stat_radio_params_5;
+       u8 padding3;
+       struct {
+               struct wl128x_ini_fem_params_5 params;
+               u8 padding;
+       } dyn_radio_params_5[WL1271_INI_FEM_MODULE_COUNT];
+} __packed;
+#endif
diff --git a/drivers/net/wireless/ti/wlcore/init.c b/drivers/net/wireless/ti/wlcore/init.c
new file mode 100644 (file)
index 0000000..9f89255
--- /dev/null
@@ -0,0 +1,737 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+
+#include "debug.h"
+#include "init.h"
+#include "wl12xx_80211.h"
+#include "acx.h"
+#include "cmd.h"
+#include "tx.h"
+#include "io.h"
+#include "hw_ops.h"
+
+int wl1271_init_templates_config(struct wl1271 *wl)
+{
+       int ret, i;
+       size_t max_size;
+
+       /* send empty templates for fw memory reservation */
+       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
+                                     CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
+                                     WL1271_CMD_TEMPL_MAX_SIZE,
+                                     0, WL1271_RATE_AUTOMATIC);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
+                                     CMD_TEMPL_CFG_PROBE_REQ_5,
+                                     NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
+                                     WL1271_RATE_AUTOMATIC);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
+                                     CMD_TEMPL_NULL_DATA, NULL,
+                                     sizeof(struct wl12xx_null_data_template),
+                                     0, WL1271_RATE_AUTOMATIC);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
+                                     CMD_TEMPL_PS_POLL, NULL,
+                                     sizeof(struct wl12xx_ps_poll_template),
+                                     0, WL1271_RATE_AUTOMATIC);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
+                                     CMD_TEMPL_QOS_NULL_DATA, NULL,
+                                     sizeof
+                                     (struct ieee80211_qos_hdr),
+                                     0, WL1271_RATE_AUTOMATIC);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
+                                     CMD_TEMPL_PROBE_RESPONSE, NULL,
+                                     WL1271_CMD_TEMPL_DFLT_SIZE,
+                                     0, WL1271_RATE_AUTOMATIC);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
+                                     CMD_TEMPL_BEACON, NULL,
+                                     WL1271_CMD_TEMPL_DFLT_SIZE,
+                                     0, WL1271_RATE_AUTOMATIC);
+       if (ret < 0)
+               return ret;
+
+       max_size = sizeof(struct wl12xx_arp_rsp_template) +
+                  WL1271_EXTRA_SPACE_MAX;
+       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
+                                     CMD_TEMPL_ARP_RSP, NULL,
+                                     max_size,
+                                     0, WL1271_RATE_AUTOMATIC);
+       if (ret < 0)
+               return ret;
+
+       /*
+        * Put very large empty placeholders for all templates. These
+        * reserve memory for later.
+        */
+       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
+                                     CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
+                                     WL1271_CMD_TEMPL_MAX_SIZE,
+                                     0, WL1271_RATE_AUTOMATIC);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
+                                     CMD_TEMPL_AP_BEACON, NULL,
+                                     WL1271_CMD_TEMPL_MAX_SIZE,
+                                     0, WL1271_RATE_AUTOMATIC);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
+                                     CMD_TEMPL_DEAUTH_AP, NULL,
+                                     sizeof
+                                     (struct wl12xx_disconn_template),
+                                     0, WL1271_RATE_AUTOMATIC);
+       if (ret < 0)
+               return ret;
+
+       for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
+               ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
+                                             CMD_TEMPL_KLV, NULL,
+                                             sizeof(struct ieee80211_qos_hdr),
+                                             i, WL1271_RATE_AUTOMATIC);
+               if (ret < 0)
+                       return ret;
+       }
+
+       return 0;
+}
+
+static int wl1271_ap_init_deauth_template(struct wl1271 *wl,
+                                         struct wl12xx_vif *wlvif)
+{
+       struct wl12xx_disconn_template *tmpl;
+       int ret;
+       u32 rate;
+
+       tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
+       if (!tmpl) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
+                                            IEEE80211_STYPE_DEAUTH);
+
+       rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
+       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
+                                     CMD_TEMPL_DEAUTH_AP,
+                                     tmpl, sizeof(*tmpl), 0, rate);
+
+out:
+       kfree(tmpl);
+       return ret;
+}
+
+static int wl1271_ap_init_null_template(struct wl1271 *wl,
+                                       struct ieee80211_vif *vif)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       struct ieee80211_hdr_3addr *nullfunc;
+       int ret;
+       u32 rate;
+
+       nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
+       if (!nullfunc) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
+                                             IEEE80211_STYPE_NULLFUNC |
+                                             IEEE80211_FCTL_FROMDS);
+
+       /* nullfunc->addr1 is filled by FW */
+
+       memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
+       memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
+
+       rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
+       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
+                                     CMD_TEMPL_NULL_DATA, nullfunc,
+                                     sizeof(*nullfunc), 0, rate);
+
+out:
+       kfree(nullfunc);
+       return ret;
+}
+
+static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
+                                           struct ieee80211_vif *vif)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       struct ieee80211_qos_hdr *qosnull;
+       int ret;
+       u32 rate;
+
+       qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
+       if (!qosnull) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
+                                            IEEE80211_STYPE_QOS_NULLFUNC |
+                                            IEEE80211_FCTL_FROMDS);
+
+       /* qosnull->addr1 is filled by FW */
+
+       memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
+       memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
+
+       rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
+       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
+                                     CMD_TEMPL_QOS_NULL_DATA, qosnull,
+                                     sizeof(*qosnull), 0, rate);
+
+out:
+       kfree(qosnull);
+       return ret;
+}
+
+static int wl12xx_init_rx_config(struct wl1271 *wl)
+{
+       int ret;
+
+       ret = wl1271_acx_rx_msdu_life_time(wl);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static int wl12xx_init_phy_vif_config(struct wl1271 *wl,
+                                           struct wl12xx_vif *wlvif)
+{
+       int ret;
+
+       ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_acx_service_period_timeout(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static int wl1271_init_sta_beacon_filter(struct wl1271 *wl,
+                                        struct wl12xx_vif *wlvif)
+{
+       int ret;
+
+       ret = wl1271_acx_beacon_filter_table(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       /* enable beacon filtering */
+       ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1271_init_pta(struct wl1271 *wl)
+{
+       int ret;
+
+       ret = wl12xx_acx_sg_cfg(wl);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1271_init_energy_detection(struct wl1271 *wl)
+{
+       int ret;
+
+       ret = wl1271_acx_cca_threshold(wl);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static int wl1271_init_beacon_broadcast(struct wl1271 *wl,
+                                       struct wl12xx_vif *wlvif)
+{
+       int ret;
+
+       ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static int wl12xx_init_fwlog(struct wl1271 *wl)
+{
+       int ret;
+
+       if (wl->quirks & WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED)
+               return 0;
+
+       ret = wl12xx_cmd_config_fwlog(wl);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+/* generic sta initialization (non vif-specific) */
+static int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       int ret;
+
+       /* PS config */
+       ret = wl12xx_acx_config_ps(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       /* FM WLAN coexistence */
+       ret = wl1271_acx_fm_coex(wl);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_acx_sta_rate_policies(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
+                                      struct ieee80211_vif *vif)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       int ret, i;
+
+       /* disable all keep-alive templates */
+       for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
+               ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
+                                                  ACX_KEEP_ALIVE_TPL_INVALID);
+               if (ret < 0)
+                       return ret;
+       }
+
+       /* disable the keep-alive feature */
+       ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+/* generic ap initialization (non vif-specific) */
+static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       int ret;
+
+       ret = wl1271_init_ap_rates(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       int ret;
+
+       ret = wl1271_ap_init_deauth_template(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_ap_init_null_template(wl, vif);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_ap_init_qos_null_template(wl, vif);
+       if (ret < 0)
+               return ret;
+
+       /*
+        * when operating as AP we want to receive external beacons for
+        * configuring ERP protection.
+        */
+       ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
+                                     struct ieee80211_vif *vif)
+{
+       return wl1271_ap_init_templates(wl, vif);
+}
+
+int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       int i, ret;
+       struct conf_tx_rate_class rc;
+       u32 supported_rates;
+
+       wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
+                    wlvif->basic_rate_set);
+
+       if (wlvif->basic_rate_set == 0)
+               return -EINVAL;
+
+       rc.enabled_rates = wlvif->basic_rate_set;
+       rc.long_retry_limit = 10;
+       rc.short_retry_limit = 10;
+       rc.aflags = 0;
+       ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
+       if (ret < 0)
+               return ret;
+
+       /* use the min basic rate for AP broadcast/multicast */
+       rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
+       rc.short_retry_limit = 10;
+       rc.long_retry_limit = 10;
+       rc.aflags = 0;
+       ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.bcast_rate_idx);
+       if (ret < 0)
+               return ret;
+
+       /*
+        * If the basic rates contain OFDM rates, use OFDM only
+        * rates for unicast TX as well. Else use all supported rates.
+        */
+       if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
+               supported_rates = CONF_TX_OFDM_RATES;
+       else
+               supported_rates = CONF_TX_AP_ENABLED_RATES;
+
+       /* unconditionally enable HT rates */
+       supported_rates |= CONF_TX_MCS_RATES;
+
+       /* configure unicast TX rate classes */
+       for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
+               rc.enabled_rates = supported_rates;
+               rc.short_retry_limit = 10;
+               rc.long_retry_limit = 10;
+               rc.aflags = 0;
+               ret = wl1271_acx_ap_rate_policy(wl, &rc,
+                                               wlvif->ap.ucast_rate_idx[i]);
+               if (ret < 0)
+                       return ret;
+       }
+
+       return 0;
+}
+
+static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       /* Reset the BA RX indicators */
+       wlvif->ba_allowed = true;
+       wl->ba_rx_session_count = 0;
+
+       /* BA is supported in STA/AP modes */
+       if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
+           wlvif->bss_type != BSS_TYPE_STA_BSS) {
+               wlvif->ba_support = false;
+               return 0;
+       }
+
+       wlvif->ba_support = true;
+
+       /* 802.11n initiator BA session setting */
+       return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
+}
+
+/* vif-specifc initialization */
+static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       int ret;
+
+       ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
+       if (ret < 0)
+               return ret;
+
+       /* Initialize connection monitoring thresholds */
+       ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
+       if (ret < 0)
+               return ret;
+
+       /* Beacon filtering */
+       ret = wl1271_init_sta_beacon_filter(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       /* Beacons and broadcast settings */
+       ret = wl1271_init_beacon_broadcast(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       /* Configure rssi/snr averaging weights */
+       ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+/* vif-specific intialization */
+static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       int ret;
+
+       ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       /* initialize Tx power */
+       ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       struct conf_tx_ac_category *conf_ac;
+       struct conf_tx_tid *conf_tid;
+       bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
+       int ret, i;
+
+       /*
+        * consider all existing roles before configuring psm.
+        * TODO: reconfigure on interface removal.
+        */
+       if (!wl->ap_count) {
+               if (is_ap) {
+                       /* Configure for power always on */
+                       ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
+                       if (ret < 0)
+                               return ret;
+               } else if (!wl->sta_count) {
+                       if (wl->quirks & WLCORE_QUIRK_NO_ELP) {
+                               /* Configure for power always on */
+                               ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
+                               if (ret < 0)
+                                       return ret;
+                       } else {
+                               /* Configure for ELP power saving */
+                               ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
+                               if (ret < 0)
+                                       return ret;
+                       }
+               }
+       }
+
+       /* Mode specific init */
+       if (is_ap) {
+               ret = wl1271_ap_hw_init(wl, wlvif);
+               if (ret < 0)
+                       return ret;
+
+               ret = wl12xx_init_ap_role(wl, wlvif);
+               if (ret < 0)
+                       return ret;
+       } else {
+               ret = wl1271_sta_hw_init(wl, wlvif);
+               if (ret < 0)
+                       return ret;
+
+               ret = wl12xx_init_sta_role(wl, wlvif);
+               if (ret < 0)
+                       return ret;
+       }
+
+       wl12xx_init_phy_vif_config(wl, wlvif);
+
+       /* Default TID/AC configuration */
+       BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
+       for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
+               conf_ac = &wl->conf.tx.ac_conf[i];
+               ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
+                                       conf_ac->cw_min, conf_ac->cw_max,
+                                       conf_ac->aifsn, conf_ac->tx_op_limit);
+               if (ret < 0)
+                       return ret;
+
+               conf_tid = &wl->conf.tx.tid_conf[i];
+               ret = wl1271_acx_tid_cfg(wl, wlvif,
+                                        conf_tid->queue_id,
+                                        conf_tid->channel_type,
+                                        conf_tid->tsid,
+                                        conf_tid->ps_scheme,
+                                        conf_tid->ack_policy,
+                                        conf_tid->apsd_conf[0],
+                                        conf_tid->apsd_conf[1]);
+               if (ret < 0)
+                       return ret;
+       }
+
+       /* Configure HW encryption */
+       ret = wl1271_acx_feature_cfg(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       /* Mode specific init - post mem init */
+       if (is_ap)
+               ret = wl1271_ap_hw_init_post_mem(wl, vif);
+       else
+               ret = wl1271_sta_hw_init_post_mem(wl, vif);
+
+       if (ret < 0)
+               return ret;
+
+       /* Configure initiator BA sessions policies */
+       ret = wl1271_set_ba_policies(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       ret = wlcore_hw_init_vif(wl, wlvif);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+int wl1271_hw_init(struct wl1271 *wl)
+{
+       int ret;
+
+       /* Chip-specific hw init */
+       ret = wl->ops->hw_init(wl);
+       if (ret < 0)
+               return ret;
+
+       /* Init templates */
+       ret = wl1271_init_templates_config(wl);
+       if (ret < 0)
+               return ret;
+
+       ret = wl12xx_acx_mem_cfg(wl);
+       if (ret < 0)
+               return ret;
+
+       /* Configure the FW logger */
+       ret = wl12xx_init_fwlog(wl);
+       if (ret < 0)
+               return ret;
+
+       /* Bluetooth WLAN coexistence */
+       ret = wl1271_init_pta(wl);
+       if (ret < 0)
+               return ret;
+
+       /* Default memory configuration */
+       ret = wl1271_acx_init_mem_config(wl);
+       if (ret < 0)
+               return ret;
+
+       /* RX config */
+       ret = wl12xx_init_rx_config(wl);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       ret = wl1271_acx_dco_itrim_params(wl);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       /* Configure TX patch complete interrupt behavior */
+       ret = wl1271_acx_tx_config_options(wl);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       /* RX complete interrupt pacing */
+       ret = wl1271_acx_init_rx_interrupt(wl);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       /* Energy detection */
+       ret = wl1271_init_energy_detection(wl);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       /* Default fragmentation threshold */
+       ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       /* Enable data path */
+       ret = wl1271_cmd_data_path(wl, 1);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       /* configure PM */
+       ret = wl1271_acx_pm_config(wl);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       ret = wl12xx_acx_set_rate_mgmt_params(wl);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       /* configure hangover */
+       ret = wl12xx_acx_config_hangover(wl);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       return 0;
+
+ out_free_memmap:
+       kfree(wl->target_mem_map);
+       wl->target_mem_map = NULL;
+
+       return ret;
+}
diff --git a/drivers/net/wireless/ti/wlcore/init.h b/drivers/net/wireless/ti/wlcore/init.h
new file mode 100644 (file)
index 0000000..a45fbfd
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __INIT_H__
+#define __INIT_H__
+
+#include "wlcore.h"
+
+int wl1271_hw_init_power_auth(struct wl1271 *wl);
+int wl1271_init_templates_config(struct wl1271 *wl);
+int wl1271_init_pta(struct wl1271 *wl);
+int wl1271_init_energy_detection(struct wl1271 *wl);
+int wl1271_chip_specific_init(struct wl1271 *wl);
+int wl1271_hw_init(struct wl1271 *wl);
+int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif);
+int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif);
+
+#endif
diff --git a/drivers/net/wireless/ti/wlcore/io.c b/drivers/net/wireless/ti/wlcore/io.c
new file mode 100644 (file)
index 0000000..7cd0081
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2008-2010 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+#include <linux/interrupt.h>
+
+#include "wlcore.h"
+#include "debug.h"
+#include "wl12xx_80211.h"
+#include "io.h"
+#include "tx.h"
+
+bool wl1271_set_block_size(struct wl1271 *wl)
+{
+       if (wl->if_ops->set_block_size) {
+               wl->if_ops->set_block_size(wl->dev, WL12XX_BUS_BLOCK_SIZE);
+               return true;
+       }
+
+       return false;
+}
+
+void wlcore_disable_interrupts(struct wl1271 *wl)
+{
+       disable_irq(wl->irq);
+}
+EXPORT_SYMBOL_GPL(wlcore_disable_interrupts);
+
+void wlcore_enable_interrupts(struct wl1271 *wl)
+{
+       enable_irq(wl->irq);
+}
+EXPORT_SYMBOL_GPL(wlcore_enable_interrupts);
+
+int wlcore_translate_addr(struct wl1271 *wl, int addr)
+{
+       struct wlcore_partition_set *part = &wl->curr_part;
+
+       /*
+        * To translate, first check to which window of addresses the
+        * particular address belongs. Then subtract the starting address
+        * of that window from the address. Then, add offset of the
+        * translated region.
+        *
+        * The translated regions occur next to each other in physical device
+        * memory, so just add the sizes of the preceding address regions to
+        * get the offset to the new region.
+        */
+       if ((addr >= part->mem.start) &&
+           (addr < part->mem.start + part->mem.size))
+               return addr - part->mem.start;
+       else if ((addr >= part->reg.start) &&
+                (addr < part->reg.start + part->reg.size))
+               return addr - part->reg.start + part->mem.size;
+       else if ((addr >= part->mem2.start) &&
+                (addr < part->mem2.start + part->mem2.size))
+               return addr - part->mem2.start + part->mem.size +
+                       part->reg.size;
+       else if ((addr >= part->mem3.start) &&
+                (addr < part->mem3.start + part->mem3.size))
+               return addr - part->mem3.start + part->mem.size +
+                       part->reg.size + part->mem2.size;
+
+       WARN(1, "HW address 0x%x out of range", addr);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wlcore_translate_addr);
+
+/* Set the partitions to access the chip addresses
+ *
+ * To simplify driver code, a fixed (virtual) memory map is defined for
+ * register and memory addresses. Because in the chipset, in different stages
+ * of operation, those addresses will move around, an address translation
+ * mechanism is required.
+ *
+ * There are four partitions (three memory and one register partition),
+ * which are mapped to two different areas of the hardware memory.
+ *
+ *                                Virtual address
+ *                                     space
+ *
+ *                                    |    |
+ *                                 ...+----+--> mem.start
+ *          Physical address    ...   |    |
+ *               space       ...      |    | [PART_0]
+ *                        ...         |    |
+ *  00000000  <--+----+...         ...+----+--> mem.start + mem.size
+ *               |    |         ...   |    |
+ *               |MEM |      ...      |    |
+ *               |    |   ...         |    |
+ *  mem.size  <--+----+...            |    | {unused area)
+ *               |    |   ...         |    |
+ *               |REG |      ...      |    |
+ *  mem.size     |    |         ...   |    |
+ *      +     <--+----+...         ...+----+--> reg.start
+ *  reg.size     |    |   ...         |    |
+ *               |MEM2|      ...      |    | [PART_1]
+ *               |    |         ...   |    |
+ *                                 ...+----+--> reg.start + reg.size
+ *                                    |    |
+ *
+ */
+void wlcore_set_partition(struct wl1271 *wl,
+                         const struct wlcore_partition_set *p)
+{
+       /* copy partition info */
+       memcpy(&wl->curr_part, p, sizeof(*p));
+
+       wl1271_debug(DEBUG_IO, "mem_start %08X mem_size %08X",
+                    p->mem.start, p->mem.size);
+       wl1271_debug(DEBUG_IO, "reg_start %08X reg_size %08X",
+                    p->reg.start, p->reg.size);
+       wl1271_debug(DEBUG_IO, "mem2_start %08X mem2_size %08X",
+                    p->mem2.start, p->mem2.size);
+       wl1271_debug(DEBUG_IO, "mem3_start %08X mem3_size %08X",
+                    p->mem3.start, p->mem3.size);
+
+       wl1271_raw_write32(wl, HW_PART0_START_ADDR, p->mem.start);
+       wl1271_raw_write32(wl, HW_PART0_SIZE_ADDR, p->mem.size);
+       wl1271_raw_write32(wl, HW_PART1_START_ADDR, p->reg.start);
+       wl1271_raw_write32(wl, HW_PART1_SIZE_ADDR, p->reg.size);
+       wl1271_raw_write32(wl, HW_PART2_START_ADDR, p->mem2.start);
+       wl1271_raw_write32(wl, HW_PART2_SIZE_ADDR, p->mem2.size);
+       /*
+        * We don't need the size of the last partition, as it is
+        * automatically calculated based on the total memory size and
+        * the sizes of the previous partitions.
+        */
+       wl1271_raw_write32(wl, HW_PART3_START_ADDR, p->mem3.start);
+}
+EXPORT_SYMBOL_GPL(wlcore_set_partition);
+
+void wlcore_select_partition(struct wl1271 *wl, u8 part)
+{
+       wl1271_debug(DEBUG_IO, "setting partition %d", part);
+
+       wlcore_set_partition(wl, &wl->ptable[part]);
+}
+EXPORT_SYMBOL_GPL(wlcore_select_partition);
+
+void wl1271_io_reset(struct wl1271 *wl)
+{
+       if (wl->if_ops->reset)
+               wl->if_ops->reset(wl->dev);
+}
+
+void wl1271_io_init(struct wl1271 *wl)
+{
+       if (wl->if_ops->init)
+               wl->if_ops->init(wl->dev);
+}
diff --git a/drivers/net/wireless/ti/wlcore/io.h b/drivers/net/wireless/ti/wlcore/io.h
new file mode 100644 (file)
index 0000000..8942954
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
+ * Copyright (C) 2008-2010 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __IO_H__
+#define __IO_H__
+
+#include <linux/irqreturn.h>
+
+#define HW_ACCESS_MEMORY_MAX_RANGE     0x1FFC0
+
+#define HW_PARTITION_REGISTERS_ADDR     0x1FFC0
+#define HW_PART0_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR)
+#define HW_PART0_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 4)
+#define HW_PART1_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR + 8)
+#define HW_PART1_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 12)
+#define HW_PART2_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR + 16)
+#define HW_PART2_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 20)
+#define HW_PART3_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 24)
+
+#define HW_ACCESS_REGISTER_SIZE         4
+
+#define HW_ACCESS_PRAM_MAX_RANGE       0x3c000
+
+struct wl1271;
+
+void wlcore_disable_interrupts(struct wl1271 *wl);
+void wlcore_enable_interrupts(struct wl1271 *wl);
+
+void wl1271_io_reset(struct wl1271 *wl);
+void wl1271_io_init(struct wl1271 *wl);
+int wlcore_translate_addr(struct wl1271 *wl, int addr);
+
+/* Raw target IO, address is not translated */
+static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
+                                   size_t len, bool fixed)
+{
+       wl->if_ops->write(wl->dev, addr, buf, len, fixed);
+}
+
+static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
+                                  size_t len, bool fixed)
+{
+       wl->if_ops->read(wl->dev, addr, buf, len, fixed);
+}
+
+static inline void wlcore_raw_read_data(struct wl1271 *wl, int reg, void *buf,
+                                       size_t len, bool fixed)
+{
+       wl1271_raw_read(wl, wl->rtable[reg], buf, len, fixed);
+}
+
+static inline void wlcore_raw_write_data(struct wl1271 *wl, int reg, void *buf,
+                                        size_t len, bool fixed)
+{
+       wl1271_raw_write(wl, wl->rtable[reg], buf, len, fixed);
+}
+
+static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr)
+{
+       wl1271_raw_read(wl, addr, &wl->buffer_32,
+                           sizeof(wl->buffer_32), false);
+
+       return le32_to_cpu(wl->buffer_32);
+}
+
+static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val)
+{
+       wl->buffer_32 = cpu_to_le32(val);
+       wl1271_raw_write(wl, addr, &wl->buffer_32,
+                            sizeof(wl->buffer_32), false);
+}
+
+static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf,
+                              size_t len, bool fixed)
+{
+       int physical;
+
+       physical = wlcore_translate_addr(wl, addr);
+
+       wl1271_raw_read(wl, physical, buf, len, fixed);
+}
+
+static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf,
+                               size_t len, bool fixed)
+{
+       int physical;
+
+       physical = wlcore_translate_addr(wl, addr);
+
+       wl1271_raw_write(wl, physical, buf, len, fixed);
+}
+
+static inline void wlcore_write_data(struct wl1271 *wl, int reg, void *buf,
+                                    size_t len, bool fixed)
+{
+       wl1271_write(wl, wl->rtable[reg], buf, len, fixed);
+}
+
+static inline void wlcore_read_data(struct wl1271 *wl, int reg, void *buf,
+                                   size_t len, bool fixed)
+{
+       wl1271_read(wl, wl->rtable[reg], buf, len, fixed);
+}
+
+static inline void wl1271_read_hwaddr(struct wl1271 *wl, int hwaddr,
+                                     void *buf, size_t len, bool fixed)
+{
+       int physical;
+       int addr;
+
+       /* Addresses are stored internally as addresses to 32 bytes blocks */
+       addr = hwaddr << 5;
+
+       physical = wlcore_translate_addr(wl, addr);
+
+       wl1271_raw_read(wl, physical, buf, len, fixed);
+}
+
+static inline u32 wl1271_read32(struct wl1271 *wl, int addr)
+{
+       return wl1271_raw_read32(wl, wlcore_translate_addr(wl, addr));
+}
+
+static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
+{
+       wl1271_raw_write32(wl, wlcore_translate_addr(wl, addr), val);
+}
+
+static inline u32 wlcore_read_reg(struct wl1271 *wl, int reg)
+{
+       return wl1271_raw_read32(wl,
+                                wlcore_translate_addr(wl, wl->rtable[reg]));
+}
+
+static inline void wlcore_write_reg(struct wl1271 *wl, int reg, u32 val)
+{
+       wl1271_raw_write32(wl, wlcore_translate_addr(wl, wl->rtable[reg]), val);
+}
+
+static inline void wl1271_power_off(struct wl1271 *wl)
+{
+       wl->if_ops->power(wl->dev, false);
+       clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
+}
+
+static inline int wl1271_power_on(struct wl1271 *wl)
+{
+       int ret = wl->if_ops->power(wl->dev, true);
+       if (ret == 0)
+               set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
+
+       return ret;
+}
+
+void wlcore_set_partition(struct wl1271 *wl,
+                         const struct wlcore_partition_set *p);
+
+bool wl1271_set_block_size(struct wl1271 *wl);
+
+/* Functions from wl1271_main.c */
+
+int wl1271_tx_dummy_packet(struct wl1271 *wl);
+
+void wlcore_select_partition(struct wl1271 *wl, u8 part);
+
+#endif
diff --git a/drivers/net/wireless/ti/wlcore/main.c b/drivers/net/wireless/ti/wlcore/main.c
new file mode 100644 (file)
index 0000000..2b0f987
--- /dev/null
@@ -0,0 +1,5093 @@
+
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2008-2010 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/firmware.h>
+#include <linux/delay.h>
+#include <linux/spi/spi.h>
+#include <linux/crc32.h>
+#include <linux/etherdevice.h>
+#include <linux/vmalloc.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/wl12xx.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+
+#include "wlcore.h"
+#include "debug.h"
+#include "wl12xx_80211.h"
+#include "io.h"
+#include "event.h"
+#include "tx.h"
+#include "rx.h"
+#include "ps.h"
+#include "init.h"
+#include "debugfs.h"
+#include "cmd.h"
+#include "boot.h"
+#include "testmode.h"
+#include "scan.h"
+#include "hw_ops.h"
+
+#define WL1271_BOOT_RETRIES 3
+
+#define WL1271_BOOT_RETRIES 3
+
+static char *fwlog_param;
+static bool bug_on_recovery;
+static bool no_recovery;
+
+static void __wl1271_op_remove_interface(struct wl1271 *wl,
+                                        struct ieee80211_vif *vif,
+                                        bool reset_tx_queues);
+static void wl1271_op_stop(struct ieee80211_hw *hw);
+static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+
+static int wl12xx_set_authorized(struct wl1271 *wl,
+                                struct wl12xx_vif *wlvif)
+{
+       int ret;
+
+       if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS))
+               return -EINVAL;
+
+       if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
+               return 0;
+
+       if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags))
+               return 0;
+
+       ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid);
+       if (ret < 0)
+               return ret;
+
+       wl12xx_croc(wl, wlvif->role_id);
+
+       wl1271_info("Association completed.");
+       return 0;
+}
+
+static int wl1271_reg_notify(struct wiphy *wiphy,
+                            struct regulatory_request *request)
+{
+       struct ieee80211_supported_band *band;
+       struct ieee80211_channel *ch;
+       int i;
+
+       band = wiphy->bands[IEEE80211_BAND_5GHZ];
+       for (i = 0; i < band->n_channels; i++) {
+               ch = &band->channels[i];
+               if (ch->flags & IEEE80211_CHAN_DISABLED)
+                       continue;
+
+               if (ch->flags & IEEE80211_CHAN_RADAR)
+                       ch->flags |= IEEE80211_CHAN_NO_IBSS |
+                                    IEEE80211_CHAN_PASSIVE_SCAN;
+
+       }
+
+       return 0;
+}
+
+static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                                  bool enable)
+{
+       int ret = 0;
+
+       /* we should hold wl->mutex */
+       ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable);
+       if (ret < 0)
+               goto out;
+
+       if (enable)
+               set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
+       else
+               clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
+out:
+       return ret;
+}
+
+/*
+ * this function is being called when the rx_streaming interval
+ * has beed changed or rx_streaming should be disabled
+ */
+int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       int ret = 0;
+       int period = wl->conf.rx_streaming.interval;
+
+       /* don't reconfigure if rx_streaming is disabled */
+       if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
+               goto out;
+
+       /* reconfigure/disable according to new streaming_period */
+       if (period &&
+           test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
+           (wl->conf.rx_streaming.always ||
+            test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
+               ret = wl1271_set_rx_streaming(wl, wlvif, true);
+       else {
+               ret = wl1271_set_rx_streaming(wl, wlvif, false);
+               /* don't cancel_work_sync since we might deadlock */
+               del_timer_sync(&wlvif->rx_streaming_timer);
+       }
+out:
+       return ret;
+}
+
+static void wl1271_rx_streaming_enable_work(struct work_struct *work)
+{
+       int ret;
+       struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
+                                               rx_streaming_enable_work);
+       struct wl1271 *wl = wlvif->wl;
+
+       mutex_lock(&wl->mutex);
+
+       if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) ||
+           !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
+           (!wl->conf.rx_streaming.always &&
+            !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
+               goto out;
+
+       if (!wl->conf.rx_streaming.interval)
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_set_rx_streaming(wl, wlvif, true);
+       if (ret < 0)
+               goto out_sleep;
+
+       /* stop it after some time of inactivity */
+       mod_timer(&wlvif->rx_streaming_timer,
+                 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
+
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+static void wl1271_rx_streaming_disable_work(struct work_struct *work)
+{
+       int ret;
+       struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
+                                               rx_streaming_disable_work);
+       struct wl1271 *wl = wlvif->wl;
+
+       mutex_lock(&wl->mutex);
+
+       if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_set_rx_streaming(wl, wlvif, false);
+       if (ret)
+               goto out_sleep;
+
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+static void wl1271_rx_streaming_timer(unsigned long data)
+{
+       struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data;
+       struct wl1271 *wl = wlvif->wl;
+       ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work);
+}
+
+/* wl->mutex must be taken */
+void wl12xx_rearm_tx_watchdog_locked(struct wl1271 *wl)
+{
+       /* if the watchdog is not armed, don't do anything */
+       if (wl->tx_allocated_blocks == 0)
+               return;
+
+       cancel_delayed_work(&wl->tx_watchdog_work);
+       ieee80211_queue_delayed_work(wl->hw, &wl->tx_watchdog_work,
+               msecs_to_jiffies(wl->conf.tx.tx_watchdog_timeout));
+}
+
+static void wl12xx_tx_watchdog_work(struct work_struct *work)
+{
+       struct delayed_work *dwork;
+       struct wl1271 *wl;
+
+       dwork = container_of(work, struct delayed_work, work);
+       wl = container_of(dwork, struct wl1271, tx_watchdog_work);
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF))
+               goto out;
+
+       /* Tx went out in the meantime - everything is ok */
+       if (unlikely(wl->tx_allocated_blocks == 0))
+               goto out;
+
+       /*
+        * if a ROC is in progress, we might not have any Tx for a long
+        * time (e.g. pending Tx on the non-ROC channels)
+        */
+       if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) {
+               wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to ROC",
+                            wl->conf.tx.tx_watchdog_timeout);
+               wl12xx_rearm_tx_watchdog_locked(wl);
+               goto out;
+       }
+
+       /*
+        * if a scan is in progress, we might not have any Tx for a long
+        * time
+        */
+       if (wl->scan.state != WL1271_SCAN_STATE_IDLE) {
+               wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to scan",
+                            wl->conf.tx.tx_watchdog_timeout);
+               wl12xx_rearm_tx_watchdog_locked(wl);
+               goto out;
+       }
+
+       /*
+       * AP might cache a frame for a long time for a sleeping station,
+       * so rearm the timer if there's an AP interface with stations. If
+       * Tx is genuinely stuck we will most hopefully discover it when all
+       * stations are removed due to inactivity.
+       */
+       if (wl->active_sta_count) {
+               wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms. AP has "
+                            " %d stations",
+                             wl->conf.tx.tx_watchdog_timeout,
+                             wl->active_sta_count);
+               wl12xx_rearm_tx_watchdog_locked(wl);
+               goto out;
+       }
+
+       wl1271_error("Tx stuck (in FW) for %d ms. Starting recovery",
+                    wl->conf.tx.tx_watchdog_timeout);
+       wl12xx_queue_recovery_work(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+static void wlcore_adjust_conf(struct wl1271 *wl)
+{
+       /* Adjust settings according to optional module parameters */
+       if (fwlog_param) {
+               if (!strcmp(fwlog_param, "continuous")) {
+                       wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
+               } else if (!strcmp(fwlog_param, "ondemand")) {
+                       wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND;
+               } else if (!strcmp(fwlog_param, "dbgpins")) {
+                       wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
+                       wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS;
+               } else if (!strcmp(fwlog_param, "disable")) {
+                       wl->conf.fwlog.mem_blocks = 0;
+                       wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE;
+               } else {
+                       wl1271_error("Unknown fwlog parameter %s", fwlog_param);
+               }
+       }
+}
+
+static int wl1271_plt_init(struct wl1271 *wl)
+{
+       int ret;
+
+       ret = wl->ops->hw_init(wl);
+       if (ret < 0)
+               return ret;
+
+       ret = wl1271_acx_init_mem_config(wl);
+       if (ret < 0)
+               return ret;
+
+       ret = wl12xx_acx_mem_cfg(wl);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       /* Enable data path */
+       ret = wl1271_cmd_data_path(wl, 1);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       /* Configure for CAM power saving (ie. always active) */
+       ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       /* configure PM */
+       ret = wl1271_acx_pm_config(wl);
+       if (ret < 0)
+               goto out_free_memmap;
+
+       return 0;
+
+ out_free_memmap:
+       kfree(wl->target_mem_map);
+       wl->target_mem_map = NULL;
+
+       return ret;
+}
+
+static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
+                                       struct wl12xx_vif *wlvif,
+                                       u8 hlid, u8 tx_pkts)
+{
+       bool fw_ps, single_sta;
+
+       fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
+       single_sta = (wl->active_sta_count == 1);
+
+       /*
+        * Wake up from high level PS if the STA is asleep with too little
+        * packets in FW or if the STA is awake.
+        */
+       if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS)
+               wl12xx_ps_link_end(wl, wlvif, hlid);
+
+       /*
+        * Start high-level PS if the STA is asleep with enough blocks in FW.
+        * Make an exception if this is the only connected station. In this
+        * case FW-memory congestion is not a problem.
+        */
+       else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
+               wl12xx_ps_link_start(wl, wlvif, hlid, true);
+}
+
+static void wl12xx_irq_update_links_status(struct wl1271 *wl,
+                                          struct wl12xx_vif *wlvif,
+                                          struct wl_fw_status *status)
+{
+       struct wl1271_link *lnk;
+       u32 cur_fw_ps_map;
+       u8 hlid, cnt;
+
+       /* TODO: also use link_fast_bitmap here */
+
+       cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
+       if (wl->ap_fw_ps_map != cur_fw_ps_map) {
+               wl1271_debug(DEBUG_PSM,
+                            "link ps prev 0x%x cur 0x%x changed 0x%x",
+                            wl->ap_fw_ps_map, cur_fw_ps_map,
+                            wl->ap_fw_ps_map ^ cur_fw_ps_map);
+
+               wl->ap_fw_ps_map = cur_fw_ps_map;
+       }
+
+       for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) {
+               lnk = &wl->links[hlid];
+               cnt = status->counters.tx_lnk_free_pkts[hlid] -
+                       lnk->prev_freed_pkts;
+
+               lnk->prev_freed_pkts = status->counters.tx_lnk_free_pkts[hlid];
+               lnk->allocated_pkts -= cnt;
+
+               wl12xx_irq_ps_regulate_link(wl, wlvif, hlid,
+                                           lnk->allocated_pkts);
+       }
+}
+
+static void wl12xx_fw_status(struct wl1271 *wl,
+                            struct wl_fw_status *status)
+{
+       struct wl12xx_vif *wlvif;
+       struct timespec ts;
+       u32 old_tx_blk_count = wl->tx_blocks_available;
+       int avail, freed_blocks;
+       int i;
+       size_t status_len;
+
+       status_len = sizeof(*status) + wl->fw_status_priv_len;
+
+       wlcore_raw_read_data(wl, REG_RAW_FW_STATUS_ADDR, status,
+                            status_len, false);
+
+       wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
+                    "drv_rx_counter = %d, tx_results_counter = %d)",
+                    status->intr,
+                    status->fw_rx_counter,
+                    status->drv_rx_counter,
+                    status->tx_results_counter);
+
+       for (i = 0; i < NUM_TX_QUEUES; i++) {
+               /* prevent wrap-around in freed-packets counter */
+               wl->tx_allocated_pkts[i] -=
+                               (status->counters.tx_released_pkts[i] -
+                               wl->tx_pkts_freed[i]) & 0xff;
+
+               wl->tx_pkts_freed[i] = status->counters.tx_released_pkts[i];
+       }
+
+       /* prevent wrap-around in total blocks counter */
+       if (likely(wl->tx_blocks_freed <=
+                  le32_to_cpu(status->total_released_blks)))
+               freed_blocks = le32_to_cpu(status->total_released_blks) -
+                              wl->tx_blocks_freed;
+       else
+               freed_blocks = 0x100000000LL - wl->tx_blocks_freed +
+                              le32_to_cpu(status->total_released_blks);
+
+       wl->tx_blocks_freed = le32_to_cpu(status->total_released_blks);
+
+       wl->tx_allocated_blocks -= freed_blocks;
+
+       /*
+        * If the FW freed some blocks:
+        * If we still have allocated blocks - re-arm the timer, Tx is
+        * not stuck. Otherwise, cancel the timer (no Tx currently).
+        */
+       if (freed_blocks) {
+               if (wl->tx_allocated_blocks)
+                       wl12xx_rearm_tx_watchdog_locked(wl);
+               else
+                       cancel_delayed_work(&wl->tx_watchdog_work);
+       }
+
+       avail = le32_to_cpu(status->tx_total) - wl->tx_allocated_blocks;
+
+       /*
+        * The FW might change the total number of TX memblocks before
+        * we get a notification about blocks being released. Thus, the
+        * available blocks calculation might yield a temporary result
+        * which is lower than the actual available blocks. Keeping in
+        * mind that only blocks that were allocated can be moved from
+        * TX to RX, tx_blocks_available should never decrease here.
+        */
+       wl->tx_blocks_available = max((int)wl->tx_blocks_available,
+                                     avail);
+
+       /* if more blocks are available now, tx work can be scheduled */
+       if (wl->tx_blocks_available > old_tx_blk_count)
+               clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
+
+       /* for AP update num of allocated TX blocks per link and ps status */
+       wl12xx_for_each_wlvif_ap(wl, wlvif) {
+               wl12xx_irq_update_links_status(wl, wlvif, status);
+       }
+
+       /* update the host-chipset time offset */
+       getnstimeofday(&ts);
+       wl->time_offset = (timespec_to_ns(&ts) >> 10) -
+               (s64)le32_to_cpu(status->fw_localtime);
+}
+
+static void wl1271_flush_deferred_work(struct wl1271 *wl)
+{
+       struct sk_buff *skb;
+
+       /* Pass all received frames to the network stack */
+       while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
+               ieee80211_rx_ni(wl->hw, skb);
+
+       /* Return sent skbs to the network stack */
+       while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
+               ieee80211_tx_status_ni(wl->hw, skb);
+}
+
+static void wl1271_netstack_work(struct work_struct *work)
+{
+       struct wl1271 *wl =
+               container_of(work, struct wl1271, netstack_work);
+
+       do {
+               wl1271_flush_deferred_work(wl);
+       } while (skb_queue_len(&wl->deferred_rx_queue));
+}
+
+#define WL1271_IRQ_MAX_LOOPS 256
+
+static irqreturn_t wl1271_irq(int irq, void *cookie)
+{
+       int ret;
+       u32 intr;
+       int loopcount = WL1271_IRQ_MAX_LOOPS;
+       struct wl1271 *wl = (struct wl1271 *)cookie;
+       bool done = false;
+       unsigned int defer_count;
+       unsigned long flags;
+
+       /* TX might be handled here, avoid redundant work */
+       set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
+       cancel_work_sync(&wl->tx_work);
+
+       /*
+        * In case edge triggered interrupt must be used, we cannot iterate
+        * more than once without introducing race conditions with the hardirq.
+        */
+       if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
+               loopcount = 1;
+
+       mutex_lock(&wl->mutex);
+
+       wl1271_debug(DEBUG_IRQ, "IRQ work");
+
+       if (unlikely(wl->state == WL1271_STATE_OFF))
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       while (!done && loopcount--) {
+               /*
+                * In order to avoid a race with the hardirq, clear the flag
+                * before acknowledging the chip. Since the mutex is held,
+                * wl1271_ps_elp_wakeup cannot be called concurrently.
+                */
+               clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
+               smp_mb__after_clear_bit();
+
+               wl12xx_fw_status(wl, wl->fw_status);
+
+               wlcore_hw_tx_immediate_compl(wl);
+
+               intr = le32_to_cpu(wl->fw_status->intr);
+               intr &= WL1271_INTR_MASK;
+               if (!intr) {
+                       done = true;
+                       continue;
+               }
+
+               if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
+                       wl1271_error("watchdog interrupt received! "
+                                    "starting recovery.");
+                       wl12xx_queue_recovery_work(wl);
+
+                       /* restarting the chip. ignore any other interrupt. */
+                       goto out;
+               }
+
+               if (likely(intr & WL1271_ACX_INTR_DATA)) {
+                       wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
+
+                       wl12xx_rx(wl, wl->fw_status);
+
+                       /* Check if any tx blocks were freed */
+                       spin_lock_irqsave(&wl->wl_lock, flags);
+                       if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
+                           wl1271_tx_total_queue_count(wl) > 0) {
+                               spin_unlock_irqrestore(&wl->wl_lock, flags);
+                               /*
+                                * In order to avoid starvation of the TX path,
+                                * call the work function directly.
+                                */
+                               wl1271_tx_work_locked(wl);
+                       } else {
+                               spin_unlock_irqrestore(&wl->wl_lock, flags);
+                       }
+
+                       /* check for tx results */
+                       wlcore_hw_tx_delayed_compl(wl);
+
+                       /* Make sure the deferred queues don't get too long */
+                       defer_count = skb_queue_len(&wl->deferred_tx_queue) +
+                                     skb_queue_len(&wl->deferred_rx_queue);
+                       if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
+                               wl1271_flush_deferred_work(wl);
+               }
+
+               if (intr & WL1271_ACX_INTR_EVENT_A) {
+                       wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
+                       wl1271_event_handle(wl, 0);
+               }
+
+               if (intr & WL1271_ACX_INTR_EVENT_B) {
+                       wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
+                       wl1271_event_handle(wl, 1);
+               }
+
+               if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
+                       wl1271_debug(DEBUG_IRQ,
+                                    "WL1271_ACX_INTR_INIT_COMPLETE");
+
+               if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
+                       wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
+       }
+
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       spin_lock_irqsave(&wl->wl_lock, flags);
+       /* In case TX was not handled here, queue TX work */
+       clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
+       if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
+           wl1271_tx_total_queue_count(wl) > 0)
+               ieee80211_queue_work(wl->hw, &wl->tx_work);
+       spin_unlock_irqrestore(&wl->wl_lock, flags);
+
+       mutex_unlock(&wl->mutex);
+
+       return IRQ_HANDLED;
+}
+
+struct vif_counter_data {
+       u8 counter;
+
+       struct ieee80211_vif *cur_vif;
+       bool cur_vif_running;
+};
+
+static void wl12xx_vif_count_iter(void *data, u8 *mac,
+                                 struct ieee80211_vif *vif)
+{
+       struct vif_counter_data *counter = data;
+
+       counter->counter++;
+       if (counter->cur_vif == vif)
+               counter->cur_vif_running = true;
+}
+
+/* caller must not hold wl->mutex, as it might deadlock */
+static void wl12xx_get_vif_count(struct ieee80211_hw *hw,
+                              struct ieee80211_vif *cur_vif,
+                              struct vif_counter_data *data)
+{
+       memset(data, 0, sizeof(*data));
+       data->cur_vif = cur_vif;
+
+       ieee80211_iterate_active_interfaces(hw,
+                                           wl12xx_vif_count_iter, data);
+}
+
+static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt)
+{
+       const struct firmware *fw;
+       const char *fw_name;
+       enum wl12xx_fw_type fw_type;
+       int ret;
+
+       if (plt) {
+               fw_type = WL12XX_FW_TYPE_PLT;
+               fw_name = wl->plt_fw_name;
+       } else {
+               /*
+                * we can't call wl12xx_get_vif_count() here because
+                * wl->mutex is taken, so use the cached last_vif_count value
+                */
+               if (wl->last_vif_count > 1) {
+                       fw_type = WL12XX_FW_TYPE_MULTI;
+                       fw_name = wl->mr_fw_name;
+               } else {
+                       fw_type = WL12XX_FW_TYPE_NORMAL;
+                       fw_name = wl->sr_fw_name;
+               }
+       }
+
+       if (wl->fw_type == fw_type)
+               return 0;
+
+       wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
+
+       ret = request_firmware(&fw, fw_name, wl->dev);
+
+       if (ret < 0) {
+               wl1271_error("could not get firmware %s: %d", fw_name, ret);
+               return ret;
+       }
+
+       if (fw->size % 4) {
+               wl1271_error("firmware size is not multiple of 32 bits: %zu",
+                            fw->size);
+               ret = -EILSEQ;
+               goto out;
+       }
+
+       vfree(wl->fw);
+       wl->fw_type = WL12XX_FW_TYPE_NONE;
+       wl->fw_len = fw->size;
+       wl->fw = vmalloc(wl->fw_len);
+
+       if (!wl->fw) {
+               wl1271_error("could not allocate memory for the firmware");
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       memcpy(wl->fw, fw->data, wl->fw_len);
+       ret = 0;
+       wl->fw_type = fw_type;
+out:
+       release_firmware(fw);
+
+       return ret;
+}
+
+static int wl1271_fetch_nvs(struct wl1271 *wl)
+{
+       const struct firmware *fw;
+       int ret;
+
+       ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev);
+
+       if (ret < 0) {
+               wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME,
+                            ret);
+               return ret;
+       }
+
+       wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
+
+       if (!wl->nvs) {
+               wl1271_error("could not allocate memory for the nvs file");
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       wl->nvs_len = fw->size;
+
+out:
+       release_firmware(fw);
+
+       return ret;
+}
+
+void wl12xx_queue_recovery_work(struct wl1271 *wl)
+{
+       if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags))
+               ieee80211_queue_work(wl->hw, &wl->recovery_work);
+}
+
+size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen)
+{
+       size_t len = 0;
+
+       /* The FW log is a length-value list, find where the log end */
+       while (len < maxlen) {
+               if (memblock[len] == 0)
+                       break;
+               if (len + memblock[len] + 1 > maxlen)
+                       break;
+               len += memblock[len] + 1;
+       }
+
+       /* Make sure we have enough room */
+       len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size));
+
+       /* Fill the FW log file, consumed by the sysfs fwlog entry */
+       memcpy(wl->fwlog + wl->fwlog_size, memblock, len);
+       wl->fwlog_size += len;
+
+       return len;
+}
+
+static void wl12xx_read_fwlog_panic(struct wl1271 *wl)
+{
+       u32 addr;
+       u32 first_addr;
+       u8 *block;
+
+       if ((wl->quirks & WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED) ||
+           (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) ||
+           (wl->conf.fwlog.mem_blocks == 0))
+               return;
+
+       wl1271_info("Reading FW panic log");
+
+       block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL);
+       if (!block)
+               return;
+
+       /*
+        * Make sure the chip is awake and the logger isn't active.
+        * This might fail if the firmware hanged.
+        */
+       if (!wl1271_ps_elp_wakeup(wl))
+               wl12xx_cmd_stop_fwlog(wl);
+
+       /* Read the first memory block address */
+       wl12xx_fw_status(wl, wl->fw_status);
+       first_addr = le32_to_cpu(wl->fw_status->log_start_addr);
+       if (!first_addr)
+               goto out;
+
+       /* Traverse the memory blocks linked list */
+       addr = first_addr;
+       do {
+               memset(block, 0, WL12XX_HW_BLOCK_SIZE);
+               wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE,
+                                  false);
+
+               /*
+                * Memory blocks are linked to one another. The first 4 bytes
+                * of each memory block hold the hardware address of the next
+                * one. The last memory block points to the first one.
+                */
+               addr = le32_to_cpup((__le32 *)block);
+               if (!wl12xx_copy_fwlog(wl, block + sizeof(addr),
+                                      WL12XX_HW_BLOCK_SIZE - sizeof(addr)))
+                       break;
+       } while (addr && (addr != first_addr));
+
+       wake_up_interruptible(&wl->fwlog_waitq);
+
+out:
+       kfree(block);
+}
+
+static void wl1271_recovery_work(struct work_struct *work)
+{
+       struct wl1271 *wl =
+               container_of(work, struct wl1271, recovery_work);
+       struct wl12xx_vif *wlvif;
+       struct ieee80211_vif *vif;
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->state != WL1271_STATE_ON || wl->plt)
+               goto out_unlock;
+
+       /* Avoid a recursive recovery */
+       set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
+
+       wl12xx_read_fwlog_panic(wl);
+
+       wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
+                   wl->chip.fw_ver_str,
+                   wlcore_read_reg(wl, REG_PC_ON_RECOVERY));
+
+       BUG_ON(bug_on_recovery &&
+              !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags));
+
+       if (no_recovery) {
+               wl1271_info("No recovery (chosen on module load). Fw will remain stuck.");
+               clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
+               goto out_unlock;
+       }
+
+       BUG_ON(bug_on_recovery);
+
+       /*
+        * Advance security sequence number to overcome potential progress
+        * in the firmware during recovery. This doens't hurt if the network is
+        * not encrypted.
+        */
+       wl12xx_for_each_wlvif(wl, wlvif) {
+               if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
+                   test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
+                       wlvif->tx_security_seq +=
+                               WL1271_TX_SQN_POST_RECOVERY_PADDING;
+       }
+
+       /* Prevent spurious TX during FW restart */
+       ieee80211_stop_queues(wl->hw);
+
+       if (wl->sched_scanning) {
+               ieee80211_sched_scan_stopped(wl->hw);
+               wl->sched_scanning = false;
+       }
+
+       /* reboot the chipset */
+       while (!list_empty(&wl->wlvif_list)) {
+               wlvif = list_first_entry(&wl->wlvif_list,
+                                      struct wl12xx_vif, list);
+               vif = wl12xx_wlvif_to_vif(wlvif);
+               __wl1271_op_remove_interface(wl, vif, false);
+       }
+       mutex_unlock(&wl->mutex);
+       wl1271_op_stop(wl->hw);
+
+       clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
+
+       ieee80211_restart_hw(wl->hw);
+
+       /*
+        * Its safe to enable TX now - the queues are stopped after a request
+        * to restart the HW.
+        */
+       ieee80211_wake_queues(wl->hw);
+       return;
+out_unlock:
+       mutex_unlock(&wl->mutex);
+}
+
+static void wl1271_fw_wakeup(struct wl1271 *wl)
+{
+       wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG, ELPCTRL_WAKE_UP);
+}
+
+static int wl1271_setup(struct wl1271 *wl)
+{
+       wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
+       if (!wl->fw_status)
+               return -ENOMEM;
+
+       wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
+       if (!wl->tx_res_if) {
+               kfree(wl->fw_status);
+               return -ENOMEM;
+       }
+
+       return 0;
+}
+
+static int wl12xx_set_power_on(struct wl1271 *wl)
+{
+       int ret;
+
+       msleep(WL1271_PRE_POWER_ON_SLEEP);
+       ret = wl1271_power_on(wl);
+       if (ret < 0)
+               goto out;
+       msleep(WL1271_POWER_ON_SLEEP);
+       wl1271_io_reset(wl);
+       wl1271_io_init(wl);
+
+       wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
+
+       /* ELP module wake up */
+       wl1271_fw_wakeup(wl);
+
+out:
+       return ret;
+}
+
+static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt)
+{
+       int ret = 0;
+
+       ret = wl12xx_set_power_on(wl);
+       if (ret < 0)
+               goto out;
+
+       /*
+        * For wl127x based devices we could use the default block
+        * size (512 bytes), but due to a bug in the sdio driver, we
+        * need to set it explicitly after the chip is powered on.  To
+        * simplify the code and since the performance impact is
+        * negligible, we use the same block size for all different
+        * chip types.
+        */
+       if (wl1271_set_block_size(wl))
+               wl->quirks |= WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN;
+
+       ret = wl->ops->identify_chip(wl);
+       if (ret < 0)
+               goto out;
+
+       /* TODO: make sure the lower driver has set things up correctly */
+
+       ret = wl1271_setup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl12xx_fetch_firmware(wl, plt);
+       if (ret < 0)
+               goto out;
+
+       /* No NVS from netlink, try to get it from the filesystem */
+       if (wl->nvs == NULL) {
+               ret = wl1271_fetch_nvs(wl);
+               if (ret < 0)
+                       goto out;
+       }
+
+out:
+       return ret;
+}
+
+int wl1271_plt_start(struct wl1271 *wl)
+{
+       int retries = WL1271_BOOT_RETRIES;
+       struct wiphy *wiphy = wl->hw->wiphy;
+       int ret;
+
+       mutex_lock(&wl->mutex);
+
+       wl1271_notice("power up");
+
+       if (wl->state != WL1271_STATE_OFF) {
+               wl1271_error("cannot go into PLT state because not "
+                            "in off state: %d", wl->state);
+               ret = -EBUSY;
+               goto out;
+       }
+
+       while (retries) {
+               retries--;
+               ret = wl12xx_chip_wakeup(wl, true);
+               if (ret < 0)
+                       goto power_off;
+
+               ret = wl->ops->boot(wl);
+               if (ret < 0)
+                       goto power_off;
+
+               ret = wl1271_plt_init(wl);
+               if (ret < 0)
+                       goto irq_disable;
+
+               wl->plt = true;
+               wl->state = WL1271_STATE_ON;
+               wl1271_notice("firmware booted in PLT mode (%s)",
+                             wl->chip.fw_ver_str);
+
+               /* update hw/fw version info in wiphy struct */
+               wiphy->hw_version = wl->chip.id;
+               strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
+                       sizeof(wiphy->fw_version));
+
+               goto out;
+
+irq_disable:
+               mutex_unlock(&wl->mutex);
+               /* Unlocking the mutex in the middle of handling is
+                  inherently unsafe. In this case we deem it safe to do,
+                  because we need to let any possibly pending IRQ out of
+                  the system (and while we are WL1271_STATE_OFF the IRQ
+                  work function will not do anything.) Also, any other
+                  possible concurrent operations will fail due to the
+                  current state, hence the wl1271 struct should be safe. */
+               wlcore_disable_interrupts(wl);
+               wl1271_flush_deferred_work(wl);
+               cancel_work_sync(&wl->netstack_work);
+               mutex_lock(&wl->mutex);
+power_off:
+               wl1271_power_off(wl);
+       }
+
+       wl1271_error("firmware boot in PLT mode failed despite %d retries",
+                    WL1271_BOOT_RETRIES);
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+int wl1271_plt_stop(struct wl1271 *wl)
+{
+       int ret = 0;
+
+       wl1271_notice("power down");
+
+       /*
+        * Interrupts must be disabled before setting the state to OFF.
+        * Otherwise, the interrupt handler might be called and exit without
+        * reading the interrupt status.
+        */
+       wlcore_disable_interrupts(wl);
+       mutex_lock(&wl->mutex);
+       if (!wl->plt) {
+               mutex_unlock(&wl->mutex);
+
+               /*
+                * This will not necessarily enable interrupts as interrupts
+                * may have been disabled when op_stop was called. It will,
+                * however, balance the above call to disable_interrupts().
+                */
+               wlcore_enable_interrupts(wl);
+
+               wl1271_error("cannot power down because not in PLT "
+                            "state: %d", wl->state);
+               ret = -EBUSY;
+               goto out;
+       }
+
+       mutex_unlock(&wl->mutex);
+
+       wl1271_flush_deferred_work(wl);
+       cancel_work_sync(&wl->netstack_work);
+       cancel_work_sync(&wl->recovery_work);
+       cancel_delayed_work_sync(&wl->elp_work);
+       cancel_delayed_work_sync(&wl->tx_watchdog_work);
+
+       mutex_lock(&wl->mutex);
+       wl1271_power_off(wl);
+       wl->flags = 0;
+       wl->state = WL1271_STATE_OFF;
+       wl->plt = false;
+       wl->rx_counter = 0;
+       mutex_unlock(&wl->mutex);
+
+out:
+       return ret;
+}
+
+static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
+{
+       struct wl1271 *wl = hw->priv;
+       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+       struct ieee80211_vif *vif = info->control.vif;
+       struct wl12xx_vif *wlvif = NULL;
+       unsigned long flags;
+       int q, mapping;
+       u8 hlid;
+
+       if (vif)
+               wlvif = wl12xx_vif_to_data(vif);
+
+       mapping = skb_get_queue_mapping(skb);
+       q = wl1271_tx_get_queue(mapping);
+
+       hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
+
+       spin_lock_irqsave(&wl->wl_lock, flags);
+
+       /* queue the packet */
+       if (hlid == WL12XX_INVALID_LINK_ID ||
+           (wlvif && !test_bit(hlid, wlvif->links_map))) {
+               wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q);
+               ieee80211_free_txskb(hw, skb);
+               goto out;
+       }
+
+       wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d len %d",
+                    hlid, q, skb->len);
+       skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
+
+       wl->tx_queue_count[q]++;
+
+       /*
+        * The workqueue is slow to process the tx_queue and we need stop
+        * the queue here, otherwise the queue will get too long.
+        */
+       if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
+               wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q);
+               ieee80211_stop_queue(wl->hw, mapping);
+               set_bit(q, &wl->stopped_queues_map);
+       }
+
+       /*
+        * The chip specific setup must run before the first TX packet -
+        * before that, the tx_work will not be initialized!
+        */
+
+       if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
+           !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
+               ieee80211_queue_work(wl->hw, &wl->tx_work);
+
+out:
+       spin_unlock_irqrestore(&wl->wl_lock, flags);
+}
+
+int wl1271_tx_dummy_packet(struct wl1271 *wl)
+{
+       unsigned long flags;
+       int q;
+
+       /* no need to queue a new dummy packet if one is already pending */
+       if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags))
+               return 0;
+
+       q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet));
+
+       spin_lock_irqsave(&wl->wl_lock, flags);
+       set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
+       wl->tx_queue_count[q]++;
+       spin_unlock_irqrestore(&wl->wl_lock, flags);
+
+       /* The FW is low on RX memory blocks, so send the dummy packet asap */
+       if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
+               wl1271_tx_work_locked(wl);
+
+       /*
+        * If the FW TX is busy, TX work will be scheduled by the threaded
+        * interrupt handler function
+        */
+       return 0;
+}
+
+/*
+ * The size of the dummy packet should be at least 1400 bytes. However, in
+ * order to minimize the number of bus transactions, aligning it to 512 bytes
+ * boundaries could be beneficial, performance wise
+ */
+#define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
+
+static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
+{
+       struct sk_buff *skb;
+       struct ieee80211_hdr_3addr *hdr;
+       unsigned int dummy_packet_size;
+
+       dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
+                           sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
+
+       skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
+       if (!skb) {
+               wl1271_warning("Failed to allocate a dummy packet skb");
+               return NULL;
+       }
+
+       skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
+
+       hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
+       memset(hdr, 0, sizeof(*hdr));
+       hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
+                                        IEEE80211_STYPE_NULLFUNC |
+                                        IEEE80211_FCTL_TODS);
+
+       memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
+
+       /* Dummy packets require the TID to be management */
+       skb->priority = WL1271_TID_MGMT;
+
+       /* Initialize all fields that might be used */
+       skb_set_queue_mapping(skb, 0);
+       memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
+
+       return skb;
+}
+
+
+#ifdef CONFIG_PM
+static int wl1271_configure_suspend_sta(struct wl1271 *wl,
+                                       struct wl12xx_vif *wlvif)
+{
+       int ret = 0;
+
+       if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_acx_wake_up_conditions(wl, wlvif,
+                                   wl->conf.conn.suspend_wake_up_event,
+                                   wl->conf.conn.suspend_listen_interval);
+
+       if (ret < 0)
+               wl1271_error("suspend: set wake up conditions failed: %d", ret);
+
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       return ret;
+
+}
+
+static int wl1271_configure_suspend_ap(struct wl1271 *wl,
+                                      struct wl12xx_vif *wlvif)
+{
+       int ret = 0;
+
+       if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
+
+       wl1271_ps_elp_sleep(wl);
+out:
+       return ret;
+
+}
+
+static int wl1271_configure_suspend(struct wl1271 *wl,
+                                   struct wl12xx_vif *wlvif)
+{
+       if (wlvif->bss_type == BSS_TYPE_STA_BSS)
+               return wl1271_configure_suspend_sta(wl, wlvif);
+       if (wlvif->bss_type == BSS_TYPE_AP_BSS)
+               return wl1271_configure_suspend_ap(wl, wlvif);
+       return 0;
+}
+
+static void wl1271_configure_resume(struct wl1271 *wl,
+                                   struct wl12xx_vif *wlvif)
+{
+       int ret = 0;
+       bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
+       bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
+
+       if ((!is_ap) && (!is_sta))
+               return;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               return;
+
+       if (is_sta) {
+               ret = wl1271_acx_wake_up_conditions(wl, wlvif,
+                                   wl->conf.conn.wake_up_event,
+                                   wl->conf.conn.listen_interval);
+
+               if (ret < 0)
+                       wl1271_error("resume: wake up conditions failed: %d",
+                                    ret);
+
+       } else if (is_ap) {
+               ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
+       }
+
+       wl1271_ps_elp_sleep(wl);
+}
+
+static int wl1271_op_suspend(struct ieee80211_hw *hw,
+                           struct cfg80211_wowlan *wow)
+{
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif;
+       int ret;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
+       WARN_ON(!wow || !wow->any);
+
+       wl1271_tx_flush(wl);
+
+       mutex_lock(&wl->mutex);
+       wl->wow_enabled = true;
+       wl12xx_for_each_wlvif(wl, wlvif) {
+               ret = wl1271_configure_suspend(wl, wlvif);
+               if (ret < 0) {
+                       wl1271_warning("couldn't prepare device to suspend");
+                       return ret;
+               }
+       }
+       mutex_unlock(&wl->mutex);
+       /* flush any remaining work */
+       wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
+
+       /*
+        * disable and re-enable interrupts in order to flush
+        * the threaded_irq
+        */
+       wlcore_disable_interrupts(wl);
+
+       /*
+        * set suspended flag to avoid triggering a new threaded_irq
+        * work. no need for spinlock as interrupts are disabled.
+        */
+       set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
+
+       wlcore_enable_interrupts(wl);
+       flush_work(&wl->tx_work);
+       flush_delayed_work(&wl->elp_work);
+
+       return 0;
+}
+
+static int wl1271_op_resume(struct ieee80211_hw *hw)
+{
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif;
+       unsigned long flags;
+       bool run_irq_work = false;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
+                    wl->wow_enabled);
+       WARN_ON(!wl->wow_enabled);
+
+       /*
+        * re-enable irq_work enqueuing, and call irq_work directly if
+        * there is a pending work.
+        */
+       spin_lock_irqsave(&wl->wl_lock, flags);
+       clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
+       if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
+               run_irq_work = true;
+       spin_unlock_irqrestore(&wl->wl_lock, flags);
+
+       if (run_irq_work) {
+               wl1271_debug(DEBUG_MAC80211,
+                            "run postponed irq_work directly");
+               wl1271_irq(0, wl);
+               wlcore_enable_interrupts(wl);
+       }
+
+       mutex_lock(&wl->mutex);
+       wl12xx_for_each_wlvif(wl, wlvif) {
+               wl1271_configure_resume(wl, wlvif);
+       }
+       wl->wow_enabled = false;
+       mutex_unlock(&wl->mutex);
+
+       return 0;
+}
+#endif
+
+static int wl1271_op_start(struct ieee80211_hw *hw)
+{
+       wl1271_debug(DEBUG_MAC80211, "mac80211 start");
+
+       /*
+        * We have to delay the booting of the hardware because
+        * we need to know the local MAC address before downloading and
+        * initializing the firmware. The MAC address cannot be changed
+        * after boot, and without the proper MAC address, the firmware
+        * will not function properly.
+        *
+        * The MAC address is first known when the corresponding interface
+        * is added. That is where we will initialize the hardware.
+        */
+
+       return 0;
+}
+
+static void wl1271_op_stop(struct ieee80211_hw *hw)
+{
+       struct wl1271 *wl = hw->priv;
+       int i;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
+
+       /*
+        * Interrupts must be disabled before setting the state to OFF.
+        * Otherwise, the interrupt handler might be called and exit without
+        * reading the interrupt status.
+        */
+       wlcore_disable_interrupts(wl);
+       mutex_lock(&wl->mutex);
+       if (wl->state == WL1271_STATE_OFF) {
+               mutex_unlock(&wl->mutex);
+
+               /*
+                * This will not necessarily enable interrupts as interrupts
+                * may have been disabled when op_stop was called. It will,
+                * however, balance the above call to disable_interrupts().
+                */
+               wlcore_enable_interrupts(wl);
+               return;
+       }
+
+       /*
+        * this must be before the cancel_work calls below, so that the work
+        * functions don't perform further work.
+        */
+       wl->state = WL1271_STATE_OFF;
+       mutex_unlock(&wl->mutex);
+
+       wl1271_flush_deferred_work(wl);
+       cancel_delayed_work_sync(&wl->scan_complete_work);
+       cancel_work_sync(&wl->netstack_work);
+       cancel_work_sync(&wl->tx_work);
+       cancel_delayed_work_sync(&wl->elp_work);
+       cancel_delayed_work_sync(&wl->tx_watchdog_work);
+
+       /* let's notify MAC80211 about the remaining pending TX frames */
+       wl12xx_tx_reset(wl, true);
+       mutex_lock(&wl->mutex);
+
+       wl1271_power_off(wl);
+
+       wl->band = IEEE80211_BAND_2GHZ;
+
+       wl->rx_counter = 0;
+       wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
+       wl->tx_blocks_available = 0;
+       wl->tx_allocated_blocks = 0;
+       wl->tx_results_count = 0;
+       wl->tx_packets_count = 0;
+       wl->time_offset = 0;
+       wl->ap_fw_ps_map = 0;
+       wl->ap_ps_map = 0;
+       wl->sched_scanning = false;
+       memset(wl->roles_map, 0, sizeof(wl->roles_map));
+       memset(wl->links_map, 0, sizeof(wl->links_map));
+       memset(wl->roc_map, 0, sizeof(wl->roc_map));
+       wl->active_sta_count = 0;
+
+       /* The system link is always allocated */
+       __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
+
+       /*
+        * this is performed after the cancel_work calls and the associated
+        * mutex_lock, so that wl1271_op_add_interface does not accidentally
+        * get executed before all these vars have been reset.
+        */
+       wl->flags = 0;
+
+       wl->tx_blocks_freed = 0;
+
+       for (i = 0; i < NUM_TX_QUEUES; i++) {
+               wl->tx_pkts_freed[i] = 0;
+               wl->tx_allocated_pkts[i] = 0;
+       }
+
+       wl1271_debugfs_reset(wl);
+
+       kfree(wl->fw_status);
+       wl->fw_status = NULL;
+       kfree(wl->tx_res_if);
+       wl->tx_res_if = NULL;
+       kfree(wl->target_mem_map);
+       wl->target_mem_map = NULL;
+
+       mutex_unlock(&wl->mutex);
+}
+
+static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx)
+{
+       u8 policy = find_first_zero_bit(wl->rate_policies_map,
+                                       WL12XX_MAX_RATE_POLICIES);
+       if (policy >= WL12XX_MAX_RATE_POLICIES)
+               return -EBUSY;
+
+       __set_bit(policy, wl->rate_policies_map);
+       *idx = policy;
+       return 0;
+}
+
+static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx)
+{
+       if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES))
+               return;
+
+       __clear_bit(*idx, wl->rate_policies_map);
+       *idx = WL12XX_MAX_RATE_POLICIES;
+}
+
+static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       switch (wlvif->bss_type) {
+       case BSS_TYPE_AP_BSS:
+               if (wlvif->p2p)
+                       return WL1271_ROLE_P2P_GO;
+               else
+                       return WL1271_ROLE_AP;
+
+       case BSS_TYPE_STA_BSS:
+               if (wlvif->p2p)
+                       return WL1271_ROLE_P2P_CL;
+               else
+                       return WL1271_ROLE_STA;
+
+       case BSS_TYPE_IBSS:
+               return WL1271_ROLE_IBSS;
+
+       default:
+               wl1271_error("invalid bss_type: %d", wlvif->bss_type);
+       }
+       return WL12XX_INVALID_ROLE_TYPE;
+}
+
+static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       int i;
+
+       /* clear everything but the persistent data */
+       memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent));
+
+       switch (ieee80211_vif_type_p2p(vif)) {
+       case NL80211_IFTYPE_P2P_CLIENT:
+               wlvif->p2p = 1;
+               /* fall-through */
+       case NL80211_IFTYPE_STATION:
+               wlvif->bss_type = BSS_TYPE_STA_BSS;
+               break;
+       case NL80211_IFTYPE_ADHOC:
+               wlvif->bss_type = BSS_TYPE_IBSS;
+               break;
+       case NL80211_IFTYPE_P2P_GO:
+               wlvif->p2p = 1;
+               /* fall-through */
+       case NL80211_IFTYPE_AP:
+               wlvif->bss_type = BSS_TYPE_AP_BSS;
+               break;
+       default:
+               wlvif->bss_type = MAX_BSS_TYPE;
+               return -EOPNOTSUPP;
+       }
+
+       wlvif->role_id = WL12XX_INVALID_ROLE_ID;
+       wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
+       wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
+
+       if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
+           wlvif->bss_type == BSS_TYPE_IBSS) {
+               /* init sta/ibss data */
+               wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
+               wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx);
+               wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx);
+               wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
+       } else {
+               /* init ap data */
+               wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
+               wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
+               wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
+               wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
+               for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
+                       wl12xx_allocate_rate_policy(wl,
+                                               &wlvif->ap.ucast_rate_idx[i]);
+       }
+
+       wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
+       wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
+       wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
+       wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
+       wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
+       wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT;
+
+       /*
+        * mac80211 configures some values globally, while we treat them
+        * per-interface. thus, on init, we have to copy them from wl
+        */
+       wlvif->band = wl->band;
+       wlvif->channel = wl->channel;
+       wlvif->power_level = wl->power_level;
+
+       INIT_WORK(&wlvif->rx_streaming_enable_work,
+                 wl1271_rx_streaming_enable_work);
+       INIT_WORK(&wlvif->rx_streaming_disable_work,
+                 wl1271_rx_streaming_disable_work);
+       INIT_LIST_HEAD(&wlvif->list);
+
+       setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer,
+                   (unsigned long) wlvif);
+       return 0;
+}
+
+static bool wl12xx_init_fw(struct wl1271 *wl)
+{
+       int retries = WL1271_BOOT_RETRIES;
+       bool booted = false;
+       struct wiphy *wiphy = wl->hw->wiphy;
+       int ret;
+
+       while (retries) {
+               retries--;
+               ret = wl12xx_chip_wakeup(wl, false);
+               if (ret < 0)
+                       goto power_off;
+
+               ret = wl->ops->boot(wl);
+               if (ret < 0)
+                       goto power_off;
+
+               ret = wl1271_hw_init(wl);
+               if (ret < 0)
+                       goto irq_disable;
+
+               booted = true;
+               break;
+
+irq_disable:
+               mutex_unlock(&wl->mutex);
+               /* Unlocking the mutex in the middle of handling is
+                  inherently unsafe. In this case we deem it safe to do,
+                  because we need to let any possibly pending IRQ out of
+                  the system (and while we are WL1271_STATE_OFF the IRQ
+                  work function will not do anything.) Also, any other
+                  possible concurrent operations will fail due to the
+                  current state, hence the wl1271 struct should be safe. */
+               wlcore_disable_interrupts(wl);
+               wl1271_flush_deferred_work(wl);
+               cancel_work_sync(&wl->netstack_work);
+               mutex_lock(&wl->mutex);
+power_off:
+               wl1271_power_off(wl);
+       }
+
+       if (!booted) {
+               wl1271_error("firmware boot failed despite %d retries",
+                            WL1271_BOOT_RETRIES);
+               goto out;
+       }
+
+       wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
+
+       /* update hw/fw version info in wiphy struct */
+       wiphy->hw_version = wl->chip.id;
+       strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
+               sizeof(wiphy->fw_version));
+
+       /*
+        * Now we know if 11a is supported (info from the NVS), so disable
+        * 11a channels if not supported
+        */
+       if (!wl->enable_11a)
+               wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
+
+       wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
+                    wl->enable_11a ? "" : "not ");
+
+       wl->state = WL1271_STATE_ON;
+out:
+       return booted;
+}
+
+static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif)
+{
+       return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID;
+}
+
+/*
+ * Check whether a fw switch (i.e. moving from one loaded
+ * fw to another) is needed. This function is also responsible
+ * for updating wl->last_vif_count, so it must be called before
+ * loading a non-plt fw (so the correct fw (single-role/multi-role)
+ * will be used).
+ */
+static bool wl12xx_need_fw_change(struct wl1271 *wl,
+                                 struct vif_counter_data vif_counter_data,
+                                 bool add)
+{
+       enum wl12xx_fw_type current_fw = wl->fw_type;
+       u8 vif_count = vif_counter_data.counter;
+
+       if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags))
+               return false;
+
+       /* increase the vif count if this is a new vif */
+       if (add && !vif_counter_data.cur_vif_running)
+               vif_count++;
+
+       wl->last_vif_count = vif_count;
+
+       /* no need for fw change if the device is OFF */
+       if (wl->state == WL1271_STATE_OFF)
+               return false;
+
+       if (vif_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL)
+               return true;
+       if (vif_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI)
+               return true;
+
+       return false;
+}
+
+/*
+ * Enter "forced psm". Make sure the sta is in psm against the ap,
+ * to make the fw switch a bit more disconnection-persistent.
+ */
+static void wl12xx_force_active_psm(struct wl1271 *wl)
+{
+       struct wl12xx_vif *wlvif;
+
+       wl12xx_for_each_wlvif_sta(wl, wlvif) {
+               wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE);
+       }
+}
+
+static int wl1271_op_add_interface(struct ieee80211_hw *hw,
+                                  struct ieee80211_vif *vif)
+{
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       struct vif_counter_data vif_count;
+       int ret = 0;
+       u8 role_type;
+       bool booted = false;
+
+       vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
+                            IEEE80211_VIF_SUPPORTS_CQM_RSSI;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
+                    ieee80211_vif_type_p2p(vif), vif->addr);
+
+       wl12xx_get_vif_count(hw, vif, &vif_count);
+
+       mutex_lock(&wl->mutex);
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out_unlock;
+
+       /*
+        * in some very corner case HW recovery scenarios its possible to
+        * get here before __wl1271_op_remove_interface is complete, so
+        * opt out if that is the case.
+        */
+       if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) ||
+           test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) {
+               ret = -EBUSY;
+               goto out;
+       }
+
+
+       ret = wl12xx_init_vif_data(wl, vif);
+       if (ret < 0)
+               goto out;
+
+       wlvif->wl = wl;
+       role_type = wl12xx_get_role_type(wl, wlvif);
+       if (role_type == WL12XX_INVALID_ROLE_TYPE) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       if (wl12xx_need_fw_change(wl, vif_count, true)) {
+               wl12xx_force_active_psm(wl);
+               set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags);
+               mutex_unlock(&wl->mutex);
+               wl1271_recovery_work(&wl->recovery_work);
+               return 0;
+       }
+
+       /*
+        * TODO: after the nvs issue will be solved, move this block
+        * to start(), and make sure here the driver is ON.
+        */
+       if (wl->state == WL1271_STATE_OFF) {
+               /*
+                * we still need this in order to configure the fw
+                * while uploading the nvs
+                */
+               memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN);
+
+               booted = wl12xx_init_fw(wl);
+               if (!booted) {
+                       ret = -EINVAL;
+                       goto out;
+               }
+       }
+
+       if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
+           wlvif->bss_type == BSS_TYPE_IBSS) {
+               /*
+                * The device role is a special role used for
+                * rx and tx frames prior to association (as
+                * the STA role can get packets only from
+                * its associated bssid)
+                */
+               ret = wl12xx_cmd_role_enable(wl, vif->addr,
+                                                WL1271_ROLE_DEVICE,
+                                                &wlvif->dev_role_id);
+               if (ret < 0)
+                       goto out;
+       }
+
+       ret = wl12xx_cmd_role_enable(wl, vif->addr,
+                                    role_type, &wlvif->role_id);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_init_vif_specific(wl, vif);
+       if (ret < 0)
+               goto out;
+
+       list_add(&wlvif->list, &wl->wlvif_list);
+       set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags);
+
+       if (wlvif->bss_type == BSS_TYPE_AP_BSS)
+               wl->ap_count++;
+       else
+               wl->sta_count++;
+out:
+       wl1271_ps_elp_sleep(wl);
+out_unlock:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+static void __wl1271_op_remove_interface(struct wl1271 *wl,
+                                        struct ieee80211_vif *vif,
+                                        bool reset_tx_queues)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       int i, ret;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
+
+       if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
+               return;
+
+       /* because of hardware recovery, we may get here twice */
+       if (wl->state != WL1271_STATE_ON)
+               return;
+
+       wl1271_info("down");
+
+       if (wl->scan.state != WL1271_SCAN_STATE_IDLE &&
+           wl->scan_vif == vif) {
+               /*
+                * Rearm the tx watchdog just before idling scan. This
+                * prevents just-finished scans from triggering the watchdog
+                */
+               wl12xx_rearm_tx_watchdog_locked(wl);
+
+               wl->scan.state = WL1271_SCAN_STATE_IDLE;
+               memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
+               wl->scan_vif = NULL;
+               wl->scan.req = NULL;
+               ieee80211_scan_completed(wl->hw, true);
+       }
+
+       if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) {
+               /* disable active roles */
+               ret = wl1271_ps_elp_wakeup(wl);
+               if (ret < 0)
+                       goto deinit;
+
+               if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
+                   wlvif->bss_type == BSS_TYPE_IBSS) {
+                       if (wl12xx_dev_role_started(wlvif))
+                               wl12xx_stop_dev(wl, wlvif);
+
+                       ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
+                       if (ret < 0)
+                               goto deinit;
+               }
+
+               ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id);
+               if (ret < 0)
+                       goto deinit;
+
+               wl1271_ps_elp_sleep(wl);
+       }
+deinit:
+       /* clear all hlids (except system_hlid) */
+       wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
+
+       if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
+           wlvif->bss_type == BSS_TYPE_IBSS) {
+               wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
+               wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
+               wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
+               wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
+       } else {
+               wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
+               wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
+               wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
+               wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
+               for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
+                       wl12xx_free_rate_policy(wl,
+                                               &wlvif->ap.ucast_rate_idx[i]);
+               wl1271_free_ap_keys(wl, wlvif);
+       }
+
+       dev_kfree_skb(wlvif->probereq);
+       wlvif->probereq = NULL;
+       wl12xx_tx_reset_wlvif(wl, wlvif);
+       if (wl->last_wlvif == wlvif)
+               wl->last_wlvif = NULL;
+       list_del(&wlvif->list);
+       memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map));
+       wlvif->role_id = WL12XX_INVALID_ROLE_ID;
+       wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
+
+       if (wlvif->bss_type == BSS_TYPE_AP_BSS)
+               wl->ap_count--;
+       else
+               wl->sta_count--;
+
+       mutex_unlock(&wl->mutex);
+
+       del_timer_sync(&wlvif->rx_streaming_timer);
+       cancel_work_sync(&wlvif->rx_streaming_enable_work);
+       cancel_work_sync(&wlvif->rx_streaming_disable_work);
+
+       mutex_lock(&wl->mutex);
+}
+
+static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
+                                      struct ieee80211_vif *vif)
+{
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       struct wl12xx_vif *iter;
+       struct vif_counter_data vif_count;
+       bool cancel_recovery = true;
+
+       wl12xx_get_vif_count(hw, vif, &vif_count);
+       mutex_lock(&wl->mutex);
+
+       if (wl->state == WL1271_STATE_OFF ||
+           !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
+               goto out;
+
+       /*
+        * wl->vif can be null here if someone shuts down the interface
+        * just when hardware recovery has been started.
+        */
+       wl12xx_for_each_wlvif(wl, iter) {
+               if (iter != wlvif)
+                       continue;
+
+               __wl1271_op_remove_interface(wl, vif, true);
+               break;
+       }
+       WARN_ON(iter != wlvif);
+       if (wl12xx_need_fw_change(wl, vif_count, false)) {
+               wl12xx_force_active_psm(wl);
+               set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags);
+               wl12xx_queue_recovery_work(wl);
+               cancel_recovery = false;
+       }
+out:
+       mutex_unlock(&wl->mutex);
+       if (cancel_recovery)
+               cancel_work_sync(&wl->recovery_work);
+}
+
+static int wl12xx_op_change_interface(struct ieee80211_hw *hw,
+                                     struct ieee80211_vif *vif,
+                                     enum nl80211_iftype new_type, bool p2p)
+{
+       struct wl1271 *wl = hw->priv;
+       int ret;
+
+       set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
+       wl1271_op_remove_interface(hw, vif);
+
+       vif->type = new_type;
+       vif->p2p = p2p;
+       ret = wl1271_op_add_interface(hw, vif);
+
+       clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
+       return ret;
+}
+
+static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                         bool set_assoc)
+{
+       int ret;
+       bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
+
+       /*
+        * One of the side effects of the JOIN command is that is clears
+        * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
+        * to a WPA/WPA2 access point will therefore kill the data-path.
+        * Currently the only valid scenario for JOIN during association
+        * is on roaming, in which case we will also be given new keys.
+        * Keep the below message for now, unless it starts bothering
+        * users who really like to roam a lot :)
+        */
+       if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
+               wl1271_info("JOIN while associated.");
+
+       /* clear encryption type */
+       wlvif->encryption_type = KEY_NONE;
+
+       if (set_assoc)
+               set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags);
+
+       if (is_ibss)
+               ret = wl12xx_cmd_role_start_ibss(wl, wlvif);
+       else
+               ret = wl12xx_cmd_role_start_sta(wl, wlvif);
+       if (ret < 0)
+               goto out;
+
+       if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
+               goto out;
+
+       /*
+        * The join command disable the keep-alive mode, shut down its process,
+        * and also clear the template config, so we need to reset it all after
+        * the join. The acx_aid starts the keep-alive process, and the order
+        * of the commands below is relevant.
+        */
+       ret = wl1271_acx_keep_alive_mode(wl, wlvif, true);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_acx_aid(wl, wlvif, wlvif->aid);
+       if (ret < 0)
+               goto out;
+
+       ret = wl12xx_cmd_build_klv_null_data(wl, wlvif);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_acx_keep_alive_config(wl, wlvif,
+                                          CMD_TEMPL_KLV_IDX_NULL_DATA,
+                                          ACX_KEEP_ALIVE_TPL_VALID);
+       if (ret < 0)
+               goto out;
+
+out:
+       return ret;
+}
+
+static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       int ret;
+
+       if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) {
+               struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+
+               wl12xx_cmd_stop_channel_switch(wl);
+               ieee80211_chswitch_done(vif, false);
+       }
+
+       /* to stop listening to a channel, we disconnect */
+       ret = wl12xx_cmd_role_stop_sta(wl, wlvif);
+       if (ret < 0)
+               goto out;
+
+       /* reset TX security counters on a clean disconnect */
+       wlvif->tx_security_last_seq_lsb = 0;
+       wlvif->tx_security_seq = 0;
+
+out:
+       return ret;
+}
+
+static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band];
+       wlvif->rate_set = wlvif->basic_rate_set;
+}
+
+static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                                 bool idle)
+{
+       int ret;
+       bool cur_idle = !test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
+
+       if (idle == cur_idle)
+               return 0;
+
+       if (idle) {
+               /* no need to croc if we weren't busy (e.g. during boot) */
+               if (wl12xx_dev_role_started(wlvif)) {
+                       ret = wl12xx_stop_dev(wl, wlvif);
+                       if (ret < 0)
+                               goto out;
+               }
+               wlvif->rate_set =
+                       wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
+               ret = wl1271_acx_sta_rate_policies(wl, wlvif);
+               if (ret < 0)
+                       goto out;
+               ret = wl1271_acx_keep_alive_config(
+                       wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA,
+                       ACX_KEEP_ALIVE_TPL_INVALID);
+               if (ret < 0)
+                       goto out;
+               clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
+       } else {
+               /* The current firmware only supports sched_scan in idle */
+               if (wl->sched_scanning) {
+                       wl1271_scan_sched_scan_stop(wl);
+                       ieee80211_sched_scan_stopped(wl->hw);
+               }
+
+               ret = wl12xx_start_dev(wl, wlvif);
+               if (ret < 0)
+                       goto out;
+               set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
+       }
+
+out:
+       return ret;
+}
+
+static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                            struct ieee80211_conf *conf, u32 changed)
+{
+       bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
+       int channel, ret;
+
+       channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
+
+       /* if the channel changes while joined, join again */
+       if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
+           ((wlvif->band != conf->channel->band) ||
+            (wlvif->channel != channel))) {
+               /* send all pending packets */
+               wl1271_tx_work_locked(wl);
+               wlvif->band = conf->channel->band;
+               wlvif->channel = channel;
+
+               if (!is_ap) {
+                       /*
+                        * FIXME: the mac80211 should really provide a fixed
+                        * rate to use here. for now, just use the smallest
+                        * possible rate for the band as a fixed rate for
+                        * association frames and other control messages.
+                        */
+                       if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
+                               wl1271_set_band_rate(wl, wlvif);
+
+                       wlvif->basic_rate =
+                               wl1271_tx_min_rate_get(wl,
+                                                      wlvif->basic_rate_set);
+                       ret = wl1271_acx_sta_rate_policies(wl, wlvif);
+                       if (ret < 0)
+                               wl1271_warning("rate policy for channel "
+                                              "failed %d", ret);
+
+                       /*
+                        * change the ROC channel. do it only if we are
+                        * not idle. otherwise, CROC will be called
+                        * anyway.
+                        */
+                       if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED,
+                                     &wlvif->flags) &&
+                           wl12xx_dev_role_started(wlvif) &&
+                           !(conf->flags & IEEE80211_CONF_IDLE)) {
+                               ret = wl12xx_stop_dev(wl, wlvif);
+                               if (ret < 0)
+                                       return ret;
+
+                               ret = wl12xx_start_dev(wl, wlvif);
+                               if (ret < 0)
+                                       return ret;
+                       }
+               }
+       }
+
+       if ((changed & IEEE80211_CONF_CHANGE_PS) && !is_ap) {
+
+               if ((conf->flags & IEEE80211_CONF_PS) &&
+                   test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
+                   !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
+
+                       int ps_mode;
+                       char *ps_mode_str;
+
+                       if (wl->conf.conn.forced_ps) {
+                               ps_mode = STATION_POWER_SAVE_MODE;
+                               ps_mode_str = "forced";
+                       } else {
+                               ps_mode = STATION_AUTO_PS_MODE;
+                               ps_mode_str = "auto";
+                       }
+
+                       wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str);
+
+                       ret = wl1271_ps_set_mode(wl, wlvif, ps_mode);
+
+                       if (ret < 0)
+                               wl1271_warning("enter %s ps failed %d",
+                                              ps_mode_str, ret);
+
+               } else if (!(conf->flags & IEEE80211_CONF_PS) &&
+                          test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
+
+                       wl1271_debug(DEBUG_PSM, "auto ps disabled");
+
+                       ret = wl1271_ps_set_mode(wl, wlvif,
+                                                STATION_ACTIVE_MODE);
+                       if (ret < 0)
+                               wl1271_warning("exit auto ps failed %d", ret);
+               }
+       }
+
+       if (conf->power_level != wlvif->power_level) {
+               ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level);
+               if (ret < 0)
+                       return ret;
+
+               wlvif->power_level = conf->power_level;
+       }
+
+       return 0;
+}
+
+static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
+{
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif;
+       struct ieee80211_conf *conf = &hw->conf;
+       int channel, ret = 0;
+
+       channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
+                    " changed 0x%x",
+                    channel,
+                    conf->flags & IEEE80211_CONF_PS ? "on" : "off",
+                    conf->power_level,
+                    conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
+                        changed);
+
+       /*
+        * mac80211 will go to idle nearly immediately after transmitting some
+        * frames, such as the deauth. To make sure those frames reach the air,
+        * wait here until the TX queue is fully flushed.
+        */
+       if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
+           (conf->flags & IEEE80211_CONF_IDLE))
+               wl1271_tx_flush(wl);
+
+       mutex_lock(&wl->mutex);
+
+       /* we support configuring the channel and band even while off */
+       if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
+               wl->band = conf->channel->band;
+               wl->channel = channel;
+       }
+
+       if (changed & IEEE80211_CONF_CHANGE_POWER)
+               wl->power_level = conf->power_level;
+
+       if (unlikely(wl->state == WL1271_STATE_OFF))
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       /* configure each interface */
+       wl12xx_for_each_wlvif(wl, wlvif) {
+               ret = wl12xx_config_vif(wl, wlvif, conf, changed);
+               if (ret < 0)
+                       goto out_sleep;
+       }
+
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+struct wl1271_filter_params {
+       bool enabled;
+       int mc_list_length;
+       u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
+};
+
+static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw,
+                                      struct netdev_hw_addr_list *mc_list)
+{
+       struct wl1271_filter_params *fp;
+       struct netdev_hw_addr *ha;
+       struct wl1271 *wl = hw->priv;
+
+       if (unlikely(wl->state == WL1271_STATE_OFF))
+               return 0;
+
+       fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
+       if (!fp) {
+               wl1271_error("Out of memory setting filters.");
+               return 0;
+       }
+
+       /* update multicast filtering parameters */
+       fp->mc_list_length = 0;
+       if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
+               fp->enabled = false;
+       } else {
+               fp->enabled = true;
+               netdev_hw_addr_list_for_each(ha, mc_list) {
+                       memcpy(fp->mc_list[fp->mc_list_length],
+                                       ha->addr, ETH_ALEN);
+                       fp->mc_list_length++;
+               }
+       }
+
+       return (u64)(unsigned long)fp;
+}
+
+#define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
+                                 FIF_ALLMULTI | \
+                                 FIF_FCSFAIL | \
+                                 FIF_BCN_PRBRESP_PROMISC | \
+                                 FIF_CONTROL | \
+                                 FIF_OTHER_BSS)
+
+static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
+                                      unsigned int changed,
+                                      unsigned int *total, u64 multicast)
+{
+       struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif;
+
+       int ret;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
+                    " total %x", changed, *total);
+
+       mutex_lock(&wl->mutex);
+
+       *total &= WL1271_SUPPORTED_FILTERS;
+       changed &= WL1271_SUPPORTED_FILTERS;
+
+       if (unlikely(wl->state == WL1271_STATE_OFF))
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       wl12xx_for_each_wlvif(wl, wlvif) {
+               if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
+                       if (*total & FIF_ALLMULTI)
+                               ret = wl1271_acx_group_address_tbl(wl, wlvif,
+                                                                  false,
+                                                                  NULL, 0);
+                       else if (fp)
+                               ret = wl1271_acx_group_address_tbl(wl, wlvif,
+                                                       fp->enabled,
+                                                       fp->mc_list,
+                                                       fp->mc_list_length);
+                       if (ret < 0)
+                               goto out_sleep;
+               }
+       }
+
+       /*
+        * the fw doesn't provide an api to configure the filters. instead,
+        * the filters configuration is based on the active roles / ROC
+        * state.
+        */
+
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+       kfree(fp);
+}
+
+static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                               u8 id, u8 key_type, u8 key_size,
+                               const u8 *key, u8 hlid, u32 tx_seq_32,
+                               u16 tx_seq_16)
+{
+       struct wl1271_ap_key *ap_key;
+       int i;
+
+       wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id);
+
+       if (key_size > MAX_KEY_SIZE)
+               return -EINVAL;
+
+       /*
+        * Find next free entry in ap_keys. Also check we are not replacing
+        * an existing key.
+        */
+       for (i = 0; i < MAX_NUM_KEYS; i++) {
+               if (wlvif->ap.recorded_keys[i] == NULL)
+                       break;
+
+               if (wlvif->ap.recorded_keys[i]->id == id) {
+                       wl1271_warning("trying to record key replacement");
+                       return -EINVAL;
+               }
+       }
+
+       if (i == MAX_NUM_KEYS)
+               return -EBUSY;
+
+       ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL);
+       if (!ap_key)
+               return -ENOMEM;
+
+       ap_key->id = id;
+       ap_key->key_type = key_type;
+       ap_key->key_size = key_size;
+       memcpy(ap_key->key, key, key_size);
+       ap_key->hlid = hlid;
+       ap_key->tx_seq_32 = tx_seq_32;
+       ap_key->tx_seq_16 = tx_seq_16;
+
+       wlvif->ap.recorded_keys[i] = ap_key;
+       return 0;
+}
+
+static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       int i;
+
+       for (i = 0; i < MAX_NUM_KEYS; i++) {
+               kfree(wlvif->ap.recorded_keys[i]);
+               wlvif->ap.recorded_keys[i] = NULL;
+       }
+}
+
+static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       int i, ret = 0;
+       struct wl1271_ap_key *key;
+       bool wep_key_added = false;
+
+       for (i = 0; i < MAX_NUM_KEYS; i++) {
+               u8 hlid;
+               if (wlvif->ap.recorded_keys[i] == NULL)
+                       break;
+
+               key = wlvif->ap.recorded_keys[i];
+               hlid = key->hlid;
+               if (hlid == WL12XX_INVALID_LINK_ID)
+                       hlid = wlvif->ap.bcast_hlid;
+
+               ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE,
+                                           key->id, key->key_type,
+                                           key->key_size, key->key,
+                                           hlid, key->tx_seq_32,
+                                           key->tx_seq_16);
+               if (ret < 0)
+                       goto out;
+
+               if (key->key_type == KEY_WEP)
+                       wep_key_added = true;
+       }
+
+       if (wep_key_added) {
+               ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key,
+                                                    wlvif->ap.bcast_hlid);
+               if (ret < 0)
+                       goto out;
+       }
+
+out:
+       wl1271_free_ap_keys(wl, wlvif);
+       return ret;
+}
+
+static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                      u16 action, u8 id, u8 key_type,
+                      u8 key_size, const u8 *key, u32 tx_seq_32,
+                      u16 tx_seq_16, struct ieee80211_sta *sta)
+{
+       int ret;
+       bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
+
+       /*
+        * A role set to GEM cipher requires different Tx settings (namely
+        * spare blocks). Note when we are in this mode so the HW can adjust.
+        */
+       if (key_type == KEY_GEM) {
+               if (action == KEY_ADD_OR_REPLACE)
+                       wlvif->is_gem = true;
+               else if (action == KEY_REMOVE)
+                       wlvif->is_gem = false;
+       }
+
+       if (is_ap) {
+               struct wl1271_station *wl_sta;
+               u8 hlid;
+
+               if (sta) {
+                       wl_sta = (struct wl1271_station *)sta->drv_priv;
+                       hlid = wl_sta->hlid;
+               } else {
+                       hlid = wlvif->ap.bcast_hlid;
+               }
+
+               if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
+                       /*
+                        * We do not support removing keys after AP shutdown.
+                        * Pretend we do to make mac80211 happy.
+                        */
+                       if (action != KEY_ADD_OR_REPLACE)
+                               return 0;
+
+                       ret = wl1271_record_ap_key(wl, wlvif, id,
+                                            key_type, key_size,
+                                            key, hlid, tx_seq_32,
+                                            tx_seq_16);
+               } else {
+                       ret = wl1271_cmd_set_ap_key(wl, wlvif, action,
+                                            id, key_type, key_size,
+                                            key, hlid, tx_seq_32,
+                                            tx_seq_16);
+               }
+
+               if (ret < 0)
+                       return ret;
+       } else {
+               const u8 *addr;
+               static const u8 bcast_addr[ETH_ALEN] = {
+                       0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+               };
+
+               addr = sta ? sta->addr : bcast_addr;
+
+               if (is_zero_ether_addr(addr)) {
+                       /* We dont support TX only encryption */
+                       return -EOPNOTSUPP;
+               }
+
+               /* The wl1271 does not allow to remove unicast keys - they
+                  will be cleared automatically on next CMD_JOIN. Ignore the
+                  request silently, as we dont want the mac80211 to emit
+                  an error message. */
+               if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
+                       return 0;
+
+               /* don't remove key if hlid was already deleted */
+               if (action == KEY_REMOVE &&
+                   wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
+                       return 0;
+
+               ret = wl1271_cmd_set_sta_key(wl, wlvif, action,
+                                            id, key_type, key_size,
+                                            key, addr, tx_seq_32,
+                                            tx_seq_16);
+               if (ret < 0)
+                       return ret;
+
+               /* the default WEP key needs to be configured at least once */
+               if (key_type == KEY_WEP) {
+                       ret = wl12xx_cmd_set_default_wep_key(wl,
+                                                       wlvif->default_key,
+                                                       wlvif->sta.hlid);
+                       if (ret < 0)
+                               return ret;
+               }
+       }
+
+       return 0;
+}
+
+static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
+                            struct ieee80211_vif *vif,
+                            struct ieee80211_sta *sta,
+                            struct ieee80211_key_conf *key_conf)
+{
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       int ret;
+       u32 tx_seq_32 = 0;
+       u16 tx_seq_16 = 0;
+       u8 key_type;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
+
+       wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta);
+       wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
+                    key_conf->cipher, key_conf->keyidx,
+                    key_conf->keylen, key_conf->flags);
+       wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF)) {
+               ret = -EAGAIN;
+               goto out_unlock;
+       }
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out_unlock;
+
+       switch (key_conf->cipher) {
+       case WLAN_CIPHER_SUITE_WEP40:
+       case WLAN_CIPHER_SUITE_WEP104:
+               key_type = KEY_WEP;
+
+               key_conf->hw_key_idx = key_conf->keyidx;
+               break;
+       case WLAN_CIPHER_SUITE_TKIP:
+               key_type = KEY_TKIP;
+
+               key_conf->hw_key_idx = key_conf->keyidx;
+               tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
+               tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
+               break;
+       case WLAN_CIPHER_SUITE_CCMP:
+               key_type = KEY_AES;
+
+               key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
+               tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
+               tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
+               break;
+       case WL1271_CIPHER_SUITE_GEM:
+               key_type = KEY_GEM;
+               tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
+               tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
+               break;
+       default:
+               wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
+
+               ret = -EOPNOTSUPP;
+               goto out_sleep;
+       }
+
+       switch (cmd) {
+       case SET_KEY:
+               ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE,
+                                key_conf->keyidx, key_type,
+                                key_conf->keylen, key_conf->key,
+                                tx_seq_32, tx_seq_16, sta);
+               if (ret < 0) {
+                       wl1271_error("Could not add or replace key");
+                       goto out_sleep;
+               }
+
+               /*
+                * reconfiguring arp response if the unicast (or common)
+                * encryption key type was changed
+                */
+               if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
+                   (sta || key_type == KEY_WEP) &&
+                   wlvif->encryption_type != key_type) {
+                       wlvif->encryption_type = key_type;
+                       ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
+                       if (ret < 0) {
+                               wl1271_warning("build arp rsp failed: %d", ret);
+                               goto out_sleep;
+                       }
+               }
+               break;
+
+       case DISABLE_KEY:
+               ret = wl1271_set_key(wl, wlvif, KEY_REMOVE,
+                                    key_conf->keyidx, key_type,
+                                    key_conf->keylen, key_conf->key,
+                                    0, 0, sta);
+               if (ret < 0) {
+                       wl1271_error("Could not remove key");
+                       goto out_sleep;
+               }
+               break;
+
+       default:
+               wl1271_error("Unsupported key cmd 0x%x", cmd);
+               ret = -EOPNOTSUPP;
+               break;
+       }
+
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+
+out_unlock:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
+                            struct ieee80211_vif *vif,
+                            struct cfg80211_scan_request *req)
+{
+       struct wl1271 *wl = hw->priv;
+       int ret;
+       u8 *ssid = NULL;
+       size_t len = 0;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
+
+       if (req->n_ssids) {
+               ssid = req->ssids[0].ssid;
+               len = req->ssids[0].ssid_len;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->state == WL1271_STATE_OFF) {
+               /*
+                * We cannot return -EBUSY here because cfg80211 will expect
+                * a call to ieee80211_scan_completed if we do - in this case
+                * there won't be any call.
+                */
+               ret = -EAGAIN;
+               goto out;
+       }
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       /* fail if there is any role in ROC */
+       if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) {
+               /* don't allow scanning right now */
+               ret = -EBUSY;
+               goto out_sleep;
+       }
+
+       ret = wl1271_scan(hw->priv, vif, ssid, len, req);
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw,
+                                    struct ieee80211_vif *vif)
+{
+       struct wl1271 *wl = hw->priv;
+       int ret;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan");
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->state == WL1271_STATE_OFF)
+               goto out;
+
+       if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       if (wl->scan.state != WL1271_SCAN_STATE_DONE) {
+               ret = wl1271_scan_stop(wl);
+               if (ret < 0)
+                       goto out_sleep;
+       }
+
+       /*
+        * Rearm the tx watchdog just before idling scan. This
+        * prevents just-finished scans from triggering the watchdog
+        */
+       wl12xx_rearm_tx_watchdog_locked(wl);
+
+       wl->scan.state = WL1271_SCAN_STATE_IDLE;
+       memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
+       wl->scan_vif = NULL;
+       wl->scan.req = NULL;
+       ieee80211_scan_completed(wl->hw, true);
+
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+
+       cancel_delayed_work_sync(&wl->scan_complete_work);
+}
+
+static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
+                                     struct ieee80211_vif *vif,
+                                     struct cfg80211_sched_scan_request *req,
+                                     struct ieee80211_sched_scan_ies *ies)
+{
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       int ret;
+
+       wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->state == WL1271_STATE_OFF) {
+               ret = -EAGAIN;
+               goto out;
+       }
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies);
+       if (ret < 0)
+               goto out_sleep;
+
+       ret = wl1271_scan_sched_scan_start(wl, wlvif);
+       if (ret < 0)
+               goto out_sleep;
+
+       wl->sched_scanning = true;
+
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+       return ret;
+}
+
+static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
+                                     struct ieee80211_vif *vif)
+{
+       struct wl1271 *wl = hw->priv;
+       int ret;
+
+       wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->state == WL1271_STATE_OFF)
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       wl1271_scan_sched_scan_stop(wl);
+
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
+{
+       struct wl1271 *wl = hw->priv;
+       int ret = 0;
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF)) {
+               ret = -EAGAIN;
+               goto out;
+       }
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_acx_frag_threshold(wl, value);
+       if (ret < 0)
+               wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
+
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
+{
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif;
+       int ret = 0;
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF)) {
+               ret = -EAGAIN;
+               goto out;
+       }
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       wl12xx_for_each_wlvif(wl, wlvif) {
+               ret = wl1271_acx_rts_threshold(wl, wlvif, value);
+               if (ret < 0)
+                       wl1271_warning("set rts threshold failed: %d", ret);
+       }
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb,
+                           int offset)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       u8 ssid_len;
+       const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
+                                        skb->len - offset);
+
+       if (!ptr) {
+               wl1271_error("No SSID in IEs!");
+               return -ENOENT;
+       }
+
+       ssid_len = ptr[1];
+       if (ssid_len > IEEE80211_MAX_SSID_LEN) {
+               wl1271_error("SSID is too long!");
+               return -EINVAL;
+       }
+
+       wlvif->ssid_len = ssid_len;
+       memcpy(wlvif->ssid, ptr+2, ssid_len);
+       return 0;
+}
+
+static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset)
+{
+       int len;
+       const u8 *next, *end = skb->data + skb->len;
+       u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset,
+                                       skb->len - ieoffset);
+       if (!ie)
+               return;
+       len = ie[1] + 2;
+       next = ie + len;
+       memmove(ie, next, end - next);
+       skb_trim(skb, skb->len - len);
+}
+
+static void wl12xx_remove_vendor_ie(struct sk_buff *skb,
+                                           unsigned int oui, u8 oui_type,
+                                           int ieoffset)
+{
+       int len;
+       const u8 *next, *end = skb->data + skb->len;
+       u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
+                                              skb->data + ieoffset,
+                                              skb->len - ieoffset);
+       if (!ie)
+               return;
+       len = ie[1] + 2;
+       next = ie + len;
+       memmove(ie, next, end - next);
+       skb_trim(skb, skb->len - len);
+}
+
+static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates,
+                                        struct ieee80211_vif *vif)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       struct sk_buff *skb;
+       int ret;
+
+       skb = ieee80211_proberesp_get(wl->hw, vif);
+       if (!skb)
+               return -EOPNOTSUPP;
+
+       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
+                                     CMD_TEMPL_AP_PROBE_RESPONSE,
+                                     skb->data,
+                                     skb->len, 0,
+                                     rates);
+
+       dev_kfree_skb(skb);
+       return ret;
+}
+
+static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl,
+                                            struct ieee80211_vif *vif,
+                                            u8 *probe_rsp_data,
+                                            size_t probe_rsp_len,
+                                            u32 rates)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
+       u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE];
+       int ssid_ie_offset, ie_offset, templ_len;
+       const u8 *ptr;
+
+       /* no need to change probe response if the SSID is set correctly */
+       if (wlvif->ssid_len > 0)
+               return wl1271_cmd_template_set(wl, wlvif->role_id,
+                                              CMD_TEMPL_AP_PROBE_RESPONSE,
+                                              probe_rsp_data,
+                                              probe_rsp_len, 0,
+                                              rates);
+
+       if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) {
+               wl1271_error("probe_rsp template too big");
+               return -EINVAL;
+       }
+
+       /* start searching from IE offset */
+       ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
+
+       ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset,
+                              probe_rsp_len - ie_offset);
+       if (!ptr) {
+               wl1271_error("No SSID in beacon!");
+               return -EINVAL;
+       }
+
+       ssid_ie_offset = ptr - probe_rsp_data;
+       ptr += (ptr[1] + 2);
+
+       memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset);
+
+       /* insert SSID from bss_conf */
+       probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID;
+       probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len;
+       memcpy(probe_rsp_templ + ssid_ie_offset + 2,
+              bss_conf->ssid, bss_conf->ssid_len);
+       templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len;
+
+       memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len,
+              ptr, probe_rsp_len - (ptr - probe_rsp_data));
+       templ_len += probe_rsp_len - (ptr - probe_rsp_data);
+
+       return wl1271_cmd_template_set(wl, wlvif->role_id,
+                                      CMD_TEMPL_AP_PROBE_RESPONSE,
+                                      probe_rsp_templ,
+                                      templ_len, 0,
+                                      rates);
+}
+
+static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
+                                      struct ieee80211_vif *vif,
+                                      struct ieee80211_bss_conf *bss_conf,
+                                      u32 changed)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       int ret = 0;
+
+       if (changed & BSS_CHANGED_ERP_SLOT) {
+               if (bss_conf->use_short_slot)
+                       ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT);
+               else
+                       ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG);
+               if (ret < 0) {
+                       wl1271_warning("Set slot time failed %d", ret);
+                       goto out;
+               }
+       }
+
+       if (changed & BSS_CHANGED_ERP_PREAMBLE) {
+               if (bss_conf->use_short_preamble)
+                       wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT);
+               else
+                       wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG);
+       }
+
+       if (changed & BSS_CHANGED_ERP_CTS_PROT) {
+               if (bss_conf->use_cts_prot)
+                       ret = wl1271_acx_cts_protect(wl, wlvif,
+                                                    CTSPROTECT_ENABLE);
+               else
+                       ret = wl1271_acx_cts_protect(wl, wlvif,
+                                                    CTSPROTECT_DISABLE);
+               if (ret < 0) {
+                       wl1271_warning("Set ctsprotect failed %d", ret);
+                       goto out;
+               }
+       }
+
+out:
+       return ret;
+}
+
+static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
+                                         struct ieee80211_vif *vif,
+                                         struct ieee80211_bss_conf *bss_conf,
+                                         u32 changed)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
+       int ret = 0;
+
+       if ((changed & BSS_CHANGED_BEACON_INT)) {
+               wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
+                       bss_conf->beacon_int);
+
+               wlvif->beacon_int = bss_conf->beacon_int;
+       }
+
+       if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) {
+               u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
+               if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) {
+                       wl1271_debug(DEBUG_AP, "probe response updated");
+                       set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
+               }
+       }
+
+       if ((changed & BSS_CHANGED_BEACON)) {
+               struct ieee80211_hdr *hdr;
+               u32 min_rate;
+               int ieoffset = offsetof(struct ieee80211_mgmt,
+                                       u.beacon.variable);
+               struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
+               u16 tmpl_id;
+
+               if (!beacon) {
+                       ret = -EINVAL;
+                       goto out;
+               }
+
+               wl1271_debug(DEBUG_MASTER, "beacon updated");
+
+               ret = wl1271_ssid_set(vif, beacon, ieoffset);
+               if (ret < 0) {
+                       dev_kfree_skb(beacon);
+                       goto out;
+               }
+               min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
+               tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
+                                 CMD_TEMPL_BEACON;
+               ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id,
+                                             beacon->data,
+                                             beacon->len, 0,
+                                             min_rate);
+               if (ret < 0) {
+                       dev_kfree_skb(beacon);
+                       goto out;
+               }
+
+               /*
+                * In case we already have a probe-resp beacon set explicitly
+                * by usermode, don't use the beacon data.
+                */
+               if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
+                       goto end_bcn;
+
+               /* remove TIM ie from probe response */
+               wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
+
+               /*
+                * remove p2p ie from probe response.
+                * the fw reponds to probe requests that don't include
+                * the p2p ie. probe requests with p2p ie will be passed,
+                * and will be responded by the supplicant (the spec
+                * forbids including the p2p ie when responding to probe
+                * requests that didn't include it).
+                */
+               wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA,
+                                       WLAN_OUI_TYPE_WFA_P2P, ieoffset);
+
+               hdr = (struct ieee80211_hdr *) beacon->data;
+               hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
+                                                IEEE80211_STYPE_PROBE_RESP);
+               if (is_ap)
+                       ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
+                                               beacon->data,
+                                               beacon->len,
+                                               min_rate);
+               else
+                       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
+                                               CMD_TEMPL_PROBE_RESPONSE,
+                                               beacon->data,
+                                               beacon->len, 0,
+                                               min_rate);
+end_bcn:
+               dev_kfree_skb(beacon);
+               if (ret < 0)
+                       goto out;
+       }
+
+out:
+       if (ret != 0)
+               wl1271_error("beacon info change failed: %d", ret);
+       return ret;
+}
+
+/* AP mode changes */
+static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
+                                      struct ieee80211_vif *vif,
+                                      struct ieee80211_bss_conf *bss_conf,
+                                      u32 changed)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       int ret = 0;
+
+       if ((changed & BSS_CHANGED_BASIC_RATES)) {
+               u32 rates = bss_conf->basic_rates;
+
+               wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates,
+                                                                wlvif->band);
+               wlvif->basic_rate = wl1271_tx_min_rate_get(wl,
+                                                       wlvif->basic_rate_set);
+
+               ret = wl1271_init_ap_rates(wl, wlvif);
+               if (ret < 0) {
+                       wl1271_error("AP rate policy change failed %d", ret);
+                       goto out;
+               }
+
+               ret = wl1271_ap_init_templates(wl, vif);
+               if (ret < 0)
+                       goto out;
+       }
+
+       ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
+       if (ret < 0)
+               goto out;
+
+       if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
+               if (bss_conf->enable_beacon) {
+                       if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
+                               ret = wl12xx_cmd_role_start_ap(wl, wlvif);
+                               if (ret < 0)
+                                       goto out;
+
+                               ret = wl1271_ap_init_hwenc(wl, wlvif);
+                               if (ret < 0)
+                                       goto out;
+
+                               set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
+                               wl1271_debug(DEBUG_AP, "started AP");
+                       }
+               } else {
+                       if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
+                               ret = wl12xx_cmd_role_stop_ap(wl, wlvif);
+                               if (ret < 0)
+                                       goto out;
+
+                               clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
+                               clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET,
+                                         &wlvif->flags);
+                               wl1271_debug(DEBUG_AP, "stopped AP");
+                       }
+               }
+       }
+
+       ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
+       if (ret < 0)
+               goto out;
+
+       /* Handle HT information change */
+       if ((changed & BSS_CHANGED_HT) &&
+           (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
+               ret = wl1271_acx_set_ht_information(wl, wlvif,
+                                       bss_conf->ht_operation_mode);
+               if (ret < 0) {
+                       wl1271_warning("Set ht information failed %d", ret);
+                       goto out;
+               }
+       }
+
+out:
+       return;
+}
+
+/* STA/IBSS mode changes */
+static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
+                                       struct ieee80211_vif *vif,
+                                       struct ieee80211_bss_conf *bss_conf,
+                                       u32 changed)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       bool do_join = false, set_assoc = false;
+       bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
+       bool ibss_joined = false;
+       u32 sta_rate_set = 0;
+       int ret;
+       struct ieee80211_sta *sta;
+       bool sta_exists = false;
+       struct ieee80211_sta_ht_cap sta_ht_cap;
+
+       if (is_ibss) {
+               ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
+                                                    changed);
+               if (ret < 0)
+                       goto out;
+       }
+
+       if (changed & BSS_CHANGED_IBSS) {
+               if (bss_conf->ibss_joined) {
+                       set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags);
+                       ibss_joined = true;
+               } else {
+                       if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED,
+                                              &wlvif->flags))
+                               wl1271_unjoin(wl, wlvif);
+               }
+       }
+
+       if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined)
+               do_join = true;
+
+       /* Need to update the SSID (for filtering etc) */
+       if ((changed & BSS_CHANGED_BEACON) && ibss_joined)
+               do_join = true;
+
+       if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) {
+               wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
+                            bss_conf->enable_beacon ? "enabled" : "disabled");
+
+               do_join = true;
+       }
+
+       if (changed & BSS_CHANGED_IDLE && !is_ibss) {
+               ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle);
+               if (ret < 0)
+                       wl1271_warning("idle mode change failed %d", ret);
+       }
+
+       if ((changed & BSS_CHANGED_CQM)) {
+               bool enable = false;
+               if (bss_conf->cqm_rssi_thold)
+                       enable = true;
+               ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable,
+                                                 bss_conf->cqm_rssi_thold,
+                                                 bss_conf->cqm_rssi_hyst);
+               if (ret < 0)
+                       goto out;
+               wlvif->rssi_thold = bss_conf->cqm_rssi_thold;
+       }
+
+       if (changed & BSS_CHANGED_BSSID)
+               if (!is_zero_ether_addr(bss_conf->bssid)) {
+                       ret = wl12xx_cmd_build_null_data(wl, wlvif);
+                       if (ret < 0)
+                               goto out;
+
+                       ret = wl1271_build_qos_null_data(wl, vif);
+                       if (ret < 0)
+                               goto out;
+               }
+
+       if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) {
+               rcu_read_lock();
+               sta = ieee80211_find_sta(vif, bss_conf->bssid);
+               if (!sta)
+                       goto sta_not_found;
+
+               /* save the supp_rates of the ap */
+               sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
+               if (sta->ht_cap.ht_supported)
+                       sta_rate_set |=
+                           (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
+               sta_ht_cap = sta->ht_cap;
+               sta_exists = true;
+
+sta_not_found:
+               rcu_read_unlock();
+       }
+
+       if ((changed & BSS_CHANGED_ASSOC)) {
+               if (bss_conf->assoc) {
+                       u32 rates;
+                       int ieoffset;
+                       wlvif->aid = bss_conf->aid;
+                       wlvif->beacon_int = bss_conf->beacon_int;
+                       do_join = true;
+                       set_assoc = true;
+
+                       /*
+                        * use basic rates from AP, and determine lowest rate
+                        * to use with control frames.
+                        */
+                       rates = bss_conf->basic_rates;
+                       wlvif->basic_rate_set =
+                               wl1271_tx_enabled_rates_get(wl, rates,
+                                                           wlvif->band);
+                       wlvif->basic_rate =
+                               wl1271_tx_min_rate_get(wl,
+                                                      wlvif->basic_rate_set);
+                       if (sta_rate_set)
+                               wlvif->rate_set =
+                                       wl1271_tx_enabled_rates_get(wl,
+                                                               sta_rate_set,
+                                                               wlvif->band);
+                       ret = wl1271_acx_sta_rate_policies(wl, wlvif);
+                       if (ret < 0)
+                               goto out;
+
+                       /*
+                        * with wl1271, we don't need to update the
+                        * beacon_int and dtim_period, because the firmware
+                        * updates it by itself when the first beacon is
+                        * received after a join.
+                        */
+                       ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid);
+                       if (ret < 0)
+                               goto out;
+
+                       /*
+                        * Get a template for hardware connection maintenance
+                        */
+                       dev_kfree_skb(wlvif->probereq);
+                       wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl,
+                                                                       wlvif,
+                                                                       NULL);
+                       ieoffset = offsetof(struct ieee80211_mgmt,
+                                           u.probe_req.variable);
+                       wl1271_ssid_set(vif, wlvif->probereq, ieoffset);
+
+                       /* enable the connection monitoring feature */
+                       ret = wl1271_acx_conn_monit_params(wl, wlvif, true);
+                       if (ret < 0)
+                               goto out;
+               } else {
+                       /* use defaults when not associated */
+                       bool was_assoc =
+                           !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED,
+                                                &wlvif->flags);
+                       bool was_ifup =
+                           !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT,
+                                                &wlvif->flags);
+                       wlvif->aid = 0;
+
+                       /* free probe-request template */
+                       dev_kfree_skb(wlvif->probereq);
+                       wlvif->probereq = NULL;
+
+                       /* revert back to minimum rates for the current band */
+                       wl1271_set_band_rate(wl, wlvif);
+                       wlvif->basic_rate =
+                               wl1271_tx_min_rate_get(wl,
+                                                      wlvif->basic_rate_set);
+                       ret = wl1271_acx_sta_rate_policies(wl, wlvif);
+                       if (ret < 0)
+                               goto out;
+
+                       /* disable connection monitor features */
+                       ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
+
+                       /* Disable the keep-alive feature */
+                       ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
+                       if (ret < 0)
+                               goto out;
+
+                       /* restore the bssid filter and go to dummy bssid */
+                       if (was_assoc) {
+                               /*
+                                * we might have to disable roc, if there was
+                                * no IF_OPER_UP notification.
+                                */
+                               if (!was_ifup) {
+                                       ret = wl12xx_croc(wl, wlvif->role_id);
+                                       if (ret < 0)
+                                               goto out;
+                               }
+                               /*
+                                * (we also need to disable roc in case of
+                                * roaming on the same channel. until we will
+                                * have a better flow...)
+                                */
+                               if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
+                                       ret = wl12xx_croc(wl,
+                                                         wlvif->dev_role_id);
+                                       if (ret < 0)
+                                               goto out;
+                               }
+
+                               wl1271_unjoin(wl, wlvif);
+                               if (!bss_conf->idle)
+                                       wl12xx_start_dev(wl, wlvif);
+                       }
+               }
+       }
+
+       if (changed & BSS_CHANGED_IBSS) {
+               wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
+                            bss_conf->ibss_joined);
+
+               if (bss_conf->ibss_joined) {
+                       u32 rates = bss_conf->basic_rates;
+                       wlvif->basic_rate_set =
+                               wl1271_tx_enabled_rates_get(wl, rates,
+                                                           wlvif->band);
+                       wlvif->basic_rate =
+                               wl1271_tx_min_rate_get(wl,
+                                                      wlvif->basic_rate_set);
+
+                       /* by default, use 11b + OFDM rates */
+                       wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
+                       ret = wl1271_acx_sta_rate_policies(wl, wlvif);
+                       if (ret < 0)
+                               goto out;
+               }
+       }
+
+       ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
+       if (ret < 0)
+               goto out;
+
+       if (do_join) {
+               ret = wl1271_join(wl, wlvif, set_assoc);
+               if (ret < 0) {
+                       wl1271_warning("cmd join failed %d", ret);
+                       goto out;
+               }
+
+               /* ROC until connected (after EAPOL exchange) */
+               if (!is_ibss) {
+                       ret = wl12xx_roc(wl, wlvif, wlvif->role_id);
+                       if (ret < 0)
+                               goto out;
+
+                       if (test_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags))
+                               wl12xx_set_authorized(wl, wlvif);
+               }
+               /*
+                * stop device role if started (we might already be in
+                * STA/IBSS role).
+                */
+               if (wl12xx_dev_role_started(wlvif)) {
+                       ret = wl12xx_stop_dev(wl, wlvif);
+                       if (ret < 0)
+                               goto out;
+               }
+       }
+
+       /* Handle new association with HT. Do this after join. */
+       if (sta_exists) {
+               if ((changed & BSS_CHANGED_HT) &&
+                   (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
+                       ret = wl1271_acx_set_ht_capabilities(wl,
+                                                            &sta_ht_cap,
+                                                            true,
+                                                            wlvif->sta.hlid);
+                       if (ret < 0) {
+                               wl1271_warning("Set ht cap true failed %d",
+                                              ret);
+                               goto out;
+                       }
+               }
+               /* handle new association without HT and disassociation */
+               else if (changed & BSS_CHANGED_ASSOC) {
+                       ret = wl1271_acx_set_ht_capabilities(wl,
+                                                            &sta_ht_cap,
+                                                            false,
+                                                            wlvif->sta.hlid);
+                       if (ret < 0) {
+                               wl1271_warning("Set ht cap false failed %d",
+                                              ret);
+                               goto out;
+                       }
+               }
+       }
+
+       /* Handle HT information change. Done after join. */
+       if ((changed & BSS_CHANGED_HT) &&
+           (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
+               ret = wl1271_acx_set_ht_information(wl, wlvif,
+                                       bss_conf->ht_operation_mode);
+               if (ret < 0) {
+                       wl1271_warning("Set ht information failed %d", ret);
+                       goto out;
+               }
+       }
+
+       /* Handle arp filtering. Done after join. */
+       if ((changed & BSS_CHANGED_ARP_FILTER) ||
+           (!is_ibss && (changed & BSS_CHANGED_QOS))) {
+               __be32 addr = bss_conf->arp_addr_list[0];
+               wlvif->sta.qos = bss_conf->qos;
+               WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS);
+
+               if (bss_conf->arp_addr_cnt == 1 &&
+                   bss_conf->arp_filter_enabled) {
+                       wlvif->ip_addr = addr;
+                       /*
+                        * The template should have been configured only upon
+                        * association. however, it seems that the correct ip
+                        * isn't being set (when sending), so we have to
+                        * reconfigure the template upon every ip change.
+                        */
+                       ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
+                       if (ret < 0) {
+                               wl1271_warning("build arp rsp failed: %d", ret);
+                               goto out;
+                       }
+
+                       ret = wl1271_acx_arp_ip_filter(wl, wlvif,
+                               (ACX_ARP_FILTER_ARP_FILTERING |
+                                ACX_ARP_FILTER_AUTO_ARP),
+                               addr);
+               } else {
+                       wlvif->ip_addr = 0;
+                       ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr);
+               }
+
+               if (ret < 0)
+                       goto out;
+       }
+
+out:
+       return;
+}
+
+static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
+                                      struct ieee80211_vif *vif,
+                                      struct ieee80211_bss_conf *bss_conf,
+                                      u32 changed)
+{
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
+       int ret;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
+                    (int)changed);
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF))
+               goto out;
+
+       if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       if (is_ap)
+               wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed);
+       else
+               wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed);
+
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
+                            struct ieee80211_vif *vif, u16 queue,
+                            const struct ieee80211_tx_queue_params *params)
+{
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       u8 ps_scheme;
+       int ret = 0;
+
+       mutex_lock(&wl->mutex);
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
+
+       if (params->uapsd)
+               ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
+       else
+               ps_scheme = CONF_PS_SCHEME_LEGACY;
+
+       if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       /*
+        * the txop is confed in units of 32us by the mac80211,
+        * we need us
+        */
+       ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
+                               params->cw_min, params->cw_max,
+                               params->aifs, params->txop << 5);
+       if (ret < 0)
+               goto out_sleep;
+
+       ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
+                                CONF_CHANNEL_TYPE_EDCF,
+                                wl1271_tx_get_queue(queue),
+                                ps_scheme, CONF_ACK_POLICY_LEGACY,
+                                0, 0);
+
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw,
+                            struct ieee80211_vif *vif)
+{
+
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       u64 mactime = ULLONG_MAX;
+       int ret;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf");
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF))
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime);
+       if (ret < 0)
+               goto out_sleep;
+
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+       return mactime;
+}
+
+static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
+                               struct survey_info *survey)
+{
+       struct wl1271 *wl = hw->priv;
+       struct ieee80211_conf *conf = &hw->conf;
+
+       if (idx != 0)
+               return -ENOENT;
+
+       survey->channel = conf->channel;
+       survey->filled = SURVEY_INFO_NOISE_DBM;
+       survey->noise = wl->noise;
+
+       return 0;
+}
+
+static int wl1271_allocate_sta(struct wl1271 *wl,
+                            struct wl12xx_vif *wlvif,
+                            struct ieee80211_sta *sta)
+{
+       struct wl1271_station *wl_sta;
+       int ret;
+
+
+       if (wl->active_sta_count >= AP_MAX_STATIONS) {
+               wl1271_warning("could not allocate HLID - too much stations");
+               return -EBUSY;
+       }
+
+       wl_sta = (struct wl1271_station *)sta->drv_priv;
+       ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid);
+       if (ret < 0) {
+               wl1271_warning("could not allocate HLID - too many links");
+               return -EBUSY;
+       }
+
+       set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map);
+       memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
+       wl->active_sta_count++;
+       return 0;
+}
+
+void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
+{
+       if (!test_bit(hlid, wlvif->ap.sta_hlid_map))
+               return;
+
+       clear_bit(hlid, wlvif->ap.sta_hlid_map);
+       memset(wl->links[hlid].addr, 0, ETH_ALEN);
+       wl->links[hlid].ba_bitmap = 0;
+       __clear_bit(hlid, &wl->ap_ps_map);
+       __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
+       wl12xx_free_link(wl, wlvif, &hlid);
+       wl->active_sta_count--;
+
+       /*
+        * rearm the tx watchdog when the last STA is freed - give the FW a
+        * chance to return STA-buffered packets before complaining.
+        */
+       if (wl->active_sta_count == 0)
+               wl12xx_rearm_tx_watchdog_locked(wl);
+}
+
+static int wl12xx_sta_add(struct wl1271 *wl,
+                         struct wl12xx_vif *wlvif,
+                         struct ieee80211_sta *sta)
+{
+       struct wl1271_station *wl_sta;
+       int ret = 0;
+       u8 hlid;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
+
+       ret = wl1271_allocate_sta(wl, wlvif, sta);
+       if (ret < 0)
+               return ret;
+
+       wl_sta = (struct wl1271_station *)sta->drv_priv;
+       hlid = wl_sta->hlid;
+
+       ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid);
+       if (ret < 0)
+               wl1271_free_sta(wl, wlvif, hlid);
+
+       return ret;
+}
+
+static int wl12xx_sta_remove(struct wl1271 *wl,
+                            struct wl12xx_vif *wlvif,
+                            struct ieee80211_sta *sta)
+{
+       struct wl1271_station *wl_sta;
+       int ret = 0, id;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
+
+       wl_sta = (struct wl1271_station *)sta->drv_priv;
+       id = wl_sta->hlid;
+       if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map)))
+               return -EINVAL;
+
+       ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid);
+       if (ret < 0)
+               return ret;
+
+       wl1271_free_sta(wl, wlvif, wl_sta->hlid);
+       return ret;
+}
+
+static int wl12xx_update_sta_state(struct wl1271 *wl,
+                                  struct wl12xx_vif *wlvif,
+                                  struct ieee80211_sta *sta,
+                                  enum ieee80211_sta_state old_state,
+                                  enum ieee80211_sta_state new_state)
+{
+       struct wl1271_station *wl_sta;
+       u8 hlid;
+       bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
+       bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
+       int ret;
+
+       wl_sta = (struct wl1271_station *)sta->drv_priv;
+       hlid = wl_sta->hlid;
+
+       /* Add station (AP mode) */
+       if (is_ap &&
+           old_state == IEEE80211_STA_NOTEXIST &&
+           new_state == IEEE80211_STA_NONE)
+               return wl12xx_sta_add(wl, wlvif, sta);
+
+       /* Remove station (AP mode) */
+       if (is_ap &&
+           old_state == IEEE80211_STA_NONE &&
+           new_state == IEEE80211_STA_NOTEXIST) {
+               /* must not fail */
+               wl12xx_sta_remove(wl, wlvif, sta);
+               return 0;
+       }
+
+       /* Authorize station (AP mode) */
+       if (is_ap &&
+           new_state == IEEE80211_STA_AUTHORIZED) {
+               ret = wl12xx_cmd_set_peer_state(wl, hlid);
+               if (ret < 0)
+                       return ret;
+
+               ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true,
+                                                    hlid);
+               return ret;
+       }
+
+       /* Authorize station */
+       if (is_sta &&
+           new_state == IEEE80211_STA_AUTHORIZED) {
+               set_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
+               return wl12xx_set_authorized(wl, wlvif);
+       }
+
+       if (is_sta &&
+           old_state == IEEE80211_STA_AUTHORIZED &&
+           new_state == IEEE80211_STA_ASSOC) {
+               clear_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
+               return 0;
+       }
+
+       return 0;
+}
+
+static int wl12xx_op_sta_state(struct ieee80211_hw *hw,
+                              struct ieee80211_vif *vif,
+                              struct ieee80211_sta *sta,
+                              enum ieee80211_sta_state old_state,
+                              enum ieee80211_sta_state new_state)
+{
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       int ret;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 sta %d state=%d->%d",
+                    sta->aid, old_state, new_state);
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF)) {
+               ret = -EBUSY;
+               goto out;
+       }
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl12xx_update_sta_state(wl, wlvif, sta, old_state, new_state);
+
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+       if (new_state < old_state)
+               return 0;
+       return ret;
+}
+
+static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
+                                 struct ieee80211_vif *vif,
+                                 enum ieee80211_ampdu_mlme_action action,
+                                 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
+                                 u8 buf_size)
+{
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       int ret;
+       u8 hlid, *ba_bitmap;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action,
+                    tid);
+
+       /* sanity check - the fields in FW are only 8bits wide */
+       if (WARN_ON(tid > 0xFF))
+               return -ENOTSUPP;
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF)) {
+               ret = -EAGAIN;
+               goto out;
+       }
+
+       if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
+               hlid = wlvif->sta.hlid;
+               ba_bitmap = &wlvif->sta.ba_rx_bitmap;
+       } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
+               struct wl1271_station *wl_sta;
+
+               wl_sta = (struct wl1271_station *)sta->drv_priv;
+               hlid = wl_sta->hlid;
+               ba_bitmap = &wl->links[hlid].ba_bitmap;
+       } else {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d",
+                    tid, action);
+
+       switch (action) {
+       case IEEE80211_AMPDU_RX_START:
+               if (!wlvif->ba_support || !wlvif->ba_allowed) {
+                       ret = -ENOTSUPP;
+                       break;
+               }
+
+               if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) {
+                       ret = -EBUSY;
+                       wl1271_error("exceeded max RX BA sessions");
+                       break;
+               }
+
+               if (*ba_bitmap & BIT(tid)) {
+                       ret = -EINVAL;
+                       wl1271_error("cannot enable RX BA session on active "
+                                    "tid: %d", tid);
+                       break;
+               }
+
+               ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true,
+                                                        hlid);
+               if (!ret) {
+                       *ba_bitmap |= BIT(tid);
+                       wl->ba_rx_session_count++;
+               }
+               break;
+
+       case IEEE80211_AMPDU_RX_STOP:
+               if (!(*ba_bitmap & BIT(tid))) {
+                       ret = -EINVAL;
+                       wl1271_error("no active RX BA session on tid: %d",
+                                    tid);
+                       break;
+               }
+
+               ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false,
+                                                        hlid);
+               if (!ret) {
+                       *ba_bitmap &= ~BIT(tid);
+                       wl->ba_rx_session_count--;
+               }
+               break;
+
+       /*
+        * The BA initiator session management in FW independently.
+        * Falling break here on purpose for all TX APDU commands.
+        */
+       case IEEE80211_AMPDU_TX_START:
+       case IEEE80211_AMPDU_TX_STOP:
+       case IEEE80211_AMPDU_TX_OPERATIONAL:
+               ret = -EINVAL;
+               break;
+
+       default:
+               wl1271_error("Incorrect ampdu action id=%x\n", action);
+               ret = -EINVAL;
+       }
+
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
+                                  struct ieee80211_vif *vif,
+                                  const struct cfg80211_bitrate_mask *mask)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       struct wl1271 *wl = hw->priv;
+       int i, ret = 0;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x",
+               mask->control[NL80211_BAND_2GHZ].legacy,
+               mask->control[NL80211_BAND_5GHZ].legacy);
+
+       mutex_lock(&wl->mutex);
+
+       for (i = 0; i < IEEE80211_NUM_BANDS; i++)
+               wlvif->bitrate_masks[i] =
+                       wl1271_tx_enabled_rates_get(wl,
+                                                   mask->control[i].legacy,
+                                                   i);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF))
+               goto out;
+
+       if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
+           !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
+
+               ret = wl1271_ps_elp_wakeup(wl);
+               if (ret < 0)
+                       goto out;
+
+               wl1271_set_band_rate(wl, wlvif);
+               wlvif->basic_rate =
+                       wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
+               ret = wl1271_acx_sta_rate_policies(wl, wlvif);
+
+               wl1271_ps_elp_sleep(wl);
+       }
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
+                                    struct ieee80211_channel_switch *ch_switch)
+{
+       struct wl1271 *wl = hw->priv;
+       struct wl12xx_vif *wlvif;
+       int ret;
+
+       wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch");
+
+       wl1271_tx_flush(wl);
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF)) {
+               wl12xx_for_each_wlvif_sta(wl, wlvif) {
+                       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+                       ieee80211_chswitch_done(vif, false);
+               }
+               goto out;
+       }
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       /* TODO: change mac80211 to pass vif as param */
+       wl12xx_for_each_wlvif_sta(wl, wlvif) {
+               ret = wl12xx_cmd_channel_switch(wl, wlvif, ch_switch);
+
+               if (!ret)
+                       set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags);
+       }
+
+       wl1271_ps_elp_sleep(wl);
+
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
+{
+       struct wl1271 *wl = hw->priv;
+       bool ret = false;
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF))
+               goto out;
+
+       /* packets are considered pending if in the TX queue or the FW */
+       ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0);
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+}
+
+/* can't be const, mac80211 writes to this */
+static struct ieee80211_rate wl1271_rates[] = {
+       { .bitrate = 10,
+         .hw_value = CONF_HW_BIT_RATE_1MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
+       { .bitrate = 20,
+         .hw_value = CONF_HW_BIT_RATE_2MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
+         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+       { .bitrate = 55,
+         .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
+         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+       { .bitrate = 110,
+         .hw_value = CONF_HW_BIT_RATE_11MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
+         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
+       { .bitrate = 60,
+         .hw_value = CONF_HW_BIT_RATE_6MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
+       { .bitrate = 90,
+         .hw_value = CONF_HW_BIT_RATE_9MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
+       { .bitrate = 120,
+         .hw_value = CONF_HW_BIT_RATE_12MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
+       { .bitrate = 180,
+         .hw_value = CONF_HW_BIT_RATE_18MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
+       { .bitrate = 240,
+         .hw_value = CONF_HW_BIT_RATE_24MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
+       { .bitrate = 360,
+        .hw_value = CONF_HW_BIT_RATE_36MBPS,
+        .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
+       { .bitrate = 480,
+         .hw_value = CONF_HW_BIT_RATE_48MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
+       { .bitrate = 540,
+         .hw_value = CONF_HW_BIT_RATE_54MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
+};
+
+/* can't be const, mac80211 writes to this */
+static struct ieee80211_channel wl1271_channels[] = {
+       { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
+       { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
+       { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
+       { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
+       { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
+       { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
+       { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
+       { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
+       { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
+       { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
+       { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
+       { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
+       { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
+       { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
+};
+
+/* can't be const, mac80211 writes to this */
+static struct ieee80211_supported_band wl1271_band_2ghz = {
+       .channels = wl1271_channels,
+       .n_channels = ARRAY_SIZE(wl1271_channels),
+       .bitrates = wl1271_rates,
+       .n_bitrates = ARRAY_SIZE(wl1271_rates),
+};
+
+/* 5 GHz data rates for WL1273 */
+static struct ieee80211_rate wl1271_rates_5ghz[] = {
+       { .bitrate = 60,
+         .hw_value = CONF_HW_BIT_RATE_6MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
+       { .bitrate = 90,
+         .hw_value = CONF_HW_BIT_RATE_9MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
+       { .bitrate = 120,
+         .hw_value = CONF_HW_BIT_RATE_12MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
+       { .bitrate = 180,
+         .hw_value = CONF_HW_BIT_RATE_18MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
+       { .bitrate = 240,
+         .hw_value = CONF_HW_BIT_RATE_24MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
+       { .bitrate = 360,
+        .hw_value = CONF_HW_BIT_RATE_36MBPS,
+        .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
+       { .bitrate = 480,
+         .hw_value = CONF_HW_BIT_RATE_48MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
+       { .bitrate = 540,
+         .hw_value = CONF_HW_BIT_RATE_54MBPS,
+         .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
+};
+
+/* 5 GHz band channels for WL1273 */
+static struct ieee80211_channel wl1271_channels_5ghz[] = {
+       { .hw_value = 7, .center_freq = 5035, .max_power = 25 },
+       { .hw_value = 8, .center_freq = 5040, .max_power = 25 },
+       { .hw_value = 9, .center_freq = 5045, .max_power = 25 },
+       { .hw_value = 11, .center_freq = 5055, .max_power = 25 },
+       { .hw_value = 12, .center_freq = 5060, .max_power = 25 },
+       { .hw_value = 16, .center_freq = 5080, .max_power = 25 },
+       { .hw_value = 34, .center_freq = 5170, .max_power = 25 },
+       { .hw_value = 36, .center_freq = 5180, .max_power = 25 },
+       { .hw_value = 38, .center_freq = 5190, .max_power = 25 },
+       { .hw_value = 40, .center_freq = 5200, .max_power = 25 },
+       { .hw_value = 42, .center_freq = 5210, .max_power = 25 },
+       { .hw_value = 44, .center_freq = 5220, .max_power = 25 },
+       { .hw_value = 46, .center_freq = 5230, .max_power = 25 },
+       { .hw_value = 48, .center_freq = 5240, .max_power = 25 },
+       { .hw_value = 52, .center_freq = 5260, .max_power = 25 },
+       { .hw_value = 56, .center_freq = 5280, .max_power = 25 },
+       { .hw_value = 60, .center_freq = 5300, .max_power = 25 },
+       { .hw_value = 64, .center_freq = 5320, .max_power = 25 },
+       { .hw_value = 100, .center_freq = 5500, .max_power = 25 },
+       { .hw_value = 104, .center_freq = 5520, .max_power = 25 },
+       { .hw_value = 108, .center_freq = 5540, .max_power = 25 },
+       { .hw_value = 112, .center_freq = 5560, .max_power = 25 },
+       { .hw_value = 116, .center_freq = 5580, .max_power = 25 },
+       { .hw_value = 120, .center_freq = 5600, .max_power = 25 },
+       { .hw_value = 124, .center_freq = 5620, .max_power = 25 },
+       { .hw_value = 128, .center_freq = 5640, .max_power = 25 },
+       { .hw_value = 132, .center_freq = 5660, .max_power = 25 },
+       { .hw_value = 136, .center_freq = 5680, .max_power = 25 },
+       { .hw_value = 140, .center_freq = 5700, .max_power = 25 },
+       { .hw_value = 149, .center_freq = 5745, .max_power = 25 },
+       { .hw_value = 153, .center_freq = 5765, .max_power = 25 },
+       { .hw_value = 157, .center_freq = 5785, .max_power = 25 },
+       { .hw_value = 161, .center_freq = 5805, .max_power = 25 },
+       { .hw_value = 165, .center_freq = 5825, .max_power = 25 },
+};
+
+static struct ieee80211_supported_band wl1271_band_5ghz = {
+       .channels = wl1271_channels_5ghz,
+       .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
+       .bitrates = wl1271_rates_5ghz,
+       .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
+};
+
+static const struct ieee80211_ops wl1271_ops = {
+       .start = wl1271_op_start,
+       .stop = wl1271_op_stop,
+       .add_interface = wl1271_op_add_interface,
+       .remove_interface = wl1271_op_remove_interface,
+       .change_interface = wl12xx_op_change_interface,
+#ifdef CONFIG_PM
+       .suspend = wl1271_op_suspend,
+       .resume = wl1271_op_resume,
+#endif
+       .config = wl1271_op_config,
+       .prepare_multicast = wl1271_op_prepare_multicast,
+       .configure_filter = wl1271_op_configure_filter,
+       .tx = wl1271_op_tx,
+       .set_key = wl1271_op_set_key,
+       .hw_scan = wl1271_op_hw_scan,
+       .cancel_hw_scan = wl1271_op_cancel_hw_scan,
+       .sched_scan_start = wl1271_op_sched_scan_start,
+       .sched_scan_stop = wl1271_op_sched_scan_stop,
+       .bss_info_changed = wl1271_op_bss_info_changed,
+       .set_frag_threshold = wl1271_op_set_frag_threshold,
+       .set_rts_threshold = wl1271_op_set_rts_threshold,
+       .conf_tx = wl1271_op_conf_tx,
+       .get_tsf = wl1271_op_get_tsf,
+       .get_survey = wl1271_op_get_survey,
+       .sta_state = wl12xx_op_sta_state,
+       .ampdu_action = wl1271_op_ampdu_action,
+       .tx_frames_pending = wl1271_tx_frames_pending,
+       .set_bitrate_mask = wl12xx_set_bitrate_mask,
+       .channel_switch = wl12xx_op_channel_switch,
+       CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
+};
+
+
+u8 wlcore_rate_to_idx(struct wl1271 *wl, u8 rate, enum ieee80211_band band)
+{
+       u8 idx;
+
+       BUG_ON(band >= 2);
+
+       if (unlikely(rate >= wl->hw_tx_rate_tbl_size)) {
+               wl1271_error("Illegal RX rate from HW: %d", rate);
+               return 0;
+       }
+
+       idx = wl->band_rate_to_idx[band][rate];
+       if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
+               wl1271_error("Unsupported RX rate from HW: %d", rate);
+               return 0;
+       }
+
+       return idx;
+}
+
+static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev,
+                                              struct device_attribute *attr,
+                                              char *buf)
+{
+       struct wl1271 *wl = dev_get_drvdata(dev);
+       ssize_t len;
+
+       len = PAGE_SIZE;
+
+       mutex_lock(&wl->mutex);
+       len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
+                      wl->sg_enabled);
+       mutex_unlock(&wl->mutex);
+
+       return len;
+
+}
+
+static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
+                                               struct device_attribute *attr,
+                                               const char *buf, size_t count)
+{
+       struct wl1271 *wl = dev_get_drvdata(dev);
+       unsigned long res;
+       int ret;
+
+       ret = kstrtoul(buf, 10, &res);
+       if (ret < 0) {
+               wl1271_warning("incorrect value written to bt_coex_mode");
+               return count;
+       }
+
+       mutex_lock(&wl->mutex);
+
+       res = !!res;
+
+       if (res == wl->sg_enabled)
+               goto out;
+
+       wl->sg_enabled = res;
+
+       if (wl->state == WL1271_STATE_OFF)
+               goto out;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       wl1271_acx_sg_enable(wl, wl->sg_enabled);
+       wl1271_ps_elp_sleep(wl);
+
+ out:
+       mutex_unlock(&wl->mutex);
+       return count;
+}
+
+static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR,
+                  wl1271_sysfs_show_bt_coex_state,
+                  wl1271_sysfs_store_bt_coex_state);
+
+static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev,
+                                          struct device_attribute *attr,
+                                          char *buf)
+{
+       struct wl1271 *wl = dev_get_drvdata(dev);
+       ssize_t len;
+
+       len = PAGE_SIZE;
+
+       mutex_lock(&wl->mutex);
+       if (wl->hw_pg_ver >= 0)
+               len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
+       else
+               len = snprintf(buf, len, "n/a\n");
+       mutex_unlock(&wl->mutex);
+
+       return len;
+}
+
+static DEVICE_ATTR(hw_pg_ver, S_IRUGO,
+                  wl1271_sysfs_show_hw_pg_ver, NULL);
+
+static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj,
+                                      struct bin_attribute *bin_attr,
+                                      char *buffer, loff_t pos, size_t count)
+{
+       struct device *dev = container_of(kobj, struct device, kobj);
+       struct wl1271 *wl = dev_get_drvdata(dev);
+       ssize_t len;
+       int ret;
+
+       ret = mutex_lock_interruptible(&wl->mutex);
+       if (ret < 0)
+               return -ERESTARTSYS;
+
+       /* Let only one thread read the log at a time, blocking others */
+       while (wl->fwlog_size == 0) {
+               DEFINE_WAIT(wait);
+
+               prepare_to_wait_exclusive(&wl->fwlog_waitq,
+                                         &wait,
+                                         TASK_INTERRUPTIBLE);
+
+               if (wl->fwlog_size != 0) {
+                       finish_wait(&wl->fwlog_waitq, &wait);
+                       break;
+               }
+
+               mutex_unlock(&wl->mutex);
+
+               schedule();
+               finish_wait(&wl->fwlog_waitq, &wait);
+
+               if (signal_pending(current))
+                       return -ERESTARTSYS;
+
+               ret = mutex_lock_interruptible(&wl->mutex);
+               if (ret < 0)
+                       return -ERESTARTSYS;
+       }
+
+       /* Check if the fwlog is still valid */
+       if (wl->fwlog_size < 0) {
+               mutex_unlock(&wl->mutex);
+               return 0;
+       }
+
+       /* Seeking is not supported - old logs are not kept. Disregard pos. */
+       len = min(count, (size_t)wl->fwlog_size);
+       wl->fwlog_size -= len;
+       memcpy(buffer, wl->fwlog, len);
+
+       /* Make room for new messages */
+       memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size);
+
+       mutex_unlock(&wl->mutex);
+
+       return len;
+}
+
+static struct bin_attribute fwlog_attr = {
+       .attr = {.name = "fwlog", .mode = S_IRUSR},
+       .read = wl1271_sysfs_read_fwlog,
+};
+
+static void wl12xx_derive_mac_addresses(struct wl1271 *wl,
+                                       u32 oui, u32 nic, int n)
+{
+       int i;
+
+       wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x, n %d",
+                    oui, nic, n);
+
+       if (nic + n - 1 > 0xffffff)
+               wl1271_warning("NIC part of the MAC address wraps around!");
+
+       for (i = 0; i < n; i++) {
+               wl->addresses[i].addr[0] = (u8)(oui >> 16);
+               wl->addresses[i].addr[1] = (u8)(oui >> 8);
+               wl->addresses[i].addr[2] = (u8) oui;
+               wl->addresses[i].addr[3] = (u8)(nic >> 16);
+               wl->addresses[i].addr[4] = (u8)(nic >> 8);
+               wl->addresses[i].addr[5] = (u8) nic;
+               nic++;
+       }
+
+       wl->hw->wiphy->n_addresses = n;
+       wl->hw->wiphy->addresses = wl->addresses;
+}
+
+static int wl12xx_get_hw_info(struct wl1271 *wl)
+{
+       int ret;
+
+       ret = wl12xx_set_power_on(wl);
+       if (ret < 0)
+               goto out;
+
+       wl->chip.id = wlcore_read_reg(wl, REG_CHIP_ID_B);
+
+       wl->fuse_oui_addr = 0;
+       wl->fuse_nic_addr = 0;
+
+       wl->hw_pg_ver = wl->ops->get_pg_ver(wl);
+
+       if (wl->ops->get_mac)
+               wl->ops->get_mac(wl);
+
+       wl1271_power_off(wl);
+out:
+       return ret;
+}
+
+static int wl1271_register_hw(struct wl1271 *wl)
+{
+       int ret;
+       u32 oui_addr = 0, nic_addr = 0;
+
+       if (wl->mac80211_registered)
+               return 0;
+
+       ret = wl12xx_get_hw_info(wl);
+       if (ret < 0) {
+               wl1271_error("couldn't get hw info");
+               goto out;
+       }
+
+       ret = wl1271_fetch_nvs(wl);
+       if (ret == 0) {
+               /* NOTE: The wl->nvs->nvs element must be first, in
+                * order to simplify the casting, we assume it is at
+                * the beginning of the wl->nvs structure.
+                */
+               u8 *nvs_ptr = (u8 *)wl->nvs;
+
+               oui_addr =
+                       (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6];
+               nic_addr =
+                       (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3];
+       }
+
+       /* if the MAC address is zeroed in the NVS derive from fuse */
+       if (oui_addr == 0 && nic_addr == 0) {
+               oui_addr = wl->fuse_oui_addr;
+               /* fuse has the BD_ADDR, the WLAN addresses are the next two */
+               nic_addr = wl->fuse_nic_addr + 1;
+       }
+
+       wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr, 2);
+
+       ret = ieee80211_register_hw(wl->hw);
+       if (ret < 0) {
+               wl1271_error("unable to register mac80211 hw: %d", ret);
+               goto out;
+       }
+
+       wl->mac80211_registered = true;
+
+       wl1271_debugfs_init(wl);
+
+       wl1271_notice("loaded");
+
+out:
+       return ret;
+}
+
+static void wl1271_unregister_hw(struct wl1271 *wl)
+{
+       if (wl->plt)
+               wl1271_plt_stop(wl);
+
+       ieee80211_unregister_hw(wl->hw);
+       wl->mac80211_registered = false;
+
+}
+
+static int wl1271_init_ieee80211(struct wl1271 *wl)
+{
+       static const u32 cipher_suites[] = {
+               WLAN_CIPHER_SUITE_WEP40,
+               WLAN_CIPHER_SUITE_WEP104,
+               WLAN_CIPHER_SUITE_TKIP,
+               WLAN_CIPHER_SUITE_CCMP,
+               WL1271_CIPHER_SUITE_GEM,
+       };
+
+       /* The tx descriptor buffer and the TKIP space. */
+       wl->hw->extra_tx_headroom = WL1271_EXTRA_SPACE_TKIP +
+               sizeof(struct wl1271_tx_hw_descr);
+
+       /* unit us */
+       /* FIXME: find a proper value */
+       wl->hw->channel_change_time = 10000;
+       wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval;
+
+       wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
+               IEEE80211_HW_SUPPORTS_PS |
+               IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
+               IEEE80211_HW_SUPPORTS_UAPSD |
+               IEEE80211_HW_HAS_RATE_CONTROL |
+               IEEE80211_HW_CONNECTION_MONITOR |
+               IEEE80211_HW_REPORTS_TX_ACK_STATUS |
+               IEEE80211_HW_SPECTRUM_MGMT |
+               IEEE80211_HW_AP_LINK_PS |
+               IEEE80211_HW_AMPDU_AGGREGATION |
+               IEEE80211_HW_TX_AMPDU_SETUP_IN_HW |
+               IEEE80211_HW_SCAN_WHILE_IDLE;
+
+       wl->hw->wiphy->cipher_suites = cipher_suites;
+       wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
+
+       wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
+               BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) |
+               BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
+       wl->hw->wiphy->max_scan_ssids = 1;
+       wl->hw->wiphy->max_sched_scan_ssids = 16;
+       wl->hw->wiphy->max_match_sets = 16;
+       /*
+        * Maximum length of elements in scanning probe request templates
+        * should be the maximum length possible for a template, without
+        * the IEEE80211 header of the template
+        */
+       wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
+                       sizeof(struct ieee80211_header);
+
+       wl->hw->wiphy->max_sched_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
+               sizeof(struct ieee80211_header);
+
+       wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD |
+                               WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
+
+       /* make sure all our channels fit in the scanned_ch bitmask */
+       BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) +
+                    ARRAY_SIZE(wl1271_channels_5ghz) >
+                    WL1271_MAX_CHANNELS);
+       /*
+        * We keep local copies of the band structs because we need to
+        * modify them on a per-device basis.
+        */
+       memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
+              sizeof(wl1271_band_2ghz));
+       memcpy(&wl->bands[IEEE80211_BAND_2GHZ].ht_cap, &wl->ht_cap,
+              sizeof(wl->ht_cap));
+       memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
+              sizeof(wl1271_band_5ghz));
+       memcpy(&wl->bands[IEEE80211_BAND_5GHZ].ht_cap, &wl->ht_cap,
+              sizeof(wl->ht_cap));
+
+       wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
+               &wl->bands[IEEE80211_BAND_2GHZ];
+       wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
+               &wl->bands[IEEE80211_BAND_5GHZ];
+
+       wl->hw->queues = 4;
+       wl->hw->max_rates = 1;
+
+       wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
+
+       /* the FW answers probe-requests in AP-mode */
+       wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
+       wl->hw->wiphy->probe_resp_offload =
+               NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
+               NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
+               NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
+
+       SET_IEEE80211_DEV(wl->hw, wl->dev);
+
+       wl->hw->sta_data_size = sizeof(struct wl1271_station);
+       wl->hw->vif_data_size = sizeof(struct wl12xx_vif);
+
+       wl->hw->max_rx_aggregation_subframes = wl->conf.ht.rx_ba_win_size;
+
+       return 0;
+}
+
+#define WL1271_DEFAULT_CHANNEL 0
+
+struct ieee80211_hw *wlcore_alloc_hw(size_t priv_size)
+{
+       struct ieee80211_hw *hw;
+       struct wl1271 *wl;
+       int i, j, ret;
+       unsigned int order;
+
+       BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS);
+
+       hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
+       if (!hw) {
+               wl1271_error("could not alloc ieee80211_hw");
+               ret = -ENOMEM;
+               goto err_hw_alloc;
+       }
+
+       wl = hw->priv;
+       memset(wl, 0, sizeof(*wl));
+
+       wl->priv = kzalloc(priv_size, GFP_KERNEL);
+       if (!wl->priv) {
+               wl1271_error("could not alloc wl priv");
+               ret = -ENOMEM;
+               goto err_priv_alloc;
+       }
+
+       INIT_LIST_HEAD(&wl->wlvif_list);
+
+       wl->hw = hw;
+
+       for (i = 0; i < NUM_TX_QUEUES; i++)
+               for (j = 0; j < WL12XX_MAX_LINKS; j++)
+                       skb_queue_head_init(&wl->links[j].tx_queue[i]);
+
+       skb_queue_head_init(&wl->deferred_rx_queue);
+       skb_queue_head_init(&wl->deferred_tx_queue);
+
+       INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
+       INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
+       INIT_WORK(&wl->tx_work, wl1271_tx_work);
+       INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
+       INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
+       INIT_DELAYED_WORK(&wl->tx_watchdog_work, wl12xx_tx_watchdog_work);
+
+       wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
+       if (!wl->freezable_wq) {
+               ret = -ENOMEM;
+               goto err_hw;
+       }
+
+       wl->channel = WL1271_DEFAULT_CHANNEL;
+       wl->rx_counter = 0;
+       wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
+       wl->band = IEEE80211_BAND_2GHZ;
+       wl->flags = 0;
+       wl->sg_enabled = true;
+       wl->hw_pg_ver = -1;
+       wl->ap_ps_map = 0;
+       wl->ap_fw_ps_map = 0;
+       wl->quirks = 0;
+       wl->platform_quirks = 0;
+       wl->sched_scanning = false;
+       wl->system_hlid = WL12XX_SYSTEM_HLID;
+       wl->active_sta_count = 0;
+       wl->fwlog_size = 0;
+       init_waitqueue_head(&wl->fwlog_waitq);
+
+       /* The system link is always allocated */
+       __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
+
+       memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
+       for (i = 0; i < wl->num_tx_desc; i++)
+               wl->tx_frames[i] = NULL;
+
+       spin_lock_init(&wl->wl_lock);
+
+       wl->state = WL1271_STATE_OFF;
+       wl->fw_type = WL12XX_FW_TYPE_NONE;
+       mutex_init(&wl->mutex);
+
+       order = get_order(WL1271_AGGR_BUFFER_SIZE);
+       wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
+       if (!wl->aggr_buf) {
+               ret = -ENOMEM;
+               goto err_wq;
+       }
+
+       wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
+       if (!wl->dummy_packet) {
+               ret = -ENOMEM;
+               goto err_aggr;
+       }
+
+       /* Allocate one page for the FW log */
+       wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL);
+       if (!wl->fwlog) {
+               ret = -ENOMEM;
+               goto err_dummy_packet;
+       }
+
+       wl->mbox = kmalloc(sizeof(*wl->mbox), GFP_DMA);
+       if (!wl->mbox) {
+               ret = -ENOMEM;
+               goto err_fwlog;
+       }
+
+       return hw;
+
+err_fwlog:
+       free_page((unsigned long)wl->fwlog);
+
+err_dummy_packet:
+       dev_kfree_skb(wl->dummy_packet);
+
+err_aggr:
+       free_pages((unsigned long)wl->aggr_buf, order);
+
+err_wq:
+       destroy_workqueue(wl->freezable_wq);
+
+err_hw:
+       wl1271_debugfs_exit(wl);
+       kfree(wl->priv);
+
+err_priv_alloc:
+       ieee80211_free_hw(hw);
+
+err_hw_alloc:
+
+       return ERR_PTR(ret);
+}
+EXPORT_SYMBOL_GPL(wlcore_alloc_hw);
+
+int wlcore_free_hw(struct wl1271 *wl)
+{
+       /* Unblock any fwlog readers */
+       mutex_lock(&wl->mutex);
+       wl->fwlog_size = -1;
+       wake_up_interruptible_all(&wl->fwlog_waitq);
+       mutex_unlock(&wl->mutex);
+
+       device_remove_bin_file(wl->dev, &fwlog_attr);
+
+       device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
+
+       device_remove_file(wl->dev, &dev_attr_bt_coex_state);
+       free_page((unsigned long)wl->fwlog);
+       dev_kfree_skb(wl->dummy_packet);
+       free_pages((unsigned long)wl->aggr_buf,
+                       get_order(WL1271_AGGR_BUFFER_SIZE));
+
+       wl1271_debugfs_exit(wl);
+
+       vfree(wl->fw);
+       wl->fw = NULL;
+       wl->fw_type = WL12XX_FW_TYPE_NONE;
+       kfree(wl->nvs);
+       wl->nvs = NULL;
+
+       kfree(wl->fw_status);
+       kfree(wl->tx_res_if);
+       destroy_workqueue(wl->freezable_wq);
+
+       kfree(wl->priv);
+       ieee80211_free_hw(wl->hw);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wlcore_free_hw);
+
+static irqreturn_t wl12xx_hardirq(int irq, void *cookie)
+{
+       struct wl1271 *wl = cookie;
+       unsigned long flags;
+
+       wl1271_debug(DEBUG_IRQ, "IRQ");
+
+       /* complete the ELP completion */
+       spin_lock_irqsave(&wl->wl_lock, flags);
+       set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
+       if (wl->elp_compl) {
+               complete(wl->elp_compl);
+               wl->elp_compl = NULL;
+       }
+
+       if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
+               /* don't enqueue a work right now. mark it as pending */
+               set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
+               wl1271_debug(DEBUG_IRQ, "should not enqueue work");
+               disable_irq_nosync(wl->irq);
+               pm_wakeup_event(wl->dev, 0);
+               spin_unlock_irqrestore(&wl->wl_lock, flags);
+               return IRQ_HANDLED;
+       }
+       spin_unlock_irqrestore(&wl->wl_lock, flags);
+
+       return IRQ_WAKE_THREAD;
+}
+
+int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev)
+{
+       struct wl12xx_platform_data *pdata = pdev->dev.platform_data;
+       unsigned long irqflags;
+       int ret;
+
+       if (!wl->ops || !wl->ptable) {
+               ret = -EINVAL;
+               goto out_free_hw;
+       }
+
+       BUG_ON(wl->num_tx_desc > WLCORE_MAX_TX_DESCRIPTORS);
+
+       /* adjust some runtime configuration parameters */
+       wlcore_adjust_conf(wl);
+
+       wl->irq = platform_get_irq(pdev, 0);
+       wl->ref_clock = pdata->board_ref_clock;
+       wl->tcxo_clock = pdata->board_tcxo_clock;
+       wl->platform_quirks = pdata->platform_quirks;
+       wl->set_power = pdata->set_power;
+       wl->dev = &pdev->dev;
+       wl->if_ops = pdata->ops;
+
+       platform_set_drvdata(pdev, wl);
+
+       if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
+               irqflags = IRQF_TRIGGER_RISING;
+       else
+               irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
+
+       ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq,
+                                  irqflags,
+                                  pdev->name, wl);
+       if (ret < 0) {
+               wl1271_error("request_irq() failed: %d", ret);
+               goto out_free_hw;
+       }
+
+       ret = enable_irq_wake(wl->irq);
+       if (!ret) {
+               wl->irq_wake_enabled = true;
+               device_init_wakeup(wl->dev, 1);
+               if (pdata->pwr_in_suspend)
+                       wl->hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
+
+       }
+       disable_irq(wl->irq);
+
+       ret = wl1271_init_ieee80211(wl);
+       if (ret)
+               goto out_irq;
+
+       ret = wl1271_register_hw(wl);
+       if (ret)
+               goto out_irq;
+
+       /* Create sysfs file to control bt coex state */
+       ret = device_create_file(wl->dev, &dev_attr_bt_coex_state);
+       if (ret < 0) {
+               wl1271_error("failed to create sysfs file bt_coex_state");
+               goto out_irq;
+       }
+
+       /* Create sysfs file to get HW PG version */
+       ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver);
+       if (ret < 0) {
+               wl1271_error("failed to create sysfs file hw_pg_ver");
+               goto out_bt_coex_state;
+       }
+
+       /* Create sysfs file for the FW log */
+       ret = device_create_bin_file(wl->dev, &fwlog_attr);
+       if (ret < 0) {
+               wl1271_error("failed to create sysfs file fwlog");
+               goto out_hw_pg_ver;
+       }
+
+       goto out;
+
+out_hw_pg_ver:
+       device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
+
+out_bt_coex_state:
+       device_remove_file(wl->dev, &dev_attr_bt_coex_state);
+
+out_irq:
+       free_irq(wl->irq, wl);
+
+out_free_hw:
+       wlcore_free_hw(wl);
+
+out:
+       return ret;
+}
+EXPORT_SYMBOL_GPL(wlcore_probe);
+
+int __devexit wlcore_remove(struct platform_device *pdev)
+{
+       struct wl1271 *wl = platform_get_drvdata(pdev);
+
+       if (wl->irq_wake_enabled) {
+               device_init_wakeup(wl->dev, 0);
+               disable_irq_wake(wl->irq);
+       }
+       wl1271_unregister_hw(wl);
+       free_irq(wl->irq, wl);
+       wlcore_free_hw(wl);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wlcore_remove);
+
+u32 wl12xx_debug_level = DEBUG_NONE;
+EXPORT_SYMBOL_GPL(wl12xx_debug_level);
+module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
+MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
+
+module_param_named(fwlog, fwlog_param, charp, 0);
+MODULE_PARM_DESC(fwlog,
+                "FW logger options: continuous, ondemand, dbgpins or disable");
+
+module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR);
+MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery");
+
+module_param(no_recovery, bool, S_IRUSR | S_IWUSR);
+MODULE_PARM_DESC(no_recovery, "Prevent HW recovery. FW will remain stuck.");
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
+MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
diff --git a/drivers/net/wireless/ti/wlcore/ps.c b/drivers/net/wireless/ti/wlcore/ps.c
new file mode 100644 (file)
index 0000000..756eee2
--- /dev/null
@@ -0,0 +1,306 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "ps.h"
+#include "io.h"
+#include "tx.h"
+#include "debug.h"
+
+#define WL1271_WAKEUP_TIMEOUT 500
+
+void wl1271_elp_work(struct work_struct *work)
+{
+       struct delayed_work *dwork;
+       struct wl1271 *wl;
+       struct wl12xx_vif *wlvif;
+
+       dwork = container_of(work, struct delayed_work, work);
+       wl = container_of(dwork, struct wl1271, elp_work);
+
+       wl1271_debug(DEBUG_PSM, "elp work");
+
+       mutex_lock(&wl->mutex);
+
+       if (unlikely(wl->state == WL1271_STATE_OFF))
+               goto out;
+
+       /* our work might have been already cancelled */
+       if (unlikely(!test_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags)))
+               goto out;
+
+       if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags))
+               goto out;
+
+       wl12xx_for_each_wlvif(wl, wlvif) {
+               if (wlvif->bss_type == BSS_TYPE_AP_BSS)
+                       goto out;
+
+               if (!test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags) &&
+                   test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags))
+                       goto out;
+       }
+
+       wl1271_debug(DEBUG_PSM, "chip to elp");
+       wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG, ELPCTRL_SLEEP);
+       set_bit(WL1271_FLAG_IN_ELP, &wl->flags);
+
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+/* Routines to toggle sleep mode while in ELP */
+void wl1271_ps_elp_sleep(struct wl1271 *wl)
+{
+       struct wl12xx_vif *wlvif;
+
+       if (wl->quirks & WLCORE_QUIRK_NO_ELP)
+               return;
+
+       /* we shouldn't get consecutive sleep requests */
+       if (WARN_ON(test_and_set_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags)))
+               return;
+
+       wl12xx_for_each_wlvif(wl, wlvif) {
+               if (wlvif->bss_type == BSS_TYPE_AP_BSS)
+                       return;
+
+               if (!test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags) &&
+                   test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags))
+                       return;
+       }
+
+       ieee80211_queue_delayed_work(wl->hw, &wl->elp_work,
+               msecs_to_jiffies(wl->conf.conn.dynamic_ps_timeout));
+}
+
+int wl1271_ps_elp_wakeup(struct wl1271 *wl)
+{
+       DECLARE_COMPLETION_ONSTACK(compl);
+       unsigned long flags;
+       int ret;
+       u32 start_time = jiffies;
+       bool pending = false;
+
+       /*
+        * we might try to wake up even if we didn't go to sleep
+        * before (e.g. on boot)
+        */
+       if (!test_and_clear_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags))
+               return 0;
+
+       /* don't cancel_sync as it might contend for a mutex and deadlock */
+       cancel_delayed_work(&wl->elp_work);
+
+       if (!test_bit(WL1271_FLAG_IN_ELP, &wl->flags))
+               return 0;
+
+       wl1271_debug(DEBUG_PSM, "waking up chip from elp");
+
+       /*
+        * The spinlock is required here to synchronize both the work and
+        * the completion variable in one entity.
+        */
+       spin_lock_irqsave(&wl->wl_lock, flags);
+       if (test_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags))
+               pending = true;
+       else
+               wl->elp_compl = &compl;
+       spin_unlock_irqrestore(&wl->wl_lock, flags);
+
+       wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG, ELPCTRL_WAKE_UP);
+
+       if (!pending) {
+               ret = wait_for_completion_timeout(
+                       &compl, msecs_to_jiffies(WL1271_WAKEUP_TIMEOUT));
+               if (ret == 0) {
+                       wl1271_error("ELP wakeup timeout!");
+                       wl12xx_queue_recovery_work(wl);
+                       ret = -ETIMEDOUT;
+                       goto err;
+               } else if (ret < 0) {
+                       wl1271_error("ELP wakeup completion error.");
+                       goto err;
+               }
+       }
+
+       clear_bit(WL1271_FLAG_IN_ELP, &wl->flags);
+
+       wl1271_debug(DEBUG_PSM, "wakeup time: %u ms",
+                    jiffies_to_msecs(jiffies - start_time));
+       goto out;
+
+err:
+       spin_lock_irqsave(&wl->wl_lock, flags);
+       wl->elp_compl = NULL;
+       spin_unlock_irqrestore(&wl->wl_lock, flags);
+       return ret;
+
+out:
+       return 0;
+}
+
+int wl1271_ps_set_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                      enum wl1271_cmd_ps_mode mode)
+{
+       int ret;
+       u16 timeout = wl->conf.conn.dynamic_ps_timeout;
+
+       switch (mode) {
+       case STATION_AUTO_PS_MODE:
+       case STATION_POWER_SAVE_MODE:
+               wl1271_debug(DEBUG_PSM, "entering psm (mode=%d,timeout=%u)",
+                            mode, timeout);
+
+               ret = wl1271_acx_wake_up_conditions(wl, wlvif,
+                                           wl->conf.conn.wake_up_event,
+                                           wl->conf.conn.listen_interval);
+               if (ret < 0) {
+                       wl1271_error("couldn't set wake up conditions");
+                       return ret;
+               }
+
+               ret = wl1271_cmd_ps_mode(wl, wlvif, mode, timeout);
+               if (ret < 0)
+                       return ret;
+
+               set_bit(WLVIF_FLAG_IN_PS, &wlvif->flags);
+
+               /* enable beacon early termination. Not relevant for 5GHz */
+               if (wlvif->band == IEEE80211_BAND_2GHZ) {
+                       ret = wl1271_acx_bet_enable(wl, wlvif, true);
+                       if (ret < 0)
+                               return ret;
+               }
+               break;
+       case STATION_ACTIVE_MODE:
+               wl1271_debug(DEBUG_PSM, "leaving psm");
+
+               /* disable beacon early termination */
+               if (wlvif->band == IEEE80211_BAND_2GHZ) {
+                       ret = wl1271_acx_bet_enable(wl, wlvif, false);
+                       if (ret < 0)
+                               return ret;
+               }
+
+               ret = wl1271_cmd_ps_mode(wl, wlvif, mode, 0);
+               if (ret < 0)
+                       return ret;
+
+               clear_bit(WLVIF_FLAG_IN_PS, &wlvif->flags);
+               break;
+       default:
+               wl1271_warning("trying to set ps to unsupported mode %d", mode);
+               ret = -EINVAL;
+       }
+
+       return ret;
+}
+
+static void wl1271_ps_filter_frames(struct wl1271 *wl, u8 hlid)
+{
+       int i;
+       struct sk_buff *skb;
+       struct ieee80211_tx_info *info;
+       unsigned long flags;
+       int filtered[NUM_TX_QUEUES];
+
+       /* filter all frames currently in the low level queues for this hlid */
+       for (i = 0; i < NUM_TX_QUEUES; i++) {
+               filtered[i] = 0;
+               while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) {
+                       filtered[i]++;
+
+                       if (WARN_ON(wl12xx_is_dummy_packet(wl, skb)))
+                               continue;
+
+                       info = IEEE80211_SKB_CB(skb);
+                       info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
+                       info->status.rates[0].idx = -1;
+                       ieee80211_tx_status_ni(wl->hw, skb);
+               }
+       }
+
+       spin_lock_irqsave(&wl->wl_lock, flags);
+       for (i = 0; i < NUM_TX_QUEUES; i++)
+               wl->tx_queue_count[i] -= filtered[i];
+       spin_unlock_irqrestore(&wl->wl_lock, flags);
+
+       wl1271_handle_tx_low_watermark(wl);
+}
+
+void wl12xx_ps_link_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                         u8 hlid, bool clean_queues)
+{
+       struct ieee80211_sta *sta;
+       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+
+       if (test_bit(hlid, &wl->ap_ps_map))
+               return;
+
+       wl1271_debug(DEBUG_PSM, "start mac80211 PSM on hlid %d pkts %d "
+                    "clean_queues %d", hlid, wl->links[hlid].allocated_pkts,
+                    clean_queues);
+
+       rcu_read_lock();
+       sta = ieee80211_find_sta(vif, wl->links[hlid].addr);
+       if (!sta) {
+               wl1271_error("could not find sta %pM for starting ps",
+                            wl->links[hlid].addr);
+               rcu_read_unlock();
+               return;
+       }
+
+       ieee80211_sta_ps_transition_ni(sta, true);
+       rcu_read_unlock();
+
+       /* do we want to filter all frames from this link's queues? */
+       if (clean_queues)
+               wl1271_ps_filter_frames(wl, hlid);
+
+       __set_bit(hlid, &wl->ap_ps_map);
+}
+
+void wl12xx_ps_link_end(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
+{
+       struct ieee80211_sta *sta;
+       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
+
+       if (!test_bit(hlid, &wl->ap_ps_map))
+               return;
+
+       wl1271_debug(DEBUG_PSM, "end mac80211 PSM on hlid %d", hlid);
+
+       __clear_bit(hlid, &wl->ap_ps_map);
+
+       rcu_read_lock();
+       sta = ieee80211_find_sta(vif, wl->links[hlid].addr);
+       if (!sta) {
+               wl1271_error("could not find sta %pM for ending ps",
+                            wl->links[hlid].addr);
+               goto end;
+       }
+
+       ieee80211_sta_ps_transition_ni(sta, false);
+end:
+       rcu_read_unlock();
+}
diff --git a/drivers/net/wireless/ti/wlcore/ps.h b/drivers/net/wireless/ti/wlcore/ps.h
new file mode 100644 (file)
index 0000000..de4f9da
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __PS_H__
+#define __PS_H__
+
+#include "wlcore.h"
+#include "acx.h"
+
+int wl1271_ps_set_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                      enum wl1271_cmd_ps_mode mode);
+void wl1271_ps_elp_sleep(struct wl1271 *wl);
+int wl1271_ps_elp_wakeup(struct wl1271 *wl);
+void wl1271_elp_work(struct work_struct *work);
+void wl12xx_ps_link_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                         u8 hlid, bool clean_queues);
+void wl12xx_ps_link_end(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid);
+
+#define WL1271_PS_COMPLETE_TIMEOUT 500
+
+#endif /* __WL1271_PS_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/rx.c b/drivers/net/wireless/ti/wlcore/rx.c
new file mode 100644 (file)
index 0000000..89bd938
--- /dev/null
@@ -0,0 +1,280 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/gfp.h>
+#include <linux/sched.h>
+
+#include "wlcore.h"
+#include "debug.h"
+#include "acx.h"
+#include "rx.h"
+#include "tx.h"
+#include "io.h"
+#include "hw_ops.h"
+
+/*
+ * TODO: this is here just for now, it must be removed when the data
+ * operations are in place.
+ */
+#include "../wl12xx/reg.h"
+
+static u32 wlcore_rx_get_buf_size(struct wl1271 *wl,
+                                 u32 rx_pkt_desc)
+{
+       if (wl->quirks & WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN)
+               return (rx_pkt_desc & ALIGNED_RX_BUF_SIZE_MASK) >>
+                      ALIGNED_RX_BUF_SIZE_SHIFT;
+
+       return (rx_pkt_desc & RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV;
+}
+
+static u32 wlcore_rx_get_align_buf_size(struct wl1271 *wl, u32 pkt_len)
+{
+       if (wl->quirks & WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN)
+               return ALIGN(pkt_len, WL12XX_BUS_BLOCK_SIZE);
+
+       return pkt_len;
+}
+
+static void wl1271_rx_status(struct wl1271 *wl,
+                            struct wl1271_rx_descriptor *desc,
+                            struct ieee80211_rx_status *status,
+                            u8 beacon)
+{
+       memset(status, 0, sizeof(struct ieee80211_rx_status));
+
+       if ((desc->flags & WL1271_RX_DESC_BAND_MASK) == WL1271_RX_DESC_BAND_BG)
+               status->band = IEEE80211_BAND_2GHZ;
+       else
+               status->band = IEEE80211_BAND_5GHZ;
+
+       status->rate_idx = wlcore_rate_to_idx(wl, desc->rate, status->band);
+
+       /* 11n support */
+       if (desc->rate <= wl->hw_min_ht_rate)
+               status->flag |= RX_FLAG_HT;
+
+       status->signal = desc->rssi;
+
+       /*
+        * FIXME: In wl1251, the SNR should be divided by two.  In wl1271 we
+        * need to divide by two for now, but TI has been discussing about
+        * changing it.  This needs to be rechecked.
+        */
+       wl->noise = desc->rssi - (desc->snr >> 1);
+
+       status->freq = ieee80211_channel_to_frequency(desc->channel,
+                                                     status->band);
+
+       if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) {
+               u8 desc_err_code = desc->status & WL1271_RX_DESC_STATUS_MASK;
+
+               status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED |
+                               RX_FLAG_DECRYPTED;
+
+               if (unlikely(desc_err_code == WL1271_RX_DESC_MIC_FAIL)) {
+                       status->flag |= RX_FLAG_MMIC_ERROR;
+                       wl1271_warning("Michael MIC error");
+               }
+       }
+}
+
+static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length,
+                                enum wl_rx_buf_align rx_align, u8 *hlid)
+{
+       struct wl1271_rx_descriptor *desc;
+       struct sk_buff *skb;
+       struct ieee80211_hdr *hdr;
+       u8 *buf;
+       u8 beacon = 0;
+       u8 is_data = 0;
+       u8 reserved = 0;
+       u16 seq_num;
+       u32 pkt_data_len;
+
+       /*
+        * In PLT mode we seem to get frames and mac80211 warns about them,
+        * workaround this by not retrieving them at all.
+        */
+       if (unlikely(wl->plt))
+               return -EINVAL;
+
+       pkt_data_len = wlcore_hw_get_rx_packet_len(wl, data, length);
+       if (!pkt_data_len) {
+               wl1271_error("Invalid packet arrived from HW. length %d",
+                            length);
+               return -EINVAL;
+       }
+
+       if (rx_align == WLCORE_RX_BUF_UNALIGNED)
+               reserved = NET_IP_ALIGN;
+
+       /* the data read starts with the descriptor */
+       desc = (struct wl1271_rx_descriptor *) data;
+
+       if (desc->packet_class == WL12XX_RX_CLASS_LOGGER) {
+               size_t len = length - sizeof(*desc);
+               wl12xx_copy_fwlog(wl, data + sizeof(*desc), len);
+               wake_up_interruptible(&wl->fwlog_waitq);
+               return 0;
+       }
+
+       switch (desc->status & WL1271_RX_DESC_STATUS_MASK) {
+       /* discard corrupted packets */
+       case WL1271_RX_DESC_DRIVER_RX_Q_FAIL:
+       case WL1271_RX_DESC_DECRYPT_FAIL:
+               wl1271_warning("corrupted packet in RX with status: 0x%x",
+                              desc->status & WL1271_RX_DESC_STATUS_MASK);
+               return -EINVAL;
+       case WL1271_RX_DESC_SUCCESS:
+       case WL1271_RX_DESC_MIC_FAIL:
+               break;
+       default:
+               wl1271_error("invalid RX descriptor status: 0x%x",
+                            desc->status & WL1271_RX_DESC_STATUS_MASK);
+               return -EINVAL;
+       }
+
+       /* skb length not including rx descriptor */
+       skb = __dev_alloc_skb(pkt_data_len + reserved, GFP_KERNEL);
+       if (!skb) {
+               wl1271_error("Couldn't allocate RX frame");
+               return -ENOMEM;
+       }
+
+       /* reserve the unaligned payload(if any) */
+       skb_reserve(skb, reserved);
+
+       buf = skb_put(skb, pkt_data_len);
+
+       /*
+        * Copy packets from aggregation buffer to the skbs without rx
+        * descriptor and with packet payload aligned care. In case of unaligned
+        * packets copy the packets in offset of 2 bytes guarantee IP header
+        * payload aligned to 4 bytes.
+        */
+       memcpy(buf, data + sizeof(*desc), pkt_data_len);
+       if (rx_align == WLCORE_RX_BUF_PADDED)
+               skb_pull(skb, NET_IP_ALIGN);
+
+       *hlid = desc->hlid;
+
+       hdr = (struct ieee80211_hdr *)skb->data;
+       if (ieee80211_is_beacon(hdr->frame_control))
+               beacon = 1;
+       if (ieee80211_is_data_present(hdr->frame_control))
+               is_data = 1;
+
+       wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon);
+
+       seq_num = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
+       wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s seq %d hlid %d", skb,
+                    skb->len - desc->pad_len,
+                    beacon ? "beacon" : "",
+                    seq_num, *hlid);
+
+       skb_queue_tail(&wl->deferred_rx_queue, skb);
+       queue_work(wl->freezable_wq, &wl->netstack_work);
+
+       return is_data;
+}
+
+void wl12xx_rx(struct wl1271 *wl, struct wl_fw_status *status)
+{
+       unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0};
+       u32 buf_size;
+       u32 fw_rx_counter  = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
+       u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
+       u32 rx_counter;
+       u32 pkt_len, align_pkt_len;
+       u32 pkt_offset, des;
+       u8 hlid;
+       enum wl_rx_buf_align rx_align;
+
+       while (drv_rx_counter != fw_rx_counter) {
+               buf_size = 0;
+               rx_counter = drv_rx_counter;
+               while (rx_counter != fw_rx_counter) {
+                       des = le32_to_cpu(status->rx_pkt_descs[rx_counter]);
+                       pkt_len = wlcore_rx_get_buf_size(wl, des);
+                       align_pkt_len = wlcore_rx_get_align_buf_size(wl,
+                                                                    pkt_len);
+                       if (buf_size + align_pkt_len > WL1271_AGGR_BUFFER_SIZE)
+                               break;
+                       buf_size += align_pkt_len;
+                       rx_counter++;
+                       rx_counter &= NUM_RX_PKT_DESC_MOD_MASK;
+               }
+
+               if (buf_size == 0) {
+                       wl1271_warning("received empty data");
+                       break;
+               }
+
+               /* Read all available packets at once */
+               des = le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]);
+               wlcore_hw_prepare_read(wl, des, buf_size);
+               wlcore_read_data(wl, REG_SLV_MEM_DATA, wl->aggr_buf,
+                                buf_size, true);
+
+               /* Split data into separate packets */
+               pkt_offset = 0;
+               while (pkt_offset < buf_size) {
+                       des = le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]);
+                       pkt_len = wlcore_rx_get_buf_size(wl, des);
+                       rx_align = wlcore_hw_get_rx_buf_align(wl, des);
+
+                       /*
+                        * the handle data call can only fail in memory-outage
+                        * conditions, in that case the received frame will just
+                        * be dropped.
+                        */
+                       if (wl1271_rx_handle_data(wl,
+                                                 wl->aggr_buf + pkt_offset,
+                                                 pkt_len, rx_align,
+                                                 &hlid) == 1) {
+                               if (hlid < WL12XX_MAX_LINKS)
+                                       __set_bit(hlid, active_hlids);
+                               else
+                                       WARN(1,
+                                            "hlid exceeded WL12XX_MAX_LINKS "
+                                            "(%d)\n", hlid);
+                       }
+
+                       wl->rx_counter++;
+                       drv_rx_counter++;
+                       drv_rx_counter &= NUM_RX_PKT_DESC_MOD_MASK;
+                       pkt_offset += wlcore_rx_get_align_buf_size(wl, pkt_len);
+               }
+       }
+
+       /*
+        * Write the driver's packet counter to the FW. This is only required
+        * for older hardware revisions
+        */
+       if (wl->quirks & WLCORE_QUIRK_END_OF_TRANSACTION)
+               wl1271_write32(wl, WL12XX_REG_RX_DRIVER_COUNTER,
+                              wl->rx_counter);
+
+       wl12xx_rearm_rx_streaming(wl, active_hlids);
+}
diff --git a/drivers/net/wireless/ti/wlcore/rx.h b/drivers/net/wireless/ti/wlcore/rx.h
new file mode 100644 (file)
index 0000000..6e129e2
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __RX_H__
+#define __RX_H__
+
+#include <linux/bitops.h>
+
+#define WL1271_RX_MAX_RSSI -30
+#define WL1271_RX_MIN_RSSI -95
+
+#define SHORT_PREAMBLE_BIT   BIT(0)
+#define OFDM_RATE_BIT        BIT(6)
+#define PBCC_RATE_BIT        BIT(7)
+
+#define PLCP_HEADER_LENGTH 8
+#define RX_DESC_PACKETID_SHIFT 11
+#define RX_MAX_PACKET_ID 3
+
+#define NUM_RX_PKT_DESC_MOD_MASK   7
+
+#define RX_DESC_VALID_FCS         0x0001
+#define RX_DESC_MATCH_RXADDR1     0x0002
+#define RX_DESC_MCAST             0x0004
+#define RX_DESC_STAINTIM          0x0008
+#define RX_DESC_VIRTUAL_BM        0x0010
+#define RX_DESC_BCAST             0x0020
+#define RX_DESC_MATCH_SSID        0x0040
+#define RX_DESC_MATCH_BSSID       0x0080
+#define RX_DESC_ENCRYPTION_MASK   0x0300
+#define RX_DESC_MEASURMENT        0x0400
+#define RX_DESC_SEQNUM_MASK       0x1800
+#define        RX_DESC_MIC_FAIL          0x2000
+#define        RX_DESC_DECRYPT_FAIL      0x4000
+
+/*
+ * RX Descriptor flags:
+ *
+ * Bits 0-1 - band
+ * Bit  2   - STBC
+ * Bit  3   - A-MPDU
+ * Bit  4   - HT
+ * Bits 5-7 - encryption
+ */
+#define WL1271_RX_DESC_BAND_MASK    0x03
+#define WL1271_RX_DESC_ENCRYPT_MASK 0xE0
+
+#define WL1271_RX_DESC_BAND_BG      0x00
+#define WL1271_RX_DESC_BAND_J       0x01
+#define WL1271_RX_DESC_BAND_A       0x02
+
+#define WL1271_RX_DESC_STBC         BIT(2)
+#define WL1271_RX_DESC_A_MPDU       BIT(3)
+#define WL1271_RX_DESC_HT           BIT(4)
+
+#define WL1271_RX_DESC_ENCRYPT_WEP  0x20
+#define WL1271_RX_DESC_ENCRYPT_TKIP 0x40
+#define WL1271_RX_DESC_ENCRYPT_AES  0x60
+#define WL1271_RX_DESC_ENCRYPT_GEM  0x80
+
+/*
+ * RX Descriptor status
+ *
+ * Bits 0-2 - error code
+ * Bits 3-5 - process_id tag (AP mode FW)
+ * Bits 6-7 - reserved
+ */
+#define WL1271_RX_DESC_STATUS_MASK      0x03
+
+#define WL1271_RX_DESC_SUCCESS          0x00
+#define WL1271_RX_DESC_DECRYPT_FAIL     0x01
+#define WL1271_RX_DESC_MIC_FAIL         0x02
+#define WL1271_RX_DESC_DRIVER_RX_Q_FAIL 0x03
+
+#define RX_MEM_BLOCK_MASK            0xFF
+#define RX_BUF_SIZE_MASK             0xFFF00
+#define RX_BUF_SIZE_SHIFT_DIV        6
+#define ALIGNED_RX_BUF_SIZE_MASK     0xFFFF00
+#define ALIGNED_RX_BUF_SIZE_SHIFT    8
+
+/* If set, the start of IP payload is not 4 bytes aligned */
+#define RX_BUF_UNALIGNED_PAYLOAD     BIT(20)
+
+/* Describes the alignment state of a Rx buffer */
+enum wl_rx_buf_align {
+       WLCORE_RX_BUF_ALIGNED,
+       WLCORE_RX_BUF_UNALIGNED,
+       WLCORE_RX_BUF_PADDED,
+};
+
+enum {
+       WL12XX_RX_CLASS_UNKNOWN,
+       WL12XX_RX_CLASS_MANAGEMENT,
+       WL12XX_RX_CLASS_DATA,
+       WL12XX_RX_CLASS_QOS_DATA,
+       WL12XX_RX_CLASS_BCN_PRBRSP,
+       WL12XX_RX_CLASS_EAPOL,
+       WL12XX_RX_CLASS_BA_EVENT,
+       WL12XX_RX_CLASS_AMSDU,
+       WL12XX_RX_CLASS_LOGGER,
+};
+
+struct wl1271_rx_descriptor {
+       __le16 length;
+       u8  status;
+       u8  flags;
+       u8  rate;
+       u8  channel;
+       s8  rssi;
+       u8  snr;
+       __le32 timestamp;
+       u8  packet_class;
+       u8  hlid;
+       u8  pad_len;
+       u8  reserved;
+} __packed;
+
+void wl12xx_rx(struct wl1271 *wl, struct wl_fw_status *status);
+u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band);
+
+#endif
diff --git a/drivers/net/wireless/ti/wlcore/scan.c b/drivers/net/wireless/ti/wlcore/scan.c
new file mode 100644 (file)
index 0000000..ade21a0
--- /dev/null
@@ -0,0 +1,790 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2009-2010 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/ieee80211.h>
+
+#include "wlcore.h"
+#include "debug.h"
+#include "cmd.h"
+#include "scan.h"
+#include "acx.h"
+#include "ps.h"
+#include "tx.h"
+
+void wl1271_scan_complete_work(struct work_struct *work)
+{
+       struct delayed_work *dwork;
+       struct wl1271 *wl;
+       struct ieee80211_vif *vif;
+       struct wl12xx_vif *wlvif;
+       int ret;
+
+       dwork = container_of(work, struct delayed_work, work);
+       wl = container_of(dwork, struct wl1271, scan_complete_work);
+
+       wl1271_debug(DEBUG_SCAN, "Scanning complete");
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->state == WL1271_STATE_OFF)
+               goto out;
+
+       if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
+               goto out;
+
+       vif = wl->scan_vif;
+       wlvif = wl12xx_vif_to_data(vif);
+
+       /*
+        * Rearm the tx watchdog just before idling scan. This
+        * prevents just-finished scans from triggering the watchdog
+        */
+       wl12xx_rearm_tx_watchdog_locked(wl);
+
+       wl->scan.state = WL1271_SCAN_STATE_IDLE;
+       memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
+       wl->scan.req = NULL;
+       wl->scan_vif = NULL;
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
+               /* restore hardware connection monitoring template */
+               wl1271_cmd_build_ap_probe_req(wl, wlvif, wlvif->probereq);
+       }
+
+       wl1271_ps_elp_sleep(wl);
+
+       if (wl->scan.failed) {
+               wl1271_info("Scan completed due to error.");
+               wl12xx_queue_recovery_work(wl);
+       }
+
+       ieee80211_scan_completed(wl->hw, false);
+
+out:
+       mutex_unlock(&wl->mutex);
+
+}
+
+
+static int wl1271_get_scan_channels(struct wl1271 *wl,
+                                   struct cfg80211_scan_request *req,
+                                   struct basic_scan_channel_params *channels,
+                                   enum ieee80211_band band, bool passive)
+{
+       struct conf_scan_settings *c = &wl->conf.scan;
+       int i, j;
+       u32 flags;
+
+       for (i = 0, j = 0;
+            i < req->n_channels && j < WL1271_SCAN_MAX_CHANNELS;
+            i++) {
+               flags = req->channels[i]->flags;
+
+               if (!test_bit(i, wl->scan.scanned_ch) &&
+                   !(flags & IEEE80211_CHAN_DISABLED) &&
+                   (req->channels[i]->band == band) &&
+                   /*
+                    * In passive scans, we scan all remaining
+                    * channels, even if not marked as such.
+                    * In active scans, we only scan channels not
+                    * marked as passive.
+                    */
+                   (passive || !(flags & IEEE80211_CHAN_PASSIVE_SCAN))) {
+                       wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
+                                    req->channels[i]->band,
+                                    req->channels[i]->center_freq);
+                       wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
+                                    req->channels[i]->hw_value,
+                                    req->channels[i]->flags);
+                       wl1271_debug(DEBUG_SCAN,
+                                    "max_antenna_gain %d, max_power %d",
+                                    req->channels[i]->max_antenna_gain,
+                                    req->channels[i]->max_power);
+                       wl1271_debug(DEBUG_SCAN, "beacon_found %d",
+                                    req->channels[i]->beacon_found);
+
+                       if (!passive) {
+                               channels[j].min_duration =
+                                       cpu_to_le32(c->min_dwell_time_active);
+                               channels[j].max_duration =
+                                       cpu_to_le32(c->max_dwell_time_active);
+                       } else {
+                               channels[j].min_duration =
+                                       cpu_to_le32(c->min_dwell_time_passive);
+                               channels[j].max_duration =
+                                       cpu_to_le32(c->max_dwell_time_passive);
+                       }
+                       channels[j].early_termination = 0;
+                       channels[j].tx_power_att = req->channels[i]->max_power;
+                       channels[j].channel = req->channels[i]->hw_value;
+
+                       memset(&channels[j].bssid_lsb, 0xff, 4);
+                       memset(&channels[j].bssid_msb, 0xff, 2);
+
+                       /* Mark the channels we already used */
+                       set_bit(i, wl->scan.scanned_ch);
+
+                       j++;
+               }
+       }
+
+       return j;
+}
+
+#define WL1271_NOTHING_TO_SCAN 1
+
+static int wl1271_scan_send(struct wl1271 *wl, struct ieee80211_vif *vif,
+                           enum ieee80211_band band,
+                           bool passive, u32 basic_rate)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       struct wl1271_cmd_scan *cmd;
+       struct wl1271_cmd_trigger_scan_to *trigger;
+       int ret;
+       u16 scan_options = 0;
+
+       /* skip active scans if we don't have SSIDs */
+       if (!passive && wl->scan.req->n_ssids == 0)
+               return WL1271_NOTHING_TO_SCAN;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
+       if (!cmd || !trigger) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       if (wl->conf.scan.split_scan_timeout)
+               scan_options |= WL1271_SCAN_OPT_SPLIT_SCAN;
+
+       if (passive)
+               scan_options |= WL1271_SCAN_OPT_PASSIVE;
+
+       if (wlvif->bss_type == BSS_TYPE_AP_BSS ||
+           test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
+               cmd->params.role_id = wlvif->role_id;
+       else
+               cmd->params.role_id = wlvif->dev_role_id;
+
+       if (WARN_ON(cmd->params.role_id == WL12XX_INVALID_ROLE_ID)) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       cmd->params.scan_options = cpu_to_le16(scan_options);
+
+       cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req,
+                                                   cmd->channels,
+                                                   band, passive);
+       if (cmd->params.n_ch == 0) {
+               ret = WL1271_NOTHING_TO_SCAN;
+               goto out;
+       }
+
+       cmd->params.tx_rate = cpu_to_le32(basic_rate);
+       cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs;
+       cmd->params.tid_trigger = CONF_TX_AC_ANY_TID;
+       cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
+
+       if (band == IEEE80211_BAND_2GHZ)
+               cmd->params.band = WL1271_SCAN_BAND_2_4_GHZ;
+       else
+               cmd->params.band = WL1271_SCAN_BAND_5_GHZ;
+
+       if (wl->scan.ssid_len && wl->scan.ssid) {
+               cmd->params.ssid_len = wl->scan.ssid_len;
+               memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len);
+       }
+
+       memcpy(cmd->addr, vif->addr, ETH_ALEN);
+
+       ret = wl12xx_cmd_build_probe_req(wl, wlvif,
+                                        cmd->params.role_id, band,
+                                        wl->scan.ssid, wl->scan.ssid_len,
+                                        wl->scan.req->ie,
+                                        wl->scan.req->ie_len);
+       if (ret < 0) {
+               wl1271_error("PROBE request template failed");
+               goto out;
+       }
+
+       trigger->timeout = cpu_to_le32(wl->conf.scan.split_scan_timeout);
+       ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
+                             sizeof(*trigger), 0);
+       if (ret < 0) {
+               wl1271_error("trigger scan to failed for hw scan");
+               goto out;
+       }
+
+       wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd));
+
+       ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("SCAN failed");
+               goto out;
+       }
+
+out:
+       kfree(cmd);
+       kfree(trigger);
+       return ret;
+}
+
+void wl1271_scan_stm(struct wl1271 *wl, struct ieee80211_vif *vif)
+{
+       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
+       int ret = 0;
+       enum ieee80211_band band;
+       u32 rate, mask;
+
+       switch (wl->scan.state) {
+       case WL1271_SCAN_STATE_IDLE:
+               break;
+
+       case WL1271_SCAN_STATE_2GHZ_ACTIVE:
+               band = IEEE80211_BAND_2GHZ;
+               mask = wlvif->bitrate_masks[band];
+               if (wl->scan.req->no_cck) {
+                       mask &= ~CONF_TX_CCK_RATES;
+                       if (!mask)
+                               mask = CONF_TX_RATE_MASK_BASIC_P2P;
+               }
+               rate = wl1271_tx_min_rate_get(wl, mask);
+               ret = wl1271_scan_send(wl, vif, band, false, rate);
+               if (ret == WL1271_NOTHING_TO_SCAN) {
+                       wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE;
+                       wl1271_scan_stm(wl, vif);
+               }
+
+               break;
+
+       case WL1271_SCAN_STATE_2GHZ_PASSIVE:
+               band = IEEE80211_BAND_2GHZ;
+               mask = wlvif->bitrate_masks[band];
+               if (wl->scan.req->no_cck) {
+                       mask &= ~CONF_TX_CCK_RATES;
+                       if (!mask)
+                               mask = CONF_TX_RATE_MASK_BASIC_P2P;
+               }
+               rate = wl1271_tx_min_rate_get(wl, mask);
+               ret = wl1271_scan_send(wl, vif, band, true, rate);
+               if (ret == WL1271_NOTHING_TO_SCAN) {
+                       if (wl->enable_11a)
+                               wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE;
+                       else
+                               wl->scan.state = WL1271_SCAN_STATE_DONE;
+                       wl1271_scan_stm(wl, vif);
+               }
+
+               break;
+
+       case WL1271_SCAN_STATE_5GHZ_ACTIVE:
+               band = IEEE80211_BAND_5GHZ;
+               rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
+               ret = wl1271_scan_send(wl, vif, band, false, rate);
+               if (ret == WL1271_NOTHING_TO_SCAN) {
+                       wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE;
+                       wl1271_scan_stm(wl, vif);
+               }
+
+               break;
+
+       case WL1271_SCAN_STATE_5GHZ_PASSIVE:
+               band = IEEE80211_BAND_5GHZ;
+               rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
+               ret = wl1271_scan_send(wl, vif, band, true, rate);
+               if (ret == WL1271_NOTHING_TO_SCAN) {
+                       wl->scan.state = WL1271_SCAN_STATE_DONE;
+                       wl1271_scan_stm(wl, vif);
+               }
+
+               break;
+
+       case WL1271_SCAN_STATE_DONE:
+               wl->scan.failed = false;
+               cancel_delayed_work(&wl->scan_complete_work);
+               ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
+                                            msecs_to_jiffies(0));
+               break;
+
+       default:
+               wl1271_error("invalid scan state");
+               break;
+       }
+
+       if (ret < 0) {
+               cancel_delayed_work(&wl->scan_complete_work);
+               ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
+                                            msecs_to_jiffies(0));
+       }
+}
+
+int wl1271_scan(struct wl1271 *wl, struct ieee80211_vif *vif,
+               const u8 *ssid, size_t ssid_len,
+               struct cfg80211_scan_request *req)
+{
+       /*
+        * cfg80211 should guarantee that we don't get more channels
+        * than what we have registered.
+        */
+       BUG_ON(req->n_channels > WL1271_MAX_CHANNELS);
+
+       if (wl->scan.state != WL1271_SCAN_STATE_IDLE)
+               return -EBUSY;
+
+       wl->scan.state = WL1271_SCAN_STATE_2GHZ_ACTIVE;
+
+       if (ssid_len && ssid) {
+               wl->scan.ssid_len = ssid_len;
+               memcpy(wl->scan.ssid, ssid, ssid_len);
+       } else {
+               wl->scan.ssid_len = 0;
+       }
+
+       wl->scan_vif = vif;
+       wl->scan.req = req;
+       memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
+
+       /* we assume failure so that timeout scenarios are handled correctly */
+       wl->scan.failed = true;
+       ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
+                                    msecs_to_jiffies(WL1271_SCAN_TIMEOUT));
+
+       wl1271_scan_stm(wl, vif);
+
+       return 0;
+}
+
+int wl1271_scan_stop(struct wl1271 *wl)
+{
+       struct wl1271_cmd_header *cmd = NULL;
+       int ret = 0;
+
+       if (WARN_ON(wl->scan.state == WL1271_SCAN_STATE_IDLE))
+               return -EINVAL;
+
+       wl1271_debug(DEBUG_CMD, "cmd scan stop");
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       ret = wl1271_cmd_send(wl, CMD_STOP_SCAN, cmd,
+                             sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("cmd stop_scan failed");
+               goto out;
+       }
+out:
+       kfree(cmd);
+       return ret;
+}
+
+static int
+wl1271_scan_get_sched_scan_channels(struct wl1271 *wl,
+                                   struct cfg80211_sched_scan_request *req,
+                                   struct conn_scan_ch_params *channels,
+                                   u32 band, bool radar, bool passive,
+                                   int start, int max_channels)
+{
+       struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
+       int i, j;
+       u32 flags;
+       bool force_passive = !req->n_ssids;
+       u32 min_dwell_time_active, max_dwell_time_active, delta_per_probe;
+       u32 dwell_time_passive, dwell_time_dfs;
+
+       if (band == IEEE80211_BAND_5GHZ)
+               delta_per_probe = c->dwell_time_delta_per_probe_5;
+       else
+               delta_per_probe = c->dwell_time_delta_per_probe;
+
+       min_dwell_time_active = c->base_dwell_time +
+                req->n_ssids * c->num_probe_reqs * delta_per_probe;
+
+       max_dwell_time_active = min_dwell_time_active + c->max_dwell_time_delta;
+
+       min_dwell_time_active = DIV_ROUND_UP(min_dwell_time_active, 1000);
+       max_dwell_time_active = DIV_ROUND_UP(max_dwell_time_active, 1000);
+       dwell_time_passive = DIV_ROUND_UP(c->dwell_time_passive, 1000);
+       dwell_time_dfs = DIV_ROUND_UP(c->dwell_time_dfs, 1000);
+
+       for (i = 0, j = start;
+            i < req->n_channels && j < max_channels;
+            i++) {
+               flags = req->channels[i]->flags;
+
+               if (force_passive)
+                       flags |= IEEE80211_CHAN_PASSIVE_SCAN;
+
+               if ((req->channels[i]->band == band) &&
+                   !(flags & IEEE80211_CHAN_DISABLED) &&
+                   (!!(flags & IEEE80211_CHAN_RADAR) == radar) &&
+                   /* if radar is set, we ignore the passive flag */
+                   (radar ||
+                    !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) {
+                       wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
+                                    req->channels[i]->band,
+                                    req->channels[i]->center_freq);
+                       wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
+                                    req->channels[i]->hw_value,
+                                    req->channels[i]->flags);
+                       wl1271_debug(DEBUG_SCAN, "max_power %d",
+                                    req->channels[i]->max_power);
+                       wl1271_debug(DEBUG_SCAN, "min_dwell_time %d max dwell time %d",
+                                    min_dwell_time_active,
+                                    max_dwell_time_active);
+
+                       if (flags & IEEE80211_CHAN_RADAR) {
+                               channels[j].flags |= SCAN_CHANNEL_FLAGS_DFS;
+
+                               channels[j].passive_duration =
+                                       cpu_to_le16(dwell_time_dfs);
+                       } else {
+                               channels[j].passive_duration =
+                                       cpu_to_le16(dwell_time_passive);
+                       }
+
+                       channels[j].min_duration =
+                               cpu_to_le16(min_dwell_time_active);
+                       channels[j].max_duration =
+                               cpu_to_le16(max_dwell_time_active);
+
+                       channels[j].tx_power_att = req->channels[i]->max_power;
+                       channels[j].channel = req->channels[i]->hw_value;
+
+                       j++;
+               }
+       }
+
+       return j - start;
+}
+
+static bool
+wl1271_scan_sched_scan_channels(struct wl1271 *wl,
+                               struct cfg80211_sched_scan_request *req,
+                               struct wl1271_cmd_sched_scan_config *cfg)
+{
+       cfg->passive[0] =
+               wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
+                                                   IEEE80211_BAND_2GHZ,
+                                                   false, true, 0,
+                                                   MAX_CHANNELS_2GHZ);
+       cfg->active[0] =
+               wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
+                                                   IEEE80211_BAND_2GHZ,
+                                                   false, false,
+                                                   cfg->passive[0],
+                                                   MAX_CHANNELS_2GHZ);
+       cfg->passive[1] =
+               wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
+                                                   IEEE80211_BAND_5GHZ,
+                                                   false, true, 0,
+                                                   MAX_CHANNELS_5GHZ);
+       cfg->dfs =
+               wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
+                                                   IEEE80211_BAND_5GHZ,
+                                                   true, true,
+                                                   cfg->passive[1],
+                                                   MAX_CHANNELS_5GHZ);
+       cfg->active[1] =
+               wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
+                                                   IEEE80211_BAND_5GHZ,
+                                                   false, false,
+                                                   cfg->passive[1] + cfg->dfs,
+                                                   MAX_CHANNELS_5GHZ);
+       /* 802.11j channels are not supported yet */
+       cfg->passive[2] = 0;
+       cfg->active[2] = 0;
+
+       wl1271_debug(DEBUG_SCAN, "    2.4GHz: active %d passive %d",
+                    cfg->active[0], cfg->passive[0]);
+       wl1271_debug(DEBUG_SCAN, "    5GHz: active %d passive %d",
+                    cfg->active[1], cfg->passive[1]);
+       wl1271_debug(DEBUG_SCAN, "    DFS: %d", cfg->dfs);
+
+       return  cfg->passive[0] || cfg->active[0] ||
+               cfg->passive[1] || cfg->active[1] || cfg->dfs ||
+               cfg->passive[2] || cfg->active[2];
+}
+
+/* Returns the scan type to be used or a negative value on error */
+static int
+wl12xx_scan_sched_scan_ssid_list(struct wl1271 *wl,
+                                struct cfg80211_sched_scan_request *req)
+{
+       struct wl1271_cmd_sched_scan_ssid_list *cmd = NULL;
+       struct cfg80211_match_set *sets = req->match_sets;
+       struct cfg80211_ssid *ssids = req->ssids;
+       int ret = 0, type, i, j, n_match_ssids = 0;
+
+       wl1271_debug(DEBUG_CMD, "cmd sched scan ssid list");
+
+       /* count the match sets that contain SSIDs */
+       for (i = 0; i < req->n_match_sets; i++)
+               if (sets[i].ssid.ssid_len > 0)
+                       n_match_ssids++;
+
+       /* No filter, no ssids or only bcast ssid */
+       if (!n_match_ssids &&
+           (!req->n_ssids ||
+            (req->n_ssids == 1 && req->ssids[0].ssid_len == 0))) {
+               type = SCAN_SSID_FILTER_ANY;
+               goto out;
+       }
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       if (!n_match_ssids) {
+               /* No filter, with ssids */
+               type = SCAN_SSID_FILTER_DISABLED;
+
+               for (i = 0; i < req->n_ssids; i++) {
+                       cmd->ssids[cmd->n_ssids].type = (ssids[i].ssid_len) ?
+                               SCAN_SSID_TYPE_HIDDEN : SCAN_SSID_TYPE_PUBLIC;
+                       cmd->ssids[cmd->n_ssids].len = ssids[i].ssid_len;
+                       memcpy(cmd->ssids[cmd->n_ssids].ssid, ssids[i].ssid,
+                              ssids[i].ssid_len);
+                       cmd->n_ssids++;
+               }
+       } else {
+               type = SCAN_SSID_FILTER_LIST;
+
+               /* Add all SSIDs from the filters */
+               for (i = 0; i < req->n_match_sets; i++) {
+                       /* ignore sets without SSIDs */
+                       if (!sets[i].ssid.ssid_len)
+                               continue;
+
+                       cmd->ssids[cmd->n_ssids].type = SCAN_SSID_TYPE_PUBLIC;
+                       cmd->ssids[cmd->n_ssids].len = sets[i].ssid.ssid_len;
+                       memcpy(cmd->ssids[cmd->n_ssids].ssid,
+                              sets[i].ssid.ssid, sets[i].ssid.ssid_len);
+                       cmd->n_ssids++;
+               }
+               if ((req->n_ssids > 1) ||
+                   (req->n_ssids == 1 && req->ssids[0].ssid_len > 0)) {
+                       /*
+                        * Mark all the SSIDs passed in the SSID list as HIDDEN,
+                        * so they're used in probe requests.
+                        */
+                       for (i = 0; i < req->n_ssids; i++) {
+                               if (!req->ssids[i].ssid_len)
+                                       continue;
+
+                               for (j = 0; j < cmd->n_ssids; j++)
+                                       if (!memcmp(req->ssids[i].ssid,
+                                                  cmd->ssids[j].ssid,
+                                                  req->ssids[i].ssid_len)) {
+                                               cmd->ssids[j].type =
+                                                       SCAN_SSID_TYPE_HIDDEN;
+                                               break;
+                                       }
+                               /* Fail if SSID isn't present in the filters */
+                               if (j == cmd->n_ssids) {
+                                       ret = -EINVAL;
+                                       goto out_free;
+                               }
+                       }
+               }
+       }
+
+       wl1271_dump(DEBUG_SCAN, "SSID_LIST: ", cmd, sizeof(*cmd));
+
+       ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_SSID_CFG, cmd,
+                             sizeof(*cmd), 0);
+       if (ret < 0) {
+               wl1271_error("cmd sched scan ssid list failed");
+               goto out_free;
+       }
+
+out_free:
+       kfree(cmd);
+out:
+       if (ret < 0)
+               return ret;
+       return type;
+}
+
+int wl1271_scan_sched_scan_config(struct wl1271 *wl,
+                                 struct wl12xx_vif *wlvif,
+                                 struct cfg80211_sched_scan_request *req,
+                                 struct ieee80211_sched_scan_ies *ies)
+{
+       struct wl1271_cmd_sched_scan_config *cfg = NULL;
+       struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
+       int i, ret;
+       bool force_passive = !req->n_ssids;
+
+       wl1271_debug(DEBUG_CMD, "cmd sched_scan scan config");
+
+       cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
+       if (!cfg)
+               return -ENOMEM;
+
+       cfg->rssi_threshold = c->rssi_threshold;
+       cfg->snr_threshold  = c->snr_threshold;
+       cfg->n_probe_reqs = c->num_probe_reqs;
+       /* cycles set to 0 it means infinite (until manually stopped) */
+       cfg->cycles = 0;
+       /* report APs when at least 1 is found */
+       cfg->report_after = 1;
+       /* don't stop scanning automatically when something is found */
+       cfg->terminate = 0;
+       cfg->tag = WL1271_SCAN_DEFAULT_TAG;
+       /* don't filter on BSS type */
+       cfg->bss_type = SCAN_BSS_TYPE_ANY;
+       /* currently NL80211 supports only a single interval */
+       for (i = 0; i < SCAN_MAX_CYCLE_INTERVALS; i++)
+               cfg->intervals[i] = cpu_to_le32(req->interval);
+
+       cfg->ssid_len = 0;
+       ret = wl12xx_scan_sched_scan_ssid_list(wl, req);
+       if (ret < 0)
+               goto out;
+
+       cfg->filter_type = ret;
+
+       wl1271_debug(DEBUG_SCAN, "filter_type = %d", cfg->filter_type);
+
+       if (!wl1271_scan_sched_scan_channels(wl, req, cfg)) {
+               wl1271_error("scan channel list is empty");
+               ret = -EINVAL;
+               goto out;
+       }
+
+       if (!force_passive && cfg->active[0]) {
+               u8 band = IEEE80211_BAND_2GHZ;
+               ret = wl12xx_cmd_build_probe_req(wl, wlvif,
+                                                wlvif->dev_role_id, band,
+                                                req->ssids[0].ssid,
+                                                req->ssids[0].ssid_len,
+                                                ies->ie[band],
+                                                ies->len[band]);
+               if (ret < 0) {
+                       wl1271_error("2.4GHz PROBE request template failed");
+                       goto out;
+               }
+       }
+
+       if (!force_passive && cfg->active[1]) {
+               u8 band = IEEE80211_BAND_5GHZ;
+               ret = wl12xx_cmd_build_probe_req(wl, wlvif,
+                                                wlvif->dev_role_id, band,
+                                                req->ssids[0].ssid,
+                                                req->ssids[0].ssid_len,
+                                                ies->ie[band],
+                                                ies->len[band]);
+               if (ret < 0) {
+                       wl1271_error("5GHz PROBE request template failed");
+                       goto out;
+               }
+       }
+
+       wl1271_dump(DEBUG_SCAN, "SCAN_CFG: ", cfg, sizeof(*cfg));
+
+       ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_CFG, cfg,
+                             sizeof(*cfg), 0);
+       if (ret < 0) {
+               wl1271_error("SCAN configuration failed");
+               goto out;
+       }
+out:
+       kfree(cfg);
+       return ret;
+}
+
+int wl1271_scan_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       struct wl1271_cmd_sched_scan_start *start;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_CMD, "cmd periodic scan start");
+
+       if (wlvif->bss_type != BSS_TYPE_STA_BSS)
+               return -EOPNOTSUPP;
+
+       if (test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags))
+               return -EBUSY;
+
+       start = kzalloc(sizeof(*start), GFP_KERNEL);
+       if (!start)
+               return -ENOMEM;
+
+       start->tag = WL1271_SCAN_DEFAULT_TAG;
+
+       ret = wl1271_cmd_send(wl, CMD_START_PERIODIC_SCAN, start,
+                             sizeof(*start), 0);
+       if (ret < 0) {
+               wl1271_error("failed to send scan start command");
+               goto out_free;
+       }
+
+out_free:
+       kfree(start);
+       return ret;
+}
+
+void wl1271_scan_sched_scan_results(struct wl1271 *wl)
+{
+       wl1271_debug(DEBUG_SCAN, "got periodic scan results");
+
+       ieee80211_sched_scan_results(wl->hw);
+}
+
+void wl1271_scan_sched_scan_stop(struct wl1271 *wl)
+{
+       struct wl1271_cmd_sched_scan_stop *stop;
+       int ret = 0;
+
+       wl1271_debug(DEBUG_CMD, "cmd periodic scan stop");
+
+       /* FIXME: what to do if alloc'ing to stop fails? */
+       stop = kzalloc(sizeof(*stop), GFP_KERNEL);
+       if (!stop) {
+               wl1271_error("failed to alloc memory to send sched scan stop");
+               return;
+       }
+
+       stop->tag = WL1271_SCAN_DEFAULT_TAG;
+
+       ret = wl1271_cmd_send(wl, CMD_STOP_PERIODIC_SCAN, stop,
+                             sizeof(*stop), 0);
+       if (ret < 0) {
+               wl1271_error("failed to send sched scan stop command");
+               goto out_free;
+       }
+
+out_free:
+       kfree(stop);
+}
diff --git a/drivers/net/wireless/ti/wlcore/scan.h b/drivers/net/wireless/ti/wlcore/scan.h
new file mode 100644 (file)
index 0000000..81ee36a
--- /dev/null
@@ -0,0 +1,233 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2009-2010 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __SCAN_H__
+#define __SCAN_H__
+
+#include "wlcore.h"
+
+int wl1271_scan(struct wl1271 *wl, struct ieee80211_vif *vif,
+               const u8 *ssid, size_t ssid_len,
+               struct cfg80211_scan_request *req);
+int wl1271_scan_stop(struct wl1271 *wl);
+int wl1271_scan_build_probe_req(struct wl1271 *wl,
+                               const u8 *ssid, size_t ssid_len,
+                               const u8 *ie, size_t ie_len, u8 band);
+void wl1271_scan_stm(struct wl1271 *wl, struct ieee80211_vif *vif);
+void wl1271_scan_complete_work(struct work_struct *work);
+int wl1271_scan_sched_scan_config(struct wl1271 *wl,
+                                    struct wl12xx_vif *wlvif,
+                                    struct cfg80211_sched_scan_request *req,
+                                    struct ieee80211_sched_scan_ies *ies);
+int wl1271_scan_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+void wl1271_scan_sched_scan_stop(struct wl1271 *wl);
+void wl1271_scan_sched_scan_results(struct wl1271 *wl);
+
+#define WL1271_SCAN_MAX_CHANNELS       24
+#define WL1271_SCAN_DEFAULT_TAG        1
+#define WL1271_SCAN_CURRENT_TX_PWR     0
+#define WL1271_SCAN_OPT_ACTIVE         0
+#define WL1271_SCAN_OPT_PASSIVE               1
+#define WL1271_SCAN_OPT_SPLIT_SCAN     2
+#define WL1271_SCAN_OPT_PRIORITY_HIGH  4
+/* scan even if we fail to enter psm */
+#define WL1271_SCAN_OPT_FORCE          8
+#define WL1271_SCAN_BAND_2_4_GHZ 0
+#define WL1271_SCAN_BAND_5_GHZ 1
+
+#define WL1271_SCAN_TIMEOUT    30000 /* msec */
+
+enum {
+       WL1271_SCAN_STATE_IDLE,
+       WL1271_SCAN_STATE_2GHZ_ACTIVE,
+       WL1271_SCAN_STATE_2GHZ_PASSIVE,
+       WL1271_SCAN_STATE_5GHZ_ACTIVE,
+       WL1271_SCAN_STATE_5GHZ_PASSIVE,
+       WL1271_SCAN_STATE_DONE
+};
+
+struct basic_scan_params {
+       /* Scan option flags (WL1271_SCAN_OPT_*) */
+       __le16 scan_options;
+       u8 role_id;
+       /* Number of scan channels in the list (maximum 30) */
+       u8 n_ch;
+       /* This field indicates the number of probe requests to send
+          per channel for an active scan */
+       u8 n_probe_reqs;
+       u8 tid_trigger;
+       u8 ssid_len;
+       u8 use_ssid_list;
+
+       /* Rate bit field for sending the probes */
+       __le32 tx_rate;
+
+       u8 ssid[IEEE80211_MAX_SSID_LEN];
+       /* Band to scan */
+       u8 band;
+
+       u8 scan_tag;
+       u8 padding2[2];
+} __packed;
+
+struct basic_scan_channel_params {
+       /* Duration in TU to wait for frames on a channel for active scan */
+       __le32 min_duration;
+       __le32 max_duration;
+       __le32 bssid_lsb;
+       __le16 bssid_msb;
+       u8 early_termination;
+       u8 tx_power_att;
+       u8 channel;
+       /* FW internal use only! */
+       u8 dfs_candidate;
+       u8 activity_detected;
+       u8 pad;
+} __packed;
+
+struct wl1271_cmd_scan {
+       struct wl1271_cmd_header header;
+
+       struct basic_scan_params params;
+       struct basic_scan_channel_params channels[WL1271_SCAN_MAX_CHANNELS];
+
+       /* src mac address */
+       u8 addr[ETH_ALEN];
+       u8 padding[2];
+} __packed;
+
+struct wl1271_cmd_trigger_scan_to {
+       struct wl1271_cmd_header header;
+
+       __le32 timeout;
+} __packed;
+
+#define MAX_CHANNELS_2GHZ      14
+#define MAX_CHANNELS_5GHZ      23
+#define MAX_CHANNELS_4GHZ      4
+
+#define SCAN_MAX_CYCLE_INTERVALS 16
+#define SCAN_MAX_BANDS 3
+
+enum {
+       SCAN_SSID_FILTER_ANY      = 0,
+       SCAN_SSID_FILTER_SPECIFIC = 1,
+       SCAN_SSID_FILTER_LIST     = 2,
+       SCAN_SSID_FILTER_DISABLED = 3
+};
+
+enum {
+       SCAN_BSS_TYPE_INDEPENDENT,
+       SCAN_BSS_TYPE_INFRASTRUCTURE,
+       SCAN_BSS_TYPE_ANY,
+};
+
+#define SCAN_CHANNEL_FLAGS_DFS         BIT(0)
+#define SCAN_CHANNEL_FLAGS_DFS_ENABLED BIT(1)
+
+struct conn_scan_ch_params {
+       __le16 min_duration;
+       __le16 max_duration;
+       __le16 passive_duration;
+
+       u8  channel;
+       u8  tx_power_att;
+
+       /* bit 0: DFS channel; bit 1: DFS enabled */
+       u8  flags;
+
+       u8  padding[3];
+} __packed;
+
+struct wl1271_cmd_sched_scan_config {
+       struct wl1271_cmd_header header;
+
+       __le32 intervals[SCAN_MAX_CYCLE_INTERVALS];
+
+       s8 rssi_threshold; /* for filtering (in dBm) */
+       s8 snr_threshold;  /* for filtering (in dB) */
+
+       u8 cycles;       /* maximum number of scan cycles */
+       u8 report_after; /* report when this number of results are received */
+       u8 terminate;    /* stop scanning after reporting */
+
+       u8 tag;
+       u8 bss_type; /* for filtering */
+       u8 filter_type;
+
+       u8 ssid_len;     /* For SCAN_SSID_FILTER_SPECIFIC */
+       u8 ssid[IEEE80211_MAX_SSID_LEN];
+
+       u8 n_probe_reqs; /* Number of probes requests per channel */
+
+       u8 passive[SCAN_MAX_BANDS];
+       u8 active[SCAN_MAX_BANDS];
+
+       u8 dfs;
+
+       u8 padding[3];
+
+       struct conn_scan_ch_params channels_2[MAX_CHANNELS_2GHZ];
+       struct conn_scan_ch_params channels_5[MAX_CHANNELS_5GHZ];
+       struct conn_scan_ch_params channels_4[MAX_CHANNELS_4GHZ];
+} __packed;
+
+
+#define SCHED_SCAN_MAX_SSIDS 16
+
+enum {
+       SCAN_SSID_TYPE_PUBLIC = 0,
+       SCAN_SSID_TYPE_HIDDEN = 1,
+};
+
+struct wl1271_ssid {
+       u8 type;
+       u8 len;
+       u8 ssid[IEEE80211_MAX_SSID_LEN];
+       /* u8 padding[2]; */
+} __packed;
+
+struct wl1271_cmd_sched_scan_ssid_list {
+       struct wl1271_cmd_header header;
+
+       u8 n_ssids;
+       struct wl1271_ssid ssids[SCHED_SCAN_MAX_SSIDS];
+       u8 padding[3];
+} __packed;
+
+struct wl1271_cmd_sched_scan_start {
+       struct wl1271_cmd_header header;
+
+       u8 tag;
+       u8 padding[3];
+} __packed;
+
+struct wl1271_cmd_sched_scan_stop {
+       struct wl1271_cmd_header header;
+
+       u8 tag;
+       u8 padding[3];
+} __packed;
+
+
+#endif /* __WL1271_SCAN_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/sdio.c b/drivers/net/wireless/ti/wlcore/sdio.c
new file mode 100644 (file)
index 0000000..0a72347
--- /dev/null
@@ -0,0 +1,378 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2009-2010 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/irq.h>
+#include <linux/module.h>
+#include <linux/vmalloc.h>
+#include <linux/platform_device.h>
+#include <linux/mmc/sdio_func.h>
+#include <linux/mmc/sdio_ids.h>
+#include <linux/mmc/card.h>
+#include <linux/mmc/host.h>
+#include <linux/gpio.h>
+#include <linux/wl12xx.h>
+#include <linux/pm_runtime.h>
+
+#include "wlcore.h"
+#include "wl12xx_80211.h"
+#include "io.h"
+
+#ifndef SDIO_VENDOR_ID_TI
+#define SDIO_VENDOR_ID_TI              0x0097
+#endif
+
+#ifndef SDIO_DEVICE_ID_TI_WL1271
+#define SDIO_DEVICE_ID_TI_WL1271       0x4076
+#endif
+
+struct wl12xx_sdio_glue {
+       struct device *dev;
+       struct platform_device *core;
+};
+
+static const struct sdio_device_id wl1271_devices[] __devinitconst = {
+       { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) },
+       {}
+};
+MODULE_DEVICE_TABLE(sdio, wl1271_devices);
+
+static void wl1271_sdio_set_block_size(struct device *child,
+                                      unsigned int blksz)
+{
+       struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+       struct sdio_func *func = dev_to_sdio_func(glue->dev);
+
+       sdio_claim_host(func);
+       sdio_set_block_size(func, blksz);
+       sdio_release_host(func);
+}
+
+static void wl12xx_sdio_raw_read(struct device *child, int addr, void *buf,
+                                size_t len, bool fixed)
+{
+       int ret;
+       struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+       struct sdio_func *func = dev_to_sdio_func(glue->dev);
+
+       sdio_claim_host(func);
+
+       if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG)) {
+               ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
+               dev_dbg(child->parent, "sdio read 52 addr 0x%x, byte 0x%02x\n",
+                       addr, ((u8 *)buf)[0]);
+       } else {
+               if (fixed)
+                       ret = sdio_readsb(func, buf, addr, len);
+               else
+                       ret = sdio_memcpy_fromio(func, buf, addr, len);
+
+               dev_dbg(child->parent, "sdio read 53 addr 0x%x, %zu bytes\n",
+                       addr, len);
+       }
+
+       sdio_release_host(func);
+
+       if (ret)
+               dev_err(child->parent, "sdio read failed (%d)\n", ret);
+}
+
+static void wl12xx_sdio_raw_write(struct device *child, int addr, void *buf,
+                                 size_t len, bool fixed)
+{
+       int ret;
+       struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+       struct sdio_func *func = dev_to_sdio_func(glue->dev);
+
+       sdio_claim_host(func);
+
+       if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG)) {
+               sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
+               dev_dbg(child->parent, "sdio write 52 addr 0x%x, byte 0x%02x\n",
+                       addr, ((u8 *)buf)[0]);
+       } else {
+               dev_dbg(child->parent, "sdio write 53 addr 0x%x, %zu bytes\n",
+                       addr, len);
+
+               if (fixed)
+                       ret = sdio_writesb(func, addr, buf, len);
+               else
+                       ret = sdio_memcpy_toio(func, addr, buf, len);
+       }
+
+       sdio_release_host(func);
+
+       if (ret)
+               dev_err(child->parent, "sdio write failed (%d)\n", ret);
+}
+
+static int wl12xx_sdio_power_on(struct wl12xx_sdio_glue *glue)
+{
+       int ret;
+       struct sdio_func *func = dev_to_sdio_func(glue->dev);
+
+       /* If enabled, tell runtime PM not to power off the card */
+       if (pm_runtime_enabled(&func->dev)) {
+               ret = pm_runtime_get_sync(&func->dev);
+               if (ret < 0)
+                       goto out;
+       } else {
+               /* Runtime PM is disabled: power up the card manually */
+               ret = mmc_power_restore_host(func->card->host);
+               if (ret < 0)
+                       goto out;
+       }
+
+       sdio_claim_host(func);
+       sdio_enable_func(func);
+       sdio_release_host(func);
+
+out:
+       return ret;
+}
+
+static int wl12xx_sdio_power_off(struct wl12xx_sdio_glue *glue)
+{
+       int ret;
+       struct sdio_func *func = dev_to_sdio_func(glue->dev);
+
+       sdio_claim_host(func);
+       sdio_disable_func(func);
+       sdio_release_host(func);
+
+       /* Power off the card manually, even if runtime PM is enabled. */
+       ret = mmc_power_save_host(func->card->host);
+       if (ret < 0)
+               return ret;
+
+       /* If enabled, let runtime PM know the card is powered off */
+       if (pm_runtime_enabled(&func->dev))
+               ret = pm_runtime_put_sync(&func->dev);
+
+       return ret;
+}
+
+static int wl12xx_sdio_set_power(struct device *child, bool enable)
+{
+       struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
+
+       if (enable)
+               return wl12xx_sdio_power_on(glue);
+       else
+               return wl12xx_sdio_power_off(glue);
+}
+
+static struct wl1271_if_operations sdio_ops = {
+       .read           = wl12xx_sdio_raw_read,
+       .write          = wl12xx_sdio_raw_write,
+       .power          = wl12xx_sdio_set_power,
+       .set_block_size = wl1271_sdio_set_block_size,
+};
+
+static int __devinit wl1271_probe(struct sdio_func *func,
+                                 const struct sdio_device_id *id)
+{
+       struct wl12xx_platform_data *wlan_data;
+       struct wl12xx_sdio_glue *glue;
+       struct resource res[1];
+       mmc_pm_flag_t mmcflags;
+       int ret = -ENOMEM;
+
+       /* We are only able to handle the wlan function */
+       if (func->num != 0x02)
+               return -ENODEV;
+
+       glue = kzalloc(sizeof(*glue), GFP_KERNEL);
+       if (!glue) {
+               dev_err(&func->dev, "can't allocate glue\n");
+               goto out;
+       }
+
+       glue->dev = &func->dev;
+
+       /* Grab access to FN0 for ELP reg. */
+       func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
+
+       /* Use block mode for transferring over one block size of data */
+       func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
+
+       wlan_data = wl12xx_get_platform_data();
+       if (IS_ERR(wlan_data)) {
+               ret = PTR_ERR(wlan_data);
+               dev_err(glue->dev, "missing wlan platform data: %d\n", ret);
+               goto out_free_glue;
+       }
+
+       /* if sdio can keep power while host is suspended, enable wow */
+       mmcflags = sdio_get_host_pm_caps(func);
+       dev_dbg(glue->dev, "sdio PM caps = 0x%x\n", mmcflags);
+
+       if (mmcflags & MMC_PM_KEEP_POWER)
+               wlan_data->pwr_in_suspend = true;
+
+       wlan_data->ops = &sdio_ops;
+
+       sdio_set_drvdata(func, glue);
+
+       /* Tell PM core that we don't need the card to be powered now */
+       pm_runtime_put_noidle(&func->dev);
+
+       glue->core = platform_device_alloc("wl12xx", -1);
+       if (!glue->core) {
+               dev_err(glue->dev, "can't allocate platform_device");
+               ret = -ENOMEM;
+               goto out_free_glue;
+       }
+
+       glue->core->dev.parent = &func->dev;
+
+       memset(res, 0x00, sizeof(res));
+
+       res[0].start = wlan_data->irq;
+       res[0].flags = IORESOURCE_IRQ;
+       res[0].name = "irq";
+
+       ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
+       if (ret) {
+               dev_err(glue->dev, "can't add resources\n");
+               goto out_dev_put;
+       }
+
+       ret = platform_device_add_data(glue->core, wlan_data,
+                                      sizeof(*wlan_data));
+       if (ret) {
+               dev_err(glue->dev, "can't add platform data\n");
+               goto out_dev_put;
+       }
+
+       ret = platform_device_add(glue->core);
+       if (ret) {
+               dev_err(glue->dev, "can't add platform device\n");
+               goto out_dev_put;
+       }
+       return 0;
+
+out_dev_put:
+       platform_device_put(glue->core);
+
+out_free_glue:
+       kfree(glue);
+
+out:
+       return ret;
+}
+
+static void __devexit wl1271_remove(struct sdio_func *func)
+{
+       struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
+
+       /* Undo decrement done above in wl1271_probe */
+       pm_runtime_get_noresume(&func->dev);
+
+       platform_device_del(glue->core);
+       platform_device_put(glue->core);
+       kfree(glue);
+}
+
+#ifdef CONFIG_PM
+static int wl1271_suspend(struct device *dev)
+{
+       /* Tell MMC/SDIO core it's OK to power down the card
+        * (if it isn't already), but not to remove it completely */
+       struct sdio_func *func = dev_to_sdio_func(dev);
+       struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
+       struct wl1271 *wl = platform_get_drvdata(glue->core);
+       mmc_pm_flag_t sdio_flags;
+       int ret = 0;
+
+       dev_dbg(dev, "wl1271 suspend. wow_enabled: %d\n",
+               wl->wow_enabled);
+
+       /* check whether sdio should keep power */
+       if (wl->wow_enabled) {
+               sdio_flags = sdio_get_host_pm_caps(func);
+
+               if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
+                       dev_err(dev, "can't keep power while host "
+                                    "is suspended\n");
+                       ret = -EINVAL;
+                       goto out;
+               }
+
+               /* keep power while host suspended */
+               ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
+               if (ret) {
+                       dev_err(dev, "error while trying to keep power\n");
+                       goto out;
+               }
+       }
+out:
+       return ret;
+}
+
+static int wl1271_resume(struct device *dev)
+{
+       dev_dbg(dev, "wl1271 resume\n");
+
+       return 0;
+}
+
+static const struct dev_pm_ops wl1271_sdio_pm_ops = {
+       .suspend        = wl1271_suspend,
+       .resume         = wl1271_resume,
+};
+#endif
+
+static struct sdio_driver wl1271_sdio_driver = {
+       .name           = "wl1271_sdio",
+       .id_table       = wl1271_devices,
+       .probe          = wl1271_probe,
+       .remove         = __devexit_p(wl1271_remove),
+#ifdef CONFIG_PM
+       .drv = {
+               .pm = &wl1271_sdio_pm_ops,
+       },
+#endif
+};
+
+static int __init wl1271_init(void)
+{
+       return sdio_register_driver(&wl1271_sdio_driver);
+}
+
+static void __exit wl1271_exit(void)
+{
+       sdio_unregister_driver(&wl1271_sdio_driver);
+}
+
+module_init(wl1271_init);
+module_exit(wl1271_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
+MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
+MODULE_FIRMWARE(WL127X_FW_NAME_SINGLE);
+MODULE_FIRMWARE(WL127X_FW_NAME_MULTI);
+MODULE_FIRMWARE(WL127X_PLT_FW_NAME);
+MODULE_FIRMWARE(WL128X_FW_NAME_SINGLE);
+MODULE_FIRMWARE(WL128X_FW_NAME_MULTI);
+MODULE_FIRMWARE(WL128X_PLT_FW_NAME);
diff --git a/drivers/net/wireless/ti/wlcore/spi.c b/drivers/net/wireless/ti/wlcore/spi.c
new file mode 100644 (file)
index 0000000..553cd3c
--- /dev/null
@@ -0,0 +1,440 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/module.h>
+#include <linux/crc7.h>
+#include <linux/spi/spi.h>
+#include <linux/wl12xx.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include "wlcore.h"
+#include "wl12xx_80211.h"
+#include "io.h"
+
+#define WSPI_CMD_READ                 0x40000000
+#define WSPI_CMD_WRITE                0x00000000
+#define WSPI_CMD_FIXED                0x20000000
+#define WSPI_CMD_BYTE_LENGTH          0x1FFE0000
+#define WSPI_CMD_BYTE_LENGTH_OFFSET   17
+#define WSPI_CMD_BYTE_ADDR            0x0001FFFF
+
+#define WSPI_INIT_CMD_CRC_LEN       5
+
+#define WSPI_INIT_CMD_START         0x00
+#define WSPI_INIT_CMD_TX            0x40
+/* the extra bypass bit is sampled by the TNET as '1' */
+#define WSPI_INIT_CMD_BYPASS_BIT    0x80
+#define WSPI_INIT_CMD_FIXEDBUSY_LEN 0x07
+#define WSPI_INIT_CMD_EN_FIXEDBUSY  0x80
+#define WSPI_INIT_CMD_DIS_FIXEDBUSY 0x00
+#define WSPI_INIT_CMD_IOD           0x40
+#define WSPI_INIT_CMD_IP            0x20
+#define WSPI_INIT_CMD_CS            0x10
+#define WSPI_INIT_CMD_WS            0x08
+#define WSPI_INIT_CMD_WSPI          0x01
+#define WSPI_INIT_CMD_END           0x01
+
+#define WSPI_INIT_CMD_LEN           8
+
+#define HW_ACCESS_WSPI_FIXED_BUSY_LEN \
+               ((WL1271_BUSY_WORD_LEN - 4) / sizeof(u32))
+#define HW_ACCESS_WSPI_INIT_CMD_MASK  0
+
+/* HW limitation: maximum possible chunk size is 4095 bytes */
+#define WSPI_MAX_CHUNK_SIZE    4092
+
+#define WSPI_MAX_NUM_OF_CHUNKS (WL1271_AGGR_BUFFER_SIZE / WSPI_MAX_CHUNK_SIZE)
+
+struct wl12xx_spi_glue {
+       struct device *dev;
+       struct platform_device *core;
+};
+
+static void wl12xx_spi_reset(struct device *child)
+{
+       struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
+       u8 *cmd;
+       struct spi_transfer t;
+       struct spi_message m;
+
+       cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
+       if (!cmd) {
+               dev_err(child->parent,
+                       "could not allocate cmd for spi reset\n");
+               return;
+       }
+
+       memset(&t, 0, sizeof(t));
+       spi_message_init(&m);
+
+       memset(cmd, 0xff, WSPI_INIT_CMD_LEN);
+
+       t.tx_buf = cmd;
+       t.len = WSPI_INIT_CMD_LEN;
+       spi_message_add_tail(&t, &m);
+
+       spi_sync(to_spi_device(glue->dev), &m);
+
+       kfree(cmd);
+}
+
+static void wl12xx_spi_init(struct device *child)
+{
+       struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
+       u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
+       struct spi_transfer t;
+       struct spi_message m;
+
+       cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
+       if (!cmd) {
+               dev_err(child->parent,
+                       "could not allocate cmd for spi init\n");
+               return;
+       }
+
+       memset(crc, 0, sizeof(crc));
+       memset(&t, 0, sizeof(t));
+       spi_message_init(&m);
+
+       /*
+        * Set WSPI_INIT_COMMAND
+        * the data is being send from the MSB to LSB
+        */
+       cmd[2] = 0xff;
+       cmd[3] = 0xff;
+       cmd[1] = WSPI_INIT_CMD_START | WSPI_INIT_CMD_TX;
+       cmd[0] = 0;
+       cmd[7] = 0;
+       cmd[6] |= HW_ACCESS_WSPI_INIT_CMD_MASK << 3;
+       cmd[6] |= HW_ACCESS_WSPI_FIXED_BUSY_LEN & WSPI_INIT_CMD_FIXEDBUSY_LEN;
+
+       if (HW_ACCESS_WSPI_FIXED_BUSY_LEN == 0)
+               cmd[5] |=  WSPI_INIT_CMD_DIS_FIXEDBUSY;
+       else
+               cmd[5] |= WSPI_INIT_CMD_EN_FIXEDBUSY;
+
+       cmd[5] |= WSPI_INIT_CMD_IOD | WSPI_INIT_CMD_IP | WSPI_INIT_CMD_CS
+               | WSPI_INIT_CMD_WSPI | WSPI_INIT_CMD_WS;
+
+       crc[0] = cmd[1];
+       crc[1] = cmd[0];
+       crc[2] = cmd[7];
+       crc[3] = cmd[6];
+       crc[4] = cmd[5];
+
+       cmd[4] |= crc7(0, crc, WSPI_INIT_CMD_CRC_LEN) << 1;
+       cmd[4] |= WSPI_INIT_CMD_END;
+
+       t.tx_buf = cmd;
+       t.len = WSPI_INIT_CMD_LEN;
+       spi_message_add_tail(&t, &m);
+
+       spi_sync(to_spi_device(glue->dev), &m);
+       kfree(cmd);
+}
+
+#define WL1271_BUSY_WORD_TIMEOUT 1000
+
+static int wl12xx_spi_read_busy(struct device *child)
+{
+       struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
+       struct wl1271 *wl = dev_get_drvdata(child);
+       struct spi_transfer t[1];
+       struct spi_message m;
+       u32 *busy_buf;
+       int num_busy_bytes = 0;
+
+       /*
+        * Read further busy words from SPI until a non-busy word is
+        * encountered, then read the data itself into the buffer.
+        */
+
+       num_busy_bytes = WL1271_BUSY_WORD_TIMEOUT;
+       busy_buf = wl->buffer_busyword;
+       while (num_busy_bytes) {
+               num_busy_bytes--;
+               spi_message_init(&m);
+               memset(t, 0, sizeof(t));
+               t[0].rx_buf = busy_buf;
+               t[0].len = sizeof(u32);
+               t[0].cs_change = true;
+               spi_message_add_tail(&t[0], &m);
+               spi_sync(to_spi_device(glue->dev), &m);
+
+               if (*busy_buf & 0x1)
+                       return 0;
+       }
+
+       /* The SPI bus is unresponsive, the read failed. */
+       dev_err(child->parent, "SPI read busy-word timeout!\n");
+       return -ETIMEDOUT;
+}
+
+static void wl12xx_spi_raw_read(struct device *child, int addr, void *buf,
+                               size_t len, bool fixed)
+{
+       struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
+       struct wl1271 *wl = dev_get_drvdata(child);
+       struct spi_transfer t[2];
+       struct spi_message m;
+       u32 *busy_buf;
+       u32 *cmd;
+       u32 chunk_len;
+
+       while (len > 0) {
+               chunk_len = min((size_t)WSPI_MAX_CHUNK_SIZE, len);
+
+               cmd = &wl->buffer_cmd;
+               busy_buf = wl->buffer_busyword;
+
+               *cmd = 0;
+               *cmd |= WSPI_CMD_READ;
+               *cmd |= (chunk_len << WSPI_CMD_BYTE_LENGTH_OFFSET) &
+                       WSPI_CMD_BYTE_LENGTH;
+               *cmd |= addr & WSPI_CMD_BYTE_ADDR;
+
+               if (fixed)
+                       *cmd |= WSPI_CMD_FIXED;
+
+               spi_message_init(&m);
+               memset(t, 0, sizeof(t));
+
+               t[0].tx_buf = cmd;
+               t[0].len = 4;
+               t[0].cs_change = true;
+               spi_message_add_tail(&t[0], &m);
+
+               /* Busy and non busy words read */
+               t[1].rx_buf = busy_buf;
+               t[1].len = WL1271_BUSY_WORD_LEN;
+               t[1].cs_change = true;
+               spi_message_add_tail(&t[1], &m);
+
+               spi_sync(to_spi_device(glue->dev), &m);
+
+               if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) &&
+                   wl12xx_spi_read_busy(child)) {
+                       memset(buf, 0, chunk_len);
+                       return;
+               }
+
+               spi_message_init(&m);
+               memset(t, 0, sizeof(t));
+
+               t[0].rx_buf = buf;
+               t[0].len = chunk_len;
+               t[0].cs_change = true;
+               spi_message_add_tail(&t[0], &m);
+
+               spi_sync(to_spi_device(glue->dev), &m);
+
+               if (!fixed)
+                       addr += chunk_len;
+               buf += chunk_len;
+               len -= chunk_len;
+       }
+}
+
+static void wl12xx_spi_raw_write(struct device *child, int addr, void *buf,
+                                size_t len, bool fixed)
+{
+       struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
+       struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS];
+       struct spi_message m;
+       u32 commands[WSPI_MAX_NUM_OF_CHUNKS];
+       u32 *cmd;
+       u32 chunk_len;
+       int i;
+
+       WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
+
+       spi_message_init(&m);
+       memset(t, 0, sizeof(t));
+
+       cmd = &commands[0];
+       i = 0;
+       while (len > 0) {
+               chunk_len = min((size_t)WSPI_MAX_CHUNK_SIZE, len);
+
+               *cmd = 0;
+               *cmd |= WSPI_CMD_WRITE;
+               *cmd |= (chunk_len << WSPI_CMD_BYTE_LENGTH_OFFSET) &
+                       WSPI_CMD_BYTE_LENGTH;
+               *cmd |= addr & WSPI_CMD_BYTE_ADDR;
+
+               if (fixed)
+                       *cmd |= WSPI_CMD_FIXED;
+
+               t[i].tx_buf = cmd;
+               t[i].len = sizeof(*cmd);
+               spi_message_add_tail(&t[i++], &m);
+
+               t[i].tx_buf = buf;
+               t[i].len = chunk_len;
+               spi_message_add_tail(&t[i++], &m);
+
+               if (!fixed)
+                       addr += chunk_len;
+               buf += chunk_len;
+               len -= chunk_len;
+               cmd++;
+       }
+
+       spi_sync(to_spi_device(glue->dev), &m);
+}
+
+static struct wl1271_if_operations spi_ops = {
+       .read           = wl12xx_spi_raw_read,
+       .write          = wl12xx_spi_raw_write,
+       .reset          = wl12xx_spi_reset,
+       .init           = wl12xx_spi_init,
+       .set_block_size = NULL,
+};
+
+static int __devinit wl1271_probe(struct spi_device *spi)
+{
+       struct wl12xx_spi_glue *glue;
+       struct wl12xx_platform_data *pdata;
+       struct resource res[1];
+       int ret = -ENOMEM;
+
+       pdata = spi->dev.platform_data;
+       if (!pdata) {
+               dev_err(&spi->dev, "no platform data\n");
+               return -ENODEV;
+       }
+
+       pdata->ops = &spi_ops;
+
+       glue = kzalloc(sizeof(*glue), GFP_KERNEL);
+       if (!glue) {
+               dev_err(&spi->dev, "can't allocate glue\n");
+               goto out;
+       }
+
+       glue->dev = &spi->dev;
+
+       spi_set_drvdata(spi, glue);
+
+       /* This is the only SPI value that we need to set here, the rest
+        * comes from the board-peripherals file */
+       spi->bits_per_word = 32;
+
+       ret = spi_setup(spi);
+       if (ret < 0) {
+               dev_err(glue->dev, "spi_setup failed\n");
+               goto out_free_glue;
+       }
+
+       glue->core = platform_device_alloc("wl12xx", -1);
+       if (!glue->core) {
+               dev_err(glue->dev, "can't allocate platform_device\n");
+               ret = -ENOMEM;
+               goto out_free_glue;
+       }
+
+       glue->core->dev.parent = &spi->dev;
+
+       memset(res, 0x00, sizeof(res));
+
+       res[0].start = spi->irq;
+       res[0].flags = IORESOURCE_IRQ;
+       res[0].name = "irq";
+
+       ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
+       if (ret) {
+               dev_err(glue->dev, "can't add resources\n");
+               goto out_dev_put;
+       }
+
+       ret = platform_device_add_data(glue->core, pdata, sizeof(*pdata));
+       if (ret) {
+               dev_err(glue->dev, "can't add platform data\n");
+               goto out_dev_put;
+       }
+
+       ret = platform_device_add(glue->core);
+       if (ret) {
+               dev_err(glue->dev, "can't register platform device\n");
+               goto out_dev_put;
+       }
+
+       return 0;
+
+out_dev_put:
+       platform_device_put(glue->core);
+
+out_free_glue:
+       kfree(glue);
+out:
+       return ret;
+}
+
+static int __devexit wl1271_remove(struct spi_device *spi)
+{
+       struct wl12xx_spi_glue *glue = spi_get_drvdata(spi);
+
+       platform_device_del(glue->core);
+       platform_device_put(glue->core);
+       kfree(glue);
+
+       return 0;
+}
+
+
+static struct spi_driver wl1271_spi_driver = {
+       .driver = {
+               .name           = "wl1271_spi",
+               .owner          = THIS_MODULE,
+       },
+
+       .probe          = wl1271_probe,
+       .remove         = __devexit_p(wl1271_remove),
+};
+
+static int __init wl1271_init(void)
+{
+       return spi_register_driver(&wl1271_spi_driver);
+}
+
+static void __exit wl1271_exit(void)
+{
+       spi_unregister_driver(&wl1271_spi_driver);
+}
+
+module_init(wl1271_init);
+module_exit(wl1271_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
+MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
+MODULE_FIRMWARE(WL127X_FW_NAME_SINGLE);
+MODULE_FIRMWARE(WL127X_FW_NAME_MULTI);
+MODULE_FIRMWARE(WL127X_PLT_FW_NAME);
+MODULE_FIRMWARE(WL128X_FW_NAME_SINGLE);
+MODULE_FIRMWARE(WL128X_FW_NAME_MULTI);
+MODULE_FIRMWARE(WL128X_PLT_FW_NAME);
+MODULE_ALIAS("spi:wl1271");
diff --git a/drivers/net/wireless/ti/wlcore/testmode.c b/drivers/net/wireless/ti/wlcore/testmode.c
new file mode 100644 (file)
index 0000000..0e59ea2
--- /dev/null
@@ -0,0 +1,346 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2010 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+#include "testmode.h"
+
+#include <linux/slab.h>
+#include <net/genetlink.h>
+
+#include "wlcore.h"
+#include "debug.h"
+#include "acx.h"
+#include "ps.h"
+#include "io.h"
+
+#define WL1271_TM_MAX_DATA_LENGTH 1024
+
+enum wl1271_tm_commands {
+       WL1271_TM_CMD_UNSPEC,
+       WL1271_TM_CMD_TEST,
+       WL1271_TM_CMD_INTERROGATE,
+       WL1271_TM_CMD_CONFIGURE,
+       WL1271_TM_CMD_NVS_PUSH,         /* Not in use. Keep to not break ABI */
+       WL1271_TM_CMD_SET_PLT_MODE,
+       WL1271_TM_CMD_RECOVER,
+       WL1271_TM_CMD_GET_MAC,
+
+       __WL1271_TM_CMD_AFTER_LAST
+};
+#define WL1271_TM_CMD_MAX (__WL1271_TM_CMD_AFTER_LAST - 1)
+
+enum wl1271_tm_attrs {
+       WL1271_TM_ATTR_UNSPEC,
+       WL1271_TM_ATTR_CMD_ID,
+       WL1271_TM_ATTR_ANSWER,
+       WL1271_TM_ATTR_DATA,
+       WL1271_TM_ATTR_IE_ID,
+       WL1271_TM_ATTR_PLT_MODE,
+
+       __WL1271_TM_ATTR_AFTER_LAST
+};
+#define WL1271_TM_ATTR_MAX (__WL1271_TM_ATTR_AFTER_LAST - 1)
+
+static struct nla_policy wl1271_tm_policy[WL1271_TM_ATTR_MAX + 1] = {
+       [WL1271_TM_ATTR_CMD_ID] =       { .type = NLA_U32 },
+       [WL1271_TM_ATTR_ANSWER] =       { .type = NLA_U8 },
+       [WL1271_TM_ATTR_DATA] =         { .type = NLA_BINARY,
+                                         .len = WL1271_TM_MAX_DATA_LENGTH },
+       [WL1271_TM_ATTR_IE_ID] =        { .type = NLA_U32 },
+       [WL1271_TM_ATTR_PLT_MODE] =     { .type = NLA_U32 },
+};
+
+
+static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[])
+{
+       int buf_len, ret, len;
+       struct sk_buff *skb;
+       void *buf;
+       u8 answer = 0;
+
+       wl1271_debug(DEBUG_TESTMODE, "testmode cmd test");
+
+       if (!tb[WL1271_TM_ATTR_DATA])
+               return -EINVAL;
+
+       buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
+       buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
+
+       if (tb[WL1271_TM_ATTR_ANSWER])
+               answer = nla_get_u8(tb[WL1271_TM_ATTR_ANSWER]);
+
+       if (buf_len > sizeof(struct wl1271_command))
+               return -EMSGSIZE;
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->state == WL1271_STATE_OFF) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       ret = wl1271_cmd_test(wl, buf, buf_len, answer);
+       if (ret < 0) {
+               wl1271_warning("testmode cmd test failed: %d", ret);
+               goto out_sleep;
+       }
+
+       if (answer) {
+               len = nla_total_size(buf_len);
+               skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, len);
+               if (!skb) {
+                       ret = -ENOMEM;
+                       goto out_sleep;
+               }
+
+               if (nla_put(skb, WL1271_TM_ATTR_DATA, buf_len, buf))
+                       goto nla_put_failure;
+               ret = cfg80211_testmode_reply(skb);
+               if (ret < 0)
+                       goto out_sleep;
+       }
+
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+
+nla_put_failure:
+       kfree_skb(skb);
+       ret = -EMSGSIZE;
+       goto out_sleep;
+}
+
+static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
+{
+       int ret;
+       struct wl1271_command *cmd;
+       struct sk_buff *skb;
+       u8 ie_id;
+
+       wl1271_debug(DEBUG_TESTMODE, "testmode cmd interrogate");
+
+       if (!tb[WL1271_TM_ATTR_IE_ID])
+               return -EINVAL;
+
+       ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
+
+       mutex_lock(&wl->mutex);
+
+       if (wl->state == WL1271_STATE_OFF) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+       if (!cmd) {
+               ret = -ENOMEM;
+               goto out_sleep;
+       }
+
+       ret = wl1271_cmd_interrogate(wl, ie_id, cmd, sizeof(*cmd));
+       if (ret < 0) {
+               wl1271_warning("testmode cmd interrogate failed: %d", ret);
+               goto out_free;
+       }
+
+       skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, sizeof(*cmd));
+       if (!skb) {
+               ret = -ENOMEM;
+               goto out_free;
+       }
+
+       if (nla_put(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd))
+               goto nla_put_failure;
+       ret = cfg80211_testmode_reply(skb);
+       if (ret < 0)
+               goto out_free;
+
+out_free:
+       kfree(cmd);
+out_sleep:
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+
+       return ret;
+
+nla_put_failure:
+       kfree_skb(skb);
+       ret = -EMSGSIZE;
+       goto out_free;
+}
+
+static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[])
+{
+       int buf_len, ret;
+       void *buf;
+       u8 ie_id;
+
+       wl1271_debug(DEBUG_TESTMODE, "testmode cmd configure");
+
+       if (!tb[WL1271_TM_ATTR_DATA])
+               return -EINVAL;
+       if (!tb[WL1271_TM_ATTR_IE_ID])
+               return -EINVAL;
+
+       ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
+       buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
+       buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
+
+       if (buf_len > sizeof(struct wl1271_command))
+               return -EMSGSIZE;
+
+       mutex_lock(&wl->mutex);
+       ret = wl1271_cmd_configure(wl, ie_id, buf, buf_len);
+       mutex_unlock(&wl->mutex);
+
+       if (ret < 0) {
+               wl1271_warning("testmode cmd configure failed: %d", ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int wl1271_tm_cmd_set_plt_mode(struct wl1271 *wl, struct nlattr *tb[])
+{
+       u32 val;
+       int ret;
+
+       wl1271_debug(DEBUG_TESTMODE, "testmode cmd set plt mode");
+
+       if (!tb[WL1271_TM_ATTR_PLT_MODE])
+               return -EINVAL;
+
+       val = nla_get_u32(tb[WL1271_TM_ATTR_PLT_MODE]);
+
+       switch (val) {
+       case 0:
+               ret = wl1271_plt_stop(wl);
+               break;
+       case 1:
+               ret = wl1271_plt_start(wl);
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
+
+       return ret;
+}
+
+static int wl1271_tm_cmd_recover(struct wl1271 *wl, struct nlattr *tb[])
+{
+       wl1271_debug(DEBUG_TESTMODE, "testmode cmd recover");
+
+       wl12xx_queue_recovery_work(wl);
+
+       return 0;
+}
+
+static int wl12xx_tm_cmd_get_mac(struct wl1271 *wl, struct nlattr *tb[])
+{
+       struct sk_buff *skb;
+       u8 mac_addr[ETH_ALEN];
+       int ret = 0;
+
+       mutex_lock(&wl->mutex);
+
+       if (!wl->plt) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       if (wl->fuse_oui_addr == 0 && wl->fuse_nic_addr == 0) {
+               ret = -EOPNOTSUPP;
+               goto out;
+       }
+
+       mac_addr[0] = (u8)(wl->fuse_oui_addr >> 16);
+       mac_addr[1] = (u8)(wl->fuse_oui_addr >> 8);
+       mac_addr[2] = (u8) wl->fuse_oui_addr;
+       mac_addr[3] = (u8)(wl->fuse_nic_addr >> 16);
+       mac_addr[4] = (u8)(wl->fuse_nic_addr >> 8);
+       mac_addr[5] = (u8) wl->fuse_nic_addr;
+
+       skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, ETH_ALEN);
+       if (!skb) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       if (nla_put(skb, WL1271_TM_ATTR_DATA, ETH_ALEN, mac_addr))
+               goto nla_put_failure;
+       ret = cfg80211_testmode_reply(skb);
+       if (ret < 0)
+               goto out;
+
+out:
+       mutex_unlock(&wl->mutex);
+       return ret;
+
+nla_put_failure:
+       kfree_skb(skb);
+       ret = -EMSGSIZE;
+       goto out;
+}
+
+int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len)
+{
+       struct wl1271 *wl = hw->priv;
+       struct nlattr *tb[WL1271_TM_ATTR_MAX + 1];
+       int err;
+
+       err = nla_parse(tb, WL1271_TM_ATTR_MAX, data, len, wl1271_tm_policy);
+       if (err)
+               return err;
+
+       if (!tb[WL1271_TM_ATTR_CMD_ID])
+               return -EINVAL;
+
+       switch (nla_get_u32(tb[WL1271_TM_ATTR_CMD_ID])) {
+       case WL1271_TM_CMD_TEST:
+               return wl1271_tm_cmd_test(wl, tb);
+       case WL1271_TM_CMD_INTERROGATE:
+               return wl1271_tm_cmd_interrogate(wl, tb);
+       case WL1271_TM_CMD_CONFIGURE:
+               return wl1271_tm_cmd_configure(wl, tb);
+       case WL1271_TM_CMD_SET_PLT_MODE:
+               return wl1271_tm_cmd_set_plt_mode(wl, tb);
+       case WL1271_TM_CMD_RECOVER:
+               return wl1271_tm_cmd_recover(wl, tb);
+       case WL1271_TM_CMD_GET_MAC:
+               return wl12xx_tm_cmd_get_mac(wl, tb);
+       default:
+               return -EOPNOTSUPP;
+       }
+}
diff --git a/drivers/net/wireless/ti/wlcore/testmode.h b/drivers/net/wireless/ti/wlcore/testmode.h
new file mode 100644 (file)
index 0000000..8071654
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2010 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __TESTMODE_H__
+#define __TESTMODE_H__
+
+#include <net/mac80211.h>
+
+int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len);
+
+#endif /* __WL1271_TESTMODE_H__ */
diff --git a/drivers/net/wireless/ti/wlcore/tx.c b/drivers/net/wireless/ti/wlcore/tx.c
new file mode 100644 (file)
index 0000000..6893bc2
--- /dev/null
@@ -0,0 +1,1056 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/etherdevice.h>
+
+#include "wlcore.h"
+#include "debug.h"
+#include "io.h"
+#include "ps.h"
+#include "tx.h"
+#include "event.h"
+#include "hw_ops.h"
+
+/*
+ * TODO: this is here just for now, it must be removed when the data
+ * operations are in place.
+ */
+#include "../wl12xx/reg.h"
+
+static int wl1271_set_default_wep_key(struct wl1271 *wl,
+                                     struct wl12xx_vif *wlvif, u8 id)
+{
+       int ret;
+       bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
+
+       if (is_ap)
+               ret = wl12xx_cmd_set_default_wep_key(wl, id,
+                                                    wlvif->ap.bcast_hlid);
+       else
+               ret = wl12xx_cmd_set_default_wep_key(wl, id, wlvif->sta.hlid);
+
+       if (ret < 0)
+               return ret;
+
+       wl1271_debug(DEBUG_CRYPT, "default wep key idx: %d", (int)id);
+       return 0;
+}
+
+static int wl1271_alloc_tx_id(struct wl1271 *wl, struct sk_buff *skb)
+{
+       int id;
+
+       id = find_first_zero_bit(wl->tx_frames_map, wl->num_tx_desc);
+       if (id >= wl->num_tx_desc)
+               return -EBUSY;
+
+       __set_bit(id, wl->tx_frames_map);
+       wl->tx_frames[id] = skb;
+       wl->tx_frames_cnt++;
+       return id;
+}
+
+static void wl1271_free_tx_id(struct wl1271 *wl, int id)
+{
+       if (__test_and_clear_bit(id, wl->tx_frames_map)) {
+               if (unlikely(wl->tx_frames_cnt == wl->num_tx_desc))
+                       clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
+
+               wl->tx_frames[id] = NULL;
+               wl->tx_frames_cnt--;
+       }
+}
+
+static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl,
+                                                struct sk_buff *skb)
+{
+       struct ieee80211_hdr *hdr;
+
+       /*
+        * add the station to the known list before transmitting the
+        * authentication response. this way it won't get de-authed by FW
+        * when transmitting too soon.
+        */
+       hdr = (struct ieee80211_hdr *)(skb->data +
+                                      sizeof(struct wl1271_tx_hw_descr));
+       if (ieee80211_is_auth(hdr->frame_control))
+               wl1271_acx_set_inconnection_sta(wl, hdr->addr1);
+}
+
+static void wl1271_tx_regulate_link(struct wl1271 *wl,
+                                   struct wl12xx_vif *wlvif,
+                                   u8 hlid)
+{
+       bool fw_ps, single_sta;
+       u8 tx_pkts;
+
+       if (WARN_ON(!test_bit(hlid, wlvif->links_map)))
+               return;
+
+       fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
+       tx_pkts = wl->links[hlid].allocated_pkts;
+       single_sta = (wl->active_sta_count == 1);
+
+       /*
+        * if in FW PS and there is enough data in FW we can put the link
+        * into high-level PS and clean out its TX queues.
+        * Make an exception if this is the only connected station. In this
+        * case FW-memory congestion is not a problem.
+        */
+       if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
+               wl12xx_ps_link_start(wl, wlvif, hlid, true);
+}
+
+bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb)
+{
+       return wl->dummy_packet == skb;
+}
+
+u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                        struct sk_buff *skb)
+{
+       struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb);
+
+       if (control->control.sta) {
+               struct wl1271_station *wl_sta;
+
+               wl_sta = (struct wl1271_station *)
+                               control->control.sta->drv_priv;
+               return wl_sta->hlid;
+       } else {
+               struct ieee80211_hdr *hdr;
+
+               if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
+                       return wl->system_hlid;
+
+               hdr = (struct ieee80211_hdr *)skb->data;
+               if (ieee80211_is_mgmt(hdr->frame_control))
+                       return wlvif->ap.global_hlid;
+               else
+                       return wlvif->ap.bcast_hlid;
+       }
+}
+
+u8 wl12xx_tx_get_hlid(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                     struct sk_buff *skb)
+{
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
+
+       if (!wlvif || wl12xx_is_dummy_packet(wl, skb))
+               return wl->system_hlid;
+
+       if (wlvif->bss_type == BSS_TYPE_AP_BSS)
+               return wl12xx_tx_get_hlid_ap(wl, wlvif, skb);
+
+       if ((test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
+            test_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags)) &&
+           !ieee80211_is_auth(hdr->frame_control) &&
+           !ieee80211_is_assoc_req(hdr->frame_control))
+               return wlvif->sta.hlid;
+       else
+               return wlvif->dev_hlid;
+}
+
+unsigned int wlcore_calc_packet_alignment(struct wl1271 *wl,
+                                         unsigned int packet_length)
+{
+       if (wl->quirks & WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN)
+               return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE);
+       else
+               return ALIGN(packet_length, WL1271_TX_ALIGN_TO);
+}
+EXPORT_SYMBOL(wlcore_calc_packet_alignment);
+
+static int wl1271_tx_allocate(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                             struct sk_buff *skb, u32 extra, u32 buf_offset,
+                             u8 hlid)
+{
+       struct wl1271_tx_hw_descr *desc;
+       u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
+       u32 total_blocks;
+       int id, ret = -EBUSY, ac;
+       u32 spare_blocks = wl->normal_tx_spare;
+       bool is_dummy = false;
+
+       if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE)
+               return -EAGAIN;
+
+       /* allocate free identifier for the packet */
+       id = wl1271_alloc_tx_id(wl, skb);
+       if (id < 0)
+               return id;
+
+       if (unlikely(wl12xx_is_dummy_packet(wl, skb)))
+               is_dummy = true;
+       else if (wlvif->is_gem)
+               spare_blocks = wl->gem_tx_spare;
+
+       total_blocks = wlcore_hw_calc_tx_blocks(wl, total_len, spare_blocks);
+
+       if (total_blocks <= wl->tx_blocks_available) {
+               desc = (struct wl1271_tx_hw_descr *)skb_push(
+                       skb, total_len - skb->len);
+
+               wlcore_hw_set_tx_desc_blocks(wl, desc, total_blocks,
+                                            spare_blocks);
+
+               desc->id = id;
+
+               wl->tx_blocks_available -= total_blocks;
+               wl->tx_allocated_blocks += total_blocks;
+
+               /* If the FW was empty before, arm the Tx watchdog */
+               if (wl->tx_allocated_blocks == total_blocks)
+                       wl12xx_rearm_tx_watchdog_locked(wl);
+
+               ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
+               wl->tx_allocated_pkts[ac]++;
+
+               if (!is_dummy && wlvif &&
+                   wlvif->bss_type == BSS_TYPE_AP_BSS &&
+                   test_bit(hlid, wlvif->ap.sta_hlid_map))
+                       wl->links[hlid].allocated_pkts++;
+
+               ret = 0;
+
+               wl1271_debug(DEBUG_TX,
+                            "tx_allocate: size: %d, blocks: %d, id: %d",
+                            total_len, total_blocks, id);
+       } else {
+               wl1271_free_tx_id(wl, id);
+       }
+
+       return ret;
+}
+
+static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                              struct sk_buff *skb, u32 extra,
+                              struct ieee80211_tx_info *control, u8 hlid)
+{
+       struct timespec ts;
+       struct wl1271_tx_hw_descr *desc;
+       int ac, rate_idx;
+       s64 hosttime;
+       u16 tx_attr = 0;
+       __le16 frame_control;
+       struct ieee80211_hdr *hdr;
+       u8 *frame_start;
+       bool is_dummy;
+
+       desc = (struct wl1271_tx_hw_descr *) skb->data;
+       frame_start = (u8 *)(desc + 1);
+       hdr = (struct ieee80211_hdr *)(frame_start + extra);
+       frame_control = hdr->frame_control;
+
+       /* relocate space for security header */
+       if (extra) {
+               int hdrlen = ieee80211_hdrlen(frame_control);
+               memmove(frame_start, hdr, hdrlen);
+       }
+
+       /* configure packet life time */
+       getnstimeofday(&ts);
+       hosttime = (timespec_to_ns(&ts) >> 10);
+       desc->start_time = cpu_to_le32(hosttime - wl->time_offset);
+
+       is_dummy = wl12xx_is_dummy_packet(wl, skb);
+       if (is_dummy || !wlvif || wlvif->bss_type != BSS_TYPE_AP_BSS)
+               desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU);
+       else
+               desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU);
+
+       /* queue */
+       ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
+       desc->tid = skb->priority;
+
+       if (is_dummy) {
+               /*
+                * FW expects the dummy packet to have an invalid session id -
+                * any session id that is different than the one set in the join
+                */
+               tx_attr = (SESSION_COUNTER_INVALID <<
+                          TX_HW_ATTR_OFST_SESSION_COUNTER) &
+                          TX_HW_ATTR_SESSION_COUNTER;
+
+               tx_attr |= TX_HW_ATTR_TX_DUMMY_REQ;
+       } else if (wlvif) {
+               /* configure the tx attributes */
+               tx_attr = wlvif->session_counter <<
+                         TX_HW_ATTR_OFST_SESSION_COUNTER;
+       }
+
+       desc->hlid = hlid;
+       if (is_dummy || !wlvif)
+               rate_idx = 0;
+       else if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
+               /* if the packets are destined for AP (have a STA entry)
+                  send them with AP rate policies, otherwise use default
+                  basic rates */
+               if (control->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
+                       rate_idx = wlvif->sta.p2p_rate_idx;
+               else if (control->control.sta)
+                       rate_idx = wlvif->sta.ap_rate_idx;
+               else
+                       rate_idx = wlvif->sta.basic_rate_idx;
+       } else {
+               if (hlid == wlvif->ap.global_hlid)
+                       rate_idx = wlvif->ap.mgmt_rate_idx;
+               else if (hlid == wlvif->ap.bcast_hlid)
+                       rate_idx = wlvif->ap.bcast_rate_idx;
+               else
+                       rate_idx = wlvif->ap.ucast_rate_idx[ac];
+       }
+
+       tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY;
+
+       /* for WEP shared auth - no fw encryption is needed */
+       if (ieee80211_is_auth(frame_control) &&
+           ieee80211_has_protected(frame_control))
+               tx_attr |= TX_HW_ATTR_HOST_ENCRYPT;
+
+       desc->reserved = 0;
+       desc->tx_attr = cpu_to_le16(tx_attr);
+
+       wlcore_hw_set_tx_desc_data_len(wl, desc, skb);
+}
+
+/* caller must hold wl->mutex */
+static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                                  struct sk_buff *skb, u32 buf_offset)
+{
+       struct ieee80211_tx_info *info;
+       u32 extra = 0;
+       int ret = 0;
+       u32 total_len;
+       u8 hlid;
+       bool is_dummy;
+
+       if (!skb)
+               return -EINVAL;
+
+       info = IEEE80211_SKB_CB(skb);
+
+       /* TODO: handle dummy packets on multi-vifs */
+       is_dummy = wl12xx_is_dummy_packet(wl, skb);
+
+       if (info->control.hw_key &&
+           info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
+               extra = WL1271_EXTRA_SPACE_TKIP;
+
+       if (info->control.hw_key) {
+               bool is_wep;
+               u8 idx = info->control.hw_key->hw_key_idx;
+               u32 cipher = info->control.hw_key->cipher;
+
+               is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) ||
+                        (cipher == WLAN_CIPHER_SUITE_WEP104);
+
+               if (unlikely(is_wep && wlvif->default_key != idx)) {
+                       ret = wl1271_set_default_wep_key(wl, wlvif, idx);
+                       if (ret < 0)
+                               return ret;
+                       wlvif->default_key = idx;
+               }
+       }
+       hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
+       if (hlid == WL12XX_INVALID_LINK_ID) {
+               wl1271_error("invalid hlid. dropping skb 0x%p", skb);
+               return -EINVAL;
+       }
+
+       ret = wl1271_tx_allocate(wl, wlvif, skb, extra, buf_offset, hlid);
+       if (ret < 0)
+               return ret;
+
+       wl1271_tx_fill_hdr(wl, wlvif, skb, extra, info, hlid);
+
+       if (!is_dummy && wlvif && wlvif->bss_type == BSS_TYPE_AP_BSS) {
+               wl1271_tx_ap_update_inconnection_sta(wl, skb);
+               wl1271_tx_regulate_link(wl, wlvif, hlid);
+       }
+
+       /*
+        * The length of each packet is stored in terms of
+        * words. Thus, we must pad the skb data to make sure its
+        * length is aligned.  The number of padding bytes is computed
+        * and set in wl1271_tx_fill_hdr.
+        * In special cases, we want to align to a specific block size
+        * (eg. for wl128x with SDIO we align to 256).
+        */
+       total_len = wlcore_calc_packet_alignment(wl, skb->len);
+
+       memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len);
+       memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len);
+
+       /* Revert side effects in the dummy packet skb, so it can be reused */
+       if (is_dummy)
+               skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
+
+       return total_len;
+}
+
+u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set,
+                               enum ieee80211_band rate_band)
+{
+       struct ieee80211_supported_band *band;
+       u32 enabled_rates = 0;
+       int bit;
+
+       band = wl->hw->wiphy->bands[rate_band];
+       for (bit = 0; bit < band->n_bitrates; bit++) {
+               if (rate_set & 0x1)
+                       enabled_rates |= band->bitrates[bit].hw_value;
+               rate_set >>= 1;
+       }
+
+       /* MCS rates indication are on bits 16 - 23 */
+       rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates;
+
+       for (bit = 0; bit < 8; bit++) {
+               if (rate_set & 0x1)
+                       enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit);
+               rate_set >>= 1;
+       }
+
+       return enabled_rates;
+}
+
+void wl1271_handle_tx_low_watermark(struct wl1271 *wl)
+{
+       unsigned long flags;
+       int i;
+
+       for (i = 0; i < NUM_TX_QUEUES; i++) {
+               if (test_bit(i, &wl->stopped_queues_map) &&
+                   wl->tx_queue_count[i] <= WL1271_TX_QUEUE_LOW_WATERMARK) {
+                       /* firmware buffer has space, restart queues */
+                       spin_lock_irqsave(&wl->wl_lock, flags);
+                       ieee80211_wake_queue(wl->hw,
+                                            wl1271_tx_get_mac80211_queue(i));
+                       clear_bit(i, &wl->stopped_queues_map);
+                       spin_unlock_irqrestore(&wl->wl_lock, flags);
+               }
+       }
+}
+
+static struct sk_buff_head *wl1271_select_queue(struct wl1271 *wl,
+                                               struct sk_buff_head *queues)
+{
+       int i, q = -1, ac;
+       u32 min_pkts = 0xffffffff;
+
+       /*
+        * Find a non-empty ac where:
+        * 1. There are packets to transmit
+        * 2. The FW has the least allocated blocks
+        *
+        * We prioritize the ACs according to VO>VI>BE>BK
+        */
+       for (i = 0; i < NUM_TX_QUEUES; i++) {
+               ac = wl1271_tx_get_queue(i);
+               if (!skb_queue_empty(&queues[ac]) &&
+                   (wl->tx_allocated_pkts[ac] < min_pkts)) {
+                       q = ac;
+                       min_pkts = wl->tx_allocated_pkts[q];
+               }
+       }
+
+       if (q == -1)
+               return NULL;
+
+       return &queues[q];
+}
+
+static struct sk_buff *wl12xx_lnk_skb_dequeue(struct wl1271 *wl,
+                                             struct wl1271_link *lnk)
+{
+       struct sk_buff *skb;
+       unsigned long flags;
+       struct sk_buff_head *queue;
+
+       queue = wl1271_select_queue(wl, lnk->tx_queue);
+       if (!queue)
+               return NULL;
+
+       skb = skb_dequeue(queue);
+       if (skb) {
+               int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
+               spin_lock_irqsave(&wl->wl_lock, flags);
+               WARN_ON_ONCE(wl->tx_queue_count[q] <= 0);
+               wl->tx_queue_count[q]--;
+               spin_unlock_irqrestore(&wl->wl_lock, flags);
+       }
+
+       return skb;
+}
+
+static struct sk_buff *wl12xx_vif_skb_dequeue(struct wl1271 *wl,
+                                             struct wl12xx_vif *wlvif)
+{
+       struct sk_buff *skb = NULL;
+       int i, h, start_hlid;
+
+       /* start from the link after the last one */
+       start_hlid = (wlvif->last_tx_hlid + 1) % WL12XX_MAX_LINKS;
+
+       /* dequeue according to AC, round robin on each link */
+       for (i = 0; i < WL12XX_MAX_LINKS; i++) {
+               h = (start_hlid + i) % WL12XX_MAX_LINKS;
+
+               /* only consider connected stations */
+               if (!test_bit(h, wlvif->links_map))
+                       continue;
+
+               skb = wl12xx_lnk_skb_dequeue(wl, &wl->links[h]);
+               if (!skb)
+                       continue;
+
+               wlvif->last_tx_hlid = h;
+               break;
+       }
+
+       if (!skb)
+               wlvif->last_tx_hlid = 0;
+
+       return skb;
+}
+
+static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl)
+{
+       unsigned long flags;
+       struct wl12xx_vif *wlvif = wl->last_wlvif;
+       struct sk_buff *skb = NULL;
+
+       /* continue from last wlvif (round robin) */
+       if (wlvif) {
+               wl12xx_for_each_wlvif_continue(wl, wlvif) {
+                       skb = wl12xx_vif_skb_dequeue(wl, wlvif);
+                       if (skb) {
+                               wl->last_wlvif = wlvif;
+                               break;
+                       }
+               }
+       }
+
+       /* dequeue from the system HLID before the restarting wlvif list */
+       if (!skb)
+               skb = wl12xx_lnk_skb_dequeue(wl, &wl->links[wl->system_hlid]);
+
+       /* do a new pass over the wlvif list */
+       if (!skb) {
+               wl12xx_for_each_wlvif(wl, wlvif) {
+                       skb = wl12xx_vif_skb_dequeue(wl, wlvif);
+                       if (skb) {
+                               wl->last_wlvif = wlvif;
+                               break;
+                       }
+
+                       /*
+                        * No need to continue after last_wlvif. The previous
+                        * pass should have found it.
+                        */
+                       if (wlvif == wl->last_wlvif)
+                               break;
+               }
+       }
+
+       if (!skb &&
+           test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) {
+               int q;
+
+               skb = wl->dummy_packet;
+               q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
+               spin_lock_irqsave(&wl->wl_lock, flags);
+               WARN_ON_ONCE(wl->tx_queue_count[q] <= 0);
+               wl->tx_queue_count[q]--;
+               spin_unlock_irqrestore(&wl->wl_lock, flags);
+       }
+
+       return skb;
+}
+
+static void wl1271_skb_queue_head(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                                 struct sk_buff *skb)
+{
+       unsigned long flags;
+       int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
+
+       if (wl12xx_is_dummy_packet(wl, skb)) {
+               set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
+       } else {
+               u8 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
+               skb_queue_head(&wl->links[hlid].tx_queue[q], skb);
+
+               /* make sure we dequeue the same packet next time */
+               wlvif->last_tx_hlid = (hlid + WL12XX_MAX_LINKS - 1) %
+                                     WL12XX_MAX_LINKS;
+       }
+
+       spin_lock_irqsave(&wl->wl_lock, flags);
+       wl->tx_queue_count[q]++;
+       spin_unlock_irqrestore(&wl->wl_lock, flags);
+}
+
+static bool wl1271_tx_is_data_present(struct sk_buff *skb)
+{
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
+
+       return ieee80211_is_data_present(hdr->frame_control);
+}
+
+void wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids)
+{
+       struct wl12xx_vif *wlvif;
+       u32 timeout;
+       u8 hlid;
+
+       if (!wl->conf.rx_streaming.interval)
+               return;
+
+       if (!wl->conf.rx_streaming.always &&
+           !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))
+               return;
+
+       timeout = wl->conf.rx_streaming.duration;
+       wl12xx_for_each_wlvif_sta(wl, wlvif) {
+               bool found = false;
+               for_each_set_bit(hlid, active_hlids, WL12XX_MAX_LINKS) {
+                       if (test_bit(hlid, wlvif->links_map)) {
+                               found  = true;
+                               break;
+                       }
+               }
+
+               if (!found)
+                       continue;
+
+               /* enable rx streaming */
+               if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
+                       ieee80211_queue_work(wl->hw,
+                                            &wlvif->rx_streaming_enable_work);
+
+               mod_timer(&wlvif->rx_streaming_timer,
+                         jiffies + msecs_to_jiffies(timeout));
+       }
+}
+
+void wl1271_tx_work_locked(struct wl1271 *wl)
+{
+       struct wl12xx_vif *wlvif;
+       struct sk_buff *skb;
+       struct wl1271_tx_hw_descr *desc;
+       u32 buf_offset = 0;
+       bool sent_packets = false;
+       unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0};
+       int ret;
+
+       if (unlikely(wl->state == WL1271_STATE_OFF))
+               return;
+
+       while ((skb = wl1271_skb_dequeue(wl))) {
+               struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
+               bool has_data = false;
+
+               wlvif = NULL;
+               if (!wl12xx_is_dummy_packet(wl, skb) && info->control.vif)
+                       wlvif = wl12xx_vif_to_data(info->control.vif);
+
+               has_data = wlvif && wl1271_tx_is_data_present(skb);
+               ret = wl1271_prepare_tx_frame(wl, wlvif, skb, buf_offset);
+               if (ret == -EAGAIN) {
+                       /*
+                        * Aggregation buffer is full.
+                        * Flush buffer and try again.
+                        */
+                       wl1271_skb_queue_head(wl, wlvif, skb);
+                       wlcore_write_data(wl, REG_SLV_MEM_DATA, wl->aggr_buf,
+                                         buf_offset, true);
+                       sent_packets = true;
+                       buf_offset = 0;
+                       continue;
+               } else if (ret == -EBUSY) {
+                       /*
+                        * Firmware buffer is full.
+                        * Queue back last skb, and stop aggregating.
+                        */
+                       wl1271_skb_queue_head(wl, wlvif, skb);
+                       /* No work left, avoid scheduling redundant tx work */
+                       set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
+                       goto out_ack;
+               } else if (ret < 0) {
+                       if (wl12xx_is_dummy_packet(wl, skb))
+                               /*
+                                * fw still expects dummy packet,
+                                * so re-enqueue it
+                                */
+                               wl1271_skb_queue_head(wl, wlvif, skb);
+                       else
+                               ieee80211_free_txskb(wl->hw, skb);
+                       goto out_ack;
+               }
+               buf_offset += ret;
+               wl->tx_packets_count++;
+               if (has_data) {
+                       desc = (struct wl1271_tx_hw_descr *) skb->data;
+                       __set_bit(desc->hlid, active_hlids);
+               }
+       }
+
+out_ack:
+       if (buf_offset) {
+               wlcore_write_data(wl, REG_SLV_MEM_DATA, wl->aggr_buf,
+                                 buf_offset, true);
+               sent_packets = true;
+       }
+       if (sent_packets) {
+               /*
+                * Interrupt the firmware with the new packets. This is only
+                * required for older hardware revisions
+                */
+               if (wl->quirks & WLCORE_QUIRK_END_OF_TRANSACTION)
+                       wl1271_write32(wl, WL12XX_HOST_WR_ACCESS,
+                                      wl->tx_packets_count);
+
+               wl1271_handle_tx_low_watermark(wl);
+       }
+       wl12xx_rearm_rx_streaming(wl, active_hlids);
+}
+
+void wl1271_tx_work(struct work_struct *work)
+{
+       struct wl1271 *wl = container_of(work, struct wl1271, tx_work);
+       int ret;
+
+       mutex_lock(&wl->mutex);
+       ret = wl1271_ps_elp_wakeup(wl);
+       if (ret < 0)
+               goto out;
+
+       wl1271_tx_work_locked(wl);
+
+       wl1271_ps_elp_sleep(wl);
+out:
+       mutex_unlock(&wl->mutex);
+}
+
+static u8 wl1271_tx_get_rate_flags(u8 rate_class_index)
+{
+       u8 flags = 0;
+
+       /*
+        * TODO: use wl12xx constants when this code is moved to wl12xx, as
+        * only it uses Tx-completion.
+        */
+       if (rate_class_index <= 8)
+               flags |= IEEE80211_TX_RC_MCS;
+
+       /*
+        * TODO: use wl12xx constants when this code is moved to wl12xx, as
+        * only it uses Tx-completion.
+        */
+       if (rate_class_index == 0)
+               flags |= IEEE80211_TX_RC_SHORT_GI;
+
+       return flags;
+}
+
+static void wl1271_tx_complete_packet(struct wl1271 *wl,
+                                     struct wl1271_tx_hw_res_descr *result)
+{
+       struct ieee80211_tx_info *info;
+       struct ieee80211_vif *vif;
+       struct wl12xx_vif *wlvif;
+       struct sk_buff *skb;
+       int id = result->id;
+       int rate = -1;
+       u8 rate_flags = 0;
+       u8 retries = 0;
+
+       /* check for id legality */
+       if (unlikely(id >= wl->num_tx_desc || wl->tx_frames[id] == NULL)) {
+               wl1271_warning("TX result illegal id: %d", id);
+               return;
+       }
+
+       skb = wl->tx_frames[id];
+       info = IEEE80211_SKB_CB(skb);
+
+       if (wl12xx_is_dummy_packet(wl, skb)) {
+               wl1271_free_tx_id(wl, id);
+               return;
+       }
+
+       /* info->control is valid as long as we don't update info->status */
+       vif = info->control.vif;
+       wlvif = wl12xx_vif_to_data(vif);
+
+       /* update the TX status info */
+       if (result->status == TX_SUCCESS) {
+               if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
+                       info->flags |= IEEE80211_TX_STAT_ACK;
+               rate = wlcore_rate_to_idx(wl, result->rate_class_index,
+                                         wlvif->band);
+               rate_flags = wl1271_tx_get_rate_flags(result->rate_class_index);
+               retries = result->ack_failures;
+       } else if (result->status == TX_RETRY_EXCEEDED) {
+               wl->stats.excessive_retries++;
+               retries = result->ack_failures;
+       }
+
+       info->status.rates[0].idx = rate;
+       info->status.rates[0].count = retries;
+       info->status.rates[0].flags = rate_flags;
+       info->status.ack_signal = -1;
+
+       wl->stats.retry_count += result->ack_failures;
+
+       /*
+        * update sequence number only when relevant, i.e. only in
+        * sessions of TKIP, AES and GEM (not in open or WEP sessions)
+        */
+       if (info->control.hw_key &&
+           (info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP ||
+            info->control.hw_key->cipher == WLAN_CIPHER_SUITE_CCMP ||
+            info->control.hw_key->cipher == WL1271_CIPHER_SUITE_GEM)) {
+               u8 fw_lsb = result->tx_security_sequence_number_lsb;
+               u8 cur_lsb = wlvif->tx_security_last_seq_lsb;
+
+               /*
+                * update security sequence number, taking care of potential
+                * wrap-around
+                */
+               wlvif->tx_security_seq += (fw_lsb - cur_lsb) & 0xff;
+               wlvif->tx_security_last_seq_lsb = fw_lsb;
+       }
+
+       /* remove private header from packet */
+       skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
+
+       /* remove TKIP header space if present */
+       if (info->control.hw_key &&
+           info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
+               int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
+               memmove(skb->data + WL1271_EXTRA_SPACE_TKIP, skb->data,
+                       hdrlen);
+               skb_pull(skb, WL1271_EXTRA_SPACE_TKIP);
+       }
+
+       wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
+                    " status 0x%x",
+                    result->id, skb, result->ack_failures,
+                    result->rate_class_index, result->status);
+
+       /* return the packet to the stack */
+       skb_queue_tail(&wl->deferred_tx_queue, skb);
+       queue_work(wl->freezable_wq, &wl->netstack_work);
+       wl1271_free_tx_id(wl, result->id);
+}
+
+/* Called upon reception of a TX complete interrupt */
+void wl1271_tx_complete(struct wl1271 *wl)
+{
+       struct wl1271_acx_mem_map *memmap =
+               (struct wl1271_acx_mem_map *)wl->target_mem_map;
+       u32 count, fw_counter;
+       u32 i;
+
+       /* read the tx results from the chipset */
+       wl1271_read(wl, le32_to_cpu(memmap->tx_result),
+                   wl->tx_res_if, sizeof(*wl->tx_res_if), false);
+       fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter);
+
+       /* write host counter to chipset (to ack) */
+       wl1271_write32(wl, le32_to_cpu(memmap->tx_result) +
+                      offsetof(struct wl1271_tx_hw_res_if,
+                               tx_result_host_counter), fw_counter);
+
+       count = fw_counter - wl->tx_results_count;
+       wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count);
+
+       /* verify that the result buffer is not getting overrun */
+       if (unlikely(count > TX_HW_RESULT_QUEUE_LEN))
+               wl1271_warning("TX result overflow from chipset: %d", count);
+
+       /* process the results */
+       for (i = 0; i < count; i++) {
+               struct wl1271_tx_hw_res_descr *result;
+               u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK;
+
+               /* process the packet */
+               result =  &(wl->tx_res_if->tx_results_queue[offset]);
+               wl1271_tx_complete_packet(wl, result);
+
+               wl->tx_results_count++;
+       }
+}
+EXPORT_SYMBOL(wl1271_tx_complete);
+
+void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid)
+{
+       struct sk_buff *skb;
+       int i;
+       unsigned long flags;
+       struct ieee80211_tx_info *info;
+       int total[NUM_TX_QUEUES];
+
+       for (i = 0; i < NUM_TX_QUEUES; i++) {
+               total[i] = 0;
+               while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) {
+                       wl1271_debug(DEBUG_TX, "link freeing skb 0x%p", skb);
+
+                       if (!wl12xx_is_dummy_packet(wl, skb)) {
+                               info = IEEE80211_SKB_CB(skb);
+                               info->status.rates[0].idx = -1;
+                               info->status.rates[0].count = 0;
+                               ieee80211_tx_status_ni(wl->hw, skb);
+                       }
+
+                       total[i]++;
+               }
+       }
+
+       spin_lock_irqsave(&wl->wl_lock, flags);
+       for (i = 0; i < NUM_TX_QUEUES; i++)
+               wl->tx_queue_count[i] -= total[i];
+       spin_unlock_irqrestore(&wl->wl_lock, flags);
+
+       wl1271_handle_tx_low_watermark(wl);
+}
+
+/* caller must hold wl->mutex and TX must be stopped */
+void wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif)
+{
+       int i;
+
+       /* TX failure */
+       for_each_set_bit(i, wlvif->links_map, WL12XX_MAX_LINKS) {
+               if (wlvif->bss_type == BSS_TYPE_AP_BSS)
+                       wl1271_free_sta(wl, wlvif, i);
+               else
+                       wlvif->sta.ba_rx_bitmap = 0;
+
+               wl->links[i].allocated_pkts = 0;
+               wl->links[i].prev_freed_pkts = 0;
+       }
+       wlvif->last_tx_hlid = 0;
+
+}
+/* caller must hold wl->mutex and TX must be stopped */
+void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues)
+{
+       int i;
+       struct sk_buff *skb;
+       struct ieee80211_tx_info *info;
+
+       /* only reset the queues if something bad happened */
+       if (WARN_ON_ONCE(wl1271_tx_total_queue_count(wl) != 0)) {
+               for (i = 0; i < WL12XX_MAX_LINKS; i++)
+                       wl1271_tx_reset_link_queues(wl, i);
+
+               for (i = 0; i < NUM_TX_QUEUES; i++)
+                       wl->tx_queue_count[i] = 0;
+       }
+
+       wl->stopped_queues_map = 0;
+
+       /*
+        * Make sure the driver is at a consistent state, in case this
+        * function is called from a context other than interface removal.
+        * This call will always wake the TX queues.
+        */
+       if (reset_tx_queues)
+               wl1271_handle_tx_low_watermark(wl);
+
+       for (i = 0; i < wl->num_tx_desc; i++) {
+               if (wl->tx_frames[i] == NULL)
+                       continue;
+
+               skb = wl->tx_frames[i];
+               wl1271_free_tx_id(wl, i);
+               wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
+
+               if (!wl12xx_is_dummy_packet(wl, skb)) {
+                       /*
+                        * Remove private headers before passing the skb to
+                        * mac80211
+                        */
+                       info = IEEE80211_SKB_CB(skb);
+                       skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
+                       if (info->control.hw_key &&
+                           info->control.hw_key->cipher ==
+                           WLAN_CIPHER_SUITE_TKIP) {
+                               int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
+                               memmove(skb->data + WL1271_EXTRA_SPACE_TKIP,
+                                       skb->data, hdrlen);
+                               skb_pull(skb, WL1271_EXTRA_SPACE_TKIP);
+                       }
+
+                       info->status.rates[0].idx = -1;
+                       info->status.rates[0].count = 0;
+
+                       ieee80211_tx_status_ni(wl->hw, skb);
+               }
+       }
+}
+
+#define WL1271_TX_FLUSH_TIMEOUT 500000
+
+/* caller must *NOT* hold wl->mutex */
+void wl1271_tx_flush(struct wl1271 *wl)
+{
+       unsigned long timeout;
+       int i;
+       timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT);
+
+       while (!time_after(jiffies, timeout)) {
+               mutex_lock(&wl->mutex);
+               wl1271_debug(DEBUG_TX, "flushing tx buffer: %d %d",
+                            wl->tx_frames_cnt,
+                            wl1271_tx_total_queue_count(wl));
+               if ((wl->tx_frames_cnt == 0) &&
+                   (wl1271_tx_total_queue_count(wl) == 0)) {
+                       mutex_unlock(&wl->mutex);
+                       return;
+               }
+               mutex_unlock(&wl->mutex);
+               msleep(1);
+       }
+
+       wl1271_warning("Unable to flush all TX buffers, timed out.");
+
+       /* forcibly flush all Tx buffers on our queues */
+       mutex_lock(&wl->mutex);
+       for (i = 0; i < WL12XX_MAX_LINKS; i++)
+               wl1271_tx_reset_link_queues(wl, i);
+       mutex_unlock(&wl->mutex);
+}
+
+u32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set)
+{
+       if (WARN_ON(!rate_set))
+               return 0;
+
+       return BIT(__ffs(rate_set));
+}
diff --git a/drivers/net/wireless/ti/wlcore/tx.h b/drivers/net/wireless/ti/wlcore/tx.h
new file mode 100644 (file)
index 0000000..2fd6e5d
--- /dev/null
@@ -0,0 +1,231 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __TX_H__
+#define __TX_H__
+
+#define TX_HW_MGMT_PKT_LIFETIME_TU       2000
+#define TX_HW_AP_MODE_PKT_LIFETIME_TU    8000
+
+#define TX_HW_ATTR_SAVE_RETRIES          BIT(0)
+#define TX_HW_ATTR_HEADER_PAD            BIT(1)
+#define TX_HW_ATTR_SESSION_COUNTER       (BIT(2) | BIT(3) | BIT(4))
+#define TX_HW_ATTR_RATE_POLICY           (BIT(5) | BIT(6) | BIT(7) | \
+                                         BIT(8) | BIT(9))
+#define TX_HW_ATTR_LAST_WORD_PAD         (BIT(10) | BIT(11))
+#define TX_HW_ATTR_TX_CMPLT_REQ          BIT(12)
+#define TX_HW_ATTR_TX_DUMMY_REQ          BIT(13)
+#define TX_HW_ATTR_HOST_ENCRYPT          BIT(14)
+
+#define TX_HW_ATTR_OFST_SAVE_RETRIES     0
+#define TX_HW_ATTR_OFST_HEADER_PAD       1
+#define TX_HW_ATTR_OFST_SESSION_COUNTER  2
+#define TX_HW_ATTR_OFST_RATE_POLICY      5
+#define TX_HW_ATTR_OFST_LAST_WORD_PAD    10
+#define TX_HW_ATTR_OFST_TX_CMPLT_REQ     12
+
+#define TX_HW_RESULT_QUEUE_LEN           16
+#define TX_HW_RESULT_QUEUE_LEN_MASK      0xf
+
+#define WL1271_TX_ALIGN_TO 4
+#define WL1271_EXTRA_SPACE_TKIP 4
+#define WL1271_EXTRA_SPACE_AES  8
+#define WL1271_EXTRA_SPACE_MAX  8
+
+/* Used for management frames and dummy packets */
+#define WL1271_TID_MGMT 7
+
+struct wl127x_tx_mem {
+       /*
+        * Number of extra memory blocks to allocate for this packet
+        * in addition to the number of blocks derived from the packet
+        * length.
+        */
+       u8 extra_blocks;
+       /*
+        * Total number of memory blocks allocated by the host for
+        * this packet. Must be equal or greater than the actual
+        * blocks number allocated by HW.
+        */
+       u8 total_mem_blocks;
+} __packed;
+
+struct wl128x_tx_mem {
+       /*
+        * Total number of memory blocks allocated by the host for
+        * this packet.
+        */
+       u8 total_mem_blocks;
+       /*
+        * Number of extra bytes, at the end of the frame. the host
+        * uses this padding to complete each frame to integer number
+        * of SDIO blocks.
+        */
+       u8 extra_bytes;
+} __packed;
+
+/*
+ * On wl128x based devices, when TX packets are aggregated, each packet
+ * size must be aligned to the SDIO block size. The maximum block size
+ * is bounded by the type of the padded bytes field that is sent to the
+ * FW. Currently the type is u8, so the maximum block size is 256 bytes.
+ */
+#define WL12XX_BUS_BLOCK_SIZE min(512u,        \
+           (1u << (8 * sizeof(((struct wl128x_tx_mem *) 0)->extra_bytes))))
+
+struct wl1271_tx_hw_descr {
+       /* Length of packet in words, including descriptor+header+data */
+       __le16 length;
+       union {
+               struct wl127x_tx_mem wl127x_mem;
+               struct wl128x_tx_mem wl128x_mem;
+       } __packed;
+       /* Device time (in us) when the packet arrived to the driver */
+       __le32 start_time;
+       /*
+        * Max delay in TUs until transmission. The last device time the
+        * packet can be transmitted is: start_time + (1024 * life_time)
+        */
+       __le16 life_time;
+       /* Bitwise fields - see TX_ATTR... definitions above. */
+       __le16 tx_attr;
+       /* Packet identifier used also in the Tx-Result. */
+       u8 id;
+       /* The packet TID value (as User-Priority) */
+       u8 tid;
+       /* host link ID (HLID) */
+       u8 hlid;
+       u8 reserved;
+} __packed;
+
+enum wl1271_tx_hw_res_status {
+       TX_SUCCESS          = 0,
+       TX_HW_ERROR         = 1,
+       TX_DISABLED         = 2,
+       TX_RETRY_EXCEEDED   = 3,
+       TX_TIMEOUT          = 4,
+       TX_KEY_NOT_FOUND    = 5,
+       TX_PEER_NOT_FOUND   = 6,
+       TX_SESSION_MISMATCH = 7,
+       TX_LINK_NOT_VALID   = 8,
+};
+
+struct wl1271_tx_hw_res_descr {
+       /* Packet Identifier - same value used in the Tx descriptor.*/
+       u8 id;
+       /* The status of the transmission, indicating success or one of
+          several possible reasons for failure. */
+       u8 status;
+       /* Total air access duration including all retrys and overheads.*/
+       __le16 medium_usage;
+       /* The time passed from host xfer to Tx-complete.*/
+       __le32 fw_handling_time;
+       /* Total media delay
+          (from 1st EDCA AIFS counter until TX Complete). */
+       __le32 medium_delay;
+       /* LS-byte of last TKIP seq-num (saved per AC for recovery). */
+       u8 tx_security_sequence_number_lsb;
+       /* Retry count - number of transmissions without successful ACK.*/
+       u8 ack_failures;
+       /* The rate that succeeded getting ACK
+          (Valid only if status=SUCCESS). */
+       u8 rate_class_index;
+       /* for 4-byte alignment. */
+       u8 spare;
+} __packed;
+
+struct wl1271_tx_hw_res_if {
+       __le32 tx_result_fw_counter;
+       __le32 tx_result_host_counter;
+       struct wl1271_tx_hw_res_descr tx_results_queue[TX_HW_RESULT_QUEUE_LEN];
+} __packed;
+
+static inline int wl1271_tx_get_queue(int queue)
+{
+       switch (queue) {
+       case 0:
+               return CONF_TX_AC_VO;
+       case 1:
+               return CONF_TX_AC_VI;
+       case 2:
+               return CONF_TX_AC_BE;
+       case 3:
+               return CONF_TX_AC_BK;
+       default:
+               return CONF_TX_AC_BE;
+       }
+}
+
+static inline int wl1271_tx_get_mac80211_queue(int queue)
+{
+       switch (queue) {
+       case CONF_TX_AC_VO:
+               return 0;
+       case CONF_TX_AC_VI:
+               return 1;
+       case CONF_TX_AC_BE:
+               return 2;
+       case CONF_TX_AC_BK:
+               return 3;
+       default:
+               return 2;
+       }
+}
+
+static inline int wl1271_tx_total_queue_count(struct wl1271 *wl)
+{
+       int i, count = 0;
+
+       for (i = 0; i < NUM_TX_QUEUES; i++)
+               count += wl->tx_queue_count[i];
+
+       return count;
+}
+
+void wl1271_tx_work(struct work_struct *work);
+void wl1271_tx_work_locked(struct wl1271 *wl);
+void wl1271_tx_complete(struct wl1271 *wl);
+void wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues);
+void wl1271_tx_flush(struct wl1271 *wl);
+u8 wlcore_rate_to_idx(struct wl1271 *wl, u8 rate, enum ieee80211_band band);
+u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set,
+                               enum ieee80211_band rate_band);
+u32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set);
+u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                        struct sk_buff *skb);
+u8 wl12xx_tx_get_hlid(struct wl1271 *wl, struct wl12xx_vif *wlvif,
+                     struct sk_buff *skb);
+void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid);
+void wl1271_handle_tx_low_watermark(struct wl1271 *wl);
+bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb);
+void wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids);
+unsigned int wlcore_calc_packet_alignment(struct wl1271 *wl,
+                                         unsigned int packet_length);
+
+/* from main.c */
+void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid);
+void wl12xx_rearm_tx_watchdog_locked(struct wl1271 *wl);
+
+#endif
diff --git a/drivers/net/wireless/ti/wlcore/wl12xx.h b/drivers/net/wireless/ti/wlcore/wl12xx.h
new file mode 100644 (file)
index 0000000..a9b220c
--- /dev/null
@@ -0,0 +1,466 @@
+/*
+ * This file is part of wl1271
+ *
+ * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
+ * Copyright (C) 2008-2009 Nokia Corporation
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WL12XX_H__
+#define __WL12XX_H__
+
+#include <linux/mutex.h>
+#include <linux/completion.h>
+#include <linux/spinlock.h>
+#include <linux/list.h>
+#include <linux/bitops.h>
+#include <net/mac80211.h>
+
+#include "conf.h"
+#include "ini.h"
+
+#define WL127X_FW_NAME_MULTI "ti-connectivity/wl127x-fw-4-mr.bin"
+#define WL127X_FW_NAME_SINGLE "ti-connectivity/wl127x-fw-4-sr.bin"
+
+#define WL128X_FW_NAME_MULTI "ti-connectivity/wl128x-fw-4-mr.bin"
+#define WL128X_FW_NAME_SINGLE "ti-connectivity/wl128x-fw-4-sr.bin"
+
+#define WL127X_PLT_FW_NAME "ti-connectivity/wl127x-fw-4-plt.bin"
+#define WL128X_PLT_FW_NAME "ti-connectivity/wl128x-fw-4-plt.bin"
+
+/*
+ * wl127x and wl128x are using the same NVS file name. However, the
+ * ini parameters between them are different.  The driver validates
+ * the correct NVS size in wl1271_boot_upload_nvs().
+ */
+#define WL12XX_NVS_NAME "ti-connectivity/wl1271-nvs.bin"
+
+#define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
+#define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
+#define WL1271_TX_SQN_POST_RECOVERY_PADDING 0xff
+
+#define WL1271_CIPHER_SUITE_GEM 0x00147201
+
+#define WL1271_BUSY_WORD_CNT 1
+#define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
+
+#define WL1271_ELP_HW_STATE_ASLEEP 0
+#define WL1271_ELP_HW_STATE_IRQ    1
+
+#define WL1271_DEFAULT_BEACON_INT  100
+#define WL1271_DEFAULT_DTIM_PERIOD 1
+
+#define WL12XX_MAX_ROLES           4
+#define WL12XX_MAX_LINKS           12
+#define WL12XX_INVALID_ROLE_ID     0xff
+#define WL12XX_INVALID_LINK_ID     0xff
+
+#define WL12XX_MAX_RATE_POLICIES 16
+
+/* Defined by FW as 0. Will not be freed or allocated. */
+#define WL12XX_SYSTEM_HLID         0
+
+/*
+ * When in AP-mode, we allow (at least) this number of packets
+ * to be transmitted to FW for a STA in PS-mode. Only when packets are
+ * present in the FW buffers it will wake the sleeping STA. We want to put
+ * enough packets for the driver to transmit all of its buffered data before
+ * the STA goes to sleep again. But we don't want to take too much memory
+ * as it might hurt the throughput of active STAs.
+ */
+#define WL1271_PS_STA_MAX_PACKETS  2
+
+#define WL1271_AP_BSS_INDEX        0
+#define WL1271_AP_DEF_BEACON_EXP   20
+
+#define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE)
+
+enum wl1271_state {
+       WL1271_STATE_OFF,
+       WL1271_STATE_ON,
+};
+
+enum wl12xx_fw_type {
+       WL12XX_FW_TYPE_NONE,
+       WL12XX_FW_TYPE_NORMAL,
+       WL12XX_FW_TYPE_MULTI,
+       WL12XX_FW_TYPE_PLT,
+};
+
+struct wl1271;
+
+enum {
+       FW_VER_CHIP,
+       FW_VER_IF_TYPE,
+       FW_VER_MAJOR,
+       FW_VER_SUBTYPE,
+       FW_VER_MINOR,
+
+       NUM_FW_VER
+};
+
+#define FW_VER_CHIP_WL127X 6
+#define FW_VER_CHIP_WL128X 7
+
+#define FW_VER_IF_TYPE_STA 1
+#define FW_VER_IF_TYPE_AP  2
+
+#define FW_VER_MINOR_1_SPARE_STA_MIN 58
+#define FW_VER_MINOR_1_SPARE_AP_MIN  47
+
+#define FW_VER_MINOR_FWLOG_STA_MIN 70
+
+struct wl1271_chip {
+       u32 id;
+       char fw_ver_str[ETHTOOL_BUSINFO_LEN];
+       unsigned int fw_ver[NUM_FW_VER];
+};
+
+struct wl1271_stats {
+       struct acx_statistics *fw_stats;
+       unsigned long fw_stats_update;
+
+       unsigned int retry_count;
+       unsigned int excessive_retries;
+};
+
+#define NUM_TX_QUEUES              4
+#define NUM_RX_PKT_DESC            8
+
+#define AP_MAX_STATIONS            8
+
+struct wl_fw_packet_counters {
+       /* Cumulative counter of released packets per AC */
+       u8 tx_released_pkts[NUM_TX_QUEUES];
+
+       /* Cumulative counter of freed packets per HLID */
+       u8 tx_lnk_free_pkts[WL12XX_MAX_LINKS];
+
+       /* Cumulative counter of released Voice memory blocks */
+       u8 tx_voice_released_blks;
+
+       u8 padding[3];
+} __packed;
+
+/* FW status registers */
+struct wl_fw_status {
+       __le32 intr;
+       u8  fw_rx_counter;
+       u8  drv_rx_counter;
+       u8  reserved;
+       u8  tx_results_counter;
+       __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
+       __le32 fw_localtime;
+
+       /*
+        * A bitmap (where each bit represents a single HLID)
+        * to indicate if the station is in PS mode.
+        */
+       __le32 link_ps_bitmap;
+
+       /*
+        * A bitmap (where each bit represents a single HLID) to indicate
+        * if the station is in Fast mode
+        */
+       __le32 link_fast_bitmap;
+
+       /* Cumulative counter of total released mem blocks since FW-reset */
+       __le32 total_released_blks;
+
+       /* Size (in Memory Blocks) of TX pool */
+       __le32 tx_total;
+
+       struct wl_fw_packet_counters counters;
+
+       __le32 log_start_addr;
+
+       /* Private status to be used by the lower drivers */
+       u8 priv[0];
+} __packed;
+
+struct wl1271_rx_mem_pool_addr {
+       u32 addr;
+       u32 addr_extra;
+};
+
+#define WL1271_MAX_CHANNELS 64
+struct wl1271_scan {
+       struct cfg80211_scan_request *req;
+       unsigned long scanned_ch[BITS_TO_LONGS(WL1271_MAX_CHANNELS)];
+       bool failed;
+       u8 state;
+       u8 ssid[IEEE80211_MAX_SSID_LEN+1];
+       size_t ssid_len;
+};
+
+struct wl1271_if_operations {
+       void (*read)(struct device *child, int addr, void *buf, size_t len,
+                    bool fixed);
+       void (*write)(struct device *child, int addr, void *buf, size_t len,
+                    bool fixed);
+       void (*reset)(struct device *child);
+       void (*init)(struct device *child);
+       int (*power)(struct device *child, bool enable);
+       void (*set_block_size) (struct device *child, unsigned int blksz);
+};
+
+#define MAX_NUM_KEYS 14
+#define MAX_KEY_SIZE 32
+
+struct wl1271_ap_key {
+       u8 id;
+       u8 key_type;
+       u8 key_size;
+       u8 key[MAX_KEY_SIZE];
+       u8 hlid;
+       u32 tx_seq_32;
+       u16 tx_seq_16;
+};
+
+enum wl12xx_flags {
+       WL1271_FLAG_GPIO_POWER,
+       WL1271_FLAG_TX_QUEUE_STOPPED,
+       WL1271_FLAG_TX_PENDING,
+       WL1271_FLAG_IN_ELP,
+       WL1271_FLAG_ELP_REQUESTED,
+       WL1271_FLAG_IRQ_RUNNING,
+       WL1271_FLAG_FW_TX_BUSY,
+       WL1271_FLAG_DUMMY_PACKET_PENDING,
+       WL1271_FLAG_SUSPENDED,
+       WL1271_FLAG_PENDING_WORK,
+       WL1271_FLAG_SOFT_GEMINI,
+       WL1271_FLAG_RECOVERY_IN_PROGRESS,
+       WL1271_FLAG_VIF_CHANGE_IN_PROGRESS,
+       WL1271_FLAG_INTENDED_FW_RECOVERY,
+};
+
+enum wl12xx_vif_flags {
+       WLVIF_FLAG_INITIALIZED,
+       WLVIF_FLAG_STA_ASSOCIATED,
+       WLVIF_FLAG_STA_AUTHORIZED,
+       WLVIF_FLAG_IBSS_JOINED,
+       WLVIF_FLAG_AP_STARTED,
+       WLVIF_FLAG_IN_PS,
+       WLVIF_FLAG_STA_STATE_SENT,
+       WLVIF_FLAG_RX_STREAMING_STARTED,
+       WLVIF_FLAG_PSPOLL_FAILURE,
+       WLVIF_FLAG_CS_PROGRESS,
+       WLVIF_FLAG_AP_PROBE_RESP_SET,
+       WLVIF_FLAG_IN_USE,
+};
+
+struct wl1271_link {
+       /* AP-mode - TX queue per AC in link */
+       struct sk_buff_head tx_queue[NUM_TX_QUEUES];
+
+       /* accounting for allocated / freed packets in FW */
+       u8 allocated_pkts;
+       u8 prev_freed_pkts;
+
+       u8 addr[ETH_ALEN];
+
+       /* bitmap of TIDs where RX BA sessions are active for this link */
+       u8 ba_bitmap;
+};
+
+struct wl1271_station {
+       u8 hlid;
+};
+
+struct wl12xx_vif {
+       struct wl1271 *wl;
+       struct list_head list;
+       unsigned long flags;
+       u8 bss_type;
+       u8 p2p; /* we are using p2p role */
+       u8 role_id;
+
+       /* sta/ibss specific */
+       u8 dev_role_id;
+       u8 dev_hlid;
+
+       union {
+               struct {
+                       u8 hlid;
+                       u8 ba_rx_bitmap;
+
+                       u8 basic_rate_idx;
+                       u8 ap_rate_idx;
+                       u8 p2p_rate_idx;
+
+                       bool qos;
+               } sta;
+               struct {
+                       u8 global_hlid;
+                       u8 bcast_hlid;
+
+                       /* HLIDs bitmap of associated stations */
+                       unsigned long sta_hlid_map[BITS_TO_LONGS(
+                                                       WL12XX_MAX_LINKS)];
+
+                       /* recoreded keys - set here before AP startup */
+                       struct wl1271_ap_key *recorded_keys[MAX_NUM_KEYS];
+
+                       u8 mgmt_rate_idx;
+                       u8 bcast_rate_idx;
+                       u8 ucast_rate_idx[CONF_TX_MAX_AC_COUNT];
+               } ap;
+       };
+
+       /* the hlid of the last transmitted skb */
+       int last_tx_hlid;
+
+       unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
+
+       u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
+       u8 ssid_len;
+
+       /* The current band */
+       enum ieee80211_band band;
+       int channel;
+
+       u32 bitrate_masks[IEEE80211_NUM_BANDS];
+       u32 basic_rate_set;
+
+       /*
+        * currently configured rate set:
+        *      bits  0-15 - 802.11abg rates
+        *      bits 16-23 - 802.11n   MCS index mask
+        * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
+        */
+       u32 basic_rate;
+       u32 rate_set;
+
+       /* probe-req template for the current AP */
+       struct sk_buff *probereq;
+
+       /* Beaconing interval (needed for ad-hoc) */
+       u32 beacon_int;
+
+       /* Default key (for WEP) */
+       u32 default_key;
+
+       /* Our association ID */
+       u16 aid;
+
+       /* Session counter for the chipset */
+       int session_counter;
+
+       /* retry counter for PSM entries */
+       u8 psm_entry_retry;
+
+       /* in dBm */
+       int power_level;
+
+       int rssi_thold;
+       int last_rssi_event;
+
+       /* save the current encryption type for auto-arp config */
+       u8 encryption_type;
+       __be32 ip_addr;
+
+       /* RX BA constraint value */
+       bool ba_support;
+       bool ba_allowed;
+
+       /* Rx Streaming */
+       struct work_struct rx_streaming_enable_work;
+       struct work_struct rx_streaming_disable_work;
+       struct timer_list rx_streaming_timer;
+
+       /* does the current role use GEM for encryption (AP or STA) */
+       bool is_gem;
+
+       /*
+        * This struct must be last!
+        * data that has to be saved acrossed reconfigs (e.g. recovery)
+        * should be declared in this struct.
+        */
+       struct {
+               u8 persistent[0];
+               /*
+                * Security sequence number
+                *     bits 0-15: lower 16 bits part of sequence number
+                *     bits 16-47: higher 32 bits part of sequence number
+                *     bits 48-63: not in use
+                */
+               u64 tx_security_seq;
+
+               /* 8 bits of the last sequence number in use */
+               u8 tx_security_last_seq_lsb;
+       };
+};
+
+static inline struct wl12xx_vif *wl12xx_vif_to_data(struct ieee80211_vif *vif)
+{
+       return (struct wl12xx_vif *)vif->drv_priv;
+}
+
+static inline
+struct ieee80211_vif *wl12xx_wlvif_to_vif(struct wl12xx_vif *wlvif)
+{
+       return container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
+}
+
+#define wl12xx_for_each_wlvif(wl, wlvif) \
+               list_for_each_entry(wlvif, &wl->wlvif_list, list)
+
+#define wl12xx_for_each_wlvif_continue(wl, wlvif) \
+               list_for_each_entry_continue(wlvif, &wl->wlvif_list, list)
+
+#define wl12xx_for_each_wlvif_bss_type(wl, wlvif, _bss_type)   \
+               wl12xx_for_each_wlvif(wl, wlvif)                \
+                       if (wlvif->bss_type == _bss_type)
+
+#define wl12xx_for_each_wlvif_sta(wl, wlvif)   \
+               wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_STA_BSS)
+
+#define wl12xx_for_each_wlvif_ap(wl, wlvif)    \
+               wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_AP_BSS)
+
+int wl1271_plt_start(struct wl1271 *wl);
+int wl1271_plt_stop(struct wl1271 *wl);
+int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+void wl12xx_queue_recovery_work(struct wl1271 *wl);
+size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen);
+
+#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
+
+#define SESSION_COUNTER_MAX 6 /* maximum value for the session counter */
+#define SESSION_COUNTER_INVALID 7 /* used with dummy_packet */
+
+#define WL1271_DEFAULT_POWER_LEVEL 0
+
+#define WL1271_TX_QUEUE_LOW_WATERMARK  32
+#define WL1271_TX_QUEUE_HIGH_WATERMARK 256
+
+#define WL1271_DEFERRED_QUEUE_LIMIT    64
+
+/* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
+   on in case is has been shut down shortly before */
+#define WL1271_PRE_POWER_ON_SLEEP 20 /* in milliseconds */
+#define WL1271_POWER_ON_SLEEP 200 /* in milliseconds */
+
+/* Macros to handle wl1271.sta_rate_set */
+#define HW_BG_RATES_MASK       0xffff
+#define HW_HT_RATES_OFFSET     16
+
+#define WL12XX_HW_BLOCK_SIZE   256
+
+#endif
diff --git a/drivers/net/wireless/ti/wlcore/wl12xx_80211.h b/drivers/net/wireless/ti/wlcore/wl12xx_80211.h
new file mode 100644 (file)
index 0000000..22b0bc9
--- /dev/null
@@ -0,0 +1,137 @@
+#ifndef __WL12XX_80211_H__
+#define __WL12XX_80211_H__
+
+#include <linux/if_ether.h>    /* ETH_ALEN */
+#include <linux/if_arp.h>
+
+/* RATES */
+#define IEEE80211_CCK_RATE_1MB                 0x02
+#define IEEE80211_CCK_RATE_2MB                 0x04
+#define IEEE80211_CCK_RATE_5MB                 0x0B
+#define IEEE80211_CCK_RATE_11MB                        0x16
+#define IEEE80211_OFDM_RATE_6MB                        0x0C
+#define IEEE80211_OFDM_RATE_9MB                        0x12
+#define IEEE80211_OFDM_RATE_12MB               0x18
+#define IEEE80211_OFDM_RATE_18MB               0x24
+#define IEEE80211_OFDM_RATE_24MB               0x30
+#define IEEE80211_OFDM_RATE_36MB               0x48
+#define IEEE80211_OFDM_RATE_48MB               0x60
+#define IEEE80211_OFDM_RATE_54MB               0x6C
+#define IEEE80211_BASIC_RATE_MASK              0x80
+
+#define IEEE80211_CCK_RATE_1MB_MASK            (1<<0)
+#define IEEE80211_CCK_RATE_2MB_MASK            (1<<1)
+#define IEEE80211_CCK_RATE_5MB_MASK            (1<<2)
+#define IEEE80211_CCK_RATE_11MB_MASK           (1<<3)
+#define IEEE80211_OFDM_RATE_6MB_MASK           (1<<4)
+#define IEEE80211_OFDM_RATE_9MB_MASK           (1<<5)
+#define IEEE80211_OFDM_RATE_12MB_MASK          (1<<6)
+#define IEEE80211_OFDM_RATE_18MB_MASK          (1<<7)
+#define IEEE80211_OFDM_RATE_24MB_MASK          (1<<8)
+#define IEEE80211_OFDM_RATE_36MB_MASK          (1<<9)
+#define IEEE80211_OFDM_RATE_48MB_MASK          (1<<10)
+#define IEEE80211_OFDM_RATE_54MB_MASK          (1<<11)
+
+#define IEEE80211_CCK_RATES_MASK         0x0000000F
+#define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
+       IEEE80211_CCK_RATE_2MB_MASK)
+#define IEEE80211_CCK_DEFAULT_RATES_MASK (IEEE80211_CCK_BASIC_RATES_MASK | \
+       IEEE80211_CCK_RATE_5MB_MASK | \
+       IEEE80211_CCK_RATE_11MB_MASK)
+
+#define IEEE80211_OFDM_RATES_MASK        0x00000FF0
+#define IEEE80211_OFDM_BASIC_RATES_MASK          (IEEE80211_OFDM_RATE_6MB_MASK | \
+       IEEE80211_OFDM_RATE_12MB_MASK | \
+       IEEE80211_OFDM_RATE_24MB_MASK)
+#define IEEE80211_OFDM_DEFAULT_RATES_MASK (IEEE80211_OFDM_BASIC_RATES_MASK | \
+       IEEE80211_OFDM_RATE_9MB_MASK  | \
+       IEEE80211_OFDM_RATE_18MB_MASK | \
+       IEEE80211_OFDM_RATE_36MB_MASK | \
+       IEEE80211_OFDM_RATE_48MB_MASK | \
+       IEEE80211_OFDM_RATE_54MB_MASK)
+#define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
+                                     IEEE80211_CCK_DEFAULT_RATES_MASK)
+
+
+/* This really should be 8, but not for our firmware */
+#define MAX_SUPPORTED_RATES 32
+#define MAX_COUNTRY_TRIPLETS 32
+
+/* Headers */
+struct ieee80211_header {
+       __le16 frame_ctl;
+       __le16 duration_id;
+       u8 da[ETH_ALEN];
+       u8 sa[ETH_ALEN];
+       u8 bssid[ETH_ALEN];
+       __le16 seq_ctl;
+       u8 payload[0];
+} __packed;
+
+struct wl12xx_ie_header {
+       u8 id;
+       u8 len;
+} __packed;
+
+/* IEs */
+
+struct wl12xx_ie_ssid {
+       struct wl12xx_ie_header header;
+       char ssid[IEEE80211_MAX_SSID_LEN];
+} __packed;
+
+struct wl12xx_ie_rates {
+       struct wl12xx_ie_header header;
+       u8 rates[MAX_SUPPORTED_RATES];
+} __packed;
+
+struct wl12xx_ie_ds_params {
+       struct wl12xx_ie_header header;
+       u8 channel;
+} __packed;
+
+struct country_triplet {
+       u8 channel;
+       u8 num_channels;
+       u8 max_tx_power;
+} __packed;
+
+struct wl12xx_ie_country {
+       struct wl12xx_ie_header header;
+       u8 country_string[IEEE80211_COUNTRY_STRING_LEN];
+       struct country_triplet triplets[MAX_COUNTRY_TRIPLETS];
+} __packed;
+
+
+/* Templates */
+
+struct wl12xx_null_data_template {
+       struct ieee80211_header header;
+} __packed;
+
+struct wl12xx_ps_poll_template {
+       __le16 fc;
+       __le16 aid;
+       u8 bssid[ETH_ALEN];
+       u8 ta[ETH_ALEN];
+} __packed;
+
+struct wl12xx_arp_rsp_template {
+       /* not including ieee80211 header */
+
+       u8 llc_hdr[sizeof(rfc1042_header)];
+       __be16 llc_type;
+
+       struct arphdr arp_hdr;
+       u8 sender_hw[ETH_ALEN];
+       __be32 sender_ip;
+       u8 target_hw[ETH_ALEN];
+       __be32 target_ip;
+} __packed;
+
+struct wl12xx_disconn_template {
+       struct ieee80211_header header;
+       __le16 disconn_reason;
+} __packed;
+
+#endif
diff --git a/drivers/net/wireless/ti/wlcore/wl12xx_platform_data.c b/drivers/net/wireless/ti/wlcore/wl12xx_platform_data.c
new file mode 100644 (file)
index 0000000..998e958
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * This file is part of wl12xx
+ *
+ * Copyright (C) 2010-2011 Texas Instruments, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/wl12xx.h>
+
+static struct wl12xx_platform_data *platform_data;
+
+int __init wl12xx_set_platform_data(const struct wl12xx_platform_data *data)
+{
+       if (platform_data)
+               return -EBUSY;
+       if (!data)
+               return -EINVAL;
+
+       platform_data = kmemdup(data, sizeof(*data), GFP_KERNEL);
+       if (!platform_data)
+               return -ENOMEM;
+
+       return 0;
+}
+
+struct wl12xx_platform_data *wl12xx_get_platform_data(void)
+{
+       if (!platform_data)
+               return ERR_PTR(-ENODEV);
+
+       return platform_data;
+}
+EXPORT_SYMBOL(wl12xx_get_platform_data);
diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
new file mode 100644 (file)
index 0000000..39f9fad
--- /dev/null
@@ -0,0 +1,448 @@
+/*
+ * This file is part of wlcore
+ *
+ * Copyright (C) 2011 Texas Instruments Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __WLCORE_H__
+#define __WLCORE_H__
+
+#include <linux/platform_device.h>
+
+#include "wl12xx.h"
+#include "event.h"
+
+/* The maximum number of Tx descriptors in all chip families */
+#define WLCORE_MAX_TX_DESCRIPTORS 32
+
+/* forward declaration */
+struct wl1271_tx_hw_descr;
+enum wl_rx_buf_align;
+
+struct wlcore_ops {
+       int (*identify_chip)(struct wl1271 *wl);
+       int (*identify_fw)(struct wl1271 *wl);
+       int (*boot)(struct wl1271 *wl);
+       void (*trigger_cmd)(struct wl1271 *wl, int cmd_box_addr,
+                           void *buf, size_t len);
+       void (*ack_event)(struct wl1271 *wl);
+       u32 (*calc_tx_blocks)(struct wl1271 *wl, u32 len, u32 spare_blks);
+       void (*set_tx_desc_blocks)(struct wl1271 *wl,
+                                  struct wl1271_tx_hw_descr *desc,
+                                  u32 blks, u32 spare_blks);
+       void (*set_tx_desc_data_len)(struct wl1271 *wl,
+                                    struct wl1271_tx_hw_descr *desc,
+                                    struct sk_buff *skb);
+       enum wl_rx_buf_align (*get_rx_buf_align)(struct wl1271 *wl,
+                                                u32 rx_desc);
+       void (*prepare_read)(struct wl1271 *wl, u32 rx_desc, u32 len);
+       u32 (*get_rx_packet_len)(struct wl1271 *wl, void *rx_data,
+                                u32 data_len);
+       void (*tx_delayed_compl)(struct wl1271 *wl);
+       void (*tx_immediate_compl)(struct wl1271 *wl);
+       int (*hw_init)(struct wl1271 *wl);
+       int (*init_vif)(struct wl1271 *wl, struct wl12xx_vif *wlvif);
+       u32 (*sta_get_ap_rate_mask)(struct wl1271 *wl,
+                                   struct wl12xx_vif *wlvif);
+       s8 (*get_pg_ver)(struct wl1271 *wl);
+       void (*get_mac)(struct wl1271 *wl);
+};
+
+enum wlcore_partitions {
+       PART_DOWN,
+       PART_WORK,
+       PART_BOOT,
+       PART_DRPW,
+       PART_TOP_PRCM_ELP_SOC,
+       PART_PHY_INIT,
+
+       PART_TABLE_LEN,
+};
+
+struct wlcore_partition {
+       u32 size;
+       u32 start;
+};
+
+struct wlcore_partition_set {
+       struct wlcore_partition mem;
+       struct wlcore_partition reg;
+       struct wlcore_partition mem2;
+       struct wlcore_partition mem3;
+};
+
+enum wlcore_registers {
+       /* register addresses, used with partition translation */
+       REG_ECPU_CONTROL,
+       REG_INTERRUPT_NO_CLEAR,
+       REG_INTERRUPT_ACK,
+       REG_COMMAND_MAILBOX_PTR,
+       REG_EVENT_MAILBOX_PTR,
+       REG_INTERRUPT_TRIG,
+       REG_INTERRUPT_MASK,
+       REG_PC_ON_RECOVERY,
+       REG_CHIP_ID_B,
+       REG_CMD_MBOX_ADDRESS,
+
+       /* data access memory addresses, used with partition translation */
+       REG_SLV_MEM_DATA,
+       REG_SLV_REG_DATA,
+
+       /* raw data access memory addresses */
+       REG_RAW_FW_STATUS_ADDR,
+
+       REG_TABLE_LEN,
+};
+
+struct wl1271 {
+       struct ieee80211_hw *hw;
+       bool mac80211_registered;
+
+       struct device *dev;
+
+       void *if_priv;
+
+       struct wl1271_if_operations *if_ops;
+
+       void (*set_power)(bool enable);
+       int irq;
+       int ref_clock;
+
+       spinlock_t wl_lock;
+
+       enum wl1271_state state;
+       enum wl12xx_fw_type fw_type;
+       bool plt;
+       u8 last_vif_count;
+       struct mutex mutex;
+
+       unsigned long flags;
+
+       struct wlcore_partition_set curr_part;
+
+       struct wl1271_chip chip;
+
+       int cmd_box_addr;
+
+       u8 *fw;
+       size_t fw_len;
+       void *nvs;
+       size_t nvs_len;
+
+       s8 hw_pg_ver;
+
+       /* address read from the fuse ROM */
+       u32 fuse_oui_addr;
+       u32 fuse_nic_addr;
+
+       /* we have up to 2 MAC addresses */
+       struct mac_address addresses[2];
+       int channel;
+       u8 system_hlid;
+
+       unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
+       unsigned long roles_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
+       unsigned long roc_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
+       unsigned long rate_policies_map[
+                       BITS_TO_LONGS(WL12XX_MAX_RATE_POLICIES)];
+
+       struct list_head wlvif_list;
+
+       u8 sta_count;
+       u8 ap_count;
+
+       struct wl1271_acx_mem_map *target_mem_map;
+
+       /* Accounting for allocated / available TX blocks on HW */
+       u32 tx_blocks_freed;
+       u32 tx_blocks_available;
+       u32 tx_allocated_blocks;
+       u32 tx_results_count;
+
+       /* Accounting for allocated / available Tx packets in HW */
+       u32 tx_pkts_freed[NUM_TX_QUEUES];
+       u32 tx_allocated_pkts[NUM_TX_QUEUES];
+
+       /* Transmitted TX packets counter for chipset interface */
+       u32 tx_packets_count;
+
+       /* Time-offset between host and chipset clocks */
+       s64 time_offset;
+
+       /* Frames scheduled for transmission, not handled yet */
+       int tx_queue_count[NUM_TX_QUEUES];
+       long stopped_queues_map;
+
+       /* Frames received, not handled yet by mac80211 */
+       struct sk_buff_head deferred_rx_queue;
+
+       /* Frames sent, not returned yet to mac80211 */
+       struct sk_buff_head deferred_tx_queue;
+
+       struct work_struct tx_work;
+       struct workqueue_struct *freezable_wq;
+
+       /* Pending TX frames */
+       unsigned long tx_frames_map[BITS_TO_LONGS(WLCORE_MAX_TX_DESCRIPTORS)];
+       struct sk_buff *tx_frames[WLCORE_MAX_TX_DESCRIPTORS];
+       int tx_frames_cnt;
+
+       /* FW Rx counter */
+       u32 rx_counter;
+
+       /* Rx memory pool address */
+       struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
+
+       /* Intermediate buffer, used for packet aggregation */
+       u8 *aggr_buf;
+
+       /* Reusable dummy packet template */
+       struct sk_buff *dummy_packet;
+
+       /* Network stack work  */
+       struct work_struct netstack_work;
+
+       /* FW log buffer */
+       u8 *fwlog;
+
+       /* Number of valid bytes in the FW log buffer */
+       ssize_t fwlog_size;
+
+       /* Sysfs FW log entry readers wait queue */
+       wait_queue_head_t fwlog_waitq;
+
+       /* Hardware recovery work */
+       struct work_struct recovery_work;
+
+       /* Pointer that holds DMA-friendly block for the mailbox */
+       struct event_mailbox *mbox;
+
+       /* The mbox event mask */
+       u32 event_mask;
+
+       /* Mailbox pointers */
+       u32 mbox_ptr[2];
+
+       /* Are we currently scanning */
+       struct ieee80211_vif *scan_vif;
+       struct wl1271_scan scan;
+       struct delayed_work scan_complete_work;
+
+       bool sched_scanning;
+
+       /* The current band */
+       enum ieee80211_band band;
+
+       struct completion *elp_compl;
+       struct delayed_work elp_work;
+
+       /* in dBm */
+       int power_level;
+
+       struct wl1271_stats stats;
+
+       __le32 buffer_32;
+       u32 buffer_cmd;
+       u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
+
+       struct wl_fw_status *fw_status;
+       struct wl1271_tx_hw_res_if *tx_res_if;
+
+       /* Current chipset configuration */
+       struct wlcore_conf conf;
+
+       bool sg_enabled;
+
+       bool enable_11a;
+
+       /* Most recently reported noise in dBm */
+       s8 noise;
+
+       /* bands supported by this instance of wl12xx */
+       struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
+
+       int tcxo_clock;
+
+       /*
+        * wowlan trigger was configured during suspend.
+        * (currently, only "ANY" trigger is supported)
+        */
+       bool wow_enabled;
+       bool irq_wake_enabled;
+
+       /*
+        * AP-mode - links indexed by HLID. The global and broadcast links
+        * are always active.
+        */
+       struct wl1271_link links[WL12XX_MAX_LINKS];
+
+       /* AP-mode - a bitmap of links currently in PS mode according to FW */
+       u32 ap_fw_ps_map;
+
+       /* AP-mode - a bitmap of links currently in PS mode in mac80211 */
+       unsigned long ap_ps_map;
+
+       /* Quirks of specific hardware revisions */
+       unsigned int quirks;
+
+       /* Platform limitations */
+       unsigned int platform_quirks;
+
+       /* number of currently active RX BA sessions */
+       int ba_rx_session_count;
+
+       /* AP-mode - number of currently connected stations */
+       int active_sta_count;
+
+       /* last wlvif we transmitted from */
+       struct wl12xx_vif *last_wlvif;
+
+       /* work to fire when Tx is stuck */
+       struct delayed_work tx_watchdog_work;
+
+       struct wlcore_ops *ops;
+       /* pointer to the lower driver partition table */
+       const struct wlcore_partition_set *ptable;
+       /* pointer to the lower driver register table */
+       const int *rtable;
+       /* name of the firmwares to load - for PLT, single role, multi-role */
+       const char *plt_fw_name;
+       const char *sr_fw_name;
+       const char *mr_fw_name;
+
+       /* per-chip-family private structure */
+       void *priv;
+
+       /* number of TX descriptors the HW supports. */
+       u32 num_tx_desc;
+
+       /* spare Tx blocks for normal/GEM operating modes */
+       u32 normal_tx_spare;
+       u32 gem_tx_spare;
+
+       /* translate HW Tx rates to standard rate-indices */
+       const u8 **band_rate_to_idx;
+
+       /* size of table for HW rates that can be received from chip */
+       u8 hw_tx_rate_tbl_size;
+
+       /* this HW rate and below are considered HT rates for this chip */
+       u8 hw_min_ht_rate;
+
+       /* HW HT (11n) capabilities */
+       struct ieee80211_sta_ht_cap ht_cap;
+
+       /* size of the private FW status data */
+       size_t fw_status_priv_len;
+};
+
+int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev);
+int __devexit wlcore_remove(struct platform_device *pdev);
+struct ieee80211_hw *wlcore_alloc_hw(size_t priv_size);
+int wlcore_free_hw(struct wl1271 *wl);
+
+/* Firmware image load chunk size */
+#define CHUNK_SIZE     16384
+
+/* Quirks */
+
+/* Each RX/TX transaction requires an end-of-transaction transfer */
+#define WLCORE_QUIRK_END_OF_TRANSACTION                BIT(0)
+
+/* wl127x and SPI don't support SDIO block size alignment */
+#define WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN                BIT(2)
+
+/* means aggregated Rx packets are aligned to a SDIO block */
+#define WLCORE_QUIRK_RX_BLOCKSIZE_ALIGN                BIT(3)
+
+/* Older firmwares did not implement the FW logger over bus feature */
+#define WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED     BIT(4)
+
+/* Older firmwares use an old NVS format */
+#define WLCORE_QUIRK_LEGACY_NVS                        BIT(5)
+
+/* Some firmwares may not support ELP */
+#define WLCORE_QUIRK_NO_ELP                    BIT(6)
+
+/* TODO: move to the lower drivers when all usages are abstracted */
+#define CHIP_ID_1271_PG10              (0x4030101)
+#define CHIP_ID_1271_PG20              (0x4030111)
+#define CHIP_ID_1283_PG10              (0x05030101)
+#define CHIP_ID_1283_PG20              (0x05030111)
+
+/* TODO: move all these common registers and values elsewhere */
+#define HW_ACCESS_ELP_CTRL_REG         0x1FFFC
+
+/* ELP register commands */
+#define ELPCTRL_WAKE_UP             0x1
+#define ELPCTRL_WAKE_UP_WLAN_READY  0x5
+#define ELPCTRL_SLEEP               0x0
+/* ELP WLAN_READY bit */
+#define ELPCTRL_WLAN_READY          0x2
+
+/*************************************************************************
+
+    Interrupt Trigger Register (Host -> WiLink)
+
+**************************************************************************/
+
+/* Hardware to Embedded CPU Interrupts - first 32-bit register set */
+
+/*
+ * The host sets this bit to inform the Wlan
+ * FW that a TX packet is in the XFER
+ * Buffer #0.
+ */
+#define INTR_TRIG_TX_PROC0 BIT(2)
+
+/*
+ * The host sets this bit to inform the FW
+ * that it read a packet from RX XFER
+ * Buffer #0.
+ */
+#define INTR_TRIG_RX_PROC0 BIT(3)
+
+#define INTR_TRIG_DEBUG_ACK BIT(4)
+
+#define INTR_TRIG_STATE_CHANGED BIT(5)
+
+/* Hardware to Embedded CPU Interrupts - second 32-bit register set */
+
+/*
+ * The host sets this bit to inform the FW
+ * that it read a packet from RX XFER
+ * Buffer #1.
+ */
+#define INTR_TRIG_RX_PROC1 BIT(17)
+
+/*
+ * The host sets this bit to inform the Wlan
+ * hardware that a TX packet is in the XFER
+ * Buffer #1.
+ */
+#define INTR_TRIG_TX_PROC1 BIT(18)
+
+#define ACX_SLV_SOFT_RESET_BIT BIT(1)
+#define SOFT_RESET_MAX_TIME    1000000
+#define SOFT_RESET_STALL_TIME  1000
+
+#define ECPU_CONTROL_HALT      0x00000101
+
+#define WELP_ARM_COMMAND_VAL   0x4
+
+#endif /* __WLCORE_H__ */
diff --git a/drivers/net/wireless/wl1251/Kconfig b/drivers/net/wireless/wl1251/Kconfig
deleted file mode 100644 (file)
index 1fb6584..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-menuconfig WL1251
-       tristate "TI wl1251 driver support"
-       depends on MAC80211 && EXPERIMENTAL && GENERIC_HARDIRQS
-       select FW_LOADER
-       select CRC7
-       ---help---
-         This will enable TI wl1251 driver support. The drivers make
-         use of the mac80211 stack.
-
-         If you choose to build a module, it'll be called wl1251. Say
-         N if unsure.
-
-config WL1251_SPI
-       tristate "TI wl1251 SPI support"
-       depends on WL1251 && SPI_MASTER
-       ---help---
-         This module adds support for the SPI interface of adapters using
-         TI wl1251 chipset.  Select this if your platform is using
-         the SPI bus.
-
-         If you choose to build a module, it'll be called wl1251_spi.
-         Say N if unsure.
-
-config WL1251_SDIO
-       tristate "TI wl1251 SDIO support"
-       depends on WL1251 && MMC
-       ---help---
-         This module adds support for the SDIO interface of adapters using
-         TI wl1251 chipset.  Select this if your platform is using
-         the SDIO bus.
-
-         If you choose to build a module, it'll be called
-         wl1251_sdio. Say N if unsure.
diff --git a/drivers/net/wireless/wl1251/Makefile b/drivers/net/wireless/wl1251/Makefile
deleted file mode 100644 (file)
index a5c6328..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-wl1251-objs            = main.o event.o tx.o rx.o ps.o cmd.o \
-                         acx.o boot.o init.o debugfs.o io.o
-wl1251_spi-objs                += spi.o
-wl1251_sdio-objs       += sdio.o
-
-obj-$(CONFIG_WL1251)           += wl1251.o
-obj-$(CONFIG_WL1251_SPI)       += wl1251_spi.o
-obj-$(CONFIG_WL1251_SDIO)      += wl1251_sdio.o
-
-ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/wl1251/acx.c b/drivers/net/wireless/wl1251/acx.c
deleted file mode 100644 (file)
index ad87a1a..0000000
+++ /dev/null
@@ -1,1097 +0,0 @@
-#include "acx.h"
-
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/crc7.h>
-
-#include "wl1251.h"
-#include "reg.h"
-#include "cmd.h"
-#include "ps.h"
-
-int wl1251_acx_frame_rates(struct wl1251 *wl, u8 ctrl_rate, u8 ctrl_mod,
-                          u8 mgt_rate, u8 mgt_mod)
-{
-       struct acx_fw_gen_frame_rates *rates;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx frame rates");
-
-       rates = kzalloc(sizeof(*rates), GFP_KERNEL);
-       if (!rates) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       rates->tx_ctrl_frame_rate = ctrl_rate;
-       rates->tx_ctrl_frame_mod = ctrl_mod;
-       rates->tx_mgt_frame_rate = mgt_rate;
-       rates->tx_mgt_frame_mod = mgt_mod;
-
-       ret = wl1251_cmd_configure(wl, ACX_FW_GEN_FRAME_RATES,
-                                  rates, sizeof(*rates));
-       if (ret < 0) {
-               wl1251_error("Failed to set FW rates and modulation");
-               goto out;
-       }
-
-out:
-       kfree(rates);
-       return ret;
-}
-
-
-int wl1251_acx_station_id(struct wl1251 *wl)
-{
-       struct acx_dot11_station_id *mac;
-       int ret, i;
-
-       wl1251_debug(DEBUG_ACX, "acx dot11_station_id");
-
-       mac = kzalloc(sizeof(*mac), GFP_KERNEL);
-       if (!mac) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       for (i = 0; i < ETH_ALEN; i++)
-               mac->mac[i] = wl->mac_addr[ETH_ALEN - 1 - i];
-
-       ret = wl1251_cmd_configure(wl, DOT11_STATION_ID, mac, sizeof(*mac));
-       if (ret < 0)
-               goto out;
-
-out:
-       kfree(mac);
-       return ret;
-}
-
-int wl1251_acx_default_key(struct wl1251 *wl, u8 key_id)
-{
-       struct acx_dot11_default_key *default_key;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx dot11_default_key (%d)", key_id);
-
-       default_key = kzalloc(sizeof(*default_key), GFP_KERNEL);
-       if (!default_key) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       default_key->id = key_id;
-
-       ret = wl1251_cmd_configure(wl, DOT11_DEFAULT_KEY,
-                                  default_key, sizeof(*default_key));
-       if (ret < 0) {
-               wl1251_error("Couldn't set default key");
-               goto out;
-       }
-
-       wl->default_key = key_id;
-
-out:
-       kfree(default_key);
-       return ret;
-}
-
-int wl1251_acx_wake_up_conditions(struct wl1251 *wl, u8 wake_up_event,
-                                 u8 listen_interval)
-{
-       struct acx_wake_up_condition *wake_up;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx wake up conditions");
-
-       wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
-       if (!wake_up) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wake_up->wake_up_event = wake_up_event;
-       wake_up->listen_interval = listen_interval;
-
-       ret = wl1251_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
-                                  wake_up, sizeof(*wake_up));
-       if (ret < 0) {
-               wl1251_warning("could not set wake up conditions: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(wake_up);
-       return ret;
-}
-
-int wl1251_acx_sleep_auth(struct wl1251 *wl, u8 sleep_auth)
-{
-       struct acx_sleep_auth *auth;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx sleep auth");
-
-       auth = kzalloc(sizeof(*auth), GFP_KERNEL);
-       if (!auth) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       auth->sleep_auth = sleep_auth;
-
-       ret = wl1251_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
-
-out:
-       kfree(auth);
-       return ret;
-}
-
-int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len)
-{
-       struct acx_revision *rev;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx fw rev");
-
-       rev = kzalloc(sizeof(*rev), GFP_KERNEL);
-       if (!rev) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       ret = wl1251_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
-       if (ret < 0) {
-               wl1251_warning("ACX_FW_REV interrogate failed");
-               goto out;
-       }
-
-       /* be careful with the buffer sizes */
-       strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
-
-       /*
-        * if the firmware version string is exactly
-        * sizeof(rev->fw_version) long or fw_len is less than
-        * sizeof(rev->fw_version) it won't be null terminated
-        */
-       buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
-
-out:
-       kfree(rev);
-       return ret;
-}
-
-int wl1251_acx_tx_power(struct wl1251 *wl, int power)
-{
-       struct acx_current_tx_power *acx;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
-
-       if (power < 0 || power > 25)
-               return -EINVAL;
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->current_tx_power = power * 10;
-
-       ret = wl1251_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1251_warning("configure of tx power failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1251_acx_feature_cfg(struct wl1251 *wl)
-{
-       struct acx_feature_config *feature;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx feature cfg");
-
-       feature = kzalloc(sizeof(*feature), GFP_KERNEL);
-       if (!feature) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
-       feature->data_flow_options = 0;
-       feature->options = 0;
-
-       ret = wl1251_cmd_configure(wl, ACX_FEATURE_CFG,
-                                  feature, sizeof(*feature));
-       if (ret < 0) {
-               wl1251_error("Couldn't set HW encryption");
-               goto out;
-       }
-
-out:
-       kfree(feature);
-       return ret;
-}
-
-int wl1251_acx_mem_map(struct wl1251 *wl, struct acx_header *mem_map,
-                      size_t len)
-{
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx mem map");
-
-       ret = wl1251_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1251_acx_data_path_params(struct wl1251 *wl,
-                               struct acx_data_path_params_resp *resp)
-{
-       struct acx_data_path_params *params;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx data path params");
-
-       params = kzalloc(sizeof(*params), GFP_KERNEL);
-       if (!params) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       params->rx_packet_ring_chunk_size = DP_RX_PACKET_RING_CHUNK_SIZE;
-       params->tx_packet_ring_chunk_size = DP_TX_PACKET_RING_CHUNK_SIZE;
-
-       params->rx_packet_ring_chunk_num = DP_RX_PACKET_RING_CHUNK_NUM;
-       params->tx_packet_ring_chunk_num = DP_TX_PACKET_RING_CHUNK_NUM;
-
-       params->tx_complete_threshold = 1;
-
-       params->tx_complete_ring_depth = FW_TX_CMPLT_BLOCK_SIZE;
-
-       params->tx_complete_timeout = DP_TX_COMPLETE_TIME_OUT;
-
-       ret = wl1251_cmd_configure(wl, ACX_DATA_PATH_PARAMS,
-                                  params, sizeof(*params));
-       if (ret < 0)
-               goto out;
-
-       /* FIXME: shouldn't this be ACX_DATA_PATH_RESP_PARAMS? */
-       ret = wl1251_cmd_interrogate(wl, ACX_DATA_PATH_PARAMS,
-                                    resp, sizeof(*resp));
-
-       if (ret < 0) {
-               wl1251_warning("failed to read data path parameters: %d", ret);
-               goto out;
-       } else if (resp->header.cmd.status != CMD_STATUS_SUCCESS) {
-               wl1251_warning("data path parameter acx status failed");
-               ret = -EIO;
-               goto out;
-       }
-
-out:
-       kfree(params);
-       return ret;
-}
-
-int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time)
-{
-       struct acx_rx_msdu_lifetime *acx;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx rx msdu life time");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->lifetime = life_time;
-       ret = wl1251_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
-                                  acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1251_warning("failed to set rx msdu life time: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter)
-{
-       struct acx_rx_config *rx_config;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx rx config");
-
-       rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
-       if (!rx_config) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       rx_config->config_options = config;
-       rx_config->filter_options = filter;
-
-       ret = wl1251_cmd_configure(wl, ACX_RX_CFG,
-                                  rx_config, sizeof(*rx_config));
-       if (ret < 0) {
-               wl1251_warning("failed to set rx config: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(rx_config);
-       return ret;
-}
-
-int wl1251_acx_pd_threshold(struct wl1251 *wl)
-{
-       struct acx_packet_detection *pd;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx data pd threshold");
-
-       pd = kzalloc(sizeof(*pd), GFP_KERNEL);
-       if (!pd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* FIXME: threshold value not set */
-
-       ret = wl1251_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
-       if (ret < 0) {
-               wl1251_warning("failed to set pd threshold: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(pd);
-       return ret;
-}
-
-int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time)
-{
-       struct acx_slot *slot;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx slot");
-
-       slot = kzalloc(sizeof(*slot), GFP_KERNEL);
-       if (!slot) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       slot->wone_index = STATION_WONE_INDEX;
-       slot->slot_time = slot_time;
-
-       ret = wl1251_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
-       if (ret < 0) {
-               wl1251_warning("failed to set slot time: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(slot);
-       return ret;
-}
-
-int wl1251_acx_group_address_tbl(struct wl1251 *wl)
-{
-       struct acx_dot11_grp_addr_tbl *acx;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx group address tbl");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* MAC filtering */
-       acx->enabled = 0;
-       acx->num_groups = 0;
-       memset(acx->mac_table, 0, ADDRESS_GROUP_MAX_LEN);
-
-       ret = wl1251_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
-                                  acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1251_warning("failed to set group addr table: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1251_acx_service_period_timeout(struct wl1251 *wl)
-{
-       struct acx_rx_timeout *rx_timeout;
-       int ret;
-
-       rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
-       if (!rx_timeout) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wl1251_debug(DEBUG_ACX, "acx service period timeout");
-
-       rx_timeout->ps_poll_timeout = RX_TIMEOUT_PS_POLL_DEF;
-       rx_timeout->upsd_timeout = RX_TIMEOUT_UPSD_DEF;
-
-       ret = wl1251_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
-                                  rx_timeout, sizeof(*rx_timeout));
-       if (ret < 0) {
-               wl1251_warning("failed to set service period timeout: %d",
-                              ret);
-               goto out;
-       }
-
-out:
-       kfree(rx_timeout);
-       return ret;
-}
-
-int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold)
-{
-       struct acx_rts_threshold *rts;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx rts threshold");
-
-       rts = kzalloc(sizeof(*rts), GFP_KERNEL);
-       if (!rts) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       rts->threshold = rts_threshold;
-
-       ret = wl1251_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
-       if (ret < 0) {
-               wl1251_warning("failed to set rts threshold: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(rts);
-       return ret;
-}
-
-int wl1251_acx_beacon_filter_opt(struct wl1251 *wl, bool enable_filter)
-{
-       struct acx_beacon_filter_option *beacon_filter;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx beacon filter opt");
-
-       beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
-       if (!beacon_filter) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       beacon_filter->enable = enable_filter;
-       beacon_filter->max_num_beacons = 0;
-
-       ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
-                                  beacon_filter, sizeof(*beacon_filter));
-       if (ret < 0) {
-               wl1251_warning("failed to set beacon filter opt: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(beacon_filter);
-       return ret;
-}
-
-int wl1251_acx_beacon_filter_table(struct wl1251 *wl)
-{
-       struct acx_beacon_filter_ie_table *ie_table;
-       int idx = 0;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx beacon filter table");
-
-       ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
-       if (!ie_table) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* configure default beacon pass-through rules */
-       ie_table->num_ie = 1;
-       ie_table->table[idx++] = BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN;
-       ie_table->table[idx++] = BEACON_RULE_PASS_ON_APPEARANCE;
-
-       ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
-                                  ie_table, sizeof(*ie_table));
-       if (ret < 0) {
-               wl1251_warning("failed to set beacon filter table: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(ie_table);
-       return ret;
-}
-
-int wl1251_acx_conn_monit_params(struct wl1251 *wl)
-{
-       struct acx_conn_monit_params *acx;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx connection monitor parameters");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->synch_fail_thold = SYNCH_FAIL_DEFAULT_THRESHOLD;
-       acx->bss_lose_timeout = NO_BEACON_DEFAULT_TIMEOUT;
-
-       ret = wl1251_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
-                                  acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1251_warning("failed to set connection monitor "
-                              "parameters: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1251_acx_sg_enable(struct wl1251 *wl)
-{
-       struct acx_bt_wlan_coex *pta;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx sg enable");
-
-       pta = kzalloc(sizeof(*pta), GFP_KERNEL);
-       if (!pta) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       pta->enable = SG_ENABLE;
-
-       ret = wl1251_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
-       if (ret < 0) {
-               wl1251_warning("failed to set softgemini enable: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(pta);
-       return ret;
-}
-
-int wl1251_acx_sg_cfg(struct wl1251 *wl)
-{
-       struct acx_bt_wlan_coex_param *param;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx sg cfg");
-
-       param = kzalloc(sizeof(*param), GFP_KERNEL);
-       if (!param) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* BT-WLAN coext parameters */
-       param->min_rate = RATE_INDEX_24MBPS;
-       param->bt_hp_max_time = PTA_BT_HP_MAXTIME_DEF;
-       param->wlan_hp_max_time = PTA_WLAN_HP_MAX_TIME_DEF;
-       param->sense_disable_timer = PTA_SENSE_DISABLE_TIMER_DEF;
-       param->rx_time_bt_hp = PTA_PROTECTIVE_RX_TIME_DEF;
-       param->tx_time_bt_hp = PTA_PROTECTIVE_TX_TIME_DEF;
-       param->rx_time_bt_hp_fast = PTA_PROTECTIVE_RX_TIME_FAST_DEF;
-       param->tx_time_bt_hp_fast = PTA_PROTECTIVE_TX_TIME_FAST_DEF;
-       param->wlan_cycle_fast = PTA_CYCLE_TIME_FAST_DEF;
-       param->bt_anti_starvation_period = PTA_ANTI_STARVE_PERIOD_DEF;
-       param->next_bt_lp_packet = PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF;
-       param->wake_up_beacon = PTA_TIME_BEFORE_BEACON_DEF;
-       param->hp_dm_max_guard_time = PTA_HPDM_MAX_TIME_DEF;
-       param->next_wlan_packet = PTA_TIME_OUT_NEXT_WLAN_DEF;
-       param->antenna_type = PTA_ANTENNA_TYPE_DEF;
-       param->signal_type = PTA_SIGNALING_TYPE_DEF;
-       param->afh_leverage_on = PTA_AFH_LEVERAGE_ON_DEF;
-       param->quiet_cycle_num = PTA_NUMBER_QUIET_CYCLE_DEF;
-       param->max_cts = PTA_MAX_NUM_CTS_DEF;
-       param->wlan_packets_num = PTA_NUMBER_OF_WLAN_PACKETS_DEF;
-       param->bt_packets_num = PTA_NUMBER_OF_BT_PACKETS_DEF;
-       param->missed_rx_avalanche = PTA_RX_FOR_AVALANCHE_DEF;
-       param->wlan_elp_hp = PTA_ELP_HP_DEF;
-       param->bt_anti_starvation_cycles = PTA_ANTI_STARVE_NUM_CYCLE_DEF;
-       param->ack_mode_dual_ant = PTA_ACK_MODE_DEF;
-       param->pa_sd_enable = PTA_ALLOW_PA_SD_DEF;
-       param->pta_auto_mode_enable = PTA_AUTO_MODE_NO_CTS_DEF;
-       param->bt_hp_respected_num = PTA_BT_HP_RESPECTED_DEF;
-
-       ret = wl1251_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
-       if (ret < 0) {
-               wl1251_warning("failed to set sg config: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(param);
-       return ret;
-}
-
-int wl1251_acx_cca_threshold(struct wl1251 *wl)
-{
-       struct acx_energy_detection *detection;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx cca threshold");
-
-       detection = kzalloc(sizeof(*detection), GFP_KERNEL);
-       if (!detection) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       detection->rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D;
-       detection->tx_energy_detection = 0;
-
-       ret = wl1251_cmd_configure(wl, ACX_CCA_THRESHOLD,
-                                  detection, sizeof(*detection));
-       if (ret < 0)
-               wl1251_warning("failed to set cca threshold: %d", ret);
-
-out:
-       kfree(detection);
-       return ret;
-}
-
-int wl1251_acx_bcn_dtim_options(struct wl1251 *wl)
-{
-       struct acx_beacon_broadcast *bb;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx bcn dtim options");
-
-       bb = kzalloc(sizeof(*bb), GFP_KERNEL);
-       if (!bb) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
-       bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
-       bb->rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE;
-       bb->ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF;
-
-       ret = wl1251_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
-       if (ret < 0) {
-               wl1251_warning("failed to set rx config: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(bb);
-       return ret;
-}
-
-int wl1251_acx_aid(struct wl1251 *wl, u16 aid)
-{
-       struct acx_aid *acx_aid;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx aid");
-
-       acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
-       if (!acx_aid) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx_aid->aid = aid;
-
-       ret = wl1251_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
-       if (ret < 0) {
-               wl1251_warning("failed to set aid: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx_aid);
-       return ret;
-}
-
-int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask)
-{
-       struct acx_event_mask *mask;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx event mbox mask");
-
-       mask = kzalloc(sizeof(*mask), GFP_KERNEL);
-       if (!mask) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* high event mask is unused */
-       mask->high_event_mask = 0xffffffff;
-
-       mask->event_mask = event_mask;
-
-       ret = wl1251_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
-                                  mask, sizeof(*mask));
-       if (ret < 0) {
-               wl1251_warning("failed to set acx_event_mbox_mask: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(mask);
-       return ret;
-}
-
-int wl1251_acx_low_rssi(struct wl1251 *wl, s8 threshold, u8 weight,
-                       u8 depth, enum wl1251_acx_low_rssi_type type)
-{
-       struct acx_low_rssi *rssi;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx low rssi");
-
-       rssi = kzalloc(sizeof(*rssi), GFP_KERNEL);
-       if (!rssi)
-               return -ENOMEM;
-
-       rssi->threshold = threshold;
-       rssi->weight = weight;
-       rssi->depth = depth;
-       rssi->type = type;
-
-       ret = wl1251_cmd_configure(wl, ACX_LOW_RSSI, rssi, sizeof(*rssi));
-       if (ret < 0)
-               wl1251_warning("failed to set low rssi threshold: %d", ret);
-
-       kfree(rssi);
-       return ret;
-}
-
-int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble)
-{
-       struct acx_preamble *acx;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx_set_preamble");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->preamble = preamble;
-
-       ret = wl1251_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1251_warning("Setting of preamble failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1251_acx_cts_protect(struct wl1251 *wl,
-                          enum acx_ctsprotect_type ctsprotect)
-{
-       struct acx_ctsprotect *acx;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx_set_ctsprotect");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->ctsprotect = ctsprotect;
-
-       ret = wl1251_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1251_warning("Setting of ctsprotect failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime)
-{
-       struct acx_tsf_info *tsf_info;
-       int ret;
-
-       tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
-       if (!tsf_info) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       ret = wl1251_cmd_interrogate(wl, ACX_TSF_INFO,
-                                    tsf_info, sizeof(*tsf_info));
-       if (ret < 0) {
-               wl1251_warning("ACX_FW_REV interrogate failed");
-               goto out;
-       }
-
-       *mactime = tsf_info->current_tsf_lsb |
-               (tsf_info->current_tsf_msb << 31);
-
-out:
-       kfree(tsf_info);
-       return ret;
-}
-
-int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats)
-{
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx statistics");
-
-       ret = wl1251_cmd_interrogate(wl, ACX_STATISTICS, stats,
-                                    sizeof(*stats));
-       if (ret < 0) {
-               wl1251_warning("acx statistics failed: %d", ret);
-               return -ENOMEM;
-       }
-
-       return 0;
-}
-
-int wl1251_acx_rate_policies(struct wl1251 *wl)
-{
-       struct acx_rate_policy *acx;
-       int ret = 0;
-
-       wl1251_debug(DEBUG_ACX, "acx rate policies");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* configure one default (one-size-fits-all) rate class */
-       acx->rate_class_cnt = 1;
-       acx->rate_class[0].enabled_rates = ACX_RATE_MASK_UNSPECIFIED;
-       acx->rate_class[0].short_retry_limit = ACX_RATE_RETRY_LIMIT;
-       acx->rate_class[0].long_retry_limit = ACX_RATE_RETRY_LIMIT;
-       acx->rate_class[0].aflags = 0;
-
-       ret = wl1251_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1251_warning("Setting of rate policies failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1251_acx_mem_cfg(struct wl1251 *wl)
-{
-       struct wl1251_acx_config_memory *mem_conf;
-       int ret, i;
-
-       wl1251_debug(DEBUG_ACX, "acx mem cfg");
-
-       mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
-       if (!mem_conf) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* memory config */
-       mem_conf->mem_config.num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
-       mem_conf->mem_config.rx_mem_block_num = 35;
-       mem_conf->mem_config.tx_min_mem_block_num = 64;
-       mem_conf->mem_config.num_tx_queues = MAX_TX_QUEUES;
-       mem_conf->mem_config.host_if_options = HOSTIF_PKT_RING;
-       mem_conf->mem_config.num_ssid_profiles = 1;
-       mem_conf->mem_config.debug_buffer_size =
-               cpu_to_le16(TRACE_BUFFER_MAX_SIZE);
-
-       /* RX queue config */
-       mem_conf->rx_queue_config.dma_address = 0;
-       mem_conf->rx_queue_config.num_descs = ACX_RX_DESC_DEF;
-       mem_conf->rx_queue_config.priority = DEFAULT_RXQ_PRIORITY;
-       mem_conf->rx_queue_config.type = DEFAULT_RXQ_TYPE;
-
-       /* TX queue config */
-       for (i = 0; i < MAX_TX_QUEUES; i++) {
-               mem_conf->tx_queue_config[i].num_descs = ACX_TX_DESC_DEF;
-               mem_conf->tx_queue_config[i].attributes = i;
-       }
-
-       ret = wl1251_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
-                                  sizeof(*mem_conf));
-       if (ret < 0) {
-               wl1251_warning("wl1251 mem config failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(mem_conf);
-       return ret;
-}
-
-int wl1251_acx_wr_tbtt_and_dtim(struct wl1251 *wl, u16 tbtt, u8 dtim)
-{
-       struct wl1251_acx_wr_tbtt_and_dtim *acx;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx tbtt and dtim");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->tbtt = tbtt;
-       acx->dtim = dtim;
-
-       ret = wl1251_cmd_configure(wl, ACX_WR_TBTT_AND_DTIM,
-                                  acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1251_warning("failed to set tbtt and dtim: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1251_acx_bet_enable(struct wl1251 *wl, enum wl1251_acx_bet_mode mode,
-                         u8 max_consecutive)
-{
-       struct wl1251_acx_bet_enable *acx;
-       int ret;
-
-       wl1251_debug(DEBUG_ACX, "acx bet enable");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->enable = mode;
-       acx->max_consecutive = max_consecutive;
-
-       ret = wl1251_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1251_warning("wl1251 acx bet enable failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1251_acx_ac_cfg(struct wl1251 *wl, u8 ac, u8 cw_min, u16 cw_max,
-                     u8 aifs, u16 txop)
-{
-       struct wl1251_acx_ac_cfg *acx;
-       int ret = 0;
-
-       wl1251_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
-                    "aifs %d txop %d", ac, cw_min, cw_max, aifs, txop);
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->ac = ac;
-       acx->cw_min = cw_min;
-       acx->cw_max = cw_max;
-       acx->aifsn = aifs;
-       acx->txop_limit = txop;
-
-       ret = wl1251_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1251_warning("acx ac cfg failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1251_acx_tid_cfg(struct wl1251 *wl, u8 queue,
-                      enum wl1251_acx_channel_type type,
-                      u8 tsid, enum wl1251_acx_ps_scheme ps_scheme,
-                      enum wl1251_acx_ack_policy ack_policy)
-{
-       struct wl1251_acx_tid_cfg *acx;
-       int ret = 0;
-
-       wl1251_debug(DEBUG_ACX, "acx tid cfg %d type %d tsid %d "
-                    "ps_scheme %d ack_policy %d", queue, type, tsid,
-                    ps_scheme, ack_policy);
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->queue = queue;
-       acx->type = type;
-       acx->tsid = tsid;
-       acx->ps_scheme = ps_scheme;
-       acx->ack_policy = ack_policy;
-
-       ret = wl1251_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1251_warning("acx tid cfg failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
diff --git a/drivers/net/wireless/wl1251/acx.h b/drivers/net/wireless/wl1251/acx.h
deleted file mode 100644 (file)
index c2ba100..0000000
+++ /dev/null
@@ -1,1483 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (c) 1998-2007 Texas Instruments Incorporated
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __WL1251_ACX_H__
-#define __WL1251_ACX_H__
-
-#include "wl1251.h"
-#include "cmd.h"
-
-/* Target's information element */
-struct acx_header {
-       struct wl1251_cmd_header cmd;
-
-       /* acx (or information element) header */
-       u16 id;
-
-       /* payload length (not including headers */
-       u16 len;
-} __packed;
-
-struct acx_error_counter {
-       struct acx_header header;
-
-       /* The number of PLCP errors since the last time this */
-       /* information element was interrogated. This field is */
-       /* automatically cleared when it is interrogated.*/
-       u32 PLCP_error;
-
-       /* The number of FCS errors since the last time this */
-       /* information element was interrogated. This field is */
-       /* automatically cleared when it is interrogated.*/
-       u32 FCS_error;
-
-       /* The number of MPDUs without PLCP header errors received*/
-       /* since the last time this information element was interrogated. */
-       /* This field is automatically cleared when it is interrogated.*/
-       u32 valid_frame;
-
-       /* the number of missed sequence numbers in the squentially */
-       /* values of frames seq numbers */
-       u32 seq_num_miss;
-} __packed;
-
-struct acx_revision {
-       struct acx_header header;
-
-       /*
-        * The WiLink firmware version, an ASCII string x.x.x.x,
-        * that uniquely identifies the current firmware.
-        * The left most digit is incremented each time a
-        * significant change is made to the firmware, such as
-        * code redesign or new platform support.
-        * The second digit is incremented when major enhancements
-        * are added or major fixes are made.
-        * The third digit is incremented for each GA release.
-        * The fourth digit is incremented for each build.
-        * The first two digits identify a firmware release version,
-        * in other words, a unique set of features.
-        * The first three digits identify a GA release.
-        */
-       char fw_version[20];
-
-       /*
-        * This 4 byte field specifies the WiLink hardware version.
-        * bits 0  - 15: Reserved.
-        * bits 16 - 23: Version ID - The WiLink version ID
-        *              (1 = first spin, 2 = second spin, and so on).
-        * bits 24 - 31: Chip ID - The WiLink chip ID.
-        */
-       u32 hw_version;
-} __packed;
-
-enum wl1251_psm_mode {
-       /* Active mode */
-       WL1251_PSM_CAM = 0,
-
-       /* Power save mode */
-       WL1251_PSM_PS = 1,
-
-       /* Extreme low power */
-       WL1251_PSM_ELP = 2,
-};
-
-struct acx_sleep_auth {
-       struct acx_header header;
-
-       /* The sleep level authorization of the device. */
-       /* 0 - Always active*/
-       /* 1 - Power down mode: light / fast sleep*/
-       /* 2 - ELP mode: Deep / Max sleep*/
-       u8  sleep_auth;
-       u8  padding[3];
-} __packed;
-
-enum {
-       HOSTIF_PCI_MASTER_HOST_INDIRECT,
-       HOSTIF_PCI_MASTER_HOST_DIRECT,
-       HOSTIF_SLAVE,
-       HOSTIF_PKT_RING,
-       HOSTIF_DONTCARE = 0xFF
-};
-
-#define DEFAULT_UCAST_PRIORITY          0
-#define DEFAULT_RX_Q_PRIORITY           0
-#define DEFAULT_NUM_STATIONS            1
-#define DEFAULT_RXQ_PRIORITY            0 /* low 0 .. 15 high  */
-#define DEFAULT_RXQ_TYPE                0x07    /* All frames, Data/Ctrl/Mgmt */
-#define TRACE_BUFFER_MAX_SIZE           256
-
-#define  DP_RX_PACKET_RING_CHUNK_SIZE 1600
-#define  DP_TX_PACKET_RING_CHUNK_SIZE 1600
-#define  DP_RX_PACKET_RING_CHUNK_NUM 2
-#define  DP_TX_PACKET_RING_CHUNK_NUM 2
-#define  DP_TX_COMPLETE_TIME_OUT 20
-#define  FW_TX_CMPLT_BLOCK_SIZE 16
-
-struct acx_data_path_params {
-       struct acx_header header;
-
-       u16 rx_packet_ring_chunk_size;
-       u16 tx_packet_ring_chunk_size;
-
-       u8 rx_packet_ring_chunk_num;
-       u8 tx_packet_ring_chunk_num;
-
-       /*
-        * Maximum number of packets that can be gathered
-        * in the TX complete ring before an interrupt
-        * is generated.
-        */
-       u8 tx_complete_threshold;
-
-       /* Number of pending TX complete entries in cyclic ring.*/
-       u8 tx_complete_ring_depth;
-
-       /*
-        * Max num microseconds since a packet enters the TX
-        * complete ring until an interrupt is generated.
-        */
-       u32 tx_complete_timeout;
-} __packed;
-
-
-struct acx_data_path_params_resp {
-       struct acx_header header;
-
-       u16 rx_packet_ring_chunk_size;
-       u16 tx_packet_ring_chunk_size;
-
-       u8 rx_packet_ring_chunk_num;
-       u8 tx_packet_ring_chunk_num;
-
-       u8 pad[2];
-
-       u32 rx_packet_ring_addr;
-       u32 tx_packet_ring_addr;
-
-       u32 rx_control_addr;
-       u32 tx_control_addr;
-
-       u32 tx_complete_addr;
-} __packed;
-
-#define TX_MSDU_LIFETIME_MIN       0
-#define TX_MSDU_LIFETIME_MAX       3000
-#define TX_MSDU_LIFETIME_DEF       512
-#define RX_MSDU_LIFETIME_MIN       0
-#define RX_MSDU_LIFETIME_MAX       0xFFFFFFFF
-#define RX_MSDU_LIFETIME_DEF       512000
-
-struct acx_rx_msdu_lifetime {
-       struct acx_header header;
-
-       /*
-        * The maximum amount of time, in TU, before the
-        * firmware discards the MSDU.
-        */
-       u32 lifetime;
-} __packed;
-
-/*
- * RX Config Options Table
- * Bit         Definition
- * ===         ==========
- * 31:14               Reserved
- * 13          Copy RX Status - when set, write three receive status words
- *             to top of rx'd MPDUs.
- *             When cleared, do not write three status words (added rev 1.5)
- * 12          Reserved
- * 11          RX Complete upon FCS error - when set, give rx complete
- *             interrupt for FCS errors, after the rx filtering, e.g. unicast
- *             frames not to us with FCS error will not generate an interrupt.
- * 10          SSID Filter Enable - When set, the WiLink discards all beacon,
- *             probe request, and probe response frames with an SSID that does
- *             not match the SSID specified by the host in the START/JOIN
- *             command.
- *             When clear, the WiLink receives frames with any SSID.
- * 9           Broadcast Filter Enable - When set, the WiLink discards all
- *             broadcast frames. When clear, the WiLink receives all received
- *             broadcast frames.
- * 8:6         Reserved
- * 5           BSSID Filter Enable - When set, the WiLink discards any frames
- *             with a BSSID that does not match the BSSID specified by the
- *             host.
- *             When clear, the WiLink receives frames from any BSSID.
- * 4           MAC Addr Filter - When set, the WiLink discards any frames
- *             with a destination address that does not match the MAC address
- *             of the adaptor.
- *             When clear, the WiLink receives frames destined to any MAC
- *             address.
- * 3           Promiscuous - When set, the WiLink receives all valid frames
- *             (i.e., all frames that pass the FCS check).
- *             When clear, only frames that pass the other filters specified
- *             are received.
- * 2           FCS - When set, the WiLink includes the FCS with the received
- *             frame.
- *             When cleared, the FCS is discarded.
- * 1           PLCP header - When set, write all data from baseband to frame
- *             buffer including PHY header.
- * 0           Reserved - Always equal to 0.
- *
- * RX Filter Options Table
- * Bit         Definition
- * ===         ==========
- * 31:12               Reserved - Always equal to 0.
- * 11          Association - When set, the WiLink receives all association
- *             related frames (association request/response, reassocation
- *             request/response, and disassociation). When clear, these frames
- *             are discarded.
- * 10          Auth/De auth - When set, the WiLink receives all authentication
- *             and de-authentication frames. When clear, these frames are
- *             discarded.
- * 9           Beacon - When set, the WiLink receives all beacon frames.
- *             When clear, these frames are discarded.
- * 8           Contention Free - When set, the WiLink receives all contention
- *             free frames.
- *             When clear, these frames are discarded.
- * 7           Control - When set, the WiLink receives all control frames.
- *             When clear, these frames are discarded.
- * 6           Data - When set, the WiLink receives all data frames.
- *             When clear, these frames are discarded.
- * 5           FCS Error - When set, the WiLink receives frames that have FCS
- *             errors.
- *             When clear, these frames are discarded.
- * 4           Management - When set, the WiLink receives all management
- *             frames.
- *             When clear, these frames are discarded.
- * 3           Probe Request - When set, the WiLink receives all probe request
- *             frames.
- *             When clear, these frames are discarded.
- * 2           Probe Response - When set, the WiLink receives all probe
- *             response frames.
- *             When clear, these frames are discarded.
- * 1           RTS/CTS/ACK - When set, the WiLink receives all RTS, CTS and ACK
- *             frames.
- *             When clear, these frames are discarded.
- * 0           Rsvd Type/Sub Type - When set, the WiLink receives all frames
- *             that have reserved frame types and sub types as defined by the
- *             802.11 specification.
- *             When clear, these frames are discarded.
- */
-struct acx_rx_config {
-       struct acx_header header;
-
-       u32 config_options;
-       u32 filter_options;
-} __packed;
-
-enum {
-       QOS_AC_BE = 0,
-       QOS_AC_BK,
-       QOS_AC_VI,
-       QOS_AC_VO,
-       QOS_HIGHEST_AC_INDEX = QOS_AC_VO,
-};
-
-#define MAX_NUM_OF_AC             (QOS_HIGHEST_AC_INDEX+1)
-#define FIRST_AC_INDEX            QOS_AC_BE
-#define MAX_NUM_OF_802_1d_TAGS    8
-#define AC_PARAMS_MAX_TSID        15
-#define MAX_APSD_CONF             0xffff
-
-#define  QOS_TX_HIGH_MIN      (0)
-#define  QOS_TX_HIGH_MAX      (100)
-
-#define  QOS_TX_HIGH_BK_DEF   (25)
-#define  QOS_TX_HIGH_BE_DEF   (35)
-#define  QOS_TX_HIGH_VI_DEF   (35)
-#define  QOS_TX_HIGH_VO_DEF   (35)
-
-#define  QOS_TX_LOW_BK_DEF    (15)
-#define  QOS_TX_LOW_BE_DEF    (25)
-#define  QOS_TX_LOW_VI_DEF    (25)
-#define  QOS_TX_LOW_VO_DEF    (25)
-
-struct acx_tx_queue_qos_config {
-       struct acx_header header;
-
-       u8 qid;
-       u8 pad[3];
-
-       /* Max number of blocks allowd in the queue */
-       u16 high_threshold;
-
-       /* Lowest memory blocks guaranteed for this queue */
-       u16 low_threshold;
-} __packed;
-
-struct acx_packet_detection {
-       struct acx_header header;
-
-       u32 threshold;
-} __packed;
-
-
-enum acx_slot_type {
-       SLOT_TIME_LONG = 0,
-       SLOT_TIME_SHORT = 1,
-       DEFAULT_SLOT_TIME = SLOT_TIME_SHORT,
-       MAX_SLOT_TIMES = 0xFF
-};
-
-#define STATION_WONE_INDEX 0
-
-struct acx_slot {
-       struct acx_header header;
-
-       u8 wone_index; /* Reserved */
-       u8 slot_time;
-       u8 reserved[6];
-} __packed;
-
-
-#define ADDRESS_GROUP_MAX      (8)
-#define ADDRESS_GROUP_MAX_LEN  (ETH_ALEN * ADDRESS_GROUP_MAX)
-
-struct acx_dot11_grp_addr_tbl {
-       struct acx_header header;
-
-       u8 enabled;
-       u8 num_groups;
-       u8 pad[2];
-       u8 mac_table[ADDRESS_GROUP_MAX_LEN];
-} __packed;
-
-
-#define  RX_TIMEOUT_PS_POLL_MIN    0
-#define  RX_TIMEOUT_PS_POLL_MAX    (200000)
-#define  RX_TIMEOUT_PS_POLL_DEF    (15)
-#define  RX_TIMEOUT_UPSD_MIN       0
-#define  RX_TIMEOUT_UPSD_MAX       (200000)
-#define  RX_TIMEOUT_UPSD_DEF       (15)
-
-struct acx_rx_timeout {
-       struct acx_header header;
-
-       /*
-        * The longest time the STA will wait to receive
-        * traffic from the AP after a PS-poll has been
-        * transmitted.
-        */
-       u16 ps_poll_timeout;
-
-       /*
-        * The longest time the STA will wait to receive
-        * traffic from the AP after a frame has been sent
-        * from an UPSD enabled queue.
-        */
-       u16 upsd_timeout;
-} __packed;
-
-#define RTS_THRESHOLD_MIN              0
-#define RTS_THRESHOLD_MAX              4096
-#define RTS_THRESHOLD_DEF              2347
-
-struct acx_rts_threshold {
-       struct acx_header header;
-
-       u16 threshold;
-       u8 pad[2];
-} __packed;
-
-enum wl1251_acx_low_rssi_type {
-       /*
-        * The event is a "Level" indication which keeps triggering
-        * as long as the average RSSI is below the threshold.
-        */
-       WL1251_ACX_LOW_RSSI_TYPE_LEVEL = 0,
-
-       /*
-        * The event is an "Edge" indication which triggers
-        * only when the RSSI threshold is crossed from above.
-        */
-       WL1251_ACX_LOW_RSSI_TYPE_EDGE = 1,
-};
-
-struct acx_low_rssi {
-       struct acx_header header;
-
-       /*
-        * The threshold (in dBm) below (or above after low rssi
-        * indication) which the firmware generates an interrupt to the
-        * host. This parameter is signed.
-        */
-       s8 threshold;
-
-       /*
-        * The weight of the current RSSI sample, before adding the new
-        * sample, that is used to calculate the average RSSI.
-        */
-       u8 weight;
-
-       /*
-        * The number of Beacons/Probe response frames that will be
-        * received before issuing the Low or Regained RSSI event.
-        */
-       u8 depth;
-
-       /*
-        * Configures how the Low RSSI Event is triggered. Refer to
-        * enum wl1251_acx_low_rssi_type for more.
-        */
-       u8 type;
-} __packed;
-
-struct acx_beacon_filter_option {
-       struct acx_header header;
-
-       u8 enable;
-
-       /*
-        * The number of beacons without the unicast TIM
-        * bit set that the firmware buffers before
-        * signaling the host about ready frames.
-        * When set to 0 and the filter is enabled, beacons
-        * without the unicast TIM bit set are dropped.
-        */
-       u8 max_num_beacons;
-       u8 pad[2];
-} __packed;
-
-/*
- * ACXBeaconFilterEntry (not 221)
- * Byte Offset     Size (Bytes)    Definition
- * ===========     ============    ==========
- * 0                           1               IE identifier
- * 1               1               Treatment bit mask
- *
- * ACXBeaconFilterEntry (221)
- * Byte Offset     Size (Bytes)    Definition
- * ===========     ============    ==========
- * 0               1               IE identifier
- * 1               1               Treatment bit mask
- * 2               3               OUI
- * 5               1               Type
- * 6               2               Version
- *
- *
- * Treatment bit mask - The information element handling:
- * bit 0 - The information element is compared and transferred
- * in case of change.
- * bit 1 - The information element is transferred to the host
- * with each appearance or disappearance.
- * Note that both bits can be set at the same time.
- */
-#define        BEACON_FILTER_TABLE_MAX_IE_NUM                 (32)
-#define BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM (6)
-#define BEACON_FILTER_TABLE_IE_ENTRY_SIZE             (2)
-#define BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE (6)
-#define BEACON_FILTER_TABLE_MAX_SIZE ((BEACON_FILTER_TABLE_MAX_IE_NUM * \
-                           BEACON_FILTER_TABLE_IE_ENTRY_SIZE) + \
-                          (BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM * \
-                           BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE))
-
-#define BEACON_RULE_PASS_ON_CHANGE                     BIT(0)
-#define BEACON_RULE_PASS_ON_APPEARANCE                 BIT(1)
-
-#define BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN         (37)
-
-struct acx_beacon_filter_ie_table {
-       struct acx_header header;
-
-       u8 num_ie;
-       u8 pad[3];
-       u8 table[BEACON_FILTER_TABLE_MAX_SIZE];
-} __packed;
-
-#define SYNCH_FAIL_DEFAULT_THRESHOLD    10     /* number of beacons */
-#define NO_BEACON_DEFAULT_TIMEOUT       (500) /* in microseconds */
-
-struct acx_conn_monit_params {
-       struct acx_header header;
-
-       u32 synch_fail_thold; /* number of beacons missed */
-       u32 bss_lose_timeout; /* number of TU's from synch fail */
-} __packed;
-
-enum {
-       SG_ENABLE = 0,
-       SG_DISABLE,
-       SG_SENSE_NO_ACTIVITY,
-       SG_SENSE_ACTIVE
-};
-
-struct acx_bt_wlan_coex {
-       struct acx_header header;
-
-       /*
-        * 0 -> PTA enabled
-        * 1 -> PTA disabled
-        * 2 -> sense no active mode, i.e.
-        *      an interrupt is sent upon
-        *      BT activity.
-        * 3 -> PTA is switched on in response
-        *      to the interrupt sending.
-        */
-       u8 enable;
-       u8 pad[3];
-} __packed;
-
-#define PTA_ANTENNA_TYPE_DEF             (0)
-#define PTA_BT_HP_MAXTIME_DEF            (2000)
-#define PTA_WLAN_HP_MAX_TIME_DEF         (5000)
-#define PTA_SENSE_DISABLE_TIMER_DEF      (1350)
-#define PTA_PROTECTIVE_RX_TIME_DEF       (1500)
-#define PTA_PROTECTIVE_TX_TIME_DEF       (1500)
-#define PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF (3000)
-#define PTA_SIGNALING_TYPE_DEF           (1)
-#define PTA_AFH_LEVERAGE_ON_DEF                  (0)
-#define PTA_NUMBER_QUIET_CYCLE_DEF       (0)
-#define PTA_MAX_NUM_CTS_DEF              (3)
-#define PTA_NUMBER_OF_WLAN_PACKETS_DEF   (2)
-#define PTA_NUMBER_OF_BT_PACKETS_DEF     (2)
-#define PTA_PROTECTIVE_RX_TIME_FAST_DEF          (1500)
-#define PTA_PROTECTIVE_TX_TIME_FAST_DEF          (3000)
-#define PTA_CYCLE_TIME_FAST_DEF                  (8700)
-#define PTA_RX_FOR_AVALANCHE_DEF         (5)
-#define PTA_ELP_HP_DEF                   (0)
-#define PTA_ANTI_STARVE_PERIOD_DEF       (500)
-#define PTA_ANTI_STARVE_NUM_CYCLE_DEF    (4)
-#define PTA_ALLOW_PA_SD_DEF              (1)
-#define PTA_TIME_BEFORE_BEACON_DEF       (6300)
-#define PTA_HPDM_MAX_TIME_DEF            (1600)
-#define PTA_TIME_OUT_NEXT_WLAN_DEF       (2550)
-#define PTA_AUTO_MODE_NO_CTS_DEF         (0)
-#define PTA_BT_HP_RESPECTED_DEF                  (3)
-#define PTA_WLAN_RX_MIN_RATE_DEF         (24)
-#define PTA_ACK_MODE_DEF                 (1)
-
-struct acx_bt_wlan_coex_param {
-       struct acx_header header;
-
-       /*
-        * The minimum rate of a received WLAN packet in the STA,
-        * during protective mode, of which a new BT-HP request
-        * during this Rx will always be respected and gain the antenna.
-        */
-       u32 min_rate;
-
-       /* Max time the BT HP will be respected. */
-       u16 bt_hp_max_time;
-
-       /* Max time the WLAN HP will be respected. */
-       u16 wlan_hp_max_time;
-
-       /*
-        * The time between the last BT activity
-        * and the moment when the sense mode returns
-        * to SENSE_INACTIVE.
-        */
-       u16 sense_disable_timer;
-
-       /* Time before the next BT HP instance */
-       u16 rx_time_bt_hp;
-       u16 tx_time_bt_hp;
-
-       /* range: 10-20000    default: 1500 */
-       u16 rx_time_bt_hp_fast;
-       u16 tx_time_bt_hp_fast;
-
-       /* range: 2000-65535  default: 8700 */
-       u16 wlan_cycle_fast;
-
-       /* range: 0 - 15000 (Msec) default: 1000 */
-       u16 bt_anti_starvation_period;
-
-       /* range 400-10000(Usec) default: 3000 */
-       u16 next_bt_lp_packet;
-
-       /* Deafult: worst case for BT DH5 traffic */
-       u16 wake_up_beacon;
-
-       /* range: 0-50000(Usec) default: 1050 */
-       u16 hp_dm_max_guard_time;
-
-       /*
-        * This is to prevent both BT & WLAN antenna
-        * starvation.
-        * Range: 100-50000(Usec) default:2550
-        */
-       u16 next_wlan_packet;
-
-       /* 0 -> shared antenna */
-       u8 antenna_type;
-
-       /*
-        * 0 -> TI legacy
-        * 1 -> Palau
-        */
-       u8 signal_type;
-
-       /*
-        * BT AFH status
-        * 0 -> no AFH
-        * 1 -> from dedicated GPIO
-        * 2 -> AFH on (from host)
-        */
-       u8 afh_leverage_on;
-
-       /*
-        * The number of cycles during which no
-        * TX will be sent after 1 cycle of RX
-        * transaction in protective mode
-        */
-       u8 quiet_cycle_num;
-
-       /*
-        * The maximum number of CTSs that will
-        * be sent for receiving RX packet in
-        * protective mode
-        */
-       u8 max_cts;
-
-       /*
-        * The number of WLAN packets
-        * transferred in common mode before
-        * switching to BT.
-        */
-       u8 wlan_packets_num;
-
-       /*
-        * The number of BT packets
-        * transferred in common mode before
-        * switching to WLAN.
-        */
-       u8 bt_packets_num;
-
-       /* range: 1-255  default: 5 */
-       u8 missed_rx_avalanche;
-
-       /* range: 0-1    default: 1 */
-       u8 wlan_elp_hp;
-
-       /* range: 0 - 15  default: 4 */
-       u8 bt_anti_starvation_cycles;
-
-       u8 ack_mode_dual_ant;
-
-       /*
-        * Allow PA_SD assertion/de-assertion
-        * during enabled BT activity.
-        */
-       u8 pa_sd_enable;
-
-       /*
-        * Enable/Disable PTA in auto mode:
-        * Support Both Active & P.S modes
-        */
-       u8 pta_auto_mode_enable;
-
-       /* range: 0 - 20  default: 1 */
-       u8 bt_hp_respected_num;
-} __packed;
-
-#define CCA_THRSH_ENABLE_ENERGY_D       0x140A
-#define CCA_THRSH_DISABLE_ENERGY_D      0xFFEF
-
-struct acx_energy_detection {
-       struct acx_header header;
-
-       /* The RX Clear Channel Assessment threshold in the PHY */
-       u16 rx_cca_threshold;
-       u8 tx_energy_detection;
-       u8 pad;
-} __packed;
-
-#define BCN_RX_TIMEOUT_DEF_VALUE        10000
-#define BROADCAST_RX_TIMEOUT_DEF_VALUE  20000
-#define RX_BROADCAST_IN_PS_DEF_VALUE    1
-#define CONSECUTIVE_PS_POLL_FAILURE_DEF 4
-
-struct acx_beacon_broadcast {
-       struct acx_header header;
-
-       u16 beacon_rx_timeout;
-       u16 broadcast_timeout;
-
-       /* Enables receiving of broadcast packets in PS mode */
-       u8 rx_broadcast_in_ps;
-
-       /* Consecutive PS Poll failures before updating the host */
-       u8 ps_poll_threshold;
-       u8 pad[2];
-} __packed;
-
-struct acx_event_mask {
-       struct acx_header header;
-
-       u32 event_mask;
-       u32 high_event_mask; /* Unused */
-} __packed;
-
-#define CFG_RX_FCS             BIT(2)
-#define CFG_RX_ALL_GOOD                BIT(3)
-#define CFG_UNI_FILTER_EN      BIT(4)
-#define CFG_BSSID_FILTER_EN    BIT(5)
-#define CFG_MC_FILTER_EN       BIT(6)
-#define CFG_MC_ADDR0_EN                BIT(7)
-#define CFG_MC_ADDR1_EN                BIT(8)
-#define CFG_BC_REJECT_EN       BIT(9)
-#define CFG_SSID_FILTER_EN     BIT(10)
-#define CFG_RX_INT_FCS_ERROR   BIT(11)
-#define CFG_RX_INT_ENCRYPTED   BIT(12)
-#define CFG_RX_WR_RX_STATUS    BIT(13)
-#define CFG_RX_FILTER_NULTI    BIT(14)
-#define CFG_RX_RESERVE         BIT(15)
-#define CFG_RX_TIMESTAMP_TSF   BIT(16)
-
-#define CFG_RX_RSV_EN          BIT(0)
-#define CFG_RX_RCTS_ACK                BIT(1)
-#define CFG_RX_PRSP_EN         BIT(2)
-#define CFG_RX_PREQ_EN         BIT(3)
-#define CFG_RX_MGMT_EN         BIT(4)
-#define CFG_RX_FCS_ERROR       BIT(5)
-#define CFG_RX_DATA_EN         BIT(6)
-#define CFG_RX_CTL_EN          BIT(7)
-#define CFG_RX_CF_EN           BIT(8)
-#define CFG_RX_BCN_EN          BIT(9)
-#define CFG_RX_AUTH_EN         BIT(10)
-#define CFG_RX_ASSOC_EN                BIT(11)
-
-#define SCAN_PASSIVE           BIT(0)
-#define SCAN_5GHZ_BAND         BIT(1)
-#define SCAN_TRIGGERED         BIT(2)
-#define SCAN_PRIORITY_HIGH     BIT(3)
-
-struct acx_fw_gen_frame_rates {
-       struct acx_header header;
-
-       u8 tx_ctrl_frame_rate; /* RATE_* */
-       u8 tx_ctrl_frame_mod; /* CCK_* or PBCC_* */
-       u8 tx_mgt_frame_rate;
-       u8 tx_mgt_frame_mod;
-} __packed;
-
-/* STA MAC */
-struct acx_dot11_station_id {
-       struct acx_header header;
-
-       u8 mac[ETH_ALEN];
-       u8 pad[2];
-} __packed;
-
-struct acx_feature_config {
-       struct acx_header header;
-
-       u32 options;
-       u32 data_flow_options;
-} __packed;
-
-struct acx_current_tx_power {
-       struct acx_header header;
-
-       u8  current_tx_power;
-       u8  padding[3];
-} __packed;
-
-struct acx_dot11_default_key {
-       struct acx_header header;
-
-       u8 id;
-       u8 pad[3];
-} __packed;
-
-struct acx_tsf_info {
-       struct acx_header header;
-
-       u32 current_tsf_msb;
-       u32 current_tsf_lsb;
-       u32 last_TBTT_msb;
-       u32 last_TBTT_lsb;
-       u8 last_dtim_count;
-       u8 pad[3];
-} __packed;
-
-enum acx_wake_up_event {
-       WAKE_UP_EVENT_BEACON_BITMAP     = 0x01, /* Wake on every Beacon*/
-       WAKE_UP_EVENT_DTIM_BITMAP       = 0x02, /* Wake on every DTIM*/
-       WAKE_UP_EVENT_N_DTIM_BITMAP     = 0x04, /* Wake on every Nth DTIM */
-       WAKE_UP_EVENT_N_BEACONS_BITMAP  = 0x08, /* Wake on every Nth Beacon */
-       WAKE_UP_EVENT_BITS_MASK         = 0x0F
-};
-
-struct acx_wake_up_condition {
-       struct acx_header header;
-
-       u8 wake_up_event; /* Only one bit can be set */
-       u8 listen_interval;
-       u8 pad[2];
-} __packed;
-
-struct acx_aid {
-       struct acx_header header;
-
-       /*
-        * To be set when associated with an AP.
-        */
-       u16 aid;
-       u8 pad[2];
-} __packed;
-
-enum acx_preamble_type {
-       ACX_PREAMBLE_LONG = 0,
-       ACX_PREAMBLE_SHORT = 1
-};
-
-struct acx_preamble {
-       struct acx_header header;
-
-       /*
-        * When set, the WiLink transmits the frames with a short preamble and
-        * when cleared, the WiLink transmits the frames with a long preamble.
-        */
-       u8 preamble;
-       u8 padding[3];
-} __packed;
-
-enum acx_ctsprotect_type {
-       CTSPROTECT_DISABLE = 0,
-       CTSPROTECT_ENABLE = 1
-};
-
-struct acx_ctsprotect {
-       struct acx_header header;
-       u8 ctsprotect;
-       u8 padding[3];
-} __packed;
-
-struct acx_tx_statistics {
-       u32 internal_desc_overflow;
-}  __packed;
-
-struct acx_rx_statistics {
-       u32 out_of_mem;
-       u32 hdr_overflow;
-       u32 hw_stuck;
-       u32 dropped;
-       u32 fcs_err;
-       u32 xfr_hint_trig;
-       u32 path_reset;
-       u32 reset_counter;
-} __packed;
-
-struct acx_dma_statistics {
-       u32 rx_requested;
-       u32 rx_errors;
-       u32 tx_requested;
-       u32 tx_errors;
-}  __packed;
-
-struct acx_isr_statistics {
-       /* host command complete */
-       u32 cmd_cmplt;
-
-       /* fiqisr() */
-       u32 fiqs;
-
-       /* (INT_STS_ND & INT_TRIG_RX_HEADER) */
-       u32 rx_headers;
-
-       /* (INT_STS_ND & INT_TRIG_RX_CMPLT) */
-       u32 rx_completes;
-
-       /* (INT_STS_ND & INT_TRIG_NO_RX_BUF) */
-       u32 rx_mem_overflow;
-
-       /* (INT_STS_ND & INT_TRIG_S_RX_RDY) */
-       u32 rx_rdys;
-
-       /* irqisr() */
-       u32 irqs;
-
-       /* (INT_STS_ND & INT_TRIG_TX_PROC) */
-       u32 tx_procs;
-
-       /* (INT_STS_ND & INT_TRIG_DECRYPT_DONE) */
-       u32 decrypt_done;
-
-       /* (INT_STS_ND & INT_TRIG_DMA0) */
-       u32 dma0_done;
-
-       /* (INT_STS_ND & INT_TRIG_DMA1) */
-       u32 dma1_done;
-
-       /* (INT_STS_ND & INT_TRIG_TX_EXC_CMPLT) */
-       u32 tx_exch_complete;
-
-       /* (INT_STS_ND & INT_TRIG_COMMAND) */
-       u32 commands;
-
-       /* (INT_STS_ND & INT_TRIG_RX_PROC) */
-       u32 rx_procs;
-
-       /* (INT_STS_ND & INT_TRIG_PM_802) */
-       u32 hw_pm_mode_changes;
-
-       /* (INT_STS_ND & INT_TRIG_ACKNOWLEDGE) */
-       u32 host_acknowledges;
-
-       /* (INT_STS_ND & INT_TRIG_PM_PCI) */
-       u32 pci_pm;
-
-       /* (INT_STS_ND & INT_TRIG_ACM_WAKEUP) */
-       u32 wakeups;
-
-       /* (INT_STS_ND & INT_TRIG_LOW_RSSI) */
-       u32 low_rssi;
-} __packed;
-
-struct acx_wep_statistics {
-       /* WEP address keys configured */
-       u32 addr_key_count;
-
-       /* default keys configured */
-       u32 default_key_count;
-
-       u32 reserved;
-
-       /* number of times that WEP key not found on lookup */
-       u32 key_not_found;
-
-       /* number of times that WEP key decryption failed */
-       u32 decrypt_fail;
-
-       /* WEP packets decrypted */
-       u32 packets;
-
-       /* WEP decrypt interrupts */
-       u32 interrupt;
-} __packed;
-
-#define ACX_MISSED_BEACONS_SPREAD 10
-
-struct acx_pwr_statistics {
-       /* the amount of enters into power save mode (both PD & ELP) */
-       u32 ps_enter;
-
-       /* the amount of enters into ELP mode */
-       u32 elp_enter;
-
-       /* the amount of missing beacon interrupts to the host */
-       u32 missing_bcns;
-
-       /* the amount of wake on host-access times */
-       u32 wake_on_host;
-
-       /* the amount of wake on timer-expire */
-       u32 wake_on_timer_exp;
-
-       /* the number of packets that were transmitted with PS bit set */
-       u32 tx_with_ps;
-
-       /* the number of packets that were transmitted with PS bit clear */
-       u32 tx_without_ps;
-
-       /* the number of received beacons */
-       u32 rcvd_beacons;
-
-       /* the number of entering into PowerOn (power save off) */
-       u32 power_save_off;
-
-       /* the number of entries into power save mode */
-       u16 enable_ps;
-
-       /*
-        * the number of exits from power save, not including failed PS
-        * transitions
-        */
-       u16 disable_ps;
-
-       /*
-        * the number of times the TSF counter was adjusted because
-        * of drift
-        */
-       u32 fix_tsf_ps;
-
-       /* Gives statistics about the spread continuous missed beacons.
-        * The 16 LSB are dedicated for the PS mode.
-        * The 16 MSB are dedicated for the PS mode.
-        * cont_miss_bcns_spread[0] - single missed beacon.
-        * cont_miss_bcns_spread[1] - two continuous missed beacons.
-        * cont_miss_bcns_spread[2] - three continuous missed beacons.
-        * ...
-        * cont_miss_bcns_spread[9] - ten and more continuous missed beacons.
-       */
-       u32 cont_miss_bcns_spread[ACX_MISSED_BEACONS_SPREAD];
-
-       /* the number of beacons in awake mode */
-       u32 rcvd_awake_beacons;
-} __packed;
-
-struct acx_mic_statistics {
-       u32 rx_pkts;
-       u32 calc_failure;
-} __packed;
-
-struct acx_aes_statistics {
-       u32 encrypt_fail;
-       u32 decrypt_fail;
-       u32 encrypt_packets;
-       u32 decrypt_packets;
-       u32 encrypt_interrupt;
-       u32 decrypt_interrupt;
-} __packed;
-
-struct acx_event_statistics {
-       u32 heart_beat;
-       u32 calibration;
-       u32 rx_mismatch;
-       u32 rx_mem_empty;
-       u32 rx_pool;
-       u32 oom_late;
-       u32 phy_transmit_error;
-       u32 tx_stuck;
-} __packed;
-
-struct acx_ps_statistics {
-       u32 pspoll_timeouts;
-       u32 upsd_timeouts;
-       u32 upsd_max_sptime;
-       u32 upsd_max_apturn;
-       u32 pspoll_max_apturn;
-       u32 pspoll_utilization;
-       u32 upsd_utilization;
-} __packed;
-
-struct acx_rxpipe_statistics {
-       u32 rx_prep_beacon_drop;
-       u32 descr_host_int_trig_rx_data;
-       u32 beacon_buffer_thres_host_int_trig_rx_data;
-       u32 missed_beacon_host_int_trig_rx_data;
-       u32 tx_xfr_host_int_trig_rx_data;
-} __packed;
-
-struct acx_statistics {
-       struct acx_header header;
-
-       struct acx_tx_statistics tx;
-       struct acx_rx_statistics rx;
-       struct acx_dma_statistics dma;
-       struct acx_isr_statistics isr;
-       struct acx_wep_statistics wep;
-       struct acx_pwr_statistics pwr;
-       struct acx_aes_statistics aes;
-       struct acx_mic_statistics mic;
-       struct acx_event_statistics event;
-       struct acx_ps_statistics ps;
-       struct acx_rxpipe_statistics rxpipe;
-} __packed;
-
-#define ACX_MAX_RATE_CLASSES       8
-#define ACX_RATE_MASK_UNSPECIFIED  0
-#define ACX_RATE_RETRY_LIMIT      10
-
-struct acx_rate_class {
-       u32 enabled_rates;
-       u8 short_retry_limit;
-       u8 long_retry_limit;
-       u8 aflags;
-       u8 reserved;
-} __packed;
-
-struct acx_rate_policy {
-       struct acx_header header;
-
-       u32 rate_class_cnt;
-       struct acx_rate_class rate_class[ACX_MAX_RATE_CLASSES];
-} __packed;
-
-struct wl1251_acx_memory {
-       __le16 num_stations; /* number of STAs to be supported. */
-       u16 reserved_1;
-
-       /*
-        * Nmber of memory buffers for the RX mem pool.
-        * The actual number may be less if there are
-        * not enough blocks left for the minimum num
-        * of TX ones.
-        */
-       u8 rx_mem_block_num;
-       u8 reserved_2;
-       u8 num_tx_queues; /* From 1 to 16 */
-       u8 host_if_options; /* HOST_IF* */
-       u8 tx_min_mem_block_num;
-       u8 num_ssid_profiles;
-       __le16 debug_buffer_size;
-} __packed;
-
-
-#define ACX_RX_DESC_MIN                1
-#define ACX_RX_DESC_MAX                127
-#define ACX_RX_DESC_DEF                32
-struct wl1251_acx_rx_queue_config {
-       u8 num_descs;
-       u8 pad;
-       u8 type;
-       u8 priority;
-       __le32 dma_address;
-} __packed;
-
-#define ACX_TX_DESC_MIN                1
-#define ACX_TX_DESC_MAX                127
-#define ACX_TX_DESC_DEF                16
-struct wl1251_acx_tx_queue_config {
-    u8 num_descs;
-    u8 pad[2];
-    u8 attributes;
-} __packed;
-
-#define MAX_TX_QUEUE_CONFIGS 5
-#define MAX_TX_QUEUES 4
-struct wl1251_acx_config_memory {
-       struct acx_header header;
-
-       struct wl1251_acx_memory mem_config;
-       struct wl1251_acx_rx_queue_config rx_queue_config;
-       struct wl1251_acx_tx_queue_config tx_queue_config[MAX_TX_QUEUE_CONFIGS];
-} __packed;
-
-struct wl1251_acx_mem_map {
-       struct acx_header header;
-
-       void *code_start;
-       void *code_end;
-
-       void *wep_defkey_start;
-       void *wep_defkey_end;
-
-       void *sta_table_start;
-       void *sta_table_end;
-
-       void *packet_template_start;
-       void *packet_template_end;
-
-       void *queue_memory_start;
-       void *queue_memory_end;
-
-       void *packet_memory_pool_start;
-       void *packet_memory_pool_end;
-
-       void *debug_buffer1_start;
-       void *debug_buffer1_end;
-
-       void *debug_buffer2_start;
-       void *debug_buffer2_end;
-
-       /* Number of blocks FW allocated for TX packets */
-       u32 num_tx_mem_blocks;
-
-       /* Number of blocks FW allocated for RX packets */
-       u32 num_rx_mem_blocks;
-} __packed;
-
-
-struct wl1251_acx_wr_tbtt_and_dtim {
-
-       struct acx_header header;
-
-       /* Time in TUs between two consecutive beacons */
-       u16 tbtt;
-
-       /*
-        * DTIM period
-        * For BSS: Number of TBTTs in a DTIM period (range: 1-10)
-        * For IBSS: value shall be set to 1
-       */
-       u8  dtim;
-       u8  padding;
-} __packed;
-
-enum wl1251_acx_bet_mode {
-       WL1251_ACX_BET_DISABLE = 0,
-       WL1251_ACX_BET_ENABLE = 1,
-};
-
-struct wl1251_acx_bet_enable {
-       struct acx_header header;
-
-       /*
-        * Specifies if beacon early termination procedure is enabled or
-        * disabled, see enum wl1251_acx_bet_mode.
-        */
-       u8 enable;
-
-       /*
-        * Specifies the maximum number of consecutive beacons that may be
-        * early terminated. After this number is reached at least one full
-        * beacon must be correctly received in FW before beacon ET
-        * resumes. Range 0 - 255.
-        */
-       u8 max_consecutive;
-
-       u8 padding[2];
-} __packed;
-
-struct wl1251_acx_ac_cfg {
-       struct acx_header header;
-
-       /*
-        * Access Category - The TX queue's access category
-        * (refer to AccessCategory_enum)
-        */
-       u8 ac;
-
-       /*
-        * The contention window minimum size (in slots) for
-        * the access class.
-        */
-       u8 cw_min;
-
-       /*
-        * The contention window maximum size (in slots) for
-        * the access class.
-        */
-       u16 cw_max;
-
-       /* The AIF value (in slots) for the access class. */
-       u8 aifsn;
-
-       u8 reserved;
-
-       /* The TX Op Limit (in microseconds) for the access class. */
-       u16 txop_limit;
-} __packed;
-
-
-enum wl1251_acx_channel_type {
-       CHANNEL_TYPE_DCF        = 0,
-       CHANNEL_TYPE_EDCF       = 1,
-       CHANNEL_TYPE_HCCA       = 2,
-};
-
-enum wl1251_acx_ps_scheme {
-       /* regular ps: simple sending of packets */
-       WL1251_ACX_PS_SCHEME_LEGACY     = 0,
-
-       /* sending a packet triggers a unscheduled apsd downstream */
-       WL1251_ACX_PS_SCHEME_UPSD_TRIGGER       = 1,
-
-       /* a pspoll packet will be sent before every data packet */
-       WL1251_ACX_PS_SCHEME_LEGACY_PSPOLL      = 2,
-
-       /* scheduled apsd mode */
-       WL1251_ACX_PS_SCHEME_SAPSD              = 3,
-};
-
-enum wl1251_acx_ack_policy {
-       WL1251_ACX_ACK_POLICY_LEGACY    = 0,
-       WL1251_ACX_ACK_POLICY_NO_ACK    = 1,
-       WL1251_ACX_ACK_POLICY_BLOCK     = 2,
-};
-
-struct wl1251_acx_tid_cfg {
-       struct acx_header header;
-
-       /* tx queue id number (0-7) */
-       u8 queue;
-
-       /* channel access type for the queue, enum wl1251_acx_channel_type */
-       u8 type;
-
-       /* EDCA: ac index (0-3), HCCA: traffic stream id (8-15) */
-       u8 tsid;
-
-       /* ps scheme of the specified queue, enum wl1251_acx_ps_scheme */
-       u8 ps_scheme;
-
-       /* the tx queue ack policy, enum wl1251_acx_ack_policy */
-       u8 ack_policy;
-
-       u8 padding[3];
-
-       /* not supported */
-       u32 apsdconf[2];
-} __packed;
-
-/*************************************************************************
-
-    Host Interrupt Register (WiLink -> Host)
-
-**************************************************************************/
-
-/* RX packet is ready in Xfer buffer #0 */
-#define WL1251_ACX_INTR_RX0_DATA      BIT(0)
-
-/* TX result(s) are in the TX complete buffer */
-#define WL1251_ACX_INTR_TX_RESULT      BIT(1)
-
-/* OBSOLETE */
-#define WL1251_ACX_INTR_TX_XFR         BIT(2)
-
-/* RX packet is ready in Xfer buffer #1 */
-#define WL1251_ACX_INTR_RX1_DATA       BIT(3)
-
-/* Event was entered to Event MBOX #A */
-#define WL1251_ACX_INTR_EVENT_A                BIT(4)
-
-/* Event was entered to Event MBOX #B */
-#define WL1251_ACX_INTR_EVENT_B                BIT(5)
-
-/* OBSOLETE */
-#define WL1251_ACX_INTR_WAKE_ON_HOST   BIT(6)
-
-/* Trace message on MBOX #A */
-#define WL1251_ACX_INTR_TRACE_A                BIT(7)
-
-/* Trace message on MBOX #B */
-#define WL1251_ACX_INTR_TRACE_B                BIT(8)
-
-/* Command processing completion */
-#define WL1251_ACX_INTR_CMD_COMPLETE   BIT(9)
-
-/* Init sequence is done */
-#define WL1251_ACX_INTR_INIT_COMPLETE  BIT(14)
-
-#define WL1251_ACX_INTR_ALL           0xFFFFFFFF
-
-enum {
-       ACX_WAKE_UP_CONDITIONS      = 0x0002,
-       ACX_MEM_CFG                 = 0x0003,
-       ACX_SLOT                    = 0x0004,
-       ACX_QUEUE_HEAD              = 0x0005, /* for MASTER mode only */
-       ACX_AC_CFG                  = 0x0007,
-       ACX_MEM_MAP                 = 0x0008,
-       ACX_AID                     = 0x000A,
-       ACX_RADIO_PARAM             = 0x000B, /* Not used */
-       ACX_CFG                     = 0x000C, /* Not used */
-       ACX_FW_REV                  = 0x000D,
-       ACX_MEDIUM_USAGE            = 0x000F,
-       ACX_RX_CFG                  = 0x0010,
-       ACX_TX_QUEUE_CFG            = 0x0011, /* FIXME: only used by wl1251 */
-       ACX_BSS_IN_PS               = 0x0012, /* for AP only */
-       ACX_STATISTICS              = 0x0013, /* Debug API */
-       ACX_FEATURE_CFG             = 0x0015,
-       ACX_MISC_CFG                = 0x0017, /* Not used */
-       ACX_TID_CFG                 = 0x001A,
-       ACX_BEACON_FILTER_OPT       = 0x001F,
-       ACX_LOW_RSSI                = 0x0020,
-       ACX_NOISE_HIST              = 0x0021,
-       ACX_HDK_VERSION             = 0x0022, /* ??? */
-       ACX_PD_THRESHOLD            = 0x0023,
-       ACX_DATA_PATH_PARAMS        = 0x0024, /* WO */
-       ACX_DATA_PATH_RESP_PARAMS   = 0x0024, /* RO */
-       ACX_CCA_THRESHOLD           = 0x0025,
-       ACX_EVENT_MBOX_MASK         = 0x0026,
-#ifdef FW_RUNNING_AS_AP
-       ACX_DTIM_PERIOD             = 0x0027, /* for AP only */
-#else
-       ACX_WR_TBTT_AND_DTIM        = 0x0027, /* STA only */
-#endif
-       ACX_ACI_OPTION_CFG          = 0x0029, /* OBSOLETE (for 1251)*/
-       ACX_GPIO_CFG                = 0x002A, /* Not used */
-       ACX_GPIO_SET                = 0x002B, /* Not used */
-       ACX_PM_CFG                  = 0x002C, /* To Be Documented */
-       ACX_CONN_MONIT_PARAMS       = 0x002D,
-       ACX_AVERAGE_RSSI            = 0x002E, /* Not used */
-       ACX_CONS_TX_FAILURE         = 0x002F,
-       ACX_BCN_DTIM_OPTIONS        = 0x0031,
-       ACX_SG_ENABLE               = 0x0032,
-       ACX_SG_CFG                  = 0x0033,
-       ACX_ANTENNA_DIVERSITY_CFG   = 0x0035, /* To Be Documented */
-       ACX_LOW_SNR                 = 0x0037, /* To Be Documented */
-       ACX_BEACON_FILTER_TABLE     = 0x0038,
-       ACX_ARP_IP_FILTER           = 0x0039,
-       ACX_ROAMING_STATISTICS_TBL  = 0x003B,
-       ACX_RATE_POLICY             = 0x003D,
-       ACX_CTS_PROTECTION          = 0x003E,
-       ACX_SLEEP_AUTH              = 0x003F,
-       ACX_PREAMBLE_TYPE           = 0x0040,
-       ACX_ERROR_CNT               = 0x0041,
-       ACX_FW_GEN_FRAME_RATES      = 0x0042,
-       ACX_IBSS_FILTER             = 0x0044,
-       ACX_SERVICE_PERIOD_TIMEOUT  = 0x0045,
-       ACX_TSF_INFO                = 0x0046,
-       ACX_CONFIG_PS_WMM           = 0x0049,
-       ACX_ENABLE_RX_DATA_FILTER   = 0x004A,
-       ACX_SET_RX_DATA_FILTER      = 0x004B,
-       ACX_GET_DATA_FILTER_STATISTICS = 0x004C,
-       ACX_POWER_LEVEL_TABLE       = 0x004D,
-       ACX_BET_ENABLE              = 0x0050,
-       DOT11_STATION_ID            = 0x1001,
-       DOT11_RX_MSDU_LIFE_TIME     = 0x1004,
-       DOT11_CUR_TX_PWR            = 0x100D,
-       DOT11_DEFAULT_KEY           = 0x1010,
-       DOT11_RX_DOT11_MODE         = 0x1012,
-       DOT11_RTS_THRESHOLD         = 0x1013,
-       DOT11_GROUP_ADDRESS_TBL     = 0x1014,
-
-       MAX_DOT11_IE = DOT11_GROUP_ADDRESS_TBL,
-
-       MAX_IE = 0xFFFF
-};
-
-
-int wl1251_acx_frame_rates(struct wl1251 *wl, u8 ctrl_rate, u8 ctrl_mod,
-                          u8 mgt_rate, u8 mgt_mod);
-int wl1251_acx_station_id(struct wl1251 *wl);
-int wl1251_acx_default_key(struct wl1251 *wl, u8 key_id);
-int wl1251_acx_wake_up_conditions(struct wl1251 *wl, u8 wake_up_event,
-                                 u8 listen_interval);
-int wl1251_acx_sleep_auth(struct wl1251 *wl, u8 sleep_auth);
-int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len);
-int wl1251_acx_tx_power(struct wl1251 *wl, int power);
-int wl1251_acx_feature_cfg(struct wl1251 *wl);
-int wl1251_acx_mem_map(struct wl1251 *wl,
-                      struct acx_header *mem_map, size_t len);
-int wl1251_acx_data_path_params(struct wl1251 *wl,
-                               struct acx_data_path_params_resp *data_path);
-int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time);
-int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter);
-int wl1251_acx_pd_threshold(struct wl1251 *wl);
-int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time);
-int wl1251_acx_group_address_tbl(struct wl1251 *wl);
-int wl1251_acx_service_period_timeout(struct wl1251 *wl);
-int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold);
-int wl1251_acx_beacon_filter_opt(struct wl1251 *wl, bool enable_filter);
-int wl1251_acx_beacon_filter_table(struct wl1251 *wl);
-int wl1251_acx_conn_monit_params(struct wl1251 *wl);
-int wl1251_acx_sg_enable(struct wl1251 *wl);
-int wl1251_acx_sg_cfg(struct wl1251 *wl);
-int wl1251_acx_cca_threshold(struct wl1251 *wl);
-int wl1251_acx_bcn_dtim_options(struct wl1251 *wl);
-int wl1251_acx_aid(struct wl1251 *wl, u16 aid);
-int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask);
-int wl1251_acx_low_rssi(struct wl1251 *wl, s8 threshold, u8 weight,
-                       u8 depth, enum wl1251_acx_low_rssi_type type);
-int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble);
-int wl1251_acx_cts_protect(struct wl1251 *wl,
-                           enum acx_ctsprotect_type ctsprotect);
-int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats);
-int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime);
-int wl1251_acx_rate_policies(struct wl1251 *wl);
-int wl1251_acx_mem_cfg(struct wl1251 *wl);
-int wl1251_acx_wr_tbtt_and_dtim(struct wl1251 *wl, u16 tbtt, u8 dtim);
-int wl1251_acx_bet_enable(struct wl1251 *wl, enum wl1251_acx_bet_mode mode,
-                         u8 max_consecutive);
-int wl1251_acx_ac_cfg(struct wl1251 *wl, u8 ac, u8 cw_min, u16 cw_max,
-                     u8 aifs, u16 txop);
-int wl1251_acx_tid_cfg(struct wl1251 *wl, u8 queue,
-                      enum wl1251_acx_channel_type type,
-                      u8 tsid, enum wl1251_acx_ps_scheme ps_scheme,
-                      enum wl1251_acx_ack_policy ack_policy);
-
-#endif /* __WL1251_ACX_H__ */
diff --git a/drivers/net/wireless/wl1251/boot.c b/drivers/net/wireless/wl1251/boot.c
deleted file mode 100644 (file)
index a2e5241..0000000
+++ /dev/null
@@ -1,554 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/slab.h>
-
-#include "reg.h"
-#include "boot.h"
-#include "io.h"
-#include "spi.h"
-#include "event.h"
-#include "acx.h"
-
-void wl1251_boot_target_enable_interrupts(struct wl1251 *wl)
-{
-       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
-       wl1251_reg_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
-}
-
-int wl1251_boot_soft_reset(struct wl1251 *wl)
-{
-       unsigned long timeout;
-       u32 boot_data;
-
-       /* perform soft reset */
-       wl1251_reg_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
-
-       /* SOFT_RESET is self clearing */
-       timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
-       while (1) {
-               boot_data = wl1251_reg_read32(wl, ACX_REG_SLV_SOFT_RESET);
-               wl1251_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
-               if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
-                       break;
-
-               if (time_after(jiffies, timeout)) {
-                       /* 1.2 check pWhalBus->uSelfClearTime if the
-                        * timeout was reached */
-                       wl1251_error("soft reset timeout");
-                       return -1;
-               }
-
-               udelay(SOFT_RESET_STALL_TIME);
-       }
-
-       /* disable Rx/Tx */
-       wl1251_reg_write32(wl, ENABLE, 0x0);
-
-       /* disable auto calibration on start*/
-       wl1251_reg_write32(wl, SPARE_A2, 0xffff);
-
-       return 0;
-}
-
-int wl1251_boot_init_seq(struct wl1251 *wl)
-{
-       u32 scr_pad6, init_data, tmp, elp_cmd, ref_freq;
-
-       /*
-        * col #1: INTEGER_DIVIDER
-        * col #2: FRACTIONAL_DIVIDER
-        * col #3: ATTN_BB
-        * col #4: ALPHA_BB
-        * col #5: STOP_TIME_BB
-        * col #6: BB_PLL_LOOP_FILTER
-        */
-       static const u32 LUT[REF_FREQ_NUM][LUT_PARAM_NUM] = {
-
-               {   83, 87381,  0xB, 5, 0xF00,  3}, /* REF_FREQ_19_2*/
-               {   61, 141154, 0xB, 5, 0x1450, 2}, /* REF_FREQ_26_0*/
-               {   41, 174763, 0xC, 6, 0x2D00, 1}, /* REF_FREQ_38_4*/
-               {   40, 0,      0xC, 6, 0x2EE0, 1}, /* REF_FREQ_40_0*/
-               {   47, 162280, 0xC, 6, 0x2760, 1}  /* REF_FREQ_33_6        */
-       };
-
-       /* read NVS params */
-       scr_pad6 = wl1251_reg_read32(wl, SCR_PAD6);
-       wl1251_debug(DEBUG_BOOT, "scr_pad6 0x%x", scr_pad6);
-
-       /* read ELP_CMD */
-       elp_cmd = wl1251_reg_read32(wl, ELP_CMD);
-       wl1251_debug(DEBUG_BOOT, "elp_cmd 0x%x", elp_cmd);
-
-       /* set the BB calibration time to be 300 usec (PLL_CAL_TIME) */
-       ref_freq = scr_pad6 & 0x000000FF;
-       wl1251_debug(DEBUG_BOOT, "ref_freq 0x%x", ref_freq);
-
-       wl1251_reg_write32(wl, PLL_CAL_TIME, 0x9);
-
-       /*
-        * PG 1.2: set the clock buffer time to be 210 usec (CLK_BUF_TIME)
-        */
-       wl1251_reg_write32(wl, CLK_BUF_TIME, 0x6);
-
-       /*
-        * set the clock detect feature to work in the restart wu procedure
-        * (ELP_CFG_MODE[14]) and Select the clock source type
-        * (ELP_CFG_MODE[13:12])
-        */
-       tmp = ((scr_pad6 & 0x0000FF00) << 4) | 0x00004000;
-       wl1251_reg_write32(wl, ELP_CFG_MODE, tmp);
-
-       /* PG 1.2: enable the BB PLL fix. Enable the PLL_LIMP_CLK_EN_CMD */
-       elp_cmd |= 0x00000040;
-       wl1251_reg_write32(wl, ELP_CMD, elp_cmd);
-
-       /* PG 1.2: Set the BB PLL stable time to be 1000usec
-        * (PLL_STABLE_TIME) */
-       wl1251_reg_write32(wl, CFG_PLL_SYNC_CNT, 0x20);
-
-       /* PG 1.2: read clock request time */
-       init_data = wl1251_reg_read32(wl, CLK_REQ_TIME);
-
-       /*
-        * PG 1.2: set the clock request time to be ref_clk_settling_time -
-        * 1ms = 4ms
-        */
-       if (init_data > 0x21)
-               tmp = init_data - 0x21;
-       else
-               tmp = 0;
-       wl1251_reg_write32(wl, CLK_REQ_TIME, tmp);
-
-       /* set BB PLL configurations in RF AFE */
-       wl1251_reg_write32(wl, 0x003058cc, 0x4B5);
-
-       /* set RF_AFE_REG_5 */
-       wl1251_reg_write32(wl, 0x003058d4, 0x50);
-
-       /* set RF_AFE_CTRL_REG_2 */
-       wl1251_reg_write32(wl, 0x00305948, 0x11c001);
-
-       /*
-        * change RF PLL and BB PLL divider for VCO clock and adjust VCO
-        * bais current(RF_AFE_REG_13)
-        */
-       wl1251_reg_write32(wl, 0x003058f4, 0x1e);
-
-       /* set BB PLL configurations */
-       tmp = LUT[ref_freq][LUT_PARAM_INTEGER_DIVIDER] | 0x00017000;
-       wl1251_reg_write32(wl, 0x00305840, tmp);
-
-       /* set fractional divider according to Appendix C-BB PLL
-        * Calculations
-        */
-       tmp = LUT[ref_freq][LUT_PARAM_FRACTIONAL_DIVIDER];
-       wl1251_reg_write32(wl, 0x00305844, tmp);
-
-       /* set the initial data for the sigma delta */
-       wl1251_reg_write32(wl, 0x00305848, 0x3039);
-
-       /*
-        * set the accumulator attenuation value, calibration loop1
-        * (alpha), calibration loop2 (beta), calibration loop3 (gamma) and
-        * the VCO gain
-        */
-       tmp = (LUT[ref_freq][LUT_PARAM_ATTN_BB] << 16) |
-               (LUT[ref_freq][LUT_PARAM_ALPHA_BB] << 12) | 0x1;
-       wl1251_reg_write32(wl, 0x00305854, tmp);
-
-       /*
-        * set the calibration stop time after holdoff time expires and set
-        * settling time HOLD_OFF_TIME_BB
-        */
-       tmp = LUT[ref_freq][LUT_PARAM_STOP_TIME_BB] | 0x000A0000;
-       wl1251_reg_write32(wl, 0x00305858, tmp);
-
-       /*
-        * set BB PLL Loop filter capacitor3- BB_C3[2:0] and set BB PLL
-        * constant leakage current to linearize PFD to 0uA -
-        * BB_ILOOPF[7:3]
-        */
-       tmp = LUT[ref_freq][LUT_PARAM_BB_PLL_LOOP_FILTER] | 0x00000030;
-       wl1251_reg_write32(wl, 0x003058f8, tmp);
-
-       /*
-        * set regulator output voltage for n divider to
-        * 1.35-BB_REFDIV[1:0], set charge pump current- BB_CPGAIN[4:2],
-        * set BB PLL Loop filter capacitor2- BB_C2[7:5], set gain of BB
-        * PLL auto-call to normal mode- BB_CALGAIN_3DB[8]
-        */
-       wl1251_reg_write32(wl, 0x003058f0, 0x29);
-
-       /* enable restart wakeup sequence (ELP_CMD[0]) */
-       wl1251_reg_write32(wl, ELP_CMD, elp_cmd | 0x1);
-
-       /* restart sequence completed */
-       udelay(2000);
-
-       return 0;
-}
-
-static void wl1251_boot_set_ecpu_ctrl(struct wl1251 *wl, u32 flag)
-{
-       u32 cpu_ctrl;
-
-       /* 10.5.0 run the firmware (I) */
-       cpu_ctrl = wl1251_reg_read32(wl, ACX_REG_ECPU_CONTROL);
-
-       /* 10.5.1 run the firmware (II) */
-       cpu_ctrl &= ~flag;
-       wl1251_reg_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl);
-}
-
-int wl1251_boot_run_firmware(struct wl1251 *wl)
-{
-       int loop, ret;
-       u32 chip_id, acx_intr;
-
-       wl1251_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
-
-       chip_id = wl1251_reg_read32(wl, CHIP_ID_B);
-
-       wl1251_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
-
-       if (chip_id != wl->chip_id) {
-               wl1251_error("chip id doesn't match after firmware boot");
-               return -EIO;
-       }
-
-       /* wait for init to complete */
-       loop = 0;
-       while (loop++ < INIT_LOOP) {
-               udelay(INIT_LOOP_DELAY);
-               acx_intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
-
-               if (acx_intr == 0xffffffff) {
-                       wl1251_error("error reading hardware complete "
-                                    "init indication");
-                       return -EIO;
-               }
-               /* check that ACX_INTR_INIT_COMPLETE is enabled */
-               else if (acx_intr & WL1251_ACX_INTR_INIT_COMPLETE) {
-                       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
-                                          WL1251_ACX_INTR_INIT_COMPLETE);
-                       break;
-               }
-       }
-
-       if (loop > INIT_LOOP) {
-               wl1251_error("timeout waiting for the hardware to "
-                            "complete initialization");
-               return -EIO;
-       }
-
-       /* get hardware config command mail box */
-       wl->cmd_box_addr = wl1251_reg_read32(wl, REG_COMMAND_MAILBOX_PTR);
-
-       /* get hardware config event mail box */
-       wl->event_box_addr = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
-
-       /* set the working partition to its "running" mode offset */
-       wl1251_set_partition(wl, WL1251_PART_WORK_MEM_START,
-                            WL1251_PART_WORK_MEM_SIZE,
-                            WL1251_PART_WORK_REG_START,
-                            WL1251_PART_WORK_REG_SIZE);
-
-       wl1251_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
-                    wl->cmd_box_addr, wl->event_box_addr);
-
-       wl1251_acx_fw_version(wl, wl->fw_ver, sizeof(wl->fw_ver));
-
-       /*
-        * in case of full asynchronous mode the firmware event must be
-        * ready to receive event from the command mailbox
-        */
-
-       /* enable gpio interrupts */
-       wl1251_enable_interrupts(wl);
-
-       /* Enable target's interrupts */
-       wl->intr_mask = WL1251_ACX_INTR_RX0_DATA |
-               WL1251_ACX_INTR_RX1_DATA |
-               WL1251_ACX_INTR_TX_RESULT |
-               WL1251_ACX_INTR_EVENT_A |
-               WL1251_ACX_INTR_EVENT_B |
-               WL1251_ACX_INTR_INIT_COMPLETE;
-       wl1251_boot_target_enable_interrupts(wl);
-
-       wl->event_mask = SCAN_COMPLETE_EVENT_ID | BSS_LOSE_EVENT_ID |
-               SYNCHRONIZATION_TIMEOUT_EVENT_ID |
-               ROAMING_TRIGGER_LOW_RSSI_EVENT_ID |
-               ROAMING_TRIGGER_REGAINED_RSSI_EVENT_ID |
-               REGAINED_BSS_EVENT_ID | BT_PTA_SENSE_EVENT_ID |
-               BT_PTA_PREDICTION_EVENT_ID | JOIN_EVENT_COMPLETE_ID;
-
-       ret = wl1251_event_unmask(wl);
-       if (ret < 0) {
-               wl1251_error("EVENT mask setting failed");
-               return ret;
-       }
-
-       wl1251_event_mbox_config(wl);
-
-       /* firmware startup completed */
-       return 0;
-}
-
-static int wl1251_boot_upload_firmware(struct wl1251 *wl)
-{
-       int addr, chunk_num, partition_limit;
-       size_t fw_data_len, len;
-       u8 *p, *buf;
-
-       /* whal_FwCtrl_LoadFwImageSm() */
-
-       wl1251_debug(DEBUG_BOOT, "chip id before fw upload: 0x%x",
-                    wl1251_reg_read32(wl, CHIP_ID_B));
-
-       /* 10.0 check firmware length and set partition */
-       fw_data_len =  (wl->fw[4] << 24) | (wl->fw[5] << 16) |
-               (wl->fw[6] << 8) | (wl->fw[7]);
-
-       wl1251_debug(DEBUG_BOOT, "fw_data_len %zu chunk_size %d", fw_data_len,
-               CHUNK_SIZE);
-
-       if ((fw_data_len % 4) != 0) {
-               wl1251_error("firmware length not multiple of four");
-               return -EIO;
-       }
-
-       buf = kmalloc(CHUNK_SIZE, GFP_KERNEL);
-       if (!buf) {
-               wl1251_error("allocation for firmware upload chunk failed");
-               return -ENOMEM;
-       }
-
-       wl1251_set_partition(wl, WL1251_PART_DOWN_MEM_START,
-                            WL1251_PART_DOWN_MEM_SIZE,
-                            WL1251_PART_DOWN_REG_START,
-                            WL1251_PART_DOWN_REG_SIZE);
-
-       /* 10.1 set partition limit and chunk num */
-       chunk_num = 0;
-       partition_limit = WL1251_PART_DOWN_MEM_SIZE;
-
-       while (chunk_num < fw_data_len / CHUNK_SIZE) {
-               /* 10.2 update partition, if needed */
-               addr = WL1251_PART_DOWN_MEM_START +
-                       (chunk_num + 2) * CHUNK_SIZE;
-               if (addr > partition_limit) {
-                       addr = WL1251_PART_DOWN_MEM_START +
-                               chunk_num * CHUNK_SIZE;
-                       partition_limit = chunk_num * CHUNK_SIZE +
-                               WL1251_PART_DOWN_MEM_SIZE;
-                       wl1251_set_partition(wl,
-                                            addr,
-                                            WL1251_PART_DOWN_MEM_SIZE,
-                                            WL1251_PART_DOWN_REG_START,
-                                            WL1251_PART_DOWN_REG_SIZE);
-               }
-
-               /* 10.3 upload the chunk */
-               addr = WL1251_PART_DOWN_MEM_START + chunk_num * CHUNK_SIZE;
-               p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
-               wl1251_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
-                            p, addr);
-
-               /* need to copy the chunk for dma */
-               len = CHUNK_SIZE;
-               memcpy(buf, p, len);
-               wl1251_mem_write(wl, addr, buf, len);
-
-               chunk_num++;
-       }
-
-       /* 10.4 upload the last chunk */
-       addr = WL1251_PART_DOWN_MEM_START + chunk_num * CHUNK_SIZE;
-       p = wl->fw + FW_HDR_SIZE + chunk_num * CHUNK_SIZE;
-
-       /* need to copy the chunk for dma */
-       len = fw_data_len % CHUNK_SIZE;
-       memcpy(buf, p, len);
-
-       wl1251_debug(DEBUG_BOOT, "uploading fw last chunk (%zu B) 0x%p to 0x%x",
-                    len, p, addr);
-       wl1251_mem_write(wl, addr, buf, len);
-
-       kfree(buf);
-
-       return 0;
-}
-
-static int wl1251_boot_upload_nvs(struct wl1251 *wl)
-{
-       size_t nvs_len, nvs_bytes_written, burst_len;
-       int nvs_start, i;
-       u32 dest_addr, val;
-       u8 *nvs_ptr, *nvs;
-
-       nvs = wl->nvs;
-       if (nvs == NULL)
-               return -ENODEV;
-
-       nvs_ptr = nvs;
-
-       nvs_len = wl->nvs_len;
-       nvs_start = wl->fw_len;
-
-       /*
-        * Layout before the actual NVS tables:
-        * 1 byte : burst length.
-        * 2 bytes: destination address.
-        * n bytes: data to burst copy.
-        *
-        * This is ended by a 0 length, then the NVS tables.
-        */
-
-       while (nvs_ptr[0]) {
-               burst_len = nvs_ptr[0];
-               dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
-
-               /* We move our pointer to the data */
-               nvs_ptr += 3;
-
-               for (i = 0; i < burst_len; i++) {
-                       val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
-                              | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
-
-                       wl1251_debug(DEBUG_BOOT,
-                                    "nvs burst write 0x%x: 0x%x",
-                                    dest_addr, val);
-                       wl1251_mem_write32(wl, dest_addr, val);
-
-                       nvs_ptr += 4;
-                       dest_addr += 4;
-               }
-       }
-
-       /*
-        * We've reached the first zero length, the first NVS table
-        * is 7 bytes further.
-        */
-       nvs_ptr += 7;
-       nvs_len -= nvs_ptr - nvs;
-       nvs_len = ALIGN(nvs_len, 4);
-
-       /* Now we must set the partition correctly */
-       wl1251_set_partition(wl, nvs_start,
-                            WL1251_PART_DOWN_MEM_SIZE,
-                            WL1251_PART_DOWN_REG_START,
-                            WL1251_PART_DOWN_REG_SIZE);
-
-       /* And finally we upload the NVS tables */
-       nvs_bytes_written = 0;
-       while (nvs_bytes_written < nvs_len) {
-               val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
-                      | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
-
-               wl1251_debug(DEBUG_BOOT,
-                            "nvs write table 0x%x: 0x%x",
-                            nvs_start, val);
-               wl1251_mem_write32(wl, nvs_start, val);
-
-               nvs_ptr += 4;
-               nvs_bytes_written += 4;
-               nvs_start += 4;
-       }
-
-       return 0;
-}
-
-int wl1251_boot(struct wl1251 *wl)
-{
-       int ret = 0, minor_minor_e2_ver;
-       u32 tmp, boot_data;
-
-       /* halt embedded ARM CPU while loading firmware */
-       wl1251_reg_write32(wl, ACX_REG_ECPU_CONTROL, ECPU_CONTROL_HALT);
-
-       ret = wl1251_boot_soft_reset(wl);
-       if (ret < 0)
-               goto out;
-
-       /* 2. start processing NVS file */
-       if (wl->use_eeprom) {
-               wl1251_reg_write32(wl, ACX_REG_EE_START, START_EEPROM_MGR);
-               /* Wait for EEPROM NVS burst read to complete */
-               msleep(40);
-               wl1251_reg_write32(wl, ACX_EEPROMLESS_IND_REG, USE_EEPROM);
-       } else {
-               ret = wl1251_boot_upload_nvs(wl);
-               if (ret < 0)
-                       goto out;
-
-               /* write firmware's last address (ie. it's length) to
-                * ACX_EEPROMLESS_IND_REG */
-               wl1251_reg_write32(wl, ACX_EEPROMLESS_IND_REG, wl->fw_len);
-       }
-
-       /* 6. read the EEPROM parameters */
-       tmp = wl1251_reg_read32(wl, SCR_PAD2);
-
-       /* 7. read bootdata */
-       wl->boot_attr.radio_type = (tmp & 0x0000FF00) >> 8;
-       wl->boot_attr.major = (tmp & 0x00FF0000) >> 16;
-       tmp = wl1251_reg_read32(wl, SCR_PAD3);
-
-       /* 8. check bootdata and call restart sequence */
-       wl->boot_attr.minor = (tmp & 0x00FF0000) >> 16;
-       minor_minor_e2_ver = (tmp & 0xFF000000) >> 24;
-
-       wl1251_debug(DEBUG_BOOT, "radioType 0x%x majorE2Ver 0x%x "
-                    "minorE2Ver 0x%x minor_minor_e2_ver 0x%x",
-                    wl->boot_attr.radio_type, wl->boot_attr.major,
-                    wl->boot_attr.minor, minor_minor_e2_ver);
-
-       ret = wl1251_boot_init_seq(wl);
-       if (ret < 0)
-               goto out;
-
-       /* 9. NVS processing done */
-       boot_data = wl1251_reg_read32(wl, ACX_REG_ECPU_CONTROL);
-
-       wl1251_debug(DEBUG_BOOT, "halt boot_data 0x%x", boot_data);
-
-       /* 10. check that ECPU_CONTROL_HALT bits are set in
-        * pWhalBus->uBootData and start uploading firmware
-        */
-       if ((boot_data & ECPU_CONTROL_HALT) == 0) {
-               wl1251_error("boot failed, ECPU_CONTROL_HALT not set");
-               ret = -EIO;
-               goto out;
-       }
-
-       ret = wl1251_boot_upload_firmware(wl);
-       if (ret < 0)
-               goto out;
-
-       /* 10.5 start firmware */
-       ret = wl1251_boot_run_firmware(wl);
-       if (ret < 0)
-               goto out;
-
-out:
-       return ret;
-}
diff --git a/drivers/net/wireless/wl1251/boot.h b/drivers/net/wireless/wl1251/boot.h
deleted file mode 100644 (file)
index 7661bc5..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __BOOT_H__
-#define __BOOT_H__
-
-#include "wl1251.h"
-
-int wl1251_boot_soft_reset(struct wl1251 *wl);
-int wl1251_boot_init_seq(struct wl1251 *wl);
-int wl1251_boot_run_firmware(struct wl1251 *wl);
-void wl1251_boot_target_enable_interrupts(struct wl1251 *wl);
-int wl1251_boot(struct wl1251 *wl);
-
-/* number of times we try to read the INIT interrupt */
-#define INIT_LOOP 20000
-
-/* delay between retries */
-#define INIT_LOOP_DELAY 50
-
-#endif
diff --git a/drivers/net/wireless/wl1251/cmd.c b/drivers/net/wireless/wl1251/cmd.c
deleted file mode 100644 (file)
index d14d69d..0000000
+++ /dev/null
@@ -1,496 +0,0 @@
-#include "cmd.h"
-
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/crc7.h>
-
-#include "wl1251.h"
-#include "reg.h"
-#include "io.h"
-#include "ps.h"
-#include "acx.h"
-
-/**
- * send command to firmware
- *
- * @wl: wl struct
- * @id: command id
- * @buf: buffer containing the command, must work with dma
- * @len: length of the buffer
- */
-int wl1251_cmd_send(struct wl1251 *wl, u16 id, void *buf, size_t len)
-{
-       struct wl1251_cmd_header *cmd;
-       unsigned long timeout;
-       u32 intr;
-       int ret = 0;
-
-       cmd = buf;
-       cmd->id = id;
-       cmd->status = 0;
-
-       WARN_ON(len % 4 != 0);
-
-       wl1251_mem_write(wl, wl->cmd_box_addr, buf, len);
-
-       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
-
-       timeout = jiffies + msecs_to_jiffies(WL1251_COMMAND_TIMEOUT);
-
-       intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
-       while (!(intr & WL1251_ACX_INTR_CMD_COMPLETE)) {
-               if (time_after(jiffies, timeout)) {
-                       wl1251_error("command complete timeout");
-                       ret = -ETIMEDOUT;
-                       goto out;
-               }
-
-               msleep(1);
-
-               intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
-       }
-
-       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
-                          WL1251_ACX_INTR_CMD_COMPLETE);
-
-out:
-       return ret;
-}
-
-/**
- * send test command to firmware
- *
- * @wl: wl struct
- * @buf: buffer containing the command, with all headers, must work with dma
- * @len: length of the buffer
- * @answer: is answer needed
- */
-int wl1251_cmd_test(struct wl1251 *wl, void *buf, size_t buf_len, u8 answer)
-{
-       int ret;
-
-       wl1251_debug(DEBUG_CMD, "cmd test");
-
-       ret = wl1251_cmd_send(wl, CMD_TEST, buf, buf_len);
-
-       if (ret < 0) {
-               wl1251_warning("TEST command failed");
-               return ret;
-       }
-
-       if (answer) {
-               struct wl1251_command *cmd_answer;
-
-               /*
-                * The test command got in, we can read the answer.
-                * The answer would be a wl1251_command, where the
-                * parameter array contains the actual answer.
-                */
-               wl1251_mem_read(wl, wl->cmd_box_addr, buf, buf_len);
-
-               cmd_answer = buf;
-
-               if (cmd_answer->header.status != CMD_STATUS_SUCCESS)
-                       wl1251_error("TEST command answer error: %d",
-                                    cmd_answer->header.status);
-       }
-
-       return 0;
-}
-
-/**
- * read acx from firmware
- *
- * @wl: wl struct
- * @id: acx id
- * @buf: buffer for the response, including all headers, must work with dma
- * @len: length of buf
- */
-int wl1251_cmd_interrogate(struct wl1251 *wl, u16 id, void *buf, size_t len)
-{
-       struct acx_header *acx = buf;
-       int ret;
-
-       wl1251_debug(DEBUG_CMD, "cmd interrogate");
-
-       acx->id = id;
-
-       /* payload length, does not include any headers */
-       acx->len = len - sizeof(*acx);
-
-       ret = wl1251_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1251_error("INTERROGATE command failed");
-               goto out;
-       }
-
-       /* the interrogate command got in, we can read the answer */
-       wl1251_mem_read(wl, wl->cmd_box_addr, buf, len);
-
-       acx = buf;
-       if (acx->cmd.status != CMD_STATUS_SUCCESS)
-               wl1251_error("INTERROGATE command error: %d",
-                            acx->cmd.status);
-
-out:
-       return ret;
-}
-
-/**
- * write acx value to firmware
- *
- * @wl: wl struct
- * @id: acx id
- * @buf: buffer containing acx, including all headers, must work with dma
- * @len: length of buf
- */
-int wl1251_cmd_configure(struct wl1251 *wl, u16 id, void *buf, size_t len)
-{
-       struct acx_header *acx = buf;
-       int ret;
-
-       wl1251_debug(DEBUG_CMD, "cmd configure");
-
-       acx->id = id;
-
-       /* payload length, does not include any headers */
-       acx->len = len - sizeof(*acx);
-
-       ret = wl1251_cmd_send(wl, CMD_CONFIGURE, acx, len);
-       if (ret < 0) {
-               wl1251_warning("CONFIGURE command NOK");
-               return ret;
-       }
-
-       return 0;
-}
-
-int wl1251_cmd_vbm(struct wl1251 *wl, u8 identity,
-                  void *bitmap, u16 bitmap_len, u8 bitmap_control)
-{
-       struct wl1251_cmd_vbm_update *vbm;
-       int ret;
-
-       wl1251_debug(DEBUG_CMD, "cmd vbm");
-
-       vbm = kzalloc(sizeof(*vbm), GFP_KERNEL);
-       if (!vbm) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* Count and period will be filled by the target */
-       vbm->tim.bitmap_ctrl = bitmap_control;
-       if (bitmap_len > PARTIAL_VBM_MAX) {
-               wl1251_warning("cmd vbm len is %d B, truncating to %d",
-                              bitmap_len, PARTIAL_VBM_MAX);
-               bitmap_len = PARTIAL_VBM_MAX;
-       }
-       memcpy(vbm->tim.pvb_field, bitmap, bitmap_len);
-       vbm->tim.identity = identity;
-       vbm->tim.length = bitmap_len + 3;
-
-       vbm->len = cpu_to_le16(bitmap_len + 5);
-
-       ret = wl1251_cmd_send(wl, CMD_VBM, vbm, sizeof(*vbm));
-       if (ret < 0) {
-               wl1251_error("VBM command failed");
-               goto out;
-       }
-
-out:
-       kfree(vbm);
-       return ret;
-}
-
-int wl1251_cmd_data_path(struct wl1251 *wl, u8 channel, bool enable)
-{
-       struct cmd_enabledisable_path *cmd;
-       int ret;
-       u16 cmd_rx, cmd_tx;
-
-       wl1251_debug(DEBUG_CMD, "cmd data path");
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       cmd->channel = channel;
-
-       if (enable) {
-               cmd_rx = CMD_ENABLE_RX;
-               cmd_tx = CMD_ENABLE_TX;
-       } else {
-               cmd_rx = CMD_DISABLE_RX;
-               cmd_tx = CMD_DISABLE_TX;
-       }
-
-       ret = wl1251_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd));
-       if (ret < 0) {
-               wl1251_error("rx %s cmd for channel %d failed",
-                            enable ? "start" : "stop", channel);
-               goto out;
-       }
-
-       wl1251_debug(DEBUG_BOOT, "rx %s cmd channel %d",
-                    enable ? "start" : "stop", channel);
-
-       ret = wl1251_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd));
-       if (ret < 0) {
-               wl1251_error("tx %s cmd for channel %d failed",
-                            enable ? "start" : "stop", channel);
-               goto out;
-       }
-
-       wl1251_debug(DEBUG_BOOT, "tx %s cmd channel %d",
-                    enable ? "start" : "stop", channel);
-
-out:
-       kfree(cmd);
-       return ret;
-}
-
-int wl1251_cmd_join(struct wl1251 *wl, u8 bss_type, u8 channel,
-                   u16 beacon_interval, u8 dtim_interval)
-{
-       struct cmd_join *join;
-       int ret, i;
-       u8 *bssid;
-
-       join = kzalloc(sizeof(*join), GFP_KERNEL);
-       if (!join) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wl1251_debug(DEBUG_CMD, "cmd join%s ch %d %d/%d",
-                    bss_type == BSS_TYPE_IBSS ? " ibss" : "",
-                    channel, beacon_interval, dtim_interval);
-
-       /* Reverse order BSSID */
-       bssid = (u8 *) &join->bssid_lsb;
-       for (i = 0; i < ETH_ALEN; i++)
-               bssid[i] = wl->bssid[ETH_ALEN - i - 1];
-
-       join->rx_config_options = wl->rx_config;
-       join->rx_filter_options = wl->rx_filter;
-
-       /*
-        * FIXME: disable temporarily all filters because after commit
-        * 9cef8737 "mac80211: fix managed mode BSSID handling" broke
-        * association. The filter logic needs to be implemented properly
-        * and once that is done, this hack can be removed.
-        */
-       join->rx_config_options = 0;
-       join->rx_filter_options = WL1251_DEFAULT_RX_FILTER;
-
-       join->basic_rate_set = RATE_MASK_1MBPS | RATE_MASK_2MBPS |
-               RATE_MASK_5_5MBPS | RATE_MASK_11MBPS;
-
-       join->beacon_interval = beacon_interval;
-       join->dtim_interval = dtim_interval;
-       join->bss_type = bss_type;
-       join->channel = channel;
-       join->ctrl = JOIN_CMD_CTRL_TX_FLUSH;
-
-       ret = wl1251_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join));
-       if (ret < 0) {
-               wl1251_error("failed to initiate cmd join");
-               goto out;
-       }
-
-out:
-       kfree(join);
-       return ret;
-}
-
-int wl1251_cmd_ps_mode(struct wl1251 *wl, u8 ps_mode)
-{
-       struct wl1251_cmd_ps_params *ps_params = NULL;
-       int ret = 0;
-
-       wl1251_debug(DEBUG_CMD, "cmd set ps mode");
-
-       ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
-       if (!ps_params) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       ps_params->ps_mode = ps_mode;
-       ps_params->send_null_data = 1;
-       ps_params->retries = 5;
-       ps_params->hang_over_period = 128;
-       ps_params->null_data_rate = 1; /* 1 Mbps */
-
-       ret = wl1251_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
-                             sizeof(*ps_params));
-       if (ret < 0) {
-               wl1251_error("cmd set_ps_mode failed");
-               goto out;
-       }
-
-out:
-       kfree(ps_params);
-       return ret;
-}
-
-int wl1251_cmd_read_memory(struct wl1251 *wl, u32 addr, void *answer,
-                          size_t len)
-{
-       struct cmd_read_write_memory *cmd;
-       int ret = 0;
-
-       wl1251_debug(DEBUG_CMD, "cmd read memory");
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       WARN_ON(len > MAX_READ_SIZE);
-       len = min_t(size_t, len, MAX_READ_SIZE);
-
-       cmd->addr = addr;
-       cmd->size = len;
-
-       ret = wl1251_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd));
-       if (ret < 0) {
-               wl1251_error("read memory command failed: %d", ret);
-               goto out;
-       }
-
-       /* the read command got in, we can now read the answer */
-       wl1251_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd));
-
-       if (cmd->header.status != CMD_STATUS_SUCCESS)
-               wl1251_error("error in read command result: %d",
-                            cmd->header.status);
-
-       memcpy(answer, cmd->value, len);
-
-out:
-       kfree(cmd);
-       return ret;
-}
-
-int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id,
-                           void *buf, size_t buf_len)
-{
-       struct wl1251_cmd_packet_template *cmd;
-       size_t cmd_len;
-       int ret = 0;
-
-       wl1251_debug(DEBUG_CMD, "cmd template %d", cmd_id);
-
-       WARN_ON(buf_len > WL1251_MAX_TEMPLATE_SIZE);
-       buf_len = min_t(size_t, buf_len, WL1251_MAX_TEMPLATE_SIZE);
-       cmd_len = ALIGN(sizeof(*cmd) + buf_len, 4);
-
-       cmd = kzalloc(cmd_len, GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       cmd->size = cpu_to_le16(buf_len);
-
-       if (buf)
-               memcpy(cmd->data, buf, buf_len);
-
-       ret = wl1251_cmd_send(wl, cmd_id, cmd, cmd_len);
-       if (ret < 0) {
-               wl1251_warning("cmd set_template failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(cmd);
-       return ret;
-}
-
-int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len,
-                   struct ieee80211_channel *channels[],
-                   unsigned int n_channels, unsigned int n_probes)
-{
-       struct wl1251_cmd_scan *cmd;
-       int i, ret = 0;
-
-       wl1251_debug(DEBUG_CMD, "cmd scan");
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd)
-               return -ENOMEM;
-
-       cmd->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
-       cmd->params.rx_filter_options = cpu_to_le32(CFG_RX_PRSP_EN |
-                                                   CFG_RX_MGMT_EN |
-                                                   CFG_RX_BCN_EN);
-       cmd->params.scan_options = 0;
-       cmd->params.num_channels = n_channels;
-       cmd->params.num_probe_requests = n_probes;
-       cmd->params.tx_rate = cpu_to_le16(1 << 1); /* 2 Mbps */
-       cmd->params.tid_trigger = 0;
-
-       for (i = 0; i < n_channels; i++) {
-               cmd->channels[i].min_duration =
-                       cpu_to_le32(WL1251_SCAN_MIN_DURATION);
-               cmd->channels[i].max_duration =
-                       cpu_to_le32(WL1251_SCAN_MAX_DURATION);
-               memset(&cmd->channels[i].bssid_lsb, 0xff, 4);
-               memset(&cmd->channels[i].bssid_msb, 0xff, 2);
-               cmd->channels[i].early_termination = 0;
-               cmd->channels[i].tx_power_att = 0;
-               cmd->channels[i].channel = channels[i]->hw_value;
-       }
-
-       cmd->params.ssid_len = ssid_len;
-       if (ssid)
-               memcpy(cmd->params.ssid, ssid, ssid_len);
-
-       ret = wl1251_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd));
-       if (ret < 0) {
-               wl1251_error("cmd scan failed: %d", ret);
-               goto out;
-       }
-
-       wl1251_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd));
-
-       if (cmd->header.status != CMD_STATUS_SUCCESS) {
-               wl1251_error("cmd scan status wasn't success: %d",
-                            cmd->header.status);
-               ret = -EIO;
-               goto out;
-       }
-
-out:
-       kfree(cmd);
-       return ret;
-}
-
-int wl1251_cmd_trigger_scan_to(struct wl1251 *wl, u32 timeout)
-{
-       struct wl1251_cmd_trigger_scan_to *cmd;
-       int ret;
-
-       wl1251_debug(DEBUG_CMD, "cmd trigger scan to");
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd)
-               return -ENOMEM;
-
-       cmd->timeout = timeout;
-
-       ret = wl1251_cmd_send(wl, CMD_TRIGGER_SCAN_TO, cmd, sizeof(*cmd));
-       if (ret < 0) {
-               wl1251_error("cmd trigger scan to failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(cmd);
-       return ret;
-}
diff --git a/drivers/net/wireless/wl1251/cmd.h b/drivers/net/wireless/wl1251/cmd.h
deleted file mode 100644 (file)
index ee4f2b3..0000000
+++ /dev/null
@@ -1,415 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (c) 1998-2007 Texas Instruments Incorporated
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __WL1251_CMD_H__
-#define __WL1251_CMD_H__
-
-#include "wl1251.h"
-
-#include <net/cfg80211.h>
-
-struct acx_header;
-
-int wl1251_cmd_send(struct wl1251 *wl, u16 type, void *buf, size_t buf_len);
-int wl1251_cmd_test(struct wl1251 *wl, void *buf, size_t buf_len, u8 answer);
-int wl1251_cmd_interrogate(struct wl1251 *wl, u16 id, void *buf, size_t len);
-int wl1251_cmd_configure(struct wl1251 *wl, u16 id, void *buf, size_t len);
-int wl1251_cmd_vbm(struct wl1251 *wl, u8 identity,
-                  void *bitmap, u16 bitmap_len, u8 bitmap_control);
-int wl1251_cmd_data_path(struct wl1251 *wl, u8 channel, bool enable);
-int wl1251_cmd_join(struct wl1251 *wl, u8 bss_type, u8 channel,
-                   u16 beacon_interval, u8 dtim_interval);
-int wl1251_cmd_ps_mode(struct wl1251 *wl, u8 ps_mode);
-int wl1251_cmd_read_memory(struct wl1251 *wl, u32 addr, void *answer,
-                          size_t len);
-int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id,
-                           void *buf, size_t buf_len);
-int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len,
-                   struct ieee80211_channel *channels[],
-                   unsigned int n_channels, unsigned int n_probes);
-int wl1251_cmd_trigger_scan_to(struct wl1251 *wl, u32 timeout);
-
-/* unit ms */
-#define WL1251_COMMAND_TIMEOUT 2000
-
-enum wl1251_commands {
-       CMD_RESET           = 0,
-       CMD_INTERROGATE     = 1,    /*use this to read information elements*/
-       CMD_CONFIGURE       = 2,    /*use this to write information elements*/
-       CMD_ENABLE_RX       = 3,
-       CMD_ENABLE_TX       = 4,
-       CMD_DISABLE_RX      = 5,
-       CMD_DISABLE_TX      = 6,
-       CMD_SCAN            = 8,
-       CMD_STOP_SCAN       = 9,
-       CMD_VBM             = 10,
-       CMD_START_JOIN      = 11,
-       CMD_SET_KEYS        = 12,
-       CMD_READ_MEMORY     = 13,
-       CMD_WRITE_MEMORY    = 14,
-       CMD_BEACON          = 19,
-       CMD_PROBE_RESP      = 20,
-       CMD_NULL_DATA       = 21,
-       CMD_PROBE_REQ       = 22,
-       CMD_TEST            = 23,
-       CMD_RADIO_CALIBRATE     = 25,   /* OBSOLETE */
-       CMD_ENABLE_RX_PATH      = 27,   /* OBSOLETE */
-       CMD_NOISE_HIST      = 28,
-       CMD_RX_RESET        = 29,
-       CMD_PS_POLL         = 30,
-       CMD_QOS_NULL_DATA   = 31,
-       CMD_LNA_CONTROL     = 32,
-       CMD_SET_BCN_MODE    = 33,
-       CMD_MEASUREMENT      = 34,
-       CMD_STOP_MEASUREMENT = 35,
-       CMD_DISCONNECT       = 36,
-       CMD_SET_PS_MODE      = 37,
-       CMD_CHANNEL_SWITCH   = 38,
-       CMD_STOP_CHANNEL_SWICTH = 39,
-       CMD_AP_DISCOVERY     = 40,
-       CMD_STOP_AP_DISCOVERY = 41,
-       CMD_SPS_SCAN = 42,
-       CMD_STOP_SPS_SCAN = 43,
-       CMD_HEALTH_CHECK     = 45,
-       CMD_DEBUG            = 46,
-       CMD_TRIGGER_SCAN_TO  = 47,
-
-       NUM_COMMANDS,
-       MAX_COMMAND_ID = 0xFFFF,
-};
-
-#define MAX_CMD_PARAMS 572
-
-struct wl1251_cmd_header {
-       u16 id;
-       u16 status;
-       /* payload */
-       u8 data[0];
-} __packed;
-
-struct  wl1251_command {
-       struct wl1251_cmd_header header;
-       u8  parameters[MAX_CMD_PARAMS];
-} __packed;
-
-enum {
-       CMD_MAILBOX_IDLE                        =  0,
-       CMD_STATUS_SUCCESS                      =  1,
-       CMD_STATUS_UNKNOWN_CMD                  =  2,
-       CMD_STATUS_UNKNOWN_IE                   =  3,
-       CMD_STATUS_REJECT_MEAS_SG_ACTIVE        = 11,
-       CMD_STATUS_RX_BUSY                      = 13,
-       CMD_STATUS_INVALID_PARAM                = 14,
-       CMD_STATUS_TEMPLATE_TOO_LARGE           = 15,
-       CMD_STATUS_OUT_OF_MEMORY                = 16,
-       CMD_STATUS_STA_TABLE_FULL               = 17,
-       CMD_STATUS_RADIO_ERROR                  = 18,
-       CMD_STATUS_WRONG_NESTING                = 19,
-       CMD_STATUS_TIMEOUT                      = 21, /* Driver internal use.*/
-       CMD_STATUS_FW_RESET                     = 22, /* Driver internal use.*/
-       MAX_COMMAND_STATUS                      = 0xff
-};
-
-
-/*
- * CMD_READ_MEMORY
- *
- * The host issues this command to read the WiLink device memory/registers.
- *
- * Note: The Base Band address has special handling (16 bits registers and
- * addresses). For more information, see the hardware specification.
- */
-/*
- * CMD_WRITE_MEMORY
- *
- * The host issues this command to write the WiLink device memory/registers.
- *
- * The Base Band address has special handling (16 bits registers and
- * addresses). For more information, see the hardware specification.
- */
-#define MAX_READ_SIZE 256
-
-struct cmd_read_write_memory {
-       struct wl1251_cmd_header header;
-
-       /* The address of the memory to read from or write to.*/
-       u32 addr;
-
-       /* The amount of data in bytes to read from or write to the WiLink
-        * device.*/
-       u32 size;
-
-       /* The actual value read from or written to the Wilink. The source
-          of this field is the Host in WRITE command or the Wilink in READ
-          command. */
-       u8 value[MAX_READ_SIZE];
-} __packed;
-
-#define CMDMBOX_HEADER_LEN 4
-#define CMDMBOX_INFO_ELEM_HEADER_LEN 4
-
-#define WL1251_SCAN_MIN_DURATION 30000
-#define WL1251_SCAN_MAX_DURATION 60000
-
-#define WL1251_SCAN_NUM_PROBES 3
-
-struct wl1251_scan_parameters {
-       __le32 rx_config_options;
-       __le32 rx_filter_options;
-
-       /*
-        * Scan options:
-        * bit 0: When this bit is set, passive scan.
-        * bit 1: Band, when this bit is set we scan
-        * in the 5Ghz band.
-        * bit 2: voice mode, 0 for normal scan.
-        * bit 3: scan priority, 1 for high priority.
-        */
-       __le16 scan_options;
-
-       /* Number of channels to scan */
-       u8 num_channels;
-
-       /* Number opf probe requests to send, per channel */
-       u8 num_probe_requests;
-
-       /* Rate and modulation for probe requests */
-       __le16 tx_rate;
-
-       u8 tid_trigger;
-       u8 ssid_len;
-       u8 ssid[32];
-
-} __packed;
-
-struct wl1251_scan_ch_parameters {
-       __le32 min_duration; /* in TU */
-       __le32 max_duration; /* in TU */
-       u32 bssid_lsb;
-       u16 bssid_msb;
-
-       /*
-        * bits 0-3: Early termination count.
-        * bits 4-5: Early termination condition.
-        */
-       u8 early_termination;
-
-       u8 tx_power_att;
-       u8 channel;
-       u8 pad[3];
-} __packed;
-
-/* SCAN parameters */
-#define SCAN_MAX_NUM_OF_CHANNELS 16
-
-struct wl1251_cmd_scan {
-       struct wl1251_cmd_header header;
-
-       struct wl1251_scan_parameters params;
-       struct wl1251_scan_ch_parameters channels[SCAN_MAX_NUM_OF_CHANNELS];
-} __packed;
-
-enum {
-       BSS_TYPE_IBSS = 0,
-       BSS_TYPE_STA_BSS = 2,
-       BSS_TYPE_AP_BSS = 3,
-       MAX_BSS_TYPE = 0xFF
-};
-
-#define JOIN_CMD_CTRL_TX_FLUSH             0x80 /* Firmware flushes all Tx */
-#define JOIN_CMD_CTRL_EARLY_WAKEUP_ENABLE  0x01 /* Early wakeup time */
-
-
-struct cmd_join {
-       struct wl1251_cmd_header header;
-
-       u32 bssid_lsb;
-       u16 bssid_msb;
-       u16 beacon_interval; /* in TBTTs */
-       u32 rx_config_options;
-       u32 rx_filter_options;
-
-       /*
-        * The target uses this field to determine the rate at
-        * which to transmit control frame responses (such as
-        * ACK or CTS frames).
-        */
-       u16 basic_rate_set;
-       u8 dtim_interval;
-       u8 tx_ctrl_frame_rate; /* OBSOLETE */
-       u8 tx_ctrl_frame_mod;  /* OBSOLETE */
-       /*
-        * bits 0-2: This bitwise field specifies the type
-        * of BSS to start or join (BSS_TYPE_*).
-        * bit 4: Band - The radio band in which to join
-        * or start.
-        *  0 - 2.4GHz band
-        *  1 - 5GHz band
-        * bits 3, 5-7: Reserved
-        */
-       u8 bss_type;
-       u8 channel;
-       u8 ssid_len;
-       u8 ssid[IEEE80211_MAX_SSID_LEN];
-       u8 ctrl; /* JOIN_CMD_CTRL_* */
-       u8 tx_mgt_frame_rate; /* OBSOLETE */
-       u8 tx_mgt_frame_mod;  /* OBSOLETE */
-       u8 reserved;
-} __packed;
-
-struct cmd_enabledisable_path {
-       struct wl1251_cmd_header header;
-
-       u8 channel;
-       u8 padding[3];
-} __packed;
-
-#define WL1251_MAX_TEMPLATE_SIZE 300
-
-struct wl1251_cmd_packet_template {
-       struct wl1251_cmd_header header;
-
-       __le16 size;
-       u8 data[0];
-} __packed;
-
-#define TIM_ELE_ID    5
-#define PARTIAL_VBM_MAX    251
-
-struct wl1251_tim {
-       u8 identity;
-       u8 length;
-       u8 dtim_count;
-       u8 dtim_period;
-       u8 bitmap_ctrl;
-       u8 pvb_field[PARTIAL_VBM_MAX]; /* Partial Virtual Bitmap */
-} __packed;
-
-/* Virtual Bit Map update */
-struct wl1251_cmd_vbm_update {
-       struct wl1251_cmd_header header;
-       __le16 len;
-       u8  padding[2];
-       struct wl1251_tim tim;
-} __packed;
-
-enum wl1251_cmd_ps_mode {
-       CHIP_ACTIVE_MODE,
-       CHIP_POWER_SAVE_MODE
-};
-
-struct wl1251_cmd_ps_params {
-       struct wl1251_cmd_header header;
-
-       u8 ps_mode; /* STATION_* */
-       u8 send_null_data; /* Do we have to send NULL data packet ? */
-       u8 retries; /* Number of retires for the initial NULL data packet */
-
-        /*
-         * TUs during which the target stays awake after switching
-         * to power save mode.
-         */
-       u8 hang_over_period;
-       u16 null_data_rate;
-       u8 pad[2];
-} __packed;
-
-struct wl1251_cmd_trigger_scan_to {
-       struct wl1251_cmd_header header;
-
-       u32 timeout;
-} __packed;
-
-/* HW encryption keys */
-#define NUM_ACCESS_CATEGORIES_COPY 4
-#define MAX_KEY_SIZE 32
-
-/* When set, disable HW encryption */
-#define DF_ENCRYPTION_DISABLE      0x01
-/* When set, disable HW decryption */
-#define DF_SNIFF_MODE_ENABLE       0x80
-
-enum wl1251_cmd_key_action {
-       KEY_ADD_OR_REPLACE = 1,
-       KEY_REMOVE         = 2,
-       KEY_SET_ID         = 3,
-       MAX_KEY_ACTION     = 0xffff,
-};
-
-enum wl1251_cmd_key_type {
-       KEY_WEP_DEFAULT       = 0,
-       KEY_WEP_ADDR          = 1,
-       KEY_AES_GROUP         = 4,
-       KEY_AES_PAIRWISE      = 5,
-       KEY_WEP_GROUP         = 6,
-       KEY_TKIP_MIC_GROUP    = 10,
-       KEY_TKIP_MIC_PAIRWISE = 11,
-};
-
-/*
- *
- * key_type_e   key size    key format
- * ----------   ---------   ----------
- * 0x00         5, 13, 29   Key data
- * 0x01         5, 13, 29   Key data
- * 0x04         16          16 bytes of key data
- * 0x05         16          16 bytes of key data
- * 0x0a         32          16 bytes of TKIP key data
- *                          8 bytes of RX MIC key data
- *                          8 bytes of TX MIC key data
- * 0x0b         32          16 bytes of TKIP key data
- *                          8 bytes of RX MIC key data
- *                          8 bytes of TX MIC key data
- *
- */
-
-struct wl1251_cmd_set_keys {
-       struct wl1251_cmd_header header;
-
-       /* Ignored for default WEP key */
-       u8 addr[ETH_ALEN];
-
-       /* key_action_e */
-       u16 key_action;
-
-       u16 reserved_1;
-
-       /* key size in bytes */
-       u8 key_size;
-
-       /* key_type_e */
-       u8 key_type;
-       u8 ssid_profile;
-
-       /*
-        * TKIP, AES: frame's key id field.
-        * For WEP default key: key id;
-        */
-       u8 id;
-       u8 reserved_2[6];
-       u8 key[MAX_KEY_SIZE];
-       u16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY];
-       u32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY];
-} __packed;
-
-
-#endif /* __WL1251_CMD_H__ */
diff --git a/drivers/net/wireless/wl1251/debugfs.c b/drivers/net/wireless/wl1251/debugfs.c
deleted file mode 100644 (file)
index 448da1f..0000000
+++ /dev/null
@@ -1,539 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (C) 2009 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include "debugfs.h"
-
-#include <linux/skbuff.h>
-#include <linux/slab.h>
-
-#include "wl1251.h"
-#include "acx.h"
-#include "ps.h"
-
-/* ms */
-#define WL1251_DEBUGFS_STATS_LIFETIME 1000
-
-/* debugfs macros idea from mac80211 */
-
-#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...)             \
-static ssize_t name## _read(struct file *file, char __user *userbuf,   \
-                           size_t count, loff_t *ppos)                 \
-{                                                                      \
-       struct wl1251 *wl = file->private_data;                         \
-       char buf[buflen];                                               \
-       int res;                                                        \
-                                                                       \
-       res = scnprintf(buf, buflen, fmt "\n", ##value);                \
-       return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
-}                                                                      \
-                                                                       \
-static const struct file_operations name## _ops = {                    \
-       .read = name## _read,                                           \
-       .open = simple_open,                                            \
-       .llseek = generic_file_llseek,                                  \
-};
-
-#define DEBUGFS_ADD(name, parent)                                      \
-       wl->debugfs.name = debugfs_create_file(#name, 0400, parent,     \
-                                              wl, &name## _ops);       \
-       if (IS_ERR(wl->debugfs.name)) {                                 \
-               ret = PTR_ERR(wl->debugfs.name);                        \
-               wl->debugfs.name = NULL;                                \
-               goto out;                                               \
-       }
-
-#define DEBUGFS_DEL(name)                                              \
-       do {                                                            \
-               debugfs_remove(wl->debugfs.name);                       \
-               wl->debugfs.name = NULL;                                \
-       } while (0)
-
-#define DEBUGFS_FWSTATS_FILE(sub, name, buflen, fmt)                   \
-static ssize_t sub## _ ##name## _read(struct file *file,               \
-                                     char __user *userbuf,             \
-                                     size_t count, loff_t *ppos)       \
-{                                                                      \
-       struct wl1251 *wl = file->private_data;                         \
-       char buf[buflen];                                               \
-       int res;                                                        \
-                                                                       \
-       wl1251_debugfs_update_stats(wl);                                \
-                                                                       \
-       res = scnprintf(buf, buflen, fmt "\n",                          \
-                       wl->stats.fw_stats->sub.name);                  \
-       return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
-}                                                                      \
-                                                                       \
-static const struct file_operations sub## _ ##name## _ops = {          \
-       .read = sub## _ ##name## _read,                                 \
-       .open = simple_open,                                            \
-       .llseek = generic_file_llseek,                                  \
-};
-
-#define DEBUGFS_FWSTATS_ADD(sub, name)                         \
-       DEBUGFS_ADD(sub## _ ##name, wl->debugfs.fw_statistics)
-
-#define DEBUGFS_FWSTATS_DEL(sub, name)                         \
-       DEBUGFS_DEL(sub## _ ##name)
-
-static void wl1251_debugfs_update_stats(struct wl1251 *wl)
-{
-       int ret;
-
-       mutex_lock(&wl->mutex);
-
-       ret = wl1251_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       if (wl->state == WL1251_STATE_ON &&
-           time_after(jiffies, wl->stats.fw_stats_update +
-                      msecs_to_jiffies(WL1251_DEBUGFS_STATS_LIFETIME))) {
-               wl1251_acx_statistics(wl, wl->stats.fw_stats);
-               wl->stats.fw_stats_update = jiffies;
-       }
-
-       wl1251_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, 20, "%u");
-
-DEBUGFS_FWSTATS_FILE(rx, out_of_mem, 20, "%u");
-DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, 20, "%u");
-DEBUGFS_FWSTATS_FILE(rx, hw_stuck, 20, "%u");
-DEBUGFS_FWSTATS_FILE(rx, dropped, 20, "%u");
-DEBUGFS_FWSTATS_FILE(rx, fcs_err, 20, "%u");
-DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, 20, "%u");
-DEBUGFS_FWSTATS_FILE(rx, path_reset, 20, "%u");
-DEBUGFS_FWSTATS_FILE(rx, reset_counter, 20, "%u");
-
-DEBUGFS_FWSTATS_FILE(dma, rx_requested, 20, "%u");
-DEBUGFS_FWSTATS_FILE(dma, rx_errors, 20, "%u");
-DEBUGFS_FWSTATS_FILE(dma, tx_requested, 20, "%u");
-DEBUGFS_FWSTATS_FILE(dma, tx_errors, 20, "%u");
-
-DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, fiqs, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, rx_headers, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, rx_rdys, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, irqs, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, tx_procs, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, decrypt_done, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, dma0_done, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, dma1_done, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, commands, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, rx_procs, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, pci_pm, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, wakeups, 20, "%u");
-DEBUGFS_FWSTATS_FILE(isr, low_rssi, 20, "%u");
-
-DEBUGFS_FWSTATS_FILE(wep, addr_key_count, 20, "%u");
-DEBUGFS_FWSTATS_FILE(wep, default_key_count, 20, "%u");
-/* skipping wep.reserved */
-DEBUGFS_FWSTATS_FILE(wep, key_not_found, 20, "%u");
-DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, 20, "%u");
-DEBUGFS_FWSTATS_FILE(wep, packets, 20, "%u");
-DEBUGFS_FWSTATS_FILE(wep, interrupt, 20, "%u");
-
-DEBUGFS_FWSTATS_FILE(pwr, ps_enter, 20, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, elp_enter, 20, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, 20, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, 20, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, 20, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, 20, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, 20, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, 20, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, power_save_off, 20, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, enable_ps, 20, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, disable_ps, 20, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, 20, "%u");
-/* skipping cont_miss_bcns_spread for now */
-DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, 20, "%u");
-
-DEBUGFS_FWSTATS_FILE(mic, rx_pkts, 20, "%u");
-DEBUGFS_FWSTATS_FILE(mic, calc_failure, 20, "%u");
-
-DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, 20, "%u");
-DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, 20, "%u");
-DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, 20, "%u");
-DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, 20, "%u");
-DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, 20, "%u");
-DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, 20, "%u");
-
-DEBUGFS_FWSTATS_FILE(event, heart_beat, 20, "%u");
-DEBUGFS_FWSTATS_FILE(event, calibration, 20, "%u");
-DEBUGFS_FWSTATS_FILE(event, rx_mismatch, 20, "%u");
-DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, 20, "%u");
-DEBUGFS_FWSTATS_FILE(event, rx_pool, 20, "%u");
-DEBUGFS_FWSTATS_FILE(event, oom_late, 20, "%u");
-DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, 20, "%u");
-DEBUGFS_FWSTATS_FILE(event, tx_stuck, 20, "%u");
-
-DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, 20, "%u");
-DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, 20, "%u");
-DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, 20, "%u");
-DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, 20, "%u");
-DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, 20, "%u");
-DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, 20, "%u");
-DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, 20, "%u");
-
-DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, 20, "%u");
-DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, 20, "%u");
-DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data,
-                    20, "%u");
-DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, 20, "%u");
-DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, 20, "%u");
-
-DEBUGFS_READONLY_FILE(retry_count, 20, "%u", wl->stats.retry_count);
-DEBUGFS_READONLY_FILE(excessive_retries, 20, "%u",
-                     wl->stats.excessive_retries);
-
-static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
-                                size_t count, loff_t *ppos)
-{
-       struct wl1251 *wl = file->private_data;
-       u32 queue_len;
-       char buf[20];
-       int res;
-
-       queue_len = skb_queue_len(&wl->tx_queue);
-
-       res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
-       return simple_read_from_buffer(userbuf, count, ppos, buf, res);
-}
-
-static const struct file_operations tx_queue_len_ops = {
-       .read = tx_queue_len_read,
-       .open = simple_open,
-       .llseek = generic_file_llseek,
-};
-
-static ssize_t tx_queue_status_read(struct file *file, char __user *userbuf,
-                                   size_t count, loff_t *ppos)
-{
-       struct wl1251 *wl = file->private_data;
-       char buf[3], status;
-       int len;
-
-       if (wl->tx_queue_stopped)
-               status = 's';
-       else
-               status = 'r';
-
-       len = scnprintf(buf, sizeof(buf), "%c\n", status);
-       return simple_read_from_buffer(userbuf, count, ppos, buf, len);
-}
-
-static const struct file_operations tx_queue_status_ops = {
-       .read = tx_queue_status_read,
-       .open = simple_open,
-       .llseek = generic_file_llseek,
-};
-
-static void wl1251_debugfs_delete_files(struct wl1251 *wl)
-{
-       DEBUGFS_FWSTATS_DEL(tx, internal_desc_overflow);
-
-       DEBUGFS_FWSTATS_DEL(rx, out_of_mem);
-       DEBUGFS_FWSTATS_DEL(rx, hdr_overflow);
-       DEBUGFS_FWSTATS_DEL(rx, hw_stuck);
-       DEBUGFS_FWSTATS_DEL(rx, dropped);
-       DEBUGFS_FWSTATS_DEL(rx, fcs_err);
-       DEBUGFS_FWSTATS_DEL(rx, xfr_hint_trig);
-       DEBUGFS_FWSTATS_DEL(rx, path_reset);
-       DEBUGFS_FWSTATS_DEL(rx, reset_counter);
-
-       DEBUGFS_FWSTATS_DEL(dma, rx_requested);
-       DEBUGFS_FWSTATS_DEL(dma, rx_errors);
-       DEBUGFS_FWSTATS_DEL(dma, tx_requested);
-       DEBUGFS_FWSTATS_DEL(dma, tx_errors);
-
-       DEBUGFS_FWSTATS_DEL(isr, cmd_cmplt);
-       DEBUGFS_FWSTATS_DEL(isr, fiqs);
-       DEBUGFS_FWSTATS_DEL(isr, rx_headers);
-       DEBUGFS_FWSTATS_DEL(isr, rx_mem_overflow);
-       DEBUGFS_FWSTATS_DEL(isr, rx_rdys);
-       DEBUGFS_FWSTATS_DEL(isr, irqs);
-       DEBUGFS_FWSTATS_DEL(isr, tx_procs);
-       DEBUGFS_FWSTATS_DEL(isr, decrypt_done);
-       DEBUGFS_FWSTATS_DEL(isr, dma0_done);
-       DEBUGFS_FWSTATS_DEL(isr, dma1_done);
-       DEBUGFS_FWSTATS_DEL(isr, tx_exch_complete);
-       DEBUGFS_FWSTATS_DEL(isr, commands);
-       DEBUGFS_FWSTATS_DEL(isr, rx_procs);
-       DEBUGFS_FWSTATS_DEL(isr, hw_pm_mode_changes);
-       DEBUGFS_FWSTATS_DEL(isr, host_acknowledges);
-       DEBUGFS_FWSTATS_DEL(isr, pci_pm);
-       DEBUGFS_FWSTATS_DEL(isr, wakeups);
-       DEBUGFS_FWSTATS_DEL(isr, low_rssi);
-
-       DEBUGFS_FWSTATS_DEL(wep, addr_key_count);
-       DEBUGFS_FWSTATS_DEL(wep, default_key_count);
-       /* skipping wep.reserved */
-       DEBUGFS_FWSTATS_DEL(wep, key_not_found);
-       DEBUGFS_FWSTATS_DEL(wep, decrypt_fail);
-       DEBUGFS_FWSTATS_DEL(wep, packets);
-       DEBUGFS_FWSTATS_DEL(wep, interrupt);
-
-       DEBUGFS_FWSTATS_DEL(pwr, ps_enter);
-       DEBUGFS_FWSTATS_DEL(pwr, elp_enter);
-       DEBUGFS_FWSTATS_DEL(pwr, missing_bcns);
-       DEBUGFS_FWSTATS_DEL(pwr, wake_on_host);
-       DEBUGFS_FWSTATS_DEL(pwr, wake_on_timer_exp);
-       DEBUGFS_FWSTATS_DEL(pwr, tx_with_ps);
-       DEBUGFS_FWSTATS_DEL(pwr, tx_without_ps);
-       DEBUGFS_FWSTATS_DEL(pwr, rcvd_beacons);
-       DEBUGFS_FWSTATS_DEL(pwr, power_save_off);
-       DEBUGFS_FWSTATS_DEL(pwr, enable_ps);
-       DEBUGFS_FWSTATS_DEL(pwr, disable_ps);
-       DEBUGFS_FWSTATS_DEL(pwr, fix_tsf_ps);
-       /* skipping cont_miss_bcns_spread for now */
-       DEBUGFS_FWSTATS_DEL(pwr, rcvd_awake_beacons);
-
-       DEBUGFS_FWSTATS_DEL(mic, rx_pkts);
-       DEBUGFS_FWSTATS_DEL(mic, calc_failure);
-
-       DEBUGFS_FWSTATS_DEL(aes, encrypt_fail);
-       DEBUGFS_FWSTATS_DEL(aes, decrypt_fail);
-       DEBUGFS_FWSTATS_DEL(aes, encrypt_packets);
-       DEBUGFS_FWSTATS_DEL(aes, decrypt_packets);
-       DEBUGFS_FWSTATS_DEL(aes, encrypt_interrupt);
-       DEBUGFS_FWSTATS_DEL(aes, decrypt_interrupt);
-
-       DEBUGFS_FWSTATS_DEL(event, heart_beat);
-       DEBUGFS_FWSTATS_DEL(event, calibration);
-       DEBUGFS_FWSTATS_DEL(event, rx_mismatch);
-       DEBUGFS_FWSTATS_DEL(event, rx_mem_empty);
-       DEBUGFS_FWSTATS_DEL(event, rx_pool);
-       DEBUGFS_FWSTATS_DEL(event, oom_late);
-       DEBUGFS_FWSTATS_DEL(event, phy_transmit_error);
-       DEBUGFS_FWSTATS_DEL(event, tx_stuck);
-
-       DEBUGFS_FWSTATS_DEL(ps, pspoll_timeouts);
-       DEBUGFS_FWSTATS_DEL(ps, upsd_timeouts);
-       DEBUGFS_FWSTATS_DEL(ps, upsd_max_sptime);
-       DEBUGFS_FWSTATS_DEL(ps, upsd_max_apturn);
-       DEBUGFS_FWSTATS_DEL(ps, pspoll_max_apturn);
-       DEBUGFS_FWSTATS_DEL(ps, pspoll_utilization);
-       DEBUGFS_FWSTATS_DEL(ps, upsd_utilization);
-
-       DEBUGFS_FWSTATS_DEL(rxpipe, rx_prep_beacon_drop);
-       DEBUGFS_FWSTATS_DEL(rxpipe, descr_host_int_trig_rx_data);
-       DEBUGFS_FWSTATS_DEL(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
-       DEBUGFS_FWSTATS_DEL(rxpipe, missed_beacon_host_int_trig_rx_data);
-       DEBUGFS_FWSTATS_DEL(rxpipe, tx_xfr_host_int_trig_rx_data);
-
-       DEBUGFS_DEL(tx_queue_len);
-       DEBUGFS_DEL(tx_queue_status);
-       DEBUGFS_DEL(retry_count);
-       DEBUGFS_DEL(excessive_retries);
-}
-
-static int wl1251_debugfs_add_files(struct wl1251 *wl)
-{
-       int ret = 0;
-
-       DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
-
-       DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
-       DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
-       DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
-       DEBUGFS_FWSTATS_ADD(rx, dropped);
-       DEBUGFS_FWSTATS_ADD(rx, fcs_err);
-       DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
-       DEBUGFS_FWSTATS_ADD(rx, path_reset);
-       DEBUGFS_FWSTATS_ADD(rx, reset_counter);
-
-       DEBUGFS_FWSTATS_ADD(dma, rx_requested);
-       DEBUGFS_FWSTATS_ADD(dma, rx_errors);
-       DEBUGFS_FWSTATS_ADD(dma, tx_requested);
-       DEBUGFS_FWSTATS_ADD(dma, tx_errors);
-
-       DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
-       DEBUGFS_FWSTATS_ADD(isr, fiqs);
-       DEBUGFS_FWSTATS_ADD(isr, rx_headers);
-       DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
-       DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
-       DEBUGFS_FWSTATS_ADD(isr, irqs);
-       DEBUGFS_FWSTATS_ADD(isr, tx_procs);
-       DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
-       DEBUGFS_FWSTATS_ADD(isr, dma0_done);
-       DEBUGFS_FWSTATS_ADD(isr, dma1_done);
-       DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
-       DEBUGFS_FWSTATS_ADD(isr, commands);
-       DEBUGFS_FWSTATS_ADD(isr, rx_procs);
-       DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
-       DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
-       DEBUGFS_FWSTATS_ADD(isr, pci_pm);
-       DEBUGFS_FWSTATS_ADD(isr, wakeups);
-       DEBUGFS_FWSTATS_ADD(isr, low_rssi);
-
-       DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
-       DEBUGFS_FWSTATS_ADD(wep, default_key_count);
-       /* skipping wep.reserved */
-       DEBUGFS_FWSTATS_ADD(wep, key_not_found);
-       DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
-       DEBUGFS_FWSTATS_ADD(wep, packets);
-       DEBUGFS_FWSTATS_ADD(wep, interrupt);
-
-       DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
-       DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
-       DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
-       DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
-       DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
-       DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
-       DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
-       DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
-       DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
-       DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
-       DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
-       DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
-       /* skipping cont_miss_bcns_spread for now */
-       DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
-
-       DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
-       DEBUGFS_FWSTATS_ADD(mic, calc_failure);
-
-       DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
-       DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
-       DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
-       DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
-       DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
-       DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
-
-       DEBUGFS_FWSTATS_ADD(event, heart_beat);
-       DEBUGFS_FWSTATS_ADD(event, calibration);
-       DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
-       DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
-       DEBUGFS_FWSTATS_ADD(event, rx_pool);
-       DEBUGFS_FWSTATS_ADD(event, oom_late);
-       DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
-       DEBUGFS_FWSTATS_ADD(event, tx_stuck);
-
-       DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
-       DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
-       DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
-       DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
-       DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
-       DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
-       DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
-
-       DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
-       DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
-       DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
-       DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
-       DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
-
-       DEBUGFS_ADD(tx_queue_len, wl->debugfs.rootdir);
-       DEBUGFS_ADD(tx_queue_status, wl->debugfs.rootdir);
-       DEBUGFS_ADD(retry_count, wl->debugfs.rootdir);
-       DEBUGFS_ADD(excessive_retries, wl->debugfs.rootdir);
-
-out:
-       if (ret < 0)
-               wl1251_debugfs_delete_files(wl);
-
-       return ret;
-}
-
-void wl1251_debugfs_reset(struct wl1251 *wl)
-{
-       if (wl->stats.fw_stats != NULL)
-               memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
-       wl->stats.retry_count = 0;
-       wl->stats.excessive_retries = 0;
-}
-
-int wl1251_debugfs_init(struct wl1251 *wl)
-{
-       int ret;
-
-       wl->debugfs.rootdir = debugfs_create_dir(KBUILD_MODNAME, NULL);
-
-       if (IS_ERR(wl->debugfs.rootdir)) {
-               ret = PTR_ERR(wl->debugfs.rootdir);
-               wl->debugfs.rootdir = NULL;
-               goto err;
-       }
-
-       wl->debugfs.fw_statistics = debugfs_create_dir("fw-statistics",
-                                                      wl->debugfs.rootdir);
-
-       if (IS_ERR(wl->debugfs.fw_statistics)) {
-               ret = PTR_ERR(wl->debugfs.fw_statistics);
-               wl->debugfs.fw_statistics = NULL;
-               goto err_root;
-       }
-
-       wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
-                                     GFP_KERNEL);
-
-       if (!wl->stats.fw_stats) {
-               ret = -ENOMEM;
-               goto err_fw;
-       }
-
-       wl->stats.fw_stats_update = jiffies;
-
-       ret = wl1251_debugfs_add_files(wl);
-
-       if (ret < 0)
-               goto err_file;
-
-       return 0;
-
-err_file:
-       kfree(wl->stats.fw_stats);
-       wl->stats.fw_stats = NULL;
-
-err_fw:
-       debugfs_remove(wl->debugfs.fw_statistics);
-       wl->debugfs.fw_statistics = NULL;
-
-err_root:
-       debugfs_remove(wl->debugfs.rootdir);
-       wl->debugfs.rootdir = NULL;
-
-err:
-       return ret;
-}
-
-void wl1251_debugfs_exit(struct wl1251 *wl)
-{
-       wl1251_debugfs_delete_files(wl);
-
-       kfree(wl->stats.fw_stats);
-       wl->stats.fw_stats = NULL;
-
-       debugfs_remove(wl->debugfs.fw_statistics);
-       wl->debugfs.fw_statistics = NULL;
-
-       debugfs_remove(wl->debugfs.rootdir);
-       wl->debugfs.rootdir = NULL;
-
-}
diff --git a/drivers/net/wireless/wl1251/debugfs.h b/drivers/net/wireless/wl1251/debugfs.h
deleted file mode 100644 (file)
index b3417c0..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (C) 2009 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef WL1251_DEBUGFS_H
-#define WL1251_DEBUGFS_H
-
-#include "wl1251.h"
-
-int wl1251_debugfs_init(struct wl1251 *wl);
-void wl1251_debugfs_exit(struct wl1251 *wl);
-void wl1251_debugfs_reset(struct wl1251 *wl);
-
-#endif /* WL1251_DEBUGFS_H */
diff --git a/drivers/net/wireless/wl1251/event.c b/drivers/net/wireless/wl1251/event.c
deleted file mode 100644 (file)
index 9f15cca..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (c) 1998-2007 Texas Instruments Incorporated
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include "wl1251.h"
-#include "reg.h"
-#include "io.h"
-#include "event.h"
-#include "ps.h"
-
-static int wl1251_event_scan_complete(struct wl1251 *wl,
-                                     struct event_mailbox *mbox)
-{
-       wl1251_debug(DEBUG_EVENT, "status: 0x%x, channels: %d",
-                    mbox->scheduled_scan_status,
-                    mbox->scheduled_scan_channels);
-
-       if (wl->scanning) {
-               ieee80211_scan_completed(wl->hw, false);
-               wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan completed");
-               wl->scanning = false;
-       }
-
-       return 0;
-}
-
-static void wl1251_event_mbox_dump(struct event_mailbox *mbox)
-{
-       wl1251_debug(DEBUG_EVENT, "MBOX DUMP:");
-       wl1251_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
-       wl1251_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
-}
-
-static int wl1251_event_process(struct wl1251 *wl, struct event_mailbox *mbox)
-{
-       int ret;
-       u32 vector;
-
-       wl1251_event_mbox_dump(mbox);
-
-       vector = mbox->events_vector & ~(mbox->events_mask);
-       wl1251_debug(DEBUG_EVENT, "vector: 0x%x", vector);
-
-       if (vector & SCAN_COMPLETE_EVENT_ID) {
-               ret = wl1251_event_scan_complete(wl, mbox);
-               if (ret < 0)
-                       return ret;
-       }
-
-       if (vector & BSS_LOSE_EVENT_ID) {
-               wl1251_debug(DEBUG_EVENT, "BSS_LOSE_EVENT");
-
-               if (wl->psm_requested &&
-                   wl->station_mode != STATION_ACTIVE_MODE) {
-                       ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
-                       if (ret < 0)
-                               return ret;
-               }
-       }
-
-       if (vector & SYNCHRONIZATION_TIMEOUT_EVENT_ID &&
-           wl->station_mode != STATION_ACTIVE_MODE) {
-               wl1251_debug(DEBUG_EVENT, "SYNCHRONIZATION_TIMEOUT_EVENT");
-
-               /* indicate to the stack, that beacons have been lost */
-               ieee80211_beacon_loss(wl->vif);
-       }
-
-       if (vector & REGAINED_BSS_EVENT_ID) {
-               if (wl->psm_requested) {
-                       ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
-                       if (ret < 0)
-                               return ret;
-               }
-       }
-
-       if (wl->vif && wl->rssi_thold) {
-               if (vector & ROAMING_TRIGGER_LOW_RSSI_EVENT_ID) {
-                       wl1251_debug(DEBUG_EVENT,
-                                    "ROAMING_TRIGGER_LOW_RSSI_EVENT");
-                       ieee80211_cqm_rssi_notify(wl->vif,
-                               NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
-                               GFP_KERNEL);
-               }
-
-               if (vector & ROAMING_TRIGGER_REGAINED_RSSI_EVENT_ID) {
-                       wl1251_debug(DEBUG_EVENT,
-                                    "ROAMING_TRIGGER_REGAINED_RSSI_EVENT");
-                       ieee80211_cqm_rssi_notify(wl->vif,
-                               NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
-                               GFP_KERNEL);
-               }
-       }
-
-       return 0;
-}
-
-/*
- * Poll the mailbox event field until any of the bits in the mask is set or a
- * timeout occurs (WL1251_EVENT_TIMEOUT in msecs)
- */
-int wl1251_event_wait(struct wl1251 *wl, u32 mask, int timeout_ms)
-{
-       u32 events_vector, event;
-       unsigned long timeout;
-
-       timeout = jiffies + msecs_to_jiffies(timeout_ms);
-
-       do {
-               if (time_after(jiffies, timeout))
-                       return -ETIMEDOUT;
-
-               msleep(1);
-
-               /* read from both event fields */
-               wl1251_mem_read(wl, wl->mbox_ptr[0], &events_vector,
-                               sizeof(events_vector));
-               event = events_vector & mask;
-               wl1251_mem_read(wl, wl->mbox_ptr[1], &events_vector,
-                               sizeof(events_vector));
-               event |= events_vector & mask;
-       } while (!event);
-
-       return 0;
-}
-
-int wl1251_event_unmask(struct wl1251 *wl)
-{
-       int ret;
-
-       ret = wl1251_acx_event_mbox_mask(wl, ~(wl->event_mask));
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-void wl1251_event_mbox_config(struct wl1251 *wl)
-{
-       wl->mbox_ptr[0] = wl1251_reg_read32(wl, REG_EVENT_MAILBOX_PTR);
-       wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
-
-       wl1251_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
-                    wl->mbox_ptr[0], wl->mbox_ptr[1]);
-}
-
-int wl1251_event_handle(struct wl1251 *wl, u8 mbox_num)
-{
-       struct event_mailbox mbox;
-       int ret;
-
-       wl1251_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
-
-       if (mbox_num > 1)
-               return -EINVAL;
-
-       /* first we read the mbox descriptor */
-       wl1251_mem_read(wl, wl->mbox_ptr[mbox_num], &mbox,
-                           sizeof(struct event_mailbox));
-
-       /* process the descriptor */
-       ret = wl1251_event_process(wl, &mbox);
-       if (ret < 0)
-               return ret;
-
-       /* then we let the firmware know it can go on...*/
-       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
-
-       return 0;
-}
diff --git a/drivers/net/wireless/wl1251/event.h b/drivers/net/wireless/wl1251/event.h
deleted file mode 100644 (file)
index 30eb5d1..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (c) 1998-2007 Texas Instruments Incorporated
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __WL1251_EVENT_H__
-#define __WL1251_EVENT_H__
-
-/*
- * Mbox events
- *
- * The event mechanism is based on a pair of event buffers (buffers A and
- * B) at fixed locations in the target's memory. The host processes one
- * buffer while the other buffer continues to collect events. If the host
- * is not processing events, an interrupt is issued to signal that a buffer
- * is ready. Once the host is done with processing events from one buffer,
- * it signals the target (with an ACK interrupt) that the event buffer is
- * free.
- */
-
-enum {
-       RESERVED1_EVENT_ID                       = BIT(0),
-       RESERVED2_EVENT_ID                       = BIT(1),
-       MEASUREMENT_START_EVENT_ID               = BIT(2),
-       SCAN_COMPLETE_EVENT_ID                   = BIT(3),
-       CALIBRATION_COMPLETE_EVENT_ID            = BIT(4),
-       ROAMING_TRIGGER_LOW_RSSI_EVENT_ID        = BIT(5),
-       PS_REPORT_EVENT_ID                       = BIT(6),
-       SYNCHRONIZATION_TIMEOUT_EVENT_ID         = BIT(7),
-       HEALTH_REPORT_EVENT_ID                   = BIT(8),
-       ACI_DETECTION_EVENT_ID                   = BIT(9),
-       DEBUG_REPORT_EVENT_ID                    = BIT(10),
-       MAC_STATUS_EVENT_ID                      = BIT(11),
-       DISCONNECT_EVENT_COMPLETE_ID             = BIT(12),
-       JOIN_EVENT_COMPLETE_ID                   = BIT(13),
-       CHANNEL_SWITCH_COMPLETE_EVENT_ID         = BIT(14),
-       BSS_LOSE_EVENT_ID                        = BIT(15),
-       ROAMING_TRIGGER_MAX_TX_RETRY_EVENT_ID    = BIT(16),
-       MEASUREMENT_COMPLETE_EVENT_ID            = BIT(17),
-       AP_DISCOVERY_COMPLETE_EVENT_ID           = BIT(18),
-       SCHEDULED_SCAN_COMPLETE_EVENT_ID         = BIT(19),
-       PSPOLL_DELIVERY_FAILURE_EVENT_ID         = BIT(20),
-       RESET_BSS_EVENT_ID                       = BIT(21),
-       REGAINED_BSS_EVENT_ID                    = BIT(22),
-       ROAMING_TRIGGER_REGAINED_RSSI_EVENT_ID   = BIT(23),
-       ROAMING_TRIGGER_LOW_SNR_EVENT_ID         = BIT(24),
-       ROAMING_TRIGGER_REGAINED_SNR_EVENT_ID    = BIT(25),
-
-       DBG_EVENT_ID                             = BIT(26),
-       BT_PTA_SENSE_EVENT_ID                    = BIT(27),
-       BT_PTA_PREDICTION_EVENT_ID               = BIT(28),
-       BT_PTA_AVALANCHE_EVENT_ID                = BIT(29),
-
-       PLT_RX_CALIBRATION_COMPLETE_EVENT_ID     = BIT(30),
-
-       EVENT_MBOX_ALL_EVENT_ID                  = 0x7fffffff,
-};
-
-struct event_debug_report {
-       u8 debug_event_id;
-       u8 num_params;
-       u16 pad;
-       u32 report_1;
-       u32 report_2;
-       u32 report_3;
-} __packed;
-
-struct event_mailbox {
-       u32 events_vector;
-       u32 events_mask;
-       u32 reserved_1;
-       u32 reserved_2;
-
-       char average_rssi_level;
-       u8 ps_status;
-       u8 channel_switch_status;
-       u8 scheduled_scan_status;
-
-       /* Channels scanned by the scheduled scan */
-       u16 scheduled_scan_channels;
-
-       /* If bit 0 is set -> target's fatal error */
-       u16 health_report;
-       u16 bad_fft_counter;
-       u8 bt_pta_sense_info;
-       u8 bt_pta_protective_info;
-       u32 reserved;
-       u32 debug_report[2];
-
-       /* Number of FCS errors since last event */
-       u32 fcs_err_counter;
-
-       struct event_debug_report report;
-       u8 average_snr_level;
-       u8 padding[19];
-} __packed;
-
-int wl1251_event_unmask(struct wl1251 *wl);
-void wl1251_event_mbox_config(struct wl1251 *wl);
-int wl1251_event_handle(struct wl1251 *wl, u8 mbox);
-int wl1251_event_wait(struct wl1251 *wl, u32 mask, int timeout_ms);
-
-#endif
diff --git a/drivers/net/wireless/wl1251/init.c b/drivers/net/wireless/wl1251/init.c
deleted file mode 100644 (file)
index 89b43d3..0000000
+++ /dev/null
@@ -1,423 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (C) 2009 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-
-#include "init.h"
-#include "wl12xx_80211.h"
-#include "acx.h"
-#include "cmd.h"
-#include "reg.h"
-
-int wl1251_hw_init_hwenc_config(struct wl1251 *wl)
-{
-       int ret;
-
-       ret = wl1251_acx_feature_cfg(wl);
-       if (ret < 0) {
-               wl1251_warning("couldn't set feature config");
-               return ret;
-       }
-
-       ret = wl1251_acx_default_key(wl, wl->default_key);
-       if (ret < 0) {
-               wl1251_warning("couldn't set default key");
-               return ret;
-       }
-
-       return 0;
-}
-
-int wl1251_hw_init_templates_config(struct wl1251 *wl)
-{
-       int ret;
-       u8 partial_vbm[PARTIAL_VBM_MAX];
-
-       /* send empty templates for fw memory reservation */
-       ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, NULL,
-                                     sizeof(struct wl12xx_probe_req_template));
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA, NULL,
-                                     sizeof(struct wl12xx_null_data_template));
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_cmd_template_set(wl, CMD_PS_POLL, NULL,
-                                     sizeof(struct wl12xx_ps_poll_template));
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, NULL,
-                                     sizeof
-                                     (struct wl12xx_qos_null_data_template));
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, NULL,
-                                     sizeof
-                                     (struct wl12xx_probe_resp_template));
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_cmd_template_set(wl, CMD_BEACON, NULL,
-                                     sizeof
-                                     (struct wl12xx_beacon_template));
-       if (ret < 0)
-               return ret;
-
-       /* tim templates, first reserve space then allocate an empty one */
-       memset(partial_vbm, 0, PARTIAL_VBM_MAX);
-       ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, PARTIAL_VBM_MAX, 0);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, 1, 0);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter)
-{
-       int ret;
-
-       ret = wl1251_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_acx_rx_config(wl, config, filter);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1251_hw_init_phy_config(struct wl1251 *wl)
-{
-       int ret;
-
-       ret = wl1251_acx_pd_threshold(wl);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_acx_slot(wl, DEFAULT_SLOT_TIME);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_acx_group_address_tbl(wl);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_acx_service_period_timeout(wl);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1251_hw_init_beacon_filter(struct wl1251 *wl)
-{
-       int ret;
-
-       /* disable beacon filtering at this stage */
-       ret = wl1251_acx_beacon_filter_opt(wl, false);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_acx_beacon_filter_table(wl);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1251_hw_init_pta(struct wl1251 *wl)
-{
-       int ret;
-
-       ret = wl1251_acx_sg_enable(wl);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_acx_sg_cfg(wl);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1251_hw_init_energy_detection(struct wl1251 *wl)
-{
-       int ret;
-
-       ret = wl1251_acx_cca_threshold(wl);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl)
-{
-       int ret;
-
-       ret = wl1251_acx_bcn_dtim_options(wl);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1251_hw_init_power_auth(struct wl1251 *wl)
-{
-       return wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
-}
-
-int wl1251_hw_init_mem_config(struct wl1251 *wl)
-{
-       int ret;
-
-       ret = wl1251_acx_mem_cfg(wl);
-       if (ret < 0)
-               return ret;
-
-       wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map),
-                                         GFP_KERNEL);
-       if (!wl->target_mem_map) {
-               wl1251_error("couldn't allocate target memory map");
-               return -ENOMEM;
-       }
-
-       /* we now ask for the firmware built memory map */
-       ret = wl1251_acx_mem_map(wl, wl->target_mem_map,
-                                sizeof(struct wl1251_acx_mem_map));
-       if (ret < 0) {
-               wl1251_error("couldn't retrieve firmware memory map");
-               kfree(wl->target_mem_map);
-               wl->target_mem_map = NULL;
-               return ret;
-       }
-
-       return 0;
-}
-
-static int wl1251_hw_init_txq_fill(u8 qid,
-                                  struct acx_tx_queue_qos_config *config,
-                                  u32 num_blocks)
-{
-       config->qid = qid;
-
-       switch (qid) {
-       case QOS_AC_BE:
-               config->high_threshold =
-                       (QOS_TX_HIGH_BE_DEF * num_blocks) / 100;
-               config->low_threshold =
-                       (QOS_TX_LOW_BE_DEF * num_blocks) / 100;
-               break;
-       case QOS_AC_BK:
-               config->high_threshold =
-                       (QOS_TX_HIGH_BK_DEF * num_blocks) / 100;
-               config->low_threshold =
-                       (QOS_TX_LOW_BK_DEF * num_blocks) / 100;
-               break;
-       case QOS_AC_VI:
-               config->high_threshold =
-                       (QOS_TX_HIGH_VI_DEF * num_blocks) / 100;
-               config->low_threshold =
-                       (QOS_TX_LOW_VI_DEF * num_blocks) / 100;
-               break;
-       case QOS_AC_VO:
-               config->high_threshold =
-                       (QOS_TX_HIGH_VO_DEF * num_blocks) / 100;
-               config->low_threshold =
-                       (QOS_TX_LOW_VO_DEF * num_blocks) / 100;
-               break;
-       default:
-               wl1251_error("Invalid TX queue id: %d", qid);
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-static int wl1251_hw_init_tx_queue_config(struct wl1251 *wl)
-{
-       struct acx_tx_queue_qos_config *config;
-       struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map;
-       int ret, i;
-
-       wl1251_debug(DEBUG_ACX, "acx tx queue config");
-
-       config = kzalloc(sizeof(*config), GFP_KERNEL);
-       if (!config) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       for (i = 0; i < MAX_NUM_OF_AC; i++) {
-               ret = wl1251_hw_init_txq_fill(i, config,
-                                             wl_mem_map->num_tx_mem_blocks);
-               if (ret < 0)
-                       goto out;
-
-               ret = wl1251_cmd_configure(wl, ACX_TX_QUEUE_CFG,
-                                          config, sizeof(*config));
-               if (ret < 0)
-                       goto out;
-       }
-
-       wl1251_acx_ac_cfg(wl, AC_BE, CWMIN_BE, CWMAX_BE, AIFS_DIFS, TXOP_BE);
-       wl1251_acx_ac_cfg(wl, AC_BK, CWMIN_BK, CWMAX_BK, AIFS_DIFS, TXOP_BK);
-       wl1251_acx_ac_cfg(wl, AC_VI, CWMIN_VI, CWMAX_VI, AIFS_DIFS, TXOP_VI);
-       wl1251_acx_ac_cfg(wl, AC_VO, CWMIN_VO, CWMAX_VO, AIFS_DIFS, TXOP_VO);
-
-out:
-       kfree(config);
-       return ret;
-}
-
-static int wl1251_hw_init_data_path_config(struct wl1251 *wl)
-{
-       int ret;
-
-       /* asking for the data path parameters */
-       wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
-                               GFP_KERNEL);
-       if (!wl->data_path) {
-               wl1251_error("Couldnt allocate data path parameters");
-               return -ENOMEM;
-       }
-
-       ret = wl1251_acx_data_path_params(wl, wl->data_path);
-       if (ret < 0) {
-               kfree(wl->data_path);
-               wl->data_path = NULL;
-               return ret;
-       }
-
-       return 0;
-}
-
-
-int wl1251_hw_init(struct wl1251 *wl)
-{
-       struct wl1251_acx_mem_map *wl_mem_map;
-       int ret;
-
-       ret = wl1251_hw_init_hwenc_config(wl);
-       if (ret < 0)
-               return ret;
-
-       /* Template settings */
-       ret = wl1251_hw_init_templates_config(wl);
-       if (ret < 0)
-               return ret;
-
-       /* Default memory configuration */
-       ret = wl1251_hw_init_mem_config(wl);
-       if (ret < 0)
-               return ret;
-
-       /* Default data path configuration  */
-       ret = wl1251_hw_init_data_path_config(wl);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       /* RX config */
-       ret = wl1251_hw_init_rx_config(wl,
-                                      RX_CFG_PROMISCUOUS | RX_CFG_TSF,
-                                      RX_FILTER_OPTION_DEF);
-       /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
-          RX_FILTER_OPTION_FILTER_ALL); */
-       if (ret < 0)
-               goto out_free_data_path;
-
-       /* TX queues config */
-       ret = wl1251_hw_init_tx_queue_config(wl);
-       if (ret < 0)
-               goto out_free_data_path;
-
-       /* PHY layer config */
-       ret = wl1251_hw_init_phy_config(wl);
-       if (ret < 0)
-               goto out_free_data_path;
-
-       /* Initialize connection monitoring thresholds */
-       ret = wl1251_acx_conn_monit_params(wl);
-       if (ret < 0)
-               goto out_free_data_path;
-
-       /* Beacon filtering */
-       ret = wl1251_hw_init_beacon_filter(wl);
-       if (ret < 0)
-               goto out_free_data_path;
-
-       /* Bluetooth WLAN coexistence */
-       ret = wl1251_hw_init_pta(wl);
-       if (ret < 0)
-               goto out_free_data_path;
-
-       /* Energy detection */
-       ret = wl1251_hw_init_energy_detection(wl);
-       if (ret < 0)
-               goto out_free_data_path;
-
-       /* Beacons and boradcast settings */
-       ret = wl1251_hw_init_beacon_broadcast(wl);
-       if (ret < 0)
-               goto out_free_data_path;
-
-       /* Enable data path */
-       ret = wl1251_cmd_data_path(wl, wl->channel, 1);
-       if (ret < 0)
-               goto out_free_data_path;
-
-       /* Default power state */
-       ret = wl1251_hw_init_power_auth(wl);
-       if (ret < 0)
-               goto out_free_data_path;
-
-       wl_mem_map = wl->target_mem_map;
-       wl1251_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
-                   wl_mem_map->num_tx_mem_blocks,
-                   wl->data_path->tx_control_addr,
-                   wl_mem_map->num_rx_mem_blocks,
-                   wl->data_path->rx_control_addr);
-
-       return 0;
-
- out_free_data_path:
-       kfree(wl->data_path);
-
- out_free_memmap:
-       kfree(wl->target_mem_map);
-
-       return ret;
-}
diff --git a/drivers/net/wireless/wl1251/init.h b/drivers/net/wireless/wl1251/init.h
deleted file mode 100644 (file)
index 543f175..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (C) 2009 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __WL1251_INIT_H__
-#define __WL1251_INIT_H__
-
-#include "wl1251.h"
-
-enum {
-       /* best effort/legacy */
-       AC_BE = 0,
-
-       /* background */
-       AC_BK = 1,
-
-       /* video */
-       AC_VI = 2,
-
-       /* voice */
-       AC_VO = 3,
-
-       /* broadcast dummy access category */
-       AC_BCAST = 4,
-
-       NUM_ACCESS_CATEGORIES = 4
-};
-
-/* following are defult values for the IE fields*/
-#define CWMIN_BK  15
-#define CWMIN_BE  15
-#define CWMIN_VI  7
-#define CWMIN_VO  3
-#define CWMAX_BK  1023
-#define CWMAX_BE  63
-#define CWMAX_VI  15
-#define CWMAX_VO  7
-
-/* slot number setting to start transmission at PIFS interval */
-#define AIFS_PIFS 1
-
-/*
- * slot number setting to start transmission at DIFS interval - normal DCF
- * access
- */
-#define AIFS_DIFS 2
-
-#define AIFSN_BK  7
-#define AIFSN_BE  3
-#define AIFSN_VI  AIFS_PIFS
-#define AIFSN_VO  AIFS_PIFS
-#define TXOP_BK   0
-#define TXOP_BE   0
-#define TXOP_VI   3008
-#define TXOP_VO   1504
-
-int wl1251_hw_init_hwenc_config(struct wl1251 *wl);
-int wl1251_hw_init_templates_config(struct wl1251 *wl);
-int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter);
-int wl1251_hw_init_phy_config(struct wl1251 *wl);
-int wl1251_hw_init_beacon_filter(struct wl1251 *wl);
-int wl1251_hw_init_pta(struct wl1251 *wl);
-int wl1251_hw_init_energy_detection(struct wl1251 *wl);
-int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl);
-int wl1251_hw_init_power_auth(struct wl1251 *wl);
-int wl1251_hw_init_mem_config(struct wl1251 *wl);
-int wl1251_hw_init(struct wl1251 *wl);
-
-#endif
diff --git a/drivers/net/wireless/wl1251/io.c b/drivers/net/wireless/wl1251/io.c
deleted file mode 100644 (file)
index cdcadbf..0000000
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * This file is part of wl12xx
- *
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include "wl1251.h"
-#include "reg.h"
-#include "io.h"
-
-/* FIXME: this is static data nowadays and the table can be removed */
-static enum wl12xx_acx_int_reg wl1251_io_reg_table[ACX_REG_TABLE_LEN] = {
-       [ACX_REG_INTERRUPT_TRIG]     = (REGISTERS_BASE + 0x0474),
-       [ACX_REG_INTERRUPT_TRIG_H]   = (REGISTERS_BASE + 0x0478),
-       [ACX_REG_INTERRUPT_MASK]     = (REGISTERS_BASE + 0x0494),
-       [ACX_REG_HINT_MASK_SET]      = (REGISTERS_BASE + 0x0498),
-       [ACX_REG_HINT_MASK_CLR]      = (REGISTERS_BASE + 0x049C),
-       [ACX_REG_INTERRUPT_NO_CLEAR] = (REGISTERS_BASE + 0x04B0),
-       [ACX_REG_INTERRUPT_CLEAR]    = (REGISTERS_BASE + 0x04A4),
-       [ACX_REG_INTERRUPT_ACK]      = (REGISTERS_BASE + 0x04A8),
-       [ACX_REG_SLV_SOFT_RESET]     = (REGISTERS_BASE + 0x0000),
-       [ACX_REG_EE_START]           = (REGISTERS_BASE + 0x080C),
-       [ACX_REG_ECPU_CONTROL]       = (REGISTERS_BASE + 0x0804)
-};
-
-static int wl1251_translate_reg_addr(struct wl1251 *wl, int addr)
-{
-       /* If the address is lower than REGISTERS_BASE, it means that this is
-        * a chip-specific register address, so look it up in the registers
-        * table */
-       if (addr < REGISTERS_BASE) {
-               /* Make sure we don't go over the table */
-               if (addr >= ACX_REG_TABLE_LEN) {
-                       wl1251_error("address out of range (%d)", addr);
-                       return -EINVAL;
-               }
-               addr = wl1251_io_reg_table[addr];
-       }
-
-       return addr - wl->physical_reg_addr + wl->virtual_reg_addr;
-}
-
-static int wl1251_translate_mem_addr(struct wl1251 *wl, int addr)
-{
-       return addr - wl->physical_mem_addr + wl->virtual_mem_addr;
-}
-
-void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len)
-{
-       int physical;
-
-       physical = wl1251_translate_mem_addr(wl, addr);
-
-       wl->if_ops->read(wl, physical, buf, len);
-}
-
-void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len)
-{
-       int physical;
-
-       physical = wl1251_translate_mem_addr(wl, addr);
-
-       wl->if_ops->write(wl, physical, buf, len);
-}
-
-u32 wl1251_mem_read32(struct wl1251 *wl, int addr)
-{
-       return wl1251_read32(wl, wl1251_translate_mem_addr(wl, addr));
-}
-
-void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val)
-{
-       wl1251_write32(wl, wl1251_translate_mem_addr(wl, addr), val);
-}
-
-u32 wl1251_reg_read32(struct wl1251 *wl, int addr)
-{
-       return wl1251_read32(wl, wl1251_translate_reg_addr(wl, addr));
-}
-
-void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val)
-{
-       wl1251_write32(wl, wl1251_translate_reg_addr(wl, addr), val);
-}
-
-/* Set the partitions to access the chip addresses.
- *
- * There are two VIRTUAL partitions (the memory partition and the
- * registers partition), which are mapped to two different areas of the
- * PHYSICAL (hardware) memory.  This function also makes other checks to
- * ensure that the partitions are not overlapping.  In the diagram below, the
- * memory partition comes before the register partition, but the opposite is
- * also supported.
- *
- *                               PHYSICAL address
- *                                     space
- *
- *                                    |    |
- *                                 ...+----+--> mem_start
- *          VIRTUAL address     ...   |    |
- *               space       ...      |    | [PART_0]
- *                        ...         |    |
- * 0x00000000 <--+----+...         ...+----+--> mem_start + mem_size
- *               |    |         ...   |    |
- *               |MEM |      ...      |    |
- *               |    |   ...         |    |
- *  part_size <--+----+...            |    | {unused area)
- *               |    |   ...         |    |
- *               |REG |      ...      |    |
- *  part_size    |    |         ...   |    |
- *      +     <--+----+...         ...+----+--> reg_start
- *  reg_size              ...         |    |
- *                           ...      |    | [PART_1]
- *                              ...   |    |
- *                                 ...+----+--> reg_start + reg_size
- *                                    |    |
- *
- */
-void wl1251_set_partition(struct wl1251 *wl,
-                         u32 mem_start, u32 mem_size,
-                         u32 reg_start, u32 reg_size)
-{
-       struct wl1251_partition partition[2];
-
-       wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
-                    mem_start, mem_size);
-       wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
-                    reg_start, reg_size);
-
-       /* Make sure that the two partitions together don't exceed the
-        * address range */
-       if ((mem_size + reg_size) > HW_ACCESS_MEMORY_MAX_RANGE) {
-               wl1251_debug(DEBUG_SPI, "Total size exceeds maximum virtual"
-                            " address range.  Truncating partition[0].");
-               mem_size = HW_ACCESS_MEMORY_MAX_RANGE - reg_size;
-               wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
-                            mem_start, mem_size);
-               wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
-                            reg_start, reg_size);
-       }
-
-       if ((mem_start < reg_start) &&
-           ((mem_start + mem_size) > reg_start)) {
-               /* Guarantee that the memory partition doesn't overlap the
-                * registers partition */
-               wl1251_debug(DEBUG_SPI, "End of partition[0] is "
-                            "overlapping partition[1].  Adjusted.");
-               mem_size = reg_start - mem_start;
-               wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
-                            mem_start, mem_size);
-               wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
-                            reg_start, reg_size);
-       } else if ((reg_start < mem_start) &&
-                  ((reg_start + reg_size) > mem_start)) {
-               /* Guarantee that the register partition doesn't overlap the
-                * memory partition */
-               wl1251_debug(DEBUG_SPI, "End of partition[1] is"
-                            " overlapping partition[0].  Adjusted.");
-               reg_size = mem_start - reg_start;
-               wl1251_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
-                            mem_start, mem_size);
-               wl1251_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
-                            reg_start, reg_size);
-       }
-
-       partition[0].start = mem_start;
-       partition[0].size  = mem_size;
-       partition[1].start = reg_start;
-       partition[1].size  = reg_size;
-
-       wl->physical_mem_addr = mem_start;
-       wl->physical_reg_addr = reg_start;
-
-       wl->virtual_mem_addr = 0;
-       wl->virtual_reg_addr = mem_size;
-
-       wl->if_ops->write(wl, HW_ACCESS_PART0_SIZE_ADDR, partition,
-               sizeof(partition));
-}
diff --git a/drivers/net/wireless/wl1251/io.h b/drivers/net/wireless/wl1251/io.h
deleted file mode 100644 (file)
index d382877..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * This file is part of wl12xx
- *
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-#ifndef __WL1251_IO_H__
-#define __WL1251_IO_H__
-
-#include "wl1251.h"
-
-#define HW_ACCESS_MEMORY_MAX_RANGE             0x1FFC0
-
-#define HW_ACCESS_PART0_SIZE_ADDR           0x1FFC0
-#define HW_ACCESS_PART0_START_ADDR          0x1FFC4
-#define HW_ACCESS_PART1_SIZE_ADDR           0x1FFC8
-#define HW_ACCESS_PART1_START_ADDR          0x1FFCC
-
-#define HW_ACCESS_REGISTER_SIZE             4
-
-#define HW_ACCESS_PRAM_MAX_RANGE               0x3c000
-
-static inline u32 wl1251_read32(struct wl1251 *wl, int addr)
-{
-       wl->if_ops->read(wl, addr, &wl->buffer_32, sizeof(wl->buffer_32));
-
-       return le32_to_cpu(wl->buffer_32);
-}
-
-static inline void wl1251_write32(struct wl1251 *wl, int addr, u32 val)
-{
-       wl->buffer_32 = cpu_to_le32(val);
-       wl->if_ops->write(wl, addr, &wl->buffer_32, sizeof(wl->buffer_32));
-}
-
-static inline u32 wl1251_read_elp(struct wl1251 *wl, int addr)
-{
-       u32 response;
-
-       if (wl->if_ops->read_elp)
-               wl->if_ops->read_elp(wl, addr, &response);
-       else
-               wl->if_ops->read(wl, addr, &response, sizeof(u32));
-
-       return response;
-}
-
-static inline void wl1251_write_elp(struct wl1251 *wl, int addr, u32 val)
-{
-       if (wl->if_ops->write_elp)
-               wl->if_ops->write_elp(wl, addr, val);
-       else
-               wl->if_ops->write(wl, addr, &val, sizeof(u32));
-}
-
-/* Memory target IO, address is translated to partition 0 */
-void wl1251_mem_read(struct wl1251 *wl, int addr, void *buf, size_t len);
-void wl1251_mem_write(struct wl1251 *wl, int addr, void *buf, size_t len);
-u32 wl1251_mem_read32(struct wl1251 *wl, int addr);
-void wl1251_mem_write32(struct wl1251 *wl, int addr, u32 val);
-/* Registers IO */
-u32 wl1251_reg_read32(struct wl1251 *wl, int addr);
-void wl1251_reg_write32(struct wl1251 *wl, int addr, u32 val);
-
-void wl1251_set_partition(struct wl1251 *wl,
-                         u32 part_start, u32 part_size,
-                         u32 reg_start,  u32 reg_size);
-
-#endif
diff --git a/drivers/net/wireless/wl1251/main.c b/drivers/net/wireless/wl1251/main.c
deleted file mode 100644 (file)
index 41302c7..0000000
+++ /dev/null
@@ -1,1471 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (C) 2008-2009 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/module.h>
-#include <linux/interrupt.h>
-#include <linux/firmware.h>
-#include <linux/delay.h>
-#include <linux/irq.h>
-#include <linux/crc32.h>
-#include <linux/etherdevice.h>
-#include <linux/vmalloc.h>
-#include <linux/slab.h>
-
-#include "wl1251.h"
-#include "wl12xx_80211.h"
-#include "reg.h"
-#include "io.h"
-#include "cmd.h"
-#include "event.h"
-#include "tx.h"
-#include "rx.h"
-#include "ps.h"
-#include "init.h"
-#include "debugfs.h"
-#include "boot.h"
-
-void wl1251_enable_interrupts(struct wl1251 *wl)
-{
-       wl->if_ops->enable_irq(wl);
-}
-
-void wl1251_disable_interrupts(struct wl1251 *wl)
-{
-       wl->if_ops->disable_irq(wl);
-}
-
-static int wl1251_power_off(struct wl1251 *wl)
-{
-       return wl->if_ops->power(wl, false);
-}
-
-static int wl1251_power_on(struct wl1251 *wl)
-{
-       return wl->if_ops->power(wl, true);
-}
-
-static int wl1251_fetch_firmware(struct wl1251 *wl)
-{
-       const struct firmware *fw;
-       struct device *dev = wiphy_dev(wl->hw->wiphy);
-       int ret;
-
-       ret = request_firmware(&fw, WL1251_FW_NAME, dev);
-
-       if (ret < 0) {
-               wl1251_error("could not get firmware: %d", ret);
-               return ret;
-       }
-
-       if (fw->size % 4) {
-               wl1251_error("firmware size is not multiple of 32 bits: %zu",
-                            fw->size);
-               ret = -EILSEQ;
-               goto out;
-       }
-
-       wl->fw_len = fw->size;
-       wl->fw = vmalloc(wl->fw_len);
-
-       if (!wl->fw) {
-               wl1251_error("could not allocate memory for the firmware");
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       memcpy(wl->fw, fw->data, wl->fw_len);
-
-       ret = 0;
-
-out:
-       release_firmware(fw);
-
-       return ret;
-}
-
-static int wl1251_fetch_nvs(struct wl1251 *wl)
-{
-       const struct firmware *fw;
-       struct device *dev = wiphy_dev(wl->hw->wiphy);
-       int ret;
-
-       ret = request_firmware(&fw, WL1251_NVS_NAME, dev);
-
-       if (ret < 0) {
-               wl1251_error("could not get nvs file: %d", ret);
-               return ret;
-       }
-
-       if (fw->size % 4) {
-               wl1251_error("nvs size is not multiple of 32 bits: %zu",
-                            fw->size);
-               ret = -EILSEQ;
-               goto out;
-       }
-
-       wl->nvs_len = fw->size;
-       wl->nvs = kmemdup(fw->data, wl->nvs_len, GFP_KERNEL);
-
-       if (!wl->nvs) {
-               wl1251_error("could not allocate memory for the nvs file");
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       ret = 0;
-
-out:
-       release_firmware(fw);
-
-       return ret;
-}
-
-static void wl1251_fw_wakeup(struct wl1251 *wl)
-{
-       u32 elp_reg;
-
-       elp_reg = ELPCTRL_WAKE_UP;
-       wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
-       elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
-
-       if (!(elp_reg & ELPCTRL_WLAN_READY))
-               wl1251_warning("WLAN not ready");
-}
-
-static int wl1251_chip_wakeup(struct wl1251 *wl)
-{
-       int ret;
-
-       ret = wl1251_power_on(wl);
-       if (ret < 0)
-               return ret;
-
-       msleep(WL1251_POWER_ON_SLEEP);
-       wl->if_ops->reset(wl);
-
-       /* We don't need a real memory partition here, because we only want
-        * to use the registers at this point. */
-       wl1251_set_partition(wl,
-                            0x00000000,
-                            0x00000000,
-                            REGISTERS_BASE,
-                            REGISTERS_DOWN_SIZE);
-
-       /* ELP module wake up */
-       wl1251_fw_wakeup(wl);
-
-       /* whal_FwCtrl_BootSm() */
-
-       /* 0. read chip id from CHIP_ID */
-       wl->chip_id = wl1251_reg_read32(wl, CHIP_ID_B);
-
-       /* 1. check if chip id is valid */
-
-       switch (wl->chip_id) {
-       case CHIP_ID_1251_PG12:
-               wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG12)",
-                            wl->chip_id);
-               break;
-       case CHIP_ID_1251_PG11:
-               wl1251_debug(DEBUG_BOOT, "chip id 0x%x (1251 PG11)",
-                            wl->chip_id);
-               break;
-       case CHIP_ID_1251_PG10:
-       default:
-               wl1251_error("unsupported chip id: 0x%x", wl->chip_id);
-               ret = -ENODEV;
-               goto out;
-       }
-
-       if (wl->fw == NULL) {
-               ret = wl1251_fetch_firmware(wl);
-               if (ret < 0)
-                       goto out;
-       }
-
-       if (wl->nvs == NULL && !wl->use_eeprom) {
-               /* No NVS from netlink, try to get it from the filesystem */
-               ret = wl1251_fetch_nvs(wl);
-               if (ret < 0)
-                       goto out;
-       }
-
-out:
-       return ret;
-}
-
-#define WL1251_IRQ_LOOP_COUNT 10
-static void wl1251_irq_work(struct work_struct *work)
-{
-       u32 intr, ctr = WL1251_IRQ_LOOP_COUNT;
-       struct wl1251 *wl =
-               container_of(work, struct wl1251, irq_work);
-       int ret;
-
-       mutex_lock(&wl->mutex);
-
-       wl1251_debug(DEBUG_IRQ, "IRQ work");
-
-       if (wl->state == WL1251_STATE_OFF)
-               goto out;
-
-       ret = wl1251_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, WL1251_ACX_INTR_ALL);
-
-       intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
-       wl1251_debug(DEBUG_IRQ, "intr: 0x%x", intr);
-
-       do {
-               if (wl->data_path) {
-                       wl->rx_counter = wl1251_mem_read32(
-                               wl, wl->data_path->rx_control_addr);
-
-                       /* We handle a frmware bug here */
-                       switch ((wl->rx_counter - wl->rx_handled) & 0xf) {
-                       case 0:
-                               wl1251_debug(DEBUG_IRQ,
-                                            "RX: FW and host in sync");
-                               intr &= ~WL1251_ACX_INTR_RX0_DATA;
-                               intr &= ~WL1251_ACX_INTR_RX1_DATA;
-                               break;
-                       case 1:
-                               wl1251_debug(DEBUG_IRQ, "RX: FW +1");
-                               intr |= WL1251_ACX_INTR_RX0_DATA;
-                               intr &= ~WL1251_ACX_INTR_RX1_DATA;
-                               break;
-                       case 2:
-                               wl1251_debug(DEBUG_IRQ, "RX: FW +2");
-                               intr |= WL1251_ACX_INTR_RX0_DATA;
-                               intr |= WL1251_ACX_INTR_RX1_DATA;
-                               break;
-                       default:
-                               wl1251_warning(
-                                       "RX: FW and host out of sync: %d",
-                                       wl->rx_counter - wl->rx_handled);
-                               break;
-                       }
-
-                       wl->rx_handled = wl->rx_counter;
-
-                       wl1251_debug(DEBUG_IRQ, "RX counter: %d",
-                                    wl->rx_counter);
-               }
-
-               intr &= wl->intr_mask;
-
-               if (intr == 0) {
-                       wl1251_debug(DEBUG_IRQ, "INTR is 0");
-                       goto out_sleep;
-               }
-
-               if (intr & WL1251_ACX_INTR_RX0_DATA) {
-                       wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX0_DATA");
-                       wl1251_rx(wl);
-               }
-
-               if (intr & WL1251_ACX_INTR_RX1_DATA) {
-                       wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_RX1_DATA");
-                       wl1251_rx(wl);
-               }
-
-               if (intr & WL1251_ACX_INTR_TX_RESULT) {
-                       wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_TX_RESULT");
-                       wl1251_tx_complete(wl);
-               }
-
-               if (intr & WL1251_ACX_INTR_EVENT_A) {
-                       wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT_A");
-                       wl1251_event_handle(wl, 0);
-               }
-
-               if (intr & WL1251_ACX_INTR_EVENT_B) {
-                       wl1251_debug(DEBUG_IRQ, "WL1251_ACX_INTR_EVENT_B");
-                       wl1251_event_handle(wl, 1);
-               }
-
-               if (intr & WL1251_ACX_INTR_INIT_COMPLETE)
-                       wl1251_debug(DEBUG_IRQ,
-                                    "WL1251_ACX_INTR_INIT_COMPLETE");
-
-               if (--ctr == 0)
-                       break;
-
-               intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_CLEAR);
-       } while (intr);
-
-out_sleep:
-       wl1251_reg_write32(wl, ACX_REG_INTERRUPT_MASK, ~(wl->intr_mask));
-       wl1251_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-static int wl1251_join(struct wl1251 *wl, u8 bss_type, u8 channel,
-                      u16 beacon_interval, u8 dtim_period)
-{
-       int ret;
-
-       ret = wl1251_acx_frame_rates(wl, DEFAULT_HW_GEN_TX_RATE,
-                                    DEFAULT_HW_GEN_MODULATION_TYPE,
-                                    wl->tx_mgmt_frm_rate,
-                                    wl->tx_mgmt_frm_mod);
-       if (ret < 0)
-               goto out;
-
-
-       ret = wl1251_cmd_join(wl, bss_type, channel, beacon_interval,
-                             dtim_period);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1251_event_wait(wl, JOIN_EVENT_COMPLETE_ID, 100);
-       if (ret < 0)
-               wl1251_warning("join timeout");
-
-out:
-       return ret;
-}
-
-static void wl1251_filter_work(struct work_struct *work)
-{
-       struct wl1251 *wl =
-               container_of(work, struct wl1251, filter_work);
-       int ret;
-
-       mutex_lock(&wl->mutex);
-
-       if (wl->state == WL1251_STATE_OFF)
-               goto out;
-
-       ret = wl1251_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1251_join(wl, wl->bss_type, wl->channel, wl->beacon_int,
-                         wl->dtim_period);
-       if (ret < 0)
-               goto out_sleep;
-
-out_sleep:
-       wl1251_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-static void wl1251_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
-{
-       struct wl1251 *wl = hw->priv;
-       unsigned long flags;
-
-       skb_queue_tail(&wl->tx_queue, skb);
-
-       /*
-        * The chip specific setup must run before the first TX packet -
-        * before that, the tx_work will not be initialized!
-        */
-
-       ieee80211_queue_work(wl->hw, &wl->tx_work);
-
-       /*
-        * The workqueue is slow to process the tx_queue and we need stop
-        * the queue here, otherwise the queue will get too long.
-        */
-       if (skb_queue_len(&wl->tx_queue) >= WL1251_TX_QUEUE_HIGH_WATERMARK) {
-               wl1251_debug(DEBUG_TX, "op_tx: tx_queue full, stop queues");
-
-               spin_lock_irqsave(&wl->wl_lock, flags);
-               ieee80211_stop_queues(wl->hw);
-               wl->tx_queue_stopped = true;
-               spin_unlock_irqrestore(&wl->wl_lock, flags);
-       }
-}
-
-static int wl1251_op_start(struct ieee80211_hw *hw)
-{
-       struct wl1251 *wl = hw->priv;
-       struct wiphy *wiphy = hw->wiphy;
-       int ret = 0;
-
-       wl1251_debug(DEBUG_MAC80211, "mac80211 start");
-
-       mutex_lock(&wl->mutex);
-
-       if (wl->state != WL1251_STATE_OFF) {
-               wl1251_error("cannot start because not in off state: %d",
-                            wl->state);
-               ret = -EBUSY;
-               goto out;
-       }
-
-       ret = wl1251_chip_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1251_boot(wl);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1251_hw_init(wl);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1251_acx_station_id(wl);
-       if (ret < 0)
-               goto out;
-
-       wl->state = WL1251_STATE_ON;
-
-       wl1251_info("firmware booted (%s)", wl->fw_ver);
-
-       /* update hw/fw version info in wiphy struct */
-       wiphy->hw_version = wl->chip_id;
-       strncpy(wiphy->fw_version, wl->fw_ver, sizeof(wiphy->fw_version));
-
-out:
-       if (ret < 0)
-               wl1251_power_off(wl);
-
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-static void wl1251_op_stop(struct ieee80211_hw *hw)
-{
-       struct wl1251 *wl = hw->priv;
-
-       wl1251_info("down");
-
-       wl1251_debug(DEBUG_MAC80211, "mac80211 stop");
-
-       mutex_lock(&wl->mutex);
-
-       WARN_ON(wl->state != WL1251_STATE_ON);
-
-       if (wl->scanning) {
-               ieee80211_scan_completed(wl->hw, true);
-               wl->scanning = false;
-       }
-
-       wl->state = WL1251_STATE_OFF;
-
-       wl1251_disable_interrupts(wl);
-
-       mutex_unlock(&wl->mutex);
-
-       cancel_work_sync(&wl->irq_work);
-       cancel_work_sync(&wl->tx_work);
-       cancel_work_sync(&wl->filter_work);
-
-       mutex_lock(&wl->mutex);
-
-       /* let's notify MAC80211 about the remaining pending TX frames */
-       wl1251_tx_flush(wl);
-       wl1251_power_off(wl);
-
-       memset(wl->bssid, 0, ETH_ALEN);
-       wl->listen_int = 1;
-       wl->bss_type = MAX_BSS_TYPE;
-
-       wl->data_in_count = 0;
-       wl->rx_counter = 0;
-       wl->rx_handled = 0;
-       wl->rx_current_buffer = 0;
-       wl->rx_last_id = 0;
-       wl->next_tx_complete = 0;
-       wl->elp = false;
-       wl->station_mode = STATION_ACTIVE_MODE;
-       wl->tx_queue_stopped = false;
-       wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
-       wl->rssi_thold = 0;
-       wl->channel = WL1251_DEFAULT_CHANNEL;
-
-       wl1251_debugfs_reset(wl);
-
-       mutex_unlock(&wl->mutex);
-}
-
-static int wl1251_op_add_interface(struct ieee80211_hw *hw,
-                                  struct ieee80211_vif *vif)
-{
-       struct wl1251 *wl = hw->priv;
-       int ret = 0;
-
-       vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
-                            IEEE80211_VIF_SUPPORTS_CQM_RSSI;
-
-       wl1251_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
-                    vif->type, vif->addr);
-
-       mutex_lock(&wl->mutex);
-       if (wl->vif) {
-               ret = -EBUSY;
-               goto out;
-       }
-
-       wl->vif = vif;
-
-       switch (vif->type) {
-       case NL80211_IFTYPE_STATION:
-               wl->bss_type = BSS_TYPE_STA_BSS;
-               break;
-       case NL80211_IFTYPE_ADHOC:
-               wl->bss_type = BSS_TYPE_IBSS;
-               break;
-       default:
-               ret = -EOPNOTSUPP;
-               goto out;
-       }
-
-       if (memcmp(wl->mac_addr, vif->addr, ETH_ALEN)) {
-               memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
-               SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
-               ret = wl1251_acx_station_id(wl);
-               if (ret < 0)
-                       goto out;
-       }
-
-out:
-       mutex_unlock(&wl->mutex);
-       return ret;
-}
-
-static void wl1251_op_remove_interface(struct ieee80211_hw *hw,
-                                        struct ieee80211_vif *vif)
-{
-       struct wl1251 *wl = hw->priv;
-
-       mutex_lock(&wl->mutex);
-       wl1251_debug(DEBUG_MAC80211, "mac80211 remove interface");
-       wl->vif = NULL;
-       mutex_unlock(&wl->mutex);
-}
-
-static int wl1251_build_qos_null_data(struct wl1251 *wl)
-{
-       struct ieee80211_qos_hdr template;
-
-       memset(&template, 0, sizeof(template));
-
-       memcpy(template.addr1, wl->bssid, ETH_ALEN);
-       memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
-       memcpy(template.addr3, wl->bssid, ETH_ALEN);
-
-       template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
-                                            IEEE80211_STYPE_QOS_NULLFUNC |
-                                            IEEE80211_FCTL_TODS);
-
-       /* FIXME: not sure what priority to use here */
-       template.qos_ctrl = cpu_to_le16(0);
-
-       return wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, &template,
-                                      sizeof(template));
-}
-
-static int wl1251_op_config(struct ieee80211_hw *hw, u32 changed)
-{
-       struct wl1251 *wl = hw->priv;
-       struct ieee80211_conf *conf = &hw->conf;
-       int channel, ret = 0;
-
-       channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
-
-       wl1251_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d",
-                    channel,
-                    conf->flags & IEEE80211_CONF_PS ? "on" : "off",
-                    conf->power_level);
-
-       mutex_lock(&wl->mutex);
-
-       ret = wl1251_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       if (channel != wl->channel) {
-               wl->channel = channel;
-
-               ret = wl1251_join(wl, wl->bss_type, wl->channel,
-                                 wl->beacon_int, wl->dtim_period);
-               if (ret < 0)
-                       goto out_sleep;
-       }
-
-       if (conf->flags & IEEE80211_CONF_PS && !wl->psm_requested) {
-               wl1251_debug(DEBUG_PSM, "psm enabled");
-
-               wl->psm_requested = true;
-
-               wl->dtim_period = conf->ps_dtim_period;
-
-               ret = wl1251_acx_wr_tbtt_and_dtim(wl, wl->beacon_int,
-                                                 wl->dtim_period);
-
-               /*
-                * mac80211 enables PSM only if we're already associated.
-                */
-               ret = wl1251_ps_set_mode(wl, STATION_POWER_SAVE_MODE);
-               if (ret < 0)
-                       goto out_sleep;
-       } else if (!(conf->flags & IEEE80211_CONF_PS) &&
-                  wl->psm_requested) {
-               wl1251_debug(DEBUG_PSM, "psm disabled");
-
-               wl->psm_requested = false;
-
-               if (wl->station_mode != STATION_ACTIVE_MODE) {
-                       ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
-                       if (ret < 0)
-                               goto out_sleep;
-               }
-       }
-
-       if (changed & IEEE80211_CONF_CHANGE_IDLE) {
-               if (conf->flags & IEEE80211_CONF_IDLE) {
-                       ret = wl1251_ps_set_mode(wl, STATION_IDLE);
-                       if (ret < 0)
-                               goto out_sleep;
-               } else {
-                       ret = wl1251_ps_set_mode(wl, STATION_ACTIVE_MODE);
-                       if (ret < 0)
-                               goto out_sleep;
-                       ret = wl1251_join(wl, wl->bss_type, wl->channel,
-                                         wl->beacon_int, wl->dtim_period);
-                       if (ret < 0)
-                               goto out_sleep;
-               }
-       }
-
-       if (conf->power_level != wl->power_level) {
-               ret = wl1251_acx_tx_power(wl, conf->power_level);
-               if (ret < 0)
-                       goto out_sleep;
-
-               wl->power_level = conf->power_level;
-       }
-
-out_sleep:
-       wl1251_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-#define WL1251_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
-                                 FIF_ALLMULTI | \
-                                 FIF_FCSFAIL | \
-                                 FIF_BCN_PRBRESP_PROMISC | \
-                                 FIF_CONTROL | \
-                                 FIF_OTHER_BSS)
-
-static void wl1251_op_configure_filter(struct ieee80211_hw *hw,
-                                      unsigned int changed,
-                                      unsigned int *total,u64 multicast)
-{
-       struct wl1251 *wl = hw->priv;
-
-       wl1251_debug(DEBUG_MAC80211, "mac80211 configure filter");
-
-       *total &= WL1251_SUPPORTED_FILTERS;
-       changed &= WL1251_SUPPORTED_FILTERS;
-
-       if (changed == 0)
-               /* no filters which we support changed */
-               return;
-
-       /* FIXME: wl->rx_config and wl->rx_filter are not protected */
-
-       wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
-       wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
-
-       if (*total & FIF_PROMISC_IN_BSS) {
-               wl->rx_config |= CFG_BSSID_FILTER_EN;
-               wl->rx_config |= CFG_RX_ALL_GOOD;
-       }
-       if (*total & FIF_ALLMULTI)
-               /*
-                * CFG_MC_FILTER_EN in rx_config needs to be 0 to receive
-                * all multicast frames
-                */
-               wl->rx_config &= ~CFG_MC_FILTER_EN;
-       if (*total & FIF_FCSFAIL)
-               wl->rx_filter |= CFG_RX_FCS_ERROR;
-       if (*total & FIF_BCN_PRBRESP_PROMISC) {
-               wl->rx_config &= ~CFG_BSSID_FILTER_EN;
-               wl->rx_config &= ~CFG_SSID_FILTER_EN;
-       }
-       if (*total & FIF_CONTROL)
-               wl->rx_filter |= CFG_RX_CTL_EN;
-       if (*total & FIF_OTHER_BSS)
-               wl->rx_filter &= ~CFG_BSSID_FILTER_EN;
-
-       /*
-        * FIXME: workqueues need to be properly cancelled on stop(), for
-        * now let's just disable changing the filter settings. They will
-        * be updated any on config().
-        */
-       /* schedule_work(&wl->filter_work); */
-}
-
-/* HW encryption */
-static int wl1251_set_key_type(struct wl1251 *wl,
-                              struct wl1251_cmd_set_keys *key,
-                              enum set_key_cmd cmd,
-                              struct ieee80211_key_conf *mac80211_key,
-                              const u8 *addr)
-{
-       switch (mac80211_key->cipher) {
-       case WLAN_CIPHER_SUITE_WEP40:
-       case WLAN_CIPHER_SUITE_WEP104:
-               if (is_broadcast_ether_addr(addr))
-                       key->key_type = KEY_WEP_DEFAULT;
-               else
-                       key->key_type = KEY_WEP_ADDR;
-
-               mac80211_key->hw_key_idx = mac80211_key->keyidx;
-               break;
-       case WLAN_CIPHER_SUITE_TKIP:
-               if (is_broadcast_ether_addr(addr))
-                       key->key_type = KEY_TKIP_MIC_GROUP;
-               else
-                       key->key_type = KEY_TKIP_MIC_PAIRWISE;
-
-               mac80211_key->hw_key_idx = mac80211_key->keyidx;
-               break;
-       case WLAN_CIPHER_SUITE_CCMP:
-               if (is_broadcast_ether_addr(addr))
-                       key->key_type = KEY_AES_GROUP;
-               else
-                       key->key_type = KEY_AES_PAIRWISE;
-               mac80211_key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
-               break;
-       default:
-               wl1251_error("Unknown key cipher 0x%x", mac80211_key->cipher);
-               return -EOPNOTSUPP;
-       }
-
-       return 0;
-}
-
-static int wl1251_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
-                            struct ieee80211_vif *vif,
-                            struct ieee80211_sta *sta,
-                            struct ieee80211_key_conf *key)
-{
-       struct wl1251 *wl = hw->priv;
-       struct wl1251_cmd_set_keys *wl_cmd;
-       const u8 *addr;
-       int ret;
-
-       static const u8 bcast_addr[ETH_ALEN] =
-               { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
-
-       wl1251_debug(DEBUG_MAC80211, "mac80211 set key");
-
-       wl_cmd = kzalloc(sizeof(*wl_cmd), GFP_KERNEL);
-       if (!wl_cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       addr = sta ? sta->addr : bcast_addr;
-
-       wl1251_debug(DEBUG_CRYPT, "CMD: 0x%x", cmd);
-       wl1251_dump(DEBUG_CRYPT, "ADDR: ", addr, ETH_ALEN);
-       wl1251_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
-                    key->cipher, key->keyidx, key->keylen, key->flags);
-       wl1251_dump(DEBUG_CRYPT, "KEY: ", key->key, key->keylen);
-
-       if (is_zero_ether_addr(addr)) {
-               /* We dont support TX only encryption */
-               ret = -EOPNOTSUPP;
-               goto out;
-       }
-
-       mutex_lock(&wl->mutex);
-
-       ret = wl1251_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out_unlock;
-
-       switch (cmd) {
-       case SET_KEY:
-               wl_cmd->key_action = KEY_ADD_OR_REPLACE;
-               break;
-       case DISABLE_KEY:
-               wl_cmd->key_action = KEY_REMOVE;
-               break;
-       default:
-               wl1251_error("Unsupported key cmd 0x%x", cmd);
-               break;
-       }
-
-       ret = wl1251_set_key_type(wl, wl_cmd, cmd, key, addr);
-       if (ret < 0) {
-               wl1251_error("Set KEY type failed");
-               goto out_sleep;
-       }
-
-       if (wl_cmd->key_type != KEY_WEP_DEFAULT)
-               memcpy(wl_cmd->addr, addr, ETH_ALEN);
-
-       if ((wl_cmd->key_type == KEY_TKIP_MIC_GROUP) ||
-           (wl_cmd->key_type == KEY_TKIP_MIC_PAIRWISE)) {
-               /*
-                * We get the key in the following form:
-                * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
-                * but the target is expecting:
-                * TKIP - RX MIC - TX MIC
-                */
-               memcpy(wl_cmd->key, key->key, 16);
-               memcpy(wl_cmd->key + 16, key->key + 24, 8);
-               memcpy(wl_cmd->key + 24, key->key + 16, 8);
-
-       } else {
-               memcpy(wl_cmd->key, key->key, key->keylen);
-       }
-       wl_cmd->key_size = key->keylen;
-
-       wl_cmd->id = key->keyidx;
-       wl_cmd->ssid_profile = 0;
-
-       wl1251_dump(DEBUG_CRYPT, "TARGET KEY: ", wl_cmd, sizeof(*wl_cmd));
-
-       ret = wl1251_cmd_send(wl, CMD_SET_KEYS, wl_cmd, sizeof(*wl_cmd));
-       if (ret < 0) {
-               wl1251_warning("could not set keys");
-               goto out_sleep;
-       }
-
-out_sleep:
-       wl1251_ps_elp_sleep(wl);
-
-out_unlock:
-       mutex_unlock(&wl->mutex);
-
-out:
-       kfree(wl_cmd);
-
-       return ret;
-}
-
-static int wl1251_op_hw_scan(struct ieee80211_hw *hw,
-                            struct ieee80211_vif *vif,
-                            struct cfg80211_scan_request *req)
-{
-       struct wl1251 *wl = hw->priv;
-       struct sk_buff *skb;
-       size_t ssid_len = 0;
-       u8 *ssid = NULL;
-       int ret;
-
-       wl1251_debug(DEBUG_MAC80211, "mac80211 hw scan");
-
-       if (req->n_ssids) {
-               ssid = req->ssids[0].ssid;
-               ssid_len = req->ssids[0].ssid_len;
-       }
-
-       mutex_lock(&wl->mutex);
-
-       if (wl->scanning) {
-               wl1251_debug(DEBUG_SCAN, "scan already in progress");
-               ret = -EINVAL;
-               goto out;
-       }
-
-       ret = wl1251_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
-                                    req->ie, req->ie_len);
-       if (!skb) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, skb->data,
-                                     skb->len);
-       dev_kfree_skb(skb);
-       if (ret < 0)
-               goto out_sleep;
-
-       ret = wl1251_cmd_trigger_scan_to(wl, 0);
-       if (ret < 0)
-               goto out_sleep;
-
-       wl->scanning = true;
-
-       ret = wl1251_cmd_scan(wl, ssid, ssid_len, req->channels,
-                             req->n_channels, WL1251_SCAN_NUM_PROBES);
-       if (ret < 0) {
-               wl->scanning = false;
-               goto out_sleep;
-       }
-
-out_sleep:
-       wl1251_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-static int wl1251_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
-{
-       struct wl1251 *wl = hw->priv;
-       int ret;
-
-       mutex_lock(&wl->mutex);
-
-       ret = wl1251_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1251_acx_rts_threshold(wl, (u16) value);
-       if (ret < 0)
-               wl1251_warning("wl1251_op_set_rts_threshold failed: %d", ret);
-
-       wl1251_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-static void wl1251_op_bss_info_changed(struct ieee80211_hw *hw,
-                                      struct ieee80211_vif *vif,
-                                      struct ieee80211_bss_conf *bss_conf,
-                                      u32 changed)
-{
-       struct wl1251 *wl = hw->priv;
-       struct sk_buff *beacon, *skb;
-       int ret;
-
-       wl1251_debug(DEBUG_MAC80211, "mac80211 bss info changed");
-
-       mutex_lock(&wl->mutex);
-
-       ret = wl1251_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       if (changed & BSS_CHANGED_CQM) {
-               ret = wl1251_acx_low_rssi(wl, bss_conf->cqm_rssi_thold,
-                                         WL1251_DEFAULT_LOW_RSSI_WEIGHT,
-                                         WL1251_DEFAULT_LOW_RSSI_DEPTH,
-                                         WL1251_ACX_LOW_RSSI_TYPE_EDGE);
-               if (ret < 0)
-                       goto out;
-               wl->rssi_thold = bss_conf->cqm_rssi_thold;
-       }
-
-       if (changed & BSS_CHANGED_BSSID) {
-               memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
-
-               skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
-               if (!skb)
-                       goto out_sleep;
-
-               ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA,
-                                             skb->data, skb->len);
-               dev_kfree_skb(skb);
-               if (ret < 0)
-                       goto out_sleep;
-
-               ret = wl1251_build_qos_null_data(wl);
-               if (ret < 0)
-                       goto out;
-
-               if (wl->bss_type != BSS_TYPE_IBSS) {
-                       ret = wl1251_join(wl, wl->bss_type, wl->channel,
-                                         wl->beacon_int, wl->dtim_period);
-                       if (ret < 0)
-                               goto out_sleep;
-               }
-       }
-
-       if (changed & BSS_CHANGED_ASSOC) {
-               if (bss_conf->assoc) {
-                       wl->beacon_int = bss_conf->beacon_int;
-
-                       skb = ieee80211_pspoll_get(wl->hw, wl->vif);
-                       if (!skb)
-                               goto out_sleep;
-
-                       ret = wl1251_cmd_template_set(wl, CMD_PS_POLL,
-                                                     skb->data,
-                                                     skb->len);
-                       dev_kfree_skb(skb);
-                       if (ret < 0)
-                               goto out_sleep;
-
-                       ret = wl1251_acx_aid(wl, bss_conf->aid);
-                       if (ret < 0)
-                               goto out_sleep;
-               } else {
-                       /* use defaults when not associated */
-                       wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
-                       wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD;
-               }
-       }
-       if (changed & BSS_CHANGED_ERP_SLOT) {
-               if (bss_conf->use_short_slot)
-                       ret = wl1251_acx_slot(wl, SLOT_TIME_SHORT);
-               else
-                       ret = wl1251_acx_slot(wl, SLOT_TIME_LONG);
-               if (ret < 0) {
-                       wl1251_warning("Set slot time failed %d", ret);
-                       goto out_sleep;
-               }
-       }
-
-       if (changed & BSS_CHANGED_ERP_PREAMBLE) {
-               if (bss_conf->use_short_preamble)
-                       wl1251_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
-               else
-                       wl1251_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
-       }
-
-       if (changed & BSS_CHANGED_ERP_CTS_PROT) {
-               if (bss_conf->use_cts_prot)
-                       ret = wl1251_acx_cts_protect(wl, CTSPROTECT_ENABLE);
-               else
-                       ret = wl1251_acx_cts_protect(wl, CTSPROTECT_DISABLE);
-               if (ret < 0) {
-                       wl1251_warning("Set ctsprotect failed %d", ret);
-                       goto out_sleep;
-               }
-       }
-
-       if (changed & BSS_CHANGED_BEACON) {
-               beacon = ieee80211_beacon_get(hw, vif);
-               if (!beacon)
-                       goto out_sleep;
-
-               ret = wl1251_cmd_template_set(wl, CMD_BEACON, beacon->data,
-                                             beacon->len);
-
-               if (ret < 0) {
-                       dev_kfree_skb(beacon);
-                       goto out_sleep;
-               }
-
-               ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, beacon->data,
-                                             beacon->len);
-
-               dev_kfree_skb(beacon);
-
-               if (ret < 0)
-                       goto out_sleep;
-
-               ret = wl1251_join(wl, wl->bss_type, wl->beacon_int,
-                                 wl->channel, wl->dtim_period);
-
-               if (ret < 0)
-                       goto out_sleep;
-       }
-
-out_sleep:
-       wl1251_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-
-/* can't be const, mac80211 writes to this */
-static struct ieee80211_rate wl1251_rates[] = {
-       { .bitrate = 10,
-         .hw_value = 0x1,
-         .hw_value_short = 0x1, },
-       { .bitrate = 20,
-         .hw_value = 0x2,
-         .hw_value_short = 0x2,
-         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
-       { .bitrate = 55,
-         .hw_value = 0x4,
-         .hw_value_short = 0x4,
-         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
-       { .bitrate = 110,
-         .hw_value = 0x20,
-         .hw_value_short = 0x20,
-         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
-       { .bitrate = 60,
-         .hw_value = 0x8,
-         .hw_value_short = 0x8, },
-       { .bitrate = 90,
-         .hw_value = 0x10,
-         .hw_value_short = 0x10, },
-       { .bitrate = 120,
-         .hw_value = 0x40,
-         .hw_value_short = 0x40, },
-       { .bitrate = 180,
-         .hw_value = 0x80,
-         .hw_value_short = 0x80, },
-       { .bitrate = 240,
-         .hw_value = 0x200,
-         .hw_value_short = 0x200, },
-       { .bitrate = 360,
-        .hw_value = 0x400,
-        .hw_value_short = 0x400, },
-       { .bitrate = 480,
-         .hw_value = 0x800,
-         .hw_value_short = 0x800, },
-       { .bitrate = 540,
-         .hw_value = 0x1000,
-         .hw_value_short = 0x1000, },
-};
-
-/* can't be const, mac80211 writes to this */
-static struct ieee80211_channel wl1251_channels[] = {
-       { .hw_value = 1, .center_freq = 2412},
-       { .hw_value = 2, .center_freq = 2417},
-       { .hw_value = 3, .center_freq = 2422},
-       { .hw_value = 4, .center_freq = 2427},
-       { .hw_value = 5, .center_freq = 2432},
-       { .hw_value = 6, .center_freq = 2437},
-       { .hw_value = 7, .center_freq = 2442},
-       { .hw_value = 8, .center_freq = 2447},
-       { .hw_value = 9, .center_freq = 2452},
-       { .hw_value = 10, .center_freq = 2457},
-       { .hw_value = 11, .center_freq = 2462},
-       { .hw_value = 12, .center_freq = 2467},
-       { .hw_value = 13, .center_freq = 2472},
-};
-
-static int wl1251_op_conf_tx(struct ieee80211_hw *hw,
-                            struct ieee80211_vif *vif, u16 queue,
-                            const struct ieee80211_tx_queue_params *params)
-{
-       enum wl1251_acx_ps_scheme ps_scheme;
-       struct wl1251 *wl = hw->priv;
-       int ret;
-
-       mutex_lock(&wl->mutex);
-
-       wl1251_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
-
-       ret = wl1251_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       /* mac80211 uses units of 32 usec */
-       ret = wl1251_acx_ac_cfg(wl, wl1251_tx_get_queue(queue),
-                               params->cw_min, params->cw_max,
-                               params->aifs, params->txop * 32);
-       if (ret < 0)
-               goto out_sleep;
-
-       if (params->uapsd)
-               ps_scheme = WL1251_ACX_PS_SCHEME_UPSD_TRIGGER;
-       else
-               ps_scheme = WL1251_ACX_PS_SCHEME_LEGACY;
-
-       ret = wl1251_acx_tid_cfg(wl, wl1251_tx_get_queue(queue),
-                                CHANNEL_TYPE_EDCF,
-                                wl1251_tx_get_queue(queue), ps_scheme,
-                                WL1251_ACX_ACK_POLICY_LEGACY);
-       if (ret < 0)
-               goto out_sleep;
-
-out_sleep:
-       wl1251_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-static int wl1251_op_get_survey(struct ieee80211_hw *hw, int idx,
-                               struct survey_info *survey)
-{
-       struct wl1251 *wl = hw->priv;
-       struct ieee80211_conf *conf = &hw->conf;
-       if (idx != 0)
-               return -ENOENT;
-       survey->channel = conf->channel;
-       survey->filled = SURVEY_INFO_NOISE_DBM;
-       survey->noise = wl->noise;
-       return 0;
-}
-
-/* can't be const, mac80211 writes to this */
-static struct ieee80211_supported_band wl1251_band_2ghz = {
-       .channels = wl1251_channels,
-       .n_channels = ARRAY_SIZE(wl1251_channels),
-       .bitrates = wl1251_rates,
-       .n_bitrates = ARRAY_SIZE(wl1251_rates),
-};
-
-static const struct ieee80211_ops wl1251_ops = {
-       .start = wl1251_op_start,
-       .stop = wl1251_op_stop,
-       .add_interface = wl1251_op_add_interface,
-       .remove_interface = wl1251_op_remove_interface,
-       .config = wl1251_op_config,
-       .configure_filter = wl1251_op_configure_filter,
-       .tx = wl1251_op_tx,
-       .set_key = wl1251_op_set_key,
-       .hw_scan = wl1251_op_hw_scan,
-       .bss_info_changed = wl1251_op_bss_info_changed,
-       .set_rts_threshold = wl1251_op_set_rts_threshold,
-       .conf_tx = wl1251_op_conf_tx,
-       .get_survey = wl1251_op_get_survey,
-};
-
-static int wl1251_read_eeprom_byte(struct wl1251 *wl, off_t offset, u8 *data)
-{
-       unsigned long timeout;
-
-       wl1251_reg_write32(wl, EE_ADDR, offset);
-       wl1251_reg_write32(wl, EE_CTL, EE_CTL_READ);
-
-       /* EE_CTL_READ clears when data is ready */
-       timeout = jiffies + msecs_to_jiffies(100);
-       while (1) {
-               if (!(wl1251_reg_read32(wl, EE_CTL) & EE_CTL_READ))
-                       break;
-
-               if (time_after(jiffies, timeout))
-                       return -ETIMEDOUT;
-
-               msleep(1);
-       }
-
-       *data = wl1251_reg_read32(wl, EE_DATA);
-       return 0;
-}
-
-static int wl1251_read_eeprom(struct wl1251 *wl, off_t offset,
-                             u8 *data, size_t len)
-{
-       size_t i;
-       int ret;
-
-       wl1251_reg_write32(wl, EE_START, 0);
-
-       for (i = 0; i < len; i++) {
-               ret = wl1251_read_eeprom_byte(wl, offset + i, &data[i]);
-               if (ret < 0)
-                       return ret;
-       }
-
-       return 0;
-}
-
-static int wl1251_read_eeprom_mac(struct wl1251 *wl)
-{
-       u8 mac[ETH_ALEN];
-       int i, ret;
-
-       wl1251_set_partition(wl, 0, 0, REGISTERS_BASE, REGISTERS_DOWN_SIZE);
-
-       ret = wl1251_read_eeprom(wl, 0x1c, mac, sizeof(mac));
-       if (ret < 0) {
-               wl1251_warning("failed to read MAC address from EEPROM");
-               return ret;
-       }
-
-       /* MAC is stored in reverse order */
-       for (i = 0; i < ETH_ALEN; i++)
-               wl->mac_addr[i] = mac[ETH_ALEN - i - 1];
-
-       return 0;
-}
-
-static int wl1251_register_hw(struct wl1251 *wl)
-{
-       int ret;
-
-       if (wl->mac80211_registered)
-               return 0;
-
-       SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
-
-       ret = ieee80211_register_hw(wl->hw);
-       if (ret < 0) {
-               wl1251_error("unable to register mac80211 hw: %d", ret);
-               return ret;
-       }
-
-       wl->mac80211_registered = true;
-
-       wl1251_notice("loaded");
-
-       return 0;
-}
-
-int wl1251_init_ieee80211(struct wl1251 *wl)
-{
-       int ret;
-
-       /* The tx descriptor buffer and the TKIP space */
-       wl->hw->extra_tx_headroom = sizeof(struct tx_double_buffer_desc)
-               + WL1251_TKIP_IV_SPACE;
-
-       /* unit us */
-       /* FIXME: find a proper value */
-       wl->hw->channel_change_time = 10000;
-
-       wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
-               IEEE80211_HW_SUPPORTS_PS |
-               IEEE80211_HW_SUPPORTS_UAPSD;
-
-       wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
-                                        BIT(NL80211_IFTYPE_ADHOC);
-       wl->hw->wiphy->max_scan_ssids = 1;
-       wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &wl1251_band_2ghz;
-
-       wl->hw->queues = 4;
-
-       if (wl->use_eeprom)
-               wl1251_read_eeprom_mac(wl);
-
-       ret = wl1251_register_hw(wl);
-       if (ret)
-               goto out;
-
-       wl1251_debugfs_init(wl);
-       wl1251_notice("initialized");
-
-       ret = 0;
-
-out:
-       return ret;
-}
-EXPORT_SYMBOL_GPL(wl1251_init_ieee80211);
-
-struct ieee80211_hw *wl1251_alloc_hw(void)
-{
-       struct ieee80211_hw *hw;
-       struct wl1251 *wl;
-       int i;
-       static const u8 nokia_oui[3] = {0x00, 0x1f, 0xdf};
-
-       hw = ieee80211_alloc_hw(sizeof(*wl), &wl1251_ops);
-       if (!hw) {
-               wl1251_error("could not alloc ieee80211_hw");
-               return ERR_PTR(-ENOMEM);
-       }
-
-       wl = hw->priv;
-       memset(wl, 0, sizeof(*wl));
-
-       wl->hw = hw;
-
-       wl->data_in_count = 0;
-
-       skb_queue_head_init(&wl->tx_queue);
-
-       INIT_WORK(&wl->filter_work, wl1251_filter_work);
-       INIT_DELAYED_WORK(&wl->elp_work, wl1251_elp_work);
-       wl->channel = WL1251_DEFAULT_CHANNEL;
-       wl->scanning = false;
-       wl->default_key = 0;
-       wl->listen_int = 1;
-       wl->rx_counter = 0;
-       wl->rx_handled = 0;
-       wl->rx_current_buffer = 0;
-       wl->rx_last_id = 0;
-       wl->rx_config = WL1251_DEFAULT_RX_CONFIG;
-       wl->rx_filter = WL1251_DEFAULT_RX_FILTER;
-       wl->elp = false;
-       wl->station_mode = STATION_ACTIVE_MODE;
-       wl->psm_requested = false;
-       wl->tx_queue_stopped = false;
-       wl->power_level = WL1251_DEFAULT_POWER_LEVEL;
-       wl->rssi_thold = 0;
-       wl->beacon_int = WL1251_DEFAULT_BEACON_INT;
-       wl->dtim_period = WL1251_DEFAULT_DTIM_PERIOD;
-       wl->vif = NULL;
-
-       for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
-               wl->tx_frames[i] = NULL;
-
-       wl->next_tx_complete = 0;
-
-       INIT_WORK(&wl->irq_work, wl1251_irq_work);
-       INIT_WORK(&wl->tx_work, wl1251_tx_work);
-
-       /*
-        * In case our MAC address is not correctly set,
-        * we use a random but Nokia MAC.
-        */
-       memcpy(wl->mac_addr, nokia_oui, 3);
-       get_random_bytes(wl->mac_addr + 3, 3);
-
-       wl->state = WL1251_STATE_OFF;
-       mutex_init(&wl->mutex);
-
-       wl->tx_mgmt_frm_rate = DEFAULT_HW_GEN_TX_RATE;
-       wl->tx_mgmt_frm_mod = DEFAULT_HW_GEN_MODULATION_TYPE;
-
-       wl->rx_descriptor = kmalloc(sizeof(*wl->rx_descriptor), GFP_KERNEL);
-       if (!wl->rx_descriptor) {
-               wl1251_error("could not allocate memory for rx descriptor");
-               ieee80211_free_hw(hw);
-               return ERR_PTR(-ENOMEM);
-       }
-
-       return hw;
-}
-EXPORT_SYMBOL_GPL(wl1251_alloc_hw);
-
-int wl1251_free_hw(struct wl1251 *wl)
-{
-       ieee80211_unregister_hw(wl->hw);
-
-       wl1251_debugfs_exit(wl);
-
-       kfree(wl->target_mem_map);
-       kfree(wl->data_path);
-       vfree(wl->fw);
-       wl->fw = NULL;
-       kfree(wl->nvs);
-       wl->nvs = NULL;
-
-       kfree(wl->rx_descriptor);
-       wl->rx_descriptor = NULL;
-
-       ieee80211_free_hw(wl->hw);
-
-       return 0;
-}
-EXPORT_SYMBOL_GPL(wl1251_free_hw);
-
-MODULE_DESCRIPTION("TI wl1251 Wireles LAN Driver Core");
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Kalle Valo <kvalo@adurom.com>");
-MODULE_FIRMWARE(WL1251_FW_NAME);
diff --git a/drivers/net/wireless/wl1251/ps.c b/drivers/net/wireless/wl1251/ps.c
deleted file mode 100644 (file)
index db719f7..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include "reg.h"
-#include "ps.h"
-#include "cmd.h"
-#include "io.h"
-
-/* in ms */
-#define WL1251_WAKEUP_TIMEOUT 100
-
-void wl1251_elp_work(struct work_struct *work)
-{
-       struct delayed_work *dwork;
-       struct wl1251 *wl;
-
-       dwork = container_of(work, struct delayed_work, work);
-       wl = container_of(dwork, struct wl1251, elp_work);
-
-       wl1251_debug(DEBUG_PSM, "elp work");
-
-       mutex_lock(&wl->mutex);
-
-       if (wl->elp || wl->station_mode == STATION_ACTIVE_MODE)
-               goto out;
-
-       wl1251_debug(DEBUG_PSM, "chip to elp");
-       wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
-       wl->elp = true;
-
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-#define ELP_ENTRY_DELAY  5
-
-/* Routines to toggle sleep mode while in ELP */
-void wl1251_ps_elp_sleep(struct wl1251 *wl)
-{
-       unsigned long delay;
-
-       if (wl->station_mode != STATION_ACTIVE_MODE) {
-               delay = msecs_to_jiffies(ELP_ENTRY_DELAY);
-               ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, delay);
-       }
-}
-
-int wl1251_ps_elp_wakeup(struct wl1251 *wl)
-{
-       unsigned long timeout, start;
-       u32 elp_reg;
-
-       if (delayed_work_pending(&wl->elp_work))
-               cancel_delayed_work(&wl->elp_work);
-
-       if (!wl->elp)
-               return 0;
-
-       wl1251_debug(DEBUG_PSM, "waking up chip from elp");
-
-       start = jiffies;
-       timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT);
-
-       wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
-
-       elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
-
-       /*
-        * FIXME: we should wait for irq from chip but, as a temporary
-        * solution to simplify locking, let's poll instead
-        */
-       while (!(elp_reg & ELPCTRL_WLAN_READY)) {
-               if (time_after(jiffies, timeout)) {
-                       wl1251_error("elp wakeup timeout");
-                       return -ETIMEDOUT;
-               }
-               msleep(1);
-               elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
-       }
-
-       wl1251_debug(DEBUG_PSM, "wakeup time: %u ms",
-                    jiffies_to_msecs(jiffies - start));
-
-       wl->elp = false;
-
-       return 0;
-}
-
-int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_station_mode mode)
-{
-       int ret;
-
-       switch (mode) {
-       case STATION_POWER_SAVE_MODE:
-               wl1251_debug(DEBUG_PSM, "entering psm");
-
-               /* enable beacon filtering */
-               ret = wl1251_acx_beacon_filter_opt(wl, true);
-               if (ret < 0)
-                       return ret;
-
-               ret = wl1251_acx_wake_up_conditions(wl,
-                                                   WAKE_UP_EVENT_DTIM_BITMAP,
-                                                   wl->listen_int);
-               if (ret < 0)
-                       return ret;
-
-               ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_ENABLE,
-                                           WL1251_DEFAULT_BET_CONSECUTIVE);
-               if (ret < 0)
-                       return ret;
-
-               ret = wl1251_cmd_ps_mode(wl, CHIP_POWER_SAVE_MODE);
-               if (ret < 0)
-                       return ret;
-
-               ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
-               if (ret < 0)
-                       return ret;
-               break;
-       case STATION_IDLE:
-               wl1251_debug(DEBUG_PSM, "entering idle");
-
-               ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
-               if (ret < 0)
-                       return ret;
-
-               ret = wl1251_cmd_template_set(wl, CMD_DISCONNECT, NULL, 0);
-               if (ret < 0)
-                       return ret;
-               break;
-       case STATION_ACTIVE_MODE:
-       default:
-               wl1251_debug(DEBUG_PSM, "leaving psm");
-
-               ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
-               if (ret < 0)
-                       return ret;
-
-               /* disable BET */
-               ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_DISABLE,
-                                           WL1251_DEFAULT_BET_CONSECUTIVE);
-               if (ret < 0)
-                       return ret;
-
-               /* disable beacon filtering */
-               ret = wl1251_acx_beacon_filter_opt(wl, false);
-               if (ret < 0)
-                       return ret;
-
-               ret = wl1251_acx_wake_up_conditions(wl,
-                                                   WAKE_UP_EVENT_DTIM_BITMAP,
-                                                   wl->listen_int);
-               if (ret < 0)
-                       return ret;
-
-               ret = wl1251_cmd_ps_mode(wl, CHIP_ACTIVE_MODE);
-               if (ret < 0)
-                       return ret;
-
-               break;
-       }
-       wl->station_mode = mode;
-
-       return ret;
-}
-
diff --git a/drivers/net/wireless/wl1251/ps.h b/drivers/net/wireless/wl1251/ps.h
deleted file mode 100644 (file)
index 75efad2..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (c) 1998-2007 Texas Instruments Incorporated
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __WL1251_PS_H__
-#define __WL1251_PS_H__
-
-#include "wl1251.h"
-#include "acx.h"
-
-int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_station_mode mode);
-void wl1251_ps_elp_sleep(struct wl1251 *wl);
-int wl1251_ps_elp_wakeup(struct wl1251 *wl);
-void wl1251_elp_work(struct work_struct *work);
-
-
-#endif /* __WL1251_PS_H__ */
diff --git a/drivers/net/wireless/wl1251/reg.h b/drivers/net/wireless/wl1251/reg.h
deleted file mode 100644 (file)
index a580901..0000000
+++ /dev/null
@@ -1,655 +0,0 @@
-/*
- * This file is part of wl12xx
- *
- * Copyright (c) 1998-2007 Texas Instruments Incorporated
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __REG_H__
-#define __REG_H__
-
-#include <linux/bitops.h>
-
-#define REGISTERS_BASE 0x00300000
-#define DRPW_BASE      0x00310000
-
-#define REGISTERS_DOWN_SIZE 0x00008800
-#define REGISTERS_WORK_SIZE 0x0000b000
-
-#define HW_ACCESS_ELP_CTRL_REG_ADDR         0x1FFFC
-
-/* ELP register commands */
-#define ELPCTRL_WAKE_UP             0x1
-#define ELPCTRL_WAKE_UP_WLAN_READY  0x5
-#define ELPCTRL_SLEEP               0x0
-/* ELP WLAN_READY bit */
-#define ELPCTRL_WLAN_READY          0x2
-
-/* Device Configuration registers*/
-#define SOR_CFG                        (REGISTERS_BASE + 0x0800)
-#define ECPU_CTRL                      (REGISTERS_BASE + 0x0804)
-#define HI_CFG                         (REGISTERS_BASE + 0x0808)
-
-/* EEPROM registers */
-#define EE_START                       (REGISTERS_BASE + 0x080C)
-#define EE_CTL                         (REGISTERS_BASE + 0x2000)
-#define EE_DATA                        (REGISTERS_BASE + 0x2004)
-#define EE_ADDR                        (REGISTERS_BASE + 0x2008)
-
-#define EE_CTL_READ                   2
-
-#define CHIP_ID_B                      (REGISTERS_BASE + 0x5674)
-
-#define CHIP_ID_1251_PG10                 (0x7010101)
-#define CHIP_ID_1251_PG11                 (0x7020101)
-#define CHIP_ID_1251_PG12                 (0x7030101)
-
-#define ENABLE                         (REGISTERS_BASE + 0x5450)
-
-/* Power Management registers */
-#define ELP_CFG_MODE                   (REGISTERS_BASE + 0x5804)
-#define ELP_CMD                        (REGISTERS_BASE + 0x5808)
-#define PLL_CAL_TIME                   (REGISTERS_BASE + 0x5810)
-#define CLK_REQ_TIME                   (REGISTERS_BASE + 0x5814)
-#define CLK_BUF_TIME                   (REGISTERS_BASE + 0x5818)
-
-#define CFG_PLL_SYNC_CNT               (REGISTERS_BASE + 0x5820)
-
-/* Scratch Pad registers*/
-#define SCR_PAD0                       (REGISTERS_BASE + 0x5608)
-#define SCR_PAD1                       (REGISTERS_BASE + 0x560C)
-#define SCR_PAD2                       (REGISTERS_BASE + 0x5610)
-#define SCR_PAD3                       (REGISTERS_BASE + 0x5614)
-#define SCR_PAD4                       (REGISTERS_BASE + 0x5618)
-#define SCR_PAD4_SET                   (REGISTERS_BASE + 0x561C)
-#define SCR_PAD4_CLR                   (REGISTERS_BASE + 0x5620)
-#define SCR_PAD5                       (REGISTERS_BASE + 0x5624)
-#define SCR_PAD5_SET                   (REGISTERS_BASE + 0x5628)
-#define SCR_PAD5_CLR                   (REGISTERS_BASE + 0x562C)
-#define SCR_PAD6                       (REGISTERS_BASE + 0x5630)
-#define SCR_PAD7                       (REGISTERS_BASE + 0x5634)
-#define SCR_PAD8                       (REGISTERS_BASE + 0x5638)
-#define SCR_PAD9                       (REGISTERS_BASE + 0x563C)
-
-/* Spare registers*/
-#define SPARE_A1                       (REGISTERS_BASE + 0x0994)
-#define SPARE_A2                       (REGISTERS_BASE + 0x0998)
-#define SPARE_A3                       (REGISTERS_BASE + 0x099C)
-#define SPARE_A4                       (REGISTERS_BASE + 0x09A0)
-#define SPARE_A5                       (REGISTERS_BASE + 0x09A4)
-#define SPARE_A6                       (REGISTERS_BASE + 0x09A8)
-#define SPARE_A7                       (REGISTERS_BASE + 0x09AC)
-#define SPARE_A8                       (REGISTERS_BASE + 0x09B0)
-#define SPARE_B1                       (REGISTERS_BASE + 0x5420)
-#define SPARE_B2                       (REGISTERS_BASE + 0x5424)
-#define SPARE_B3                       (REGISTERS_BASE + 0x5428)
-#define SPARE_B4                       (REGISTERS_BASE + 0x542C)
-#define SPARE_B5                       (REGISTERS_BASE + 0x5430)
-#define SPARE_B6                       (REGISTERS_BASE + 0x5434)
-#define SPARE_B7                       (REGISTERS_BASE + 0x5438)
-#define SPARE_B8                       (REGISTERS_BASE + 0x543C)
-
-enum wl12xx_acx_int_reg {
-       ACX_REG_INTERRUPT_TRIG,
-       ACX_REG_INTERRUPT_TRIG_H,
-
-/*=============================================
-  Host Interrupt Mask Register - 32bit (RW)
-  ------------------------------------------
-  Setting a bit in this register masks the
-  corresponding interrupt to the host.
-  0 - RX0              - Rx first dubble buffer Data Interrupt
-  1 - TXD              - Tx Data Interrupt
-  2 - TXXFR            - Tx Transfer Interrupt
-  3 - RX1              - Rx second dubble buffer Data Interrupt
-  4 - RXXFR            - Rx Transfer Interrupt
-  5 - EVENT_A  - Event Mailbox interrupt
-  6 - EVENT_B  - Event Mailbox interrupt
-  7 - WNONHST  - Wake On Host Interrupt
-  8 - TRACE_A  - Debug Trace interrupt
-  9 - TRACE_B  - Debug Trace interrupt
- 10 - CDCMP            - Command Complete Interrupt
- 11 -
- 12 -
- 13 -
- 14 - ICOMP            - Initialization Complete Interrupt
- 16 - SG SE            - Soft Gemini - Sense enable interrupt
- 17 - SG SD            - Soft Gemini - Sense disable interrupt
- 18 -                  -
- 19 -                  -
- 20 -                  -
- 21-                   -
- Default: 0x0001
-*==============================================*/
-       ACX_REG_INTERRUPT_MASK,
-
-/*=============================================
-  Host Interrupt Mask Set 16bit, (Write only)
-  ------------------------------------------
- Setting a bit in this register sets
- the corresponding bin in ACX_HINT_MASK register
- without effecting the mask
- state of other bits (0 = no effect).
-==============================================*/
-       ACX_REG_HINT_MASK_SET,
-
-/*=============================================
-  Host Interrupt Mask Clear 16bit,(Write only)
-  ------------------------------------------
- Setting a bit in this register clears
- the corresponding bin in ACX_HINT_MASK register
- without effecting the mask
- state of other bits (0 = no effect).
-=============================================*/
-       ACX_REG_HINT_MASK_CLR,
-
-/*=============================================
-  Host Interrupt Status Nondestructive Read
-  16bit,(Read only)
-  ------------------------------------------
- The host can read this register to determine
- which interrupts are active.
- Reading this register doesn't
- effect its content.
-=============================================*/
-       ACX_REG_INTERRUPT_NO_CLEAR,
-
-/*=============================================
-  Host Interrupt Status Clear on Read  Register
-  16bit,(Read only)
-  ------------------------------------------
- The host can read this register to determine
- which interrupts are active.
- Reading this register clears it,
- thus making all interrupts inactive.
-==============================================*/
-       ACX_REG_INTERRUPT_CLEAR,
-
-/*=============================================
-  Host Interrupt Acknowledge Register
-  16bit,(Write only)
-  ------------------------------------------
- The host can set individual bits in this
- register to clear (acknowledge) the corresp.
- interrupt status bits in the HINT_STS_CLR and
- HINT_STS_ND registers, thus making the
- assotiated interrupt inactive. (0-no effect)
-==============================================*/
-       ACX_REG_INTERRUPT_ACK,
-
-/*===============================================
-   Host Software Reset - 32bit RW
- ------------------------------------------
-    [31:1] Reserved
-    0  SOFT_RESET Soft Reset  - When this bit is set,
-    it holds the Wlan hardware in a soft reset state.
-    This reset disables all MAC and baseband processor
-    clocks except the CardBus/PCI interface clock.
-    It also initializes all MAC state machines except
-    the host interface. It does not reload the
-    contents of the EEPROM. When this bit is cleared
-    (not self-clearing), the Wlan hardware
-    exits the software reset state.
-===============================================*/
-       ACX_REG_SLV_SOFT_RESET,
-
-/*===============================================
- EEPROM Burst Read Start  - 32bit RW
- ------------------------------------------
- [31:1] Reserved
- 0  ACX_EE_START -  EEPROM Burst Read Start 0
- Setting this bit starts a burst read from
- the external EEPROM.
- If this bit is set (after reset) before an EEPROM read/write,
- the burst read starts at EEPROM address 0.
- Otherwise, it starts at the address
- following the address of the previous access.
- TheWlan hardware hardware clears this bit automatically.
-
- Default: 0x00000000
-*================================================*/
-       ACX_REG_EE_START,
-
-/* Embedded ARM CPU Control */
-
-/*===============================================
- Halt eCPU   - 32bit RW
- ------------------------------------------
- 0 HALT_ECPU Halt Embedded CPU - This bit is the
- compliment of bit 1 (MDATA2) in the SOR_CFG register.
- During a hardware reset, this bit holds
- the inverse of MDATA2.
- When downloading firmware from the host,
- set this bit (pull down MDATA2).
- The host clears this bit after downloading the firmware into
- zero-wait-state SSRAM.
- When loading firmware from Flash, clear this bit (pull up MDATA2)
- so that the eCPU can run the bootloader code in Flash
- HALT_ECPU eCPU State
- --------------------
- 1 halt eCPU
- 0 enable eCPU
- ===============================================*/
-       ACX_REG_ECPU_CONTROL,
-
-       ACX_REG_TABLE_LEN
-};
-
-#define ACX_SLV_SOFT_RESET_BIT   BIT(0)
-#define ACX_REG_EEPROM_START_BIT BIT(0)
-
-/* Command/Information Mailbox Pointers */
-
-/*===============================================
-  Command Mailbox Pointer - 32bit RW
- ------------------------------------------
- This register holds the start address of
- the command mailbox located in the Wlan hardware memory.
- The host must read this pointer after a reset to
- find the location of the command mailbox.
- The Wlan hardware initializes the command mailbox
- pointer with the default address of the command mailbox.
- The command mailbox pointer is not valid until after
- the host receives the Init Complete interrupt from
- the Wlan hardware.
- ===============================================*/
-#define REG_COMMAND_MAILBOX_PTR                                (SCR_PAD0)
-
-/*===============================================
-  Information Mailbox Pointer - 32bit RW
- ------------------------------------------
- This register holds the start address of
- the information mailbox located in the Wlan hardware memory.
- The host must read this pointer after a reset to find
- the location of the information mailbox.
- The Wlan hardware initializes the information mailbox pointer
- with the default address of the information mailbox.
- The information mailbox pointer is not valid
- until after the host receives the Init Complete interrupt from
- the Wlan hardware.
- ===============================================*/
-#define REG_EVENT_MAILBOX_PTR                          (SCR_PAD1)
-
-
-/* Misc */
-
-#define REG_ENABLE_TX_RX                               (ENABLE)
-/*
- * Rx configuration (filter) information element
- * ---------------------------------------------
- */
-#define REG_RX_CONFIG                          (RX_CFG)
-#define REG_RX_FILTER                          (RX_FILTER_CFG)
-
-
-#define RX_CFG_ENABLE_PHY_HEADER_PLCP   0x0002
-
-/* promiscuous - receives all valid frames */
-#define RX_CFG_PROMISCUOUS              0x0008
-
-/* receives frames from any BSSID */
-#define RX_CFG_BSSID                    0x0020
-
-/* receives frames destined to any MAC address */
-#define RX_CFG_MAC                      0x0010
-
-#define RX_CFG_ENABLE_ONLY_MY_DEST_MAC  0x0010
-#define RX_CFG_ENABLE_ANY_DEST_MAC      0x0000
-#define RX_CFG_ENABLE_ONLY_MY_BSSID     0x0020
-#define RX_CFG_ENABLE_ANY_BSSID                 0x0000
-
-/* discards all broadcast frames */
-#define RX_CFG_DISABLE_BCAST            0x0200
-
-#define RX_CFG_ENABLE_ONLY_MY_SSID      0x0400
-#define RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR 0x0800
-#define RX_CFG_COPY_RX_STATUS           0x2000
-#define RX_CFG_TSF                      0x10000
-
-#define RX_CONFIG_OPTION_ANY_DST_MY_BSS         (RX_CFG_ENABLE_ANY_DEST_MAC | \
-                                         RX_CFG_ENABLE_ONLY_MY_BSSID)
-
-#define RX_CONFIG_OPTION_MY_DST_ANY_BSS         (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\
-                                         | RX_CFG_ENABLE_ANY_BSSID)
-
-#define RX_CONFIG_OPTION_ANY_DST_ANY_BSS (RX_CFG_ENABLE_ANY_DEST_MAC | \
-                                         RX_CFG_ENABLE_ANY_BSSID)
-
-#define RX_CONFIG_OPTION_MY_DST_MY_BSS  (RX_CFG_ENABLE_ONLY_MY_DEST_MAC\
-                                         | RX_CFG_ENABLE_ONLY_MY_BSSID)
-
-#define RX_CONFIG_OPTION_FOR_SCAN  (RX_CFG_ENABLE_PHY_HEADER_PLCP \
-                                   | RX_CFG_ENABLE_RX_CMPLT_FCS_ERROR \
-                                   | RX_CFG_COPY_RX_STATUS | RX_CFG_TSF)
-
-#define RX_CONFIG_OPTION_FOR_MEASUREMENT (RX_CFG_ENABLE_ANY_DEST_MAC)
-
-#define RX_CONFIG_OPTION_FOR_JOIN       (RX_CFG_ENABLE_ONLY_MY_BSSID | \
-                                         RX_CFG_ENABLE_ONLY_MY_DEST_MAC)
-
-#define RX_CONFIG_OPTION_FOR_IBSS_JOIN   (RX_CFG_ENABLE_ONLY_MY_SSID | \
-                                         RX_CFG_ENABLE_ONLY_MY_DEST_MAC)
-
-#define RX_FILTER_OPTION_DEF         (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\
-                                      | CFG_RX_CTL_EN | CFG_RX_BCN_EN\
-                                      | CFG_RX_AUTH_EN | CFG_RX_ASSOC_EN)
-
-#define RX_FILTER_OPTION_FILTER_ALL     0
-
-#define RX_FILTER_OPTION_DEF_PRSP_BCN  (CFG_RX_PRSP_EN | CFG_RX_MGMT_EN\
-                                       | CFG_RX_RCTS_ACK | CFG_RX_BCN_EN)
-
-#define RX_FILTER_OPTION_JOIN       (CFG_RX_MGMT_EN | CFG_RX_DATA_EN\
-                                     | CFG_RX_BCN_EN | CFG_RX_AUTH_EN\
-                                     | CFG_RX_ASSOC_EN | CFG_RX_RCTS_ACK\
-                                     | CFG_RX_PRSP_EN)
-
-
-/*===============================================
- EEPROM Read/Write Request 32bit RW
- ------------------------------------------
- 1 EE_READ - EEPROM Read Request 1 - Setting this bit
- loads a single byte of data into the EE_DATA
- register from the EEPROM location specified in
- the EE_ADDR register.
- The Wlan hardware hardware clears this bit automatically.
- EE_DATA is valid when this bit is cleared.
-
- 0 EE_WRITE  - EEPROM Write Request  - Setting this bit
- writes a single byte of data from the EE_DATA register into the
- EEPROM location specified in the EE_ADDR register.
- The Wlan hardware hardware clears this bit automatically.
-*===============================================*/
-#define EE_CTL                              (REGISTERS_BASE + 0x2000)
-#define ACX_EE_CTL_REG                      EE_CTL
-#define EE_WRITE                            0x00000001ul
-#define EE_READ                             0x00000002ul
-
-/*===============================================
-  EEPROM Address  - 32bit RW
-  ------------------------------------------
-  This register specifies the address
-  within the EEPROM from/to which to read/write data.
-  ===============================================*/
-#define EE_ADDR                             (REGISTERS_BASE + 0x2008)
-#define ACX_EE_ADDR_REG                     EE_ADDR
-
-/*===============================================
-  EEPROM Data  - 32bit RW
-  ------------------------------------------
-  This register either holds the read 8 bits of
-  data from the EEPROM or the write data
-  to be written to the EEPROM.
-  ===============================================*/
-#define EE_DATA                             (REGISTERS_BASE + 0x2004)
-#define ACX_EE_DATA_REG                     EE_DATA
-
-#define EEPROM_ACCESS_TO                    10000   /* timeout counter */
-#define START_EEPROM_MGR                    0x00000001
-
-/*===============================================
-  EEPROM Base Address  - 32bit RW
-  ------------------------------------------
-  This register holds the upper nine bits
-  [23:15] of the 24-bit Wlan hardware memory
-  address for burst reads from EEPROM accesses.
-  The EEPROM provides the lower 15 bits of this address.
-  The MSB of the address from the EEPROM is ignored.
-  ===============================================*/
-#define ACX_EE_CFG                          EE_CFG
-
-/*===============================================
-  GPIO Output Values  -32bit, RW
-  ------------------------------------------
-  [31:16]  Reserved
-  [15: 0]  Specify the output values (at the output driver inputs) for
-  GPIO[15:0], respectively.
-  ===============================================*/
-#define ACX_GPIO_OUT_REG            GPIO_OUT
-#define ACX_MAX_GPIO_LINES          15
-
-/*===============================================
-  Contention window  -32bit, RW
-  ------------------------------------------
-  [31:26]  Reserved
-  [25:16]  Max (0x3ff)
-  [15:07]  Reserved
-  [06:00]  Current contention window value - default is 0x1F
-  ===============================================*/
-#define ACX_CONT_WIND_CFG_REG    CONT_WIND_CFG
-#define ACX_CONT_WIND_MIN_MASK   0x0000007f
-#define ACX_CONT_WIND_MAX        0x03ff0000
-
-/*===============================================
-  HI_CFG Interface Configuration Register Values
-  ------------------------------------------
-  ===============================================*/
-#define HI_CFG_UART_ENABLE          0x00000004
-#define HI_CFG_RST232_ENABLE        0x00000008
-#define HI_CFG_CLOCK_REQ_SELECT     0x00000010
-#define HI_CFG_HOST_INT_ENABLE      0x00000020
-#define HI_CFG_VLYNQ_OUTPUT_ENABLE  0x00000040
-#define HI_CFG_HOST_INT_ACTIVE_LOW  0x00000080
-#define HI_CFG_UART_TX_OUT_GPIO_15  0x00000100
-#define HI_CFG_UART_TX_OUT_GPIO_14  0x00000200
-#define HI_CFG_UART_TX_OUT_GPIO_7   0x00000400
-
-/*
- * NOTE: USE_ACTIVE_HIGH compilation flag should be defined in makefile
- *       for platforms using active high interrupt level
- */
-#ifdef USE_ACTIVE_HIGH
-#define HI_CFG_DEF_VAL              \
-       (HI_CFG_UART_ENABLE |        \
-       HI_CFG_RST232_ENABLE |      \
-       HI_CFG_CLOCK_REQ_SELECT |   \
-       HI_CFG_HOST_INT_ENABLE)
-#else
-#define HI_CFG_DEF_VAL              \
-       (HI_CFG_UART_ENABLE |        \
-       HI_CFG_RST232_ENABLE |      \
-       HI_CFG_CLOCK_REQ_SELECT |   \
-       HI_CFG_HOST_INT_ENABLE)
-
-#endif
-
-#define REF_FREQ_19_2                       0
-#define REF_FREQ_26_0                       1
-#define REF_FREQ_38_4                       2
-#define REF_FREQ_40_0                       3
-#define REF_FREQ_33_6                       4
-#define REF_FREQ_NUM                        5
-
-#define LUT_PARAM_INTEGER_DIVIDER           0
-#define LUT_PARAM_FRACTIONAL_DIVIDER        1
-#define LUT_PARAM_ATTN_BB                   2
-#define LUT_PARAM_ALPHA_BB                  3
-#define LUT_PARAM_STOP_TIME_BB              4
-#define LUT_PARAM_BB_PLL_LOOP_FILTER        5
-#define LUT_PARAM_NUM                       6
-
-#define ACX_EEPROMLESS_IND_REG              (SCR_PAD4)
-#define USE_EEPROM                          0
-#define SOFT_RESET_MAX_TIME                 1000000
-#define SOFT_RESET_STALL_TIME               1000
-#define NVS_DATA_BUNDARY_ALIGNMENT          4
-
-
-/* Firmware image load chunk size */
-#define CHUNK_SIZE          512
-
-/* Firmware image header size */
-#define FW_HDR_SIZE 8
-
-#define ECPU_CONTROL_HALT                                      0x00000101
-
-
-/******************************************************************************
-
-    CHANNELS, BAND & REG DOMAINS definitions
-
-******************************************************************************/
-
-
-enum {
-       RADIO_BAND_2_4GHZ = 0,  /* 2.4 Ghz band */
-       RADIO_BAND_5GHZ = 1,    /* 5 Ghz band */
-       RADIO_BAND_JAPAN_4_9_GHZ = 2,
-       DEFAULT_BAND = RADIO_BAND_2_4GHZ,
-       INVALID_BAND = 0xFE,
-       MAX_RADIO_BANDS = 0xFF
-};
-
-enum {
-       NO_RATE      = 0,
-       RATE_1MBPS   = 0x0A,
-       RATE_2MBPS   = 0x14,
-       RATE_5_5MBPS = 0x37,
-       RATE_6MBPS   = 0x0B,
-       RATE_9MBPS   = 0x0F,
-       RATE_11MBPS  = 0x6E,
-       RATE_12MBPS  = 0x0A,
-       RATE_18MBPS  = 0x0E,
-       RATE_22MBPS  = 0xDC,
-       RATE_24MBPS  = 0x09,
-       RATE_36MBPS  = 0x0D,
-       RATE_48MBPS  = 0x08,
-       RATE_54MBPS  = 0x0C
-};
-
-enum {
-       RATE_INDEX_1MBPS   =  0,
-       RATE_INDEX_2MBPS   =  1,
-       RATE_INDEX_5_5MBPS =  2,
-       RATE_INDEX_6MBPS   =  3,
-       RATE_INDEX_9MBPS   =  4,
-       RATE_INDEX_11MBPS  =  5,
-       RATE_INDEX_12MBPS  =  6,
-       RATE_INDEX_18MBPS  =  7,
-       RATE_INDEX_22MBPS  =  8,
-       RATE_INDEX_24MBPS  =  9,
-       RATE_INDEX_36MBPS  =  10,
-       RATE_INDEX_48MBPS  =  11,
-       RATE_INDEX_54MBPS  =  12,
-       RATE_INDEX_MAX     =  RATE_INDEX_54MBPS,
-       MAX_RATE_INDEX,
-       INVALID_RATE_INDEX = MAX_RATE_INDEX,
-       RATE_INDEX_ENUM_MAX_SIZE = 0x7FFFFFFF
-};
-
-enum {
-       RATE_MASK_1MBPS = 0x1,
-       RATE_MASK_2MBPS = 0x2,
-       RATE_MASK_5_5MBPS = 0x4,
-       RATE_MASK_11MBPS = 0x20,
-};
-
-#define SHORT_PREAMBLE_BIT   BIT(0) /* CCK or Barker depending on the rate */
-#define OFDM_RATE_BIT        BIT(6)
-#define PBCC_RATE_BIT        BIT(7)
-
-enum {
-       CCK_LONG = 0,
-       CCK_SHORT = SHORT_PREAMBLE_BIT,
-       PBCC_LONG = PBCC_RATE_BIT,
-       PBCC_SHORT = PBCC_RATE_BIT | SHORT_PREAMBLE_BIT,
-       OFDM = OFDM_RATE_BIT
-};
-
-/******************************************************************************
-
-Transmit-Descriptor RATE-SET field definitions...
-
-Define a new "Rate-Set" for TX path that incorporates the
-Rate & Modulation info into a single 16-bit field.
-
-TxdRateSet_t:
-b15   - Indicates Preamble type (1=SHORT, 0=LONG).
-       Notes:
-       Must be LONG (0) for 1Mbps rate.
-       Does not apply (set to 0) for RevG-OFDM rates.
-b14   - Indicates PBCC encoding (1=PBCC, 0=not).
-       Notes:
-       Does not apply (set to 0) for rates 1 and 2 Mbps.
-       Does not apply (set to 0) for RevG-OFDM rates.
-b13    - Unused (set to 0).
-b12-b0 - Supported Rate indicator bits as defined below.
-
-******************************************************************************/
-
-
-/*************************************************************************
-
-    Interrupt Trigger Register (Host -> WiLink)
-
-**************************************************************************/
-
-/* Hardware to Embedded CPU Interrupts - first 32-bit register set */
-
-/*
- * Host Command Interrupt. Setting this bit masks
- * the interrupt that the host issues to inform
- * the FW that it has sent a command
- * to the Wlan hardware Command Mailbox.
- */
-#define INTR_TRIG_CMD       BIT(0)
-
-/*
- * Host Event Acknowlegde Interrupt. The host
- * sets this bit to acknowledge that it received
- * the unsolicited information from the event
- * mailbox.
- */
-#define INTR_TRIG_EVENT_ACK BIT(1)
-
-/*
- * The host sets this bit to inform the Wlan
- * FW that a TX packet is in the XFER
- * Buffer #0.
- */
-#define INTR_TRIG_TX_PROC0 BIT(2)
-
-/*
- * The host sets this bit to inform the FW
- * that it read a packet from RX XFER
- * Buffer #0.
- */
-#define INTR_TRIG_RX_PROC0 BIT(3)
-
-#define INTR_TRIG_DEBUG_ACK BIT(4)
-
-#define INTR_TRIG_STATE_CHANGED BIT(5)
-
-
-/* Hardware to Embedded CPU Interrupts - second 32-bit register set */
-
-/*
- * The host sets this bit to inform the FW
- * that it read a packet from RX XFER
- * Buffer #1.
- */
-#define INTR_TRIG_RX_PROC1 BIT(17)
-
-/*
- * The host sets this bit to inform the Wlan
- * hardware that a TX packet is in the XFER
- * Buffer #1.
- */
-#define INTR_TRIG_TX_PROC1 BIT(18)
-
-#endif
diff --git a/drivers/net/wireless/wl1251/rx.c b/drivers/net/wireless/wl1251/rx.c
deleted file mode 100644 (file)
index 6af3526..0000000
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (c) 1998-2007 Texas Instruments Incorporated
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/skbuff.h>
-#include <linux/gfp.h>
-#include <net/mac80211.h>
-
-#include "wl1251.h"
-#include "reg.h"
-#include "io.h"
-#include "rx.h"
-#include "cmd.h"
-#include "acx.h"
-
-static void wl1251_rx_header(struct wl1251 *wl,
-                            struct wl1251_rx_descriptor *desc)
-{
-       u32 rx_packet_ring_addr;
-
-       rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr;
-       if (wl->rx_current_buffer)
-               rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
-
-       wl1251_mem_read(wl, rx_packet_ring_addr, desc, sizeof(*desc));
-}
-
-static void wl1251_rx_status(struct wl1251 *wl,
-                            struct wl1251_rx_descriptor *desc,
-                            struct ieee80211_rx_status *status,
-                            u8 beacon)
-{
-       u64 mactime;
-       int ret;
-
-       memset(status, 0, sizeof(struct ieee80211_rx_status));
-
-       status->band = IEEE80211_BAND_2GHZ;
-       status->mactime = desc->timestamp;
-
-       /*
-        * The rx status timestamp is a 32 bits value while the TSF is a
-        * 64 bits one.
-        * For IBSS merging, TSF is mandatory, so we have to get it
-        * somehow, so we ask for ACX_TSF_INFO.
-        * That could be moved to the get_tsf() hook, but unfortunately,
-        * this one must be atomic, while our SPI routines can sleep.
-        */
-       if ((wl->bss_type == BSS_TYPE_IBSS) && beacon) {
-               ret = wl1251_acx_tsf_info(wl, &mactime);
-               if (ret == 0)
-                       status->mactime = mactime;
-       }
-
-       status->signal = desc->rssi;
-
-       /*
-        * FIXME: guessing that snr needs to be divided by two, otherwise
-        * the values don't make any sense
-        */
-       wl->noise = desc->rssi - desc->snr / 2;
-
-       status->freq = ieee80211_channel_to_frequency(desc->channel,
-                                                     status->band);
-
-       status->flag |= RX_FLAG_MACTIME_MPDU;
-
-       if (desc->flags & RX_DESC_ENCRYPTION_MASK) {
-               status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED;
-
-               if (likely(!(desc->flags & RX_DESC_DECRYPT_FAIL)))
-                       status->flag |= RX_FLAG_DECRYPTED;
-
-               if (unlikely(desc->flags & RX_DESC_MIC_FAIL))
-                       status->flag |= RX_FLAG_MMIC_ERROR;
-       }
-
-       if (unlikely(!(desc->flags & RX_DESC_VALID_FCS)))
-               status->flag |= RX_FLAG_FAILED_FCS_CRC;
-
-       switch (desc->rate) {
-               /* skip 1 and 12 Mbps because they have same value 0x0a */
-       case RATE_2MBPS:
-               status->rate_idx = 1;
-               break;
-       case RATE_5_5MBPS:
-               status->rate_idx = 2;
-               break;
-       case RATE_11MBPS:
-               status->rate_idx = 3;
-               break;
-       case RATE_6MBPS:
-               status->rate_idx = 4;
-               break;
-       case RATE_9MBPS:
-               status->rate_idx = 5;
-               break;
-       case RATE_18MBPS:
-               status->rate_idx = 7;
-               break;
-       case RATE_24MBPS:
-               status->rate_idx = 8;
-               break;
-       case RATE_36MBPS:
-               status->rate_idx = 9;
-               break;
-       case RATE_48MBPS:
-               status->rate_idx = 10;
-               break;
-       case RATE_54MBPS:
-               status->rate_idx = 11;
-               break;
-       }
-
-       /* for 1 and 12 Mbps we have to check the modulation */
-       if (desc->rate == RATE_1MBPS) {
-               if (!(desc->mod_pre & OFDM_RATE_BIT))
-                       /* CCK -> RATE_1MBPS */
-                       status->rate_idx = 0;
-               else
-                       /* OFDM -> RATE_12MBPS */
-                       status->rate_idx = 6;
-       }
-
-       if (desc->mod_pre & SHORT_PREAMBLE_BIT)
-               status->flag |= RX_FLAG_SHORTPRE;
-}
-
-static void wl1251_rx_body(struct wl1251 *wl,
-                          struct wl1251_rx_descriptor *desc)
-{
-       struct sk_buff *skb;
-       struct ieee80211_rx_status status;
-       u8 *rx_buffer, beacon = 0;
-       u16 length, *fc;
-       u32 curr_id, last_id_inc, rx_packet_ring_addr;
-
-       length = WL1251_RX_ALIGN(desc->length  - PLCP_HEADER_LENGTH);
-       curr_id = (desc->flags & RX_DESC_SEQNUM_MASK) >> RX_DESC_PACKETID_SHIFT;
-       last_id_inc = (wl->rx_last_id + 1) % (RX_MAX_PACKET_ID + 1);
-
-       if (last_id_inc != curr_id) {
-               wl1251_warning("curr ID:%d, last ID inc:%d",
-                              curr_id, last_id_inc);
-               wl->rx_last_id = curr_id;
-       } else {
-               wl->rx_last_id = last_id_inc;
-       }
-
-       rx_packet_ring_addr = wl->data_path->rx_packet_ring_addr +
-               sizeof(struct wl1251_rx_descriptor) + 20;
-       if (wl->rx_current_buffer)
-               rx_packet_ring_addr += wl->data_path->rx_packet_ring_chunk_size;
-
-       skb = __dev_alloc_skb(length, GFP_KERNEL);
-       if (!skb) {
-               wl1251_error("Couldn't allocate RX frame");
-               return;
-       }
-
-       rx_buffer = skb_put(skb, length);
-       wl1251_mem_read(wl, rx_packet_ring_addr, rx_buffer, length);
-
-       /* The actual length doesn't include the target's alignment */
-       skb->len = desc->length  - PLCP_HEADER_LENGTH;
-
-       fc = (u16 *)skb->data;
-
-       if ((*fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_BEACON)
-               beacon = 1;
-
-       wl1251_rx_status(wl, desc, &status, beacon);
-
-       wl1251_debug(DEBUG_RX, "rx skb 0x%p: %d B %s", skb, skb->len,
-                    beacon ? "beacon" : "");
-
-       memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
-       ieee80211_rx_ni(wl->hw, skb);
-}
-
-static void wl1251_rx_ack(struct wl1251 *wl)
-{
-       u32 data, addr;
-
-       if (wl->rx_current_buffer) {
-               addr = ACX_REG_INTERRUPT_TRIG_H;
-               data = INTR_TRIG_RX_PROC1;
-       } else {
-               addr = ACX_REG_INTERRUPT_TRIG;
-               data = INTR_TRIG_RX_PROC0;
-       }
-
-       wl1251_reg_write32(wl, addr, data);
-
-       /* Toggle buffer ring */
-       wl->rx_current_buffer = !wl->rx_current_buffer;
-}
-
-
-void wl1251_rx(struct wl1251 *wl)
-{
-       struct wl1251_rx_descriptor *rx_desc;
-
-       if (wl->state != WL1251_STATE_ON)
-               return;
-
-       rx_desc = wl->rx_descriptor;
-
-       /* We first read the frame's header */
-       wl1251_rx_header(wl, rx_desc);
-
-       /* Now we can read the body */
-       wl1251_rx_body(wl, rx_desc);
-
-       /* Finally, we need to ACK the RX */
-       wl1251_rx_ack(wl);
-}
diff --git a/drivers/net/wireless/wl1251/rx.h b/drivers/net/wireless/wl1251/rx.h
deleted file mode 100644 (file)
index 4448f63..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (c) 1998-2007 Texas Instruments Incorporated
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __WL1251_RX_H__
-#define __WL1251_RX_H__
-
-#include <linux/bitops.h>
-
-#include "wl1251.h"
-
-/*
- * RX PATH
- *
- * The Rx path uses a double buffer and an rx_contro structure, each located
- * at a fixed address in the device memory. The host keeps track of which
- * buffer is available and alternates between them on a per packet basis.
- * The size of each of the two buffers is large enough to hold the longest
- * 802.3 packet.
- * The RX path goes like that:
- * 1) The target generates an interrupt each time a new packet is received.
- *   There are 2 RX interrupts, one for each buffer.
- * 2) The host reads the received packet from one of the double buffers.
- * 3) The host triggers a target interrupt.
- * 4) The target prepares the next RX packet.
- */
-
-#define WL1251_RX_MAX_RSSI -30
-#define WL1251_RX_MIN_RSSI -95
-
-#define WL1251_RX_ALIGN_TO 4
-#define WL1251_RX_ALIGN(len) (((len) + WL1251_RX_ALIGN_TO - 1) & \
-                            ~(WL1251_RX_ALIGN_TO - 1))
-
-#define SHORT_PREAMBLE_BIT   BIT(0)
-#define OFDM_RATE_BIT        BIT(6)
-#define PBCC_RATE_BIT        BIT(7)
-
-#define PLCP_HEADER_LENGTH 8
-#define RX_DESC_PACKETID_SHIFT 11
-#define RX_MAX_PACKET_ID 3
-
-#define RX_DESC_VALID_FCS         0x0001
-#define RX_DESC_MATCH_RXADDR1     0x0002
-#define RX_DESC_MCAST             0x0004
-#define RX_DESC_STAINTIM          0x0008
-#define RX_DESC_VIRTUAL_BM        0x0010
-#define RX_DESC_BCAST             0x0020
-#define RX_DESC_MATCH_SSID        0x0040
-#define RX_DESC_MATCH_BSSID       0x0080
-#define RX_DESC_ENCRYPTION_MASK   0x0300
-#define RX_DESC_MEASURMENT        0x0400
-#define RX_DESC_SEQNUM_MASK       0x1800
-#define        RX_DESC_MIC_FAIL          0x2000
-#define        RX_DESC_DECRYPT_FAIL      0x4000
-
-struct wl1251_rx_descriptor {
-       u32 timestamp; /* In microseconds */
-       u16 length; /* Paylod length, including headers */
-       u16 flags;
-
-       /*
-        * 0 - 802.11
-        * 1 - 802.3
-        * 2 - IP
-        * 3 - Raw Codec
-        */
-       u8 type;
-
-       /*
-        * Received Rate:
-        * 0x0A - 1MBPS
-        * 0x14 - 2MBPS
-        * 0x37 - 5_5MBPS
-        * 0x0B - 6MBPS
-        * 0x0F - 9MBPS
-        * 0x6E - 11MBPS
-        * 0x0A - 12MBPS
-        * 0x0E - 18MBPS
-        * 0xDC - 22MBPS
-        * 0x09 - 24MBPS
-        * 0x0D - 36MBPS
-        * 0x08 - 48MBPS
-        * 0x0C - 54MBPS
-        */
-       u8 rate;
-
-       u8 mod_pre; /* Modulation and preamble */
-       u8 channel;
-
-       /*
-        * 0 - 2.4 Ghz
-        * 1 - 5 Ghz
-        */
-       u8 band;
-
-       s8 rssi; /* in dB */
-       u8 rcpi; /* in dB */
-       u8 snr; /* in dB */
-} __packed;
-
-void wl1251_rx(struct wl1251 *wl);
-
-#endif
diff --git a/drivers/net/wireless/wl1251/sdio.c b/drivers/net/wireless/wl1251/sdio.c
deleted file mode 100644 (file)
index f786942..0000000
+++ /dev/null
@@ -1,374 +0,0 @@
-/*
- * wl12xx SDIO routines
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- * Copyright (C) 2005 Texas Instruments Incorporated
- * Copyright (C) 2008 Google Inc
- * Copyright (C) 2009 Bob Copeland (me@bobcopeland.com)
- */
-#include <linux/interrupt.h>
-#include <linux/module.h>
-#include <linux/mod_devicetable.h>
-#include <linux/mmc/sdio_func.h>
-#include <linux/mmc/sdio_ids.h>
-#include <linux/platform_device.h>
-#include <linux/wl12xx.h>
-#include <linux/irq.h>
-#include <linux/pm_runtime.h>
-
-#include "wl1251.h"
-
-#ifndef SDIO_VENDOR_ID_TI
-#define SDIO_VENDOR_ID_TI              0x104c
-#endif
-
-#ifndef SDIO_DEVICE_ID_TI_WL1251
-#define SDIO_DEVICE_ID_TI_WL1251       0x9066
-#endif
-
-struct wl1251_sdio {
-       struct sdio_func *func;
-       u32 elp_val;
-};
-
-static struct sdio_func *wl_to_func(struct wl1251 *wl)
-{
-       struct wl1251_sdio *wl_sdio = wl->if_priv;
-       return wl_sdio->func;
-}
-
-static void wl1251_sdio_interrupt(struct sdio_func *func)
-{
-       struct wl1251 *wl = sdio_get_drvdata(func);
-
-       wl1251_debug(DEBUG_IRQ, "IRQ");
-
-       /* FIXME should be synchronous for sdio */
-       ieee80211_queue_work(wl->hw, &wl->irq_work);
-}
-
-static const struct sdio_device_id wl1251_devices[] = {
-       { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1251) },
-       {}
-};
-MODULE_DEVICE_TABLE(sdio, wl1251_devices);
-
-
-static void wl1251_sdio_read(struct wl1251 *wl, int addr,
-                            void *buf, size_t len)
-{
-       int ret;
-       struct sdio_func *func = wl_to_func(wl);
-
-       sdio_claim_host(func);
-       ret = sdio_memcpy_fromio(func, buf, addr, len);
-       if (ret)
-               wl1251_error("sdio read failed (%d)", ret);
-       sdio_release_host(func);
-}
-
-static void wl1251_sdio_write(struct wl1251 *wl, int addr,
-                             void *buf, size_t len)
-{
-       int ret;
-       struct sdio_func *func = wl_to_func(wl);
-
-       sdio_claim_host(func);
-       ret = sdio_memcpy_toio(func, addr, buf, len);
-       if (ret)
-               wl1251_error("sdio write failed (%d)", ret);
-       sdio_release_host(func);
-}
-
-static void wl1251_sdio_read_elp(struct wl1251 *wl, int addr, u32 *val)
-{
-       int ret = 0;
-       struct wl1251_sdio *wl_sdio = wl->if_priv;
-       struct sdio_func *func = wl_sdio->func;
-
-       /*
-        * The hardware only supports RAW (read after write) access for
-        * reading, regular sdio_readb won't work here (it interprets
-        * the unused bits of CMD52 as write data even if we send read
-        * request).
-        */
-       sdio_claim_host(func);
-       *val = sdio_writeb_readb(func, wl_sdio->elp_val, addr, &ret);
-       sdio_release_host(func);
-
-       if (ret)
-               wl1251_error("sdio_readb failed (%d)", ret);
-}
-
-static void wl1251_sdio_write_elp(struct wl1251 *wl, int addr, u32 val)
-{
-       int ret = 0;
-       struct wl1251_sdio *wl_sdio = wl->if_priv;
-       struct sdio_func *func = wl_sdio->func;
-
-       sdio_claim_host(func);
-       sdio_writeb(func, val, addr, &ret);
-       sdio_release_host(func);
-
-       if (ret)
-               wl1251_error("sdio_writeb failed (%d)", ret);
-       else
-               wl_sdio->elp_val = val;
-}
-
-static void wl1251_sdio_reset(struct wl1251 *wl)
-{
-}
-
-static void wl1251_sdio_enable_irq(struct wl1251 *wl)
-{
-       struct sdio_func *func = wl_to_func(wl);
-
-       sdio_claim_host(func);
-       sdio_claim_irq(func, wl1251_sdio_interrupt);
-       sdio_release_host(func);
-}
-
-static void wl1251_sdio_disable_irq(struct wl1251 *wl)
-{
-       struct sdio_func *func = wl_to_func(wl);
-
-       sdio_claim_host(func);
-       sdio_release_irq(func);
-       sdio_release_host(func);
-}
-
-/* Interrupts when using dedicated WLAN_IRQ pin */
-static irqreturn_t wl1251_line_irq(int irq, void *cookie)
-{
-       struct wl1251 *wl = cookie;
-
-       ieee80211_queue_work(wl->hw, &wl->irq_work);
-
-       return IRQ_HANDLED;
-}
-
-static void wl1251_enable_line_irq(struct wl1251 *wl)
-{
-       return enable_irq(wl->irq);
-}
-
-static void wl1251_disable_line_irq(struct wl1251 *wl)
-{
-       return disable_irq(wl->irq);
-}
-
-static int wl1251_sdio_set_power(struct wl1251 *wl, bool enable)
-{
-       struct sdio_func *func = wl_to_func(wl);
-       int ret;
-
-       if (enable) {
-               /*
-                * Power is controlled by runtime PM, but we still call board
-                * callback in case it wants to do any additional setup,
-                * for example enabling clock buffer for the module.
-                */
-               if (wl->set_power)
-                       wl->set_power(true);
-
-               ret = pm_runtime_get_sync(&func->dev);
-               if (ret < 0)
-                       goto out;
-
-               sdio_claim_host(func);
-               sdio_enable_func(func);
-               sdio_release_host(func);
-       } else {
-               sdio_claim_host(func);
-               sdio_disable_func(func);
-               sdio_release_host(func);
-
-               ret = pm_runtime_put_sync(&func->dev);
-               if (ret < 0)
-                       goto out;
-
-               if (wl->set_power)
-                       wl->set_power(false);
-       }
-
-out:
-       return ret;
-}
-
-static struct wl1251_if_operations wl1251_sdio_ops = {
-       .read = wl1251_sdio_read,
-       .write = wl1251_sdio_write,
-       .write_elp = wl1251_sdio_write_elp,
-       .read_elp = wl1251_sdio_read_elp,
-       .reset = wl1251_sdio_reset,
-       .power = wl1251_sdio_set_power,
-};
-
-static int wl1251_sdio_probe(struct sdio_func *func,
-                            const struct sdio_device_id *id)
-{
-       int ret;
-       struct wl1251 *wl;
-       struct ieee80211_hw *hw;
-       struct wl1251_sdio *wl_sdio;
-       const struct wl12xx_platform_data *wl12xx_board_data;
-
-       hw = wl1251_alloc_hw();
-       if (IS_ERR(hw))
-               return PTR_ERR(hw);
-
-       wl = hw->priv;
-
-       wl_sdio = kzalloc(sizeof(*wl_sdio), GFP_KERNEL);
-       if (wl_sdio == NULL) {
-               ret = -ENOMEM;
-               goto out_free_hw;
-       }
-
-       sdio_claim_host(func);
-       ret = sdio_enable_func(func);
-       if (ret)
-               goto release;
-
-       sdio_set_block_size(func, 512);
-       sdio_release_host(func);
-
-       SET_IEEE80211_DEV(hw, &func->dev);
-       wl_sdio->func = func;
-       wl->if_priv = wl_sdio;
-       wl->if_ops = &wl1251_sdio_ops;
-
-       wl12xx_board_data = wl12xx_get_platform_data();
-       if (!IS_ERR(wl12xx_board_data)) {
-               wl->set_power = wl12xx_board_data->set_power;
-               wl->irq = wl12xx_board_data->irq;
-               wl->use_eeprom = wl12xx_board_data->use_eeprom;
-       }
-
-       if (wl->irq) {
-               ret = request_irq(wl->irq, wl1251_line_irq, 0, "wl1251", wl);
-               if (ret < 0) {
-                       wl1251_error("request_irq() failed: %d", ret);
-                       goto disable;
-               }
-
-               irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
-               disable_irq(wl->irq);
-
-               wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
-               wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
-
-               wl1251_info("using dedicated interrupt line");
-       } else {
-               wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
-               wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
-
-               wl1251_info("using SDIO interrupt");
-       }
-
-       ret = wl1251_init_ieee80211(wl);
-       if (ret)
-               goto out_free_irq;
-
-       sdio_set_drvdata(func, wl);
-
-       /* Tell PM core that we don't need the card to be powered now */
-       pm_runtime_put_noidle(&func->dev);
-
-       return ret;
-
-out_free_irq:
-       if (wl->irq)
-               free_irq(wl->irq, wl);
-disable:
-       sdio_claim_host(func);
-       sdio_disable_func(func);
-release:
-       sdio_release_host(func);
-       kfree(wl_sdio);
-out_free_hw:
-       wl1251_free_hw(wl);
-       return ret;
-}
-
-static void __devexit wl1251_sdio_remove(struct sdio_func *func)
-{
-       struct wl1251 *wl = sdio_get_drvdata(func);
-       struct wl1251_sdio *wl_sdio = wl->if_priv;
-
-       /* Undo decrement done above in wl1251_probe */
-       pm_runtime_get_noresume(&func->dev);
-
-       if (wl->irq)
-               free_irq(wl->irq, wl);
-       kfree(wl_sdio);
-       wl1251_free_hw(wl);
-
-       sdio_claim_host(func);
-       sdio_release_irq(func);
-       sdio_disable_func(func);
-       sdio_release_host(func);
-}
-
-static int wl1251_suspend(struct device *dev)
-{
-       /*
-        * Tell MMC/SDIO core it's OK to power down the card
-        * (if it isn't already), but not to remove it completely.
-        */
-       return 0;
-}
-
-static int wl1251_resume(struct device *dev)
-{
-       return 0;
-}
-
-static const struct dev_pm_ops wl1251_sdio_pm_ops = {
-       .suspend        = wl1251_suspend,
-       .resume         = wl1251_resume,
-};
-
-static struct sdio_driver wl1251_sdio_driver = {
-       .name           = "wl1251_sdio",
-       .id_table       = wl1251_devices,
-       .probe          = wl1251_sdio_probe,
-       .remove         = __devexit_p(wl1251_sdio_remove),
-       .drv.pm         = &wl1251_sdio_pm_ops,
-};
-
-static int __init wl1251_sdio_init(void)
-{
-       int err;
-
-       err = sdio_register_driver(&wl1251_sdio_driver);
-       if (err)
-               wl1251_error("failed to register sdio driver: %d", err);
-       return err;
-}
-
-static void __exit wl1251_sdio_exit(void)
-{
-       sdio_unregister_driver(&wl1251_sdio_driver);
-       wl1251_notice("unloaded");
-}
-
-module_init(wl1251_sdio_init);
-module_exit(wl1251_sdio_exit);
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Kalle Valo <kvalo@adurom.com>");
diff --git a/drivers/net/wireless/wl1251/spi.c b/drivers/net/wireless/wl1251/spi.c
deleted file mode 100644 (file)
index 6248c35..0000000
+++ /dev/null
@@ -1,355 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/interrupt.h>
-#include <linux/irq.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/crc7.h>
-#include <linux/spi/spi.h>
-#include <linux/wl12xx.h>
-
-#include "wl1251.h"
-#include "reg.h"
-#include "spi.h"
-
-static irqreturn_t wl1251_irq(int irq, void *cookie)
-{
-       struct wl1251 *wl;
-
-       wl1251_debug(DEBUG_IRQ, "IRQ");
-
-       wl = cookie;
-
-       ieee80211_queue_work(wl->hw, &wl->irq_work);
-
-       return IRQ_HANDLED;
-}
-
-static struct spi_device *wl_to_spi(struct wl1251 *wl)
-{
-       return wl->if_priv;
-}
-
-static void wl1251_spi_reset(struct wl1251 *wl)
-{
-       u8 *cmd;
-       struct spi_transfer t;
-       struct spi_message m;
-
-       cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
-       if (!cmd) {
-               wl1251_error("could not allocate cmd for spi reset");
-               return;
-       }
-
-       memset(&t, 0, sizeof(t));
-       spi_message_init(&m);
-
-       memset(cmd, 0xff, WSPI_INIT_CMD_LEN);
-
-       t.tx_buf = cmd;
-       t.len = WSPI_INIT_CMD_LEN;
-       spi_message_add_tail(&t, &m);
-
-       spi_sync(wl_to_spi(wl), &m);
-
-       wl1251_dump(DEBUG_SPI, "spi reset -> ", cmd, WSPI_INIT_CMD_LEN);
-}
-
-static void wl1251_spi_wake(struct wl1251 *wl)
-{
-       u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
-       struct spi_transfer t;
-       struct spi_message m;
-
-       cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
-       if (!cmd) {
-               wl1251_error("could not allocate cmd for spi init");
-               return;
-       }
-
-       memset(crc, 0, sizeof(crc));
-       memset(&t, 0, sizeof(t));
-       spi_message_init(&m);
-
-       /*
-        * Set WSPI_INIT_COMMAND
-        * the data is being send from the MSB to LSB
-        */
-       cmd[2] = 0xff;
-       cmd[3] = 0xff;
-       cmd[1] = WSPI_INIT_CMD_START | WSPI_INIT_CMD_TX;
-       cmd[0] = 0;
-       cmd[7] = 0;
-       cmd[6] |= HW_ACCESS_WSPI_INIT_CMD_MASK << 3;
-       cmd[6] |= HW_ACCESS_WSPI_FIXED_BUSY_LEN & WSPI_INIT_CMD_FIXEDBUSY_LEN;
-
-       if (HW_ACCESS_WSPI_FIXED_BUSY_LEN == 0)
-               cmd[5] |=  WSPI_INIT_CMD_DIS_FIXEDBUSY;
-       else
-               cmd[5] |= WSPI_INIT_CMD_EN_FIXEDBUSY;
-
-       cmd[5] |= WSPI_INIT_CMD_IOD | WSPI_INIT_CMD_IP | WSPI_INIT_CMD_CS
-               | WSPI_INIT_CMD_WSPI | WSPI_INIT_CMD_WS;
-
-       crc[0] = cmd[1];
-       crc[1] = cmd[0];
-       crc[2] = cmd[7];
-       crc[3] = cmd[6];
-       crc[4] = cmd[5];
-
-       cmd[4] |= crc7(0, crc, WSPI_INIT_CMD_CRC_LEN) << 1;
-       cmd[4] |= WSPI_INIT_CMD_END;
-
-       t.tx_buf = cmd;
-       t.len = WSPI_INIT_CMD_LEN;
-       spi_message_add_tail(&t, &m);
-
-       spi_sync(wl_to_spi(wl), &m);
-
-       wl1251_dump(DEBUG_SPI, "spi init -> ", cmd, WSPI_INIT_CMD_LEN);
-}
-
-static void wl1251_spi_reset_wake(struct wl1251 *wl)
-{
-       wl1251_spi_reset(wl);
-       wl1251_spi_wake(wl);
-}
-
-static void wl1251_spi_read(struct wl1251 *wl, int addr, void *buf,
-                           size_t len)
-{
-       struct spi_transfer t[3];
-       struct spi_message m;
-       u8 *busy_buf;
-       u32 *cmd;
-
-       cmd = &wl->buffer_cmd;
-       busy_buf = wl->buffer_busyword;
-
-       *cmd = 0;
-       *cmd |= WSPI_CMD_READ;
-       *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
-       *cmd |= addr & WSPI_CMD_BYTE_ADDR;
-
-       spi_message_init(&m);
-       memset(t, 0, sizeof(t));
-
-       t[0].tx_buf = cmd;
-       t[0].len = 4;
-       spi_message_add_tail(&t[0], &m);
-
-       /* Busy and non busy words read */
-       t[1].rx_buf = busy_buf;
-       t[1].len = WL1251_BUSY_WORD_LEN;
-       spi_message_add_tail(&t[1], &m);
-
-       t[2].rx_buf = buf;
-       t[2].len = len;
-       spi_message_add_tail(&t[2], &m);
-
-       spi_sync(wl_to_spi(wl), &m);
-
-       /* FIXME: check busy words */
-
-       wl1251_dump(DEBUG_SPI, "spi_read cmd -> ", cmd, sizeof(*cmd));
-       wl1251_dump(DEBUG_SPI, "spi_read buf <- ", buf, len);
-}
-
-static void wl1251_spi_write(struct wl1251 *wl, int addr, void *buf,
-                            size_t len)
-{
-       struct spi_transfer t[2];
-       struct spi_message m;
-       u32 *cmd;
-
-       cmd = &wl->buffer_cmd;
-
-       *cmd = 0;
-       *cmd |= WSPI_CMD_WRITE;
-       *cmd |= (len << WSPI_CMD_BYTE_LENGTH_OFFSET) & WSPI_CMD_BYTE_LENGTH;
-       *cmd |= addr & WSPI_CMD_BYTE_ADDR;
-
-       spi_message_init(&m);
-       memset(t, 0, sizeof(t));
-
-       t[0].tx_buf = cmd;
-       t[0].len = sizeof(*cmd);
-       spi_message_add_tail(&t[0], &m);
-
-       t[1].tx_buf = buf;
-       t[1].len = len;
-       spi_message_add_tail(&t[1], &m);
-
-       spi_sync(wl_to_spi(wl), &m);
-
-       wl1251_dump(DEBUG_SPI, "spi_write cmd -> ", cmd, sizeof(*cmd));
-       wl1251_dump(DEBUG_SPI, "spi_write buf -> ", buf, len);
-}
-
-static void wl1251_spi_enable_irq(struct wl1251 *wl)
-{
-       return enable_irq(wl->irq);
-}
-
-static void wl1251_spi_disable_irq(struct wl1251 *wl)
-{
-       return disable_irq(wl->irq);
-}
-
-static int wl1251_spi_set_power(struct wl1251 *wl, bool enable)
-{
-       if (wl->set_power)
-               wl->set_power(enable);
-
-       return 0;
-}
-
-static const struct wl1251_if_operations wl1251_spi_ops = {
-       .read = wl1251_spi_read,
-       .write = wl1251_spi_write,
-       .reset = wl1251_spi_reset_wake,
-       .enable_irq = wl1251_spi_enable_irq,
-       .disable_irq = wl1251_spi_disable_irq,
-       .power = wl1251_spi_set_power,
-};
-
-static int __devinit wl1251_spi_probe(struct spi_device *spi)
-{
-       struct wl12xx_platform_data *pdata;
-       struct ieee80211_hw *hw;
-       struct wl1251 *wl;
-       int ret;
-
-       pdata = spi->dev.platform_data;
-       if (!pdata) {
-               wl1251_error("no platform data");
-               return -ENODEV;
-       }
-
-       hw = wl1251_alloc_hw();
-       if (IS_ERR(hw))
-               return PTR_ERR(hw);
-
-       wl = hw->priv;
-
-       SET_IEEE80211_DEV(hw, &spi->dev);
-       dev_set_drvdata(&spi->dev, wl);
-       wl->if_priv = spi;
-       wl->if_ops = &wl1251_spi_ops;
-
-       /* This is the only SPI value that we need to set here, the rest
-        * comes from the board-peripherals file */
-       spi->bits_per_word = 32;
-
-       ret = spi_setup(spi);
-       if (ret < 0) {
-               wl1251_error("spi_setup failed");
-               goto out_free;
-       }
-
-       wl->set_power = pdata->set_power;
-       if (!wl->set_power) {
-               wl1251_error("set power function missing in platform data");
-               return -ENODEV;
-       }
-
-       wl->irq = spi->irq;
-       if (wl->irq < 0) {
-               wl1251_error("irq missing in platform data");
-               return -ENODEV;
-       }
-
-       wl->use_eeprom = pdata->use_eeprom;
-
-       ret = request_irq(wl->irq, wl1251_irq, 0, DRIVER_NAME, wl);
-       if (ret < 0) {
-               wl1251_error("request_irq() failed: %d", ret);
-               goto out_free;
-       }
-
-       irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
-
-       disable_irq(wl->irq);
-
-       ret = wl1251_init_ieee80211(wl);
-       if (ret)
-               goto out_irq;
-
-       return 0;
-
- out_irq:
-       free_irq(wl->irq, wl);
-
- out_free:
-       ieee80211_free_hw(hw);
-
-       return ret;
-}
-
-static int __devexit wl1251_spi_remove(struct spi_device *spi)
-{
-       struct wl1251 *wl = dev_get_drvdata(&spi->dev);
-
-       free_irq(wl->irq, wl);
-       wl1251_free_hw(wl);
-
-       return 0;
-}
-
-static struct spi_driver wl1251_spi_driver = {
-       .driver = {
-               .name           = DRIVER_NAME,
-               .owner          = THIS_MODULE,
-       },
-
-       .probe          = wl1251_spi_probe,
-       .remove         = __devexit_p(wl1251_spi_remove),
-};
-
-static int __init wl1251_spi_init(void)
-{
-       int ret;
-
-       ret = spi_register_driver(&wl1251_spi_driver);
-       if (ret < 0) {
-               wl1251_error("failed to register spi driver: %d", ret);
-               goto out;
-       }
-
-out:
-       return ret;
-}
-
-static void __exit wl1251_spi_exit(void)
-{
-       spi_unregister_driver(&wl1251_spi_driver);
-
-       wl1251_notice("unloaded");
-}
-
-module_init(wl1251_spi_init);
-module_exit(wl1251_spi_exit);
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Kalle Valo <kvalo@adurom.com>");
-MODULE_ALIAS("spi:wl1251");
diff --git a/drivers/net/wireless/wl1251/spi.h b/drivers/net/wireless/wl1251/spi.h
deleted file mode 100644 (file)
index 16d5069..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (c) 1998-2007 Texas Instruments Incorporated
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __WL1251_SPI_H__
-#define __WL1251_SPI_H__
-
-#include "cmd.h"
-#include "acx.h"
-#include "reg.h"
-
-#define WSPI_CMD_READ                 0x40000000
-#define WSPI_CMD_WRITE                0x00000000
-#define WSPI_CMD_FIXED                0x20000000
-#define WSPI_CMD_BYTE_LENGTH          0x1FFE0000
-#define WSPI_CMD_BYTE_LENGTH_OFFSET   17
-#define WSPI_CMD_BYTE_ADDR            0x0001FFFF
-
-#define WSPI_INIT_CMD_CRC_LEN       5
-
-#define WSPI_INIT_CMD_START         0x00
-#define WSPI_INIT_CMD_TX            0x40
-/* the extra bypass bit is sampled by the TNET as '1' */
-#define WSPI_INIT_CMD_BYPASS_BIT    0x80
-#define WSPI_INIT_CMD_FIXEDBUSY_LEN 0x07
-#define WSPI_INIT_CMD_EN_FIXEDBUSY  0x80
-#define WSPI_INIT_CMD_DIS_FIXEDBUSY 0x00
-#define WSPI_INIT_CMD_IOD           0x40
-#define WSPI_INIT_CMD_IP            0x20
-#define WSPI_INIT_CMD_CS            0x10
-#define WSPI_INIT_CMD_WS            0x08
-#define WSPI_INIT_CMD_WSPI          0x01
-#define WSPI_INIT_CMD_END           0x01
-
-#define WSPI_INIT_CMD_LEN           8
-
-#define HW_ACCESS_WSPI_FIXED_BUSY_LEN \
-               ((WL1251_BUSY_WORD_LEN - 4) / sizeof(u32))
-#define HW_ACCESS_WSPI_INIT_CMD_MASK  0
-
-#endif /* __WL1251_SPI_H__ */
diff --git a/drivers/net/wireless/wl1251/tx.c b/drivers/net/wireless/wl1251/tx.c
deleted file mode 100644 (file)
index 28121c5..0000000
+++ /dev/null
@@ -1,560 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (c) 1998-2007 Texas Instruments Incorporated
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-
-#include "wl1251.h"
-#include "reg.h"
-#include "tx.h"
-#include "ps.h"
-#include "io.h"
-
-static bool wl1251_tx_double_buffer_busy(struct wl1251 *wl, u32 data_out_count)
-{
-       int used, data_in_count;
-
-       data_in_count = wl->data_in_count;
-
-       if (data_in_count < data_out_count)
-               /* data_in_count has wrapped */
-               data_in_count += TX_STATUS_DATA_OUT_COUNT_MASK + 1;
-
-       used = data_in_count - data_out_count;
-
-       WARN_ON(used < 0);
-       WARN_ON(used > DP_TX_PACKET_RING_CHUNK_NUM);
-
-       if (used >= DP_TX_PACKET_RING_CHUNK_NUM)
-               return true;
-       else
-               return false;
-}
-
-static int wl1251_tx_path_status(struct wl1251 *wl)
-{
-       u32 status, addr, data_out_count;
-       bool busy;
-
-       addr = wl->data_path->tx_control_addr;
-       status = wl1251_mem_read32(wl, addr);
-       data_out_count = status & TX_STATUS_DATA_OUT_COUNT_MASK;
-       busy = wl1251_tx_double_buffer_busy(wl, data_out_count);
-
-       if (busy)
-               return -EBUSY;
-
-       return 0;
-}
-
-static int wl1251_tx_id(struct wl1251 *wl, struct sk_buff *skb)
-{
-       int i;
-
-       for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
-               if (wl->tx_frames[i] == NULL) {
-                       wl->tx_frames[i] = skb;
-                       return i;
-               }
-
-       return -EBUSY;
-}
-
-static void wl1251_tx_control(struct tx_double_buffer_desc *tx_hdr,
-                             struct ieee80211_tx_info *control, u16 fc)
-{
-       *(u16 *)&tx_hdr->control = 0;
-
-       tx_hdr->control.rate_policy = 0;
-
-       /* 802.11 packets */
-       tx_hdr->control.packet_type = 0;
-
-       if (control->flags & IEEE80211_TX_CTL_NO_ACK)
-               tx_hdr->control.ack_policy = 1;
-
-       tx_hdr->control.tx_complete = 1;
-
-       if ((fc & IEEE80211_FTYPE_DATA) &&
-           ((fc & IEEE80211_STYPE_QOS_DATA) ||
-            (fc & IEEE80211_STYPE_QOS_NULLFUNC)))
-               tx_hdr->control.qos = 1;
-}
-
-/* RSN + MIC = 8 + 8 = 16 bytes (worst case - AES). */
-#define MAX_MSDU_SECURITY_LENGTH      16
-#define MAX_MPDU_SECURITY_LENGTH      16
-#define WLAN_QOS_HDR_LEN              26
-#define MAX_MPDU_HEADER_AND_SECURITY  (MAX_MPDU_SECURITY_LENGTH + \
-                                      WLAN_QOS_HDR_LEN)
-#define HW_BLOCK_SIZE                 252
-static void wl1251_tx_frag_block_num(struct tx_double_buffer_desc *tx_hdr)
-{
-       u16 payload_len, frag_threshold, mem_blocks;
-       u16 num_mpdus, mem_blocks_per_frag;
-
-       frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
-       tx_hdr->frag_threshold = cpu_to_le16(frag_threshold);
-
-       payload_len = le16_to_cpu(tx_hdr->length) + MAX_MSDU_SECURITY_LENGTH;
-
-       if (payload_len > frag_threshold) {
-               mem_blocks_per_frag =
-                       ((frag_threshold + MAX_MPDU_HEADER_AND_SECURITY) /
-                        HW_BLOCK_SIZE) + 1;
-               num_mpdus = payload_len / frag_threshold;
-               mem_blocks = num_mpdus * mem_blocks_per_frag;
-               payload_len -= num_mpdus * frag_threshold;
-               num_mpdus++;
-
-       } else {
-               mem_blocks_per_frag = 0;
-               mem_blocks = 0;
-               num_mpdus = 1;
-       }
-
-       mem_blocks += (payload_len / HW_BLOCK_SIZE) + 1;
-
-       if (num_mpdus > 1)
-               mem_blocks += min(num_mpdus, mem_blocks_per_frag);
-
-       tx_hdr->num_mem_blocks = mem_blocks;
-}
-
-static int wl1251_tx_fill_hdr(struct wl1251 *wl, struct sk_buff *skb,
-                             struct ieee80211_tx_info *control)
-{
-       struct tx_double_buffer_desc *tx_hdr;
-       struct ieee80211_rate *rate;
-       int id;
-       u16 fc;
-
-       if (!skb)
-               return -EINVAL;
-
-       id = wl1251_tx_id(wl, skb);
-       if (id < 0)
-               return id;
-
-       fc = *(u16 *)skb->data;
-       tx_hdr = (struct tx_double_buffer_desc *) skb_push(skb,
-                                                          sizeof(*tx_hdr));
-
-       tx_hdr->length = cpu_to_le16(skb->len - sizeof(*tx_hdr));
-       rate = ieee80211_get_tx_rate(wl->hw, control);
-       tx_hdr->rate = cpu_to_le16(rate->hw_value);
-       tx_hdr->expiry_time = cpu_to_le32(1 << 16);
-       tx_hdr->id = id;
-
-       tx_hdr->xmit_queue = wl1251_tx_get_queue(skb_get_queue_mapping(skb));
-
-       wl1251_tx_control(tx_hdr, control, fc);
-       wl1251_tx_frag_block_num(tx_hdr);
-
-       return 0;
-}
-
-/* We copy the packet to the target */
-static int wl1251_tx_send_packet(struct wl1251 *wl, struct sk_buff *skb,
-                                struct ieee80211_tx_info *control)
-{
-       struct tx_double_buffer_desc *tx_hdr;
-       int len;
-       u32 addr;
-
-       if (!skb)
-               return -EINVAL;
-
-       tx_hdr = (struct tx_double_buffer_desc *) skb->data;
-
-       if (control->control.hw_key &&
-           control->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
-               int hdrlen;
-               __le16 fc;
-               u16 length;
-               u8 *pos;
-
-               fc = *(__le16 *)(skb->data + sizeof(*tx_hdr));
-               length = le16_to_cpu(tx_hdr->length) + WL1251_TKIP_IV_SPACE;
-               tx_hdr->length = cpu_to_le16(length);
-
-               hdrlen = ieee80211_hdrlen(fc);
-
-               pos = skb_push(skb, WL1251_TKIP_IV_SPACE);
-               memmove(pos, pos + WL1251_TKIP_IV_SPACE,
-                       sizeof(*tx_hdr) + hdrlen);
-       }
-
-       /* Revisit. This is a workaround for getting non-aligned packets.
-          This happens at least with EAPOL packets from the user space.
-          Our DMA requires packets to be aligned on a 4-byte boundary.
-       */
-       if (unlikely((long)skb->data & 0x03)) {
-               int offset = (4 - (long)skb->data) & 0x03;
-               wl1251_debug(DEBUG_TX, "skb offset %d", offset);
-
-               /* check whether the current skb can be used */
-               if (skb_cloned(skb) || (skb_tailroom(skb) < offset)) {
-                       struct sk_buff *newskb = skb_copy_expand(skb, 0, 3,
-                                                                GFP_KERNEL);
-
-                       if (unlikely(newskb == NULL)) {
-                               wl1251_error("Can't allocate skb!");
-                               return -EINVAL;
-                       }
-
-                       tx_hdr = (struct tx_double_buffer_desc *) newskb->data;
-
-                       dev_kfree_skb_any(skb);
-                       wl->tx_frames[tx_hdr->id] = skb = newskb;
-
-                       offset = (4 - (long)skb->data) & 0x03;
-                       wl1251_debug(DEBUG_TX, "new skb offset %d", offset);
-               }
-
-               /* align the buffer on a 4-byte boundary */
-               if (offset) {
-                       unsigned char *src = skb->data;
-                       skb_reserve(skb, offset);
-                       memmove(skb->data, src, skb->len);
-                       tx_hdr = (struct tx_double_buffer_desc *) skb->data;
-               }
-       }
-
-       /* Our skb->data at this point includes the HW header */
-       len = WL1251_TX_ALIGN(skb->len);
-
-       if (wl->data_in_count & 0x1)
-               addr = wl->data_path->tx_packet_ring_addr +
-                       wl->data_path->tx_packet_ring_chunk_size;
-       else
-               addr = wl->data_path->tx_packet_ring_addr;
-
-       wl1251_mem_write(wl, addr, skb->data, len);
-
-       wl1251_debug(DEBUG_TX, "tx id %u skb 0x%p payload %u rate 0x%x "
-                    "queue %d", tx_hdr->id, skb, tx_hdr->length,
-                    tx_hdr->rate, tx_hdr->xmit_queue);
-
-       return 0;
-}
-
-static void wl1251_tx_trigger(struct wl1251 *wl)
-{
-       u32 data, addr;
-
-       if (wl->data_in_count & 0x1) {
-               addr = ACX_REG_INTERRUPT_TRIG_H;
-               data = INTR_TRIG_TX_PROC1;
-       } else {
-               addr = ACX_REG_INTERRUPT_TRIG;
-               data = INTR_TRIG_TX_PROC0;
-       }
-
-       wl1251_reg_write32(wl, addr, data);
-
-       /* Bumping data in */
-       wl->data_in_count = (wl->data_in_count + 1) &
-               TX_STATUS_DATA_OUT_COUNT_MASK;
-}
-
-/* caller must hold wl->mutex */
-static int wl1251_tx_frame(struct wl1251 *wl, struct sk_buff *skb)
-{
-       struct ieee80211_tx_info *info;
-       int ret = 0;
-       u8 idx;
-
-       info = IEEE80211_SKB_CB(skb);
-
-       if (info->control.hw_key) {
-               idx = info->control.hw_key->hw_key_idx;
-               if (unlikely(wl->default_key != idx)) {
-                       ret = wl1251_acx_default_key(wl, idx);
-                       if (ret < 0)
-                               return ret;
-               }
-       }
-
-       ret = wl1251_tx_path_status(wl);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_tx_fill_hdr(wl, skb, info);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1251_tx_send_packet(wl, skb, info);
-       if (ret < 0)
-               return ret;
-
-       wl1251_tx_trigger(wl);
-
-       return ret;
-}
-
-void wl1251_tx_work(struct work_struct *work)
-{
-       struct wl1251 *wl = container_of(work, struct wl1251, tx_work);
-       struct sk_buff *skb;
-       bool woken_up = false;
-       int ret;
-
-       mutex_lock(&wl->mutex);
-
-       if (unlikely(wl->state == WL1251_STATE_OFF))
-               goto out;
-
-       while ((skb = skb_dequeue(&wl->tx_queue))) {
-               if (!woken_up) {
-                       ret = wl1251_ps_elp_wakeup(wl);
-                       if (ret < 0)
-                               goto out;
-                       woken_up = true;
-               }
-
-               ret = wl1251_tx_frame(wl, skb);
-               if (ret == -EBUSY) {
-                       skb_queue_head(&wl->tx_queue, skb);
-                       goto out;
-               } else if (ret < 0) {
-                       dev_kfree_skb(skb);
-                       goto out;
-               }
-       }
-
-out:
-       if (woken_up)
-               wl1251_ps_elp_sleep(wl);
-
-       mutex_unlock(&wl->mutex);
-}
-
-static const char *wl1251_tx_parse_status(u8 status)
-{
-       /* 8 bit status field, one character per bit plus null */
-       static char buf[9];
-       int i = 0;
-
-       memset(buf, 0, sizeof(buf));
-
-       if (status & TX_DMA_ERROR)
-               buf[i++] = 'm';
-       if (status & TX_DISABLED)
-               buf[i++] = 'd';
-       if (status & TX_RETRY_EXCEEDED)
-               buf[i++] = 'r';
-       if (status & TX_TIMEOUT)
-               buf[i++] = 't';
-       if (status & TX_KEY_NOT_FOUND)
-               buf[i++] = 'k';
-       if (status & TX_ENCRYPT_FAIL)
-               buf[i++] = 'e';
-       if (status & TX_UNAVAILABLE_PRIORITY)
-               buf[i++] = 'p';
-
-       /* bit 0 is unused apparently */
-
-       return buf;
-}
-
-static void wl1251_tx_packet_cb(struct wl1251 *wl,
-                               struct tx_result *result)
-{
-       struct ieee80211_tx_info *info;
-       struct sk_buff *skb;
-       int hdrlen;
-       u8 *frame;
-
-       skb = wl->tx_frames[result->id];
-       if (skb == NULL) {
-               wl1251_error("SKB for packet %d is NULL", result->id);
-               return;
-       }
-
-       info = IEEE80211_SKB_CB(skb);
-
-       if (!(info->flags & IEEE80211_TX_CTL_NO_ACK) &&
-           (result->status == TX_SUCCESS))
-               info->flags |= IEEE80211_TX_STAT_ACK;
-
-       info->status.rates[0].count = result->ack_failures + 1;
-       wl->stats.retry_count += result->ack_failures;
-
-       /*
-        * We have to remove our private TX header before pushing
-        * the skb back to mac80211.
-        */
-       frame = skb_pull(skb, sizeof(struct tx_double_buffer_desc));
-       if (info->control.hw_key &&
-           info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
-               hdrlen = ieee80211_get_hdrlen_from_skb(skb);
-               memmove(frame + WL1251_TKIP_IV_SPACE, frame, hdrlen);
-               skb_pull(skb, WL1251_TKIP_IV_SPACE);
-       }
-
-       wl1251_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
-                    " status 0x%x (%s)",
-                    result->id, skb, result->ack_failures, result->rate,
-                    result->status, wl1251_tx_parse_status(result->status));
-
-
-       ieee80211_tx_status(wl->hw, skb);
-
-       wl->tx_frames[result->id] = NULL;
-}
-
-/* Called upon reception of a TX complete interrupt */
-void wl1251_tx_complete(struct wl1251 *wl)
-{
-       int i, result_index, num_complete = 0, queue_len;
-       struct tx_result result[FW_TX_CMPLT_BLOCK_SIZE], *result_ptr;
-       unsigned long flags;
-
-       if (unlikely(wl->state != WL1251_STATE_ON))
-               return;
-
-       /* First we read the result */
-       wl1251_mem_read(wl, wl->data_path->tx_complete_addr,
-                           result, sizeof(result));
-
-       result_index = wl->next_tx_complete;
-
-       for (i = 0; i < ARRAY_SIZE(result); i++) {
-               result_ptr = &result[result_index];
-
-               if (result_ptr->done_1 == 1 &&
-                   result_ptr->done_2 == 1) {
-                       wl1251_tx_packet_cb(wl, result_ptr);
-
-                       result_ptr->done_1 = 0;
-                       result_ptr->done_2 = 0;
-
-                       result_index = (result_index + 1) &
-                               (FW_TX_CMPLT_BLOCK_SIZE - 1);
-                       num_complete++;
-               } else {
-                       break;
-               }
-       }
-
-       queue_len = skb_queue_len(&wl->tx_queue);
-
-       if ((num_complete > 0) && (queue_len > 0)) {
-               /* firmware buffer has space, reschedule tx_work */
-               wl1251_debug(DEBUG_TX, "tx_complete: reschedule tx_work");
-               ieee80211_queue_work(wl->hw, &wl->tx_work);
-       }
-
-       if (wl->tx_queue_stopped &&
-           queue_len <= WL1251_TX_QUEUE_LOW_WATERMARK) {
-               /* tx_queue has space, restart queues */
-               wl1251_debug(DEBUG_TX, "tx_complete: waking queues");
-               spin_lock_irqsave(&wl->wl_lock, flags);
-               ieee80211_wake_queues(wl->hw);
-               wl->tx_queue_stopped = false;
-               spin_unlock_irqrestore(&wl->wl_lock, flags);
-       }
-
-       /* Every completed frame needs to be acknowledged */
-       if (num_complete) {
-               /*
-                * If we've wrapped, we have to clear
-                * the results in 2 steps.
-                */
-               if (result_index > wl->next_tx_complete) {
-                       /* Only 1 write is needed */
-                       wl1251_mem_write(wl,
-                                        wl->data_path->tx_complete_addr +
-                                        (wl->next_tx_complete *
-                                         sizeof(struct tx_result)),
-                                        &result[wl->next_tx_complete],
-                                        num_complete *
-                                        sizeof(struct tx_result));
-
-
-               } else if (result_index < wl->next_tx_complete) {
-                       /* 2 writes are needed */
-                       wl1251_mem_write(wl,
-                                        wl->data_path->tx_complete_addr +
-                                        (wl->next_tx_complete *
-                                         sizeof(struct tx_result)),
-                                        &result[wl->next_tx_complete],
-                                        (FW_TX_CMPLT_BLOCK_SIZE -
-                                         wl->next_tx_complete) *
-                                        sizeof(struct tx_result));
-
-                       wl1251_mem_write(wl,
-                                        wl->data_path->tx_complete_addr,
-                                        result,
-                                        (num_complete -
-                                         FW_TX_CMPLT_BLOCK_SIZE +
-                                         wl->next_tx_complete) *
-                                        sizeof(struct tx_result));
-
-               } else {
-                       /* We have to write the whole array */
-                       wl1251_mem_write(wl,
-                                        wl->data_path->tx_complete_addr,
-                                        result,
-                                        FW_TX_CMPLT_BLOCK_SIZE *
-                                        sizeof(struct tx_result));
-               }
-
-       }
-
-       wl->next_tx_complete = result_index;
-}
-
-/* caller must hold wl->mutex */
-void wl1251_tx_flush(struct wl1251 *wl)
-{
-       int i;
-       struct sk_buff *skb;
-       struct ieee80211_tx_info *info;
-
-       /* TX failure */
-/*     control->flags = 0; FIXME */
-
-       while ((skb = skb_dequeue(&wl->tx_queue))) {
-               info = IEEE80211_SKB_CB(skb);
-
-               wl1251_debug(DEBUG_TX, "flushing skb 0x%p", skb);
-
-               if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS))
-                               continue;
-
-               ieee80211_tx_status(wl->hw, skb);
-       }
-
-       for (i = 0; i < FW_TX_CMPLT_BLOCK_SIZE; i++)
-               if (wl->tx_frames[i] != NULL) {
-                       skb = wl->tx_frames[i];
-                       info = IEEE80211_SKB_CB(skb);
-
-                       if (!(info->flags & IEEE80211_TX_CTL_REQ_TX_STATUS))
-                               continue;
-
-                       ieee80211_tx_status(wl->hw, skb);
-                       wl->tx_frames[i] = NULL;
-               }
-}
diff --git a/drivers/net/wireless/wl1251/tx.h b/drivers/net/wireless/wl1251/tx.h
deleted file mode 100644 (file)
index 81338d3..0000000
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (c) 1998-2007 Texas Instruments Incorporated
- * Copyright (C) 2008 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __WL1251_TX_H__
-#define __WL1251_TX_H__
-
-#include <linux/bitops.h>
-#include "acx.h"
-
-/*
- *
- * TX PATH
- *
- * The Tx path uses a double buffer and a tx_control structure, each located
- * at a fixed address in the device's memory. On startup, the host retrieves
- * the pointers to these addresses. A double buffer allows for continuous data
- * flow towards the device. The host keeps track of which buffer is available
- * and alternates between these two buffers on a per packet basis.
- *
- * The size of each of the two buffers is large enough to hold the longest
- * 802.3 packet - maximum size Ethernet packet + header + descriptor.
- * TX complete indication will be received a-synchronously in a TX done cyclic
- * buffer which is composed of 16 tx_result descriptors structures and is used
- * in a cyclic manner.
- *
- * The TX (HOST) procedure is as follows:
- * 1. Read the Tx path status, that will give the data_out_count.
- * 2. goto 1, if not possible.
- *    i.e. if data_in_count - data_out_count >= HwBuffer size (2 for double
- *    buffer).
- * 3. Copy the packet (preceded by double_buffer_desc), if possible.
- *    i.e. if data_in_count - data_out_count < HwBuffer size (2 for double
- *    buffer).
- * 4. increment data_in_count.
- * 5. Inform the firmware by generating a firmware internal interrupt.
- * 6. FW will increment data_out_count after it reads the buffer.
- *
- * The TX Complete procedure:
- * 1. To get a TX complete indication the host enables the tx_complete flag in
- *    the TX descriptor Structure.
- * 2. For each packet with a Tx Complete field set, the firmware adds the
- *    transmit results to the cyclic buffer (txDoneRing) and sets both done_1
- *    and done_2 to 1 to indicate driver ownership.
- * 3. The firmware sends a Tx Complete interrupt to the host to trigger the
- *    host to process the new data. Note: interrupt will be send per packet if
- *    TX complete indication was requested in tx_control or per crossing
- *    aggregation threshold.
- * 4. After receiving the Tx Complete interrupt, the host reads the
- *    TxDescriptorDone information in a cyclic manner and clears both done_1
- *    and done_2 fields.
- *
- */
-
-#define TX_COMPLETE_REQUIRED_BIT       0x80
-#define TX_STATUS_DATA_OUT_COUNT_MASK   0xf
-
-#define WL1251_TX_ALIGN_TO 4
-#define WL1251_TX_ALIGN(len) (((len) + WL1251_TX_ALIGN_TO - 1) & \
-                            ~(WL1251_TX_ALIGN_TO - 1))
-#define WL1251_TKIP_IV_SPACE 4
-
-struct tx_control {
-       /* Rate Policy (class) index */
-       unsigned rate_policy:3;
-
-       /* When set, no ack policy is expected */
-       unsigned ack_policy:1;
-
-       /*
-        * Packet type:
-        * 0 -> 802.11
-        * 1 -> 802.3
-        * 2 -> IP
-        * 3 -> raw codec
-        */
-       unsigned packet_type:2;
-
-       /* If set, this is a QoS-Null or QoS-Data frame */
-       unsigned qos:1;
-
-       /*
-        * If set, the target triggers the tx complete INT
-        * upon frame sending completion.
-        */
-       unsigned tx_complete:1;
-
-       /* 2 bytes padding before packet header */
-       unsigned xfer_pad:1;
-
-       unsigned reserved:7;
-} __packed;
-
-
-struct tx_double_buffer_desc {
-       /* Length of payload, including headers. */
-       __le16 length;
-
-       /*
-        * A bit mask that specifies the initial rate to be used
-        * Possible values are:
-        * 0x0001 - 1Mbits
-        * 0x0002 - 2Mbits
-        * 0x0004 - 5.5Mbits
-        * 0x0008 - 6Mbits
-        * 0x0010 - 9Mbits
-        * 0x0020 - 11Mbits
-        * 0x0040 - 12Mbits
-        * 0x0080 - 18Mbits
-        * 0x0100 - 22Mbits
-        * 0x0200 - 24Mbits
-        * 0x0400 - 36Mbits
-        * 0x0800 - 48Mbits
-        * 0x1000 - 54Mbits
-        */
-       __le16 rate;
-
-       /* Time in us that a packet can spend in the target */
-       __le32 expiry_time;
-
-       /* index of the TX queue used for this packet */
-       u8 xmit_queue;
-
-       /* Used to identify a packet */
-       u8 id;
-
-       struct tx_control control;
-
-       /*
-        * The FW should cut the packet into fragments
-        * of this size.
-        */
-       __le16 frag_threshold;
-
-       /* Numbers of HW queue blocks to be allocated */
-       u8 num_mem_blocks;
-
-       u8 reserved;
-} __packed;
-
-enum {
-       TX_SUCCESS              = 0,
-       TX_DMA_ERROR            = BIT(7),
-       TX_DISABLED             = BIT(6),
-       TX_RETRY_EXCEEDED       = BIT(5),
-       TX_TIMEOUT              = BIT(4),
-       TX_KEY_NOT_FOUND        = BIT(3),
-       TX_ENCRYPT_FAIL         = BIT(2),
-       TX_UNAVAILABLE_PRIORITY = BIT(1),
-};
-
-struct tx_result {
-       /*
-        * Ownership synchronization between the host and
-        * the firmware. If done_1 and done_2 are cleared,
-        * owned by the FW (no info ready).
-        */
-       u8 done_1;
-
-       /* same as double_buffer_desc->id */
-       u8 id;
-
-       /*
-        * Total air access duration consumed by this
-        * packet, including all retries and overheads.
-        */
-       u16 medium_usage;
-
-       /* Total media delay (from 1st EDCA AIFS counter until TX Complete). */
-       u32 medium_delay;
-
-       /* Time between host xfer and tx complete */
-       u32 fw_hnadling_time;
-
-       /* The LS-byte of the last TKIP sequence number. */
-       u8 lsb_seq_num;
-
-       /* Retry count */
-       u8 ack_failures;
-
-       /* At which rate we got a ACK */
-       u16 rate;
-
-       u16 reserved;
-
-       /* TX_* */
-       u8 status;
-
-       /* See done_1 */
-       u8 done_2;
-} __packed;
-
-static inline int wl1251_tx_get_queue(int queue)
-{
-       switch (queue) {
-       case 0:
-               return QOS_AC_VO;
-       case 1:
-               return QOS_AC_VI;
-       case 2:
-               return QOS_AC_BE;
-       case 3:
-               return QOS_AC_BK;
-       default:
-               return QOS_AC_BE;
-       }
-}
-
-void wl1251_tx_work(struct work_struct *work);
-void wl1251_tx_complete(struct wl1251 *wl);
-void wl1251_tx_flush(struct wl1251 *wl);
-
-#endif
diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
deleted file mode 100644 (file)
index 9d8f581..0000000
+++ /dev/null
@@ -1,446 +0,0 @@
-/*
- * This file is part of wl1251
- *
- * Copyright (c) 1998-2007 Texas Instruments Incorporated
- * Copyright (C) 2008-2009 Nokia Corporation
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __WL1251_H__
-#define __WL1251_H__
-
-#include <linux/mutex.h>
-#include <linux/list.h>
-#include <linux/bitops.h>
-#include <net/mac80211.h>
-
-#define DRIVER_NAME "wl1251"
-#define DRIVER_PREFIX DRIVER_NAME ": "
-
-enum {
-       DEBUG_NONE      = 0,
-       DEBUG_IRQ       = BIT(0),
-       DEBUG_SPI       = BIT(1),
-       DEBUG_BOOT      = BIT(2),
-       DEBUG_MAILBOX   = BIT(3),
-       DEBUG_NETLINK   = BIT(4),
-       DEBUG_EVENT     = BIT(5),
-       DEBUG_TX        = BIT(6),
-       DEBUG_RX        = BIT(7),
-       DEBUG_SCAN      = BIT(8),
-       DEBUG_CRYPT     = BIT(9),
-       DEBUG_PSM       = BIT(10),
-       DEBUG_MAC80211  = BIT(11),
-       DEBUG_CMD       = BIT(12),
-       DEBUG_ACX       = BIT(13),
-       DEBUG_ALL       = ~0,
-};
-
-#define DEBUG_LEVEL (DEBUG_NONE)
-
-#define DEBUG_DUMP_LIMIT 1024
-
-#define wl1251_error(fmt, arg...) \
-       printk(KERN_ERR DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
-
-#define wl1251_warning(fmt, arg...) \
-       printk(KERN_WARNING DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
-
-#define wl1251_notice(fmt, arg...) \
-       printk(KERN_INFO DRIVER_PREFIX fmt "\n", ##arg)
-
-#define wl1251_info(fmt, arg...) \
-       printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg)
-
-#define wl1251_debug(level, fmt, arg...) \
-       do { \
-               if (level & DEBUG_LEVEL) \
-                       printk(KERN_DEBUG DRIVER_PREFIX fmt "\n", ##arg); \
-       } while (0)
-
-#define wl1251_dump(level, prefix, buf, len)   \
-       do { \
-               if (level & DEBUG_LEVEL) \
-                       print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
-                                      DUMP_PREFIX_OFFSET, 16, 1,       \
-                                      buf,                             \
-                                      min_t(size_t, len, DEBUG_DUMP_LIMIT), \
-                                      0);                              \
-       } while (0)
-
-#define wl1251_dump_ascii(level, prefix, buf, len)     \
-       do { \
-               if (level & DEBUG_LEVEL) \
-                       print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
-                                      DUMP_PREFIX_OFFSET, 16, 1,       \
-                                      buf,                             \
-                                      min_t(size_t, len, DEBUG_DUMP_LIMIT), \
-                                      true);                           \
-       } while (0)
-
-#define WL1251_DEFAULT_RX_CONFIG (CFG_UNI_FILTER_EN |  \
-                                 CFG_BSSID_FILTER_EN)
-
-#define WL1251_DEFAULT_RX_FILTER (CFG_RX_PRSP_EN |  \
-                                 CFG_RX_MGMT_EN |  \
-                                 CFG_RX_DATA_EN |  \
-                                 CFG_RX_CTL_EN |   \
-                                 CFG_RX_BCN_EN |   \
-                                 CFG_RX_AUTH_EN |  \
-                                 CFG_RX_ASSOC_EN)
-
-#define WL1251_BUSY_WORD_LEN 8
-
-struct boot_attr {
-       u32 radio_type;
-       u8 mac_clock;
-       u8 arm_clock;
-       int firmware_debug;
-       u32 minor;
-       u32 major;
-       u32 bugfix;
-};
-
-enum wl1251_state {
-       WL1251_STATE_OFF,
-       WL1251_STATE_ON,
-       WL1251_STATE_PLT,
-};
-
-enum wl1251_partition_type {
-       PART_DOWN,
-       PART_WORK,
-       PART_DRPW,
-
-       PART_TABLE_LEN
-};
-
-enum wl1251_station_mode {
-       STATION_ACTIVE_MODE,
-       STATION_POWER_SAVE_MODE,
-       STATION_IDLE,
-};
-
-struct wl1251_partition {
-       u32 size;
-       u32 start;
-};
-
-struct wl1251_partition_set {
-       struct wl1251_partition mem;
-       struct wl1251_partition reg;
-};
-
-struct wl1251;
-
-struct wl1251_stats {
-       struct acx_statistics *fw_stats;
-       unsigned long fw_stats_update;
-
-       unsigned int retry_count;
-       unsigned int excessive_retries;
-};
-
-struct wl1251_debugfs {
-       struct dentry *rootdir;
-       struct dentry *fw_statistics;
-
-       struct dentry *tx_internal_desc_overflow;
-
-       struct dentry *rx_out_of_mem;
-       struct dentry *rx_hdr_overflow;
-       struct dentry *rx_hw_stuck;
-       struct dentry *rx_dropped;
-       struct dentry *rx_fcs_err;
-       struct dentry *rx_xfr_hint_trig;
-       struct dentry *rx_path_reset;
-       struct dentry *rx_reset_counter;
-
-       struct dentry *dma_rx_requested;
-       struct dentry *dma_rx_errors;
-       struct dentry *dma_tx_requested;
-       struct dentry *dma_tx_errors;
-
-       struct dentry *isr_cmd_cmplt;
-       struct dentry *isr_fiqs;
-       struct dentry *isr_rx_headers;
-       struct dentry *isr_rx_mem_overflow;
-       struct dentry *isr_rx_rdys;
-       struct dentry *isr_irqs;
-       struct dentry *isr_tx_procs;
-       struct dentry *isr_decrypt_done;
-       struct dentry *isr_dma0_done;
-       struct dentry *isr_dma1_done;
-       struct dentry *isr_tx_exch_complete;
-       struct dentry *isr_commands;
-       struct dentry *isr_rx_procs;
-       struct dentry *isr_hw_pm_mode_changes;
-       struct dentry *isr_host_acknowledges;
-       struct dentry *isr_pci_pm;
-       struct dentry *isr_wakeups;
-       struct dentry *isr_low_rssi;
-
-       struct dentry *wep_addr_key_count;
-       struct dentry *wep_default_key_count;
-       /* skipping wep.reserved */
-       struct dentry *wep_key_not_found;
-       struct dentry *wep_decrypt_fail;
-       struct dentry *wep_packets;
-       struct dentry *wep_interrupt;
-
-       struct dentry *pwr_ps_enter;
-       struct dentry *pwr_elp_enter;
-       struct dentry *pwr_missing_bcns;
-       struct dentry *pwr_wake_on_host;
-       struct dentry *pwr_wake_on_timer_exp;
-       struct dentry *pwr_tx_with_ps;
-       struct dentry *pwr_tx_without_ps;
-       struct dentry *pwr_rcvd_beacons;
-       struct dentry *pwr_power_save_off;
-       struct dentry *pwr_enable_ps;
-       struct dentry *pwr_disable_ps;
-       struct dentry *pwr_fix_tsf_ps;
-       /* skipping cont_miss_bcns_spread for now */
-       struct dentry *pwr_rcvd_awake_beacons;
-
-       struct dentry *mic_rx_pkts;
-       struct dentry *mic_calc_failure;
-
-       struct dentry *aes_encrypt_fail;
-       struct dentry *aes_decrypt_fail;
-       struct dentry *aes_encrypt_packets;
-       struct dentry *aes_decrypt_packets;
-       struct dentry *aes_encrypt_interrupt;
-       struct dentry *aes_decrypt_interrupt;
-
-       struct dentry *event_heart_beat;
-       struct dentry *event_calibration;
-       struct dentry *event_rx_mismatch;
-       struct dentry *event_rx_mem_empty;
-       struct dentry *event_rx_pool;
-       struct dentry *event_oom_late;
-       struct dentry *event_phy_transmit_error;
-       struct dentry *event_tx_stuck;
-
-       struct dentry *ps_pspoll_timeouts;
-       struct dentry *ps_upsd_timeouts;
-       struct dentry *ps_upsd_max_sptime;
-       struct dentry *ps_upsd_max_apturn;
-       struct dentry *ps_pspoll_max_apturn;
-       struct dentry *ps_pspoll_utilization;
-       struct dentry *ps_upsd_utilization;
-
-       struct dentry *rxpipe_rx_prep_beacon_drop;
-       struct dentry *rxpipe_descr_host_int_trig_rx_data;
-       struct dentry *rxpipe_beacon_buffer_thres_host_int_trig_rx_data;
-       struct dentry *rxpipe_missed_beacon_host_int_trig_rx_data;
-       struct dentry *rxpipe_tx_xfr_host_int_trig_rx_data;
-
-       struct dentry *tx_queue_len;
-       struct dentry *tx_queue_status;
-
-       struct dentry *retry_count;
-       struct dentry *excessive_retries;
-};
-
-struct wl1251_if_operations {
-       void (*read)(struct wl1251 *wl, int addr, void *buf, size_t len);
-       void (*write)(struct wl1251 *wl, int addr, void *buf, size_t len);
-       void (*read_elp)(struct wl1251 *wl, int addr, u32 *val);
-       void (*write_elp)(struct wl1251 *wl, int addr, u32 val);
-       int  (*power)(struct wl1251 *wl, bool enable);
-       void (*reset)(struct wl1251 *wl);
-       void (*enable_irq)(struct wl1251 *wl);
-       void (*disable_irq)(struct wl1251 *wl);
-};
-
-struct wl1251 {
-       struct ieee80211_hw *hw;
-       bool mac80211_registered;
-
-       void *if_priv;
-       const struct wl1251_if_operations *if_ops;
-
-       void (*set_power)(bool enable);
-       int irq;
-       bool use_eeprom;
-
-       spinlock_t wl_lock;
-
-       enum wl1251_state state;
-       struct mutex mutex;
-
-       int physical_mem_addr;
-       int physical_reg_addr;
-       int virtual_mem_addr;
-       int virtual_reg_addr;
-
-       int cmd_box_addr;
-       int event_box_addr;
-       struct boot_attr boot_attr;
-
-       u8 *fw;
-       size_t fw_len;
-       u8 *nvs;
-       size_t nvs_len;
-
-       u8 bssid[ETH_ALEN];
-       u8 mac_addr[ETH_ALEN];
-       u8 bss_type;
-       u8 listen_int;
-       int channel;
-
-       void *target_mem_map;
-       struct acx_data_path_params_resp *data_path;
-
-       /* Number of TX packets transferred to the FW, modulo 16 */
-       u32 data_in_count;
-
-       /* Frames scheduled for transmission, not handled yet */
-       struct sk_buff_head tx_queue;
-       bool tx_queue_stopped;
-
-       struct work_struct tx_work;
-       struct work_struct filter_work;
-
-       /* Pending TX frames */
-       struct sk_buff *tx_frames[16];
-
-       /*
-        * Index pointing to the next TX complete entry
-        * in the cyclic XT complete array we get from
-        * the FW.
-        */
-       u32 next_tx_complete;
-
-       /* FW Rx counter */
-       u32 rx_counter;
-
-       /* Rx frames handled */
-       u32 rx_handled;
-
-       /* Current double buffer */
-       u32 rx_current_buffer;
-       u32 rx_last_id;
-
-       /* The target interrupt mask */
-       u32 intr_mask;
-       struct work_struct irq_work;
-
-       /* The mbox event mask */
-       u32 event_mask;
-
-       /* Mailbox pointers */
-       u32 mbox_ptr[2];
-
-       /* Are we currently scanning */
-       bool scanning;
-
-       /* Default key (for WEP) */
-       u32 default_key;
-
-       unsigned int tx_mgmt_frm_rate;
-       unsigned int tx_mgmt_frm_mod;
-
-       unsigned int rx_config;
-       unsigned int rx_filter;
-
-       /* is firmware in elp mode */
-       bool elp;
-
-       struct delayed_work elp_work;
-
-       enum wl1251_station_mode station_mode;
-
-       /* PSM mode requested */
-       bool psm_requested;
-
-       u16 beacon_int;
-       u8 dtim_period;
-
-       /* in dBm */
-       int power_level;
-
-       int rssi_thold;
-
-       struct wl1251_stats stats;
-       struct wl1251_debugfs debugfs;
-
-       __le32 buffer_32;
-       u32 buffer_cmd;
-       u8 buffer_busyword[WL1251_BUSY_WORD_LEN];
-       struct wl1251_rx_descriptor *rx_descriptor;
-
-       struct ieee80211_vif *vif;
-
-       u32 chip_id;
-       char fw_ver[21];
-
-       /* Most recently reported noise in dBm */
-       s8 noise;
-};
-
-int wl1251_plt_start(struct wl1251 *wl);
-int wl1251_plt_stop(struct wl1251 *wl);
-
-struct ieee80211_hw *wl1251_alloc_hw(void);
-int wl1251_free_hw(struct wl1251 *wl);
-int wl1251_init_ieee80211(struct wl1251 *wl);
-void wl1251_enable_interrupts(struct wl1251 *wl);
-void wl1251_disable_interrupts(struct wl1251 *wl);
-
-#define DEFAULT_HW_GEN_MODULATION_TYPE    CCK_LONG /* Long Preamble */
-#define DEFAULT_HW_GEN_TX_RATE          RATE_2MBPS
-#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
-
-#define WL1251_DEFAULT_POWER_LEVEL 20
-
-#define WL1251_TX_QUEUE_LOW_WATERMARK  10
-#define WL1251_TX_QUEUE_HIGH_WATERMARK 25
-
-#define WL1251_DEFAULT_BEACON_INT 100
-#define WL1251_DEFAULT_DTIM_PERIOD 1
-
-#define WL1251_DEFAULT_CHANNEL 0
-
-#define WL1251_DEFAULT_BET_CONSECUTIVE 10
-
-#define CHIP_ID_1251_PG10                 (0x7010101)
-#define CHIP_ID_1251_PG11                 (0x7020101)
-#define CHIP_ID_1251_PG12                 (0x7030101)
-#define CHIP_ID_1271_PG10                 (0x4030101)
-#define CHIP_ID_1271_PG20                 (0x4030111)
-
-#define WL1251_FW_NAME "wl1251-fw.bin"
-#define WL1251_NVS_NAME "wl1251-nvs.bin"
-
-#define WL1251_POWER_ON_SLEEP 10 /* in milliseconds */
-
-#define WL1251_PART_DOWN_MEM_START     0x0
-#define WL1251_PART_DOWN_MEM_SIZE      0x16800
-#define WL1251_PART_DOWN_REG_START     REGISTERS_BASE
-#define WL1251_PART_DOWN_REG_SIZE      REGISTERS_DOWN_SIZE
-
-#define WL1251_PART_WORK_MEM_START     0x28000
-#define WL1251_PART_WORK_MEM_SIZE      0x14000
-#define WL1251_PART_WORK_REG_START     REGISTERS_BASE
-#define WL1251_PART_WORK_REG_SIZE      REGISTERS_WORK_SIZE
-
-#define WL1251_DEFAULT_LOW_RSSI_WEIGHT          10
-#define WL1251_DEFAULT_LOW_RSSI_DEPTH           10
-
-#endif
diff --git a/drivers/net/wireless/wl1251/wl12xx_80211.h b/drivers/net/wireless/wl1251/wl12xx_80211.h
deleted file mode 100644 (file)
index 04ed514..0000000
+++ /dev/null
@@ -1,155 +0,0 @@
-#ifndef __WL12XX_80211_H__
-#define __WL12XX_80211_H__
-
-#include <linux/if_ether.h>    /* ETH_ALEN */
-
-/* RATES */
-#define IEEE80211_CCK_RATE_1MB                 0x02
-#define IEEE80211_CCK_RATE_2MB                 0x04
-#define IEEE80211_CCK_RATE_5MB                 0x0B
-#define IEEE80211_CCK_RATE_11MB                        0x16
-#define IEEE80211_OFDM_RATE_6MB                        0x0C
-#define IEEE80211_OFDM_RATE_9MB                        0x12
-#define IEEE80211_OFDM_RATE_12MB               0x18
-#define IEEE80211_OFDM_RATE_18MB               0x24
-#define IEEE80211_OFDM_RATE_24MB               0x30
-#define IEEE80211_OFDM_RATE_36MB               0x48
-#define IEEE80211_OFDM_RATE_48MB               0x60
-#define IEEE80211_OFDM_RATE_54MB               0x6C
-#define IEEE80211_BASIC_RATE_MASK              0x80
-
-#define IEEE80211_CCK_RATE_1MB_MASK            (1<<0)
-#define IEEE80211_CCK_RATE_2MB_MASK            (1<<1)
-#define IEEE80211_CCK_RATE_5MB_MASK            (1<<2)
-#define IEEE80211_CCK_RATE_11MB_MASK           (1<<3)
-#define IEEE80211_OFDM_RATE_6MB_MASK           (1<<4)
-#define IEEE80211_OFDM_RATE_9MB_MASK           (1<<5)
-#define IEEE80211_OFDM_RATE_12MB_MASK          (1<<6)
-#define IEEE80211_OFDM_RATE_18MB_MASK          (1<<7)
-#define IEEE80211_OFDM_RATE_24MB_MASK          (1<<8)
-#define IEEE80211_OFDM_RATE_36MB_MASK          (1<<9)
-#define IEEE80211_OFDM_RATE_48MB_MASK          (1<<10)
-#define IEEE80211_OFDM_RATE_54MB_MASK          (1<<11)
-
-#define IEEE80211_CCK_RATES_MASK         0x0000000F
-#define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
-       IEEE80211_CCK_RATE_2MB_MASK)
-#define IEEE80211_CCK_DEFAULT_RATES_MASK (IEEE80211_CCK_BASIC_RATES_MASK | \
-       IEEE80211_CCK_RATE_5MB_MASK | \
-       IEEE80211_CCK_RATE_11MB_MASK)
-
-#define IEEE80211_OFDM_RATES_MASK        0x00000FF0
-#define IEEE80211_OFDM_BASIC_RATES_MASK          (IEEE80211_OFDM_RATE_6MB_MASK | \
-       IEEE80211_OFDM_RATE_12MB_MASK | \
-       IEEE80211_OFDM_RATE_24MB_MASK)
-#define IEEE80211_OFDM_DEFAULT_RATES_MASK (IEEE80211_OFDM_BASIC_RATES_MASK | \
-       IEEE80211_OFDM_RATE_9MB_MASK  | \
-       IEEE80211_OFDM_RATE_18MB_MASK | \
-       IEEE80211_OFDM_RATE_36MB_MASK | \
-       IEEE80211_OFDM_RATE_48MB_MASK | \
-       IEEE80211_OFDM_RATE_54MB_MASK)
-#define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
-                                     IEEE80211_CCK_DEFAULT_RATES_MASK)
-
-
-/* This really should be 8, but not for our firmware */
-#define MAX_SUPPORTED_RATES 32
-#define MAX_COUNTRY_TRIPLETS 32
-
-/* Headers */
-struct ieee80211_header {
-       __le16 frame_ctl;
-       __le16 duration_id;
-       u8 da[ETH_ALEN];
-       u8 sa[ETH_ALEN];
-       u8 bssid[ETH_ALEN];
-       __le16 seq_ctl;
-       u8 payload[0];
-} __packed;
-
-struct wl12xx_ie_header {
-       u8 id;
-       u8 len;
-} __packed;
-
-/* IEs */
-
-struct wl12xx_ie_ssid {
-       struct wl12xx_ie_header header;
-       char ssid[IEEE80211_MAX_SSID_LEN];
-} __packed;
-
-struct wl12xx_ie_rates {
-       struct wl12xx_ie_header header;
-       u8 rates[MAX_SUPPORTED_RATES];
-} __packed;
-
-struct wl12xx_ie_ds_params {
-       struct wl12xx_ie_header header;
-       u8 channel;
-} __packed;
-
-struct country_triplet {
-       u8 channel;
-       u8 num_channels;
-       u8 max_tx_power;
-} __packed;
-
-struct wl12xx_ie_country {
-       struct wl12xx_ie_header header;
-       u8 country_string[IEEE80211_COUNTRY_STRING_LEN];
-       struct country_triplet triplets[MAX_COUNTRY_TRIPLETS];
-} __packed;
-
-
-/* Templates */
-
-struct wl12xx_beacon_template {
-       struct ieee80211_header header;
-       __le32 time_stamp[2];
-       __le16 beacon_interval;
-       __le16 capability;
-       struct wl12xx_ie_ssid ssid;
-       struct wl12xx_ie_rates rates;
-       struct wl12xx_ie_rates ext_rates;
-       struct wl12xx_ie_ds_params ds_params;
-       struct wl12xx_ie_country country;
-} __packed;
-
-struct wl12xx_null_data_template {
-       struct ieee80211_header header;
-} __packed;
-
-struct wl12xx_ps_poll_template {
-       __le16 fc;
-       __le16 aid;
-       u8 bssid[ETH_ALEN];
-       u8 ta[ETH_ALEN];
-} __packed;
-
-struct wl12xx_qos_null_data_template {
-       struct ieee80211_header header;
-       __le16 qos_ctl;
-} __packed;
-
-struct wl12xx_probe_req_template {
-       struct ieee80211_header header;
-       struct wl12xx_ie_ssid ssid;
-       struct wl12xx_ie_rates rates;
-       struct wl12xx_ie_rates ext_rates;
-} __packed;
-
-
-struct wl12xx_probe_resp_template {
-       struct ieee80211_header header;
-       __le32 time_stamp[2];
-       __le16 beacon_interval;
-       __le16 capability;
-       struct wl12xx_ie_ssid ssid;
-       struct wl12xx_ie_rates rates;
-       struct wl12xx_ie_rates ext_rates;
-       struct wl12xx_ie_ds_params ds_params;
-       struct wl12xx_ie_country country;
-} __packed;
-
-#endif
diff --git a/drivers/net/wireless/wl12xx/Kconfig b/drivers/net/wireless/wl12xx/Kconfig
deleted file mode 100644 (file)
index af08c86..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-menuconfig WL12XX_MENU
-       tristate "TI wl12xx driver support"
-       depends on MAC80211 && EXPERIMENTAL
-       ---help---
-         This will enable TI wl12xx driver support for the following chips:
-         wl1271, wl1273, wl1281 and wl1283.
-         The drivers make use of the mac80211 stack.
-
-config WL12XX
-       tristate "TI wl12xx support"
-       depends on WL12XX_MENU && GENERIC_HARDIRQS
-       depends on INET
-       select FW_LOADER
-       ---help---
-         This module adds support for wireless adapters based on TI wl1271 and
-         TI wl1273 chipsets. This module does *not* include support for wl1251.
-         For wl1251 support, use the separate homonymous driver instead.
-
-         If you choose to build a module, it will be called wl12xx. Say N if
-         unsure.
-
-config WL12XX_SPI
-       tristate "TI wl12xx SPI support"
-       depends on WL12XX && SPI_MASTER
-       select CRC7
-       ---help---
-         This module adds support for the SPI interface of adapters using
-         TI wl12xx chipsets.  Select this if your platform is using
-         the SPI bus.
-
-         If you choose to build a module, it'll be called wl12xx_spi.
-         Say N if unsure.
-
-config WL12XX_SDIO
-       tristate "TI wl12xx SDIO support"
-       depends on WL12XX && MMC
-       ---help---
-         This module adds support for the SDIO interface of adapters using
-         TI wl12xx chipsets.  Select this if your platform is using
-         the SDIO bus.
-
-         If you choose to build a module, it'll be called wl12xx_sdio.
-         Say N if unsure.
-
-config WL12XX_PLATFORM_DATA
-       bool
-       depends on WL12XX_SDIO != n || WL1251_SDIO != n
-       default y
diff --git a/drivers/net/wireless/wl12xx/Makefile b/drivers/net/wireless/wl12xx/Makefile
deleted file mode 100644 (file)
index 98f289c..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-wl12xx-objs            = main.o cmd.o io.o event.o tx.o rx.o ps.o acx.o \
-                         boot.o init.o debugfs.o scan.o
-
-wl12xx_spi-objs        = spi.o
-wl12xx_sdio-objs       = sdio.o
-
-wl12xx-$(CONFIG_NL80211_TESTMODE)      += testmode.o
-obj-$(CONFIG_WL12XX)                   += wl12xx.o
-obj-$(CONFIG_WL12XX_SPI)               += wl12xx_spi.o
-obj-$(CONFIG_WL12XX_SDIO)              += wl12xx_sdio.o
-
-# small builtin driver bit
-obj-$(CONFIG_WL12XX_PLATFORM_DATA)     += wl12xx_platform_data.o
-
-ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/net/wireless/wl12xx/acx.c b/drivers/net/wireless/wl12xx/acx.c
deleted file mode 100644 (file)
index bc96db0..0000000
+++ /dev/null
@@ -1,1742 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2008-2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include "acx.h"
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/spi/spi.h>
-#include <linux/slab.h>
-
-#include "wl12xx.h"
-#include "debug.h"
-#include "wl12xx_80211.h"
-#include "reg.h"
-#include "ps.h"
-
-int wl1271_acx_wake_up_conditions(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                                 u8 wake_up_event, u8 listen_interval)
-{
-       struct acx_wake_up_condition *wake_up;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx wake up conditions (wake_up_event %d listen_interval %d)",
-                    wake_up_event, listen_interval);
-
-       wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
-       if (!wake_up) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wake_up->role_id = wlvif->role_id;
-       wake_up->wake_up_event = wake_up_event;
-       wake_up->listen_interval = listen_interval;
-
-       ret = wl1271_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
-                                  wake_up, sizeof(*wake_up));
-       if (ret < 0) {
-               wl1271_warning("could not set wake up conditions: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(wake_up);
-       return ret;
-}
-
-int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth)
-{
-       struct acx_sleep_auth *auth;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx sleep auth");
-
-       auth = kzalloc(sizeof(*auth), GFP_KERNEL);
-       if (!auth) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       auth->sleep_auth = sleep_auth;
-
-       ret = wl1271_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
-
-out:
-       kfree(auth);
-       return ret;
-}
-
-int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                       int power)
-{
-       struct acx_current_tx_power *acx;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr %d", power);
-
-       if (power < 0 || power > 25)
-               return -EINVAL;
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->role_id = wlvif->role_id;
-       acx->current_tx_power = power * 10;
-
-       ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("configure of tx power failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_feature_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       struct acx_feature_config *feature;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx feature cfg");
-
-       feature = kzalloc(sizeof(*feature), GFP_KERNEL);
-       if (!feature) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
-       feature->role_id = wlvif->role_id;
-       feature->data_flow_options = 0;
-       feature->options = 0;
-
-       ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
-                                  feature, sizeof(*feature));
-       if (ret < 0) {
-               wl1271_error("Couldnt set HW encryption");
-               goto out;
-       }
-
-out:
-       kfree(feature);
-       return ret;
-}
-
-int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
-                      size_t len)
-{
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx mem map");
-
-       ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
-{
-       struct acx_rx_msdu_lifetime *acx;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
-       ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
-                                  acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("failed to set rx msdu life time: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_slot(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                   enum acx_slot_type slot_time)
-{
-       struct acx_slot *slot;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx slot");
-
-       slot = kzalloc(sizeof(*slot), GFP_KERNEL);
-       if (!slot) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       slot->role_id = wlvif->role_id;
-       slot->wone_index = STATION_WONE_INDEX;
-       slot->slot_time = slot_time;
-
-       ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
-       if (ret < 0) {
-               wl1271_warning("failed to set slot time: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(slot);
-       return ret;
-}
-
-int wl1271_acx_group_address_tbl(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                                bool enable, void *mc_list, u32 mc_list_len)
-{
-       struct acx_dot11_grp_addr_tbl *acx;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx group address tbl");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* MAC filtering */
-       acx->role_id = wlvif->role_id;
-       acx->enabled = enable;
-       acx->num_groups = mc_list_len;
-       memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
-
-       ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
-                                  acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("failed to set group addr table: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_service_period_timeout(struct wl1271 *wl,
-                                     struct wl12xx_vif *wlvif)
-{
-       struct acx_rx_timeout *rx_timeout;
-       int ret;
-
-       rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
-       if (!rx_timeout) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wl1271_debug(DEBUG_ACX, "acx service period timeout");
-
-       rx_timeout->role_id = wlvif->role_id;
-       rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
-       rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
-
-       ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
-                                  rx_timeout, sizeof(*rx_timeout));
-       if (ret < 0) {
-               wl1271_warning("failed to set service period timeout: %d",
-                              ret);
-               goto out;
-       }
-
-out:
-       kfree(rx_timeout);
-       return ret;
-}
-
-int wl1271_acx_rts_threshold(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                            u32 rts_threshold)
-{
-       struct acx_rts_threshold *rts;
-       int ret;
-
-       /*
-        * If the RTS threshold is not configured or out of range, use the
-        * default value.
-        */
-       if (rts_threshold > IEEE80211_MAX_RTS_THRESHOLD)
-               rts_threshold = wl->conf.rx.rts_threshold;
-
-       wl1271_debug(DEBUG_ACX, "acx rts threshold: %d", rts_threshold);
-
-       rts = kzalloc(sizeof(*rts), GFP_KERNEL);
-       if (!rts) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       rts->role_id = wlvif->role_id;
-       rts->threshold = cpu_to_le16((u16)rts_threshold);
-
-       ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
-       if (ret < 0) {
-               wl1271_warning("failed to set rts threshold: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(rts);
-       return ret;
-}
-
-int wl1271_acx_dco_itrim_params(struct wl1271 *wl)
-{
-       struct acx_dco_itrim_params *dco;
-       struct conf_itrim_settings *c = &wl->conf.itrim;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx dco itrim parameters");
-
-       dco = kzalloc(sizeof(*dco), GFP_KERNEL);
-       if (!dco) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       dco->enable = c->enable;
-       dco->timeout = cpu_to_le32(c->timeout);
-
-       ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS,
-                                  dco, sizeof(*dco));
-       if (ret < 0) {
-               wl1271_warning("failed to set dco itrim parameters: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(dco);
-       return ret;
-}
-
-int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                                bool enable_filter)
-{
-       struct acx_beacon_filter_option *beacon_filter = NULL;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
-
-       if (enable_filter &&
-           wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
-               goto out;
-
-       beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
-       if (!beacon_filter) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       beacon_filter->role_id = wlvif->role_id;
-       beacon_filter->enable = enable_filter;
-
-       /*
-        * When set to zero, and the filter is enabled, beacons
-        * without the unicast TIM bit set are dropped.
-        */
-       beacon_filter->max_num_beacons = 0;
-
-       ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
-                                  beacon_filter, sizeof(*beacon_filter));
-       if (ret < 0) {
-               wl1271_warning("failed to set beacon filter opt: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(beacon_filter);
-       return ret;
-}
-
-int wl1271_acx_beacon_filter_table(struct wl1271 *wl,
-                                  struct wl12xx_vif *wlvif)
-{
-       struct acx_beacon_filter_ie_table *ie_table;
-       int i, idx = 0;
-       int ret;
-       bool vendor_spec = false;
-
-       wl1271_debug(DEBUG_ACX, "acx beacon filter table");
-
-       ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
-       if (!ie_table) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* configure default beacon pass-through rules */
-       ie_table->role_id = wlvif->role_id;
-       ie_table->num_ie = 0;
-       for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
-               struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
-               ie_table->table[idx++] = r->ie;
-               ie_table->table[idx++] = r->rule;
-
-               if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
-                       /* only one vendor specific ie allowed */
-                       if (vendor_spec)
-                               continue;
-
-                       /* for vendor specific rules configure the
-                          additional fields */
-                       memcpy(&(ie_table->table[idx]), r->oui,
-                              CONF_BCN_IE_OUI_LEN);
-                       idx += CONF_BCN_IE_OUI_LEN;
-                       ie_table->table[idx++] = r->type;
-                       memcpy(&(ie_table->table[idx]), r->version,
-                              CONF_BCN_IE_VER_LEN);
-                       idx += CONF_BCN_IE_VER_LEN;
-                       vendor_spec = true;
-               }
-
-               ie_table->num_ie++;
-       }
-
-       ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
-                                  ie_table, sizeof(*ie_table));
-       if (ret < 0) {
-               wl1271_warning("failed to set beacon filter table: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(ie_table);
-       return ret;
-}
-
-#define ACX_CONN_MONIT_DISABLE_VALUE  0xffffffff
-
-int wl1271_acx_conn_monit_params(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                                bool enable)
-{
-       struct acx_conn_monit_params *acx;
-       u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE;
-       u32 timeout = ACX_CONN_MONIT_DISABLE_VALUE;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx connection monitor parameters: %s",
-                    enable ? "enabled" : "disabled");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       if (enable) {
-               threshold = wl->conf.conn.synch_fail_thold;
-               timeout = wl->conf.conn.bss_lose_timeout;
-       }
-
-       acx->role_id = wlvif->role_id;
-       acx->synch_fail_thold = cpu_to_le32(threshold);
-       acx->bss_lose_timeout = cpu_to_le32(timeout);
-
-       ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
-                                  acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("failed to set connection monitor "
-                              "parameters: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-
-int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable)
-{
-       struct acx_bt_wlan_coex *pta;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx sg enable");
-
-       pta = kzalloc(sizeof(*pta), GFP_KERNEL);
-       if (!pta) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       if (enable)
-               pta->enable = wl->conf.sg.state;
-       else
-               pta->enable = CONF_SG_DISABLE;
-
-       ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
-       if (ret < 0) {
-               wl1271_warning("failed to set softgemini enable: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(pta);
-       return ret;
-}
-
-int wl12xx_acx_sg_cfg(struct wl1271 *wl)
-{
-       struct acx_bt_wlan_coex_param *param;
-       struct conf_sg_settings *c = &wl->conf.sg;
-       int i, ret;
-
-       wl1271_debug(DEBUG_ACX, "acx sg cfg");
-
-       param = kzalloc(sizeof(*param), GFP_KERNEL);
-       if (!param) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* BT-WLAN coext parameters */
-       for (i = 0; i < CONF_SG_PARAMS_MAX; i++)
-               param->params[i] = cpu_to_le32(c->params[i]);
-       param->param_idx = CONF_SG_PARAMS_ALL;
-
-       ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
-       if (ret < 0) {
-               wl1271_warning("failed to set sg config: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(param);
-       return ret;
-}
-
-int wl1271_acx_cca_threshold(struct wl1271 *wl)
-{
-       struct acx_energy_detection *detection;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx cca threshold");
-
-       detection = kzalloc(sizeof(*detection), GFP_KERNEL);
-       if (!detection) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
-       detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
-
-       ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
-                                  detection, sizeof(*detection));
-       if (ret < 0)
-               wl1271_warning("failed to set cca threshold: %d", ret);
-
-out:
-       kfree(detection);
-       return ret;
-}
-
-int wl1271_acx_bcn_dtim_options(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       struct acx_beacon_broadcast *bb;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
-
-       bb = kzalloc(sizeof(*bb), GFP_KERNEL);
-       if (!bb) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       bb->role_id = wlvif->role_id;
-       bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
-       bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
-       bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
-       bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
-
-       ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
-       if (ret < 0) {
-               wl1271_warning("failed to set rx config: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(bb);
-       return ret;
-}
-
-int wl1271_acx_aid(struct wl1271 *wl, struct wl12xx_vif *wlvif, u16 aid)
-{
-       struct acx_aid *acx_aid;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx aid");
-
-       acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
-       if (!acx_aid) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx_aid->role_id = wlvif->role_id;
-       acx_aid->aid = cpu_to_le16(aid);
-
-       ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
-       if (ret < 0) {
-               wl1271_warning("failed to set aid: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx_aid);
-       return ret;
-}
-
-int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
-{
-       struct acx_event_mask *mask;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx event mbox mask");
-
-       mask = kzalloc(sizeof(*mask), GFP_KERNEL);
-       if (!mask) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* high event mask is unused */
-       mask->high_event_mask = cpu_to_le32(0xffffffff);
-       mask->event_mask = cpu_to_le32(event_mask);
-
-       ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
-                                  mask, sizeof(*mask));
-       if (ret < 0) {
-               wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(mask);
-       return ret;
-}
-
-int wl1271_acx_set_preamble(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                           enum acx_preamble_type preamble)
-{
-       struct acx_preamble *acx;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx_set_preamble");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->role_id = wlvif->role_id;
-       acx->preamble = preamble;
-
-       ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("Setting of preamble failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                          enum acx_ctsprotect_type ctsprotect)
-{
-       struct acx_ctsprotect *acx;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->role_id = wlvif->role_id;
-       acx->ctsprotect = ctsprotect;
-
-       ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("Setting of ctsprotect failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
-{
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx statistics");
-
-       ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
-                                    sizeof(*stats));
-       if (ret < 0) {
-               wl1271_warning("acx statistics failed: %d", ret);
-               return -ENOMEM;
-       }
-
-       return 0;
-}
-
-int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       struct acx_rate_policy *acx;
-       struct conf_tx_rate_class *c = &wl->conf.tx.sta_rc_conf;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx rate policies");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wl1271_debug(DEBUG_ACX, "basic_rate: 0x%x, full_rate: 0x%x",
-               wlvif->basic_rate, wlvif->rate_set);
-
-       /* configure one basic rate class */
-       acx->rate_policy_idx = cpu_to_le32(wlvif->sta.basic_rate_idx);
-       acx->rate_policy.enabled_rates = cpu_to_le32(wlvif->basic_rate);
-       acx->rate_policy.short_retry_limit = c->short_retry_limit;
-       acx->rate_policy.long_retry_limit = c->long_retry_limit;
-       acx->rate_policy.aflags = c->aflags;
-
-       ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("Setting of rate policies failed: %d", ret);
-               goto out;
-       }
-
-       /* configure one AP supported rate class */
-       acx->rate_policy_idx = cpu_to_le32(wlvif->sta.ap_rate_idx);
-       acx->rate_policy.enabled_rates = cpu_to_le32(wlvif->rate_set);
-       acx->rate_policy.short_retry_limit = c->short_retry_limit;
-       acx->rate_policy.long_retry_limit = c->long_retry_limit;
-       acx->rate_policy.aflags = c->aflags;
-
-       ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("Setting of rate policies failed: %d", ret);
-               goto out;
-       }
-
-       /*
-        * configure one rate class for basic p2p operations.
-        * (p2p packets should always go out with OFDM rates, even
-        * if we are currently connected to 11b AP)
-        */
-       acx->rate_policy_idx = cpu_to_le32(wlvif->sta.p2p_rate_idx);
-       acx->rate_policy.enabled_rates =
-                               cpu_to_le32(CONF_TX_RATE_MASK_BASIC_P2P);
-       acx->rate_policy.short_retry_limit = c->short_retry_limit;
-       acx->rate_policy.long_retry_limit = c->long_retry_limit;
-       acx->rate_policy.aflags = c->aflags;
-
-       ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("Setting of rate policies failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
-                     u8 idx)
-{
-       struct acx_rate_policy *acx;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx ap rate policy %d rates 0x%x",
-                    idx, c->enabled_rates);
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->rate_policy.enabled_rates = cpu_to_le32(c->enabled_rates);
-       acx->rate_policy.short_retry_limit = c->short_retry_limit;
-       acx->rate_policy.long_retry_limit = c->long_retry_limit;
-       acx->rate_policy.aflags = c->aflags;
-
-       acx->rate_policy_idx = cpu_to_le32(idx);
-
-       ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("Setting of ap rate policy failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_ac_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                     u8 ac, u8 cw_min, u16 cw_max, u8 aifsn, u16 txop)
-{
-       struct acx_ac_cfg *acx;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
-                    "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop);
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->role_id = wlvif->role_id;
-       acx->ac = ac;
-       acx->cw_min = cw_min;
-       acx->cw_max = cpu_to_le16(cw_max);
-       acx->aifsn = aifsn;
-       acx->tx_op_limit = cpu_to_le16(txop);
-
-       ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx ac cfg failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_tid_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                      u8 queue_id, u8 channel_type,
-                      u8 tsid, u8 ps_scheme, u8 ack_policy,
-                      u32 apsd_conf0, u32 apsd_conf1)
-{
-       struct acx_tid_config *acx;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx tid config");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->role_id = wlvif->role_id;
-       acx->queue_id = queue_id;
-       acx->channel_type = channel_type;
-       acx->tsid = tsid;
-       acx->ps_scheme = ps_scheme;
-       acx->ack_policy = ack_policy;
-       acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
-       acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
-
-       ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("Setting of tid config failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold)
-{
-       struct acx_frag_threshold *acx;
-       int ret = 0;
-
-       /*
-        * If the fragmentation is not configured or out of range, use the
-        * default value.
-        */
-       if (frag_threshold > IEEE80211_MAX_FRAG_THRESHOLD)
-               frag_threshold = wl->conf.tx.frag_threshold;
-
-       wl1271_debug(DEBUG_ACX, "acx frag threshold: %d", frag_threshold);
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->frag_threshold = cpu_to_le16((u16)frag_threshold);
-       ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("Setting of frag threshold failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_tx_config_options(struct wl1271 *wl)
-{
-       struct acx_tx_config_options *acx;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx tx config options");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
-       acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
-       ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("Setting of tx options failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl12xx_acx_mem_cfg(struct wl1271 *wl)
-{
-       struct wl12xx_acx_config_memory *mem_conf;
-       struct conf_memory_settings *mem;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
-
-       mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
-       if (!mem_conf) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       if (wl->chip.id == CHIP_ID_1283_PG20)
-               mem = &wl->conf.mem_wl128x;
-       else
-               mem = &wl->conf.mem_wl127x;
-
-       /* memory config */
-       mem_conf->num_stations = mem->num_stations;
-       mem_conf->rx_mem_block_num = mem->rx_block_num;
-       mem_conf->tx_min_mem_block_num = mem->tx_min_block_num;
-       mem_conf->num_ssid_profiles = mem->ssid_profiles;
-       mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS);
-       mem_conf->dyn_mem_enable = mem->dynamic_memory;
-       mem_conf->tx_free_req = mem->min_req_tx_blocks;
-       mem_conf->rx_free_req = mem->min_req_rx_blocks;
-       mem_conf->tx_min = mem->tx_min;
-       mem_conf->fwlog_blocks = wl->conf.fwlog.mem_blocks;
-
-       ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
-                                  sizeof(*mem_conf));
-       if (ret < 0) {
-               wl1271_warning("wl1271 mem config failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(mem_conf);
-       return ret;
-}
-
-int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap)
-{
-       struct wl1271_acx_host_config_bitmap *bitmap_conf;
-       int ret;
-
-       bitmap_conf = kzalloc(sizeof(*bitmap_conf), GFP_KERNEL);
-       if (!bitmap_conf) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       bitmap_conf->host_cfg_bitmap = cpu_to_le32(host_cfg_bitmap);
-
-       ret = wl1271_cmd_configure(wl, ACX_HOST_IF_CFG_BITMAP,
-                                  bitmap_conf, sizeof(*bitmap_conf));
-       if (ret < 0) {
-               wl1271_warning("wl1271 bitmap config opt failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(bitmap_conf);
-
-       return ret;
-}
-
-int wl1271_acx_init_mem_config(struct wl1271 *wl)
-{
-       int ret;
-
-       wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
-                                    GFP_KERNEL);
-       if (!wl->target_mem_map) {
-               wl1271_error("couldn't allocate target memory map");
-               return -ENOMEM;
-       }
-
-       /* we now ask for the firmware built memory map */
-       ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
-                                sizeof(struct wl1271_acx_mem_map));
-       if (ret < 0) {
-               wl1271_error("couldn't retrieve firmware memory map");
-               kfree(wl->target_mem_map);
-               wl->target_mem_map = NULL;
-               return ret;
-       }
-
-       /* initialize TX block book keeping */
-       wl->tx_blocks_available =
-               le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
-       wl1271_debug(DEBUG_TX, "available tx blocks: %d",
-                    wl->tx_blocks_available);
-
-       return 0;
-}
-
-int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
-{
-       struct wl1271_acx_rx_config_opt *rx_conf;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
-
-       rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
-       if (!rx_conf) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
-       rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
-       rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
-       rx_conf->queue_type = wl->conf.rx.queue_type;
-
-       ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
-                                  sizeof(*rx_conf));
-       if (ret < 0) {
-               wl1271_warning("wl1271 rx config opt failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(rx_conf);
-       return ret;
-}
-
-int wl1271_acx_bet_enable(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                         bool enable)
-{
-       struct wl1271_acx_bet_enable *acx = NULL;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx bet enable");
-
-       if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
-               goto out;
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->role_id = wlvif->role_id;
-       acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
-       acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
-
-       ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx bet enable failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_arp_ip_filter(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                            u8 enable, __be32 address)
-{
-       struct wl1271_acx_arp_filter *acx;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->role_id = wlvif->role_id;
-       acx->version = ACX_IPV4_VERSION;
-       acx->enable = enable;
-
-       if (enable)
-               memcpy(acx->address, &address, ACX_IPV4_ADDR_SIZE);
-
-       ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
-                                  acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("failed to set arp ip filter: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_pm_config(struct wl1271 *wl)
-{
-       struct wl1271_acx_pm_config *acx = NULL;
-       struct  conf_pm_config_settings *c = &wl->conf.pm_config;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx pm config");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
-       acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
-
-       ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx pm config failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                              bool enable)
-{
-       struct wl1271_acx_keep_alive_mode *acx = NULL;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx keep alive mode: %d", enable);
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->role_id = wlvif->role_id;
-       acx->enabled = enable;
-
-       ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx keep alive mode failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_keep_alive_config(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                                u8 index, u8 tpl_valid)
-{
-       struct wl1271_acx_keep_alive_config *acx = NULL;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx keep alive config");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->role_id = wlvif->role_id;
-       acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval);
-       acx->index = index;
-       acx->tpl_validation = tpl_valid;
-       acx->trigger = ACX_KEEP_ALIVE_NO_TX;
-
-       ret = wl1271_cmd_configure(wl, ACX_SET_KEEP_ALIVE_CONFIG,
-                                  acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx keep alive config failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                               bool enable, s16 thold, u8 hyst)
-{
-       struct wl1271_acx_rssi_snr_trigger *acx = NULL;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx rssi snr trigger");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wlvif->last_rssi_event = -1;
-
-       acx->role_id = wlvif->role_id;
-       acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing);
-       acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON;
-       acx->type = WL1271_ACX_TRIG_TYPE_EDGE;
-       if (enable)
-               acx->enable = WL1271_ACX_TRIG_ENABLE;
-       else
-               acx->enable = WL1271_ACX_TRIG_DISABLE;
-
-       acx->index = WL1271_ACX_TRIG_IDX_RSSI;
-       acx->dir = WL1271_ACX_TRIG_DIR_BIDIR;
-       acx->threshold = cpu_to_le16(thold);
-       acx->hysteresis = hyst;
-
-       ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_TRIGGER, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx rssi snr trigger setting failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl,
-                                   struct wl12xx_vif *wlvif)
-{
-       struct wl1271_acx_rssi_snr_avg_weights *acx = NULL;
-       struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx rssi snr avg weights");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->role_id = wlvif->role_id;
-       acx->rssi_beacon = c->avg_weight_rssi_beacon;
-       acx->rssi_data = c->avg_weight_rssi_data;
-       acx->snr_beacon = c->avg_weight_snr_beacon;
-       acx->snr_data = c->avg_weight_snr_data;
-
-       ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_WEIGHTS, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx rssi snr trigger weights failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
-                                   struct ieee80211_sta_ht_cap *ht_cap,
-                                   bool allow_ht_operation, u8 hlid)
-{
-       struct wl1271_acx_ht_capabilities *acx;
-       int ret = 0;
-       u32 ht_capabilites = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx ht capabilities setting "
-                    "sta supp: %d sta cap: %d", ht_cap->ht_supported,
-                    ht_cap->cap);
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       if (allow_ht_operation && ht_cap->ht_supported) {
-               /* no need to translate capabilities - use the spec values */
-               ht_capabilites = ht_cap->cap;
-
-               /*
-                * this bit is not employed by the spec but only by FW to
-                * indicate peer HT support
-                */
-               ht_capabilites |= WL12XX_HT_CAP_HT_OPERATION;
-
-               /* get data from A-MPDU parameters field */
-               acx->ampdu_max_length = ht_cap->ampdu_factor;
-               acx->ampdu_min_spacing = ht_cap->ampdu_density;
-       }
-
-       acx->hlid = hlid;
-       acx->ht_capabilites = cpu_to_le32(ht_capabilites);
-
-       ret = wl1271_cmd_configure(wl, ACX_PEER_HT_CAP, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx ht capabilities setting failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_set_ht_information(struct wl1271 *wl,
-                                  struct wl12xx_vif *wlvif,
-                                  u16 ht_operation_mode)
-{
-       struct wl1271_acx_ht_information *acx;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx ht information setting");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->role_id = wlvif->role_id;
-       acx->ht_protection =
-               (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION);
-       acx->rifs_mode = 0;
-       acx->gf_protection =
-               !!(ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
-       acx->ht_tx_burst_limit = 0;
-       acx->dual_cts_protection = 0;
-
-       ret = wl1271_cmd_configure(wl, ACX_HT_BSS_OPERATION, acx, sizeof(*acx));
-
-       if (ret < 0) {
-               wl1271_warning("acx ht information setting failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-/* Configure BA session initiator/receiver parameters setting in the FW. */
-int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl,
-                                      struct wl12xx_vif *wlvif)
-{
-       struct wl1271_acx_ba_initiator_policy *acx;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx ba initiator policy");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* set for the current role */
-       acx->role_id = wlvif->role_id;
-       acx->tid_bitmap = wl->conf.ht.tx_ba_tid_bitmap;
-       acx->win_size = wl->conf.ht.tx_ba_win_size;
-       acx->inactivity_timeout = wl->conf.ht.inactivity_timeout;
-
-       ret = wl1271_cmd_configure(wl,
-                                  ACX_BA_SESSION_INIT_POLICY,
-                                  acx,
-                                  sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx ba initiator policy failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-/* setup BA session receiver setting in the FW. */
-int wl12xx_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index,
-                                      u16 ssn, bool enable, u8 peer_hlid)
-{
-       struct wl1271_acx_ba_receiver_setup *acx;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx ba receiver session setting");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->hlid = peer_hlid;
-       acx->tid = tid_index;
-       acx->enable = enable;
-       acx->win_size = wl->conf.ht.rx_ba_win_size;
-       acx->ssn = ssn;
-
-       ret = wl1271_cmd_configure(wl, ACX_BA_SESSION_RX_SETUP, acx,
-                                  sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx ba receiver session failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl12xx_acx_tsf_info(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                       u64 *mactime)
-{
-       struct wl12xx_acx_fw_tsf_information *tsf_info;
-       int ret;
-
-       tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
-       if (!tsf_info) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       tsf_info->role_id = wlvif->role_id;
-
-       ret = wl1271_cmd_interrogate(wl, ACX_TSF_INFO,
-                                    tsf_info, sizeof(*tsf_info));
-       if (ret < 0) {
-               wl1271_warning("acx tsf info interrogate failed");
-               goto out;
-       }
-
-       *mactime = le32_to_cpu(tsf_info->current_tsf_low) |
-               ((u64) le32_to_cpu(tsf_info->current_tsf_high) << 32);
-
-out:
-       kfree(tsf_info);
-       return ret;
-}
-
-int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                              bool enable)
-{
-       struct wl1271_acx_ps_rx_streaming *rx_streaming;
-       u32 conf_queues, enable_queues;
-       int i, ret = 0;
-
-       wl1271_debug(DEBUG_ACX, "acx ps rx streaming");
-
-       rx_streaming = kzalloc(sizeof(*rx_streaming), GFP_KERNEL);
-       if (!rx_streaming) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       conf_queues = wl->conf.rx_streaming.queues;
-       if (enable)
-               enable_queues = conf_queues;
-       else
-               enable_queues = 0;
-
-       for (i = 0; i < 8; i++) {
-               /*
-                * Skip non-changed queues, to avoid redundant acxs.
-                * this check assumes conf.rx_streaming.queues can't
-                * be changed while rx_streaming is enabled.
-                */
-               if (!(conf_queues & BIT(i)))
-                       continue;
-
-               rx_streaming->role_id = wlvif->role_id;
-               rx_streaming->tid = i;
-               rx_streaming->enable = enable_queues & BIT(i);
-               rx_streaming->period = wl->conf.rx_streaming.interval;
-               rx_streaming->timeout = wl->conf.rx_streaming.interval;
-
-               ret = wl1271_cmd_configure(wl, ACX_PS_RX_STREAMING,
-                                          rx_streaming,
-                                          sizeof(*rx_streaming));
-               if (ret < 0) {
-                       wl1271_warning("acx ps rx streaming failed: %d", ret);
-                       goto out;
-               }
-       }
-out:
-       kfree(rx_streaming);
-       return ret;
-}
-
-int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       struct wl1271_acx_ap_max_tx_retry *acx = NULL;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx ap max tx retry");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx)
-               return -ENOMEM;
-
-       acx->role_id = wlvif->role_id;
-       acx->max_tx_retry = cpu_to_le16(wl->conf.tx.max_tx_retries);
-
-       ret = wl1271_cmd_configure(wl, ACX_MAX_TX_FAILURE, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx ap max tx retry failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl12xx_acx_config_ps(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       struct wl1271_acx_config_ps *config_ps;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx config ps");
-
-       config_ps = kzalloc(sizeof(*config_ps), GFP_KERNEL);
-       if (!config_ps) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       config_ps->exit_retries = wl->conf.conn.psm_exit_retries;
-       config_ps->enter_retries = wl->conf.conn.psm_entry_retries;
-       config_ps->null_data_rate = cpu_to_le32(wlvif->basic_rate);
-
-       ret = wl1271_cmd_configure(wl, ACX_CONFIG_PS, config_ps,
-                                  sizeof(*config_ps));
-
-       if (ret < 0) {
-               wl1271_warning("acx config ps failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(config_ps);
-       return ret;
-}
-
-int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr)
-{
-       struct wl1271_acx_inconnection_sta *acx = NULL;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx set inconnaction sta %pM", addr);
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx)
-               return -ENOMEM;
-
-       memcpy(acx->addr, addr, ETH_ALEN);
-
-       ret = wl1271_cmd_configure(wl, ACX_UPDATE_INCONNECTION_STA_LIST,
-                                  acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx set inconnaction sta failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl1271_acx_fm_coex(struct wl1271 *wl)
-{
-       struct wl1271_acx_fm_coex *acx;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx fm coex setting");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->enable = wl->conf.fm_coex.enable;
-       acx->swallow_period = wl->conf.fm_coex.swallow_period;
-       acx->n_divider_fref_set_1 = wl->conf.fm_coex.n_divider_fref_set_1;
-       acx->n_divider_fref_set_2 = wl->conf.fm_coex.n_divider_fref_set_2;
-       acx->m_divider_fref_set_1 =
-               cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_1);
-       acx->m_divider_fref_set_2 =
-               cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_2);
-       acx->coex_pll_stabilization_time =
-               cpu_to_le32(wl->conf.fm_coex.coex_pll_stabilization_time);
-       acx->ldo_stabilization_time =
-               cpu_to_le16(wl->conf.fm_coex.ldo_stabilization_time);
-       acx->fm_disturbed_band_margin =
-               wl->conf.fm_coex.fm_disturbed_band_margin;
-       acx->swallow_clk_diff = wl->conf.fm_coex.swallow_clk_diff;
-
-       ret = wl1271_cmd_configure(wl, ACX_FM_COEX_CFG, acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx fm coex setting failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl12xx_acx_set_rate_mgmt_params(struct wl1271 *wl)
-{
-       struct wl12xx_acx_set_rate_mgmt_params *acx = NULL;
-       struct conf_rate_policy_settings *conf = &wl->conf.rate;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx set rate mgmt params");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx)
-               return -ENOMEM;
-
-       acx->index = ACX_RATE_MGMT_ALL_PARAMS;
-       acx->rate_retry_score = cpu_to_le16(conf->rate_retry_score);
-       acx->per_add = cpu_to_le16(conf->per_add);
-       acx->per_th1 = cpu_to_le16(conf->per_th1);
-       acx->per_th2 = cpu_to_le16(conf->per_th2);
-       acx->max_per = cpu_to_le16(conf->max_per);
-       acx->inverse_curiosity_factor = conf->inverse_curiosity_factor;
-       acx->tx_fail_low_th = conf->tx_fail_low_th;
-       acx->tx_fail_high_th = conf->tx_fail_high_th;
-       acx->per_alpha_shift = conf->per_alpha_shift;
-       acx->per_add_shift = conf->per_add_shift;
-       acx->per_beta1_shift = conf->per_beta1_shift;
-       acx->per_beta2_shift = conf->per_beta2_shift;
-       acx->rate_check_up = conf->rate_check_up;
-       acx->rate_check_down = conf->rate_check_down;
-       memcpy(acx->rate_retry_policy, conf->rate_retry_policy,
-              sizeof(acx->rate_retry_policy));
-
-       ret = wl1271_cmd_configure(wl, ACX_SET_RATE_MGMT_PARAMS,
-                                  acx, sizeof(*acx));
-       if (ret < 0) {
-               wl1271_warning("acx set rate mgmt params failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-}
-
-int wl12xx_acx_config_hangover(struct wl1271 *wl)
-{
-       struct wl12xx_acx_config_hangover *acx;
-       struct conf_hangover_settings *conf = &wl->conf.hangover;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "acx config hangover");
-
-       acx = kzalloc(sizeof(*acx), GFP_KERNEL);
-       if (!acx) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       acx->recover_time = cpu_to_le32(conf->recover_time);
-       acx->hangover_period = conf->hangover_period;
-       acx->dynamic_mode = conf->dynamic_mode;
-       acx->early_termination_mode = conf->early_termination_mode;
-       acx->max_period = conf->max_period;
-       acx->min_period = conf->min_period;
-       acx->increase_delta = conf->increase_delta;
-       acx->decrease_delta = conf->decrease_delta;
-       acx->quiet_time = conf->quiet_time;
-       acx->increase_time = conf->increase_time;
-       acx->window_size = acx->window_size;
-
-       ret = wl1271_cmd_configure(wl, ACX_CONFIG_HANGOVER, acx,
-                                  sizeof(*acx));
-
-       if (ret < 0) {
-               wl1271_warning("acx config hangover failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(acx);
-       return ret;
-
-}
diff --git a/drivers/net/wireless/wl12xx/acx.h b/drivers/net/wireless/wl12xx/acx.h
deleted file mode 100644 (file)
index a28fc04..0000000
+++ /dev/null
@@ -1,1314 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
- * Copyright (C) 2008-2010 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __ACX_H__
-#define __ACX_H__
-
-#include "wl12xx.h"
-#include "cmd.h"
-
-/*************************************************************************
-
-    Host Interrupt Register (WiLink -> Host)
-
-**************************************************************************/
-/* HW Initiated interrupt Watchdog timer expiration */
-#define WL1271_ACX_INTR_WATCHDOG           BIT(0)
-/* Init sequence is done (masked interrupt, detection through polling only ) */
-#define WL1271_ACX_INTR_INIT_COMPLETE      BIT(1)
-/* Event was entered to Event MBOX #A*/
-#define WL1271_ACX_INTR_EVENT_A            BIT(2)
-/* Event was entered to Event MBOX #B*/
-#define WL1271_ACX_INTR_EVENT_B            BIT(3)
-/* Command processing completion*/
-#define WL1271_ACX_INTR_CMD_COMPLETE       BIT(4)
-/* Signaling the host on HW wakeup */
-#define WL1271_ACX_INTR_HW_AVAILABLE       BIT(5)
-/* The MISC bit is used for aggregation of RX, TxComplete and TX rate update */
-#define WL1271_ACX_INTR_DATA               BIT(6)
-/* Trace message on MBOX #A */
-#define WL1271_ACX_INTR_TRACE_A            BIT(7)
-/* Trace message on MBOX #B */
-#define WL1271_ACX_INTR_TRACE_B            BIT(8)
-
-#define WL1271_ACX_INTR_ALL               0xFFFFFFFF
-#define WL1271_ACX_ALL_EVENTS_VECTOR       (WL1271_ACX_INTR_WATCHDOG      | \
-                                           WL1271_ACX_INTR_INIT_COMPLETE | \
-                                           WL1271_ACX_INTR_EVENT_A       | \
-                                           WL1271_ACX_INTR_EVENT_B       | \
-                                           WL1271_ACX_INTR_CMD_COMPLETE  | \
-                                           WL1271_ACX_INTR_HW_AVAILABLE  | \
-                                           WL1271_ACX_INTR_DATA)
-
-#define WL1271_INTR_MASK                   (WL1271_ACX_INTR_WATCHDOG     | \
-                                           WL1271_ACX_INTR_EVENT_A      | \
-                                           WL1271_ACX_INTR_EVENT_B      | \
-                                           WL1271_ACX_INTR_HW_AVAILABLE | \
-                                           WL1271_ACX_INTR_DATA)
-
-/* Target's information element */
-struct acx_header {
-       struct wl1271_cmd_header cmd;
-
-       /* acx (or information element) header */
-       __le16 id;
-
-       /* payload length (not including headers */
-       __le16 len;
-} __packed;
-
-struct acx_error_counter {
-       struct acx_header header;
-
-       /* The number of PLCP errors since the last time this */
-       /* information element was interrogated. This field is */
-       /* automatically cleared when it is interrogated.*/
-       __le32 PLCP_error;
-
-       /* The number of FCS errors since the last time this */
-       /* information element was interrogated. This field is */
-       /* automatically cleared when it is interrogated.*/
-       __le32 FCS_error;
-
-       /* The number of MPDUs without PLCP header errors received*/
-       /* since the last time this information element was interrogated. */
-       /* This field is automatically cleared when it is interrogated.*/
-       __le32 valid_frame;
-
-       /* the number of missed sequence numbers in the squentially */
-       /* values of frames seq numbers */
-       __le32 seq_num_miss;
-} __packed;
-
-enum wl12xx_role {
-       WL1271_ROLE_STA = 0,
-       WL1271_ROLE_IBSS,
-       WL1271_ROLE_AP,
-       WL1271_ROLE_DEVICE,
-       WL1271_ROLE_P2P_CL,
-       WL1271_ROLE_P2P_GO,
-
-       WL12XX_INVALID_ROLE_TYPE = 0xff
-};
-
-enum wl1271_psm_mode {
-       /* Active mode */
-       WL1271_PSM_CAM = 0,
-
-       /* Power save mode */
-       WL1271_PSM_PS = 1,
-
-       /* Extreme low power */
-       WL1271_PSM_ELP = 2,
-};
-
-struct acx_sleep_auth {
-       struct acx_header header;
-
-       /* The sleep level authorization of the device. */
-       /* 0 - Always active*/
-       /* 1 - Power down mode: light / fast sleep*/
-       /* 2 - ELP mode: Deep / Max sleep*/
-       u8  sleep_auth;
-       u8  padding[3];
-} __packed;
-
-enum {
-       HOSTIF_PCI_MASTER_HOST_INDIRECT,
-       HOSTIF_PCI_MASTER_HOST_DIRECT,
-       HOSTIF_SLAVE,
-       HOSTIF_PKT_RING,
-       HOSTIF_DONTCARE = 0xFF
-};
-
-#define DEFAULT_UCAST_PRIORITY          0
-#define DEFAULT_RX_Q_PRIORITY           0
-#define DEFAULT_RXQ_PRIORITY            0 /* low 0 .. 15 high  */
-#define DEFAULT_RXQ_TYPE                0x07    /* All frames, Data/Ctrl/Mgmt */
-#define TRACE_BUFFER_MAX_SIZE           256
-
-#define  DP_RX_PACKET_RING_CHUNK_SIZE 1600
-#define  DP_TX_PACKET_RING_CHUNK_SIZE 1600
-#define  DP_RX_PACKET_RING_CHUNK_NUM 2
-#define  DP_TX_PACKET_RING_CHUNK_NUM 2
-#define  DP_TX_COMPLETE_TIME_OUT 20
-
-#define TX_MSDU_LIFETIME_MIN       0
-#define TX_MSDU_LIFETIME_MAX       3000
-#define TX_MSDU_LIFETIME_DEF       512
-#define RX_MSDU_LIFETIME_MIN       0
-#define RX_MSDU_LIFETIME_MAX       0xFFFFFFFF
-#define RX_MSDU_LIFETIME_DEF       512000
-
-struct acx_rx_msdu_lifetime {
-       struct acx_header header;
-
-       /*
-        * The maximum amount of time, in TU, before the
-        * firmware discards the MSDU.
-        */
-       __le32 lifetime;
-} __packed;
-
-enum acx_slot_type {
-       SLOT_TIME_LONG = 0,
-       SLOT_TIME_SHORT = 1,
-       DEFAULT_SLOT_TIME = SLOT_TIME_SHORT,
-       MAX_SLOT_TIMES = 0xFF
-};
-
-#define STATION_WONE_INDEX 0
-
-struct acx_slot {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 wone_index; /* Reserved */
-       u8 slot_time;
-       u8 reserved[5];
-} __packed;
-
-
-#define ACX_MC_ADDRESS_GROUP_MAX       (8)
-#define ADDRESS_GROUP_MAX_LEN          (ETH_ALEN * ACX_MC_ADDRESS_GROUP_MAX)
-
-struct acx_dot11_grp_addr_tbl {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 enabled;
-       u8 num_groups;
-       u8 pad[1];
-       u8 mac_table[ADDRESS_GROUP_MAX_LEN];
-} __packed;
-
-struct acx_rx_timeout {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 reserved;
-       __le16 ps_poll_timeout;
-       __le16 upsd_timeout;
-       u8 padding[2];
-} __packed;
-
-struct acx_rts_threshold {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 reserved;
-       __le16 threshold;
-} __packed;
-
-struct acx_beacon_filter_option {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 enable;
-       /*
-        * The number of beacons without the unicast TIM
-        * bit set that the firmware buffers before
-        * signaling the host about ready frames.
-        * When set to 0 and the filter is enabled, beacons
-        * without the unicast TIM bit set are dropped.
-        */
-       u8 max_num_beacons;
-       u8 pad[1];
-} __packed;
-
-/*
- * ACXBeaconFilterEntry (not 221)
- * Byte Offset     Size (Bytes)    Definition
- * ===========     ============    ==========
- * 0               1               IE identifier
- * 1               1               Treatment bit mask
- *
- * ACXBeaconFilterEntry (221)
- * Byte Offset     Size (Bytes)    Definition
- * ===========     ============    ==========
- * 0               1               IE identifier
- * 1               1               Treatment bit mask
- * 2               3               OUI
- * 5               1               Type
- * 6               2               Version
- *
- *
- * Treatment bit mask - The information element handling:
- * bit 0 - The information element is compared and transferred
- * in case of change.
- * bit 1 - The information element is transferred to the host
- * with each appearance or disappearance.
- * Note that both bits can be set at the same time.
- */
-#define        BEACON_FILTER_TABLE_MAX_IE_NUM                 (32)
-#define BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM (6)
-#define BEACON_FILTER_TABLE_IE_ENTRY_SIZE             (2)
-#define BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE (6)
-#define BEACON_FILTER_TABLE_MAX_SIZE ((BEACON_FILTER_TABLE_MAX_IE_NUM * \
-                           BEACON_FILTER_TABLE_IE_ENTRY_SIZE) + \
-                          (BEACON_FILTER_TABLE_MAX_VENDOR_SPECIFIC_IE_NUM * \
-                           BEACON_FILTER_TABLE_EXTRA_VENDOR_SPECIFIC_IE_SIZE))
-
-struct acx_beacon_filter_ie_table {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 num_ie;
-       u8 pad[2];
-       u8 table[BEACON_FILTER_TABLE_MAX_SIZE];
-} __packed;
-
-struct acx_conn_monit_params {
-       struct acx_header header;
-
-          u8 role_id;
-          u8 padding[3];
-       __le32 synch_fail_thold; /* number of beacons missed */
-       __le32 bss_lose_timeout; /* number of TU's from synch fail */
-} __packed;
-
-struct acx_bt_wlan_coex {
-       struct acx_header header;
-
-       u8 enable;
-       u8 pad[3];
-} __packed;
-
-struct acx_bt_wlan_coex_param {
-       struct acx_header header;
-
-       __le32 params[CONF_SG_PARAMS_MAX];
-       u8 param_idx;
-       u8 padding[3];
-} __packed;
-
-struct acx_dco_itrim_params {
-       struct acx_header header;
-
-       u8 enable;
-       u8 padding[3];
-       __le32 timeout;
-} __packed;
-
-struct acx_energy_detection {
-       struct acx_header header;
-
-       /* The RX Clear Channel Assessment threshold in the PHY */
-       __le16 rx_cca_threshold;
-       u8 tx_energy_detection;
-       u8 pad;
-} __packed;
-
-struct acx_beacon_broadcast {
-       struct acx_header header;
-
-       u8 role_id;
-       /* Enables receiving of broadcast packets in PS mode */
-       u8 rx_broadcast_in_ps;
-
-       __le16 beacon_rx_timeout;
-       __le16 broadcast_timeout;
-
-       /* Consecutive PS Poll failures before updating the host */
-       u8 ps_poll_threshold;
-       u8 pad[1];
-} __packed;
-
-struct acx_event_mask {
-       struct acx_header header;
-
-       __le32 event_mask;
-       __le32 high_event_mask; /* Unused */
-} __packed;
-
-#define SCAN_PASSIVE           BIT(0)
-#define SCAN_5GHZ_BAND         BIT(1)
-#define SCAN_TRIGGERED         BIT(2)
-#define SCAN_PRIORITY_HIGH     BIT(3)
-
-/* When set, disable HW encryption */
-#define DF_ENCRYPTION_DISABLE      0x01
-#define DF_SNIFF_MODE_ENABLE       0x80
-
-struct acx_feature_config {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 padding[3];
-       __le32 options;
-       __le32 data_flow_options;
-} __packed;
-
-struct acx_current_tx_power {
-       struct acx_header header;
-
-       u8  role_id;
-       u8  current_tx_power;
-       u8  padding[2];
-} __packed;
-
-struct acx_wake_up_condition {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 wake_up_event; /* Only one bit can be set */
-       u8 listen_interval;
-       u8 pad[1];
-} __packed;
-
-struct acx_aid {
-       struct acx_header header;
-
-       /*
-        * To be set when associated with an AP.
-        */
-       u8 role_id;
-       u8 reserved;
-       __le16 aid;
-} __packed;
-
-enum acx_preamble_type {
-       ACX_PREAMBLE_LONG = 0,
-       ACX_PREAMBLE_SHORT = 1
-};
-
-struct acx_preamble {
-       struct acx_header header;
-
-       /*
-        * When set, the WiLink transmits the frames with a short preamble and
-        * when cleared, the WiLink transmits the frames with a long preamble.
-        */
-       u8 role_id;
-       u8 preamble;
-       u8 padding[2];
-} __packed;
-
-enum acx_ctsprotect_type {
-       CTSPROTECT_DISABLE = 0,
-       CTSPROTECT_ENABLE = 1
-};
-
-struct acx_ctsprotect {
-       struct acx_header header;
-       u8 role_id;
-       u8 ctsprotect;
-       u8 padding[2];
-} __packed;
-
-struct acx_tx_statistics {
-       __le32 internal_desc_overflow;
-}  __packed;
-
-struct acx_rx_statistics {
-       __le32 out_of_mem;
-       __le32 hdr_overflow;
-       __le32 hw_stuck;
-       __le32 dropped;
-       __le32 fcs_err;
-       __le32 xfr_hint_trig;
-       __le32 path_reset;
-       __le32 reset_counter;
-} __packed;
-
-struct acx_dma_statistics {
-       __le32 rx_requested;
-       __le32 rx_errors;
-       __le32 tx_requested;
-       __le32 tx_errors;
-}  __packed;
-
-struct acx_isr_statistics {
-       /* host command complete */
-       __le32 cmd_cmplt;
-
-       /* fiqisr() */
-       __le32 fiqs;
-
-       /* (INT_STS_ND & INT_TRIG_RX_HEADER) */
-       __le32 rx_headers;
-
-       /* (INT_STS_ND & INT_TRIG_RX_CMPLT) */
-       __le32 rx_completes;
-
-       /* (INT_STS_ND & INT_TRIG_NO_RX_BUF) */
-       __le32 rx_mem_overflow;
-
-       /* (INT_STS_ND & INT_TRIG_S_RX_RDY) */
-       __le32 rx_rdys;
-
-       /* irqisr() */
-       __le32 irqs;
-
-       /* (INT_STS_ND & INT_TRIG_TX_PROC) */
-       __le32 tx_procs;
-
-       /* (INT_STS_ND & INT_TRIG_DECRYPT_DONE) */
-       __le32 decrypt_done;
-
-       /* (INT_STS_ND & INT_TRIG_DMA0) */
-       __le32 dma0_done;
-
-       /* (INT_STS_ND & INT_TRIG_DMA1) */
-       __le32 dma1_done;
-
-       /* (INT_STS_ND & INT_TRIG_TX_EXC_CMPLT) */
-       __le32 tx_exch_complete;
-
-       /* (INT_STS_ND & INT_TRIG_COMMAND) */
-       __le32 commands;
-
-       /* (INT_STS_ND & INT_TRIG_RX_PROC) */
-       __le32 rx_procs;
-
-       /* (INT_STS_ND & INT_TRIG_PM_802) */
-       __le32 hw_pm_mode_changes;
-
-       /* (INT_STS_ND & INT_TRIG_ACKNOWLEDGE) */
-       __le32 host_acknowledges;
-
-       /* (INT_STS_ND & INT_TRIG_PM_PCI) */
-       __le32 pci_pm;
-
-       /* (INT_STS_ND & INT_TRIG_ACM_WAKEUP) */
-       __le32 wakeups;
-
-       /* (INT_STS_ND & INT_TRIG_LOW_RSSI) */
-       __le32 low_rssi;
-} __packed;
-
-struct acx_wep_statistics {
-       /* WEP address keys configured */
-       __le32 addr_key_count;
-
-       /* default keys configured */
-       __le32 default_key_count;
-
-       __le32 reserved;
-
-       /* number of times that WEP key not found on lookup */
-       __le32 key_not_found;
-
-       /* number of times that WEP key decryption failed */
-       __le32 decrypt_fail;
-
-       /* WEP packets decrypted */
-       __le32 packets;
-
-       /* WEP decrypt interrupts */
-       __le32 interrupt;
-} __packed;
-
-#define ACX_MISSED_BEACONS_SPREAD 10
-
-struct acx_pwr_statistics {
-       /* the amount of enters into power save mode (both PD & ELP) */
-       __le32 ps_enter;
-
-       /* the amount of enters into ELP mode */
-       __le32 elp_enter;
-
-       /* the amount of missing beacon interrupts to the host */
-       __le32 missing_bcns;
-
-       /* the amount of wake on host-access times */
-       __le32 wake_on_host;
-
-       /* the amount of wake on timer-expire */
-       __le32 wake_on_timer_exp;
-
-       /* the number of packets that were transmitted with PS bit set */
-       __le32 tx_with_ps;
-
-       /* the number of packets that were transmitted with PS bit clear */
-       __le32 tx_without_ps;
-
-       /* the number of received beacons */
-       __le32 rcvd_beacons;
-
-       /* the number of entering into PowerOn (power save off) */
-       __le32 power_save_off;
-
-       /* the number of entries into power save mode */
-       __le16 enable_ps;
-
-       /*
-        * the number of exits from power save, not including failed PS
-        * transitions
-        */
-       __le16 disable_ps;
-
-       /*
-        * the number of times the TSF counter was adjusted because
-        * of drift
-        */
-       __le32 fix_tsf_ps;
-
-       /* Gives statistics about the spread continuous missed beacons.
-        * The 16 LSB are dedicated for the PS mode.
-        * The 16 MSB are dedicated for the PS mode.
-        * cont_miss_bcns_spread[0] - single missed beacon.
-        * cont_miss_bcns_spread[1] - two continuous missed beacons.
-        * cont_miss_bcns_spread[2] - three continuous missed beacons.
-        * ...
-        * cont_miss_bcns_spread[9] - ten and more continuous missed beacons.
-       */
-       __le32 cont_miss_bcns_spread[ACX_MISSED_BEACONS_SPREAD];
-
-       /* the number of beacons in awake mode */
-       __le32 rcvd_awake_beacons;
-} __packed;
-
-struct acx_mic_statistics {
-       __le32 rx_pkts;
-       __le32 calc_failure;
-} __packed;
-
-struct acx_aes_statistics {
-       __le32 encrypt_fail;
-       __le32 decrypt_fail;
-       __le32 encrypt_packets;
-       __le32 decrypt_packets;
-       __le32 encrypt_interrupt;
-       __le32 decrypt_interrupt;
-} __packed;
-
-struct acx_event_statistics {
-       __le32 heart_beat;
-       __le32 calibration;
-       __le32 rx_mismatch;
-       __le32 rx_mem_empty;
-       __le32 rx_pool;
-       __le32 oom_late;
-       __le32 phy_transmit_error;
-       __le32 tx_stuck;
-} __packed;
-
-struct acx_ps_statistics {
-       __le32 pspoll_timeouts;
-       __le32 upsd_timeouts;
-       __le32 upsd_max_sptime;
-       __le32 upsd_max_apturn;
-       __le32 pspoll_max_apturn;
-       __le32 pspoll_utilization;
-       __le32 upsd_utilization;
-} __packed;
-
-struct acx_rxpipe_statistics {
-       __le32 rx_prep_beacon_drop;
-       __le32 descr_host_int_trig_rx_data;
-       __le32 beacon_buffer_thres_host_int_trig_rx_data;
-       __le32 missed_beacon_host_int_trig_rx_data;
-       __le32 tx_xfr_host_int_trig_rx_data;
-} __packed;
-
-struct acx_statistics {
-       struct acx_header header;
-
-       struct acx_tx_statistics tx;
-       struct acx_rx_statistics rx;
-       struct acx_dma_statistics dma;
-       struct acx_isr_statistics isr;
-       struct acx_wep_statistics wep;
-       struct acx_pwr_statistics pwr;
-       struct acx_aes_statistics aes;
-       struct acx_mic_statistics mic;
-       struct acx_event_statistics event;
-       struct acx_ps_statistics ps;
-       struct acx_rxpipe_statistics rxpipe;
-} __packed;
-
-struct acx_rate_class {
-       __le32 enabled_rates;
-       u8 short_retry_limit;
-       u8 long_retry_limit;
-       u8 aflags;
-       u8 reserved;
-};
-
-struct acx_rate_policy {
-       struct acx_header header;
-
-       __le32 rate_policy_idx;
-       struct acx_rate_class rate_policy;
-} __packed;
-
-struct acx_ac_cfg {
-       struct acx_header header;
-       u8 role_id;
-       u8 ac;
-       u8 aifsn;
-       u8 cw_min;
-       __le16 cw_max;
-       __le16 tx_op_limit;
-} __packed;
-
-struct acx_tid_config {
-       struct acx_header header;
-       u8 role_id;
-       u8 queue_id;
-       u8 channel_type;
-       u8 tsid;
-       u8 ps_scheme;
-       u8 ack_policy;
-       u8 padding[2];
-       __le32 apsd_conf[2];
-} __packed;
-
-struct acx_frag_threshold {
-       struct acx_header header;
-       __le16 frag_threshold;
-       u8 padding[2];
-} __packed;
-
-struct acx_tx_config_options {
-       struct acx_header header;
-       __le16 tx_compl_timeout;     /* msec */
-       __le16 tx_compl_threshold;   /* number of packets */
-} __packed;
-
-struct wl12xx_acx_config_memory {
-       struct acx_header header;
-
-       u8 rx_mem_block_num;
-       u8 tx_min_mem_block_num;
-       u8 num_stations;
-       u8 num_ssid_profiles;
-       __le32 total_tx_descriptors;
-       u8 dyn_mem_enable;
-       u8 tx_free_req;
-       u8 rx_free_req;
-       u8 tx_min;
-       u8 fwlog_blocks;
-       u8 padding[3];
-} __packed;
-
-struct wl1271_acx_mem_map {
-       struct acx_header header;
-
-       __le32 code_start;
-       __le32 code_end;
-
-       __le32 wep_defkey_start;
-       __le32 wep_defkey_end;
-
-       __le32 sta_table_start;
-       __le32 sta_table_end;
-
-       __le32 packet_template_start;
-       __le32 packet_template_end;
-
-       /* Address of the TX result interface (control block) */
-       __le32 tx_result;
-       __le32 tx_result_queue_start;
-
-       __le32 queue_memory_start;
-       __le32 queue_memory_end;
-
-       __le32 packet_memory_pool_start;
-       __le32 packet_memory_pool_end;
-
-       __le32 debug_buffer1_start;
-       __le32 debug_buffer1_end;
-
-       __le32 debug_buffer2_start;
-       __le32 debug_buffer2_end;
-
-       /* Number of blocks FW allocated for TX packets */
-       __le32 num_tx_mem_blocks;
-
-       /* Number of blocks FW allocated for RX packets */
-       __le32 num_rx_mem_blocks;
-
-       /* the following 4 fields are valid in SLAVE mode only */
-       u8 *tx_cbuf;
-       u8 *rx_cbuf;
-       __le32 rx_ctrl;
-       __le32 tx_ctrl;
-} __packed;
-
-struct wl1271_acx_rx_config_opt {
-       struct acx_header header;
-
-       __le16 mblk_threshold;
-       __le16 threshold;
-       __le16 timeout;
-       u8 queue_type;
-       u8 reserved;
-} __packed;
-
-
-struct wl1271_acx_bet_enable {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 enable;
-       u8 max_consecutive;
-       u8 padding[1];
-} __packed;
-
-#define ACX_IPV4_VERSION 4
-#define ACX_IPV6_VERSION 6
-#define ACX_IPV4_ADDR_SIZE 4
-
-/* bitmap of enabled arp_filter features */
-#define ACX_ARP_FILTER_ARP_FILTERING   BIT(0)
-#define ACX_ARP_FILTER_AUTO_ARP                BIT(1)
-
-struct wl1271_acx_arp_filter {
-       struct acx_header header;
-       u8 role_id;
-       u8 version;         /* ACX_IPV4_VERSION, ACX_IPV6_VERSION */
-       u8 enable;          /* bitmap of enabled ARP filtering features */
-       u8 padding[1];
-       u8 address[16];     /* The configured device IP address - all ARP
-                              requests directed to this IP address will pass
-                              through. For IPv4, the first four bytes are
-                              used. */
-} __packed;
-
-struct wl1271_acx_pm_config {
-       struct acx_header header;
-
-       __le32 host_clk_settling_time;
-       u8 host_fast_wakeup_support;
-       u8 padding[3];
-} __packed;
-
-struct wl1271_acx_keep_alive_mode {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 enabled;
-       u8 padding[2];
-} __packed;
-
-enum {
-       ACX_KEEP_ALIVE_NO_TX = 0,
-       ACX_KEEP_ALIVE_PERIOD_ONLY
-};
-
-enum {
-       ACX_KEEP_ALIVE_TPL_INVALID = 0,
-       ACX_KEEP_ALIVE_TPL_VALID
-};
-
-struct wl1271_acx_keep_alive_config {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 index;
-       u8 tpl_validation;
-       u8 trigger;
-       __le32 period;
-} __packed;
-
-#define HOST_IF_CFG_RX_FIFO_ENABLE     BIT(0)
-#define HOST_IF_CFG_TX_EXTRA_BLKS_SWAP BIT(1)
-#define HOST_IF_CFG_TX_PAD_TO_SDIO_BLK BIT(3)
-
-struct wl1271_acx_host_config_bitmap {
-       struct acx_header header;
-
-       __le32 host_cfg_bitmap;
-} __packed;
-
-enum {
-       WL1271_ACX_TRIG_TYPE_LEVEL = 0,
-       WL1271_ACX_TRIG_TYPE_EDGE,
-};
-
-enum {
-       WL1271_ACX_TRIG_DIR_LOW = 0,
-       WL1271_ACX_TRIG_DIR_HIGH,
-       WL1271_ACX_TRIG_DIR_BIDIR,
-};
-
-enum {
-       WL1271_ACX_TRIG_ENABLE = 1,
-       WL1271_ACX_TRIG_DISABLE,
-};
-
-enum {
-       WL1271_ACX_TRIG_METRIC_RSSI_BEACON = 0,
-       WL1271_ACX_TRIG_METRIC_RSSI_DATA,
-       WL1271_ACX_TRIG_METRIC_SNR_BEACON,
-       WL1271_ACX_TRIG_METRIC_SNR_DATA,
-};
-
-enum {
-       WL1271_ACX_TRIG_IDX_RSSI = 0,
-       WL1271_ACX_TRIG_COUNT = 8,
-};
-
-struct wl1271_acx_rssi_snr_trigger {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 metric;
-       u8 type;
-       u8 dir;
-       __le16 threshold;
-       __le16 pacing; /* 0 - 60000 ms */
-       u8 hysteresis;
-       u8 index;
-       u8 enable;
-       u8 padding[1];
-};
-
-struct wl1271_acx_rssi_snr_avg_weights {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 padding[3];
-       u8 rssi_beacon;
-       u8 rssi_data;
-       u8 snr_beacon;
-       u8 snr_data;
-};
-
-
-/* special capability bit (not employed by the 802.11n spec) */
-#define WL12XX_HT_CAP_HT_OPERATION BIT(16)
-
-/*
- * ACX_PEER_HT_CAP
- * Configure HT capabilities - declare the capabilities of the peer
- * we are connected to.
- */
-struct wl1271_acx_ht_capabilities {
-       struct acx_header header;
-
-       /* bitmask of capability bits supported by the peer */
-       __le32 ht_capabilites;
-
-       /* Indicates to which link these capabilities apply. */
-       u8 hlid;
-
-       /*
-        * This the maximum A-MPDU length supported by the AP. The FW may not
-        * exceed this length when sending A-MPDUs
-        */
-       u8 ampdu_max_length;
-
-       /* This is the minimal spacing required when sending A-MPDUs to the AP*/
-       u8 ampdu_min_spacing;
-
-       u8 padding;
-} __packed;
-
-/*
- * ACX_HT_BSS_OPERATION
- * Configure HT capabilities - AP rules for behavior in the BSS.
- */
-struct wl1271_acx_ht_information {
-       struct acx_header header;
-
-       u8 role_id;
-
-       /* Values: 0 - RIFS not allowed, 1 - RIFS allowed */
-       u8 rifs_mode;
-
-       /* Values: 0 - 3 like in spec */
-       u8 ht_protection;
-
-       /* Values: 0 - GF protection not required, 1 - GF protection required */
-       u8 gf_protection;
-
-       /*Values: 0 - TX Burst limit not required, 1 - TX Burst Limit required*/
-       u8 ht_tx_burst_limit;
-
-       /*
-        * Values: 0 - Dual CTS protection not required,
-        *         1 - Dual CTS Protection required
-        * Note: When this value is set to 1 FW will protect all TXOP with RTS
-        * frame and will not use CTS-to-self regardless of the value of the
-        * ACX_CTS_PROTECTION information element
-        */
-       u8 dual_cts_protection;
-
-       u8 padding[2];
-} __packed;
-
-#define RX_BA_MAX_SESSIONS 2
-
-struct wl1271_acx_ba_initiator_policy {
-       struct acx_header header;
-
-       /* Specifies role Id, Range 0-7, 0xFF means ANY role. */
-       u8 role_id;
-
-       /*
-        * Per TID setting for allowing TX BA. Set a bit to 1 to allow
-        * TX BA sessions for the corresponding TID.
-        */
-       u8 tid_bitmap;
-
-       /* Windows size in number of packets */
-       u8 win_size;
-
-       u8 padding1[1];
-
-       /* As initiator inactivity timeout in time units(TU) of 1024us */
-       u16 inactivity_timeout;
-
-       u8 padding[2];
-} __packed;
-
-struct wl1271_acx_ba_receiver_setup {
-       struct acx_header header;
-
-       /* Specifies link id, range 0-31 */
-       u8 hlid;
-
-       u8 tid;
-
-       u8 enable;
-
-       /* Windows size in number of packets */
-       u8 win_size;
-
-       /* BA session starting sequence number.  RANGE 0-FFF */
-       u16 ssn;
-
-       u8 padding[2];
-} __packed;
-
-struct wl12xx_acx_fw_tsf_information {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 padding1[3];
-       __le32 current_tsf_high;
-       __le32 current_tsf_low;
-       __le32 last_bttt_high;
-       __le32 last_tbtt_low;
-       u8 last_dtim_count;
-       u8 padding2[3];
-} __packed;
-
-struct wl1271_acx_ps_rx_streaming {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 tid;
-       u8 enable;
-
-       /* interval between triggers (10-100 msec) */
-       u8 period;
-
-       /* timeout before first trigger (0-200 msec) */
-       u8 timeout;
-       u8 padding[3];
-} __packed;
-
-struct wl1271_acx_ap_max_tx_retry {
-       struct acx_header header;
-
-       u8 role_id;
-       u8 padding_1;
-
-       /*
-        * the number of frames transmission failures before
-        * issuing the aging event.
-        */
-       __le16 max_tx_retry;
-} __packed;
-
-struct wl1271_acx_config_ps {
-       struct acx_header header;
-
-       u8 exit_retries;
-       u8 enter_retries;
-       u8 padding[2];
-       __le32 null_data_rate;
-} __packed;
-
-struct wl1271_acx_inconnection_sta {
-       struct acx_header header;
-
-       u8 addr[ETH_ALEN];
-       u8 padding1[2];
-} __packed;
-
-/*
- * ACX_FM_COEX_CFG
- * set the FM co-existence parameters.
- */
-struct wl1271_acx_fm_coex {
-       struct acx_header header;
-       /* enable(1) / disable(0) the FM Coex feature */
-       u8 enable;
-       /*
-        * Swallow period used in COEX PLL swallowing mechanism.
-        * 0xFF = use FW default
-        */
-       u8 swallow_period;
-       /*
-        * The N divider used in COEX PLL swallowing mechanism for Fref of
-        * 38.4/19.2 Mhz. 0xFF = use FW default
-        */
-       u8 n_divider_fref_set_1;
-       /*
-        * The N divider used in COEX PLL swallowing mechanism for Fref of
-        * 26/52 Mhz. 0xFF = use FW default
-        */
-       u8 n_divider_fref_set_2;
-       /*
-        * The M divider used in COEX PLL swallowing mechanism for Fref of
-        * 38.4/19.2 Mhz. 0xFFFF = use FW default
-        */
-       __le16 m_divider_fref_set_1;
-       /*
-        * The M divider used in COEX PLL swallowing mechanism for Fref of
-        * 26/52 Mhz. 0xFFFF = use FW default
-        */
-       __le16 m_divider_fref_set_2;
-       /*
-        * The time duration in uSec required for COEX PLL to stabilize.
-        * 0xFFFFFFFF = use FW default
-        */
-       __le32 coex_pll_stabilization_time;
-       /*
-        * The time duration in uSec required for LDO to stabilize.
-        * 0xFFFFFFFF = use FW default
-        */
-       __le16 ldo_stabilization_time;
-       /*
-        * The disturbed frequency band margin around the disturbed frequency
-        * center (single sided).
-        * For example, if 2 is configured, the following channels will be
-        * considered disturbed channel:
-        *   80 +- 0.1 MHz, 91 +- 0.1 MHz, 98 +- 0.1 MHz, 102 +- 0.1 MH
-        * 0xFF = use FW default
-        */
-       u8 fm_disturbed_band_margin;
-       /*
-        * The swallow clock difference of the swallowing mechanism.
-        * 0xFF = use FW default
-        */
-       u8 swallow_clk_diff;
-} __packed;
-
-#define ACX_RATE_MGMT_ALL_PARAMS 0xff
-struct wl12xx_acx_set_rate_mgmt_params {
-       struct acx_header header;
-
-       u8 index; /* 0xff to configure all params */
-       u8 padding1;
-       __le16 rate_retry_score;
-       __le16 per_add;
-       __le16 per_th1;
-       __le16 per_th2;
-       __le16 max_per;
-       u8 inverse_curiosity_factor;
-       u8 tx_fail_low_th;
-       u8 tx_fail_high_th;
-       u8 per_alpha_shift;
-       u8 per_add_shift;
-       u8 per_beta1_shift;
-       u8 per_beta2_shift;
-       u8 rate_check_up;
-       u8 rate_check_down;
-       u8 rate_retry_policy[ACX_RATE_MGMT_NUM_OF_RATES];
-       u8 padding2[2];
-} __packed;
-
-struct wl12xx_acx_config_hangover {
-       struct acx_header header;
-
-       __le32 recover_time;
-       u8 hangover_period;
-       u8 dynamic_mode;
-       u8 early_termination_mode;
-       u8 max_period;
-       u8 min_period;
-       u8 increase_delta;
-       u8 decrease_delta;
-       u8 quiet_time;
-       u8 increase_time;
-       u8 window_size;
-       u8 padding[2];
-} __packed;
-
-enum {
-       ACX_WAKE_UP_CONDITIONS           = 0x0000,
-       ACX_MEM_CFG                      = 0x0001,
-       ACX_SLOT                         = 0x0002,
-       ACX_AC_CFG                       = 0x0003,
-       ACX_MEM_MAP                      = 0x0004,
-       ACX_AID                          = 0x0005,
-       ACX_MEDIUM_USAGE                 = 0x0006,
-       ACX_STATISTICS                   = 0x0007,
-       ACX_PWR_CONSUMPTION_STATISTICS   = 0x0008,
-       ACX_TID_CFG                      = 0x0009,
-       ACX_PS_RX_STREAMING              = 0x000A,
-       ACX_BEACON_FILTER_OPT            = 0x000B,
-       ACX_NOISE_HIST                   = 0x000C,
-       ACX_HDK_VERSION                  = 0x000D,
-       ACX_PD_THRESHOLD                 = 0x000E,
-       ACX_TX_CONFIG_OPT                = 0x000F,
-       ACX_CCA_THRESHOLD                = 0x0010,
-       ACX_EVENT_MBOX_MASK              = 0x0011,
-       ACX_CONN_MONIT_PARAMS            = 0x0012,
-       ACX_DISABLE_BROADCASTS           = 0x0013,
-       ACX_BCN_DTIM_OPTIONS             = 0x0014,
-       ACX_SG_ENABLE                    = 0x0015,
-       ACX_SG_CFG                       = 0x0016,
-       ACX_FM_COEX_CFG                  = 0x0017,
-       ACX_BEACON_FILTER_TABLE          = 0x0018,
-       ACX_ARP_IP_FILTER                = 0x0019,
-       ACX_ROAMING_STATISTICS_TBL       = 0x001A,
-       ACX_RATE_POLICY                  = 0x001B,
-       ACX_CTS_PROTECTION               = 0x001C,
-       ACX_SLEEP_AUTH                   = 0x001D,
-       ACX_PREAMBLE_TYPE                = 0x001E,
-       ACX_ERROR_CNT                    = 0x001F,
-       ACX_IBSS_FILTER                  = 0x0020,
-       ACX_SERVICE_PERIOD_TIMEOUT       = 0x0021,
-       ACX_TSF_INFO                     = 0x0022,
-       ACX_CONFIG_PS_WMM                = 0x0023,
-       ACX_ENABLE_RX_DATA_FILTER        = 0x0024,
-       ACX_SET_RX_DATA_FILTER           = 0x0025,
-       ACX_GET_DATA_FILTER_STATISTICS   = 0x0026,
-       ACX_RX_CONFIG_OPT                = 0x0027,
-       ACX_FRAG_CFG                     = 0x0028,
-       ACX_BET_ENABLE                   = 0x0029,
-       ACX_RSSI_SNR_TRIGGER             = 0x002A,
-       ACX_RSSI_SNR_WEIGHTS             = 0x002B,
-       ACX_KEEP_ALIVE_MODE              = 0x002C,
-       ACX_SET_KEEP_ALIVE_CONFIG        = 0x002D,
-       ACX_BA_SESSION_INIT_POLICY       = 0x002E,
-       ACX_BA_SESSION_RX_SETUP          = 0x002F,
-       ACX_PEER_HT_CAP                  = 0x0030,
-       ACX_HT_BSS_OPERATION             = 0x0031,
-       ACX_COEX_ACTIVITY                = 0x0032,
-       ACX_BURST_MODE                   = 0x0033,
-       ACX_SET_RATE_MGMT_PARAMS         = 0x0034,
-       ACX_GET_RATE_MGMT_PARAMS         = 0x0035,
-       ACX_SET_RATE_ADAPT_PARAMS        = 0x0036,
-       ACX_SET_DCO_ITRIM_PARAMS         = 0x0037,
-       ACX_GEN_FW_CMD                   = 0x0038,
-       ACX_HOST_IF_CFG_BITMAP           = 0x0039,
-       ACX_MAX_TX_FAILURE               = 0x003A,
-       ACX_UPDATE_INCONNECTION_STA_LIST = 0x003B,
-       DOT11_RX_MSDU_LIFE_TIME          = 0x003C,
-       DOT11_CUR_TX_PWR                 = 0x003D,
-       DOT11_RTS_THRESHOLD              = 0x003E,
-       DOT11_GROUP_ADDRESS_TBL          = 0x003F,
-       ACX_PM_CONFIG                    = 0x0040,
-       ACX_CONFIG_PS                    = 0x0041,
-       ACX_CONFIG_HANGOVER              = 0x0042,
-       ACX_FEATURE_CFG                  = 0x0043,
-       ACX_PROTECTION_CFG               = 0x0044,
-};
-
-
-int wl1271_acx_wake_up_conditions(struct wl1271 *wl,
-                                 struct wl12xx_vif *wlvif,
-                                 u8 wake_up_event, u8 listen_interval);
-int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth);
-int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                       int power);
-int wl1271_acx_feature_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl1271_acx_mem_map(struct wl1271 *wl,
-                      struct acx_header *mem_map, size_t len);
-int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl);
-int wl1271_acx_slot(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                   enum acx_slot_type slot_time);
-int wl1271_acx_group_address_tbl(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                                bool enable, void *mc_list, u32 mc_list_len);
-int wl1271_acx_service_period_timeout(struct wl1271 *wl,
-                                     struct wl12xx_vif *wlvif);
-int wl1271_acx_rts_threshold(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                            u32 rts_threshold);
-int wl1271_acx_dco_itrim_params(struct wl1271 *wl);
-int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                                bool enable_filter);
-int wl1271_acx_beacon_filter_table(struct wl1271 *wl,
-                                  struct wl12xx_vif *wlvif);
-int wl1271_acx_conn_monit_params(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                                bool enable);
-int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable);
-int wl12xx_acx_sg_cfg(struct wl1271 *wl);
-int wl1271_acx_cca_threshold(struct wl1271 *wl);
-int wl1271_acx_bcn_dtim_options(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl1271_acx_aid(struct wl1271 *wl, struct wl12xx_vif *wlvif, u16 aid);
-int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask);
-int wl1271_acx_set_preamble(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                           enum acx_preamble_type preamble);
-int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                          enum acx_ctsprotect_type ctsprotect);
-int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats);
-int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
-                     u8 idx);
-int wl1271_acx_ac_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                     u8 ac, u8 cw_min, u16 cw_max, u8 aifsn, u16 txop);
-int wl1271_acx_tid_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                      u8 queue_id, u8 channel_type,
-                      u8 tsid, u8 ps_scheme, u8 ack_policy,
-                      u32 apsd_conf0, u32 apsd_conf1);
-int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold);
-int wl1271_acx_tx_config_options(struct wl1271 *wl);
-int wl12xx_acx_mem_cfg(struct wl1271 *wl);
-int wl1271_acx_init_mem_config(struct wl1271 *wl);
-int wl1271_acx_host_if_cfg_bitmap(struct wl1271 *wl, u32 host_cfg_bitmap);
-int wl1271_acx_init_rx_interrupt(struct wl1271 *wl);
-int wl1271_acx_smart_reflex(struct wl1271 *wl);
-int wl1271_acx_bet_enable(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                         bool enable);
-int wl1271_acx_arp_ip_filter(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                            u8 enable, __be32 address);
-int wl1271_acx_pm_config(struct wl1271 *wl);
-int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *vif,
-                              bool enable);
-int wl1271_acx_keep_alive_config(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                                u8 index, u8 tpl_valid);
-int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                               bool enable, s16 thold, u8 hyst);
-int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl,
-                                   struct wl12xx_vif *wlvif);
-int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
-                                   struct ieee80211_sta_ht_cap *ht_cap,
-                                   bool allow_ht_operation, u8 hlid);
-int wl1271_acx_set_ht_information(struct wl1271 *wl,
-                                  struct wl12xx_vif *wlvif,
-                                  u16 ht_operation_mode);
-int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl,
-                                      struct wl12xx_vif *wlvif);
-int wl12xx_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index,
-                                      u16 ssn, bool enable, u8 peer_hlid);
-int wl12xx_acx_tsf_info(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                       u64 *mactime);
-int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                              bool enable);
-int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl12xx_acx_config_ps(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl1271_acx_set_inconnection_sta(struct wl1271 *wl, u8 *addr);
-int wl1271_acx_fm_coex(struct wl1271 *wl);
-int wl12xx_acx_set_rate_mgmt_params(struct wl1271 *wl);
-int wl12xx_acx_config_hangover(struct wl1271 *wl);
-
-#endif /* __WL1271_ACX_H__ */
diff --git a/drivers/net/wireless/wl12xx/boot.c b/drivers/net/wireless/wl12xx/boot.c
deleted file mode 100644 (file)
index 954101d..0000000
+++ /dev/null
@@ -1,786 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2008-2010 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/slab.h>
-#include <linux/wl12xx.h>
-#include <linux/export.h>
-
-#include "debug.h"
-#include "acx.h"
-#include "reg.h"
-#include "boot.h"
-#include "io.h"
-#include "event.h"
-#include "rx.h"
-
-static void wl1271_boot_set_ecpu_ctrl(struct wl1271 *wl, u32 flag)
-{
-       u32 cpu_ctrl;
-
-       /* 10.5.0 run the firmware (I) */
-       cpu_ctrl = wl1271_read32(wl, ACX_REG_ECPU_CONTROL);
-
-       /* 10.5.1 run the firmware (II) */
-       cpu_ctrl |= flag;
-       wl1271_write32(wl, ACX_REG_ECPU_CONTROL, cpu_ctrl);
-}
-
-static unsigned int wl12xx_get_fw_ver_quirks(struct wl1271 *wl)
-{
-       unsigned int quirks = 0;
-       unsigned int *fw_ver = wl->chip.fw_ver;
-
-       /* Only new station firmwares support routing fw logs to the host */
-       if ((fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_STA) &&
-           (fw_ver[FW_VER_MINOR] < FW_VER_MINOR_FWLOG_STA_MIN))
-               quirks |= WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED;
-
-       /* This feature is not yet supported for AP mode */
-       if (fw_ver[FW_VER_IF_TYPE] == FW_VER_IF_TYPE_AP)
-               quirks |= WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED;
-
-       return quirks;
-}
-
-static void wl1271_parse_fw_ver(struct wl1271 *wl)
-{
-       int ret;
-
-       ret = sscanf(wl->chip.fw_ver_str + 4, "%u.%u.%u.%u.%u",
-                    &wl->chip.fw_ver[0], &wl->chip.fw_ver[1],
-                    &wl->chip.fw_ver[2], &wl->chip.fw_ver[3],
-                    &wl->chip.fw_ver[4]);
-
-       if (ret != 5) {
-               wl1271_warning("fw version incorrect value");
-               memset(wl->chip.fw_ver, 0, sizeof(wl->chip.fw_ver));
-               return;
-       }
-
-       /* Check if any quirks are needed with older fw versions */
-       wl->quirks |= wl12xx_get_fw_ver_quirks(wl);
-}
-
-static void wl1271_boot_fw_version(struct wl1271 *wl)
-{
-       struct wl1271_static_data static_data;
-
-       wl1271_read(wl, wl->cmd_box_addr, &static_data, sizeof(static_data),
-                   false);
-
-       strncpy(wl->chip.fw_ver_str, static_data.fw_version,
-               sizeof(wl->chip.fw_ver_str));
-
-       /* make sure the string is NULL-terminated */
-       wl->chip.fw_ver_str[sizeof(wl->chip.fw_ver_str) - 1] = '\0';
-
-       wl1271_parse_fw_ver(wl);
-}
-
-static int wl1271_boot_upload_firmware_chunk(struct wl1271 *wl, void *buf,
-                                            size_t fw_data_len, u32 dest)
-{
-       struct wl1271_partition_set partition;
-       int addr, chunk_num, partition_limit;
-       u8 *p, *chunk;
-
-       /* whal_FwCtrl_LoadFwImageSm() */
-
-       wl1271_debug(DEBUG_BOOT, "starting firmware upload");
-
-       wl1271_debug(DEBUG_BOOT, "fw_data_len %zd chunk_size %d",
-                    fw_data_len, CHUNK_SIZE);
-
-       if ((fw_data_len % 4) != 0) {
-               wl1271_error("firmware length not multiple of four");
-               return -EIO;
-       }
-
-       chunk = kmalloc(CHUNK_SIZE, GFP_KERNEL);
-       if (!chunk) {
-               wl1271_error("allocation for firmware upload chunk failed");
-               return -ENOMEM;
-       }
-
-       memcpy(&partition, &wl12xx_part_table[PART_DOWN], sizeof(partition));
-       partition.mem.start = dest;
-       wl1271_set_partition(wl, &partition);
-
-       /* 10.1 set partition limit and chunk num */
-       chunk_num = 0;
-       partition_limit = wl12xx_part_table[PART_DOWN].mem.size;
-
-       while (chunk_num < fw_data_len / CHUNK_SIZE) {
-               /* 10.2 update partition, if needed */
-               addr = dest + (chunk_num + 2) * CHUNK_SIZE;
-               if (addr > partition_limit) {
-                       addr = dest + chunk_num * CHUNK_SIZE;
-                       partition_limit = chunk_num * CHUNK_SIZE +
-                               wl12xx_part_table[PART_DOWN].mem.size;
-                       partition.mem.start = addr;
-                       wl1271_set_partition(wl, &partition);
-               }
-
-               /* 10.3 upload the chunk */
-               addr = dest + chunk_num * CHUNK_SIZE;
-               p = buf + chunk_num * CHUNK_SIZE;
-               memcpy(chunk, p, CHUNK_SIZE);
-               wl1271_debug(DEBUG_BOOT, "uploading fw chunk 0x%p to 0x%x",
-                            p, addr);
-               wl1271_write(wl, addr, chunk, CHUNK_SIZE, false);
-
-               chunk_num++;
-       }
-
-       /* 10.4 upload the last chunk */
-       addr = dest + chunk_num * CHUNK_SIZE;
-       p = buf + chunk_num * CHUNK_SIZE;
-       memcpy(chunk, p, fw_data_len % CHUNK_SIZE);
-       wl1271_debug(DEBUG_BOOT, "uploading fw last chunk (%zd B) 0x%p to 0x%x",
-                    fw_data_len % CHUNK_SIZE, p, addr);
-       wl1271_write(wl, addr, chunk, fw_data_len % CHUNK_SIZE, false);
-
-       kfree(chunk);
-       return 0;
-}
-
-static int wl1271_boot_upload_firmware(struct wl1271 *wl)
-{
-       u32 chunks, addr, len;
-       int ret = 0;
-       u8 *fw;
-
-       fw = wl->fw;
-       chunks = be32_to_cpup((__be32 *) fw);
-       fw += sizeof(u32);
-
-       wl1271_debug(DEBUG_BOOT, "firmware chunks to be uploaded: %u", chunks);
-
-       while (chunks--) {
-               addr = be32_to_cpup((__be32 *) fw);
-               fw += sizeof(u32);
-               len = be32_to_cpup((__be32 *) fw);
-               fw += sizeof(u32);
-
-               if (len > 300000) {
-                       wl1271_info("firmware chunk too long: %u", len);
-                       return -EINVAL;
-               }
-               wl1271_debug(DEBUG_BOOT, "chunk %d addr 0x%x len %u",
-                            chunks, addr, len);
-               ret = wl1271_boot_upload_firmware_chunk(wl, fw, len, addr);
-               if (ret != 0)
-                       break;
-               fw += len;
-       }
-
-       return ret;
-}
-
-static int wl1271_boot_upload_nvs(struct wl1271 *wl)
-{
-       size_t nvs_len, burst_len;
-       int i;
-       u32 dest_addr, val;
-       u8 *nvs_ptr, *nvs_aligned;
-
-       if (wl->nvs == NULL)
-               return -ENODEV;
-
-       if (wl->chip.id == CHIP_ID_1283_PG20) {
-               struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
-
-               if (wl->nvs_len == sizeof(struct wl128x_nvs_file)) {
-                       if (nvs->general_params.dual_mode_select)
-                               wl->enable_11a = true;
-               } else {
-                       wl1271_error("nvs size is not as expected: %zu != %zu",
-                                    wl->nvs_len,
-                                    sizeof(struct wl128x_nvs_file));
-                       kfree(wl->nvs);
-                       wl->nvs = NULL;
-                       wl->nvs_len = 0;
-                       return -EILSEQ;
-               }
-
-               /* only the first part of the NVS needs to be uploaded */
-               nvs_len = sizeof(nvs->nvs);
-               nvs_ptr = (u8 *)nvs->nvs;
-
-       } else {
-               struct wl1271_nvs_file *nvs =
-                       (struct wl1271_nvs_file *)wl->nvs;
-               /*
-                * FIXME: the LEGACY NVS image support (NVS's missing the 5GHz
-                * band configurations) can be removed when those NVS files stop
-                * floating around.
-                */
-               if (wl->nvs_len == sizeof(struct wl1271_nvs_file) ||
-                   wl->nvs_len == WL1271_INI_LEGACY_NVS_FILE_SIZE) {
-                       if (nvs->general_params.dual_mode_select)
-                               wl->enable_11a = true;
-               }
-
-               if (wl->nvs_len != sizeof(struct wl1271_nvs_file) &&
-                   (wl->nvs_len != WL1271_INI_LEGACY_NVS_FILE_SIZE ||
-                    wl->enable_11a)) {
-                       wl1271_error("nvs size is not as expected: %zu != %zu",
-                               wl->nvs_len, sizeof(struct wl1271_nvs_file));
-                       kfree(wl->nvs);
-                       wl->nvs = NULL;
-                       wl->nvs_len = 0;
-                       return -EILSEQ;
-               }
-
-               /* only the first part of the NVS needs to be uploaded */
-               nvs_len = sizeof(nvs->nvs);
-               nvs_ptr = (u8 *) nvs->nvs;
-       }
-
-       /* update current MAC address to NVS */
-       nvs_ptr[11] = wl->addresses[0].addr[0];
-       nvs_ptr[10] = wl->addresses[0].addr[1];
-       nvs_ptr[6] = wl->addresses[0].addr[2];
-       nvs_ptr[5] = wl->addresses[0].addr[3];
-       nvs_ptr[4] = wl->addresses[0].addr[4];
-       nvs_ptr[3] = wl->addresses[0].addr[5];
-
-       /*
-        * Layout before the actual NVS tables:
-        * 1 byte : burst length.
-        * 2 bytes: destination address.
-        * n bytes: data to burst copy.
-        *
-        * This is ended by a 0 length, then the NVS tables.
-        */
-
-       /* FIXME: Do we need to check here whether the LSB is 1? */
-       while (nvs_ptr[0]) {
-               burst_len = nvs_ptr[0];
-               dest_addr = (nvs_ptr[1] & 0xfe) | ((u32)(nvs_ptr[2] << 8));
-
-               /*
-                * Due to our new wl1271_translate_reg_addr function,
-                * we need to add the REGISTER_BASE to the destination
-                */
-               dest_addr += REGISTERS_BASE;
-
-               /* We move our pointer to the data */
-               nvs_ptr += 3;
-
-               for (i = 0; i < burst_len; i++) {
-                       if (nvs_ptr + 3 >= (u8 *) wl->nvs + nvs_len)
-                               goto out_badnvs;
-
-                       val = (nvs_ptr[0] | (nvs_ptr[1] << 8)
-                              | (nvs_ptr[2] << 16) | (nvs_ptr[3] << 24));
-
-                       wl1271_debug(DEBUG_BOOT,
-                                    "nvs burst write 0x%x: 0x%x",
-                                    dest_addr, val);
-                       wl1271_write32(wl, dest_addr, val);
-
-                       nvs_ptr += 4;
-                       dest_addr += 4;
-               }
-
-               if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
-                       goto out_badnvs;
-       }
-
-       /*
-        * We've reached the first zero length, the first NVS table
-        * is located at an aligned offset which is at least 7 bytes further.
-        * NOTE: The wl->nvs->nvs element must be first, in order to
-        * simplify the casting, we assume it is at the beginning of
-        * the wl->nvs structure.
-        */
-       nvs_ptr = (u8 *)wl->nvs +
-                       ALIGN(nvs_ptr - (u8 *)wl->nvs + 7, 4);
-
-       if (nvs_ptr >= (u8 *) wl->nvs + nvs_len)
-               goto out_badnvs;
-
-       nvs_len -= nvs_ptr - (u8 *)wl->nvs;
-
-       /* Now we must set the partition correctly */
-       wl1271_set_partition(wl, &wl12xx_part_table[PART_WORK]);
-
-       /* Copy the NVS tables to a new block to ensure alignment */
-       nvs_aligned = kmemdup(nvs_ptr, nvs_len, GFP_KERNEL);
-       if (!nvs_aligned)
-               return -ENOMEM;
-
-       /* And finally we upload the NVS tables */
-       wl1271_write(wl, CMD_MBOX_ADDRESS, nvs_aligned, nvs_len, false);
-
-       kfree(nvs_aligned);
-       return 0;
-
-out_badnvs:
-       wl1271_error("nvs data is malformed");
-       return -EILSEQ;
-}
-
-static void wl1271_boot_enable_interrupts(struct wl1271 *wl)
-{
-       wl1271_enable_interrupts(wl);
-       wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
-                      WL1271_ACX_INTR_ALL & ~(WL1271_INTR_MASK));
-       wl1271_write32(wl, HI_CFG, HI_CFG_DEF_VAL);
-}
-
-static int wl1271_boot_soft_reset(struct wl1271 *wl)
-{
-       unsigned long timeout;
-       u32 boot_data;
-
-       /* perform soft reset */
-       wl1271_write32(wl, ACX_REG_SLV_SOFT_RESET, ACX_SLV_SOFT_RESET_BIT);
-
-       /* SOFT_RESET is self clearing */
-       timeout = jiffies + usecs_to_jiffies(SOFT_RESET_MAX_TIME);
-       while (1) {
-               boot_data = wl1271_read32(wl, ACX_REG_SLV_SOFT_RESET);
-               wl1271_debug(DEBUG_BOOT, "soft reset bootdata 0x%x", boot_data);
-               if ((boot_data & ACX_SLV_SOFT_RESET_BIT) == 0)
-                       break;
-
-               if (time_after(jiffies, timeout)) {
-                       /* 1.2 check pWhalBus->uSelfClearTime if the
-                        * timeout was reached */
-                       wl1271_error("soft reset timeout");
-                       return -1;
-               }
-
-               udelay(SOFT_RESET_STALL_TIME);
-       }
-
-       /* disable Rx/Tx */
-       wl1271_write32(wl, ENABLE, 0x0);
-
-       /* disable auto calibration on start*/
-       wl1271_write32(wl, SPARE_A2, 0xffff);
-
-       return 0;
-}
-
-static int wl1271_boot_run_firmware(struct wl1271 *wl)
-{
-       int loop, ret;
-       u32 chip_id, intr;
-
-       wl1271_boot_set_ecpu_ctrl(wl, ECPU_CONTROL_HALT);
-
-       chip_id = wl1271_read32(wl, CHIP_ID_B);
-
-       wl1271_debug(DEBUG_BOOT, "chip id after firmware boot: 0x%x", chip_id);
-
-       if (chip_id != wl->chip.id) {
-               wl1271_error("chip id doesn't match after firmware boot");
-               return -EIO;
-       }
-
-       /* wait for init to complete */
-       loop = 0;
-       while (loop++ < INIT_LOOP) {
-               udelay(INIT_LOOP_DELAY);
-               intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
-
-               if (intr == 0xffffffff) {
-                       wl1271_error("error reading hardware complete "
-                                    "init indication");
-                       return -EIO;
-               }
-               /* check that ACX_INTR_INIT_COMPLETE is enabled */
-               else if (intr & WL1271_ACX_INTR_INIT_COMPLETE) {
-                       wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
-                                      WL1271_ACX_INTR_INIT_COMPLETE);
-                       break;
-               }
-       }
-
-       if (loop > INIT_LOOP) {
-               wl1271_error("timeout waiting for the hardware to "
-                            "complete initialization");
-               return -EIO;
-       }
-
-       /* get hardware config command mail box */
-       wl->cmd_box_addr = wl1271_read32(wl, REG_COMMAND_MAILBOX_PTR);
-
-       /* get hardware config event mail box */
-       wl->event_box_addr = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
-
-       /* set the working partition to its "running" mode offset */
-       wl1271_set_partition(wl, &wl12xx_part_table[PART_WORK]);
-
-       wl1271_debug(DEBUG_MAILBOX, "cmd_box_addr 0x%x event_box_addr 0x%x",
-                    wl->cmd_box_addr, wl->event_box_addr);
-
-       wl1271_boot_fw_version(wl);
-
-       /*
-        * in case of full asynchronous mode the firmware event must be
-        * ready to receive event from the command mailbox
-        */
-
-       /* unmask required mbox events  */
-       wl->event_mask = BSS_LOSE_EVENT_ID |
-               SCAN_COMPLETE_EVENT_ID |
-               ROLE_STOP_COMPLETE_EVENT_ID |
-               RSSI_SNR_TRIGGER_0_EVENT_ID |
-               PSPOLL_DELIVERY_FAILURE_EVENT_ID |
-               SOFT_GEMINI_SENSE_EVENT_ID |
-               PERIODIC_SCAN_REPORT_EVENT_ID |
-               PERIODIC_SCAN_COMPLETE_EVENT_ID |
-               DUMMY_PACKET_EVENT_ID |
-               PEER_REMOVE_COMPLETE_EVENT_ID |
-               BA_SESSION_RX_CONSTRAINT_EVENT_ID |
-               REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID |
-               INACTIVE_STA_EVENT_ID |
-               MAX_TX_RETRY_EVENT_ID |
-               CHANNEL_SWITCH_COMPLETE_EVENT_ID;
-
-       ret = wl1271_event_unmask(wl);
-       if (ret < 0) {
-               wl1271_error("EVENT mask setting failed");
-               return ret;
-       }
-
-       wl1271_event_mbox_config(wl);
-
-       /* firmware startup completed */
-       return 0;
-}
-
-static int wl1271_boot_write_irq_polarity(struct wl1271 *wl)
-{
-       u32 polarity;
-
-       polarity = wl1271_top_reg_read(wl, OCP_REG_POLARITY);
-
-       /* We use HIGH polarity, so unset the LOW bit */
-       polarity &= ~POLARITY_LOW;
-       wl1271_top_reg_write(wl, OCP_REG_POLARITY, polarity);
-
-       return 0;
-}
-
-static int wl128x_switch_tcxo_to_fref(struct wl1271 *wl)
-{
-       u16 spare_reg;
-
-       /* Mask bits [2] & [8:4] in the sys_clk_cfg register */
-       spare_reg = wl1271_top_reg_read(wl, WL_SPARE_REG);
-       if (spare_reg == 0xFFFF)
-               return -EFAULT;
-       spare_reg |= (BIT(3) | BIT(5) | BIT(6));
-       wl1271_top_reg_write(wl, WL_SPARE_REG, spare_reg);
-
-       /* Enable FREF_CLK_REQ & mux MCS and coex PLLs to FREF */
-       wl1271_top_reg_write(wl, SYS_CLK_CFG_REG,
-                            WL_CLK_REQ_TYPE_PG2 | MCS_PLL_CLK_SEL_FREF);
-
-       /* Delay execution for 15msec, to let the HW settle */
-       mdelay(15);
-
-       return 0;
-}
-
-static bool wl128x_is_tcxo_valid(struct wl1271 *wl)
-{
-       u16 tcxo_detection;
-
-       tcxo_detection = wl1271_top_reg_read(wl, TCXO_CLK_DETECT_REG);
-       if (tcxo_detection & TCXO_DET_FAILED)
-               return false;
-
-       return true;
-}
-
-static bool wl128x_is_fref_valid(struct wl1271 *wl)
-{
-       u16 fref_detection;
-
-       fref_detection = wl1271_top_reg_read(wl, FREF_CLK_DETECT_REG);
-       if (fref_detection & FREF_CLK_DETECT_FAIL)
-               return false;
-
-       return true;
-}
-
-static int wl128x_manually_configure_mcs_pll(struct wl1271 *wl)
-{
-       wl1271_top_reg_write(wl, MCS_PLL_M_REG, MCS_PLL_M_REG_VAL);
-       wl1271_top_reg_write(wl, MCS_PLL_N_REG, MCS_PLL_N_REG_VAL);
-       wl1271_top_reg_write(wl, MCS_PLL_CONFIG_REG, MCS_PLL_CONFIG_REG_VAL);
-
-       return 0;
-}
-
-static int wl128x_configure_mcs_pll(struct wl1271 *wl, int clk)
-{
-       u16 spare_reg;
-       u16 pll_config;
-       u8 input_freq;
-
-       /* Mask bits [3:1] in the sys_clk_cfg register */
-       spare_reg = wl1271_top_reg_read(wl, WL_SPARE_REG);
-       if (spare_reg == 0xFFFF)
-               return -EFAULT;
-       spare_reg |= BIT(2);
-       wl1271_top_reg_write(wl, WL_SPARE_REG, spare_reg);
-
-       /* Handle special cases of the TCXO clock */
-       if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_8 ||
-           wl->tcxo_clock == WL12XX_TCXOCLOCK_33_6)
-               return wl128x_manually_configure_mcs_pll(wl);
-
-       /* Set the input frequency according to the selected clock source */
-       input_freq = (clk & 1) + 1;
-
-       pll_config = wl1271_top_reg_read(wl, MCS_PLL_CONFIG_REG);
-       if (pll_config == 0xFFFF)
-               return -EFAULT;
-       pll_config |= (input_freq << MCS_SEL_IN_FREQ_SHIFT);
-       pll_config |= MCS_PLL_ENABLE_HP;
-       wl1271_top_reg_write(wl, MCS_PLL_CONFIG_REG, pll_config);
-
-       return 0;
-}
-
-/*
- * WL128x has two clocks input - TCXO and FREF.
- * TCXO is the main clock of the device, while FREF is used to sync
- * between the GPS and the cellular modem.
- * In cases where TCXO is 32.736MHz or 16.368MHz, the FREF will be used
- * as the WLAN/BT main clock.
- */
-static int wl128x_boot_clk(struct wl1271 *wl, int *selected_clock)
-{
-       u16 sys_clk_cfg;
-
-       /* For XTAL-only modes, FREF will be used after switching from TCXO */
-       if (wl->ref_clock == WL12XX_REFCLOCK_26_XTAL ||
-           wl->ref_clock == WL12XX_REFCLOCK_38_XTAL) {
-               if (!wl128x_switch_tcxo_to_fref(wl))
-                       return -EINVAL;
-               goto fref_clk;
-       }
-
-       /* Query the HW, to determine which clock source we should use */
-       sys_clk_cfg = wl1271_top_reg_read(wl, SYS_CLK_CFG_REG);
-       if (sys_clk_cfg == 0xFFFF)
-               return -EINVAL;
-       if (sys_clk_cfg & PRCM_CM_EN_MUX_WLAN_FREF)
-               goto fref_clk;
-
-       /* If TCXO is either 32.736MHz or 16.368MHz, switch to FREF */
-       if (wl->tcxo_clock == WL12XX_TCXOCLOCK_16_368 ||
-           wl->tcxo_clock == WL12XX_TCXOCLOCK_32_736) {
-               if (!wl128x_switch_tcxo_to_fref(wl))
-                       return -EINVAL;
-               goto fref_clk;
-       }
-
-       /* TCXO clock is selected */
-       if (!wl128x_is_tcxo_valid(wl))
-               return -EINVAL;
-       *selected_clock = wl->tcxo_clock;
-       goto config_mcs_pll;
-
-fref_clk:
-       /* FREF clock is selected */
-       if (!wl128x_is_fref_valid(wl))
-               return -EINVAL;
-       *selected_clock = wl->ref_clock;
-
-config_mcs_pll:
-       return wl128x_configure_mcs_pll(wl, *selected_clock);
-}
-
-static int wl127x_boot_clk(struct wl1271 *wl)
-{
-       u32 pause;
-       u32 clk;
-
-       if (WL127X_PG_GET_MAJOR(wl->hw_pg_ver) < 3)
-               wl->quirks |= WL12XX_QUIRK_END_OF_TRANSACTION;
-
-       if (wl->ref_clock == CONF_REF_CLK_19_2_E ||
-           wl->ref_clock == CONF_REF_CLK_38_4_E ||
-           wl->ref_clock == CONF_REF_CLK_38_4_M_XTAL)
-               /* ref clk: 19.2/38.4/38.4-XTAL */
-               clk = 0x3;
-       else if (wl->ref_clock == CONF_REF_CLK_26_E ||
-                wl->ref_clock == CONF_REF_CLK_52_E)
-               /* ref clk: 26/52 */
-               clk = 0x5;
-       else
-               return -EINVAL;
-
-       if (wl->ref_clock != CONF_REF_CLK_19_2_E) {
-               u16 val;
-               /* Set clock type (open drain) */
-               val = wl1271_top_reg_read(wl, OCP_REG_CLK_TYPE);
-               val &= FREF_CLK_TYPE_BITS;
-               wl1271_top_reg_write(wl, OCP_REG_CLK_TYPE, val);
-
-               /* Set clock pull mode (no pull) */
-               val = wl1271_top_reg_read(wl, OCP_REG_CLK_PULL);
-               val |= NO_PULL;
-               wl1271_top_reg_write(wl, OCP_REG_CLK_PULL, val);
-       } else {
-               u16 val;
-               /* Set clock polarity */
-               val = wl1271_top_reg_read(wl, OCP_REG_CLK_POLARITY);
-               val &= FREF_CLK_POLARITY_BITS;
-               val |= CLK_REQ_OUTN_SEL;
-               wl1271_top_reg_write(wl, OCP_REG_CLK_POLARITY, val);
-       }
-
-       wl1271_write32(wl, PLL_PARAMETERS, clk);
-
-       pause = wl1271_read32(wl, PLL_PARAMETERS);
-
-       wl1271_debug(DEBUG_BOOT, "pause1 0x%x", pause);
-
-       pause &= ~(WU_COUNTER_PAUSE_VAL);
-       pause |= WU_COUNTER_PAUSE_VAL;
-       wl1271_write32(wl, WU_COUNTER_PAUSE, pause);
-
-       return 0;
-}
-
-/* uploads NVS and firmware */
-int wl1271_load_firmware(struct wl1271 *wl)
-{
-       int ret = 0;
-       u32 tmp, clk;
-       int selected_clock = -1;
-
-       if (wl->chip.id == CHIP_ID_1283_PG20) {
-               ret = wl128x_boot_clk(wl, &selected_clock);
-               if (ret < 0)
-                       goto out;
-       } else {
-               ret = wl127x_boot_clk(wl);
-               if (ret < 0)
-                       goto out;
-       }
-
-       /* Continue the ELP wake up sequence */
-       wl1271_write32(wl, WELP_ARM_COMMAND, WELP_ARM_COMMAND_VAL);
-       udelay(500);
-
-       wl1271_set_partition(wl, &wl12xx_part_table[PART_DRPW]);
-
-       /* Read-modify-write DRPW_SCRATCH_START register (see next state)
-          to be used by DRPw FW. The RTRIM value will be added by the FW
-          before taking DRPw out of reset */
-
-       wl1271_debug(DEBUG_BOOT, "DRPW_SCRATCH_START %08x", DRPW_SCRATCH_START);
-       clk = wl1271_read32(wl, DRPW_SCRATCH_START);
-
-       wl1271_debug(DEBUG_BOOT, "clk2 0x%x", clk);
-
-       if (wl->chip.id == CHIP_ID_1283_PG20) {
-               clk |= ((selected_clock & 0x3) << 1) << 4;
-       } else {
-               clk |= (wl->ref_clock << 1) << 4;
-       }
-
-       wl1271_write32(wl, DRPW_SCRATCH_START, clk);
-
-       wl1271_set_partition(wl, &wl12xx_part_table[PART_WORK]);
-
-       /* Disable interrupts */
-       wl1271_write32(wl, ACX_REG_INTERRUPT_MASK, WL1271_ACX_INTR_ALL);
-
-       ret = wl1271_boot_soft_reset(wl);
-       if (ret < 0)
-               goto out;
-
-       /* 2. start processing NVS file */
-       ret = wl1271_boot_upload_nvs(wl);
-       if (ret < 0)
-               goto out;
-
-       /* write firmware's last address (ie. it's length) to
-        * ACX_EEPROMLESS_IND_REG */
-       wl1271_debug(DEBUG_BOOT, "ACX_EEPROMLESS_IND_REG");
-
-       wl1271_write32(wl, ACX_EEPROMLESS_IND_REG, ACX_EEPROMLESS_IND_REG);
-
-       tmp = wl1271_read32(wl, CHIP_ID_B);
-
-       wl1271_debug(DEBUG_BOOT, "chip id 0x%x", tmp);
-
-       /* 6. read the EEPROM parameters */
-       tmp = wl1271_read32(wl, SCR_PAD2);
-
-       /* WL1271: The reference driver skips steps 7 to 10 (jumps directly
-        * to upload_fw) */
-
-       if (wl->chip.id == CHIP_ID_1283_PG20)
-               wl1271_top_reg_write(wl, SDIO_IO_DS, wl->conf.hci_io_ds);
-
-       ret = wl1271_boot_upload_firmware(wl);
-       if (ret < 0)
-               goto out;
-
-out:
-       return ret;
-}
-EXPORT_SYMBOL_GPL(wl1271_load_firmware);
-
-int wl1271_boot(struct wl1271 *wl)
-{
-       int ret;
-
-       /* upload NVS and firmware */
-       ret = wl1271_load_firmware(wl);
-       if (ret)
-               return ret;
-
-       /* 10.5 start firmware */
-       ret = wl1271_boot_run_firmware(wl);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1271_boot_write_irq_polarity(wl);
-       if (ret < 0)
-               goto out;
-
-       wl1271_write32(wl, ACX_REG_INTERRUPT_MASK,
-                      WL1271_ACX_ALL_EVENTS_VECTOR);
-
-       /* Enable firmware interrupts now */
-       wl1271_boot_enable_interrupts(wl);
-
-       wl1271_event_mbox_config(wl);
-
-out:
-       return ret;
-}
diff --git a/drivers/net/wireless/wl12xx/boot.h b/drivers/net/wireless/wl12xx/boot.h
deleted file mode 100644 (file)
index c3adc09..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2008-2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __BOOT_H__
-#define __BOOT_H__
-
-#include "wl12xx.h"
-
-int wl1271_boot(struct wl1271 *wl);
-int wl1271_load_firmware(struct wl1271 *wl);
-
-#define WL1271_NO_SUBBANDS 8
-#define WL1271_NO_POWER_LEVELS 4
-#define WL1271_FW_VERSION_MAX_LEN 20
-
-struct wl1271_static_data {
-       u8 mac_address[ETH_ALEN];
-       u8 padding[2];
-       u8 fw_version[WL1271_FW_VERSION_MAX_LEN];
-       u32 hw_version;
-       u8 tx_power_table[WL1271_NO_SUBBANDS][WL1271_NO_POWER_LEVELS];
-};
-
-/* number of times we try to read the INIT interrupt */
-#define INIT_LOOP 20000
-
-/* delay between retries */
-#define INIT_LOOP_DELAY 50
-
-#define WU_COUNTER_PAUSE_VAL 0x3FF
-#define WELP_ARM_COMMAND_VAL 0x4
-
-#define OCP_REG_POLARITY     0x0064
-#define OCP_REG_CLK_TYPE     0x0448
-#define OCP_REG_CLK_POLARITY 0x0cb2
-#define OCP_REG_CLK_PULL     0x0cb4
-
-#define CMD_MBOX_ADDRESS     0x407B4
-
-#define POLARITY_LOW         BIT(1)
-#define NO_PULL              (BIT(14) | BIT(15))
-
-#define FREF_CLK_TYPE_BITS     0xfffffe7f
-#define CLK_REQ_PRCM           0x100
-#define FREF_CLK_POLARITY_BITS 0xfffff8ff
-#define CLK_REQ_OUTN_SEL       0x700
-
-/* PLL configuration algorithm for wl128x */
-#define SYS_CLK_CFG_REG              0x2200
-/* Bit[0]   -  0-TCXO,  1-FREF */
-#define MCS_PLL_CLK_SEL_FREF         BIT(0)
-/* Bit[3:2] - 01-TCXO, 10-FREF */
-#define WL_CLK_REQ_TYPE_FREF         BIT(3)
-#define WL_CLK_REQ_TYPE_PG2          (BIT(3) | BIT(2))
-/* Bit[4]   -  0-TCXO,  1-FREF */
-#define PRCM_CM_EN_MUX_WLAN_FREF     BIT(4)
-
-#define TCXO_ILOAD_INT_REG           0x2264
-#define TCXO_CLK_DETECT_REG          0x2266
-
-#define TCXO_DET_FAILED              BIT(4)
-
-#define FREF_ILOAD_INT_REG           0x2084
-#define FREF_CLK_DETECT_REG          0x2086
-#define FREF_CLK_DETECT_FAIL         BIT(4)
-
-/* Use this reg for masking during driver access */
-#define WL_SPARE_REG                 0x2320
-#define WL_SPARE_VAL                 BIT(2)
-/* Bit[6:5:3] -  mask wl write SYS_CLK_CFG[8:5:2:4] */
-#define WL_SPARE_MASK_8526           (BIT(6) | BIT(5) | BIT(3))
-
-#define PLL_LOCK_COUNTERS_REG        0xD8C
-#define PLL_LOCK_COUNTERS_COEX       0x0F
-#define PLL_LOCK_COUNTERS_MCS        0xF0
-#define MCS_PLL_OVERRIDE_REG         0xD90
-#define MCS_PLL_CONFIG_REG           0xD92
-#define MCS_SEL_IN_FREQ_MASK         0x0070
-#define MCS_SEL_IN_FREQ_SHIFT        4
-#define MCS_PLL_CONFIG_REG_VAL       0x73
-#define MCS_PLL_ENABLE_HP            (BIT(0) | BIT(1))
-
-#define MCS_PLL_M_REG                0xD94
-#define MCS_PLL_N_REG                0xD96
-#define MCS_PLL_M_REG_VAL            0xC8
-#define MCS_PLL_N_REG_VAL            0x07
-
-#define SDIO_IO_DS                   0xd14
-
-/* SDIO/wSPI DS configuration values */
-enum {
-       HCI_IO_DS_8MA = 0,
-       HCI_IO_DS_4MA = 1, /* default */
-       HCI_IO_DS_6MA = 2,
-       HCI_IO_DS_2MA = 3,
-};
-
-/* end PLL configuration algorithm for wl128x */
-
-#endif
diff --git a/drivers/net/wireless/wl12xx/cmd.c b/drivers/net/wireless/wl12xx/cmd.c
deleted file mode 100644 (file)
index 3414fc1..0000000
+++ /dev/null
@@ -1,1943 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2009-2010 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/spi/spi.h>
-#include <linux/etherdevice.h>
-#include <linux/ieee80211.h>
-#include <linux/slab.h>
-
-#include "wl12xx.h"
-#include "debug.h"
-#include "reg.h"
-#include "io.h"
-#include "acx.h"
-#include "wl12xx_80211.h"
-#include "cmd.h"
-#include "event.h"
-#include "tx.h"
-
-#define WL1271_CMD_FAST_POLL_COUNT       50
-
-/*
- * send command to firmware
- *
- * @wl: wl struct
- * @id: command id
- * @buf: buffer containing the command, must work with dma
- * @len: length of the buffer
- */
-int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
-                   size_t res_len)
-{
-       struct wl1271_cmd_header *cmd;
-       unsigned long timeout;
-       u32 intr;
-       int ret = 0;
-       u16 status;
-       u16 poll_count = 0;
-
-       cmd = buf;
-       cmd->id = cpu_to_le16(id);
-       cmd->status = 0;
-
-       WARN_ON(len % 4 != 0);
-       WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
-
-       wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
-
-       wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
-
-       timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
-
-       intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
-       while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
-               if (time_after(jiffies, timeout)) {
-                       wl1271_error("command complete timeout");
-                       ret = -ETIMEDOUT;
-                       goto fail;
-               }
-
-               poll_count++;
-               if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
-                       udelay(10);
-               else
-                       msleep(1);
-
-               intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
-       }
-
-       /* read back the status code of the command */
-       if (res_len == 0)
-               res_len = sizeof(struct wl1271_cmd_header);
-       wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
-
-       status = le16_to_cpu(cmd->status);
-       if (status != CMD_STATUS_SUCCESS) {
-               wl1271_error("command execute failure %d", status);
-               ret = -EIO;
-               goto fail;
-       }
-
-       wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
-                      WL1271_ACX_INTR_CMD_COMPLETE);
-       return 0;
-
-fail:
-       WARN_ON(1);
-       wl12xx_queue_recovery_work(wl);
-       return ret;
-}
-
-int wl1271_cmd_general_parms(struct wl1271 *wl)
-{
-       struct wl1271_general_parms_cmd *gen_parms;
-       struct wl1271_ini_general_params *gp =
-               &((struct wl1271_nvs_file *)wl->nvs)->general_params;
-       bool answer = false;
-       int ret;
-
-       if (!wl->nvs)
-               return -ENODEV;
-
-       if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
-               wl1271_warning("FEM index from INI out of bounds");
-               return -EINVAL;
-       }
-
-       gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
-       if (!gen_parms)
-               return -ENOMEM;
-
-       gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
-
-       memcpy(&gen_parms->general_params, gp, sizeof(*gp));
-
-       if (gp->tx_bip_fem_auto_detect)
-               answer = true;
-
-       /* Override the REF CLK from the NVS with the one from platform data */
-       gen_parms->general_params.ref_clock = wl->ref_clock;
-
-       ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
-       if (ret < 0) {
-               wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
-               goto out;
-       }
-
-       gp->tx_bip_fem_manufacturer =
-               gen_parms->general_params.tx_bip_fem_manufacturer;
-
-       if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
-               wl1271_warning("FEM index from FW out of bounds");
-               ret = -EINVAL;
-               goto out;
-       }
-
-       wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
-                    answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
-
-out:
-       kfree(gen_parms);
-       return ret;
-}
-
-int wl128x_cmd_general_parms(struct wl1271 *wl)
-{
-       struct wl128x_general_parms_cmd *gen_parms;
-       struct wl128x_ini_general_params *gp =
-               &((struct wl128x_nvs_file *)wl->nvs)->general_params;
-       bool answer = false;
-       int ret;
-
-       if (!wl->nvs)
-               return -ENODEV;
-
-       if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
-               wl1271_warning("FEM index from ini out of bounds");
-               return -EINVAL;
-       }
-
-       gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
-       if (!gen_parms)
-               return -ENOMEM;
-
-       gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
-
-       memcpy(&gen_parms->general_params, gp, sizeof(*gp));
-
-       if (gp->tx_bip_fem_auto_detect)
-               answer = true;
-
-       /* Replace REF and TCXO CLKs with the ones from platform data */
-       gen_parms->general_params.ref_clock = wl->ref_clock;
-       gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock;
-
-       ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
-       if (ret < 0) {
-               wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
-               goto out;
-       }
-
-       gp->tx_bip_fem_manufacturer =
-               gen_parms->general_params.tx_bip_fem_manufacturer;
-
-       if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
-               wl1271_warning("FEM index from FW out of bounds");
-               ret = -EINVAL;
-               goto out;
-       }
-
-       wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
-                    answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
-
-out:
-       kfree(gen_parms);
-       return ret;
-}
-
-int wl1271_cmd_radio_parms(struct wl1271 *wl)
-{
-       struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs;
-       struct wl1271_radio_parms_cmd *radio_parms;
-       struct wl1271_ini_general_params *gp = &nvs->general_params;
-       int ret;
-
-       if (!wl->nvs)
-               return -ENODEV;
-
-       radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
-       if (!radio_parms)
-               return -ENOMEM;
-
-       radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
-
-       /* 2.4GHz parameters */
-       memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
-              sizeof(struct wl1271_ini_band_params_2));
-       memcpy(&radio_parms->dyn_params_2,
-              &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
-              sizeof(struct wl1271_ini_fem_params_2));
-
-       /* 5GHz parameters */
-       memcpy(&radio_parms->static_params_5,
-              &nvs->stat_radio_params_5,
-              sizeof(struct wl1271_ini_band_params_5));
-       memcpy(&radio_parms->dyn_params_5,
-              &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
-              sizeof(struct wl1271_ini_fem_params_5));
-
-       wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
-                   radio_parms, sizeof(*radio_parms));
-
-       ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
-       if (ret < 0)
-               wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
-
-       kfree(radio_parms);
-       return ret;
-}
-
-int wl128x_cmd_radio_parms(struct wl1271 *wl)
-{
-       struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
-       struct wl128x_radio_parms_cmd *radio_parms;
-       struct wl128x_ini_general_params *gp = &nvs->general_params;
-       int ret;
-
-       if (!wl->nvs)
-               return -ENODEV;
-
-       radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
-       if (!radio_parms)
-               return -ENOMEM;
-
-       radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
-
-       /* 2.4GHz parameters */
-       memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
-              sizeof(struct wl128x_ini_band_params_2));
-       memcpy(&radio_parms->dyn_params_2,
-              &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
-              sizeof(struct wl128x_ini_fem_params_2));
-
-       /* 5GHz parameters */
-       memcpy(&radio_parms->static_params_5,
-              &nvs->stat_radio_params_5,
-              sizeof(struct wl128x_ini_band_params_5));
-       memcpy(&radio_parms->dyn_params_5,
-              &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
-              sizeof(struct wl128x_ini_fem_params_5));
-
-       radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options;
-
-       wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
-                   radio_parms, sizeof(*radio_parms));
-
-       ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
-       if (ret < 0)
-               wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
-
-       kfree(radio_parms);
-       return ret;
-}
-
-int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
-{
-       struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
-       struct conf_rf_settings *rf = &wl->conf.rf;
-       int ret;
-
-       if (!wl->nvs)
-               return -ENODEV;
-
-       ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
-       if (!ext_radio_parms)
-               return -ENOMEM;
-
-       ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
-
-       memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
-              rf->tx_per_channel_power_compensation_2,
-              CONF_TX_PWR_COMPENSATION_LEN_2);
-       memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
-              rf->tx_per_channel_power_compensation_5,
-              CONF_TX_PWR_COMPENSATION_LEN_5);
-
-       wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
-                   ext_radio_parms, sizeof(*ext_radio_parms));
-
-       ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
-       if (ret < 0)
-               wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
-
-       kfree(ext_radio_parms);
-       return ret;
-}
-
-/*
- * Poll the mailbox event field until any of the bits in the mask is set or a
- * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
- */
-static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
-{
-       u32 events_vector, event;
-       unsigned long timeout;
-
-       timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
-
-       do {
-               if (time_after(jiffies, timeout)) {
-                       wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
-                                    (int)mask);
-                       return -ETIMEDOUT;
-               }
-
-               msleep(1);
-
-               /* read from both event fields */
-               wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
-                           sizeof(events_vector), false);
-               event = events_vector & mask;
-               wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
-                           sizeof(events_vector), false);
-               event |= events_vector & mask;
-       } while (!event);
-
-       return 0;
-}
-
-static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
-{
-       int ret;
-
-       ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
-       if (ret != 0) {
-               wl12xx_queue_recovery_work(wl);
-               return ret;
-       }
-
-       return 0;
-}
-
-int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
-                          u8 *role_id)
-{
-       struct wl12xx_cmd_role_enable *cmd;
-       int ret;
-
-       wl1271_debug(DEBUG_CMD, "cmd role enable");
-
-       if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID))
-               return -EBUSY;
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* get role id */
-       cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES);
-       if (cmd->role_id >= WL12XX_MAX_ROLES) {
-               ret = -EBUSY;
-               goto out_free;
-       }
-
-       memcpy(cmd->mac_address, addr, ETH_ALEN);
-       cmd->role_type = role_type;
-
-       ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to initiate cmd role enable");
-               goto out_free;
-       }
-
-       __set_bit(cmd->role_id, wl->roles_map);
-       *role_id = cmd->role_id;
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id)
-{
-       struct wl12xx_cmd_role_disable *cmd;
-       int ret;
-
-       wl1271_debug(DEBUG_CMD, "cmd role disable");
-
-       if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID))
-               return -ENOENT;
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-       cmd->role_id = *role_id;
-
-       ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to initiate cmd role disable");
-               goto out_free;
-       }
-
-       __clear_bit(*role_id, wl->roles_map);
-       *role_id = WL12XX_INVALID_ROLE_ID;
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
-{
-       unsigned long flags;
-       u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
-       if (link >= WL12XX_MAX_LINKS)
-               return -EBUSY;
-
-       /* these bits are used by op_tx */
-       spin_lock_irqsave(&wl->wl_lock, flags);
-       __set_bit(link, wl->links_map);
-       __set_bit(link, wlvif->links_map);
-       spin_unlock_irqrestore(&wl->wl_lock, flags);
-       *hlid = link;
-       return 0;
-}
-
-void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
-{
-       unsigned long flags;
-
-       if (*hlid == WL12XX_INVALID_LINK_ID)
-               return;
-
-       /* these bits are used by op_tx */
-       spin_lock_irqsave(&wl->wl_lock, flags);
-       __clear_bit(*hlid, wl->links_map);
-       __clear_bit(*hlid, wlvif->links_map);
-       spin_unlock_irqrestore(&wl->wl_lock, flags);
-
-       /*
-        * At this point op_tx() will not add more packets to the queues. We
-        * can purge them.
-        */
-       wl1271_tx_reset_link_queues(wl, *hlid);
-
-       *hlid = WL12XX_INVALID_LINK_ID;
-}
-
-static int wl12xx_get_new_session_id(struct wl1271 *wl,
-                                    struct wl12xx_vif *wlvif)
-{
-       if (wlvif->session_counter >= SESSION_COUNTER_MAX)
-               wlvif->session_counter = 0;
-
-       wlvif->session_counter++;
-
-       return wlvif->session_counter;
-}
-
-static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
-                                    struct wl12xx_vif *wlvif)
-{
-       struct wl12xx_cmd_role_start *cmd;
-       int ret;
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
-
-       cmd->role_id = wlvif->dev_role_id;
-       if (wlvif->band == IEEE80211_BAND_5GHZ)
-               cmd->band = WL12XX_BAND_5GHZ;
-       cmd->channel = wlvif->channel;
-
-       if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
-               ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
-               if (ret)
-                       goto out_free;
-       }
-       cmd->device.hlid = wlvif->dev_hlid;
-       cmd->device.session = wl12xx_get_new_session_id(wl, wlvif);
-
-       wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
-                    cmd->role_id, cmd->device.hlid, cmd->device.session);
-
-       ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to initiate cmd role enable");
-               goto err_hlid;
-       }
-
-       goto out_free;
-
-err_hlid:
-       /* clear links on error */
-       wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
-                                   struct wl12xx_vif *wlvif)
-{
-       struct wl12xx_cmd_role_stop *cmd;
-       int ret;
-
-       if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
-               return -EINVAL;
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wl1271_debug(DEBUG_CMD, "cmd role stop dev");
-
-       cmd->role_id = wlvif->dev_role_id;
-       cmd->disc_type = DISCONNECT_IMMEDIATE;
-       cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
-
-       ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to initiate cmd role stop");
-               goto out_free;
-       }
-
-       ret = wl1271_cmd_wait_for_event(wl, ROLE_STOP_COMPLETE_EVENT_ID);
-       if (ret < 0) {
-               wl1271_error("cmd role stop dev event completion error");
-               goto out_free;
-       }
-
-       wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-       struct wl12xx_cmd_role_start *cmd;
-       int ret;
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
-
-       cmd->role_id = wlvif->role_id;
-       if (wlvif->band == IEEE80211_BAND_5GHZ)
-               cmd->band = WL12XX_BAND_5GHZ;
-       cmd->channel = wlvif->channel;
-       cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
-       cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
-       cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
-       cmd->sta.ssid_len = wlvif->ssid_len;
-       memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
-       memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
-       cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
-
-       if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
-               ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
-               if (ret)
-                       goto out_free;
-       }
-       cmd->sta.hlid = wlvif->sta.hlid;
-       cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
-       cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
-
-       wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
-                    "basic_rate_set: 0x%x, remote_rates: 0x%x",
-                    wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
-                    wlvif->basic_rate_set, wlvif->rate_set);
-
-       ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to initiate cmd role start sta");
-               goto err_hlid;
-       }
-
-       goto out_free;
-
-err_hlid:
-       /* clear links on error. */
-       wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-/* use this function to stop ibss as well */
-int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       struct wl12xx_cmd_role_stop *cmd;
-       int ret;
-
-       if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
-               return -EINVAL;
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
-
-       cmd->role_id = wlvif->role_id;
-       cmd->disc_type = DISCONNECT_IMMEDIATE;
-       cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
-
-       ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to initiate cmd role stop sta");
-               goto out_free;
-       }
-
-       wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       struct wl12xx_cmd_role_start *cmd;
-       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-       struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
-       int ret;
-
-       wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
-
-       /* trying to use hidden SSID with an old hostapd version */
-       if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
-               wl1271_error("got a null SSID from beacon/bss");
-               ret = -EINVAL;
-               goto out;
-       }
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
-       if (ret < 0)
-               goto out_free;
-
-       ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
-       if (ret < 0)
-               goto out_free_global;
-
-       cmd->role_id = wlvif->role_id;
-       cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
-       cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
-       cmd->ap.global_hlid = wlvif->ap.global_hlid;
-       cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
-       cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
-       cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
-       cmd->ap.dtim_interval = bss_conf->dtim_period;
-       cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
-       /* FIXME: Change when adding DFS */
-       cmd->ap.reset_tsf = 1;  /* By default reset AP TSF */
-       cmd->channel = wlvif->channel;
-
-       if (!bss_conf->hidden_ssid) {
-               /* take the SSID from the beacon for backward compatibility */
-               cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
-               cmd->ap.ssid_len = wlvif->ssid_len;
-               memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
-       } else {
-               cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
-               cmd->ap.ssid_len = bss_conf->ssid_len;
-               memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
-       }
-
-       cmd->ap.local_rates = cpu_to_le32(0xffffffff);
-
-       switch (wlvif->band) {
-       case IEEE80211_BAND_2GHZ:
-               cmd->band = RADIO_BAND_2_4GHZ;
-               break;
-       case IEEE80211_BAND_5GHZ:
-               cmd->band = RADIO_BAND_5GHZ;
-               break;
-       default:
-               wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
-               cmd->band = RADIO_BAND_2_4GHZ;
-               break;
-       }
-
-       ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to initiate cmd role start ap");
-               goto out_free_bcast;
-       }
-
-       goto out_free;
-
-out_free_bcast:
-       wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
-
-out_free_global:
-       wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       struct wl12xx_cmd_role_stop *cmd;
-       int ret;
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
-
-       cmd->role_id = wlvif->role_id;
-
-       ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to initiate cmd role stop ap");
-               goto out_free;
-       }
-
-       wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
-       wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-       struct wl12xx_cmd_role_start *cmd;
-       struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
-       int ret;
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
-
-       cmd->role_id = wlvif->role_id;
-       if (wlvif->band == IEEE80211_BAND_5GHZ)
-               cmd->band = WL12XX_BAND_5GHZ;
-       cmd->channel = wlvif->channel;
-       cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
-       cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
-       cmd->ibss.dtim_interval = bss_conf->dtim_period;
-       cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
-       cmd->ibss.ssid_len = wlvif->ssid_len;
-       memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
-       memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
-       cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
-
-       if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
-               ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
-               if (ret)
-                       goto out_free;
-       }
-       cmd->ibss.hlid = wlvif->sta.hlid;
-       cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
-
-       wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
-                    "basic_rate_set: 0x%x, remote_rates: 0x%x",
-                    wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
-                    wlvif->basic_rate_set, wlvif->rate_set);
-
-       wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
-                    vif->bss_conf.bssid);
-
-       ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to initiate cmd role enable");
-               goto err_hlid;
-       }
-
-       goto out_free;
-
-err_hlid:
-       /* clear links on error. */
-       wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-
-/**
- * send test command to firmware
- *
- * @wl: wl struct
- * @buf: buffer containing the command, with all headers, must work with dma
- * @len: length of the buffer
- * @answer: is answer needed
- */
-int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
-{
-       int ret;
-       size_t res_len = 0;
-
-       wl1271_debug(DEBUG_CMD, "cmd test");
-
-       if (answer)
-               res_len = buf_len;
-
-       ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
-
-       if (ret < 0) {
-               wl1271_warning("TEST command failed");
-               return ret;
-       }
-
-       return ret;
-}
-
-/**
- * read acx from firmware
- *
- * @wl: wl struct
- * @id: acx id
- * @buf: buffer for the response, including all headers, must work with dma
- * @len: length of buf
- */
-int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
-{
-       struct acx_header *acx = buf;
-       int ret;
-
-       wl1271_debug(DEBUG_CMD, "cmd interrogate");
-
-       acx->id = cpu_to_le16(id);
-
-       /* payload length, does not include any headers */
-       acx->len = cpu_to_le16(len - sizeof(*acx));
-
-       ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
-       if (ret < 0)
-               wl1271_error("INTERROGATE command failed");
-
-       return ret;
-}
-
-/**
- * write acx value to firmware
- *
- * @wl: wl struct
- * @id: acx id
- * @buf: buffer containing acx, including all headers, must work with dma
- * @len: length of buf
- */
-int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
-{
-       struct acx_header *acx = buf;
-       int ret;
-
-       wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
-
-       acx->id = cpu_to_le16(id);
-
-       /* payload length, does not include any headers */
-       acx->len = cpu_to_le16(len - sizeof(*acx));
-
-       ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
-       if (ret < 0) {
-               wl1271_warning("CONFIGURE command NOK");
-               return ret;
-       }
-
-       return 0;
-}
-
-int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
-{
-       struct cmd_enabledisable_path *cmd;
-       int ret;
-       u16 cmd_rx, cmd_tx;
-
-       wl1271_debug(DEBUG_CMD, "cmd data path");
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* the channel here is only used for calibration, so hardcoded to 1 */
-       cmd->channel = 1;
-
-       if (enable) {
-               cmd_rx = CMD_ENABLE_RX;
-               cmd_tx = CMD_ENABLE_TX;
-       } else {
-               cmd_rx = CMD_DISABLE_RX;
-               cmd_tx = CMD_DISABLE_TX;
-       }
-
-       ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("rx %s cmd for channel %d failed",
-                            enable ? "start" : "stop", cmd->channel);
-               goto out;
-       }
-
-       wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
-                    enable ? "start" : "stop", cmd->channel);
-
-       ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("tx %s cmd for channel %d failed",
-                            enable ? "start" : "stop", cmd->channel);
-               goto out;
-       }
-
-       wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
-                    enable ? "start" : "stop", cmd->channel);
-
-out:
-       kfree(cmd);
-       return ret;
-}
-
-int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                      u8 ps_mode, u16 auto_ps_timeout)
-{
-       struct wl1271_cmd_ps_params *ps_params = NULL;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_CMD, "cmd set ps mode");
-
-       ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
-       if (!ps_params) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       ps_params->role_id = wlvif->role_id;
-       ps_params->ps_mode = ps_mode;
-       ps_params->auto_ps_timeout = auto_ps_timeout;
-
-       ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
-                             sizeof(*ps_params), 0);
-       if (ret < 0) {
-               wl1271_error("cmd set_ps_mode failed");
-               goto out;
-       }
-
-out:
-       kfree(ps_params);
-       return ret;
-}
-
-int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
-                           u16 template_id, void *buf, size_t buf_len,
-                           int index, u32 rates)
-{
-       struct wl1271_cmd_template_set *cmd;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)",
-                    template_id, role_id);
-
-       WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
-       buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       /* during initialization wlvif is NULL */
-       cmd->role_id = role_id;
-       cmd->len = cpu_to_le16(buf_len);
-       cmd->template_type = template_id;
-       cmd->enabled_rates = cpu_to_le32(rates);
-       cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
-       cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
-       cmd->index = index;
-
-       if (buf)
-               memcpy(cmd->template_data, buf, buf_len);
-
-       ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_warning("cmd set_template failed: %d", ret);
-               goto out_free;
-       }
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       struct sk_buff *skb = NULL;
-       int size;
-       void *ptr;
-       int ret = -ENOMEM;
-
-
-       if (wlvif->bss_type == BSS_TYPE_IBSS) {
-               size = sizeof(struct wl12xx_null_data_template);
-               ptr = NULL;
-       } else {
-               skb = ieee80211_nullfunc_get(wl->hw,
-                                            wl12xx_wlvif_to_vif(wlvif));
-               if (!skb)
-                       goto out;
-               size = skb->len;
-               ptr = skb->data;
-       }
-
-       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
-                                     CMD_TEMPL_NULL_DATA, ptr, size, 0,
-                                     wlvif->basic_rate);
-
-out:
-       dev_kfree_skb(skb);
-       if (ret)
-               wl1271_warning("cmd buld null data failed %d", ret);
-
-       return ret;
-
-}
-
-int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
-                                  struct wl12xx_vif *wlvif)
-{
-       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-       struct sk_buff *skb = NULL;
-       int ret = -ENOMEM;
-
-       skb = ieee80211_nullfunc_get(wl->hw, vif);
-       if (!skb)
-               goto out;
-
-       ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV,
-                                     skb->data, skb->len,
-                                     CMD_TEMPL_KLV_IDX_NULL_DATA,
-                                     wlvif->basic_rate);
-
-out:
-       dev_kfree_skb(skb);
-       if (ret)
-               wl1271_warning("cmd build klv null data failed %d", ret);
-
-       return ret;
-
-}
-
-int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                            u16 aid)
-{
-       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-       struct sk_buff *skb;
-       int ret = 0;
-
-       skb = ieee80211_pspoll_get(wl->hw, vif);
-       if (!skb)
-               goto out;
-
-       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
-                                     CMD_TEMPL_PS_POLL, skb->data,
-                                     skb->len, 0, wlvif->basic_rate_set);
-
-out:
-       dev_kfree_skb(skb);
-       return ret;
-}
-
-int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                              u8 role_id, u8 band,
-                              const u8 *ssid, size_t ssid_len,
-                              const u8 *ie, size_t ie_len)
-{
-       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-       struct sk_buff *skb;
-       int ret;
-       u32 rate;
-
-       skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
-                                    ie, ie_len);
-       if (!skb) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
-
-       rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
-       if (band == IEEE80211_BAND_2GHZ)
-               ret = wl1271_cmd_template_set(wl, role_id,
-                                             CMD_TEMPL_CFG_PROBE_REQ_2_4,
-                                             skb->data, skb->len, 0, rate);
-       else
-               ret = wl1271_cmd_template_set(wl, role_id,
-                                             CMD_TEMPL_CFG_PROBE_REQ_5,
-                                             skb->data, skb->len, 0, rate);
-
-out:
-       dev_kfree_skb(skb);
-       return ret;
-}
-
-struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
-                                             struct wl12xx_vif *wlvif,
-                                             struct sk_buff *skb)
-{
-       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-       int ret;
-       u32 rate;
-
-       if (!skb)
-               skb = ieee80211_ap_probereq_get(wl->hw, vif);
-       if (!skb)
-               goto out;
-
-       wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
-
-       rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
-       if (wlvif->band == IEEE80211_BAND_2GHZ)
-               ret = wl1271_cmd_template_set(wl, wlvif->role_id,
-                                             CMD_TEMPL_CFG_PROBE_REQ_2_4,
-                                             skb->data, skb->len, 0, rate);
-       else
-               ret = wl1271_cmd_template_set(wl, wlvif->role_id,
-                                             CMD_TEMPL_CFG_PROBE_REQ_5,
-                                             skb->data, skb->len, 0, rate);
-
-       if (ret < 0)
-               wl1271_error("Unable to set ap probe request template.");
-
-out:
-       return skb;
-}
-
-int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       int ret, extra;
-       u16 fc;
-       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-       struct sk_buff *skb;
-       struct wl12xx_arp_rsp_template *tmpl;
-       struct ieee80211_hdr_3addr *hdr;
-       struct arphdr *arp_hdr;
-
-       skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) +
-                           WL1271_EXTRA_SPACE_MAX);
-       if (!skb) {
-               wl1271_error("failed to allocate buffer for arp rsp template");
-               return -ENOMEM;
-       }
-
-       skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX);
-
-       tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl));
-       memset(tmpl, 0, sizeof(tmpl));
-
-       /* llc layer */
-       memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header));
-       tmpl->llc_type = cpu_to_be16(ETH_P_ARP);
-
-       /* arp header */
-       arp_hdr = &tmpl->arp_hdr;
-       arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
-       arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
-       arp_hdr->ar_hln = ETH_ALEN;
-       arp_hdr->ar_pln = 4;
-       arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
-
-       /* arp payload */
-       memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN);
-       tmpl->sender_ip = wlvif->ip_addr;
-
-       /* encryption space */
-       switch (wlvif->encryption_type) {
-       case KEY_TKIP:
-               extra = WL1271_EXTRA_SPACE_TKIP;
-               break;
-       case KEY_AES:
-               extra = WL1271_EXTRA_SPACE_AES;
-               break;
-       case KEY_NONE:
-       case KEY_WEP:
-       case KEY_GEM:
-               extra = 0;
-               break;
-       default:
-               wl1271_warning("Unknown encryption type: %d",
-                              wlvif->encryption_type);
-               ret = -EINVAL;
-               goto out;
-       }
-
-       if (extra) {
-               u8 *space = skb_push(skb, extra);
-               memset(space, 0, extra);
-       }
-
-       /* QoS header - BE */
-       if (wlvif->sta.qos)
-               memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16));
-
-       /* mac80211 header */
-       hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr));
-       memset(hdr, 0, sizeof(hdr));
-       fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS;
-       if (wlvif->sta.qos)
-               fc |= IEEE80211_STYPE_QOS_DATA;
-       else
-               fc |= IEEE80211_STYPE_DATA;
-       if (wlvif->encryption_type != KEY_NONE)
-               fc |= IEEE80211_FCTL_PROTECTED;
-
-       hdr->frame_control = cpu_to_le16(fc);
-       memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
-       memcpy(hdr->addr2, vif->addr, ETH_ALEN);
-       memset(hdr->addr3, 0xff, ETH_ALEN);
-
-       ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP,
-                                     skb->data, skb->len, 0,
-                                     wlvif->basic_rate);
-out:
-       dev_kfree_skb(skb);
-       return ret;
-}
-
-int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       struct ieee80211_qos_hdr template;
-
-       memset(&template, 0, sizeof(template));
-
-       memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
-       memcpy(template.addr2, vif->addr, ETH_ALEN);
-       memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
-
-       template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
-                                            IEEE80211_STYPE_QOS_NULLFUNC |
-                                            IEEE80211_FCTL_TODS);
-
-       /* FIXME: not sure what priority to use here */
-       template.qos_ctrl = cpu_to_le16(0);
-
-       return wl1271_cmd_template_set(wl, wlvif->role_id,
-                                      CMD_TEMPL_QOS_NULL_DATA, &template,
-                                      sizeof(template), 0,
-                                      wlvif->basic_rate);
-}
-
-int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
-{
-       struct wl1271_cmd_set_keys *cmd;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       cmd->hlid = hlid;
-       cmd->key_id = id;
-       cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
-       cmd->key_action = cpu_to_le16(KEY_SET_ID);
-       cmd->key_type = KEY_WEP;
-
-       ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_warning("cmd set_default_wep_key failed: %d", ret);
-               goto out;
-       }
-
-out:
-       kfree(cmd);
-
-       return ret;
-}
-
-int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                      u16 action, u8 id, u8 key_type,
-                      u8 key_size, const u8 *key, const u8 *addr,
-                      u32 tx_seq_32, u16 tx_seq_16)
-{
-       struct wl1271_cmd_set_keys *cmd;
-       int ret = 0;
-
-       /* hlid might have already been deleted */
-       if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
-               return 0;
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       cmd->hlid = wlvif->sta.hlid;
-
-       if (key_type == KEY_WEP)
-               cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
-       else if (is_broadcast_ether_addr(addr))
-               cmd->lid_key_type = BROADCAST_LID_TYPE;
-       else
-               cmd->lid_key_type = UNICAST_LID_TYPE;
-
-       cmd->key_action = cpu_to_le16(action);
-       cmd->key_size = key_size;
-       cmd->key_type = key_type;
-
-       cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
-       cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
-
-       cmd->key_id = id;
-
-       if (key_type == KEY_TKIP) {
-               /*
-                * We get the key in the following form:
-                * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
-                * but the target is expecting:
-                * TKIP - RX MIC - TX MIC
-                */
-               memcpy(cmd->key, key, 16);
-               memcpy(cmd->key + 16, key + 24, 8);
-               memcpy(cmd->key + 24, key + 16, 8);
-
-       } else {
-               memcpy(cmd->key, key, key_size);
-       }
-
-       wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
-
-       ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_warning("could not set keys");
-       goto out;
-       }
-
-out:
-       kfree(cmd);
-
-       return ret;
-}
-
-/*
- * TODO: merge with sta/ibss into 1 set_key function.
- * note there are slight diffs
- */
-int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                         u16 action, u8 id, u8 key_type,
-                         u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
-                         u16 tx_seq_16)
-{
-       struct wl1271_cmd_set_keys *cmd;
-       int ret = 0;
-       u8 lid_type;
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd)
-               return -ENOMEM;
-
-       if (hlid == wlvif->ap.bcast_hlid) {
-               if (key_type == KEY_WEP)
-                       lid_type = WEP_DEFAULT_LID_TYPE;
-               else
-                       lid_type = BROADCAST_LID_TYPE;
-       } else {
-               lid_type = UNICAST_LID_TYPE;
-       }
-
-       wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
-                    " hlid: %d", (int)action, (int)id, (int)lid_type,
-                    (int)key_type, (int)hlid);
-
-       cmd->lid_key_type = lid_type;
-       cmd->hlid = hlid;
-       cmd->key_action = cpu_to_le16(action);
-       cmd->key_size = key_size;
-       cmd->key_type = key_type;
-       cmd->key_id = id;
-       cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
-       cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
-
-       if (key_type == KEY_TKIP) {
-               /*
-                * We get the key in the following form:
-                * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
-                * but the target is expecting:
-                * TKIP - RX MIC - TX MIC
-                */
-               memcpy(cmd->key, key, 16);
-               memcpy(cmd->key + 16, key + 24, 8);
-               memcpy(cmd->key + 24, key + 16, 8);
-       } else {
-               memcpy(cmd->key, key, key_size);
-       }
-
-       wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
-
-       ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_warning("could not set ap keys");
-               goto out;
-       }
-
-out:
-       kfree(cmd);
-       return ret;
-}
-
-int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid)
-{
-       struct wl12xx_cmd_set_peer_state *cmd;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid);
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       cmd->hlid = hlid;
-       cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
-
-       ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to send set peer state command");
-               goto out_free;
-       }
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                       struct ieee80211_sta *sta, u8 hlid)
-{
-       struct wl12xx_cmd_add_peer *cmd;
-       int i, ret;
-       u32 sta_rates;
-
-       wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       memcpy(cmd->addr, sta->addr, ETH_ALEN);
-       cmd->bss_index = WL1271_AP_BSS_INDEX;
-       cmd->aid = sta->aid;
-       cmd->hlid = hlid;
-       cmd->sp_len = sta->max_sp;
-       cmd->wmm = sta->wme ? 1 : 0;
-
-       for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
-               if (sta->wme && (sta->uapsd_queues & BIT(i)))
-                       cmd->psd_type[i] = WL1271_PSD_UPSD_TRIGGER;
-               else
-                       cmd->psd_type[i] = WL1271_PSD_LEGACY;
-
-       sta_rates = sta->supp_rates[wlvif->band];
-       if (sta->ht_cap.ht_supported)
-               sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET;
-
-       cmd->supported_rates =
-               cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
-                                                       wlvif->band));
-
-       wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
-                    cmd->supported_rates, sta->uapsd_queues);
-
-       ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to initiate cmd add peer");
-               goto out_free;
-       }
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
-{
-       struct wl12xx_cmd_remove_peer *cmd;
-       int ret;
-
-       wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       cmd->hlid = hlid;
-       /* We never send a deauth, mac80211 is in charge of this */
-       cmd->reason_opcode = 0;
-       cmd->send_deauth_flag = 0;
-
-       ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to initiate cmd remove peer");
-               goto out_free;
-       }
-
-       /*
-        * We are ok with a timeout here. The event is sometimes not sent
-        * due to a firmware bug.
-        */
-       wl1271_cmd_wait_for_event_or_timeout(wl,
-                                            PEER_REMOVE_COMPLETE_EVENT_ID);
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
-{
-       struct wl12xx_cmd_config_fwlog *cmd;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       cmd->logger_mode = wl->conf.fwlog.mode;
-       cmd->log_severity = wl->conf.fwlog.severity;
-       cmd->timestamp = wl->conf.fwlog.timestamp;
-       cmd->output = wl->conf.fwlog.output;
-       cmd->threshold = wl->conf.fwlog.threshold;
-
-       ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to send config firmware logger command");
-               goto out_free;
-       }
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
-{
-       struct wl12xx_cmd_start_fwlog *cmd;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to send start firmware logger command");
-               goto out_free;
-       }
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
-{
-       struct wl12xx_cmd_stop_fwlog *cmd;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to send stop firmware logger command");
-               goto out_free;
-       }
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                         u8 role_id)
-{
-       struct wl12xx_cmd_roc *cmd;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
-
-       if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
-               return -EINVAL;
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       cmd->role_id = role_id;
-       cmd->channel = wlvif->channel;
-       switch (wlvif->band) {
-       case IEEE80211_BAND_2GHZ:
-               cmd->band = RADIO_BAND_2_4GHZ;
-               break;
-       case IEEE80211_BAND_5GHZ:
-               cmd->band = RADIO_BAND_5GHZ;
-               break;
-       default:
-               wl1271_error("roc - unknown band: %d", (int)wlvif->band);
-               ret = -EINVAL;
-               goto out_free;
-       }
-
-
-       ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to send ROC command");
-               goto out_free;
-       }
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
-{
-       struct wl12xx_cmd_croc *cmd;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-       cmd->role_id = role_id;
-
-       ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
-                             sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to send ROC command");
-               goto out_free;
-       }
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
-{
-       int ret = 0;
-
-       if (WARN_ON(test_bit(role_id, wl->roc_map)))
-               return 0;
-
-       ret = wl12xx_cmd_roc(wl, wlvif, role_id);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1271_cmd_wait_for_event(wl,
-                                       REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
-       if (ret < 0) {
-               wl1271_error("cmd roc event completion error");
-               goto out;
-       }
-
-       __set_bit(role_id, wl->roc_map);
-out:
-       return ret;
-}
-
-int wl12xx_croc(struct wl1271 *wl, u8 role_id)
-{
-       int ret = 0;
-
-       if (WARN_ON(!test_bit(role_id, wl->roc_map)))
-               return 0;
-
-       ret = wl12xx_cmd_croc(wl, role_id);
-       if (ret < 0)
-               goto out;
-
-       __clear_bit(role_id, wl->roc_map);
-
-       /*
-        * Rearm the tx watchdog when removing the last ROC. This prevents
-        * recoveries due to just finished ROCs - when Tx hasn't yet had
-        * a chance to get out.
-        */
-       if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES)
-               wl12xx_rearm_tx_watchdog_locked(wl);
-out:
-       return ret;
-}
-
-int wl12xx_cmd_channel_switch(struct wl1271 *wl,
-                             struct wl12xx_vif *wlvif,
-                             struct ieee80211_channel_switch *ch_switch)
-{
-       struct wl12xx_cmd_channel_switch *cmd;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "cmd channel switch");
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       cmd->role_id = wlvif->role_id;
-       cmd->channel = ch_switch->channel->hw_value;
-       cmd->switch_time = ch_switch->count;
-       cmd->stop_tx = ch_switch->block_tx;
-
-       /* FIXME: control from mac80211 in the future */
-       cmd->post_switch_tx_disable = 0;  /* Enable TX on the target channel */
-
-       ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to send channel switch command");
-               goto out_free;
-       }
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl)
-{
-       struct wl12xx_cmd_stop_channel_switch *cmd;
-       int ret;
-
-       wl1271_debug(DEBUG_ACX, "cmd stop channel switch");
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("failed to stop channel switch command");
-               goto out_free;
-       }
-
-out_free:
-       kfree(cmd);
-
-out:
-       return ret;
-}
-
-/* start dev role and roc on its channel */
-int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       int ret;
-
-       if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
-                     wlvif->bss_type == BSS_TYPE_IBSS)))
-               return -EINVAL;
-
-       ret = wl12xx_cmd_role_start_dev(wl, wlvif);
-       if (ret < 0)
-               goto out;
-
-       ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id);
-       if (ret < 0)
-               goto out_stop;
-
-       return 0;
-
-out_stop:
-       wl12xx_cmd_role_stop_dev(wl, wlvif);
-out:
-       return ret;
-}
-
-/* croc dev hlid, and stop the role */
-int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       int ret;
-
-       if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
-                     wlvif->bss_type == BSS_TYPE_IBSS)))
-               return -EINVAL;
-
-       /* flush all pending packets */
-       wl1271_tx_work_locked(wl);
-
-       if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
-               ret = wl12xx_croc(wl, wlvif->dev_role_id);
-               if (ret < 0)
-                       goto out;
-       }
-
-       ret = wl12xx_cmd_role_stop_dev(wl, wlvif);
-       if (ret < 0)
-               goto out;
-out:
-       return ret;
-}
diff --git a/drivers/net/wireless/wl12xx/cmd.h b/drivers/net/wireless/wl12xx/cmd.h
deleted file mode 100644 (file)
index de217d9..0000000
+++ /dev/null
@@ -1,728 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
- * Copyright (C) 2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __CMD_H__
-#define __CMD_H__
-
-#include "wl12xx.h"
-
-struct acx_header;
-
-int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
-                   size_t res_len);
-int wl1271_cmd_general_parms(struct wl1271 *wl);
-int wl128x_cmd_general_parms(struct wl1271 *wl);
-int wl1271_cmd_radio_parms(struct wl1271 *wl);
-int wl128x_cmd_radio_parms(struct wl1271 *wl);
-int wl1271_cmd_ext_radio_parms(struct wl1271 *wl);
-int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
-                          u8 *role_id);
-int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id);
-int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer);
-int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len);
-int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len);
-int wl1271_cmd_data_path(struct wl1271 *wl, bool enable);
-int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                      u8 ps_mode, u16 auto_ps_timeout);
-int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
-                          size_t len);
-int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
-                           u16 template_id, void *buf, size_t buf_len,
-                           int index, u32 rates);
-int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                            u16 aid);
-int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                              u8 role_id, u8 band,
-                              const u8 *ssid, size_t ssid_len,
-                              const u8 *ie, size_t ie_len);
-struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
-                                             struct wl12xx_vif *wlvif,
-                                             struct sk_buff *skb);
-int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif);
-int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
-                                  struct wl12xx_vif *wlvif);
-int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid);
-int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                          u16 action, u8 id, u8 key_type,
-                          u8 key_size, const u8 *key, const u8 *addr,
-                          u32 tx_seq_32, u16 tx_seq_16);
-int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                         u16 action, u8 id, u8 key_type,
-                         u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
-                         u16 tx_seq_16);
-int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid);
-int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id);
-int wl12xx_croc(struct wl1271 *wl, u8 role_id);
-int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                       struct ieee80211_sta *sta, u8 hlid);
-int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid);
-int wl12xx_cmd_config_fwlog(struct wl1271 *wl);
-int wl12xx_cmd_start_fwlog(struct wl1271 *wl);
-int wl12xx_cmd_stop_fwlog(struct wl1271 *wl);
-int wl12xx_cmd_channel_switch(struct wl1271 *wl,
-                             struct wl12xx_vif *wlvif,
-                             struct ieee80211_channel_switch *ch_switch);
-int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl);
-int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                        u8 *hlid);
-void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid);
-
-enum wl1271_commands {
-       CMD_INTERROGATE = 1, /* use this to read information elements */
-       CMD_CONFIGURE   = 2, /* use this to write information elements */
-       CMD_ENABLE_RX   = 3,
-       CMD_ENABLE_TX   = 4,
-       CMD_DISABLE_RX  = 5,
-       CMD_DISABLE_TX  = 6,
-       CMD_SCAN        = 7,
-       CMD_STOP_SCAN   = 8,
-       CMD_SET_KEYS    = 9,
-       CMD_READ_MEMORY = 10,
-       CMD_WRITE_MEMORY        = 11,
-       CMD_SET_TEMPLATE        = 12,
-       CMD_TEST                = 13,
-       CMD_NOISE_HIST          = 14,
-       CMD_QUIET_ELEMENT_SET_STATE = 15,
-       CMD_SET_BCN_MODE        = 16,
-
-       CMD_MEASUREMENT         = 17,
-       CMD_STOP_MEASUREMENT    = 18,
-       CMD_SET_PS_MODE         = 19,
-       CMD_CHANNEL_SWITCH      = 20,
-       CMD_STOP_CHANNEL_SWICTH = 21,
-       CMD_AP_DISCOVERY        = 22,
-       CMD_STOP_AP_DISCOVERY   = 23,
-       CMD_HEALTH_CHECK        = 24,
-       CMD_DEBUG               = 25,
-       CMD_TRIGGER_SCAN_TO     = 26,
-       CMD_CONNECTION_SCAN_CFG = 27,
-       CMD_CONNECTION_SCAN_SSID_CFG    = 28,
-       CMD_START_PERIODIC_SCAN = 29,
-       CMD_STOP_PERIODIC_SCAN  = 30,
-       CMD_SET_PEER_STATE      = 31,
-       CMD_REMAIN_ON_CHANNEL   = 32,
-       CMD_CANCEL_REMAIN_ON_CHANNEL    = 33,
-       CMD_CONFIG_FWLOGGER             = 34,
-       CMD_START_FWLOGGER                      = 35,
-       CMD_STOP_FWLOGGER                       = 36,
-
-       /* Access point commands */
-       CMD_ADD_PEER            = 37,
-       CMD_REMOVE_PEER         = 38,
-
-       /* Role API */
-       CMD_ROLE_ENABLE         = 39,
-       CMD_ROLE_DISABLE        = 40,
-       CMD_ROLE_START          = 41,
-       CMD_ROLE_STOP           = 42,
-
-       /* DFS */
-       CMD_START_RADAR_DETECTION       = 43,
-       CMD_STOP_RADAR_DETECTION        = 44,
-
-       /* WIFI Direct */
-       CMD_WFD_START_DISCOVERY = 45,
-       CMD_WFD_STOP_DISCOVERY  = 46,
-       CMD_WFD_ATTRIBUTE_CONFIG        = 47,
-       CMD_NOP                 = 48,
-       CMD_LAST_COMMAND,
-
-       MAX_COMMAND_ID = 0xFFFF,
-};
-
-#define MAX_CMD_PARAMS 572
-
-enum {
-       CMD_TEMPL_KLV_IDX_NULL_DATA = 0,
-       CMD_TEMPL_KLV_IDX_MAX = 4
-};
-
-enum cmd_templ {
-       CMD_TEMPL_NULL_DATA = 0,
-       CMD_TEMPL_BEACON,
-       CMD_TEMPL_CFG_PROBE_REQ_2_4,
-       CMD_TEMPL_CFG_PROBE_REQ_5,
-       CMD_TEMPL_PROBE_RESPONSE,
-       CMD_TEMPL_QOS_NULL_DATA,
-       CMD_TEMPL_PS_POLL,
-       CMD_TEMPL_KLV,
-       CMD_TEMPL_DISCONNECT,
-       CMD_TEMPL_PROBE_REQ_2_4, /* for firmware internal use only */
-       CMD_TEMPL_PROBE_REQ_5,   /* for firmware internal use only */
-       CMD_TEMPL_BAR,           /* for firmware internal use only */
-       CMD_TEMPL_CTS,           /*
-                                 * For CTS-to-self (FastCTS) mechanism
-                                 * for BT/WLAN coexistence (SoftGemini). */
-       CMD_TEMPL_AP_BEACON,
-       CMD_TEMPL_AP_PROBE_RESPONSE,
-       CMD_TEMPL_ARP_RSP,
-       CMD_TEMPL_DEAUTH_AP,
-       CMD_TEMPL_TEMPORARY,
-       CMD_TEMPL_LINK_MEASUREMENT_REPORT,
-
-       CMD_TEMPL_MAX = 0xff
-};
-
-/* unit ms */
-#define WL1271_COMMAND_TIMEOUT     2000
-#define WL1271_CMD_TEMPL_DFLT_SIZE 252
-#define WL1271_CMD_TEMPL_MAX_SIZE  512
-#define WL1271_EVENT_TIMEOUT       750
-
-struct wl1271_cmd_header {
-       __le16 id;
-       __le16 status;
-       /* payload */
-       u8 data[0];
-} __packed;
-
-#define WL1271_CMD_MAX_PARAMS 572
-
-struct wl1271_command {
-       struct wl1271_cmd_header header;
-       u8  parameters[WL1271_CMD_MAX_PARAMS];
-} __packed;
-
-enum {
-       CMD_MAILBOX_IDLE                =  0,
-       CMD_STATUS_SUCCESS              =  1,
-       CMD_STATUS_UNKNOWN_CMD          =  2,
-       CMD_STATUS_UNKNOWN_IE           =  3,
-       CMD_STATUS_REJECT_MEAS_SG_ACTIVE        = 11,
-       CMD_STATUS_RX_BUSY              = 13,
-       CMD_STATUS_INVALID_PARAM                = 14,
-       CMD_STATUS_TEMPLATE_TOO_LARGE           = 15,
-       CMD_STATUS_OUT_OF_MEMORY                = 16,
-       CMD_STATUS_STA_TABLE_FULL               = 17,
-       CMD_STATUS_RADIO_ERROR          = 18,
-       CMD_STATUS_WRONG_NESTING                = 19,
-       CMD_STATUS_TIMEOUT              = 21, /* Driver internal use.*/
-       CMD_STATUS_FW_RESET             = 22, /* Driver internal use.*/
-       CMD_STATUS_TEMPLATE_OOM         = 23,
-       CMD_STATUS_NO_RX_BA_SESSION     = 24,
-       MAX_COMMAND_STATUS              = 0xff
-};
-
-#define CMDMBOX_HEADER_LEN 4
-#define CMDMBOX_INFO_ELEM_HEADER_LEN 4
-
-enum {
-       BSS_TYPE_IBSS = 0,
-       BSS_TYPE_STA_BSS = 2,
-       BSS_TYPE_AP_BSS = 3,
-       MAX_BSS_TYPE = 0xFF
-};
-
-#define WL1271_JOIN_CMD_CTRL_TX_FLUSH     0x80 /* Firmware flushes all Tx */
-#define WL1271_JOIN_CMD_TX_SESSION_OFFSET 1
-#define WL1271_JOIN_CMD_BSS_TYPE_5GHZ 0x10
-
-struct wl12xx_cmd_role_enable {
-       struct wl1271_cmd_header header;
-
-       u8 role_id;
-       u8 role_type;
-       u8 mac_address[ETH_ALEN];
-} __packed;
-
-struct wl12xx_cmd_role_disable {
-       struct wl1271_cmd_header header;
-
-       u8 role_id;
-       u8 padding[3];
-} __packed;
-
-enum wl12xx_band {
-       WL12XX_BAND_2_4GHZ              = 0,
-       WL12XX_BAND_5GHZ                = 1,
-       WL12XX_BAND_JAPAN_4_9_GHZ       = 2,
-       WL12XX_BAND_DEFAULT             = WL12XX_BAND_2_4GHZ,
-       WL12XX_BAND_INVALID             = 0x7E,
-       WL12XX_BAND_MAX_RADIO           = 0x7F,
-};
-
-struct wl12xx_cmd_role_start {
-       struct wl1271_cmd_header header;
-
-       u8 role_id;
-       u8 band;
-       u8 channel;
-       u8 padding;
-
-       union {
-               struct {
-                       u8 hlid;
-                       u8 session;
-                       u8 padding_1[54];
-               } __packed device;
-               /* sta & p2p_cli use the same struct */
-               struct {
-                       u8 bssid[ETH_ALEN];
-                       u8 hlid; /* data hlid */
-                       u8 session;
-                       __le32 remote_rates; /* remote supported rates */
-
-                       /*
-                        * The target uses this field to determine the rate at
-                        * which to transmit control frame responses (such as
-                        * ACK or CTS frames).
-                        */
-                       __le32 basic_rate_set;
-                       __le32 local_rates; /* local supported rates */
-
-                       u8 ssid_type;
-                       u8 ssid_len;
-                       u8 ssid[IEEE80211_MAX_SSID_LEN];
-
-                       __le16 beacon_interval; /* in TBTTs */
-               } __packed sta;
-               struct {
-                       u8 bssid[ETH_ALEN];
-                       u8 hlid; /* data hlid */
-                       u8 dtim_interval;
-                       __le32 remote_rates; /* remote supported rates */
-
-                       __le32 basic_rate_set;
-                       __le32 local_rates; /* local supported rates */
-
-                       u8 ssid_type;
-                       u8 ssid_len;
-                       u8 ssid[IEEE80211_MAX_SSID_LEN];
-
-                       __le16 beacon_interval; /* in TBTTs */
-
-                       u8 padding_1[4];
-               } __packed ibss;
-               /* ap & p2p_go use the same struct */
-               struct {
-                       __le16 aging_period; /* in secs */
-                       u8 beacon_expiry; /* in ms */
-                       u8 bss_index;
-                       /* The host link id for the AP's global queue */
-                       u8 global_hlid;
-                       /* The host link id for the AP's broadcast queue */
-                       u8 broadcast_hlid;
-
-                       __le16 beacon_interval; /* in TBTTs */
-
-                       __le32 basic_rate_set;
-                       __le32 local_rates; /* local supported rates */
-
-                       u8 dtim_interval;
-
-                       u8 ssid_type;
-                       u8 ssid_len;
-                       u8 ssid[IEEE80211_MAX_SSID_LEN];
-
-                       u8 reset_tsf;
-
-                       u8 padding_1[4];
-               } __packed ap;
-       };
-} __packed;
-
-struct wl12xx_cmd_role_stop {
-       struct wl1271_cmd_header header;
-
-       u8 role_id;
-       u8 disc_type; /* only STA and P2P_CLI */
-       __le16 reason; /* only STA and P2P_CLI */
-} __packed;
-
-struct cmd_enabledisable_path {
-       struct wl1271_cmd_header header;
-
-       u8 channel;
-       u8 padding[3];
-} __packed;
-
-#define WL1271_RATE_AUTOMATIC  0
-
-struct wl1271_cmd_template_set {
-       struct wl1271_cmd_header header;
-
-       u8 role_id;
-       u8 template_type;
-       __le16 len;
-       u8 index;  /* relevant only for KLV_TEMPLATE type */
-       u8 padding[3];
-
-       __le32 enabled_rates;
-       u8 short_retry_limit;
-       u8 long_retry_limit;
-       u8 aflags;
-       u8 reserved;
-
-       u8 template_data[WL1271_CMD_TEMPL_MAX_SIZE];
-} __packed;
-
-#define TIM_ELE_ID    5
-#define PARTIAL_VBM_MAX    251
-
-struct wl1271_tim {
-       u8 identity;
-       u8 length;
-       u8 dtim_count;
-       u8 dtim_period;
-       u8 bitmap_ctrl;
-       u8 pvb_field[PARTIAL_VBM_MAX]; /* Partial Virtual Bitmap */
-} __packed;
-
-enum wl1271_cmd_ps_mode {
-       STATION_AUTO_PS_MODE,   /* Dynamic Power Save */
-       STATION_ACTIVE_MODE,
-       STATION_POWER_SAVE_MODE
-};
-
-struct wl1271_cmd_ps_params {
-       struct wl1271_cmd_header header;
-
-       u8 role_id;
-       u8 ps_mode; /* STATION_* */
-       u16 auto_ps_timeout;
-} __packed;
-
-/* HW encryption keys */
-#define NUM_ACCESS_CATEGORIES_COPY 4
-
-enum wl1271_cmd_key_action {
-       KEY_ADD_OR_REPLACE = 1,
-       KEY_REMOVE         = 2,
-       KEY_SET_ID         = 3,
-       MAX_KEY_ACTION     = 0xffff,
-};
-
-enum wl1271_cmd_lid_key_type {
-       UNICAST_LID_TYPE     = 0,
-       BROADCAST_LID_TYPE   = 1,
-       WEP_DEFAULT_LID_TYPE = 2
-};
-
-enum wl1271_cmd_key_type {
-       KEY_NONE = 0,
-       KEY_WEP  = 1,
-       KEY_TKIP = 2,
-       KEY_AES  = 3,
-       KEY_GEM  = 4,
-};
-
-struct wl1271_cmd_set_keys {
-       struct wl1271_cmd_header header;
-
-       /*
-        * Indicates whether the HLID is a unicast key set
-        * or broadcast key set. A special value 0xFF is
-        * used to indicate that the HLID is on WEP-default
-        * (multi-hlids). of type wl1271_cmd_lid_key_type.
-        */
-       u8 hlid;
-
-       /*
-        * In WEP-default network (hlid == 0xFF) used to
-        * indicate which network STA/IBSS/AP role should be
-        * changed
-        */
-       u8 lid_key_type;
-
-       /*
-        * Key ID - For TKIP and AES key types, this field
-        * indicates the value that should be inserted into
-        * the KeyID field of frames transmitted using this
-        * key entry. For broadcast keys the index use as a
-        * marker for TX/RX key.
-        * For WEP default network (HLID=0xFF), this field
-        * indicates the ID of the key to add or remove.
-        */
-       u8 key_id;
-       u8 reserved_1;
-
-       /* key_action_e */
-       __le16 key_action;
-
-       /* key size in bytes */
-       u8 key_size;
-
-       /* key_type_e */
-       u8 key_type;
-
-       /* This field holds the security key data to add to the STA table */
-       u8 key[MAX_KEY_SIZE];
-       __le16 ac_seq_num16[NUM_ACCESS_CATEGORIES_COPY];
-       __le32 ac_seq_num32[NUM_ACCESS_CATEGORIES_COPY];
-} __packed;
-
-struct wl1271_cmd_test_header {
-       u8 id;
-       u8 padding[3];
-} __packed;
-
-enum wl1271_channel_tune_bands {
-       WL1271_CHANNEL_TUNE_BAND_2_4,
-       WL1271_CHANNEL_TUNE_BAND_5,
-       WL1271_CHANNEL_TUNE_BAND_4_9
-};
-
-#define WL1271_PD_REFERENCE_POINT_BAND_B_G  0
-
-#define TEST_CMD_INI_FILE_RADIO_PARAM       0x19
-#define TEST_CMD_INI_FILE_GENERAL_PARAM     0x1E
-#define TEST_CMD_INI_FILE_RF_EXTENDED_PARAM 0x26
-
-struct wl1271_general_parms_cmd {
-       struct wl1271_cmd_header header;
-
-       struct wl1271_cmd_test_header test;
-
-       struct wl1271_ini_general_params general_params;
-
-       u8 sr_debug_table[WL1271_INI_MAX_SMART_REFLEX_PARAM];
-       u8 sr_sen_n_p;
-       u8 sr_sen_n_p_gain;
-       u8 sr_sen_nrn;
-       u8 sr_sen_prn;
-       u8 padding[3];
-} __packed;
-
-struct wl128x_general_parms_cmd {
-       struct wl1271_cmd_header header;
-
-       struct wl1271_cmd_test_header test;
-
-       struct wl128x_ini_general_params general_params;
-
-       u8 sr_debug_table[WL1271_INI_MAX_SMART_REFLEX_PARAM];
-       u8 sr_sen_n_p;
-       u8 sr_sen_n_p_gain;
-       u8 sr_sen_nrn;
-       u8 sr_sen_prn;
-       u8 padding[3];
-} __packed;
-
-struct wl1271_radio_parms_cmd {
-       struct wl1271_cmd_header header;
-
-       struct wl1271_cmd_test_header test;
-
-       /* Static radio parameters */
-       struct wl1271_ini_band_params_2 static_params_2;
-       struct wl1271_ini_band_params_5 static_params_5;
-
-       /* Dynamic radio parameters */
-       struct wl1271_ini_fem_params_2 dyn_params_2;
-       u8 padding2;
-       struct wl1271_ini_fem_params_5 dyn_params_5;
-       u8 padding3[2];
-} __packed;
-
-struct wl128x_radio_parms_cmd {
-       struct wl1271_cmd_header header;
-
-       struct wl1271_cmd_test_header test;
-
-       /* Static radio parameters */
-       struct wl128x_ini_band_params_2 static_params_2;
-       struct wl128x_ini_band_params_5 static_params_5;
-
-       u8 fem_vendor_and_options;
-
-       /* Dynamic radio parameters */
-       struct wl128x_ini_fem_params_2 dyn_params_2;
-       u8 padding2;
-       struct wl128x_ini_fem_params_5 dyn_params_5;
-} __packed;
-
-struct wl1271_ext_radio_parms_cmd {
-       struct wl1271_cmd_header header;
-
-       struct wl1271_cmd_test_header test;
-
-       u8 tx_per_channel_power_compensation_2[CONF_TX_PWR_COMPENSATION_LEN_2];
-       u8 tx_per_channel_power_compensation_5[CONF_TX_PWR_COMPENSATION_LEN_5];
-       u8 padding[3];
-} __packed;
-
-/*
- * There are three types of disconnections:
- *
- * DISCONNECT_IMMEDIATE: the fw doesn't send any frames
- * DISCONNECT_DEAUTH:    the fw generates a DEAUTH request with the reason
- *                       we have passed
- * DISCONNECT_DISASSOC:  the fw generates a DESASSOC request with the reason
- *                       we have passed
- */
-enum wl1271_disconnect_type {
-       DISCONNECT_IMMEDIATE,
-       DISCONNECT_DEAUTH,
-       DISCONNECT_DISASSOC
-};
-
-#define WL1271_CMD_STA_STATE_CONNECTED  1
-
-struct wl12xx_cmd_set_peer_state {
-       struct wl1271_cmd_header header;
-
-       u8 hlid;
-       u8 state;
-       u8 padding[2];
-} __packed;
-
-struct wl12xx_cmd_roc {
-       struct wl1271_cmd_header header;
-
-       u8 role_id;
-       u8 channel;
-       u8 band;
-       u8 padding;
-};
-
-struct wl12xx_cmd_croc {
-       struct wl1271_cmd_header header;
-
-       u8 role_id;
-       u8 padding[3];
-};
-
-enum wl12xx_ssid_type {
-       WL12XX_SSID_TYPE_PUBLIC = 0,
-       WL12XX_SSID_TYPE_HIDDEN = 1,
-       WL12XX_SSID_TYPE_ANY = 2,
-};
-
-enum wl1271_psd_type {
-       WL1271_PSD_LEGACY = 0,
-       WL1271_PSD_UPSD_TRIGGER = 1,
-       WL1271_PSD_LEGACY_PSPOLL = 2,
-       WL1271_PSD_SAPSD = 3
-};
-
-struct wl12xx_cmd_add_peer {
-       struct wl1271_cmd_header header;
-
-       u8 addr[ETH_ALEN];
-       u8 hlid;
-       u8 aid;
-       u8 psd_type[NUM_ACCESS_CATEGORIES_COPY];
-       __le32 supported_rates;
-       u8 bss_index;
-       u8 sp_len;
-       u8 wmm;
-       u8 padding1;
-} __packed;
-
-struct wl12xx_cmd_remove_peer {
-       struct wl1271_cmd_header header;
-
-       u8 hlid;
-       u8 reason_opcode;
-       u8 send_deauth_flag;
-       u8 padding1;
-} __packed;
-
-/*
- * Continuous mode - packets are transferred to the host periodically
- * via the data path.
- * On demand - Log messages are stored in a cyclic buffer in the
- * firmware, and only transferred to the host when explicitly requested
- */
-enum wl12xx_fwlogger_log_mode {
-       WL12XX_FWLOG_CONTINUOUS,
-       WL12XX_FWLOG_ON_DEMAND
-};
-
-/* Include/exclude timestamps from the log messages */
-enum wl12xx_fwlogger_timestamp {
-       WL12XX_FWLOG_TIMESTAMP_DISABLED,
-       WL12XX_FWLOG_TIMESTAMP_ENABLED
-};
-
-/*
- * Logs can be routed to the debug pinouts (where available), to the host bus
- * (SDIO/SPI), or dropped
- */
-enum wl12xx_fwlogger_output {
-       WL12XX_FWLOG_OUTPUT_NONE,
-       WL12XX_FWLOG_OUTPUT_DBG_PINS,
-       WL12XX_FWLOG_OUTPUT_HOST,
-};
-
-struct wl12xx_cmd_config_fwlog {
-       struct wl1271_cmd_header header;
-
-       /* See enum wl12xx_fwlogger_log_mode */
-       u8 logger_mode;
-
-       /* Minimum log level threshold */
-       u8 log_severity;
-
-       /* Include/exclude timestamps from the log messages */
-       u8 timestamp;
-
-       /* See enum wl1271_fwlogger_output */
-       u8 output;
-
-       /* Regulates the frequency of log messages */
-       u8 threshold;
-
-       u8 padding[3];
-} __packed;
-
-struct wl12xx_cmd_start_fwlog {
-       struct wl1271_cmd_header header;
-} __packed;
-
-struct wl12xx_cmd_stop_fwlog {
-       struct wl1271_cmd_header header;
-} __packed;
-
-struct wl12xx_cmd_channel_switch {
-       struct wl1271_cmd_header header;
-
-       u8 role_id;
-
-       /* The new serving channel */
-       u8 channel;
-       /* Relative time of the serving channel switch in TBTT units */
-       u8 switch_time;
-       /* Stop the role TX, should expect it after radar detection */
-       u8 stop_tx;
-       /* The target channel tx status 1-stopped 0-open*/
-       u8 post_switch_tx_disable;
-
-       u8 padding[3];
-} __packed;
-
-struct wl12xx_cmd_stop_channel_switch {
-       struct wl1271_cmd_header header;
-} __packed;
-
-#endif /* __WL1271_CMD_H__ */
diff --git a/drivers/net/wireless/wl12xx/conf.h b/drivers/net/wireless/wl12xx/conf.h
deleted file mode 100644 (file)
index 3e581e1..0000000
+++ /dev/null
@@ -1,1311 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __CONF_H__
-#define __CONF_H__
-
-enum {
-       CONF_HW_BIT_RATE_1MBPS   = BIT(0),
-       CONF_HW_BIT_RATE_2MBPS   = BIT(1),
-       CONF_HW_BIT_RATE_5_5MBPS = BIT(2),
-       CONF_HW_BIT_RATE_6MBPS   = BIT(3),
-       CONF_HW_BIT_RATE_9MBPS   = BIT(4),
-       CONF_HW_BIT_RATE_11MBPS  = BIT(5),
-       CONF_HW_BIT_RATE_12MBPS  = BIT(6),
-       CONF_HW_BIT_RATE_18MBPS  = BIT(7),
-       CONF_HW_BIT_RATE_22MBPS  = BIT(8),
-       CONF_HW_BIT_RATE_24MBPS  = BIT(9),
-       CONF_HW_BIT_RATE_36MBPS  = BIT(10),
-       CONF_HW_BIT_RATE_48MBPS  = BIT(11),
-       CONF_HW_BIT_RATE_54MBPS  = BIT(12),
-       CONF_HW_BIT_RATE_MCS_0   = BIT(13),
-       CONF_HW_BIT_RATE_MCS_1   = BIT(14),
-       CONF_HW_BIT_RATE_MCS_2   = BIT(15),
-       CONF_HW_BIT_RATE_MCS_3   = BIT(16),
-       CONF_HW_BIT_RATE_MCS_4   = BIT(17),
-       CONF_HW_BIT_RATE_MCS_5   = BIT(18),
-       CONF_HW_BIT_RATE_MCS_6   = BIT(19),
-       CONF_HW_BIT_RATE_MCS_7   = BIT(20)
-};
-
-enum {
-       CONF_HW_RATE_INDEX_1MBPS   = 0,
-       CONF_HW_RATE_INDEX_2MBPS   = 1,
-       CONF_HW_RATE_INDEX_5_5MBPS = 2,
-       CONF_HW_RATE_INDEX_6MBPS   = 3,
-       CONF_HW_RATE_INDEX_9MBPS   = 4,
-       CONF_HW_RATE_INDEX_11MBPS  = 5,
-       CONF_HW_RATE_INDEX_12MBPS  = 6,
-       CONF_HW_RATE_INDEX_18MBPS  = 7,
-       CONF_HW_RATE_INDEX_22MBPS  = 8,
-       CONF_HW_RATE_INDEX_24MBPS  = 9,
-       CONF_HW_RATE_INDEX_36MBPS  = 10,
-       CONF_HW_RATE_INDEX_48MBPS  = 11,
-       CONF_HW_RATE_INDEX_54MBPS  = 12,
-       CONF_HW_RATE_INDEX_MAX     = CONF_HW_RATE_INDEX_54MBPS,
-};
-
-enum {
-       CONF_HW_RXTX_RATE_MCS7_SGI = 0,
-       CONF_HW_RXTX_RATE_MCS7,
-       CONF_HW_RXTX_RATE_MCS6,
-       CONF_HW_RXTX_RATE_MCS5,
-       CONF_HW_RXTX_RATE_MCS4,
-       CONF_HW_RXTX_RATE_MCS3,
-       CONF_HW_RXTX_RATE_MCS2,
-       CONF_HW_RXTX_RATE_MCS1,
-       CONF_HW_RXTX_RATE_MCS0,
-       CONF_HW_RXTX_RATE_54,
-       CONF_HW_RXTX_RATE_48,
-       CONF_HW_RXTX_RATE_36,
-       CONF_HW_RXTX_RATE_24,
-       CONF_HW_RXTX_RATE_22,
-       CONF_HW_RXTX_RATE_18,
-       CONF_HW_RXTX_RATE_12,
-       CONF_HW_RXTX_RATE_11,
-       CONF_HW_RXTX_RATE_9,
-       CONF_HW_RXTX_RATE_6,
-       CONF_HW_RXTX_RATE_5_5,
-       CONF_HW_RXTX_RATE_2,
-       CONF_HW_RXTX_RATE_1,
-       CONF_HW_RXTX_RATE_MAX,
-       CONF_HW_RXTX_RATE_UNSUPPORTED = 0xff
-};
-
-/* Rates between and including these are MCS rates */
-#define CONF_HW_RXTX_RATE_MCS_MIN CONF_HW_RXTX_RATE_MCS7_SGI
-#define CONF_HW_RXTX_RATE_MCS_MAX CONF_HW_RXTX_RATE_MCS0
-
-enum {
-       CONF_SG_DISABLE = 0,
-       CONF_SG_PROTECTIVE,
-       CONF_SG_OPPORTUNISTIC
-};
-
-enum {
-       /*
-        * Configure the min and max time BT gains the antenna
-        * in WLAN / BT master basic rate
-        *
-        * Range: 0 - 255 (ms)
-        */
-       CONF_SG_ACL_BT_MASTER_MIN_BR = 0,
-       CONF_SG_ACL_BT_MASTER_MAX_BR,
-
-       /*
-        * Configure the min and max time BT gains the antenna
-        * in WLAN / BT slave basic rate
-        *
-        * Range: 0 - 255 (ms)
-        */
-       CONF_SG_ACL_BT_SLAVE_MIN_BR,
-       CONF_SG_ACL_BT_SLAVE_MAX_BR,
-
-       /*
-        * Configure the min and max time BT gains the antenna
-        * in WLAN / BT master EDR
-        *
-        * Range: 0 - 255 (ms)
-        */
-       CONF_SG_ACL_BT_MASTER_MIN_EDR,
-       CONF_SG_ACL_BT_MASTER_MAX_EDR,
-
-       /*
-        * Configure the min and max time BT gains the antenna
-        * in WLAN / BT slave EDR
-        *
-        * Range: 0 - 255 (ms)
-        */
-       CONF_SG_ACL_BT_SLAVE_MIN_EDR,
-       CONF_SG_ACL_BT_SLAVE_MAX_EDR,
-
-       /*
-        * The maximum time WLAN can gain the antenna
-        * in WLAN PSM / BT master/slave BR
-        *
-        * Range: 0 - 255 (ms)
-        */
-       CONF_SG_ACL_WLAN_PS_MASTER_BR,
-       CONF_SG_ACL_WLAN_PS_SLAVE_BR,
-
-       /*
-        * The maximum time WLAN can gain the antenna
-        * in WLAN PSM / BT master/slave EDR
-        *
-        * Range: 0 - 255 (ms)
-        */
-       CONF_SG_ACL_WLAN_PS_MASTER_EDR,
-       CONF_SG_ACL_WLAN_PS_SLAVE_EDR,
-
-       /* TODO: explain these values */
-       CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR,
-       CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR,
-       CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR,
-       CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR,
-       CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR,
-       CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR,
-       CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR,
-       CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR,
-
-       CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR,
-       CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR,
-       CONF_SG_ACL_PASSIVE_SCAN_BT_BR,
-       CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR,
-       CONF_SG_ACL_PASSIVE_SCAN_BT_EDR,
-       CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR,
-
-       /*
-        * Compensation percentage of probe requests when scan initiated
-        * during BT voice/ACL link.
-        *
-        * Range: 0 - 255 (%)
-        */
-       CONF_SG_AUTO_SCAN_PROBE_REQ,
-
-       /*
-        * Compensation percentage of probe requests when active scan initiated
-        * during BT voice
-        *
-        * Range: 0 - 255 (%)
-        */
-       CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3,
-
-       /*
-        * Compensation percentage of WLAN active scan window if initiated
-        * during BT A2DP
-        *
-        * Range: 0 - 1000 (%)
-        */
-       CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP,
-
-       /*
-        * Compensation percentage of WLAN passive scan window if initiated
-        * during BT A2DP BR
-        *
-        * Range: 0 - 1000 (%)
-        */
-       CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR,
-
-       /*
-        * Compensation percentage of WLAN passive scan window if initiated
-        * during BT A2DP EDR
-        *
-        * Range: 0 - 1000 (%)
-        */
-       CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR,
-
-       /*
-        * Compensation percentage of WLAN passive scan window if initiated
-        * during BT voice
-        *
-        * Range: 0 - 1000 (%)
-        */
-       CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3,
-
-       /* TODO: explain these values */
-       CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN,
-       CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN,
-       CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN,
-
-       /*
-        * Defines whether the SG will force WLAN host to enter/exit PSM
-        *
-        * Range: 1 - SG can force, 0 - host handles PSM
-        */
-       CONF_SG_STA_FORCE_PS_IN_BT_SCO,
-
-       /*
-        * Defines antenna configuration (single/dual antenna)
-        *
-        * Range: 0 - single antenna, 1 - dual antenna
-        */
-       CONF_SG_ANTENNA_CONFIGURATION,
-
-       /*
-        * The threshold (percent) of max consecutive beacon misses before
-        * increasing priority of beacon reception.
-        *
-        * Range: 0 - 100 (%)
-        */
-       CONF_SG_BEACON_MISS_PERCENT,
-
-       /*
-        * Protection time of the DHCP procedure.
-        *
-        * Range: 0 - 100000 (ms)
-        */
-       CONF_SG_DHCP_TIME,
-
-       /*
-        * RX guard time before the beginning of a new BT voice frame during
-        * which no new WLAN trigger frame is transmitted.
-        *
-        * Range: 0 - 100000 (us)
-        */
-       CONF_SG_RXT,
-
-       /*
-        * TX guard time before the beginning of a new BT voice frame during
-        * which no new WLAN frame is transmitted.
-        *
-        * Range: 0 - 100000 (us)
-        */
-
-       CONF_SG_TXT,
-
-       /*
-        * Enable adaptive RXT/TXT algorithm. If disabled, the host values
-        * will be utilized.
-        *
-        * Range: 0 - disable, 1 - enable
-        */
-       CONF_SG_ADAPTIVE_RXT_TXT,
-
-       /* TODO: explain this value */
-       CONF_SG_GENERAL_USAGE_BIT_MAP,
-
-       /*
-        * Number of consecutive BT voice frames not interrupted by WLAN
-        *
-        * Range: 0 - 100
-        */
-       CONF_SG_HV3_MAX_SERVED,
-
-       /*
-        * The used WLAN legacy service period during active BT ACL link
-        *
-        * Range: 0 - 255 (ms)
-        */
-       CONF_SG_PS_POLL_TIMEOUT,
-
-       /*
-        * The used WLAN UPSD service period during active BT ACL link
-        *
-        * Range: 0 - 255 (ms)
-        */
-       CONF_SG_UPSD_TIMEOUT,
-
-       CONF_SG_CONSECUTIVE_CTS_THRESHOLD,
-       CONF_SG_STA_RX_WINDOW_AFTER_DTIM,
-       CONF_SG_STA_CONNECTION_PROTECTION_TIME,
-
-       /* AP params */
-       CONF_AP_BEACON_MISS_TX,
-       CONF_AP_RX_WINDOW_AFTER_BEACON,
-       CONF_AP_BEACON_WINDOW_INTERVAL,
-       CONF_AP_CONNECTION_PROTECTION_TIME,
-       CONF_AP_BT_ACL_VAL_BT_SERVE_TIME,
-       CONF_AP_BT_ACL_VAL_WL_SERVE_TIME,
-
-       /* CTS Diluting params */
-       CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH,
-       CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER,
-
-       CONF_SG_TEMP_PARAM_1,
-       CONF_SG_TEMP_PARAM_2,
-       CONF_SG_TEMP_PARAM_3,
-       CONF_SG_TEMP_PARAM_4,
-       CONF_SG_TEMP_PARAM_5,
-       CONF_SG_TEMP_PARAM_6,
-       CONF_SG_TEMP_PARAM_7,
-       CONF_SG_TEMP_PARAM_8,
-       CONF_SG_TEMP_PARAM_9,
-       CONF_SG_TEMP_PARAM_10,
-
-       CONF_SG_PARAMS_MAX,
-       CONF_SG_PARAMS_ALL = 0xff
-};
-
-struct conf_sg_settings {
-       u32 params[CONF_SG_PARAMS_MAX];
-       u8 state;
-};
-
-enum conf_rx_queue_type {
-       CONF_RX_QUEUE_TYPE_LOW_PRIORITY,  /* All except the high priority */
-       CONF_RX_QUEUE_TYPE_HIGH_PRIORITY, /* Management and voice packets */
-};
-
-struct conf_rx_settings {
-       /*
-        * The maximum amount of time, in TU, before the
-        * firmware discards the MSDU.
-        *
-        * Range: 0 - 0xFFFFFFFF
-        */
-       u32 rx_msdu_life_time;
-
-       /*
-        * Packet detection threshold in the PHY.
-        *
-        * FIXME: details unknown.
-        */
-       u32 packet_detection_threshold;
-
-       /*
-        * The longest time the STA will wait to receive traffic from the AP
-        * after a PS-poll has been transmitted.
-        *
-        * Range: 0 - 200000
-        */
-       u16 ps_poll_timeout;
-       /*
-        * The longest time the STA will wait to receive traffic from the AP
-        * after a frame has been sent from an UPSD enabled queue.
-        *
-        * Range: 0 - 200000
-        */
-       u16 upsd_timeout;
-
-       /*
-        * The number of octets in an MPDU, below which an RTS/CTS
-        * handshake is not performed.
-        *
-        * Range: 0 - 4096
-        */
-       u16 rts_threshold;
-
-       /*
-        * The RX Clear Channel Assessment threshold in the PHY
-        * (the energy threshold).
-        *
-        * Range: ENABLE_ENERGY_D  == 0x140A
-        *        DISABLE_ENERGY_D == 0xFFEF
-        */
-       u16 rx_cca_threshold;
-
-       /*
-        * Occupied Rx mem-blocks number which requires interrupting the host
-        * (0 = no buffering, 0xffff = disabled).
-        *
-        * Range: u16
-        */
-       u16 irq_blk_threshold;
-
-       /*
-        * Rx packets number which requires interrupting the host
-        * (0 = no buffering).
-        *
-        * Range: u16
-        */
-       u16 irq_pkt_threshold;
-
-       /*
-        * Max time in msec the FW may delay RX-Complete interrupt.
-        *
-        * Range: 1 - 100
-        */
-       u16 irq_timeout;
-
-       /*
-        * The RX queue type.
-        *
-        * Range: RX_QUEUE_TYPE_RX_LOW_PRIORITY, RX_QUEUE_TYPE_RX_HIGH_PRIORITY,
-        */
-       u8 queue_type;
-};
-
-#define CONF_TX_MAX_RATE_CLASSES       10
-
-#define CONF_TX_RATE_MASK_UNSPECIFIED  0
-#define CONF_TX_RATE_MASK_BASIC        (CONF_HW_BIT_RATE_1MBPS | \
-                                       CONF_HW_BIT_RATE_2MBPS)
-#define CONF_TX_RATE_RETRY_LIMIT       10
-
-/* basic rates for p2p operations (probe req/resp, etc.) */
-#define CONF_TX_RATE_MASK_BASIC_P2P    (CONF_HW_BIT_RATE_6MBPS | \
-       CONF_HW_BIT_RATE_12MBPS | CONF_HW_BIT_RATE_24MBPS)
-
-/*
- * Rates supported for data packets when operating as AP. Note the absence
- * of the 22Mbps rate. There is a FW limitation on 12 rates so we must drop
- * one. The rate dropped is not mandatory under any operating mode.
- */
-#define CONF_TX_AP_ENABLED_RATES       (CONF_HW_BIT_RATE_1MBPS | \
-       CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS |      \
-       CONF_HW_BIT_RATE_6MBPS | CONF_HW_BIT_RATE_9MBPS |        \
-       CONF_HW_BIT_RATE_11MBPS | CONF_HW_BIT_RATE_12MBPS |      \
-       CONF_HW_BIT_RATE_18MBPS | CONF_HW_BIT_RATE_24MBPS |      \
-       CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS |      \
-       CONF_HW_BIT_RATE_54MBPS)
-
-#define CONF_TX_CCK_RATES  (CONF_HW_BIT_RATE_1MBPS |           \
-       CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS |     \
-       CONF_HW_BIT_RATE_11MBPS)
-
-#define CONF_TX_OFDM_RATES (CONF_HW_BIT_RATE_6MBPS |             \
-       CONF_HW_BIT_RATE_12MBPS | CONF_HW_BIT_RATE_24MBPS |      \
-       CONF_HW_BIT_RATE_36MBPS | CONF_HW_BIT_RATE_48MBPS |      \
-       CONF_HW_BIT_RATE_54MBPS)
-
-#define CONF_TX_MCS_RATES (CONF_HW_BIT_RATE_MCS_0 |              \
-       CONF_HW_BIT_RATE_MCS_1 | CONF_HW_BIT_RATE_MCS_2 |        \
-       CONF_HW_BIT_RATE_MCS_3 | CONF_HW_BIT_RATE_MCS_4 |        \
-       CONF_HW_BIT_RATE_MCS_5 | CONF_HW_BIT_RATE_MCS_6 |        \
-       CONF_HW_BIT_RATE_MCS_7)
-
-/*
- * Default rates for management traffic when operating in AP mode. This
- * should be configured according to the basic rate set of the AP
- */
-#define CONF_TX_AP_DEFAULT_MGMT_RATES  (CONF_HW_BIT_RATE_1MBPS | \
-       CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS)
-
-/* default rates for working as IBSS (11b and OFDM) */
-#define CONF_TX_IBSS_DEFAULT_RATES  (CONF_HW_BIT_RATE_1MBPS |       \
-               CONF_HW_BIT_RATE_2MBPS | CONF_HW_BIT_RATE_5_5MBPS | \
-               CONF_HW_BIT_RATE_11MBPS | CONF_TX_OFDM_RATES);
-
-struct conf_tx_rate_class {
-
-       /*
-        * The rates enabled for this rate class.
-        *
-        * Range: CONF_HW_BIT_RATE_* bit mask
-        */
-       u32 enabled_rates;
-
-       /*
-        * The dot11 short retry limit used for TX retries.
-        *
-        * Range: u8
-        */
-       u8 short_retry_limit;
-
-       /*
-        * The dot11 long retry limit used for TX retries.
-        *
-        * Range: u8
-        */
-       u8 long_retry_limit;
-
-       /*
-        * Flags controlling the attributes of TX transmission.
-        *
-        * Range: bit 0: Truncate - when set, FW attempts to send a frame stop
-        *               when the total valid per-rate attempts have
-        *               been exhausted; otherwise transmissions
-        *               will continue at the lowest available rate
-        *               until the appropriate one of the
-        *               short_retry_limit, long_retry_limit,
-        *               dot11_max_transmit_msdu_life_time, or
-        *               max_tx_life_time, is exhausted.
-        *            1: Preamble Override - indicates if the preamble type
-        *               should be used in TX.
-        *            2: Preamble Type - the type of the preamble to be used by
-        *               the policy (0 - long preamble, 1 - short preamble.
-        */
-       u8 aflags;
-};
-
-#define CONF_TX_MAX_AC_COUNT 4
-
-/* Slot number setting to start transmission at PIFS interval */
-#define CONF_TX_AIFS_PIFS 1
-/* Slot number setting to start transmission at DIFS interval normal
- * DCF access */
-#define CONF_TX_AIFS_DIFS 2
-
-
-enum conf_tx_ac {
-       CONF_TX_AC_BE = 0,         /* best effort / legacy */
-       CONF_TX_AC_BK = 1,         /* background */
-       CONF_TX_AC_VI = 2,         /* video */
-       CONF_TX_AC_VO = 3,         /* voice */
-       CONF_TX_AC_CTS2SELF = 4,   /* fictitious AC, follows AC_VO */
-       CONF_TX_AC_ANY_TID = 0x1f
-};
-
-struct conf_tx_ac_category {
-       /*
-        * The AC class identifier.
-        *
-        * Range: enum conf_tx_ac
-        */
-       u8 ac;
-
-       /*
-        * The contention window minimum size (in slots) for the access
-        * class.
-        *
-        * Range: u8
-        */
-       u8 cw_min;
-
-       /*
-        * The contention window maximum size (in slots) for the access
-        * class.
-        *
-        * Range: u8
-        */
-       u16 cw_max;
-
-       /*
-        * The AIF value (in slots) for the access class.
-        *
-        * Range: u8
-        */
-       u8 aifsn;
-
-       /*
-        * The TX Op Limit (in microseconds) for the access class.
-        *
-        * Range: u16
-        */
-       u16 tx_op_limit;
-};
-
-#define CONF_TX_MAX_TID_COUNT 8
-
-/* Allow TX BA on all TIDs but 6,7. These are currently reserved in the FW */
-#define CONF_TX_BA_ENABLED_TID_BITMAP 0x3F
-
-enum {
-       CONF_CHANNEL_TYPE_DCF = 0,   /* DC/LEGACY*/
-       CONF_CHANNEL_TYPE_EDCF = 1,  /* EDCA*/
-       CONF_CHANNEL_TYPE_HCCA = 2,  /* HCCA*/
-};
-
-enum {
-       CONF_PS_SCHEME_LEGACY = 0,
-       CONF_PS_SCHEME_UPSD_TRIGGER = 1,
-       CONF_PS_SCHEME_LEGACY_PSPOLL = 2,
-       CONF_PS_SCHEME_SAPSD = 3,
-};
-
-enum {
-       CONF_ACK_POLICY_LEGACY = 0,
-       CONF_ACK_POLICY_NO_ACK = 1,
-       CONF_ACK_POLICY_BLOCK = 2,
-};
-
-
-struct conf_tx_tid {
-       u8 queue_id;
-       u8 channel_type;
-       u8 tsid;
-       u8 ps_scheme;
-       u8 ack_policy;
-       u32 apsd_conf[2];
-};
-
-struct conf_tx_settings {
-       /*
-        * The TX ED value for TELEC Enable/Disable.
-        *
-        * Range: 0, 1
-        */
-       u8 tx_energy_detection;
-
-       /*
-        * Configuration for rate classes for TX (currently only one
-        * rate class supported). Used in non-AP mode.
-        */
-       struct conf_tx_rate_class sta_rc_conf;
-
-       /*
-        * Configuration for access categories for TX rate control.
-        */
-       u8 ac_conf_count;
-       struct conf_tx_ac_category ac_conf[CONF_TX_MAX_AC_COUNT];
-
-       /*
-        * AP-mode - allow this number of TX retries to a station before an
-        * event is triggered from FW.
-        * In AP-mode the hlids of unreachable stations are given in the
-        * "sta_tx_retry_exceeded" member in the event mailbox.
-        */
-       u8 max_tx_retries;
-
-       /*
-        * AP-mode - after this number of seconds a connected station is
-        * considered inactive.
-        */
-       u16 ap_aging_period;
-
-       /*
-        * Configuration for TID parameters.
-        */
-       u8 tid_conf_count;
-       struct conf_tx_tid tid_conf[CONF_TX_MAX_TID_COUNT];
-
-       /*
-        * The TX fragmentation threshold.
-        *
-        * Range: u16
-        */
-       u16 frag_threshold;
-
-       /*
-        * Max time in msec the FW may delay frame TX-Complete interrupt.
-        *
-        * Range: u16
-        */
-       u16 tx_compl_timeout;
-
-       /*
-        * Completed TX packet count which requires to issue the TX-Complete
-        * interrupt.
-        *
-        * Range: u16
-        */
-       u16 tx_compl_threshold;
-
-       /*
-        * The rate used for control messages and scanning on the 2.4GHz band
-        *
-        * Range: CONF_HW_BIT_RATE_* bit mask
-        */
-       u32 basic_rate;
-
-       /*
-        * The rate used for control messages and scanning on the 5GHz band
-        *
-        * Range: CONF_HW_BIT_RATE_* bit mask
-        */
-       u32 basic_rate_5;
-
-       /*
-        * TX retry limits for templates
-        */
-       u8 tmpl_short_retry_limit;
-       u8 tmpl_long_retry_limit;
-
-       /* Time in ms for Tx watchdog timer to expire */
-       u32 tx_watchdog_timeout;
-};
-
-enum {
-       CONF_WAKE_UP_EVENT_BEACON    = 0x01, /* Wake on every Beacon*/
-       CONF_WAKE_UP_EVENT_DTIM      = 0x02, /* Wake on every DTIM*/
-       CONF_WAKE_UP_EVENT_N_DTIM    = 0x04, /* Wake every Nth DTIM */
-       CONF_WAKE_UP_EVENT_N_BEACONS = 0x08, /* Wake every Nth beacon */
-       CONF_WAKE_UP_EVENT_BITS_MASK = 0x0F
-};
-
-#define CONF_MAX_BCN_FILT_IE_COUNT 32
-
-#define CONF_BCN_RULE_PASS_ON_CHANGE         BIT(0)
-#define CONF_BCN_RULE_PASS_ON_APPEARANCE     BIT(1)
-
-#define CONF_BCN_IE_OUI_LEN    3
-#define CONF_BCN_IE_VER_LEN    2
-
-struct conf_bcn_filt_rule {
-       /*
-        * IE number to which to associate a rule.
-        *
-        * Range: u8
-        */
-       u8 ie;
-
-       /*
-        * Rule to associate with the specific ie.
-        *
-        * Range: CONF_BCN_RULE_PASS_ON_*
-        */
-       u8 rule;
-
-       /*
-        * OUI for the vendor specifie IE (221)
-        */
-       u8 oui[CONF_BCN_IE_OUI_LEN];
-
-       /*
-        * Type for the vendor specifie IE (221)
-        */
-       u8 type;
-
-       /*
-        * Version for the vendor specifie IE (221)
-        */
-       u8 version[CONF_BCN_IE_VER_LEN];
-};
-
-#define CONF_MAX_RSSI_SNR_TRIGGERS 8
-
-enum {
-       CONF_TRIG_METRIC_RSSI_BEACON = 0,
-       CONF_TRIG_METRIC_RSSI_DATA,
-       CONF_TRIG_METRIC_SNR_BEACON,
-       CONF_TRIG_METRIC_SNR_DATA
-};
-
-enum {
-       CONF_TRIG_EVENT_TYPE_LEVEL = 0,
-       CONF_TRIG_EVENT_TYPE_EDGE
-};
-
-enum {
-       CONF_TRIG_EVENT_DIR_LOW = 0,
-       CONF_TRIG_EVENT_DIR_HIGH,
-       CONF_TRIG_EVENT_DIR_BIDIR
-};
-
-struct conf_sig_weights {
-
-       /*
-        * RSSI from beacons average weight.
-        *
-        * Range: u8
-        */
-       u8 rssi_bcn_avg_weight;
-
-       /*
-        * RSSI from data average weight.
-        *
-        * Range: u8
-        */
-       u8 rssi_pkt_avg_weight;
-
-       /*
-        * SNR from beacons average weight.
-        *
-        * Range: u8
-        */
-       u8 snr_bcn_avg_weight;
-
-       /*
-        * SNR from data average weight.
-        *
-        * Range: u8
-        */
-       u8 snr_pkt_avg_weight;
-};
-
-enum conf_bcn_filt_mode {
-       CONF_BCN_FILT_MODE_DISABLED = 0,
-       CONF_BCN_FILT_MODE_ENABLED = 1
-};
-
-enum conf_bet_mode {
-       CONF_BET_MODE_DISABLE = 0,
-       CONF_BET_MODE_ENABLE = 1,
-};
-
-struct conf_conn_settings {
-       /*
-        * Firmware wakeup conditions configuration. The host may set only
-        * one bit.
-        *
-        * Range: CONF_WAKE_UP_EVENT_*
-        */
-       u8 wake_up_event;
-
-       /*
-        * Listen interval for beacons or Dtims.
-        *
-        * Range: 0 for beacon and Dtim wakeup
-        *        1-10 for x Dtims
-        *        1-255 for x beacons
-        */
-       u8 listen_interval;
-
-       /*
-        * Firmware wakeup conditions during suspend
-        * Range: CONF_WAKE_UP_EVENT_*
-        */
-       u8 suspend_wake_up_event;
-
-       /*
-        * Listen interval during suspend.
-        * Currently will be in DTIMs (1-10)
-        *
-        */
-       u8 suspend_listen_interval;
-
-       /*
-        * Enable or disable the beacon filtering.
-        *
-        * Range: CONF_BCN_FILT_MODE_*
-        */
-       enum conf_bcn_filt_mode bcn_filt_mode;
-
-       /*
-        * Configure Beacon filter pass-thru rules.
-        */
-       u8 bcn_filt_ie_count;
-       struct conf_bcn_filt_rule bcn_filt_ie[CONF_MAX_BCN_FILT_IE_COUNT];
-
-       /*
-        * The number of consecutive beacons to lose, before the firmware
-        * becomes out of synch.
-        *
-        * Range: u32
-        */
-       u32 synch_fail_thold;
-
-       /*
-        * After out-of-synch, the number of TU's to wait without a further
-        * received beacon (or probe response) before issuing the BSS_EVENT_LOSE
-        * event.
-        *
-        * Range: u32
-        */
-       u32 bss_lose_timeout;
-
-       /*
-        * Beacon receive timeout.
-        *
-        * Range: u32
-        */
-       u32 beacon_rx_timeout;
-
-       /*
-        * Broadcast receive timeout.
-        *
-        * Range: u32
-        */
-       u32 broadcast_timeout;
-
-       /*
-        * Enable/disable reception of broadcast packets in power save mode
-        *
-        * Range: 1 - enable, 0 - disable
-        */
-       u8 rx_broadcast_in_ps;
-
-       /*
-        * Consecutive PS Poll failures before sending event to driver
-        *
-        * Range: u8
-        */
-       u8 ps_poll_threshold;
-
-       /*
-        * Configuration of signal average weights.
-        */
-       struct conf_sig_weights sig_weights;
-
-       /*
-        * Specifies if beacon early termination procedure is enabled or
-        * disabled.
-        *
-        * Range: CONF_BET_MODE_*
-        */
-       u8 bet_enable;
-
-       /*
-        * Specifies the maximum number of consecutive beacons that may be
-        * early terminated. After this number is reached at least one full
-        * beacon must be correctly received in FW before beacon ET
-        * resumes.
-        *
-        * Range 0 - 255
-        */
-       u8 bet_max_consecutive;
-
-       /*
-        * Specifies the maximum number of times to try PSM entry if it fails
-        * (if sending the appropriate null-func message fails.)
-        *
-        * Range 0 - 255
-        */
-       u8 psm_entry_retries;
-
-       /*
-        * Specifies the maximum number of times to try PSM exit if it fails
-        * (if sending the appropriate null-func message fails.)
-        *
-        * Range 0 - 255
-        */
-       u8 psm_exit_retries;
-
-       /*
-        * Specifies the maximum number of times to try transmit the PSM entry
-        * null-func frame for each PSM entry attempt
-        *
-        * Range 0 - 255
-        */
-       u8 psm_entry_nullfunc_retries;
-
-       /*
-        * Specifies the dynamic PS timeout in ms that will be used
-        * by the FW when in AUTO_PS mode
-        */
-       u16 dynamic_ps_timeout;
-
-       /*
-        * Specifies whether dynamic PS should be disabled and PSM forced.
-        * This is required for certain WiFi certification tests.
-        */
-       u8 forced_ps;
-
-       /*
-        *
-        * Specifies the interval of the connection keep-alive null-func
-        * frame in ms.
-        *
-        * Range: 1000 - 3600000
-        */
-       u32 keep_alive_interval;
-
-       /*
-        * Maximum listen interval supported by the driver in units of beacons.
-        *
-        * Range: u16
-        */
-       u8 max_listen_interval;
-};
-
-enum {
-       CONF_REF_CLK_19_2_E,
-       CONF_REF_CLK_26_E,
-       CONF_REF_CLK_38_4_E,
-       CONF_REF_CLK_52_E,
-       CONF_REF_CLK_38_4_M_XTAL,
-       CONF_REF_CLK_26_M_XTAL,
-};
-
-enum single_dual_band_enum {
-       CONF_SINGLE_BAND,
-       CONF_DUAL_BAND
-};
-
-#define CONF_RSSI_AND_PROCESS_COMPENSATION_SIZE 15
-#define CONF_NUMBER_OF_SUB_BANDS_5  7
-#define CONF_NUMBER_OF_RATE_GROUPS  6
-#define CONF_NUMBER_OF_CHANNELS_2_4 14
-#define CONF_NUMBER_OF_CHANNELS_5   35
-
-struct conf_itrim_settings {
-       /* enable dco itrim */
-       u8 enable;
-
-       /* moderation timeout in microsecs from the last TX */
-       u32 timeout;
-};
-
-struct conf_pm_config_settings {
-       /*
-        * Host clock settling time
-        *
-        * Range: 0 - 30000 us
-        */
-       u32 host_clk_settling_time;
-
-       /*
-        * Host fast wakeup support
-        *
-        * Range: true, false
-        */
-       bool host_fast_wakeup_support;
-};
-
-struct conf_roam_trigger_settings {
-       /*
-        * The minimum interval between two trigger events.
-        *
-        * Range: 0 - 60000 ms
-        */
-       u16 trigger_pacing;
-
-       /*
-        * The weight for rssi/beacon average calculation
-        *
-        * Range: 0 - 255
-        */
-       u8 avg_weight_rssi_beacon;
-
-       /*
-        * The weight for rssi/data frame average calculation
-        *
-        * Range: 0 - 255
-        */
-       u8 avg_weight_rssi_data;
-
-       /*
-        * The weight for snr/beacon average calculation
-        *
-        * Range: 0 - 255
-        */
-       u8 avg_weight_snr_beacon;
-
-       /*
-        * The weight for snr/data frame average calculation
-        *
-        * Range: 0 - 255
-        */
-       u8 avg_weight_snr_data;
-};
-
-struct conf_scan_settings {
-       /*
-        * The minimum time to wait on each channel for active scans
-        *
-        * Range: u32 tu/1000
-        */
-       u32 min_dwell_time_active;
-
-       /*
-        * The maximum time to wait on each channel for active scans
-        *
-        * Range: u32 tu/1000
-        */
-       u32 max_dwell_time_active;
-
-       /*
-        * The minimum time to wait on each channel for passive scans
-        *
-        * Range: u32 tu/1000
-        */
-       u32 min_dwell_time_passive;
-
-       /*
-        * The maximum time to wait on each channel for passive scans
-        *
-        * Range: u32 tu/1000
-        */
-       u32 max_dwell_time_passive;
-
-       /*
-        * Number of probe requests to transmit on each active scan channel
-        *
-        * Range: u8
-        */
-       u16 num_probe_reqs;
-
-       /*
-        * Scan trigger (split scan) timeout. The FW will split the scan
-        * operation into slices of the given time and allow the FW to schedule
-        * other tasks in between.
-        *
-        * Range: u32 Microsecs
-        */
-       u32 split_scan_timeout;
-};
-
-struct conf_sched_scan_settings {
-       /* minimum time to wait on the channel for active scans (in TUs) */
-       u16 min_dwell_time_active;
-
-       /* maximum time to wait on the channel for active scans (in TUs) */
-       u16 max_dwell_time_active;
-
-       /* time to wait on the channel for passive scans (in TUs) */
-       u32 dwell_time_passive;
-
-       /* time to wait on the channel for DFS scans (in TUs) */
-       u32 dwell_time_dfs;
-
-       /* number of probe requests to send on each channel in active scans */
-       u8 num_probe_reqs;
-
-       /* RSSI threshold to be used for filtering */
-       s8 rssi_threshold;
-
-       /* SNR threshold to be used for filtering */
-       s8 snr_threshold;
-};
-
-/* these are number of channels on the band divided by two, rounded up */
-#define CONF_TX_PWR_COMPENSATION_LEN_2 7
-#define CONF_TX_PWR_COMPENSATION_LEN_5 18
-
-struct conf_rf_settings {
-       /*
-        * Per channel power compensation for 2.4GHz
-        *
-        * Range: s8
-        */
-       u8 tx_per_channel_power_compensation_2[CONF_TX_PWR_COMPENSATION_LEN_2];
-
-       /*
-        * Per channel power compensation for 5GHz
-        *
-        * Range: s8
-        */
-       u8 tx_per_channel_power_compensation_5[CONF_TX_PWR_COMPENSATION_LEN_5];
-};
-
-struct conf_ht_setting {
-       u8 rx_ba_win_size;
-       u8 tx_ba_win_size;
-       u16 inactivity_timeout;
-
-       /* bitmap of enabled TIDs for TX BA sessions */
-       u8 tx_ba_tid_bitmap;
-};
-
-struct conf_memory_settings {
-       /* Number of stations supported in IBSS mode */
-       u8 num_stations;
-
-       /* Number of ssid profiles used in IBSS mode */
-       u8 ssid_profiles;
-
-       /* Number of memory buffers allocated to rx pool */
-       u8 rx_block_num;
-
-       /* Minimum number of blocks allocated to tx pool */
-       u8 tx_min_block_num;
-
-       /* Disable/Enable dynamic memory */
-       u8 dynamic_memory;
-
-       /*
-        * Minimum required free tx memory blocks in order to assure optimum
-        * performance
-        *
-        * Range: 0-120
-        */
-       u8 min_req_tx_blocks;
-
-       /*
-        * Minimum required free rx memory blocks in order to assure optimum
-        * performance
-        *
-        * Range: 0-120
-        */
-       u8 min_req_rx_blocks;
-
-       /*
-        * Minimum number of mem blocks (free+used) guaranteed for TX
-        *
-        * Range: 0-120
-        */
-       u8 tx_min;
-};
-
-struct conf_fm_coex {
-       u8 enable;
-       u8 swallow_period;
-       u8 n_divider_fref_set_1;
-       u8 n_divider_fref_set_2;
-       u16 m_divider_fref_set_1;
-       u16 m_divider_fref_set_2;
-       u32 coex_pll_stabilization_time;
-       u16 ldo_stabilization_time;
-       u8 fm_disturbed_band_margin;
-       u8 swallow_clk_diff;
-};
-
-struct conf_rx_streaming_settings {
-       /*
-        * RX Streaming duration (in msec) from last tx/rx
-        *
-        * Range: u32
-        */
-       u32 duration;
-
-       /*
-        * Bitmap of tids to be polled during RX streaming.
-        * (Note: it doesn't look like it really matters)
-        *
-        * Range: 0x1-0xff
-        */
-       u8 queues;
-
-       /*
-        * RX Streaming interval.
-        * (Note:this value is also used as the rx streaming timeout)
-        * Range: 0 (disabled), 10 - 100
-        */
-       u8 interval;
-
-       /*
-        * enable rx streaming also when there is no coex activity
-        */
-       u8 always;
-};
-
-struct conf_fwlog {
-       /* Continuous or on-demand */
-       u8 mode;
-
-       /*
-        * Number of memory blocks dedicated for the FW logger
-        *
-        * Range: 1-3, or 0 to disable the FW logger
-        */
-       u8 mem_blocks;
-
-       /* Minimum log level threshold */
-       u8 severity;
-
-       /* Include/exclude timestamps from the log messages */
-       u8 timestamp;
-
-       /* See enum wl1271_fwlogger_output */
-       u8 output;
-
-       /* Regulates the frequency of log messages */
-       u8 threshold;
-};
-
-#define ACX_RATE_MGMT_NUM_OF_RATES 13
-struct conf_rate_policy_settings {
-       u16 rate_retry_score;
-       u16 per_add;
-       u16 per_th1;
-       u16 per_th2;
-       u16 max_per;
-       u8 inverse_curiosity_factor;
-       u8 tx_fail_low_th;
-       u8 tx_fail_high_th;
-       u8 per_alpha_shift;
-       u8 per_add_shift;
-       u8 per_beta1_shift;
-       u8 per_beta2_shift;
-       u8 rate_check_up;
-       u8 rate_check_down;
-       u8 rate_retry_policy[ACX_RATE_MGMT_NUM_OF_RATES];
-};
-
-struct conf_hangover_settings {
-       u32 recover_time;
-       u8 hangover_period;
-       u8 dynamic_mode;
-       u8 early_termination_mode;
-       u8 max_period;
-       u8 min_period;
-       u8 increase_delta;
-       u8 decrease_delta;
-       u8 quiet_time;
-       u8 increase_time;
-       u8 window_size;
-};
-
-struct conf_drv_settings {
-       struct conf_sg_settings sg;
-       struct conf_rx_settings rx;
-       struct conf_tx_settings tx;
-       struct conf_conn_settings conn;
-       struct conf_itrim_settings itrim;
-       struct conf_pm_config_settings pm_config;
-       struct conf_roam_trigger_settings roam_trigger;
-       struct conf_scan_settings scan;
-       struct conf_sched_scan_settings sched_scan;
-       struct conf_rf_settings rf;
-       struct conf_ht_setting ht;
-       struct conf_memory_settings mem_wl127x;
-       struct conf_memory_settings mem_wl128x;
-       struct conf_fm_coex fm_coex;
-       struct conf_rx_streaming_settings rx_streaming;
-       struct conf_fwlog fwlog;
-       struct conf_rate_policy_settings rate;
-       struct conf_hangover_settings hangover;
-       u8 hci_io_ds;
-};
-
-#endif
diff --git a/drivers/net/wireless/wl12xx/debug.h b/drivers/net/wireless/wl12xx/debug.h
deleted file mode 100644 (file)
index ec0fdc2..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * This file is part of wl12xx
- *
- * Copyright (C) 2011 Texas Instruments. All rights reserved.
- * Copyright (C) 2008-2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <coelho@ti.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __DEBUG_H__
-#define __DEBUG_H__
-
-#include <linux/bitops.h>
-#include <linux/printk.h>
-
-#define DRIVER_NAME "wl12xx"
-#define DRIVER_PREFIX DRIVER_NAME ": "
-
-enum {
-       DEBUG_NONE      = 0,
-       DEBUG_IRQ       = BIT(0),
-       DEBUG_SPI       = BIT(1),
-       DEBUG_BOOT      = BIT(2),
-       DEBUG_MAILBOX   = BIT(3),
-       DEBUG_TESTMODE  = BIT(4),
-       DEBUG_EVENT     = BIT(5),
-       DEBUG_TX        = BIT(6),
-       DEBUG_RX        = BIT(7),
-       DEBUG_SCAN      = BIT(8),
-       DEBUG_CRYPT     = BIT(9),
-       DEBUG_PSM       = BIT(10),
-       DEBUG_MAC80211  = BIT(11),
-       DEBUG_CMD       = BIT(12),
-       DEBUG_ACX       = BIT(13),
-       DEBUG_SDIO      = BIT(14),
-       DEBUG_FILTERS   = BIT(15),
-       DEBUG_ADHOC     = BIT(16),
-       DEBUG_AP        = BIT(17),
-       DEBUG_PROBE     = BIT(18),
-       DEBUG_MASTER    = (DEBUG_ADHOC | DEBUG_AP),
-       DEBUG_ALL       = ~0,
-};
-
-extern u32 wl12xx_debug_level;
-
-#define DEBUG_DUMP_LIMIT 1024
-
-#define wl1271_error(fmt, arg...) \
-       pr_err(DRIVER_PREFIX "ERROR " fmt "\n", ##arg)
-
-#define wl1271_warning(fmt, arg...) \
-       pr_warning(DRIVER_PREFIX "WARNING " fmt "\n", ##arg)
-
-#define wl1271_notice(fmt, arg...) \
-       pr_info(DRIVER_PREFIX fmt "\n", ##arg)
-
-#define wl1271_info(fmt, arg...) \
-       pr_info(DRIVER_PREFIX fmt "\n", ##arg)
-
-#define wl1271_debug(level, fmt, arg...) \
-       do { \
-               if (level & wl12xx_debug_level) \
-                       pr_debug(DRIVER_PREFIX fmt "\n", ##arg); \
-       } while (0)
-
-/* TODO: use pr_debug_hex_dump when it becomes available */
-#define wl1271_dump(level, prefix, buf, len)   \
-       do { \
-               if (level & wl12xx_debug_level) \
-                       print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
-                                      DUMP_PREFIX_OFFSET, 16, 1,       \
-                                      buf,                             \
-                                      min_t(size_t, len, DEBUG_DUMP_LIMIT), \
-                                      0);                              \
-       } while (0)
-
-#define wl1271_dump_ascii(level, prefix, buf, len)     \
-       do { \
-               if (level & wl12xx_debug_level) \
-                       print_hex_dump(KERN_DEBUG, DRIVER_PREFIX prefix, \
-                                      DUMP_PREFIX_OFFSET, 16, 1,       \
-                                      buf,                             \
-                                      min_t(size_t, len, DEBUG_DUMP_LIMIT), \
-                                      true);                           \
-       } while (0)
-
-#endif /* __DEBUG_H__ */
diff --git a/drivers/net/wireless/wl12xx/debugfs.c b/drivers/net/wireless/wl12xx/debugfs.c
deleted file mode 100644 (file)
index 564d495..0000000
+++ /dev/null
@@ -1,1197 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include "debugfs.h"
-
-#include <linux/skbuff.h>
-#include <linux/slab.h>
-
-#include "wl12xx.h"
-#include "debug.h"
-#include "acx.h"
-#include "ps.h"
-#include "io.h"
-#include "tx.h"
-
-/* ms */
-#define WL1271_DEBUGFS_STATS_LIFETIME 1000
-
-/* debugfs macros idea from mac80211 */
-#define DEBUGFS_FORMAT_BUFFER_SIZE 100
-static int wl1271_format_buffer(char __user *userbuf, size_t count,
-                                   loff_t *ppos, char *fmt, ...)
-{
-       va_list args;
-       char buf[DEBUGFS_FORMAT_BUFFER_SIZE];
-       int res;
-
-       va_start(args, fmt);
-       res = vscnprintf(buf, sizeof(buf), fmt, args);
-       va_end(args);
-
-       return simple_read_from_buffer(userbuf, count, ppos, buf, res);
-}
-
-#define DEBUGFS_READONLY_FILE(name, fmt, value...)                     \
-static ssize_t name## _read(struct file *file, char __user *userbuf,   \
-                           size_t count, loff_t *ppos)                 \
-{                                                                      \
-       struct wl1271 *wl = file->private_data;                         \
-       return wl1271_format_buffer(userbuf, count, ppos,               \
-                                   fmt "\n", ##value);                 \
-}                                                                      \
-                                                                       \
-static const struct file_operations name## _ops = {                    \
-       .read = name## _read,                                           \
-       .open = simple_open,                                            \
-       .llseek = generic_file_llseek,                                  \
-};
-
-#define DEBUGFS_ADD(name, parent)                                      \
-       entry = debugfs_create_file(#name, 0400, parent,                \
-                                   wl, &name## _ops);                  \
-       if (!entry || IS_ERR(entry))                                    \
-               goto err;                                               \
-
-#define DEBUGFS_ADD_PREFIX(prefix, name, parent)                       \
-       do {                                                            \
-               entry = debugfs_create_file(#name, 0400, parent,        \
-                                   wl, &prefix## _## name## _ops);     \
-               if (!entry || IS_ERR(entry))                            \
-                       goto err;                                       \
-       } while (0);
-
-#define DEBUGFS_FWSTATS_FILE(sub, name, fmt)                           \
-static ssize_t sub## _ ##name## _read(struct file *file,               \
-                                     char __user *userbuf,             \
-                                     size_t count, loff_t *ppos)       \
-{                                                                      \
-       struct wl1271 *wl = file->private_data;                         \
-                                                                       \
-       wl1271_debugfs_update_stats(wl);                                \
-                                                                       \
-       return wl1271_format_buffer(userbuf, count, ppos, fmt "\n",     \
-                                   wl->stats.fw_stats->sub.name);      \
-}                                                                      \
-                                                                       \
-static const struct file_operations sub## _ ##name## _ops = {          \
-       .read = sub## _ ##name## _read,                                 \
-       .open = simple_open,                                            \
-       .llseek = generic_file_llseek,                                  \
-};
-
-#define DEBUGFS_FWSTATS_ADD(sub, name)                         \
-       DEBUGFS_ADD(sub## _ ##name, stats)
-
-static void wl1271_debugfs_update_stats(struct wl1271 *wl)
-{
-       int ret;
-
-       mutex_lock(&wl->mutex);
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       if (wl->state == WL1271_STATE_ON && !wl->plt &&
-           time_after(jiffies, wl->stats.fw_stats_update +
-                      msecs_to_jiffies(WL1271_DEBUGFS_STATS_LIFETIME))) {
-               wl1271_acx_statistics(wl, wl->stats.fw_stats);
-               wl->stats.fw_stats_update = jiffies;
-       }
-
-       wl1271_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-DEBUGFS_FWSTATS_FILE(tx, internal_desc_overflow, "%u");
-
-DEBUGFS_FWSTATS_FILE(rx, out_of_mem, "%u");
-DEBUGFS_FWSTATS_FILE(rx, hdr_overflow, "%u");
-DEBUGFS_FWSTATS_FILE(rx, hw_stuck, "%u");
-DEBUGFS_FWSTATS_FILE(rx, dropped, "%u");
-DEBUGFS_FWSTATS_FILE(rx, fcs_err, "%u");
-DEBUGFS_FWSTATS_FILE(rx, xfr_hint_trig, "%u");
-DEBUGFS_FWSTATS_FILE(rx, path_reset, "%u");
-DEBUGFS_FWSTATS_FILE(rx, reset_counter, "%u");
-
-DEBUGFS_FWSTATS_FILE(dma, rx_requested, "%u");
-DEBUGFS_FWSTATS_FILE(dma, rx_errors, "%u");
-DEBUGFS_FWSTATS_FILE(dma, tx_requested, "%u");
-DEBUGFS_FWSTATS_FILE(dma, tx_errors, "%u");
-
-DEBUGFS_FWSTATS_FILE(isr, cmd_cmplt, "%u");
-DEBUGFS_FWSTATS_FILE(isr, fiqs, "%u");
-DEBUGFS_FWSTATS_FILE(isr, rx_headers, "%u");
-DEBUGFS_FWSTATS_FILE(isr, rx_mem_overflow, "%u");
-DEBUGFS_FWSTATS_FILE(isr, rx_rdys, "%u");
-DEBUGFS_FWSTATS_FILE(isr, irqs, "%u");
-DEBUGFS_FWSTATS_FILE(isr, tx_procs, "%u");
-DEBUGFS_FWSTATS_FILE(isr, decrypt_done, "%u");
-DEBUGFS_FWSTATS_FILE(isr, dma0_done, "%u");
-DEBUGFS_FWSTATS_FILE(isr, dma1_done, "%u");
-DEBUGFS_FWSTATS_FILE(isr, tx_exch_complete, "%u");
-DEBUGFS_FWSTATS_FILE(isr, commands, "%u");
-DEBUGFS_FWSTATS_FILE(isr, rx_procs, "%u");
-DEBUGFS_FWSTATS_FILE(isr, hw_pm_mode_changes, "%u");
-DEBUGFS_FWSTATS_FILE(isr, host_acknowledges, "%u");
-DEBUGFS_FWSTATS_FILE(isr, pci_pm, "%u");
-DEBUGFS_FWSTATS_FILE(isr, wakeups, "%u");
-DEBUGFS_FWSTATS_FILE(isr, low_rssi, "%u");
-
-DEBUGFS_FWSTATS_FILE(wep, addr_key_count, "%u");
-DEBUGFS_FWSTATS_FILE(wep, default_key_count, "%u");
-/* skipping wep.reserved */
-DEBUGFS_FWSTATS_FILE(wep, key_not_found, "%u");
-DEBUGFS_FWSTATS_FILE(wep, decrypt_fail, "%u");
-DEBUGFS_FWSTATS_FILE(wep, packets, "%u");
-DEBUGFS_FWSTATS_FILE(wep, interrupt, "%u");
-
-DEBUGFS_FWSTATS_FILE(pwr, ps_enter, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, elp_enter, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, missing_bcns, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, wake_on_host, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, wake_on_timer_exp, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, tx_with_ps, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, tx_without_ps, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, rcvd_beacons, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, power_save_off, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, enable_ps, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, disable_ps, "%u");
-DEBUGFS_FWSTATS_FILE(pwr, fix_tsf_ps, "%u");
-/* skipping cont_miss_bcns_spread for now */
-DEBUGFS_FWSTATS_FILE(pwr, rcvd_awake_beacons, "%u");
-
-DEBUGFS_FWSTATS_FILE(mic, rx_pkts, "%u");
-DEBUGFS_FWSTATS_FILE(mic, calc_failure, "%u");
-
-DEBUGFS_FWSTATS_FILE(aes, encrypt_fail, "%u");
-DEBUGFS_FWSTATS_FILE(aes, decrypt_fail, "%u");
-DEBUGFS_FWSTATS_FILE(aes, encrypt_packets, "%u");
-DEBUGFS_FWSTATS_FILE(aes, decrypt_packets, "%u");
-DEBUGFS_FWSTATS_FILE(aes, encrypt_interrupt, "%u");
-DEBUGFS_FWSTATS_FILE(aes, decrypt_interrupt, "%u");
-
-DEBUGFS_FWSTATS_FILE(event, heart_beat, "%u");
-DEBUGFS_FWSTATS_FILE(event, calibration, "%u");
-DEBUGFS_FWSTATS_FILE(event, rx_mismatch, "%u");
-DEBUGFS_FWSTATS_FILE(event, rx_mem_empty, "%u");
-DEBUGFS_FWSTATS_FILE(event, rx_pool, "%u");
-DEBUGFS_FWSTATS_FILE(event, oom_late, "%u");
-DEBUGFS_FWSTATS_FILE(event, phy_transmit_error, "%u");
-DEBUGFS_FWSTATS_FILE(event, tx_stuck, "%u");
-
-DEBUGFS_FWSTATS_FILE(ps, pspoll_timeouts, "%u");
-DEBUGFS_FWSTATS_FILE(ps, upsd_timeouts, "%u");
-DEBUGFS_FWSTATS_FILE(ps, upsd_max_sptime, "%u");
-DEBUGFS_FWSTATS_FILE(ps, upsd_max_apturn, "%u");
-DEBUGFS_FWSTATS_FILE(ps, pspoll_max_apturn, "%u");
-DEBUGFS_FWSTATS_FILE(ps, pspoll_utilization, "%u");
-DEBUGFS_FWSTATS_FILE(ps, upsd_utilization, "%u");
-
-DEBUGFS_FWSTATS_FILE(rxpipe, rx_prep_beacon_drop, "%u");
-DEBUGFS_FWSTATS_FILE(rxpipe, descr_host_int_trig_rx_data, "%u");
-DEBUGFS_FWSTATS_FILE(rxpipe, beacon_buffer_thres_host_int_trig_rx_data, "%u");
-DEBUGFS_FWSTATS_FILE(rxpipe, missed_beacon_host_int_trig_rx_data, "%u");
-DEBUGFS_FWSTATS_FILE(rxpipe, tx_xfr_host_int_trig_rx_data, "%u");
-
-DEBUGFS_READONLY_FILE(retry_count, "%u", wl->stats.retry_count);
-DEBUGFS_READONLY_FILE(excessive_retries, "%u",
-                     wl->stats.excessive_retries);
-
-static ssize_t tx_queue_len_read(struct file *file, char __user *userbuf,
-                                size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       u32 queue_len;
-       char buf[20];
-       int res;
-
-       queue_len = wl1271_tx_total_queue_count(wl);
-
-       res = scnprintf(buf, sizeof(buf), "%u\n", queue_len);
-       return simple_read_from_buffer(userbuf, count, ppos, buf, res);
-}
-
-static const struct file_operations tx_queue_len_ops = {
-       .read = tx_queue_len_read,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-static ssize_t gpio_power_read(struct file *file, char __user *user_buf,
-                         size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       bool state = test_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
-
-       int res;
-       char buf[10];
-
-       res = scnprintf(buf, sizeof(buf), "%d\n", state);
-
-       return simple_read_from_buffer(user_buf, count, ppos, buf, res);
-}
-
-static ssize_t gpio_power_write(struct file *file,
-                          const char __user *user_buf,
-                          size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       unsigned long value;
-       int ret;
-
-       ret = kstrtoul_from_user(user_buf, count, 10, &value);
-       if (ret < 0) {
-               wl1271_warning("illegal value in gpio_power");
-               return -EINVAL;
-       }
-
-       mutex_lock(&wl->mutex);
-
-       if (value)
-               wl1271_power_on(wl);
-       else
-               wl1271_power_off(wl);
-
-       mutex_unlock(&wl->mutex);
-       return count;
-}
-
-static const struct file_operations gpio_power_ops = {
-       .read = gpio_power_read,
-       .write = gpio_power_write,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-static ssize_t start_recovery_write(struct file *file,
-                                   const char __user *user_buf,
-                                   size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-
-       mutex_lock(&wl->mutex);
-       wl12xx_queue_recovery_work(wl);
-       mutex_unlock(&wl->mutex);
-
-       return count;
-}
-
-static const struct file_operations start_recovery_ops = {
-       .write = start_recovery_write,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-static ssize_t dynamic_ps_timeout_read(struct file *file, char __user *user_buf,
-                         size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-
-       return wl1271_format_buffer(user_buf, count,
-                                   ppos, "%d\n",
-                                   wl->conf.conn.dynamic_ps_timeout);
-}
-
-static ssize_t dynamic_ps_timeout_write(struct file *file,
-                                   const char __user *user_buf,
-                                   size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       struct wl12xx_vif *wlvif;
-       unsigned long value;
-       int ret;
-
-       ret = kstrtoul_from_user(user_buf, count, 10, &value);
-       if (ret < 0) {
-               wl1271_warning("illegal value in dynamic_ps");
-               return -EINVAL;
-       }
-
-       if (value < 1 || value > 65535) {
-               wl1271_warning("dyanmic_ps_timeout is not in valid range");
-               return -ERANGE;
-       }
-
-       mutex_lock(&wl->mutex);
-
-       wl->conf.conn.dynamic_ps_timeout = value;
-
-       if (wl->state == WL1271_STATE_OFF)
-               goto out;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       /* In case we're already in PSM, trigger it again to set new timeout
-        * immediately without waiting for re-association
-        */
-
-       wl12xx_for_each_wlvif_sta(wl, wlvif) {
-               if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
-                       wl1271_ps_set_mode(wl, wlvif, STATION_AUTO_PS_MODE);
-       }
-
-       wl1271_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-       return count;
-}
-
-static const struct file_operations dynamic_ps_timeout_ops = {
-       .read = dynamic_ps_timeout_read,
-       .write = dynamic_ps_timeout_write,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-static ssize_t forced_ps_read(struct file *file, char __user *user_buf,
-                         size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-
-       return wl1271_format_buffer(user_buf, count,
-                                   ppos, "%d\n",
-                                   wl->conf.conn.forced_ps);
-}
-
-static ssize_t forced_ps_write(struct file *file,
-                                   const char __user *user_buf,
-                                   size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       struct wl12xx_vif *wlvif;
-       unsigned long value;
-       int ret, ps_mode;
-
-       ret = kstrtoul_from_user(user_buf, count, 10, &value);
-       if (ret < 0) {
-               wl1271_warning("illegal value in forced_ps");
-               return -EINVAL;
-       }
-
-       if (value != 1 && value != 0) {
-               wl1271_warning("forced_ps should be either 0 or 1");
-               return -ERANGE;
-       }
-
-       mutex_lock(&wl->mutex);
-
-       if (wl->conf.conn.forced_ps == value)
-               goto out;
-
-       wl->conf.conn.forced_ps = value;
-
-       if (wl->state == WL1271_STATE_OFF)
-               goto out;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       /* In case we're already in PSM, trigger it again to switch mode
-        * immediately without waiting for re-association
-        */
-
-       ps_mode = value ? STATION_POWER_SAVE_MODE : STATION_AUTO_PS_MODE;
-
-       wl12xx_for_each_wlvif_sta(wl, wlvif) {
-               if (test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags))
-                       wl1271_ps_set_mode(wl, wlvif, ps_mode);
-       }
-
-       wl1271_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-       return count;
-}
-
-static const struct file_operations forced_ps_ops = {
-       .read = forced_ps_read,
-       .write = forced_ps_write,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-static ssize_t split_scan_timeout_read(struct file *file, char __user *user_buf,
-                         size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-
-       return wl1271_format_buffer(user_buf, count,
-                                   ppos, "%d\n",
-                                   wl->conf.scan.split_scan_timeout / 1000);
-}
-
-static ssize_t split_scan_timeout_write(struct file *file,
-                                   const char __user *user_buf,
-                                   size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       unsigned long value;
-       int ret;
-
-       ret = kstrtoul_from_user(user_buf, count, 10, &value);
-       if (ret < 0) {
-               wl1271_warning("illegal value in split_scan_timeout");
-               return -EINVAL;
-       }
-
-       if (value == 0)
-               wl1271_info("split scan will be disabled");
-
-       mutex_lock(&wl->mutex);
-
-       wl->conf.scan.split_scan_timeout = value * 1000;
-
-       mutex_unlock(&wl->mutex);
-       return count;
-}
-
-static const struct file_operations split_scan_timeout_ops = {
-       .read = split_scan_timeout_read,
-       .write = split_scan_timeout_write,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-static ssize_t driver_state_read(struct file *file, char __user *user_buf,
-                                size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       int res = 0;
-       ssize_t ret;
-       char *buf;
-
-#define DRIVER_STATE_BUF_LEN 1024
-
-       buf = kmalloc(DRIVER_STATE_BUF_LEN, GFP_KERNEL);
-       if (!buf)
-               return -ENOMEM;
-
-       mutex_lock(&wl->mutex);
-
-#define DRIVER_STATE_PRINT(x, fmt)   \
-       (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\
-                         #x " = " fmt "\n", wl->x))
-
-#define DRIVER_STATE_PRINT_LONG(x) DRIVER_STATE_PRINT(x, "%ld")
-#define DRIVER_STATE_PRINT_INT(x)  DRIVER_STATE_PRINT(x, "%d")
-#define DRIVER_STATE_PRINT_STR(x)  DRIVER_STATE_PRINT(x, "%s")
-#define DRIVER_STATE_PRINT_LHEX(x) DRIVER_STATE_PRINT(x, "0x%lx")
-#define DRIVER_STATE_PRINT_HEX(x)  DRIVER_STATE_PRINT(x, "0x%x")
-
-       DRIVER_STATE_PRINT_INT(tx_blocks_available);
-       DRIVER_STATE_PRINT_INT(tx_allocated_blocks);
-       DRIVER_STATE_PRINT_INT(tx_allocated_pkts[0]);
-       DRIVER_STATE_PRINT_INT(tx_allocated_pkts[1]);
-       DRIVER_STATE_PRINT_INT(tx_allocated_pkts[2]);
-       DRIVER_STATE_PRINT_INT(tx_allocated_pkts[3]);
-       DRIVER_STATE_PRINT_INT(tx_frames_cnt);
-       DRIVER_STATE_PRINT_LHEX(tx_frames_map[0]);
-       DRIVER_STATE_PRINT_INT(tx_queue_count[0]);
-       DRIVER_STATE_PRINT_INT(tx_queue_count[1]);
-       DRIVER_STATE_PRINT_INT(tx_queue_count[2]);
-       DRIVER_STATE_PRINT_INT(tx_queue_count[3]);
-       DRIVER_STATE_PRINT_INT(tx_packets_count);
-       DRIVER_STATE_PRINT_INT(tx_results_count);
-       DRIVER_STATE_PRINT_LHEX(flags);
-       DRIVER_STATE_PRINT_INT(tx_blocks_freed);
-       DRIVER_STATE_PRINT_INT(rx_counter);
-       DRIVER_STATE_PRINT_INT(state);
-       DRIVER_STATE_PRINT_INT(channel);
-       DRIVER_STATE_PRINT_INT(band);
-       DRIVER_STATE_PRINT_INT(power_level);
-       DRIVER_STATE_PRINT_INT(sg_enabled);
-       DRIVER_STATE_PRINT_INT(enable_11a);
-       DRIVER_STATE_PRINT_INT(noise);
-       DRIVER_STATE_PRINT_HEX(ap_fw_ps_map);
-       DRIVER_STATE_PRINT_LHEX(ap_ps_map);
-       DRIVER_STATE_PRINT_HEX(quirks);
-       DRIVER_STATE_PRINT_HEX(irq);
-       DRIVER_STATE_PRINT_HEX(ref_clock);
-       DRIVER_STATE_PRINT_HEX(tcxo_clock);
-       DRIVER_STATE_PRINT_HEX(hw_pg_ver);
-       DRIVER_STATE_PRINT_HEX(platform_quirks);
-       DRIVER_STATE_PRINT_HEX(chip.id);
-       DRIVER_STATE_PRINT_STR(chip.fw_ver_str);
-       DRIVER_STATE_PRINT_INT(sched_scanning);
-
-#undef DRIVER_STATE_PRINT_INT
-#undef DRIVER_STATE_PRINT_LONG
-#undef DRIVER_STATE_PRINT_HEX
-#undef DRIVER_STATE_PRINT_LHEX
-#undef DRIVER_STATE_PRINT_STR
-#undef DRIVER_STATE_PRINT
-#undef DRIVER_STATE_BUF_LEN
-
-       mutex_unlock(&wl->mutex);
-
-       ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
-       kfree(buf);
-       return ret;
-}
-
-static const struct file_operations driver_state_ops = {
-       .read = driver_state_read,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-static ssize_t vifs_state_read(struct file *file, char __user *user_buf,
-                                size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       struct wl12xx_vif *wlvif;
-       int ret, res = 0;
-       const int buf_size = 4096;
-       char *buf;
-       char tmp_buf[64];
-
-       buf = kzalloc(buf_size, GFP_KERNEL);
-       if (!buf)
-               return -ENOMEM;
-
-       mutex_lock(&wl->mutex);
-
-#define VIF_STATE_PRINT(x, fmt)                                \
-       (res += scnprintf(buf + res, buf_size - res,    \
-                         #x " = " fmt "\n", wlvif->x))
-
-#define VIF_STATE_PRINT_LONG(x)  VIF_STATE_PRINT(x, "%ld")
-#define VIF_STATE_PRINT_INT(x)   VIF_STATE_PRINT(x, "%d")
-#define VIF_STATE_PRINT_STR(x)   VIF_STATE_PRINT(x, "%s")
-#define VIF_STATE_PRINT_LHEX(x)  VIF_STATE_PRINT(x, "0x%lx")
-#define VIF_STATE_PRINT_LLHEX(x) VIF_STATE_PRINT(x, "0x%llx")
-#define VIF_STATE_PRINT_HEX(x)   VIF_STATE_PRINT(x, "0x%x")
-
-#define VIF_STATE_PRINT_NSTR(x, len)                           \
-       do {                                                    \
-               memset(tmp_buf, 0, sizeof(tmp_buf));            \
-               memcpy(tmp_buf, wlvif->x,                       \
-                      min_t(u8, len, sizeof(tmp_buf) - 1));    \
-               res += scnprintf(buf + res, buf_size - res,     \
-                                #x " = %s\n", tmp_buf);        \
-       } while (0)
-
-       wl12xx_for_each_wlvif(wl, wlvif) {
-               VIF_STATE_PRINT_INT(role_id);
-               VIF_STATE_PRINT_INT(bss_type);
-               VIF_STATE_PRINT_LHEX(flags);
-               VIF_STATE_PRINT_INT(p2p);
-               VIF_STATE_PRINT_INT(dev_role_id);
-               VIF_STATE_PRINT_INT(dev_hlid);
-
-               if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
-                   wlvif->bss_type == BSS_TYPE_IBSS) {
-                       VIF_STATE_PRINT_INT(sta.hlid);
-                       VIF_STATE_PRINT_INT(sta.ba_rx_bitmap);
-                       VIF_STATE_PRINT_INT(sta.basic_rate_idx);
-                       VIF_STATE_PRINT_INT(sta.ap_rate_idx);
-                       VIF_STATE_PRINT_INT(sta.p2p_rate_idx);
-                       VIF_STATE_PRINT_INT(sta.qos);
-               } else {
-                       VIF_STATE_PRINT_INT(ap.global_hlid);
-                       VIF_STATE_PRINT_INT(ap.bcast_hlid);
-                       VIF_STATE_PRINT_LHEX(ap.sta_hlid_map[0]);
-                       VIF_STATE_PRINT_INT(ap.mgmt_rate_idx);
-                       VIF_STATE_PRINT_INT(ap.bcast_rate_idx);
-                       VIF_STATE_PRINT_INT(ap.ucast_rate_idx[0]);
-                       VIF_STATE_PRINT_INT(ap.ucast_rate_idx[1]);
-                       VIF_STATE_PRINT_INT(ap.ucast_rate_idx[2]);
-                       VIF_STATE_PRINT_INT(ap.ucast_rate_idx[3]);
-               }
-               VIF_STATE_PRINT_INT(last_tx_hlid);
-               VIF_STATE_PRINT_LHEX(links_map[0]);
-               VIF_STATE_PRINT_NSTR(ssid, wlvif->ssid_len);
-               VIF_STATE_PRINT_INT(band);
-               VIF_STATE_PRINT_INT(channel);
-               VIF_STATE_PRINT_HEX(bitrate_masks[0]);
-               VIF_STATE_PRINT_HEX(bitrate_masks[1]);
-               VIF_STATE_PRINT_HEX(basic_rate_set);
-               VIF_STATE_PRINT_HEX(basic_rate);
-               VIF_STATE_PRINT_HEX(rate_set);
-               VIF_STATE_PRINT_INT(beacon_int);
-               VIF_STATE_PRINT_INT(default_key);
-               VIF_STATE_PRINT_INT(aid);
-               VIF_STATE_PRINT_INT(session_counter);
-               VIF_STATE_PRINT_INT(psm_entry_retry);
-               VIF_STATE_PRINT_INT(power_level);
-               VIF_STATE_PRINT_INT(rssi_thold);
-               VIF_STATE_PRINT_INT(last_rssi_event);
-               VIF_STATE_PRINT_INT(ba_support);
-               VIF_STATE_PRINT_INT(ba_allowed);
-               VIF_STATE_PRINT_LLHEX(tx_security_seq);
-               VIF_STATE_PRINT_INT(tx_security_last_seq_lsb);
-       }
-
-#undef VIF_STATE_PRINT_INT
-#undef VIF_STATE_PRINT_LONG
-#undef VIF_STATE_PRINT_HEX
-#undef VIF_STATE_PRINT_LHEX
-#undef VIF_STATE_PRINT_LLHEX
-#undef VIF_STATE_PRINT_STR
-#undef VIF_STATE_PRINT_NSTR
-#undef VIF_STATE_PRINT
-
-       mutex_unlock(&wl->mutex);
-
-       ret = simple_read_from_buffer(user_buf, count, ppos, buf, res);
-       kfree(buf);
-       return ret;
-}
-
-static const struct file_operations vifs_state_ops = {
-       .read = vifs_state_read,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-static ssize_t dtim_interval_read(struct file *file, char __user *user_buf,
-                                 size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       u8 value;
-
-       if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
-           wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
-               value = wl->conf.conn.listen_interval;
-       else
-               value = 0;
-
-       return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
-}
-
-static ssize_t dtim_interval_write(struct file *file,
-                                  const char __user *user_buf,
-                                  size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       unsigned long value;
-       int ret;
-
-       ret = kstrtoul_from_user(user_buf, count, 10, &value);
-       if (ret < 0) {
-               wl1271_warning("illegal value for dtim_interval");
-               return -EINVAL;
-       }
-
-       if (value < 1 || value > 10) {
-               wl1271_warning("dtim value is not in valid range");
-               return -ERANGE;
-       }
-
-       mutex_lock(&wl->mutex);
-
-       wl->conf.conn.listen_interval = value;
-       /* for some reason there are different event types for 1 and >1 */
-       if (value == 1)
-               wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
-       else
-               wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
-
-       /*
-        * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
-        * take effect on the next time we enter psm.
-        */
-       mutex_unlock(&wl->mutex);
-       return count;
-}
-
-static const struct file_operations dtim_interval_ops = {
-       .read = dtim_interval_read,
-       .write = dtim_interval_write,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-
-
-static ssize_t suspend_dtim_interval_read(struct file *file,
-                                         char __user *user_buf,
-                                         size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       u8 value;
-
-       if (wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_DTIM ||
-           wl->conf.conn.suspend_wake_up_event == CONF_WAKE_UP_EVENT_N_DTIM)
-               value = wl->conf.conn.suspend_listen_interval;
-       else
-               value = 0;
-
-       return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
-}
-
-static ssize_t suspend_dtim_interval_write(struct file *file,
-                                          const char __user *user_buf,
-                                          size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       unsigned long value;
-       int ret;
-
-       ret = kstrtoul_from_user(user_buf, count, 10, &value);
-       if (ret < 0) {
-               wl1271_warning("illegal value for suspend_dtim_interval");
-               return -EINVAL;
-       }
-
-       if (value < 1 || value > 10) {
-               wl1271_warning("suspend_dtim value is not in valid range");
-               return -ERANGE;
-       }
-
-       mutex_lock(&wl->mutex);
-
-       wl->conf.conn.suspend_listen_interval = value;
-       /* for some reason there are different event types for 1 and >1 */
-       if (value == 1)
-               wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_DTIM;
-       else
-               wl->conf.conn.suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM;
-
-       mutex_unlock(&wl->mutex);
-       return count;
-}
-
-
-static const struct file_operations suspend_dtim_interval_ops = {
-       .read = suspend_dtim_interval_read,
-       .write = suspend_dtim_interval_write,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-static ssize_t beacon_interval_read(struct file *file, char __user *user_buf,
-                                   size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       u8 value;
-
-       if (wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_BEACON ||
-           wl->conf.conn.wake_up_event == CONF_WAKE_UP_EVENT_N_BEACONS)
-               value = wl->conf.conn.listen_interval;
-       else
-               value = 0;
-
-       return wl1271_format_buffer(user_buf, count, ppos, "%d\n", value);
-}
-
-static ssize_t beacon_interval_write(struct file *file,
-                                    const char __user *user_buf,
-                                    size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       unsigned long value;
-       int ret;
-
-       ret = kstrtoul_from_user(user_buf, count, 10, &value);
-       if (ret < 0) {
-               wl1271_warning("illegal value for beacon_interval");
-               return -EINVAL;
-       }
-
-       if (value < 1 || value > 255) {
-               wl1271_warning("beacon interval value is not in valid range");
-               return -ERANGE;
-       }
-
-       mutex_lock(&wl->mutex);
-
-       wl->conf.conn.listen_interval = value;
-       /* for some reason there are different event types for 1 and >1 */
-       if (value == 1)
-               wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_BEACON;
-       else
-               wl->conf.conn.wake_up_event = CONF_WAKE_UP_EVENT_N_BEACONS;
-
-       /*
-        * we don't reconfigure ACX_WAKE_UP_CONDITIONS now, so it will only
-        * take effect on the next time we enter psm.
-        */
-       mutex_unlock(&wl->mutex);
-       return count;
-}
-
-static const struct file_operations beacon_interval_ops = {
-       .read = beacon_interval_read,
-       .write = beacon_interval_write,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-static ssize_t rx_streaming_interval_write(struct file *file,
-                          const char __user *user_buf,
-                          size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       struct wl12xx_vif *wlvif;
-       unsigned long value;
-       int ret;
-
-       ret = kstrtoul_from_user(user_buf, count, 10, &value);
-       if (ret < 0) {
-               wl1271_warning("illegal value in rx_streaming_interval!");
-               return -EINVAL;
-       }
-
-       /* valid values: 0, 10-100 */
-       if (value && (value < 10 || value > 100)) {
-               wl1271_warning("value is not in range!");
-               return -ERANGE;
-       }
-
-       mutex_lock(&wl->mutex);
-
-       wl->conf.rx_streaming.interval = value;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       wl12xx_for_each_wlvif_sta(wl, wlvif) {
-               wl1271_recalc_rx_streaming(wl, wlvif);
-       }
-
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-       return count;
-}
-
-static ssize_t rx_streaming_interval_read(struct file *file,
-                           char __user *userbuf,
-                           size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       return wl1271_format_buffer(userbuf, count, ppos,
-                                   "%d\n", wl->conf.rx_streaming.interval);
-}
-
-static const struct file_operations rx_streaming_interval_ops = {
-       .read = rx_streaming_interval_read,
-       .write = rx_streaming_interval_write,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-static ssize_t rx_streaming_always_write(struct file *file,
-                          const char __user *user_buf,
-                          size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       struct wl12xx_vif *wlvif;
-       unsigned long value;
-       int ret;
-
-       ret = kstrtoul_from_user(user_buf, count, 10, &value);
-       if (ret < 0) {
-               wl1271_warning("illegal value in rx_streaming_write!");
-               return -EINVAL;
-       }
-
-       /* valid values: 0, 10-100 */
-       if (!(value == 0 || value == 1)) {
-               wl1271_warning("value is not in valid!");
-               return -EINVAL;
-       }
-
-       mutex_lock(&wl->mutex);
-
-       wl->conf.rx_streaming.always = value;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       wl12xx_for_each_wlvif_sta(wl, wlvif) {
-               wl1271_recalc_rx_streaming(wl, wlvif);
-       }
-
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-       return count;
-}
-
-static ssize_t rx_streaming_always_read(struct file *file,
-                           char __user *userbuf,
-                           size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       return wl1271_format_buffer(userbuf, count, ppos,
-                                   "%d\n", wl->conf.rx_streaming.always);
-}
-
-static const struct file_operations rx_streaming_always_ops = {
-       .read = rx_streaming_always_read,
-       .write = rx_streaming_always_write,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-static ssize_t beacon_filtering_write(struct file *file,
-                                     const char __user *user_buf,
-                                     size_t count, loff_t *ppos)
-{
-       struct wl1271 *wl = file->private_data;
-       struct wl12xx_vif *wlvif;
-       char buf[10];
-       size_t len;
-       unsigned long value;
-       int ret;
-
-       len = min(count, sizeof(buf) - 1);
-       if (copy_from_user(buf, user_buf, len))
-               return -EFAULT;
-       buf[len] = '\0';
-
-       ret = kstrtoul(buf, 0, &value);
-       if (ret < 0) {
-               wl1271_warning("illegal value for beacon_filtering!");
-               return -EINVAL;
-       }
-
-       mutex_lock(&wl->mutex);
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       wl12xx_for_each_wlvif(wl, wlvif) {
-               ret = wl1271_acx_beacon_filter_opt(wl, wlvif, !!value);
-       }
-
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-       return count;
-}
-
-static const struct file_operations beacon_filtering_ops = {
-       .write = beacon_filtering_write,
-       .open = simple_open,
-       .llseek = default_llseek,
-};
-
-static int wl1271_debugfs_add_files(struct wl1271 *wl,
-                                    struct dentry *rootdir)
-{
-       int ret = 0;
-       struct dentry *entry, *stats, *streaming;
-
-       stats = debugfs_create_dir("fw-statistics", rootdir);
-       if (!stats || IS_ERR(stats)) {
-               entry = stats;
-               goto err;
-       }
-
-       DEBUGFS_FWSTATS_ADD(tx, internal_desc_overflow);
-
-       DEBUGFS_FWSTATS_ADD(rx, out_of_mem);
-       DEBUGFS_FWSTATS_ADD(rx, hdr_overflow);
-       DEBUGFS_FWSTATS_ADD(rx, hw_stuck);
-       DEBUGFS_FWSTATS_ADD(rx, dropped);
-       DEBUGFS_FWSTATS_ADD(rx, fcs_err);
-       DEBUGFS_FWSTATS_ADD(rx, xfr_hint_trig);
-       DEBUGFS_FWSTATS_ADD(rx, path_reset);
-       DEBUGFS_FWSTATS_ADD(rx, reset_counter);
-
-       DEBUGFS_FWSTATS_ADD(dma, rx_requested);
-       DEBUGFS_FWSTATS_ADD(dma, rx_errors);
-       DEBUGFS_FWSTATS_ADD(dma, tx_requested);
-       DEBUGFS_FWSTATS_ADD(dma, tx_errors);
-
-       DEBUGFS_FWSTATS_ADD(isr, cmd_cmplt);
-       DEBUGFS_FWSTATS_ADD(isr, fiqs);
-       DEBUGFS_FWSTATS_ADD(isr, rx_headers);
-       DEBUGFS_FWSTATS_ADD(isr, rx_mem_overflow);
-       DEBUGFS_FWSTATS_ADD(isr, rx_rdys);
-       DEBUGFS_FWSTATS_ADD(isr, irqs);
-       DEBUGFS_FWSTATS_ADD(isr, tx_procs);
-       DEBUGFS_FWSTATS_ADD(isr, decrypt_done);
-       DEBUGFS_FWSTATS_ADD(isr, dma0_done);
-       DEBUGFS_FWSTATS_ADD(isr, dma1_done);
-       DEBUGFS_FWSTATS_ADD(isr, tx_exch_complete);
-       DEBUGFS_FWSTATS_ADD(isr, commands);
-       DEBUGFS_FWSTATS_ADD(isr, rx_procs);
-       DEBUGFS_FWSTATS_ADD(isr, hw_pm_mode_changes);
-       DEBUGFS_FWSTATS_ADD(isr, host_acknowledges);
-       DEBUGFS_FWSTATS_ADD(isr, pci_pm);
-       DEBUGFS_FWSTATS_ADD(isr, wakeups);
-       DEBUGFS_FWSTATS_ADD(isr, low_rssi);
-
-       DEBUGFS_FWSTATS_ADD(wep, addr_key_count);
-       DEBUGFS_FWSTATS_ADD(wep, default_key_count);
-       /* skipping wep.reserved */
-       DEBUGFS_FWSTATS_ADD(wep, key_not_found);
-       DEBUGFS_FWSTATS_ADD(wep, decrypt_fail);
-       DEBUGFS_FWSTATS_ADD(wep, packets);
-       DEBUGFS_FWSTATS_ADD(wep, interrupt);
-
-       DEBUGFS_FWSTATS_ADD(pwr, ps_enter);
-       DEBUGFS_FWSTATS_ADD(pwr, elp_enter);
-       DEBUGFS_FWSTATS_ADD(pwr, missing_bcns);
-       DEBUGFS_FWSTATS_ADD(pwr, wake_on_host);
-       DEBUGFS_FWSTATS_ADD(pwr, wake_on_timer_exp);
-       DEBUGFS_FWSTATS_ADD(pwr, tx_with_ps);
-       DEBUGFS_FWSTATS_ADD(pwr, tx_without_ps);
-       DEBUGFS_FWSTATS_ADD(pwr, rcvd_beacons);
-       DEBUGFS_FWSTATS_ADD(pwr, power_save_off);
-       DEBUGFS_FWSTATS_ADD(pwr, enable_ps);
-       DEBUGFS_FWSTATS_ADD(pwr, disable_ps);
-       DEBUGFS_FWSTATS_ADD(pwr, fix_tsf_ps);
-       /* skipping cont_miss_bcns_spread for now */
-       DEBUGFS_FWSTATS_ADD(pwr, rcvd_awake_beacons);
-
-       DEBUGFS_FWSTATS_ADD(mic, rx_pkts);
-       DEBUGFS_FWSTATS_ADD(mic, calc_failure);
-
-       DEBUGFS_FWSTATS_ADD(aes, encrypt_fail);
-       DEBUGFS_FWSTATS_ADD(aes, decrypt_fail);
-       DEBUGFS_FWSTATS_ADD(aes, encrypt_packets);
-       DEBUGFS_FWSTATS_ADD(aes, decrypt_packets);
-       DEBUGFS_FWSTATS_ADD(aes, encrypt_interrupt);
-       DEBUGFS_FWSTATS_ADD(aes, decrypt_interrupt);
-
-       DEBUGFS_FWSTATS_ADD(event, heart_beat);
-       DEBUGFS_FWSTATS_ADD(event, calibration);
-       DEBUGFS_FWSTATS_ADD(event, rx_mismatch);
-       DEBUGFS_FWSTATS_ADD(event, rx_mem_empty);
-       DEBUGFS_FWSTATS_ADD(event, rx_pool);
-       DEBUGFS_FWSTATS_ADD(event, oom_late);
-       DEBUGFS_FWSTATS_ADD(event, phy_transmit_error);
-       DEBUGFS_FWSTATS_ADD(event, tx_stuck);
-
-       DEBUGFS_FWSTATS_ADD(ps, pspoll_timeouts);
-       DEBUGFS_FWSTATS_ADD(ps, upsd_timeouts);
-       DEBUGFS_FWSTATS_ADD(ps, upsd_max_sptime);
-       DEBUGFS_FWSTATS_ADD(ps, upsd_max_apturn);
-       DEBUGFS_FWSTATS_ADD(ps, pspoll_max_apturn);
-       DEBUGFS_FWSTATS_ADD(ps, pspoll_utilization);
-       DEBUGFS_FWSTATS_ADD(ps, upsd_utilization);
-
-       DEBUGFS_FWSTATS_ADD(rxpipe, rx_prep_beacon_drop);
-       DEBUGFS_FWSTATS_ADD(rxpipe, descr_host_int_trig_rx_data);
-       DEBUGFS_FWSTATS_ADD(rxpipe, beacon_buffer_thres_host_int_trig_rx_data);
-       DEBUGFS_FWSTATS_ADD(rxpipe, missed_beacon_host_int_trig_rx_data);
-       DEBUGFS_FWSTATS_ADD(rxpipe, tx_xfr_host_int_trig_rx_data);
-
-       DEBUGFS_ADD(tx_queue_len, rootdir);
-       DEBUGFS_ADD(retry_count, rootdir);
-       DEBUGFS_ADD(excessive_retries, rootdir);
-
-       DEBUGFS_ADD(gpio_power, rootdir);
-       DEBUGFS_ADD(start_recovery, rootdir);
-       DEBUGFS_ADD(driver_state, rootdir);
-       DEBUGFS_ADD(vifs_state, rootdir);
-       DEBUGFS_ADD(dtim_interval, rootdir);
-       DEBUGFS_ADD(suspend_dtim_interval, rootdir);
-       DEBUGFS_ADD(beacon_interval, rootdir);
-       DEBUGFS_ADD(beacon_filtering, rootdir);
-       DEBUGFS_ADD(dynamic_ps_timeout, rootdir);
-       DEBUGFS_ADD(forced_ps, rootdir);
-       DEBUGFS_ADD(split_scan_timeout, rootdir);
-
-       streaming = debugfs_create_dir("rx_streaming", rootdir);
-       if (!streaming || IS_ERR(streaming))
-               goto err;
-
-       DEBUGFS_ADD_PREFIX(rx_streaming, interval, streaming);
-       DEBUGFS_ADD_PREFIX(rx_streaming, always, streaming);
-
-
-       return 0;
-
-err:
-       if (IS_ERR(entry))
-               ret = PTR_ERR(entry);
-       else
-               ret = -ENOMEM;
-
-       return ret;
-}
-
-void wl1271_debugfs_reset(struct wl1271 *wl)
-{
-       if (!wl->stats.fw_stats)
-               return;
-
-       memset(wl->stats.fw_stats, 0, sizeof(*wl->stats.fw_stats));
-       wl->stats.retry_count = 0;
-       wl->stats.excessive_retries = 0;
-}
-
-int wl1271_debugfs_init(struct wl1271 *wl)
-{
-       int ret;
-       struct dentry *rootdir;
-
-       rootdir = debugfs_create_dir(KBUILD_MODNAME,
-                                    wl->hw->wiphy->debugfsdir);
-
-       if (IS_ERR(rootdir)) {
-               ret = PTR_ERR(rootdir);
-               goto err;
-       }
-
-       wl->stats.fw_stats = kzalloc(sizeof(*wl->stats.fw_stats),
-                                     GFP_KERNEL);
-
-       if (!wl->stats.fw_stats) {
-               ret = -ENOMEM;
-               goto err_fw;
-       }
-
-       wl->stats.fw_stats_update = jiffies;
-
-       ret = wl1271_debugfs_add_files(wl, rootdir);
-
-       if (ret < 0)
-               goto err_file;
-
-       return 0;
-
-err_file:
-       kfree(wl->stats.fw_stats);
-       wl->stats.fw_stats = NULL;
-
-err_fw:
-       debugfs_remove_recursive(rootdir);
-
-err:
-       return ret;
-}
-
-void wl1271_debugfs_exit(struct wl1271 *wl)
-{
-       kfree(wl->stats.fw_stats);
-       wl->stats.fw_stats = NULL;
-}
diff --git a/drivers/net/wireless/wl12xx/debugfs.h b/drivers/net/wireless/wl12xx/debugfs.h
deleted file mode 100644 (file)
index 254c5b2..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __DEBUGFS_H__
-#define __DEBUGFS_H__
-
-#include "wl12xx.h"
-
-int wl1271_debugfs_init(struct wl1271 *wl);
-void wl1271_debugfs_exit(struct wl1271 *wl);
-void wl1271_debugfs_reset(struct wl1271 *wl);
-
-#endif /* WL1271_DEBUGFS_H */
diff --git a/drivers/net/wireless/wl12xx/event.c b/drivers/net/wireless/wl12xx/event.c
deleted file mode 100644 (file)
index c953717..0000000
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2008-2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include "wl12xx.h"
-#include "debug.h"
-#include "reg.h"
-#include "io.h"
-#include "event.h"
-#include "ps.h"
-#include "scan.h"
-#include "wl12xx_80211.h"
-
-static void wl1271_event_rssi_trigger(struct wl1271 *wl,
-                                     struct wl12xx_vif *wlvif,
-                                     struct event_mailbox *mbox)
-{
-       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-       enum nl80211_cqm_rssi_threshold_event event;
-       s8 metric = mbox->rssi_snr_trigger_metric[0];
-
-       wl1271_debug(DEBUG_EVENT, "RSSI trigger metric: %d", metric);
-
-       if (metric <= wlvif->rssi_thold)
-               event = NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW;
-       else
-               event = NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH;
-
-       if (event != wlvif->last_rssi_event)
-               ieee80211_cqm_rssi_notify(vif, event, GFP_KERNEL);
-       wlvif->last_rssi_event = event;
-}
-
-static void wl1271_stop_ba_event(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-
-       if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
-               if (!wlvif->sta.ba_rx_bitmap)
-                       return;
-               ieee80211_stop_rx_ba_session(vif, wlvif->sta.ba_rx_bitmap,
-                                            vif->bss_conf.bssid);
-       } else {
-               u8 hlid;
-               struct wl1271_link *lnk;
-               for_each_set_bit(hlid, wlvif->ap.sta_hlid_map,
-                                WL12XX_MAX_LINKS) {
-                       lnk = &wl->links[hlid];
-                       if (!lnk->ba_bitmap)
-                               continue;
-
-                       ieee80211_stop_rx_ba_session(vif,
-                                                    lnk->ba_bitmap,
-                                                    lnk->addr);
-               }
-       }
-}
-
-static void wl12xx_event_soft_gemini_sense(struct wl1271 *wl,
-                                              u8 enable)
-{
-       struct wl12xx_vif *wlvif;
-
-       if (enable) {
-               set_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
-       } else {
-               clear_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags);
-               wl12xx_for_each_wlvif_sta(wl, wlvif) {
-                       wl1271_recalc_rx_streaming(wl, wlvif);
-               }
-       }
-
-}
-
-static void wl1271_event_mbox_dump(struct event_mailbox *mbox)
-{
-       wl1271_debug(DEBUG_EVENT, "MBOX DUMP:");
-       wl1271_debug(DEBUG_EVENT, "\tvector: 0x%x", mbox->events_vector);
-       wl1271_debug(DEBUG_EVENT, "\tmask: 0x%x", mbox->events_mask);
-}
-
-static int wl1271_event_process(struct wl1271 *wl, struct event_mailbox *mbox)
-{
-       struct ieee80211_vif *vif;
-       struct wl12xx_vif *wlvif;
-       u32 vector;
-       bool beacon_loss = false;
-       bool disconnect_sta = false;
-       unsigned long sta_bitmap = 0;
-
-       wl1271_event_mbox_dump(mbox);
-
-       vector = le32_to_cpu(mbox->events_vector);
-       vector &= ~(le32_to_cpu(mbox->events_mask));
-       wl1271_debug(DEBUG_EVENT, "vector: 0x%x", vector);
-
-       if (vector & SCAN_COMPLETE_EVENT_ID) {
-               wl1271_debug(DEBUG_EVENT, "status: 0x%x",
-                            mbox->scheduled_scan_status);
-
-               wl1271_scan_stm(wl, wl->scan_vif);
-       }
-
-       if (vector & PERIODIC_SCAN_REPORT_EVENT_ID) {
-               wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_REPORT_EVENT "
-                            "(status 0x%0x)", mbox->scheduled_scan_status);
-
-               wl1271_scan_sched_scan_results(wl);
-       }
-
-       if (vector & PERIODIC_SCAN_COMPLETE_EVENT_ID) {
-               wl1271_debug(DEBUG_EVENT, "PERIODIC_SCAN_COMPLETE_EVENT "
-                            "(status 0x%0x)", mbox->scheduled_scan_status);
-               if (wl->sched_scanning) {
-                       ieee80211_sched_scan_stopped(wl->hw);
-                       wl->sched_scanning = false;
-               }
-       }
-
-       if (vector & SOFT_GEMINI_SENSE_EVENT_ID)
-               wl12xx_event_soft_gemini_sense(wl,
-                                              mbox->soft_gemini_sense_info);
-
-       /*
-        * The BSS_LOSE_EVENT_ID is only needed while psm (and hence beacon
-        * filtering) is enabled. Without PSM, the stack will receive all
-        * beacons and can detect beacon loss by itself.
-        *
-        * As there's possibility that the driver disables PSM before receiving
-        * BSS_LOSE_EVENT, beacon loss has to be reported to the stack.
-        *
-        */
-       if (vector & BSS_LOSE_EVENT_ID) {
-               /* TODO: check for multi-role */
-               wl1271_info("Beacon loss detected.");
-
-               /* indicate to the stack, that beacons have been lost */
-               beacon_loss = true;
-       }
-
-       if (vector & RSSI_SNR_TRIGGER_0_EVENT_ID) {
-               /* TODO: check actual multi-role support */
-               wl1271_debug(DEBUG_EVENT, "RSSI_SNR_TRIGGER_0_EVENT");
-               wl12xx_for_each_wlvif_sta(wl, wlvif) {
-                       wl1271_event_rssi_trigger(wl, wlvif, mbox);
-               }
-       }
-
-       if (vector & BA_SESSION_RX_CONSTRAINT_EVENT_ID) {
-               u8 role_id = mbox->role_id;
-               wl1271_debug(DEBUG_EVENT, "BA_SESSION_RX_CONSTRAINT_EVENT_ID. "
-                            "ba_allowed = 0x%x, role_id=%d",
-                            mbox->rx_ba_allowed, role_id);
-
-               wl12xx_for_each_wlvif(wl, wlvif) {
-                       if (role_id != 0xff && role_id != wlvif->role_id)
-                               continue;
-
-                       wlvif->ba_allowed = !!mbox->rx_ba_allowed;
-                       if (!wlvif->ba_allowed)
-                               wl1271_stop_ba_event(wl, wlvif);
-               }
-       }
-
-       if (vector & CHANNEL_SWITCH_COMPLETE_EVENT_ID) {
-               wl1271_debug(DEBUG_EVENT, "CHANNEL_SWITCH_COMPLETE_EVENT_ID. "
-                                         "status = 0x%x",
-                                         mbox->channel_switch_status);
-               /*
-                * That event uses for two cases:
-                * 1) channel switch complete with status=0
-                * 2) channel switch failed status=1
-                */
-
-               /* TODO: configure only the relevant vif */
-               wl12xx_for_each_wlvif_sta(wl, wlvif) {
-                       bool success;
-
-                       if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS,
-                                               &wl->flags))
-                               continue;
-
-                       success = mbox->channel_switch_status ? false : true;
-                       vif = wl12xx_wlvif_to_vif(wlvif);
-
-                       ieee80211_chswitch_done(vif, success);
-               }
-       }
-
-       if ((vector & DUMMY_PACKET_EVENT_ID)) {
-               wl1271_debug(DEBUG_EVENT, "DUMMY_PACKET_ID_EVENT_ID");
-               wl1271_tx_dummy_packet(wl);
-       }
-
-       /*
-        * "TX retries exceeded" has a different meaning according to mode.
-        * In AP mode the offending station is disconnected.
-        */
-       if (vector & MAX_TX_RETRY_EVENT_ID) {
-               wl1271_debug(DEBUG_EVENT, "MAX_TX_RETRY_EVENT_ID");
-               sta_bitmap |= le16_to_cpu(mbox->sta_tx_retry_exceeded);
-               disconnect_sta = true;
-       }
-
-       if (vector & INACTIVE_STA_EVENT_ID) {
-               wl1271_debug(DEBUG_EVENT, "INACTIVE_STA_EVENT_ID");
-               sta_bitmap |= le16_to_cpu(mbox->sta_aging_status);
-               disconnect_sta = true;
-       }
-
-       if (disconnect_sta) {
-               u32 num_packets = wl->conf.tx.max_tx_retries;
-               struct ieee80211_sta *sta;
-               const u8 *addr;
-               int h;
-
-               for_each_set_bit(h, &sta_bitmap, WL12XX_MAX_LINKS) {
-                       bool found = false;
-                       /* find the ap vif connected to this sta */
-                       wl12xx_for_each_wlvif_ap(wl, wlvif) {
-                               if (!test_bit(h, wlvif->ap.sta_hlid_map))
-                                       continue;
-                               found = true;
-                               break;
-                       }
-                       if (!found)
-                               continue;
-
-                       vif = wl12xx_wlvif_to_vif(wlvif);
-                       addr = wl->links[h].addr;
-
-                       rcu_read_lock();
-                       sta = ieee80211_find_sta(vif, addr);
-                       if (sta) {
-                               wl1271_debug(DEBUG_EVENT, "remove sta %d", h);
-                               ieee80211_report_low_ack(sta, num_packets);
-                       }
-                       rcu_read_unlock();
-               }
-       }
-
-       if (beacon_loss)
-               wl12xx_for_each_wlvif_sta(wl, wlvif) {
-                       vif = wl12xx_wlvif_to_vif(wlvif);
-                       ieee80211_connection_loss(vif);
-               }
-
-       return 0;
-}
-
-int wl1271_event_unmask(struct wl1271 *wl)
-{
-       int ret;
-
-       ret = wl1271_acx_event_mbox_mask(wl, ~(wl->event_mask));
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-void wl1271_event_mbox_config(struct wl1271 *wl)
-{
-       wl->mbox_ptr[0] = wl1271_read32(wl, REG_EVENT_MAILBOX_PTR);
-       wl->mbox_ptr[1] = wl->mbox_ptr[0] + sizeof(struct event_mailbox);
-
-       wl1271_debug(DEBUG_EVENT, "MBOX ptrs: 0x%x 0x%x",
-                    wl->mbox_ptr[0], wl->mbox_ptr[1]);
-}
-
-int wl1271_event_handle(struct wl1271 *wl, u8 mbox_num)
-{
-       struct event_mailbox mbox;
-       int ret;
-
-       wl1271_debug(DEBUG_EVENT, "EVENT on mbox %d", mbox_num);
-
-       if (mbox_num > 1)
-               return -EINVAL;
-
-       /* first we read the mbox descriptor */
-       wl1271_read(wl, wl->mbox_ptr[mbox_num], &mbox,
-                   sizeof(struct event_mailbox), false);
-
-       /* process the descriptor */
-       ret = wl1271_event_process(wl, &mbox);
-       if (ret < 0)
-               return ret;
-
-       /* then we let the firmware know it can go on...*/
-       wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_EVENT_ACK);
-
-       return 0;
-}
diff --git a/drivers/net/wireless/wl12xx/event.h b/drivers/net/wireless/wl12xx/event.h
deleted file mode 100644 (file)
index 057d193..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
- * Copyright (C) 2008-2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __EVENT_H__
-#define __EVENT_H__
-
-/*
- * Mbox events
- *
- * The event mechanism is based on a pair of event buffers (buffers A and
- * B) at fixed locations in the target's memory. The host processes one
- * buffer while the other buffer continues to collect events. If the host
- * is not processing events, an interrupt is issued to signal that a buffer
- * is ready. Once the host is done with processing events from one buffer,
- * it signals the target (with an ACK interrupt) that the event buffer is
- * free.
- */
-
-enum {
-       RSSI_SNR_TRIGGER_0_EVENT_ID              = BIT(0),
-       RSSI_SNR_TRIGGER_1_EVENT_ID              = BIT(1),
-       RSSI_SNR_TRIGGER_2_EVENT_ID              = BIT(2),
-       RSSI_SNR_TRIGGER_3_EVENT_ID              = BIT(3),
-       RSSI_SNR_TRIGGER_4_EVENT_ID              = BIT(4),
-       RSSI_SNR_TRIGGER_5_EVENT_ID              = BIT(5),
-       RSSI_SNR_TRIGGER_6_EVENT_ID              = BIT(6),
-       RSSI_SNR_TRIGGER_7_EVENT_ID              = BIT(7),
-       MEASUREMENT_START_EVENT_ID               = BIT(8),
-       MEASUREMENT_COMPLETE_EVENT_ID            = BIT(9),
-       SCAN_COMPLETE_EVENT_ID                   = BIT(10),
-       WFD_DISCOVERY_COMPLETE_EVENT_ID          = BIT(11),
-       AP_DISCOVERY_COMPLETE_EVENT_ID           = BIT(12),
-       RESERVED1                                = BIT(13),
-       PSPOLL_DELIVERY_FAILURE_EVENT_ID         = BIT(14),
-       ROLE_STOP_COMPLETE_EVENT_ID              = BIT(15),
-       RADAR_DETECTED_EVENT_ID                  = BIT(16),
-       CHANNEL_SWITCH_COMPLETE_EVENT_ID         = BIT(17),
-       BSS_LOSE_EVENT_ID                        = BIT(18),
-       REGAINED_BSS_EVENT_ID                    = BIT(19),
-       MAX_TX_RETRY_EVENT_ID                    = BIT(20),
-       DUMMY_PACKET_EVENT_ID                    = BIT(21),
-       SOFT_GEMINI_SENSE_EVENT_ID               = BIT(22),
-       CHANGE_AUTO_MODE_TIMEOUT_EVENT_ID        = BIT(23),
-       SOFT_GEMINI_AVALANCHE_EVENT_ID           = BIT(24),
-       PLT_RX_CALIBRATION_COMPLETE_EVENT_ID     = BIT(25),
-       INACTIVE_STA_EVENT_ID                    = BIT(26),
-       PEER_REMOVE_COMPLETE_EVENT_ID            = BIT(27),
-       PERIODIC_SCAN_COMPLETE_EVENT_ID          = BIT(28),
-       PERIODIC_SCAN_REPORT_EVENT_ID            = BIT(29),
-       BA_SESSION_RX_CONSTRAINT_EVENT_ID        = BIT(30),
-       REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID      = BIT(31),
-       EVENT_MBOX_ALL_EVENT_ID                  = 0x7fffffff,
-};
-
-enum {
-       EVENT_ENTER_POWER_SAVE_FAIL = 0,
-       EVENT_ENTER_POWER_SAVE_SUCCESS,
-};
-
-#define NUM_OF_RSSI_SNR_TRIGGERS 8
-
-struct event_mailbox {
-       __le32 events_vector;
-       __le32 events_mask;
-       __le32 reserved_1;
-       __le32 reserved_2;
-
-       u8 number_of_scan_results;
-       u8 scan_tag;
-       u8 completed_scan_status;
-       u8 reserved_3;
-
-       u8 soft_gemini_sense_info;
-       u8 soft_gemini_protective_info;
-       s8 rssi_snr_trigger_metric[NUM_OF_RSSI_SNR_TRIGGERS];
-       u8 change_auto_mode_timeout;
-       u8 scheduled_scan_status;
-       u8 reserved4;
-       /* tuned channel (roc) */
-       u8 roc_channel;
-
-       __le16 hlid_removed_bitmap;
-
-       /* bitmap of aged stations (by HLID) */
-       __le16 sta_aging_status;
-
-       /* bitmap of stations (by HLID) which exceeded max tx retries */
-       __le16 sta_tx_retry_exceeded;
-
-       /* discovery completed results */
-       u8 discovery_tag;
-       u8 number_of_preq_results;
-       u8 number_of_prsp_results;
-       u8 reserved_5;
-
-       /* rx ba constraint */
-       u8 role_id; /* 0xFF means any role. */
-       u8 rx_ba_allowed;
-       u8 reserved_6[2];
-
-       /* Channel switch results */
-
-       u8 channel_switch_role_id;
-       u8 channel_switch_status;
-       u8 reserved_7[2];
-
-       u8 ps_poll_delivery_failure_role_ids;
-       u8 stopped_role_ids;
-       u8 started_role_ids;
-
-       u8 reserved_8[9];
-} __packed;
-
-int wl1271_event_unmask(struct wl1271 *wl);
-void wl1271_event_mbox_config(struct wl1271 *wl);
-int wl1271_event_handle(struct wl1271 *wl, u8 mbox);
-
-#endif
diff --git a/drivers/net/wireless/wl12xx/ini.h b/drivers/net/wireless/wl12xx/ini.h
deleted file mode 100644 (file)
index 4cf9ecc..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2010 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __INI_H__
-#define __INI_H__
-
-#define GENERAL_SETTINGS_DRPW_LPD 0xc0
-#define SCRATCH_ENABLE_LPD        BIT(25)
-
-#define WL1271_INI_MAX_SMART_REFLEX_PARAM 16
-
-struct wl1271_ini_general_params {
-       u8 ref_clock;
-       u8 settling_time;
-       u8 clk_valid_on_wakeup;
-       u8 dc2dc_mode;
-       u8 dual_mode_select;
-       u8 tx_bip_fem_auto_detect;
-       u8 tx_bip_fem_manufacturer;
-       u8 general_settings;
-       u8 sr_state;
-       u8 srf1[WL1271_INI_MAX_SMART_REFLEX_PARAM];
-       u8 srf2[WL1271_INI_MAX_SMART_REFLEX_PARAM];
-       u8 srf3[WL1271_INI_MAX_SMART_REFLEX_PARAM];
-} __packed;
-
-#define WL128X_INI_MAX_SETTINGS_PARAM 4
-
-struct wl128x_ini_general_params {
-       u8 ref_clock;
-       u8 settling_time;
-       u8 clk_valid_on_wakeup;
-       u8 tcxo_ref_clock;
-       u8 tcxo_settling_time;
-       u8 tcxo_valid_on_wakeup;
-       u8 tcxo_ldo_voltage;
-       u8 xtal_itrim_val;
-       u8 platform_conf;
-       u8 dual_mode_select;
-       u8 tx_bip_fem_auto_detect;
-       u8 tx_bip_fem_manufacturer;
-       u8 general_settings[WL128X_INI_MAX_SETTINGS_PARAM];
-       u8 sr_state;
-       u8 srf1[WL1271_INI_MAX_SMART_REFLEX_PARAM];
-       u8 srf2[WL1271_INI_MAX_SMART_REFLEX_PARAM];
-       u8 srf3[WL1271_INI_MAX_SMART_REFLEX_PARAM];
-} __packed;
-
-#define WL1271_INI_RSSI_PROCESS_COMPENS_SIZE 15
-
-struct wl1271_ini_band_params_2 {
-       u8 rx_trace_insertion_loss;
-       u8 tx_trace_loss;
-       u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
-} __packed;
-
-#define WL1271_INI_CHANNEL_COUNT_2 14
-
-struct wl128x_ini_band_params_2 {
-       u8 rx_trace_insertion_loss;
-       u8 tx_trace_loss[WL1271_INI_CHANNEL_COUNT_2];
-       u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
-} __packed;
-
-#define WL1271_INI_RATE_GROUP_COUNT 6
-
-struct wl1271_ini_fem_params_2 {
-       __le16 tx_bip_ref_pd_voltage;
-       u8 tx_bip_ref_power;
-       u8 tx_bip_ref_offset;
-       u8 tx_per_rate_pwr_limits_normal[WL1271_INI_RATE_GROUP_COUNT];
-       u8 tx_per_rate_pwr_limits_degraded[WL1271_INI_RATE_GROUP_COUNT];
-       u8 tx_per_rate_pwr_limits_extreme[WL1271_INI_RATE_GROUP_COUNT];
-       u8 tx_per_chan_pwr_limits_11b[WL1271_INI_CHANNEL_COUNT_2];
-       u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_2];
-       u8 tx_pd_vs_rate_offsets[WL1271_INI_RATE_GROUP_COUNT];
-       u8 tx_ibias[WL1271_INI_RATE_GROUP_COUNT];
-       u8 rx_fem_insertion_loss;
-       u8 degraded_low_to_normal_thr;
-       u8 normal_to_degraded_high_thr;
-} __packed;
-
-#define WL128X_INI_RATE_GROUP_COUNT 7
-/* low and high temperatures */
-#define WL128X_INI_PD_VS_TEMPERATURE_RANGES 2
-
-struct wl128x_ini_fem_params_2 {
-       __le16 tx_bip_ref_pd_voltage;
-       u8 tx_bip_ref_power;
-       u8 tx_bip_ref_offset;
-       u8 tx_per_rate_pwr_limits_normal[WL128X_INI_RATE_GROUP_COUNT];
-       u8 tx_per_rate_pwr_limits_degraded[WL128X_INI_RATE_GROUP_COUNT];
-       u8 tx_per_rate_pwr_limits_extreme[WL128X_INI_RATE_GROUP_COUNT];
-       u8 tx_per_chan_pwr_limits_11b[WL1271_INI_CHANNEL_COUNT_2];
-       u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_2];
-       u8 tx_pd_vs_rate_offsets[WL128X_INI_RATE_GROUP_COUNT];
-       u8 tx_ibias[WL128X_INI_RATE_GROUP_COUNT + 1];
-       u8 tx_pd_vs_chan_offsets[WL1271_INI_CHANNEL_COUNT_2];
-       u8 tx_pd_vs_temperature[WL128X_INI_PD_VS_TEMPERATURE_RANGES];
-       u8 rx_fem_insertion_loss;
-       u8 degraded_low_to_normal_thr;
-       u8 normal_to_degraded_high_thr;
-} __packed;
-
-#define WL1271_INI_CHANNEL_COUNT_5 35
-#define WL1271_INI_SUB_BAND_COUNT_5 7
-
-struct wl1271_ini_band_params_5 {
-       u8 rx_trace_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
-       u8 tx_trace_loss[WL1271_INI_SUB_BAND_COUNT_5];
-       u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
-} __packed;
-
-struct wl128x_ini_band_params_5 {
-       u8 rx_trace_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
-       u8 tx_trace_loss[WL1271_INI_CHANNEL_COUNT_5];
-       u8 rx_rssi_process_compens[WL1271_INI_RSSI_PROCESS_COMPENS_SIZE];
-} __packed;
-
-struct wl1271_ini_fem_params_5 {
-       __le16 tx_bip_ref_pd_voltage[WL1271_INI_SUB_BAND_COUNT_5];
-       u8 tx_bip_ref_power[WL1271_INI_SUB_BAND_COUNT_5];
-       u8 tx_bip_ref_offset[WL1271_INI_SUB_BAND_COUNT_5];
-       u8 tx_per_rate_pwr_limits_normal[WL1271_INI_RATE_GROUP_COUNT];
-       u8 tx_per_rate_pwr_limits_degraded[WL1271_INI_RATE_GROUP_COUNT];
-       u8 tx_per_rate_pwr_limits_extreme[WL1271_INI_RATE_GROUP_COUNT];
-       u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_5];
-       u8 tx_pd_vs_rate_offsets[WL1271_INI_RATE_GROUP_COUNT];
-       u8 tx_ibias[WL1271_INI_RATE_GROUP_COUNT];
-       u8 rx_fem_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
-       u8 degraded_low_to_normal_thr;
-       u8 normal_to_degraded_high_thr;
-} __packed;
-
-struct wl128x_ini_fem_params_5 {
-       __le16 tx_bip_ref_pd_voltage[WL1271_INI_SUB_BAND_COUNT_5];
-       u8 tx_bip_ref_power[WL1271_INI_SUB_BAND_COUNT_5];
-       u8 tx_bip_ref_offset[WL1271_INI_SUB_BAND_COUNT_5];
-       u8 tx_per_rate_pwr_limits_normal[WL128X_INI_RATE_GROUP_COUNT];
-       u8 tx_per_rate_pwr_limits_degraded[WL128X_INI_RATE_GROUP_COUNT];
-       u8 tx_per_rate_pwr_limits_extreme[WL128X_INI_RATE_GROUP_COUNT];
-       u8 tx_per_chan_pwr_limits_ofdm[WL1271_INI_CHANNEL_COUNT_5];
-       u8 tx_pd_vs_rate_offsets[WL128X_INI_RATE_GROUP_COUNT];
-       u8 tx_ibias[WL128X_INI_RATE_GROUP_COUNT];
-       u8 tx_pd_vs_chan_offsets[WL1271_INI_CHANNEL_COUNT_5];
-       u8 tx_pd_vs_temperature[WL1271_INI_SUB_BAND_COUNT_5 *
-               WL128X_INI_PD_VS_TEMPERATURE_RANGES];
-       u8 rx_fem_insertion_loss[WL1271_INI_SUB_BAND_COUNT_5];
-       u8 degraded_low_to_normal_thr;
-       u8 normal_to_degraded_high_thr;
-} __packed;
-
-/* NVS data structure */
-#define WL1271_INI_NVS_SECTION_SIZE                 468
-#define WL1271_INI_FEM_MODULE_COUNT                  2
-
-#define WL1271_INI_LEGACY_NVS_FILE_SIZE              800
-
-struct wl1271_nvs_file {
-       /* NVS section - must be first! */
-       u8 nvs[WL1271_INI_NVS_SECTION_SIZE];
-
-       /* INI section */
-       struct wl1271_ini_general_params general_params;
-       u8 padding1;
-       struct wl1271_ini_band_params_2 stat_radio_params_2;
-       u8 padding2;
-       struct {
-               struct wl1271_ini_fem_params_2 params;
-               u8 padding;
-       } dyn_radio_params_2[WL1271_INI_FEM_MODULE_COUNT];
-       struct wl1271_ini_band_params_5 stat_radio_params_5;
-       u8 padding3;
-       struct {
-               struct wl1271_ini_fem_params_5 params;
-               u8 padding;
-       } dyn_radio_params_5[WL1271_INI_FEM_MODULE_COUNT];
-} __packed;
-
-struct wl128x_nvs_file {
-       /* NVS section - must be first! */
-       u8 nvs[WL1271_INI_NVS_SECTION_SIZE];
-
-       /* INI section */
-       struct wl128x_ini_general_params general_params;
-       u8 fem_vendor_and_options;
-       struct wl128x_ini_band_params_2 stat_radio_params_2;
-       u8 padding2;
-       struct {
-               struct wl128x_ini_fem_params_2 params;
-               u8 padding;
-       } dyn_radio_params_2[WL1271_INI_FEM_MODULE_COUNT];
-       struct wl128x_ini_band_params_5 stat_radio_params_5;
-       u8 padding3;
-       struct {
-               struct wl128x_ini_fem_params_5 params;
-               u8 padding;
-       } dyn_radio_params_5[WL1271_INI_FEM_MODULE_COUNT];
-} __packed;
-#endif
diff --git a/drivers/net/wireless/wl12xx/init.c b/drivers/net/wireless/wl12xx/init.c
deleted file mode 100644 (file)
index 203fbeb..0000000
+++ /dev/null
@@ -1,765 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-
-#include "debug.h"
-#include "init.h"
-#include "wl12xx_80211.h"
-#include "acx.h"
-#include "cmd.h"
-#include "reg.h"
-#include "tx.h"
-#include "io.h"
-
-int wl1271_init_templates_config(struct wl1271 *wl)
-{
-       int ret, i;
-       size_t max_size;
-
-       /* send empty templates for fw memory reservation */
-       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
-                                     CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
-                                     WL1271_CMD_TEMPL_MAX_SIZE,
-                                     0, WL1271_RATE_AUTOMATIC);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
-                                     CMD_TEMPL_CFG_PROBE_REQ_5,
-                                     NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
-                                     WL1271_RATE_AUTOMATIC);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
-                                     CMD_TEMPL_NULL_DATA, NULL,
-                                     sizeof(struct wl12xx_null_data_template),
-                                     0, WL1271_RATE_AUTOMATIC);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
-                                     CMD_TEMPL_PS_POLL, NULL,
-                                     sizeof(struct wl12xx_ps_poll_template),
-                                     0, WL1271_RATE_AUTOMATIC);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
-                                     CMD_TEMPL_QOS_NULL_DATA, NULL,
-                                     sizeof
-                                     (struct ieee80211_qos_hdr),
-                                     0, WL1271_RATE_AUTOMATIC);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
-                                     CMD_TEMPL_PROBE_RESPONSE, NULL,
-                                     WL1271_CMD_TEMPL_DFLT_SIZE,
-                                     0, WL1271_RATE_AUTOMATIC);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
-                                     CMD_TEMPL_BEACON, NULL,
-                                     WL1271_CMD_TEMPL_DFLT_SIZE,
-                                     0, WL1271_RATE_AUTOMATIC);
-       if (ret < 0)
-               return ret;
-
-       max_size = sizeof(struct wl12xx_arp_rsp_template) +
-                  WL1271_EXTRA_SPACE_MAX;
-       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
-                                     CMD_TEMPL_ARP_RSP, NULL,
-                                     max_size,
-                                     0, WL1271_RATE_AUTOMATIC);
-       if (ret < 0)
-               return ret;
-
-       /*
-        * Put very large empty placeholders for all templates. These
-        * reserve memory for later.
-        */
-       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
-                                     CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
-                                     WL1271_CMD_TEMPL_MAX_SIZE,
-                                     0, WL1271_RATE_AUTOMATIC);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
-                                     CMD_TEMPL_AP_BEACON, NULL,
-                                     WL1271_CMD_TEMPL_MAX_SIZE,
-                                     0, WL1271_RATE_AUTOMATIC);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
-                                     CMD_TEMPL_DEAUTH_AP, NULL,
-                                     sizeof
-                                     (struct wl12xx_disconn_template),
-                                     0, WL1271_RATE_AUTOMATIC);
-       if (ret < 0)
-               return ret;
-
-       for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
-               ret = wl1271_cmd_template_set(wl, WL12XX_INVALID_ROLE_ID,
-                                             CMD_TEMPL_KLV, NULL,
-                                             sizeof(struct ieee80211_qos_hdr),
-                                             i, WL1271_RATE_AUTOMATIC);
-               if (ret < 0)
-                       return ret;
-       }
-
-       return 0;
-}
-
-static int wl1271_ap_init_deauth_template(struct wl1271 *wl,
-                                         struct wl12xx_vif *wlvif)
-{
-       struct wl12xx_disconn_template *tmpl;
-       int ret;
-       u32 rate;
-
-       tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
-       if (!tmpl) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
-                                            IEEE80211_STYPE_DEAUTH);
-
-       rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
-       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
-                                     CMD_TEMPL_DEAUTH_AP,
-                                     tmpl, sizeof(*tmpl), 0, rate);
-
-out:
-       kfree(tmpl);
-       return ret;
-}
-
-static int wl1271_ap_init_null_template(struct wl1271 *wl,
-                                       struct ieee80211_vif *vif)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       struct ieee80211_hdr_3addr *nullfunc;
-       int ret;
-       u32 rate;
-
-       nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
-       if (!nullfunc) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
-                                             IEEE80211_STYPE_NULLFUNC |
-                                             IEEE80211_FCTL_FROMDS);
-
-       /* nullfunc->addr1 is filled by FW */
-
-       memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
-       memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
-
-       rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
-       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
-                                     CMD_TEMPL_NULL_DATA, nullfunc,
-                                     sizeof(*nullfunc), 0, rate);
-
-out:
-       kfree(nullfunc);
-       return ret;
-}
-
-static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
-                                           struct ieee80211_vif *vif)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       struct ieee80211_qos_hdr *qosnull;
-       int ret;
-       u32 rate;
-
-       qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
-       if (!qosnull) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
-                                            IEEE80211_STYPE_QOS_NULLFUNC |
-                                            IEEE80211_FCTL_FROMDS);
-
-       /* qosnull->addr1 is filled by FW */
-
-       memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
-       memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
-
-       rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
-       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
-                                     CMD_TEMPL_QOS_NULL_DATA, qosnull,
-                                     sizeof(*qosnull), 0, rate);
-
-out:
-       kfree(qosnull);
-       return ret;
-}
-
-static int wl12xx_init_rx_config(struct wl1271 *wl)
-{
-       int ret;
-
-       ret = wl1271_acx_rx_msdu_life_time(wl);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-static int wl12xx_init_phy_vif_config(struct wl1271 *wl,
-                                           struct wl12xx_vif *wlvif)
-{
-       int ret;
-
-       ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_acx_service_period_timeout(wl, wlvif);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-static int wl1271_init_sta_beacon_filter(struct wl1271 *wl,
-                                        struct wl12xx_vif *wlvif)
-{
-       int ret;
-
-       ret = wl1271_acx_beacon_filter_table(wl, wlvif);
-       if (ret < 0)
-               return ret;
-
-       /* enable beacon filtering */
-       ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1271_init_pta(struct wl1271 *wl)
-{
-       int ret;
-
-       ret = wl12xx_acx_sg_cfg(wl);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1271_init_energy_detection(struct wl1271 *wl)
-{
-       int ret;
-
-       ret = wl1271_acx_cca_threshold(wl);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-static int wl1271_init_beacon_broadcast(struct wl1271 *wl,
-                                       struct wl12xx_vif *wlvif)
-{
-       int ret;
-
-       ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-static int wl12xx_init_fwlog(struct wl1271 *wl)
-{
-       int ret;
-
-       if (wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED)
-               return 0;
-
-       ret = wl12xx_cmd_config_fwlog(wl);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-/* generic sta initialization (non vif-specific) */
-static int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       int ret;
-
-       /* PS config */
-       ret = wl12xx_acx_config_ps(wl, wlvif);
-       if (ret < 0)
-               return ret;
-
-       /* FM WLAN coexistence */
-       ret = wl1271_acx_fm_coex(wl);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_acx_sta_rate_policies(wl, wlvif);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
-                                      struct ieee80211_vif *vif)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       int ret, i;
-
-       /* disable all keep-alive templates */
-       for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
-               ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
-                                                  ACX_KEEP_ALIVE_TPL_INVALID);
-               if (ret < 0)
-                       return ret;
-       }
-
-       /* disable the keep-alive feature */
-       ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-/* generic ap initialization (non vif-specific) */
-static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       int ret;
-
-       ret = wl1271_init_ap_rates(wl, wlvif);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       int ret;
-
-       ret = wl1271_ap_init_deauth_template(wl, wlvif);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_ap_init_null_template(wl, vif);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_ap_init_qos_null_template(wl, vif);
-       if (ret < 0)
-               return ret;
-
-       /*
-        * when operating as AP we want to receive external beacons for
-        * configuring ERP protection.
-        */
-       ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
-                                     struct ieee80211_vif *vif)
-{
-       return wl1271_ap_init_templates(wl, vif);
-}
-
-int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       int i, ret;
-       struct conf_tx_rate_class rc;
-       u32 supported_rates;
-
-       wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
-                    wlvif->basic_rate_set);
-
-       if (wlvif->basic_rate_set == 0)
-               return -EINVAL;
-
-       rc.enabled_rates = wlvif->basic_rate_set;
-       rc.long_retry_limit = 10;
-       rc.short_retry_limit = 10;
-       rc.aflags = 0;
-       ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
-       if (ret < 0)
-               return ret;
-
-       /* use the min basic rate for AP broadcast/multicast */
-       rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
-       rc.short_retry_limit = 10;
-       rc.long_retry_limit = 10;
-       rc.aflags = 0;
-       ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.bcast_rate_idx);
-       if (ret < 0)
-               return ret;
-
-       /*
-        * If the basic rates contain OFDM rates, use OFDM only
-        * rates for unicast TX as well. Else use all supported rates.
-        */
-       if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
-               supported_rates = CONF_TX_OFDM_RATES;
-       else
-               supported_rates = CONF_TX_AP_ENABLED_RATES;
-
-       /* unconditionally enable HT rates */
-       supported_rates |= CONF_TX_MCS_RATES;
-
-       /* configure unicast TX rate classes */
-       for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
-               rc.enabled_rates = supported_rates;
-               rc.short_retry_limit = 10;
-               rc.long_retry_limit = 10;
-               rc.aflags = 0;
-               ret = wl1271_acx_ap_rate_policy(wl, &rc,
-                                               wlvif->ap.ucast_rate_idx[i]);
-               if (ret < 0)
-                       return ret;
-       }
-
-       return 0;
-}
-
-static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       /* Reset the BA RX indicators */
-       wlvif->ba_allowed = true;
-       wl->ba_rx_session_count = 0;
-
-       /* BA is supported in STA/AP modes */
-       if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
-           wlvif->bss_type != BSS_TYPE_STA_BSS) {
-               wlvif->ba_support = false;
-               return 0;
-       }
-
-       wlvif->ba_support = true;
-
-       /* 802.11n initiator BA session setting */
-       return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
-}
-
-int wl1271_chip_specific_init(struct wl1271 *wl)
-{
-       int ret = 0;
-
-       if (wl->chip.id == CHIP_ID_1283_PG20) {
-               u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
-
-               if (!(wl->quirks & WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT))
-                       /* Enable SDIO padding */
-                       host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
-
-               /* Must be before wl1271_acx_init_mem_config() */
-               ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
-               if (ret < 0)
-                       goto out;
-       }
-out:
-       return ret;
-}
-
-/* vif-specifc initialization */
-static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       int ret;
-
-       ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
-       if (ret < 0)
-               return ret;
-
-       /* Initialize connection monitoring thresholds */
-       ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
-       if (ret < 0)
-               return ret;
-
-       /* Beacon filtering */
-       ret = wl1271_init_sta_beacon_filter(wl, wlvif);
-       if (ret < 0)
-               return ret;
-
-       /* Beacons and broadcast settings */
-       ret = wl1271_init_beacon_broadcast(wl, wlvif);
-       if (ret < 0)
-               return ret;
-
-       /* Configure rssi/snr averaging weights */
-       ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-/* vif-specific intialization */
-static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       int ret;
-
-       ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
-       if (ret < 0)
-               return ret;
-
-       /* initialize Tx power */
-       ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       struct conf_tx_ac_category *conf_ac;
-       struct conf_tx_tid *conf_tid;
-       bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
-       int ret, i;
-
-       /*
-        * consider all existing roles before configuring psm.
-        * TODO: reconfigure on interface removal.
-        */
-       if (!wl->ap_count) {
-               if (is_ap) {
-                       /* Configure for power always on */
-                       ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
-                       if (ret < 0)
-                               return ret;
-               } else if (!wl->sta_count) {
-                       /* Configure for ELP power saving */
-                       ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
-                       if (ret < 0)
-                               return ret;
-               }
-       }
-
-       /* Mode specific init */
-       if (is_ap) {
-               ret = wl1271_ap_hw_init(wl, wlvif);
-               if (ret < 0)
-                       return ret;
-
-               ret = wl12xx_init_ap_role(wl, wlvif);
-               if (ret < 0)
-                       return ret;
-       } else {
-               ret = wl1271_sta_hw_init(wl, wlvif);
-               if (ret < 0)
-                       return ret;
-
-               ret = wl12xx_init_sta_role(wl, wlvif);
-               if (ret < 0)
-                       return ret;
-       }
-
-       wl12xx_init_phy_vif_config(wl, wlvif);
-
-       /* Default TID/AC configuration */
-       BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
-       for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
-               conf_ac = &wl->conf.tx.ac_conf[i];
-               ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
-                                       conf_ac->cw_min, conf_ac->cw_max,
-                                       conf_ac->aifsn, conf_ac->tx_op_limit);
-               if (ret < 0)
-                       return ret;
-
-               conf_tid = &wl->conf.tx.tid_conf[i];
-               ret = wl1271_acx_tid_cfg(wl, wlvif,
-                                        conf_tid->queue_id,
-                                        conf_tid->channel_type,
-                                        conf_tid->tsid,
-                                        conf_tid->ps_scheme,
-                                        conf_tid->ack_policy,
-                                        conf_tid->apsd_conf[0],
-                                        conf_tid->apsd_conf[1]);
-               if (ret < 0)
-                       return ret;
-       }
-
-       /* Configure HW encryption */
-       ret = wl1271_acx_feature_cfg(wl, wlvif);
-       if (ret < 0)
-               return ret;
-
-       /* Mode specific init - post mem init */
-       if (is_ap)
-               ret = wl1271_ap_hw_init_post_mem(wl, vif);
-       else
-               ret = wl1271_sta_hw_init_post_mem(wl, vif);
-
-       if (ret < 0)
-               return ret;
-
-       /* Configure initiator BA sessions policies */
-       ret = wl1271_set_ba_policies(wl, wlvif);
-       if (ret < 0)
-               return ret;
-
-       return 0;
-}
-
-int wl1271_hw_init(struct wl1271 *wl)
-{
-       int ret;
-
-       if (wl->chip.id == CHIP_ID_1283_PG20) {
-               ret = wl128x_cmd_general_parms(wl);
-               if (ret < 0)
-                       return ret;
-               ret = wl128x_cmd_radio_parms(wl);
-               if (ret < 0)
-                       return ret;
-       } else {
-               ret = wl1271_cmd_general_parms(wl);
-               if (ret < 0)
-                       return ret;
-               ret = wl1271_cmd_radio_parms(wl);
-               if (ret < 0)
-                       return ret;
-               ret = wl1271_cmd_ext_radio_parms(wl);
-               if (ret < 0)
-                       return ret;
-       }
-
-       /* Chip-specific init */
-       ret = wl1271_chip_specific_init(wl);
-       if (ret < 0)
-               return ret;
-
-       /* Init templates */
-       ret = wl1271_init_templates_config(wl);
-       if (ret < 0)
-               return ret;
-
-       ret = wl12xx_acx_mem_cfg(wl);
-       if (ret < 0)
-               return ret;
-
-       /* Configure the FW logger */
-       ret = wl12xx_init_fwlog(wl);
-       if (ret < 0)
-               return ret;
-
-       /* Bluetooth WLAN coexistence */
-       ret = wl1271_init_pta(wl);
-       if (ret < 0)
-               return ret;
-
-       /* Default memory configuration */
-       ret = wl1271_acx_init_mem_config(wl);
-       if (ret < 0)
-               return ret;
-
-       /* RX config */
-       ret = wl12xx_init_rx_config(wl);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       ret = wl1271_acx_dco_itrim_params(wl);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       /* Configure TX patch complete interrupt behavior */
-       ret = wl1271_acx_tx_config_options(wl);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       /* RX complete interrupt pacing */
-       ret = wl1271_acx_init_rx_interrupt(wl);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       /* Energy detection */
-       ret = wl1271_init_energy_detection(wl);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       /* Default fragmentation threshold */
-       ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       /* Enable data path */
-       ret = wl1271_cmd_data_path(wl, 1);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       /* configure PM */
-       ret = wl1271_acx_pm_config(wl);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       ret = wl12xx_acx_set_rate_mgmt_params(wl);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       /* configure hangover */
-       ret = wl12xx_acx_config_hangover(wl);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       return 0;
-
- out_free_memmap:
-       kfree(wl->target_mem_map);
-       wl->target_mem_map = NULL;
-
-       return ret;
-}
diff --git a/drivers/net/wireless/wl12xx/init.h b/drivers/net/wireless/wl12xx/init.h
deleted file mode 100644 (file)
index 2da0f40..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __INIT_H__
-#define __INIT_H__
-
-#include "wl12xx.h"
-
-int wl1271_hw_init_power_auth(struct wl1271 *wl);
-int wl1271_init_templates_config(struct wl1271 *wl);
-int wl1271_init_pta(struct wl1271 *wl);
-int wl1271_init_energy_detection(struct wl1271 *wl);
-int wl1271_chip_specific_init(struct wl1271 *wl);
-int wl1271_hw_init(struct wl1271 *wl);
-int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif);
-int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif);
-
-#endif
diff --git a/drivers/net/wireless/wl12xx/io.c b/drivers/net/wireless/wl12xx/io.c
deleted file mode 100644 (file)
index c574a3b..0000000
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2008-2010 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/spi/spi.h>
-#include <linux/interrupt.h>
-
-#include "wl12xx.h"
-#include "debug.h"
-#include "wl12xx_80211.h"
-#include "io.h"
-#include "tx.h"
-
-#define OCP_CMD_LOOP  32
-
-#define OCP_CMD_WRITE 0x1
-#define OCP_CMD_READ  0x2
-
-#define OCP_READY_MASK  BIT(18)
-#define OCP_STATUS_MASK (BIT(16) | BIT(17))
-
-#define OCP_STATUS_NO_RESP    0x00000
-#define OCP_STATUS_OK         0x10000
-#define OCP_STATUS_REQ_FAILED 0x20000
-#define OCP_STATUS_RESP_ERROR 0x30000
-
-struct wl1271_partition_set wl12xx_part_table[PART_TABLE_LEN] = {
-       [PART_DOWN] = {
-               .mem = {
-                       .start = 0x00000000,
-                       .size  = 0x000177c0
-               },
-               .reg = {
-                       .start = REGISTERS_BASE,
-                       .size  = 0x00008800
-               },
-               .mem2 = {
-                       .start = 0x00000000,
-                       .size  = 0x00000000
-               },
-               .mem3 = {
-                       .start = 0x00000000,
-                       .size  = 0x00000000
-               },
-       },
-
-       [PART_WORK] = {
-               .mem = {
-                       .start = 0x00040000,
-                       .size  = 0x00014fc0
-               },
-               .reg = {
-                       .start = REGISTERS_BASE,
-                       .size  = 0x0000a000
-               },
-               .mem2 = {
-                       .start = 0x003004f8,
-                       .size  = 0x00000004
-               },
-               .mem3 = {
-                       .start = 0x00040404,
-                       .size  = 0x00000000
-               },
-       },
-
-       [PART_DRPW] = {
-               .mem = {
-                       .start = 0x00040000,
-                       .size  = 0x00014fc0
-               },
-               .reg = {
-                       .start = DRPW_BASE,
-                       .size  = 0x00006000
-               },
-               .mem2 = {
-                       .start = 0x00000000,
-                       .size  = 0x00000000
-               },
-               .mem3 = {
-                       .start = 0x00000000,
-                       .size  = 0x00000000
-               }
-       }
-};
-
-bool wl1271_set_block_size(struct wl1271 *wl)
-{
-       if (wl->if_ops->set_block_size) {
-               wl->if_ops->set_block_size(wl->dev, WL12XX_BUS_BLOCK_SIZE);
-               return true;
-       }
-
-       return false;
-}
-
-void wl1271_disable_interrupts(struct wl1271 *wl)
-{
-       disable_irq(wl->irq);
-}
-
-void wl1271_enable_interrupts(struct wl1271 *wl)
-{
-       enable_irq(wl->irq);
-}
-
-/* Set the SPI partitions to access the chip addresses
- *
- * To simplify driver code, a fixed (virtual) memory map is defined for
- * register and memory addresses. Because in the chipset, in different stages
- * of operation, those addresses will move around, an address translation
- * mechanism is required.
- *
- * There are four partitions (three memory and one register partition),
- * which are mapped to two different areas of the hardware memory.
- *
- *                                Virtual address
- *                                     space
- *
- *                                    |    |
- *                                 ...+----+--> mem.start
- *          Physical address    ...   |    |
- *               space       ...      |    | [PART_0]
- *                        ...         |    |
- *  00000000  <--+----+...         ...+----+--> mem.start + mem.size
- *               |    |         ...   |    |
- *               |MEM |      ...      |    |
- *               |    |   ...         |    |
- *  mem.size  <--+----+...            |    | {unused area)
- *               |    |   ...         |    |
- *               |REG |      ...      |    |
- *  mem.size     |    |         ...   |    |
- *      +     <--+----+...         ...+----+--> reg.start
- *  reg.size     |    |   ...         |    |
- *               |MEM2|      ...      |    | [PART_1]
- *               |    |         ...   |    |
- *                                 ...+----+--> reg.start + reg.size
- *                                    |    |
- *
- */
-int wl1271_set_partition(struct wl1271 *wl,
-                        struct wl1271_partition_set *p)
-{
-       /* copy partition info */
-       memcpy(&wl->part, p, sizeof(*p));
-
-       wl1271_debug(DEBUG_SPI, "mem_start %08X mem_size %08X",
-                    p->mem.start, p->mem.size);
-       wl1271_debug(DEBUG_SPI, "reg_start %08X reg_size %08X",
-                    p->reg.start, p->reg.size);
-       wl1271_debug(DEBUG_SPI, "mem2_start %08X mem2_size %08X",
-                    p->mem2.start, p->mem2.size);
-       wl1271_debug(DEBUG_SPI, "mem3_start %08X mem3_size %08X",
-                    p->mem3.start, p->mem3.size);
-
-       /* write partition info to the chipset */
-       wl1271_raw_write32(wl, HW_PART0_START_ADDR, p->mem.start);
-       wl1271_raw_write32(wl, HW_PART0_SIZE_ADDR, p->mem.size);
-       wl1271_raw_write32(wl, HW_PART1_START_ADDR, p->reg.start);
-       wl1271_raw_write32(wl, HW_PART1_SIZE_ADDR, p->reg.size);
-       wl1271_raw_write32(wl, HW_PART2_START_ADDR, p->mem2.start);
-       wl1271_raw_write32(wl, HW_PART2_SIZE_ADDR, p->mem2.size);
-       wl1271_raw_write32(wl, HW_PART3_START_ADDR, p->mem3.start);
-
-       return 0;
-}
-EXPORT_SYMBOL_GPL(wl1271_set_partition);
-
-void wl1271_io_reset(struct wl1271 *wl)
-{
-       if (wl->if_ops->reset)
-               wl->if_ops->reset(wl->dev);
-}
-
-void wl1271_io_init(struct wl1271 *wl)
-{
-       if (wl->if_ops->init)
-               wl->if_ops->init(wl->dev);
-}
-
-void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val)
-{
-       /* write address >> 1 + 0x30000 to OCP_POR_CTR */
-       addr = (addr >> 1) + 0x30000;
-       wl1271_write32(wl, OCP_POR_CTR, addr);
-
-       /* write value to OCP_POR_WDATA */
-       wl1271_write32(wl, OCP_DATA_WRITE, val);
-
-       /* write 1 to OCP_CMD */
-       wl1271_write32(wl, OCP_CMD, OCP_CMD_WRITE);
-}
-
-u16 wl1271_top_reg_read(struct wl1271 *wl, int addr)
-{
-       u32 val;
-       int timeout = OCP_CMD_LOOP;
-
-       /* write address >> 1 + 0x30000 to OCP_POR_CTR */
-       addr = (addr >> 1) + 0x30000;
-       wl1271_write32(wl, OCP_POR_CTR, addr);
-
-       /* write 2 to OCP_CMD */
-       wl1271_write32(wl, OCP_CMD, OCP_CMD_READ);
-
-       /* poll for data ready */
-       do {
-               val = wl1271_read32(wl, OCP_DATA_READ);
-       } while (!(val & OCP_READY_MASK) && --timeout);
-
-       if (!timeout) {
-               wl1271_warning("Top register access timed out.");
-               return 0xffff;
-       }
-
-       /* check data status and return if OK */
-       if ((val & OCP_STATUS_MASK) == OCP_STATUS_OK)
-               return val & 0xffff;
-       else {
-               wl1271_warning("Top register access returned error.");
-               return 0xffff;
-       }
-}
-
diff --git a/drivers/net/wireless/wl12xx/io.h b/drivers/net/wireless/wl12xx/io.h
deleted file mode 100644 (file)
index 4fb3dab..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
- * Copyright (C) 2008-2010 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __IO_H__
-#define __IO_H__
-
-#include <linux/irqreturn.h>
-#include "reg.h"
-
-#define HW_ACCESS_MEMORY_MAX_RANGE     0x1FFC0
-
-#define HW_PARTITION_REGISTERS_ADDR     0x1FFC0
-#define HW_PART0_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR)
-#define HW_PART0_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 4)
-#define HW_PART1_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR + 8)
-#define HW_PART1_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 12)
-#define HW_PART2_SIZE_ADDR              (HW_PARTITION_REGISTERS_ADDR + 16)
-#define HW_PART2_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 20)
-#define HW_PART3_START_ADDR             (HW_PARTITION_REGISTERS_ADDR + 24)
-
-#define HW_ACCESS_REGISTER_SIZE         4
-
-#define HW_ACCESS_PRAM_MAX_RANGE       0x3c000
-
-extern struct wl1271_partition_set wl12xx_part_table[PART_TABLE_LEN];
-
-struct wl1271;
-
-void wl1271_disable_interrupts(struct wl1271 *wl);
-void wl1271_enable_interrupts(struct wl1271 *wl);
-
-void wl1271_io_reset(struct wl1271 *wl);
-void wl1271_io_init(struct wl1271 *wl);
-
-/* Raw target IO, address is not translated */
-static inline void wl1271_raw_write(struct wl1271 *wl, int addr, void *buf,
-                                   size_t len, bool fixed)
-{
-       wl->if_ops->write(wl->dev, addr, buf, len, fixed);
-}
-
-static inline void wl1271_raw_read(struct wl1271 *wl, int addr, void *buf,
-                                  size_t len, bool fixed)
-{
-       wl->if_ops->read(wl->dev, addr, buf, len, fixed);
-}
-
-static inline u32 wl1271_raw_read32(struct wl1271 *wl, int addr)
-{
-       wl1271_raw_read(wl, addr, &wl->buffer_32,
-                           sizeof(wl->buffer_32), false);
-
-       return le32_to_cpu(wl->buffer_32);
-}
-
-static inline void wl1271_raw_write32(struct wl1271 *wl, int addr, u32 val)
-{
-       wl->buffer_32 = cpu_to_le32(val);
-       wl1271_raw_write(wl, addr, &wl->buffer_32,
-                            sizeof(wl->buffer_32), false);
-}
-
-/* Translated target IO */
-static inline int wl1271_translate_addr(struct wl1271 *wl, int addr)
-{
-       /*
-        * To translate, first check to which window of addresses the
-        * particular address belongs. Then subtract the starting address
-        * of that window from the address. Then, add offset of the
-        * translated region.
-        *
-        * The translated regions occur next to each other in physical device
-        * memory, so just add the sizes of the preceding address regions to
-        * get the offset to the new region.
-        *
-        * Currently, only the two first regions are addressed, and the
-        * assumption is that all addresses will fall into either of those
-        * two.
-        */
-       if ((addr >= wl->part.reg.start) &&
-           (addr < wl->part.reg.start + wl->part.reg.size))
-               return addr - wl->part.reg.start + wl->part.mem.size;
-       else
-               return addr - wl->part.mem.start;
-}
-
-static inline void wl1271_read(struct wl1271 *wl, int addr, void *buf,
-                              size_t len, bool fixed)
-{
-       int physical;
-
-       physical = wl1271_translate_addr(wl, addr);
-
-       wl1271_raw_read(wl, physical, buf, len, fixed);
-}
-
-static inline void wl1271_write(struct wl1271 *wl, int addr, void *buf,
-                               size_t len, bool fixed)
-{
-       int physical;
-
-       physical = wl1271_translate_addr(wl, addr);
-
-       wl1271_raw_write(wl, physical, buf, len, fixed);
-}
-
-static inline void wl1271_read_hwaddr(struct wl1271 *wl, int hwaddr,
-                                     void *buf, size_t len, bool fixed)
-{
-       int physical;
-       int addr;
-
-       /* Addresses are stored internally as addresses to 32 bytes blocks */
-       addr = hwaddr << 5;
-
-       physical = wl1271_translate_addr(wl, addr);
-
-       wl1271_raw_read(wl, physical, buf, len, fixed);
-}
-
-static inline u32 wl1271_read32(struct wl1271 *wl, int addr)
-{
-       return wl1271_raw_read32(wl, wl1271_translate_addr(wl, addr));
-}
-
-static inline void wl1271_write32(struct wl1271 *wl, int addr, u32 val)
-{
-       wl1271_raw_write32(wl, wl1271_translate_addr(wl, addr), val);
-}
-
-static inline void wl1271_power_off(struct wl1271 *wl)
-{
-       wl->if_ops->power(wl->dev, false);
-       clear_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
-}
-
-static inline int wl1271_power_on(struct wl1271 *wl)
-{
-       int ret = wl->if_ops->power(wl->dev, true);
-       if (ret == 0)
-               set_bit(WL1271_FLAG_GPIO_POWER, &wl->flags);
-
-       return ret;
-}
-
-
-/* Top Register IO */
-void wl1271_top_reg_write(struct wl1271 *wl, int addr, u16 val);
-u16 wl1271_top_reg_read(struct wl1271 *wl, int addr);
-
-int wl1271_set_partition(struct wl1271 *wl,
-                        struct wl1271_partition_set *p);
-
-bool wl1271_set_block_size(struct wl1271 *wl);
-
-/* Functions from wl1271_main.c */
-
-int wl1271_tx_dummy_packet(struct wl1271 *wl);
-
-#endif
diff --git a/drivers/net/wireless/wl12xx/main.c b/drivers/net/wireless/wl12xx/main.c
deleted file mode 100644 (file)
index 362ff1a..0000000
+++ /dev/null
@@ -1,5624 +0,0 @@
-
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2008-2010 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/module.h>
-#include <linux/firmware.h>
-#include <linux/delay.h>
-#include <linux/spi/spi.h>
-#include <linux/crc32.h>
-#include <linux/etherdevice.h>
-#include <linux/vmalloc.h>
-#include <linux/platform_device.h>
-#include <linux/slab.h>
-#include <linux/wl12xx.h>
-#include <linux/sched.h>
-#include <linux/interrupt.h>
-
-#include "wl12xx.h"
-#include "debug.h"
-#include "wl12xx_80211.h"
-#include "reg.h"
-#include "io.h"
-#include "event.h"
-#include "tx.h"
-#include "rx.h"
-#include "ps.h"
-#include "init.h"
-#include "debugfs.h"
-#include "cmd.h"
-#include "boot.h"
-#include "testmode.h"
-#include "scan.h"
-
-#define WL1271_BOOT_RETRIES 3
-
-static struct conf_drv_settings default_conf = {
-       .sg = {
-               .params = {
-                       [CONF_SG_ACL_BT_MASTER_MIN_BR] = 10,
-                       [CONF_SG_ACL_BT_MASTER_MAX_BR] = 180,
-                       [CONF_SG_ACL_BT_SLAVE_MIN_BR] = 10,
-                       [CONF_SG_ACL_BT_SLAVE_MAX_BR] = 180,
-                       [CONF_SG_ACL_BT_MASTER_MIN_EDR] = 10,
-                       [CONF_SG_ACL_BT_MASTER_MAX_EDR] = 80,
-                       [CONF_SG_ACL_BT_SLAVE_MIN_EDR] = 10,
-                       [CONF_SG_ACL_BT_SLAVE_MAX_EDR] = 80,
-                       [CONF_SG_ACL_WLAN_PS_MASTER_BR] = 8,
-                       [CONF_SG_ACL_WLAN_PS_SLAVE_BR] = 8,
-                       [CONF_SG_ACL_WLAN_PS_MASTER_EDR] = 20,
-                       [CONF_SG_ACL_WLAN_PS_SLAVE_EDR] = 20,
-                       [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR] = 20,
-                       [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR] = 35,
-                       [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR] = 16,
-                       [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR] = 35,
-                       [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR] = 32,
-                       [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR] = 50,
-                       [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR] = 28,
-                       [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR] = 50,
-                       [CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR] = 10,
-                       [CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR] = 20,
-                       [CONF_SG_ACL_PASSIVE_SCAN_BT_BR] = 75,
-                       [CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR] = 15,
-                       [CONF_SG_ACL_PASSIVE_SCAN_BT_EDR] = 27,
-                       [CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR] = 17,
-                       /* active scan params */
-                       [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
-                       [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
-                       [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
-                       /* passive scan params */
-                       [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR] = 800,
-                       [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR] = 200,
-                       [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
-                       /* passive scan in dual antenna params */
-                       [CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN] = 0,
-                       [CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN] = 0,
-                       [CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN] = 0,
-                       /* general params */
-                       [CONF_SG_STA_FORCE_PS_IN_BT_SCO] = 1,
-                       [CONF_SG_ANTENNA_CONFIGURATION] = 0,
-                       [CONF_SG_BEACON_MISS_PERCENT] = 60,
-                       [CONF_SG_DHCP_TIME] = 5000,
-                       [CONF_SG_RXT] = 1200,
-                       [CONF_SG_TXT] = 1000,
-                       [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
-                       [CONF_SG_GENERAL_USAGE_BIT_MAP] = 3,
-                       [CONF_SG_HV3_MAX_SERVED] = 6,
-                       [CONF_SG_PS_POLL_TIMEOUT] = 10,
-                       [CONF_SG_UPSD_TIMEOUT] = 10,
-                       [CONF_SG_CONSECUTIVE_CTS_THRESHOLD] = 2,
-                       [CONF_SG_STA_RX_WINDOW_AFTER_DTIM] = 5,
-                       [CONF_SG_STA_CONNECTION_PROTECTION_TIME] = 30,
-                       /* AP params */
-                       [CONF_AP_BEACON_MISS_TX] = 3,
-                       [CONF_AP_RX_WINDOW_AFTER_BEACON] = 10,
-                       [CONF_AP_BEACON_WINDOW_INTERVAL] = 2,
-                       [CONF_AP_CONNECTION_PROTECTION_TIME] = 0,
-                       [CONF_AP_BT_ACL_VAL_BT_SERVE_TIME] = 25,
-                       [CONF_AP_BT_ACL_VAL_WL_SERVE_TIME] = 25,
-                       /* CTS Diluting params */
-                       [CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH] = 0,
-                       [CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER] = 0,
-               },
-               .state = CONF_SG_PROTECTIVE,
-       },
-       .rx = {
-               .rx_msdu_life_time           = 512000,
-               .packet_detection_threshold  = 0,
-               .ps_poll_timeout             = 15,
-               .upsd_timeout                = 15,
-               .rts_threshold               = IEEE80211_MAX_RTS_THRESHOLD,
-               .rx_cca_threshold            = 0,
-               .irq_blk_threshold           = 0xFFFF,
-               .irq_pkt_threshold           = 0,
-               .irq_timeout                 = 600,
-               .queue_type                  = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
-       },
-       .tx = {
-               .tx_energy_detection         = 0,
-               .sta_rc_conf                 = {
-                       .enabled_rates       = 0,
-                       .short_retry_limit   = 10,
-                       .long_retry_limit    = 10,
-                       .aflags              = 0,
-               },
-               .ac_conf_count               = 4,
-               .ac_conf                     = {
-                       [CONF_TX_AC_BE] = {
-                               .ac          = CONF_TX_AC_BE,
-                               .cw_min      = 15,
-                               .cw_max      = 63,
-                               .aifsn       = 3,
-                               .tx_op_limit = 0,
-                       },
-                       [CONF_TX_AC_BK] = {
-                               .ac          = CONF_TX_AC_BK,
-                               .cw_min      = 15,
-                               .cw_max      = 63,
-                               .aifsn       = 7,
-                               .tx_op_limit = 0,
-                       },
-                       [CONF_TX_AC_VI] = {
-                               .ac          = CONF_TX_AC_VI,
-                               .cw_min      = 15,
-                               .cw_max      = 63,
-                               .aifsn       = CONF_TX_AIFS_PIFS,
-                               .tx_op_limit = 3008,
-                       },
-                       [CONF_TX_AC_VO] = {
-                               .ac          = CONF_TX_AC_VO,
-                               .cw_min      = 15,
-                               .cw_max      = 63,
-                               .aifsn       = CONF_TX_AIFS_PIFS,
-                               .tx_op_limit = 1504,
-                       },
-               },
-               .max_tx_retries = 100,
-               .ap_aging_period = 300,
-               .tid_conf_count = 4,
-               .tid_conf = {
-                       [CONF_TX_AC_BE] = {
-                               .queue_id    = CONF_TX_AC_BE,
-                               .channel_type = CONF_CHANNEL_TYPE_EDCF,
-                               .tsid        = CONF_TX_AC_BE,
-                               .ps_scheme   = CONF_PS_SCHEME_LEGACY,
-                               .ack_policy  = CONF_ACK_POLICY_LEGACY,
-                               .apsd_conf   = {0, 0},
-                       },
-                       [CONF_TX_AC_BK] = {
-                               .queue_id    = CONF_TX_AC_BK,
-                               .channel_type = CONF_CHANNEL_TYPE_EDCF,
-                               .tsid        = CONF_TX_AC_BK,
-                               .ps_scheme   = CONF_PS_SCHEME_LEGACY,
-                               .ack_policy  = CONF_ACK_POLICY_LEGACY,
-                               .apsd_conf   = {0, 0},
-                       },
-                       [CONF_TX_AC_VI] = {
-                               .queue_id    = CONF_TX_AC_VI,
-                               .channel_type = CONF_CHANNEL_TYPE_EDCF,
-                               .tsid        = CONF_TX_AC_VI,
-                               .ps_scheme   = CONF_PS_SCHEME_LEGACY,
-                               .ack_policy  = CONF_ACK_POLICY_LEGACY,
-                               .apsd_conf   = {0, 0},
-                       },
-                       [CONF_TX_AC_VO] = {
-                               .queue_id    = CONF_TX_AC_VO,
-                               .channel_type = CONF_CHANNEL_TYPE_EDCF,
-                               .tsid        = CONF_TX_AC_VO,
-                               .ps_scheme   = CONF_PS_SCHEME_LEGACY,
-                               .ack_policy  = CONF_ACK_POLICY_LEGACY,
-                               .apsd_conf   = {0, 0},
-                       },
-               },
-               .frag_threshold              = IEEE80211_MAX_FRAG_THRESHOLD,
-               .tx_compl_timeout            = 700,
-               .tx_compl_threshold          = 4,
-               .basic_rate                  = CONF_HW_BIT_RATE_1MBPS,
-               .basic_rate_5                = CONF_HW_BIT_RATE_6MBPS,
-               .tmpl_short_retry_limit      = 10,
-               .tmpl_long_retry_limit       = 10,
-               .tx_watchdog_timeout         = 5000,
-       },
-       .conn = {
-               .wake_up_event               = CONF_WAKE_UP_EVENT_DTIM,
-               .listen_interval             = 1,
-               .suspend_wake_up_event       = CONF_WAKE_UP_EVENT_N_DTIM,
-               .suspend_listen_interval     = 3,
-               .bcn_filt_mode               = CONF_BCN_FILT_MODE_ENABLED,
-               .bcn_filt_ie_count           = 2,
-               .bcn_filt_ie = {
-                       [0] = {
-                               .ie          = WLAN_EID_CHANNEL_SWITCH,
-                               .rule        = CONF_BCN_RULE_PASS_ON_APPEARANCE,
-                       },
-                       [1] = {
-                               .ie          = WLAN_EID_HT_OPERATION,
-                               .rule        = CONF_BCN_RULE_PASS_ON_CHANGE,
-                       },
-               },
-               .synch_fail_thold            = 10,
-               .bss_lose_timeout            = 100,
-               .beacon_rx_timeout           = 10000,
-               .broadcast_timeout           = 20000,
-               .rx_broadcast_in_ps          = 1,
-               .ps_poll_threshold           = 10,
-               .bet_enable                  = CONF_BET_MODE_ENABLE,
-               .bet_max_consecutive         = 50,
-               .psm_entry_retries           = 8,
-               .psm_exit_retries            = 16,
-               .psm_entry_nullfunc_retries  = 3,
-               .dynamic_ps_timeout          = 200,
-               .forced_ps                   = false,
-               .keep_alive_interval         = 55000,
-               .max_listen_interval         = 20,
-       },
-       .itrim = {
-               .enable = false,
-               .timeout = 50000,
-       },
-       .pm_config = {
-               .host_clk_settling_time = 5000,
-               .host_fast_wakeup_support = false
-       },
-       .roam_trigger = {
-               .trigger_pacing               = 1,
-               .avg_weight_rssi_beacon       = 20,
-               .avg_weight_rssi_data         = 10,
-               .avg_weight_snr_beacon        = 20,
-               .avg_weight_snr_data          = 10,
-       },
-       .scan = {
-               .min_dwell_time_active        = 7500,
-               .max_dwell_time_active        = 30000,
-               .min_dwell_time_passive       = 100000,
-               .max_dwell_time_passive       = 100000,
-               .num_probe_reqs               = 2,
-               .split_scan_timeout           = 50000,
-       },
-       .sched_scan = {
-               /* sched_scan requires dwell times in TU instead of TU/1000 */
-               .min_dwell_time_active = 30,
-               .max_dwell_time_active = 60,
-               .dwell_time_passive    = 100,
-               .dwell_time_dfs        = 150,
-               .num_probe_reqs        = 2,
-               .rssi_threshold        = -90,
-               .snr_threshold         = 0,
-       },
-       .rf = {
-               .tx_per_channel_power_compensation_2 = {
-                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-               },
-               .tx_per_channel_power_compensation_5 = {
-                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-                       0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-               },
-       },
-       .ht = {
-               .rx_ba_win_size = 8,
-               .tx_ba_win_size = 64,
-               .inactivity_timeout = 10000,
-               .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP,
-       },
-       .mem_wl127x = {
-               .num_stations                 = 1,
-               .ssid_profiles                = 1,
-               .rx_block_num                 = 70,
-               .tx_min_block_num             = 40,
-               .dynamic_memory               = 1,
-               .min_req_tx_blocks            = 100,
-               .min_req_rx_blocks            = 22,
-               .tx_min                       = 27,
-       },
-       .mem_wl128x = {
-               .num_stations                 = 1,
-               .ssid_profiles                = 1,
-               .rx_block_num                 = 40,
-               .tx_min_block_num             = 40,
-               .dynamic_memory               = 1,
-               .min_req_tx_blocks            = 45,
-               .min_req_rx_blocks            = 22,
-               .tx_min                       = 27,
-       },
-       .fm_coex = {
-               .enable                       = true,
-               .swallow_period               = 5,
-               .n_divider_fref_set_1         = 0xff,       /* default */
-               .n_divider_fref_set_2         = 12,
-               .m_divider_fref_set_1         = 148,
-               .m_divider_fref_set_2         = 0xffff,     /* default */
-               .coex_pll_stabilization_time  = 0xffffffff, /* default */
-               .ldo_stabilization_time       = 0xffff,     /* default */
-               .fm_disturbed_band_margin     = 0xff,       /* default */
-               .swallow_clk_diff             = 0xff,       /* default */
-       },
-       .rx_streaming = {
-               .duration                      = 150,
-               .queues                        = 0x1,
-               .interval                      = 20,
-               .always                        = 0,
-       },
-       .fwlog = {
-               .mode                         = WL12XX_FWLOG_ON_DEMAND,
-               .mem_blocks                   = 2,
-               .severity                     = 0,
-               .timestamp                    = WL12XX_FWLOG_TIMESTAMP_DISABLED,
-               .output                       = WL12XX_FWLOG_OUTPUT_HOST,
-               .threshold                    = 0,
-       },
-       .hci_io_ds = HCI_IO_DS_6MA,
-       .rate = {
-               .rate_retry_score = 32000,
-               .per_add = 8192,
-               .per_th1 = 2048,
-               .per_th2 = 4096,
-               .max_per = 8100,
-               .inverse_curiosity_factor = 5,
-               .tx_fail_low_th = 4,
-               .tx_fail_high_th = 10,
-               .per_alpha_shift = 4,
-               .per_add_shift = 13,
-               .per_beta1_shift = 10,
-               .per_beta2_shift = 8,
-               .rate_check_up = 2,
-               .rate_check_down = 12,
-               .rate_retry_policy = {
-                       0x00, 0x00, 0x00, 0x00, 0x00,
-                       0x00, 0x00, 0x00, 0x00, 0x00,
-                       0x00, 0x00, 0x00,
-               },
-       },
-       .hangover = {
-               .recover_time               = 0,
-               .hangover_period            = 20,
-               .dynamic_mode               = 1,
-               .early_termination_mode     = 1,
-               .max_period                 = 20,
-               .min_period                 = 1,
-               .increase_delta             = 1,
-               .decrease_delta             = 2,
-               .quiet_time                 = 4,
-               .increase_time              = 1,
-               .window_size                = 16,
-       },
-};
-
-static char *fwlog_param;
-static bool bug_on_recovery;
-
-static void __wl1271_op_remove_interface(struct wl1271 *wl,
-                                        struct ieee80211_vif *vif,
-                                        bool reset_tx_queues);
-static void wl1271_op_stop(struct ieee80211_hw *hw);
-static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-
-static int wl12xx_set_authorized(struct wl1271 *wl,
-                                struct wl12xx_vif *wlvif)
-{
-       int ret;
-
-       if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS))
-               return -EINVAL;
-
-       if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
-               return 0;
-
-       if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags))
-               return 0;
-
-       ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid);
-       if (ret < 0)
-               return ret;
-
-       wl12xx_croc(wl, wlvif->role_id);
-
-       wl1271_info("Association completed.");
-       return 0;
-}
-
-static int wl1271_reg_notify(struct wiphy *wiphy,
-                            struct regulatory_request *request)
-{
-       struct ieee80211_supported_band *band;
-       struct ieee80211_channel *ch;
-       int i;
-
-       band = wiphy->bands[IEEE80211_BAND_5GHZ];
-       for (i = 0; i < band->n_channels; i++) {
-               ch = &band->channels[i];
-               if (ch->flags & IEEE80211_CHAN_DISABLED)
-                       continue;
-
-               if (ch->flags & IEEE80211_CHAN_RADAR)
-                       ch->flags |= IEEE80211_CHAN_NO_IBSS |
-                                    IEEE80211_CHAN_PASSIVE_SCAN;
-
-       }
-
-       return 0;
-}
-
-static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                                  bool enable)
-{
-       int ret = 0;
-
-       /* we should hold wl->mutex */
-       ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable);
-       if (ret < 0)
-               goto out;
-
-       if (enable)
-               set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
-       else
-               clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
-out:
-       return ret;
-}
-
-/*
- * this function is being called when the rx_streaming interval
- * has beed changed or rx_streaming should be disabled
- */
-int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       int ret = 0;
-       int period = wl->conf.rx_streaming.interval;
-
-       /* don't reconfigure if rx_streaming is disabled */
-       if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
-               goto out;
-
-       /* reconfigure/disable according to new streaming_period */
-       if (period &&
-           test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
-           (wl->conf.rx_streaming.always ||
-            test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
-               ret = wl1271_set_rx_streaming(wl, wlvif, true);
-       else {
-               ret = wl1271_set_rx_streaming(wl, wlvif, false);
-               /* don't cancel_work_sync since we might deadlock */
-               del_timer_sync(&wlvif->rx_streaming_timer);
-       }
-out:
-       return ret;
-}
-
-static void wl1271_rx_streaming_enable_work(struct work_struct *work)
-{
-       int ret;
-       struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
-                                               rx_streaming_enable_work);
-       struct wl1271 *wl = wlvif->wl;
-
-       mutex_lock(&wl->mutex);
-
-       if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) ||
-           !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
-           (!wl->conf.rx_streaming.always &&
-            !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
-               goto out;
-
-       if (!wl->conf.rx_streaming.interval)
-               goto out;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1271_set_rx_streaming(wl, wlvif, true);
-       if (ret < 0)
-               goto out_sleep;
-
-       /* stop it after some time of inactivity */
-       mod_timer(&wlvif->rx_streaming_timer,
-                 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
-
-out_sleep:
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-static void wl1271_rx_streaming_disable_work(struct work_struct *work)
-{
-       int ret;
-       struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
-                                               rx_streaming_disable_work);
-       struct wl1271 *wl = wlvif->wl;
-
-       mutex_lock(&wl->mutex);
-
-       if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
-               goto out;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1271_set_rx_streaming(wl, wlvif, false);
-       if (ret)
-               goto out_sleep;
-
-out_sleep:
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-static void wl1271_rx_streaming_timer(unsigned long data)
-{
-       struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data;
-       struct wl1271 *wl = wlvif->wl;
-       ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work);
-}
-
-/* wl->mutex must be taken */
-void wl12xx_rearm_tx_watchdog_locked(struct wl1271 *wl)
-{
-       /* if the watchdog is not armed, don't do anything */
-       if (wl->tx_allocated_blocks == 0)
-               return;
-
-       cancel_delayed_work(&wl->tx_watchdog_work);
-       ieee80211_queue_delayed_work(wl->hw, &wl->tx_watchdog_work,
-               msecs_to_jiffies(wl->conf.tx.tx_watchdog_timeout));
-}
-
-static void wl12xx_tx_watchdog_work(struct work_struct *work)
-{
-       struct delayed_work *dwork;
-       struct wl1271 *wl;
-
-       dwork = container_of(work, struct delayed_work, work);
-       wl = container_of(dwork, struct wl1271, tx_watchdog_work);
-
-       mutex_lock(&wl->mutex);
-
-       if (unlikely(wl->state == WL1271_STATE_OFF))
-               goto out;
-
-       /* Tx went out in the meantime - everything is ok */
-       if (unlikely(wl->tx_allocated_blocks == 0))
-               goto out;
-
-       /*
-        * if a ROC is in progress, we might not have any Tx for a long
-        * time (e.g. pending Tx on the non-ROC channels)
-        */
-       if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) {
-               wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to ROC",
-                            wl->conf.tx.tx_watchdog_timeout);
-               wl12xx_rearm_tx_watchdog_locked(wl);
-               goto out;
-       }
-
-       /*
-        * if a scan is in progress, we might not have any Tx for a long
-        * time
-        */
-       if (wl->scan.state != WL1271_SCAN_STATE_IDLE) {
-               wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to scan",
-                            wl->conf.tx.tx_watchdog_timeout);
-               wl12xx_rearm_tx_watchdog_locked(wl);
-               goto out;
-       }
-
-       /*
-       * AP might cache a frame for a long time for a sleeping station,
-       * so rearm the timer if there's an AP interface with stations. If
-       * Tx is genuinely stuck we will most hopefully discover it when all
-       * stations are removed due to inactivity.
-       */
-       if (wl->active_sta_count) {
-               wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms. AP has "
-                            " %d stations",
-                             wl->conf.tx.tx_watchdog_timeout,
-                             wl->active_sta_count);
-               wl12xx_rearm_tx_watchdog_locked(wl);
-               goto out;
-       }
-
-       wl1271_error("Tx stuck (in FW) for %d ms. Starting recovery",
-                    wl->conf.tx.tx_watchdog_timeout);
-       wl12xx_queue_recovery_work(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-static void wl1271_conf_init(struct wl1271 *wl)
-{
-
-       /*
-        * This function applies the default configuration to the driver. This
-        * function is invoked upon driver load (spi probe.)
-        *
-        * The configuration is stored in a run-time structure in order to
-        * facilitate for run-time adjustment of any of the parameters. Making
-        * changes to the configuration structure will apply the new values on
-        * the next interface up (wl1271_op_start.)
-        */
-
-       /* apply driver default configuration */
-       memcpy(&wl->conf, &default_conf, sizeof(default_conf));
-
-       /* Adjust settings according to optional module parameters */
-       if (fwlog_param) {
-               if (!strcmp(fwlog_param, "continuous")) {
-                       wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
-               } else if (!strcmp(fwlog_param, "ondemand")) {
-                       wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND;
-               } else if (!strcmp(fwlog_param, "dbgpins")) {
-                       wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
-                       wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS;
-               } else if (!strcmp(fwlog_param, "disable")) {
-                       wl->conf.fwlog.mem_blocks = 0;
-                       wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE;
-               } else {
-                       wl1271_error("Unknown fwlog parameter %s", fwlog_param);
-               }
-       }
-}
-
-static int wl1271_plt_init(struct wl1271 *wl)
-{
-       int ret;
-
-       if (wl->chip.id == CHIP_ID_1283_PG20)
-               ret = wl128x_cmd_general_parms(wl);
-       else
-               ret = wl1271_cmd_general_parms(wl);
-       if (ret < 0)
-               return ret;
-
-       if (wl->chip.id == CHIP_ID_1283_PG20)
-               ret = wl128x_cmd_radio_parms(wl);
-       else
-               ret = wl1271_cmd_radio_parms(wl);
-       if (ret < 0)
-               return ret;
-
-       if (wl->chip.id != CHIP_ID_1283_PG20) {
-               ret = wl1271_cmd_ext_radio_parms(wl);
-               if (ret < 0)
-                       return ret;
-       }
-
-       /* Chip-specific initializations */
-       ret = wl1271_chip_specific_init(wl);
-       if (ret < 0)
-               return ret;
-
-       ret = wl1271_acx_init_mem_config(wl);
-       if (ret < 0)
-               return ret;
-
-       ret = wl12xx_acx_mem_cfg(wl);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       /* Enable data path */
-       ret = wl1271_cmd_data_path(wl, 1);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       /* Configure for CAM power saving (ie. always active) */
-       ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       /* configure PM */
-       ret = wl1271_acx_pm_config(wl);
-       if (ret < 0)
-               goto out_free_memmap;
-
-       return 0;
-
- out_free_memmap:
-       kfree(wl->target_mem_map);
-       wl->target_mem_map = NULL;
-
-       return ret;
-}
-
-static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
-                                       struct wl12xx_vif *wlvif,
-                                       u8 hlid, u8 tx_pkts)
-{
-       bool fw_ps, single_sta;
-
-       fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
-       single_sta = (wl->active_sta_count == 1);
-
-       /*
-        * Wake up from high level PS if the STA is asleep with too little
-        * packets in FW or if the STA is awake.
-        */
-       if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS)
-               wl12xx_ps_link_end(wl, wlvif, hlid);
-
-       /*
-        * Start high-level PS if the STA is asleep with enough blocks in FW.
-        * Make an exception if this is the only connected station. In this
-        * case FW-memory congestion is not a problem.
-        */
-       else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
-               wl12xx_ps_link_start(wl, wlvif, hlid, true);
-}
-
-static void wl12xx_irq_update_links_status(struct wl1271 *wl,
-                                          struct wl12xx_vif *wlvif,
-                                          struct wl12xx_fw_status *status)
-{
-       struct wl1271_link *lnk;
-       u32 cur_fw_ps_map;
-       u8 hlid, cnt;
-
-       /* TODO: also use link_fast_bitmap here */
-
-       cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
-       if (wl->ap_fw_ps_map != cur_fw_ps_map) {
-               wl1271_debug(DEBUG_PSM,
-                            "link ps prev 0x%x cur 0x%x changed 0x%x",
-                            wl->ap_fw_ps_map, cur_fw_ps_map,
-                            wl->ap_fw_ps_map ^ cur_fw_ps_map);
-
-               wl->ap_fw_ps_map = cur_fw_ps_map;
-       }
-
-       for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) {
-               lnk = &wl->links[hlid];
-               cnt = status->tx_lnk_free_pkts[hlid] - lnk->prev_freed_pkts;
-
-               lnk->prev_freed_pkts = status->tx_lnk_free_pkts[hlid];
-               lnk->allocated_pkts -= cnt;
-
-               wl12xx_irq_ps_regulate_link(wl, wlvif, hlid,
-                                           lnk->allocated_pkts);
-       }
-}
-
-static void wl12xx_fw_status(struct wl1271 *wl,
-                            struct wl12xx_fw_status *status)
-{
-       struct wl12xx_vif *wlvif;
-       struct timespec ts;
-       u32 old_tx_blk_count = wl->tx_blocks_available;
-       int avail, freed_blocks;
-       int i;
-
-       wl1271_raw_read(wl, FW_STATUS_ADDR, status, sizeof(*status), false);
-
-       wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
-                    "drv_rx_counter = %d, tx_results_counter = %d)",
-                    status->intr,
-                    status->fw_rx_counter,
-                    status->drv_rx_counter,
-                    status->tx_results_counter);
-
-       for (i = 0; i < NUM_TX_QUEUES; i++) {
-               /* prevent wrap-around in freed-packets counter */
-               wl->tx_allocated_pkts[i] -=
-                               (status->tx_released_pkts[i] -
-                               wl->tx_pkts_freed[i]) & 0xff;
-
-               wl->tx_pkts_freed[i] = status->tx_released_pkts[i];
-       }
-
-       /* prevent wrap-around in total blocks counter */
-       if (likely(wl->tx_blocks_freed <=
-                  le32_to_cpu(status->total_released_blks)))
-               freed_blocks = le32_to_cpu(status->total_released_blks) -
-                              wl->tx_blocks_freed;
-       else
-               freed_blocks = 0x100000000LL - wl->tx_blocks_freed +
-                              le32_to_cpu(status->total_released_blks);
-
-       wl->tx_blocks_freed = le32_to_cpu(status->total_released_blks);
-
-       wl->tx_allocated_blocks -= freed_blocks;
-
-       /*
-        * If the FW freed some blocks:
-        * If we still have allocated blocks - re-arm the timer, Tx is
-        * not stuck. Otherwise, cancel the timer (no Tx currently).
-        */
-       if (freed_blocks) {
-               if (wl->tx_allocated_blocks)
-                       wl12xx_rearm_tx_watchdog_locked(wl);
-               else
-                       cancel_delayed_work(&wl->tx_watchdog_work);
-       }
-
-       avail = le32_to_cpu(status->tx_total) - wl->tx_allocated_blocks;
-
-       /*
-        * The FW might change the total number of TX memblocks before
-        * we get a notification about blocks being released. Thus, the
-        * available blocks calculation might yield a temporary result
-        * which is lower than the actual available blocks. Keeping in
-        * mind that only blocks that were allocated can be moved from
-        * TX to RX, tx_blocks_available should never decrease here.
-        */
-       wl->tx_blocks_available = max((int)wl->tx_blocks_available,
-                                     avail);
-
-       /* if more blocks are available now, tx work can be scheduled */
-       if (wl->tx_blocks_available > old_tx_blk_count)
-               clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
-
-       /* for AP update num of allocated TX blocks per link and ps status */
-       wl12xx_for_each_wlvif_ap(wl, wlvif) {
-               wl12xx_irq_update_links_status(wl, wlvif, status);
-       }
-
-       /* update the host-chipset time offset */
-       getnstimeofday(&ts);
-       wl->time_offset = (timespec_to_ns(&ts) >> 10) -
-               (s64)le32_to_cpu(status->fw_localtime);
-}
-
-static void wl1271_flush_deferred_work(struct wl1271 *wl)
-{
-       struct sk_buff *skb;
-
-       /* Pass all received frames to the network stack */
-       while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
-               ieee80211_rx_ni(wl->hw, skb);
-
-       /* Return sent skbs to the network stack */
-       while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
-               ieee80211_tx_status_ni(wl->hw, skb);
-}
-
-static void wl1271_netstack_work(struct work_struct *work)
-{
-       struct wl1271 *wl =
-               container_of(work, struct wl1271, netstack_work);
-
-       do {
-               wl1271_flush_deferred_work(wl);
-       } while (skb_queue_len(&wl->deferred_rx_queue));
-}
-
-#define WL1271_IRQ_MAX_LOOPS 256
-
-static irqreturn_t wl1271_irq(int irq, void *cookie)
-{
-       int ret;
-       u32 intr;
-       int loopcount = WL1271_IRQ_MAX_LOOPS;
-       struct wl1271 *wl = (struct wl1271 *)cookie;
-       bool done = false;
-       unsigned int defer_count;
-       unsigned long flags;
-
-       /* TX might be handled here, avoid redundant work */
-       set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
-       cancel_work_sync(&wl->tx_work);
-
-       /*
-        * In case edge triggered interrupt must be used, we cannot iterate
-        * more than once without introducing race conditions with the hardirq.
-        */
-       if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
-               loopcount = 1;
-
-       mutex_lock(&wl->mutex);
-
-       wl1271_debug(DEBUG_IRQ, "IRQ work");
-
-       if (unlikely(wl->state == WL1271_STATE_OFF))
-               goto out;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       while (!done && loopcount--) {
-               /*
-                * In order to avoid a race with the hardirq, clear the flag
-                * before acknowledging the chip. Since the mutex is held,
-                * wl1271_ps_elp_wakeup cannot be called concurrently.
-                */
-               clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
-               smp_mb__after_clear_bit();
-
-               wl12xx_fw_status(wl, wl->fw_status);
-               intr = le32_to_cpu(wl->fw_status->intr);
-               intr &= WL1271_INTR_MASK;
-               if (!intr) {
-                       done = true;
-                       continue;
-               }
-
-               if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
-                       wl1271_error("watchdog interrupt received! "
-                                    "starting recovery.");
-                       wl12xx_queue_recovery_work(wl);
-
-                       /* restarting the chip. ignore any other interrupt. */
-                       goto out;
-               }
-
-               if (likely(intr & WL1271_ACX_INTR_DATA)) {
-                       wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
-
-                       wl12xx_rx(wl, wl->fw_status);
-
-                       /* Check if any tx blocks were freed */
-                       spin_lock_irqsave(&wl->wl_lock, flags);
-                       if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
-                           wl1271_tx_total_queue_count(wl) > 0) {
-                               spin_unlock_irqrestore(&wl->wl_lock, flags);
-                               /*
-                                * In order to avoid starvation of the TX path,
-                                * call the work function directly.
-                                */
-                               wl1271_tx_work_locked(wl);
-                       } else {
-                               spin_unlock_irqrestore(&wl->wl_lock, flags);
-                       }
-
-                       /* check for tx results */
-                       if (wl->fw_status->tx_results_counter !=
-                           (wl->tx_results_count & 0xff))
-                               wl1271_tx_complete(wl);
-
-                       /* Make sure the deferred queues don't get too long */
-                       defer_count = skb_queue_len(&wl->deferred_tx_queue) +
-                                     skb_queue_len(&wl->deferred_rx_queue);
-                       if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
-                               wl1271_flush_deferred_work(wl);
-               }
-
-               if (intr & WL1271_ACX_INTR_EVENT_A) {
-                       wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
-                       wl1271_event_handle(wl, 0);
-               }
-
-               if (intr & WL1271_ACX_INTR_EVENT_B) {
-                       wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
-                       wl1271_event_handle(wl, 1);
-               }
-
-               if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
-                       wl1271_debug(DEBUG_IRQ,
-                                    "WL1271_ACX_INTR_INIT_COMPLETE");
-
-               if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
-                       wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
-       }
-
-       wl1271_ps_elp_sleep(wl);
-
-out:
-       spin_lock_irqsave(&wl->wl_lock, flags);
-       /* In case TX was not handled here, queue TX work */
-       clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
-       if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
-           wl1271_tx_total_queue_count(wl) > 0)
-               ieee80211_queue_work(wl->hw, &wl->tx_work);
-       spin_unlock_irqrestore(&wl->wl_lock, flags);
-
-       mutex_unlock(&wl->mutex);
-
-       return IRQ_HANDLED;
-}
-
-struct vif_counter_data {
-       u8 counter;
-
-       struct ieee80211_vif *cur_vif;
-       bool cur_vif_running;
-};
-
-static void wl12xx_vif_count_iter(void *data, u8 *mac,
-                                 struct ieee80211_vif *vif)
-{
-       struct vif_counter_data *counter = data;
-
-       counter->counter++;
-       if (counter->cur_vif == vif)
-               counter->cur_vif_running = true;
-}
-
-/* caller must not hold wl->mutex, as it might deadlock */
-static void wl12xx_get_vif_count(struct ieee80211_hw *hw,
-                              struct ieee80211_vif *cur_vif,
-                              struct vif_counter_data *data)
-{
-       memset(data, 0, sizeof(*data));
-       data->cur_vif = cur_vif;
-
-       ieee80211_iterate_active_interfaces(hw,
-                                           wl12xx_vif_count_iter, data);
-}
-
-static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt)
-{
-       const struct firmware *fw;
-       const char *fw_name;
-       enum wl12xx_fw_type fw_type;
-       int ret;
-
-       if (plt) {
-               fw_type = WL12XX_FW_TYPE_PLT;
-               if (wl->chip.id == CHIP_ID_1283_PG20)
-                       fw_name = WL128X_PLT_FW_NAME;
-               else
-                       fw_name = WL127X_PLT_FW_NAME;
-       } else {
-               /*
-                * we can't call wl12xx_get_vif_count() here because
-                * wl->mutex is taken, so use the cached last_vif_count value
-                */
-               if (wl->last_vif_count > 1) {
-                       fw_type = WL12XX_FW_TYPE_MULTI;
-                       if (wl->chip.id == CHIP_ID_1283_PG20)
-                               fw_name = WL128X_FW_NAME_MULTI;
-                       else
-                               fw_name = WL127X_FW_NAME_MULTI;
-               } else {
-                       fw_type = WL12XX_FW_TYPE_NORMAL;
-                       if (wl->chip.id == CHIP_ID_1283_PG20)
-                               fw_name = WL128X_FW_NAME_SINGLE;
-                       else
-                               fw_name = WL127X_FW_NAME_SINGLE;
-               }
-       }
-
-       if (wl->fw_type == fw_type)
-               return 0;
-
-       wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
-
-       ret = request_firmware(&fw, fw_name, wl->dev);
-
-       if (ret < 0) {
-               wl1271_error("could not get firmware %s: %d", fw_name, ret);
-               return ret;
-       }
-
-       if (fw->size % 4) {
-               wl1271_error("firmware size is not multiple of 32 bits: %zu",
-                            fw->size);
-               ret = -EILSEQ;
-               goto out;
-       }
-
-       vfree(wl->fw);
-       wl->fw_type = WL12XX_FW_TYPE_NONE;
-       wl->fw_len = fw->size;
-       wl->fw = vmalloc(wl->fw_len);
-
-       if (!wl->fw) {
-               wl1271_error("could not allocate memory for the firmware");
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       memcpy(wl->fw, fw->data, wl->fw_len);
-       ret = 0;
-       wl->fw_type = fw_type;
-out:
-       release_firmware(fw);
-
-       return ret;
-}
-
-static int wl1271_fetch_nvs(struct wl1271 *wl)
-{
-       const struct firmware *fw;
-       int ret;
-
-       ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev);
-
-       if (ret < 0) {
-               wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME,
-                            ret);
-               return ret;
-       }
-
-       wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
-
-       if (!wl->nvs) {
-               wl1271_error("could not allocate memory for the nvs file");
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       wl->nvs_len = fw->size;
-
-out:
-       release_firmware(fw);
-
-       return ret;
-}
-
-void wl12xx_queue_recovery_work(struct wl1271 *wl)
-{
-       if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags))
-               ieee80211_queue_work(wl->hw, &wl->recovery_work);
-}
-
-size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen)
-{
-       size_t len = 0;
-
-       /* The FW log is a length-value list, find where the log end */
-       while (len < maxlen) {
-               if (memblock[len] == 0)
-                       break;
-               if (len + memblock[len] + 1 > maxlen)
-                       break;
-               len += memblock[len] + 1;
-       }
-
-       /* Make sure we have enough room */
-       len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size));
-
-       /* Fill the FW log file, consumed by the sysfs fwlog entry */
-       memcpy(wl->fwlog + wl->fwlog_size, memblock, len);
-       wl->fwlog_size += len;
-
-       return len;
-}
-
-static void wl12xx_read_fwlog_panic(struct wl1271 *wl)
-{
-       u32 addr;
-       u32 first_addr;
-       u8 *block;
-
-       if ((wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED) ||
-           (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) ||
-           (wl->conf.fwlog.mem_blocks == 0))
-               return;
-
-       wl1271_info("Reading FW panic log");
-
-       block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL);
-       if (!block)
-               return;
-
-       /*
-        * Make sure the chip is awake and the logger isn't active.
-        * This might fail if the firmware hanged.
-        */
-       if (!wl1271_ps_elp_wakeup(wl))
-               wl12xx_cmd_stop_fwlog(wl);
-
-       /* Read the first memory block address */
-       wl12xx_fw_status(wl, wl->fw_status);
-       first_addr = le32_to_cpu(wl->fw_status->log_start_addr);
-       if (!first_addr)
-               goto out;
-
-       /* Traverse the memory blocks linked list */
-       addr = first_addr;
-       do {
-               memset(block, 0, WL12XX_HW_BLOCK_SIZE);
-               wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE,
-                                  false);
-
-               /*
-                * Memory blocks are linked to one another. The first 4 bytes
-                * of each memory block hold the hardware address of the next
-                * one. The last memory block points to the first one.
-                */
-               addr = le32_to_cpup((__le32 *)block);
-               if (!wl12xx_copy_fwlog(wl, block + sizeof(addr),
-                                      WL12XX_HW_BLOCK_SIZE - sizeof(addr)))
-                       break;
-       } while (addr && (addr != first_addr));
-
-       wake_up_interruptible(&wl->fwlog_waitq);
-
-out:
-       kfree(block);
-}
-
-static void wl1271_recovery_work(struct work_struct *work)
-{
-       struct wl1271 *wl =
-               container_of(work, struct wl1271, recovery_work);
-       struct wl12xx_vif *wlvif;
-       struct ieee80211_vif *vif;
-
-       mutex_lock(&wl->mutex);
-
-       if (wl->state != WL1271_STATE_ON || wl->plt)
-               goto out_unlock;
-
-       /* Avoid a recursive recovery */
-       set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
-
-       wl12xx_read_fwlog_panic(wl);
-
-       wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
-                   wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4));
-
-       BUG_ON(bug_on_recovery &&
-              !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags));
-
-       /*
-        * Advance security sequence number to overcome potential progress
-        * in the firmware during recovery. This doens't hurt if the network is
-        * not encrypted.
-        */
-       wl12xx_for_each_wlvif(wl, wlvif) {
-               if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
-                   test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
-                       wlvif->tx_security_seq +=
-                               WL1271_TX_SQN_POST_RECOVERY_PADDING;
-       }
-
-       /* Prevent spurious TX during FW restart */
-       ieee80211_stop_queues(wl->hw);
-
-       if (wl->sched_scanning) {
-               ieee80211_sched_scan_stopped(wl->hw);
-               wl->sched_scanning = false;
-       }
-
-       /* reboot the chipset */
-       while (!list_empty(&wl->wlvif_list)) {
-               wlvif = list_first_entry(&wl->wlvif_list,
-                                      struct wl12xx_vif, list);
-               vif = wl12xx_wlvif_to_vif(wlvif);
-               __wl1271_op_remove_interface(wl, vif, false);
-       }
-       mutex_unlock(&wl->mutex);
-       wl1271_op_stop(wl->hw);
-
-       clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
-
-       ieee80211_restart_hw(wl->hw);
-
-       /*
-        * Its safe to enable TX now - the queues are stopped after a request
-        * to restart the HW.
-        */
-       ieee80211_wake_queues(wl->hw);
-       return;
-out_unlock:
-       mutex_unlock(&wl->mutex);
-}
-
-static void wl1271_fw_wakeup(struct wl1271 *wl)
-{
-       u32 elp_reg;
-
-       elp_reg = ELPCTRL_WAKE_UP;
-       wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
-}
-
-static int wl1271_setup(struct wl1271 *wl)
-{
-       wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
-       if (!wl->fw_status)
-               return -ENOMEM;
-
-       wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
-       if (!wl->tx_res_if) {
-               kfree(wl->fw_status);
-               return -ENOMEM;
-       }
-
-       return 0;
-}
-
-static int wl12xx_set_power_on(struct wl1271 *wl)
-{
-       int ret;
-
-       msleep(WL1271_PRE_POWER_ON_SLEEP);
-       ret = wl1271_power_on(wl);
-       if (ret < 0)
-               goto out;
-       msleep(WL1271_POWER_ON_SLEEP);
-       wl1271_io_reset(wl);
-       wl1271_io_init(wl);
-
-       wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
-
-       /* ELP module wake up */
-       wl1271_fw_wakeup(wl);
-
-out:
-       return ret;
-}
-
-static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt)
-{
-       int ret = 0;
-
-       ret = wl12xx_set_power_on(wl);
-       if (ret < 0)
-               goto out;
-
-       /*
-        * For wl127x based devices we could use the default block
-        * size (512 bytes), but due to a bug in the sdio driver, we
-        * need to set it explicitly after the chip is powered on.  To
-        * simplify the code and since the performance impact is
-        * negligible, we use the same block size for all different
-        * chip types.
-        */
-       if (!wl1271_set_block_size(wl))
-               wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
-
-       switch (wl->chip.id) {
-       case CHIP_ID_1271_PG10:
-               wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
-                              wl->chip.id);
-
-               ret = wl1271_setup(wl);
-               if (ret < 0)
-                       goto out;
-               wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
-               break;
-
-       case CHIP_ID_1271_PG20:
-               wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
-                            wl->chip.id);
-
-               ret = wl1271_setup(wl);
-               if (ret < 0)
-                       goto out;
-               wl->quirks |= WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
-               break;
-
-       case CHIP_ID_1283_PG20:
-               wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
-                            wl->chip.id);
-
-               ret = wl1271_setup(wl);
-               if (ret < 0)
-                       goto out;
-               break;
-       case CHIP_ID_1283_PG10:
-       default:
-               wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
-               ret = -ENODEV;
-               goto out;
-       }
-
-       ret = wl12xx_fetch_firmware(wl, plt);
-       if (ret < 0)
-               goto out;
-
-       /* No NVS from netlink, try to get it from the filesystem */
-       if (wl->nvs == NULL) {
-               ret = wl1271_fetch_nvs(wl);
-               if (ret < 0)
-                       goto out;
-       }
-
-out:
-       return ret;
-}
-
-int wl1271_plt_start(struct wl1271 *wl)
-{
-       int retries = WL1271_BOOT_RETRIES;
-       struct wiphy *wiphy = wl->hw->wiphy;
-       int ret;
-
-       mutex_lock(&wl->mutex);
-
-       wl1271_notice("power up");
-
-       if (wl->state != WL1271_STATE_OFF) {
-               wl1271_error("cannot go into PLT state because not "
-                            "in off state: %d", wl->state);
-               ret = -EBUSY;
-               goto out;
-       }
-
-       while (retries) {
-               retries--;
-               ret = wl12xx_chip_wakeup(wl, true);
-               if (ret < 0)
-                       goto power_off;
-
-               ret = wl1271_boot(wl);
-               if (ret < 0)
-                       goto power_off;
-
-               ret = wl1271_plt_init(wl);
-               if (ret < 0)
-                       goto irq_disable;
-
-               wl->plt = true;
-               wl->state = WL1271_STATE_ON;
-               wl1271_notice("firmware booted in PLT mode (%s)",
-                             wl->chip.fw_ver_str);
-
-               /* update hw/fw version info in wiphy struct */
-               wiphy->hw_version = wl->chip.id;
-               strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
-                       sizeof(wiphy->fw_version));
-
-               goto out;
-
-irq_disable:
-               mutex_unlock(&wl->mutex);
-               /* Unlocking the mutex in the middle of handling is
-                  inherently unsafe. In this case we deem it safe to do,
-                  because we need to let any possibly pending IRQ out of
-                  the system (and while we are WL1271_STATE_OFF the IRQ
-                  work function will not do anything.) Also, any other
-                  possible concurrent operations will fail due to the
-                  current state, hence the wl1271 struct should be safe. */
-               wl1271_disable_interrupts(wl);
-               wl1271_flush_deferred_work(wl);
-               cancel_work_sync(&wl->netstack_work);
-               mutex_lock(&wl->mutex);
-power_off:
-               wl1271_power_off(wl);
-       }
-
-       wl1271_error("firmware boot in PLT mode failed despite %d retries",
-                    WL1271_BOOT_RETRIES);
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-int wl1271_plt_stop(struct wl1271 *wl)
-{
-       int ret = 0;
-
-       wl1271_notice("power down");
-
-       /*
-        * Interrupts must be disabled before setting the state to OFF.
-        * Otherwise, the interrupt handler might be called and exit without
-        * reading the interrupt status.
-        */
-       wl1271_disable_interrupts(wl);
-       mutex_lock(&wl->mutex);
-       if (!wl->plt) {
-               mutex_unlock(&wl->mutex);
-
-               /*
-                * This will not necessarily enable interrupts as interrupts
-                * may have been disabled when op_stop was called. It will,
-                * however, balance the above call to disable_interrupts().
-                */
-               wl1271_enable_interrupts(wl);
-
-               wl1271_error("cannot power down because not in PLT "
-                            "state: %d", wl->state);
-               ret = -EBUSY;
-               goto out;
-       }
-
-       mutex_unlock(&wl->mutex);
-
-       wl1271_flush_deferred_work(wl);
-       cancel_work_sync(&wl->netstack_work);
-       cancel_work_sync(&wl->recovery_work);
-       cancel_delayed_work_sync(&wl->elp_work);
-       cancel_delayed_work_sync(&wl->tx_watchdog_work);
-
-       mutex_lock(&wl->mutex);
-       wl1271_power_off(wl);
-       wl->flags = 0;
-       wl->state = WL1271_STATE_OFF;
-       wl->plt = false;
-       wl->rx_counter = 0;
-       mutex_unlock(&wl->mutex);
-
-out:
-       return ret;
-}
-
-static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
-{
-       struct wl1271 *wl = hw->priv;
-       struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-       struct ieee80211_vif *vif = info->control.vif;
-       struct wl12xx_vif *wlvif = NULL;
-       unsigned long flags;
-       int q, mapping;
-       u8 hlid;
-
-       if (vif)
-               wlvif = wl12xx_vif_to_data(vif);
-
-       mapping = skb_get_queue_mapping(skb);
-       q = wl1271_tx_get_queue(mapping);
-
-       hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
-
-       spin_lock_irqsave(&wl->wl_lock, flags);
-
-       /* queue the packet */
-       if (hlid == WL12XX_INVALID_LINK_ID ||
-           (wlvif && !test_bit(hlid, wlvif->links_map))) {
-               wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q);
-               ieee80211_free_txskb(hw, skb);
-               goto out;
-       }
-
-       wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d len %d",
-                    hlid, q, skb->len);
-       skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
-
-       wl->tx_queue_count[q]++;
-
-       /*
-        * The workqueue is slow to process the tx_queue and we need stop
-        * the queue here, otherwise the queue will get too long.
-        */
-       if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
-               wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q);
-               ieee80211_stop_queue(wl->hw, mapping);
-               set_bit(q, &wl->stopped_queues_map);
-       }
-
-       /*
-        * The chip specific setup must run before the first TX packet -
-        * before that, the tx_work will not be initialized!
-        */
-
-       if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
-           !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
-               ieee80211_queue_work(wl->hw, &wl->tx_work);
-
-out:
-       spin_unlock_irqrestore(&wl->wl_lock, flags);
-}
-
-int wl1271_tx_dummy_packet(struct wl1271 *wl)
-{
-       unsigned long flags;
-       int q;
-
-       /* no need to queue a new dummy packet if one is already pending */
-       if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags))
-               return 0;
-
-       q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet));
-
-       spin_lock_irqsave(&wl->wl_lock, flags);
-       set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
-       wl->tx_queue_count[q]++;
-       spin_unlock_irqrestore(&wl->wl_lock, flags);
-
-       /* The FW is low on RX memory blocks, so send the dummy packet asap */
-       if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
-               wl1271_tx_work_locked(wl);
-
-       /*
-        * If the FW TX is busy, TX work will be scheduled by the threaded
-        * interrupt handler function
-        */
-       return 0;
-}
-
-/*
- * The size of the dummy packet should be at least 1400 bytes. However, in
- * order to minimize the number of bus transactions, aligning it to 512 bytes
- * boundaries could be beneficial, performance wise
- */
-#define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
-
-static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
-{
-       struct sk_buff *skb;
-       struct ieee80211_hdr_3addr *hdr;
-       unsigned int dummy_packet_size;
-
-       dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
-                           sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
-
-       skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
-       if (!skb) {
-               wl1271_warning("Failed to allocate a dummy packet skb");
-               return NULL;
-       }
-
-       skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
-
-       hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
-       memset(hdr, 0, sizeof(*hdr));
-       hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
-                                        IEEE80211_STYPE_NULLFUNC |
-                                        IEEE80211_FCTL_TODS);
-
-       memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
-
-       /* Dummy packets require the TID to be management */
-       skb->priority = WL1271_TID_MGMT;
-
-       /* Initialize all fields that might be used */
-       skb_set_queue_mapping(skb, 0);
-       memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
-
-       return skb;
-}
-
-
-#ifdef CONFIG_PM
-static int wl1271_configure_suspend_sta(struct wl1271 *wl,
-                                       struct wl12xx_vif *wlvif)
-{
-       int ret = 0;
-
-       mutex_lock(&wl->mutex);
-
-       if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
-               goto out_unlock;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out_unlock;
-
-       ret = wl1271_acx_wake_up_conditions(wl, wlvif,
-                                   wl->conf.conn.suspend_wake_up_event,
-                                   wl->conf.conn.suspend_listen_interval);
-
-       if (ret < 0)
-               wl1271_error("suspend: set wake up conditions failed: %d", ret);
-
-
-       wl1271_ps_elp_sleep(wl);
-
-out_unlock:
-       mutex_unlock(&wl->mutex);
-       return ret;
-
-}
-
-static int wl1271_configure_suspend_ap(struct wl1271 *wl,
-                                      struct wl12xx_vif *wlvif)
-{
-       int ret = 0;
-
-       mutex_lock(&wl->mutex);
-
-       if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
-               goto out_unlock;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out_unlock;
-
-       ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
-
-       wl1271_ps_elp_sleep(wl);
-out_unlock:
-       mutex_unlock(&wl->mutex);
-       return ret;
-
-}
-
-static int wl1271_configure_suspend(struct wl1271 *wl,
-                                   struct wl12xx_vif *wlvif)
-{
-       if (wlvif->bss_type == BSS_TYPE_STA_BSS)
-               return wl1271_configure_suspend_sta(wl, wlvif);
-       if (wlvif->bss_type == BSS_TYPE_AP_BSS)
-               return wl1271_configure_suspend_ap(wl, wlvif);
-       return 0;
-}
-
-static void wl1271_configure_resume(struct wl1271 *wl,
-                                   struct wl12xx_vif *wlvif)
-{
-       int ret = 0;
-       bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
-       bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
-
-       if ((!is_ap) && (!is_sta))
-               return;
-
-       mutex_lock(&wl->mutex);
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       if (is_sta) {
-               ret = wl1271_acx_wake_up_conditions(wl, wlvif,
-                                   wl->conf.conn.wake_up_event,
-                                   wl->conf.conn.listen_interval);
-
-               if (ret < 0)
-                       wl1271_error("resume: wake up conditions failed: %d",
-                                    ret);
-
-       } else if (is_ap) {
-               ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
-       }
-
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-static int wl1271_op_suspend(struct ieee80211_hw *hw,
-                           struct cfg80211_wowlan *wow)
-{
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif;
-       int ret;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
-       WARN_ON(!wow || !wow->any);
-
-       wl1271_tx_flush(wl);
-
-       wl->wow_enabled = true;
-       wl12xx_for_each_wlvif(wl, wlvif) {
-               ret = wl1271_configure_suspend(wl, wlvif);
-               if (ret < 0) {
-                       wl1271_warning("couldn't prepare device to suspend");
-                       return ret;
-               }
-       }
-       /* flush any remaining work */
-       wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
-
-       /*
-        * disable and re-enable interrupts in order to flush
-        * the threaded_irq
-        */
-       wl1271_disable_interrupts(wl);
-
-       /*
-        * set suspended flag to avoid triggering a new threaded_irq
-        * work. no need for spinlock as interrupts are disabled.
-        */
-       set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
-
-       wl1271_enable_interrupts(wl);
-       flush_work(&wl->tx_work);
-       flush_delayed_work(&wl->elp_work);
-
-       return 0;
-}
-
-static int wl1271_op_resume(struct ieee80211_hw *hw)
-{
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif;
-       unsigned long flags;
-       bool run_irq_work = false;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
-                    wl->wow_enabled);
-       WARN_ON(!wl->wow_enabled);
-
-       /*
-        * re-enable irq_work enqueuing, and call irq_work directly if
-        * there is a pending work.
-        */
-       spin_lock_irqsave(&wl->wl_lock, flags);
-       clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
-       if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
-               run_irq_work = true;
-       spin_unlock_irqrestore(&wl->wl_lock, flags);
-
-       if (run_irq_work) {
-               wl1271_debug(DEBUG_MAC80211,
-                            "run postponed irq_work directly");
-               wl1271_irq(0, wl);
-               wl1271_enable_interrupts(wl);
-       }
-       wl12xx_for_each_wlvif(wl, wlvif) {
-               wl1271_configure_resume(wl, wlvif);
-       }
-       wl->wow_enabled = false;
-
-       return 0;
-}
-#endif
-
-static int wl1271_op_start(struct ieee80211_hw *hw)
-{
-       wl1271_debug(DEBUG_MAC80211, "mac80211 start");
-
-       /*
-        * We have to delay the booting of the hardware because
-        * we need to know the local MAC address before downloading and
-        * initializing the firmware. The MAC address cannot be changed
-        * after boot, and without the proper MAC address, the firmware
-        * will not function properly.
-        *
-        * The MAC address is first known when the corresponding interface
-        * is added. That is where we will initialize the hardware.
-        */
-
-       return 0;
-}
-
-static void wl1271_op_stop(struct ieee80211_hw *hw)
-{
-       struct wl1271 *wl = hw->priv;
-       int i;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
-
-       /*
-        * Interrupts must be disabled before setting the state to OFF.
-        * Otherwise, the interrupt handler might be called and exit without
-        * reading the interrupt status.
-        */
-       wl1271_disable_interrupts(wl);
-       mutex_lock(&wl->mutex);
-       if (wl->state == WL1271_STATE_OFF) {
-               mutex_unlock(&wl->mutex);
-
-               /*
-                * This will not necessarily enable interrupts as interrupts
-                * may have been disabled when op_stop was called. It will,
-                * however, balance the above call to disable_interrupts().
-                */
-               wl1271_enable_interrupts(wl);
-               return;
-       }
-
-       /*
-        * this must be before the cancel_work calls below, so that the work
-        * functions don't perform further work.
-        */
-       wl->state = WL1271_STATE_OFF;
-       mutex_unlock(&wl->mutex);
-
-       wl1271_flush_deferred_work(wl);
-       cancel_delayed_work_sync(&wl->scan_complete_work);
-       cancel_work_sync(&wl->netstack_work);
-       cancel_work_sync(&wl->tx_work);
-       cancel_delayed_work_sync(&wl->elp_work);
-       cancel_delayed_work_sync(&wl->tx_watchdog_work);
-
-       /* let's notify MAC80211 about the remaining pending TX frames */
-       wl12xx_tx_reset(wl, true);
-       mutex_lock(&wl->mutex);
-
-       wl1271_power_off(wl);
-
-       wl->band = IEEE80211_BAND_2GHZ;
-
-       wl->rx_counter = 0;
-       wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
-       wl->tx_blocks_available = 0;
-       wl->tx_allocated_blocks = 0;
-       wl->tx_results_count = 0;
-       wl->tx_packets_count = 0;
-       wl->time_offset = 0;
-       wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
-       wl->ap_fw_ps_map = 0;
-       wl->ap_ps_map = 0;
-       wl->sched_scanning = false;
-       memset(wl->roles_map, 0, sizeof(wl->roles_map));
-       memset(wl->links_map, 0, sizeof(wl->links_map));
-       memset(wl->roc_map, 0, sizeof(wl->roc_map));
-       wl->active_sta_count = 0;
-
-       /* The system link is always allocated */
-       __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
-
-       /*
-        * this is performed after the cancel_work calls and the associated
-        * mutex_lock, so that wl1271_op_add_interface does not accidentally
-        * get executed before all these vars have been reset.
-        */
-       wl->flags = 0;
-
-       wl->tx_blocks_freed = 0;
-
-       for (i = 0; i < NUM_TX_QUEUES; i++) {
-               wl->tx_pkts_freed[i] = 0;
-               wl->tx_allocated_pkts[i] = 0;
-       }
-
-       wl1271_debugfs_reset(wl);
-
-       kfree(wl->fw_status);
-       wl->fw_status = NULL;
-       kfree(wl->tx_res_if);
-       wl->tx_res_if = NULL;
-       kfree(wl->target_mem_map);
-       wl->target_mem_map = NULL;
-
-       mutex_unlock(&wl->mutex);
-}
-
-static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx)
-{
-       u8 policy = find_first_zero_bit(wl->rate_policies_map,
-                                       WL12XX_MAX_RATE_POLICIES);
-       if (policy >= WL12XX_MAX_RATE_POLICIES)
-               return -EBUSY;
-
-       __set_bit(policy, wl->rate_policies_map);
-       *idx = policy;
-       return 0;
-}
-
-static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx)
-{
-       if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES))
-               return;
-
-       __clear_bit(*idx, wl->rate_policies_map);
-       *idx = WL12XX_MAX_RATE_POLICIES;
-}
-
-static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       switch (wlvif->bss_type) {
-       case BSS_TYPE_AP_BSS:
-               if (wlvif->p2p)
-                       return WL1271_ROLE_P2P_GO;
-               else
-                       return WL1271_ROLE_AP;
-
-       case BSS_TYPE_STA_BSS:
-               if (wlvif->p2p)
-                       return WL1271_ROLE_P2P_CL;
-               else
-                       return WL1271_ROLE_STA;
-
-       case BSS_TYPE_IBSS:
-               return WL1271_ROLE_IBSS;
-
-       default:
-               wl1271_error("invalid bss_type: %d", wlvif->bss_type);
-       }
-       return WL12XX_INVALID_ROLE_TYPE;
-}
-
-static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       int i;
-
-       /* clear everything but the persistent data */
-       memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent));
-
-       switch (ieee80211_vif_type_p2p(vif)) {
-       case NL80211_IFTYPE_P2P_CLIENT:
-               wlvif->p2p = 1;
-               /* fall-through */
-       case NL80211_IFTYPE_STATION:
-               wlvif->bss_type = BSS_TYPE_STA_BSS;
-               break;
-       case NL80211_IFTYPE_ADHOC:
-               wlvif->bss_type = BSS_TYPE_IBSS;
-               break;
-       case NL80211_IFTYPE_P2P_GO:
-               wlvif->p2p = 1;
-               /* fall-through */
-       case NL80211_IFTYPE_AP:
-               wlvif->bss_type = BSS_TYPE_AP_BSS;
-               break;
-       default:
-               wlvif->bss_type = MAX_BSS_TYPE;
-               return -EOPNOTSUPP;
-       }
-
-       wlvif->role_id = WL12XX_INVALID_ROLE_ID;
-       wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
-       wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
-
-       if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
-           wlvif->bss_type == BSS_TYPE_IBSS) {
-               /* init sta/ibss data */
-               wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
-               wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx);
-               wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx);
-               wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
-       } else {
-               /* init ap data */
-               wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
-               wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
-               wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
-               wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
-               for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
-                       wl12xx_allocate_rate_policy(wl,
-                                               &wlvif->ap.ucast_rate_idx[i]);
-       }
-
-       wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
-       wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
-       wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
-       wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
-       wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
-       wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT;
-
-       /*
-        * mac80211 configures some values globally, while we treat them
-        * per-interface. thus, on init, we have to copy them from wl
-        */
-       wlvif->band = wl->band;
-       wlvif->channel = wl->channel;
-       wlvif->power_level = wl->power_level;
-
-       INIT_WORK(&wlvif->rx_streaming_enable_work,
-                 wl1271_rx_streaming_enable_work);
-       INIT_WORK(&wlvif->rx_streaming_disable_work,
-                 wl1271_rx_streaming_disable_work);
-       INIT_LIST_HEAD(&wlvif->list);
-
-       setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer,
-                   (unsigned long) wlvif);
-       return 0;
-}
-
-static bool wl12xx_init_fw(struct wl1271 *wl)
-{
-       int retries = WL1271_BOOT_RETRIES;
-       bool booted = false;
-       struct wiphy *wiphy = wl->hw->wiphy;
-       int ret;
-
-       while (retries) {
-               retries--;
-               ret = wl12xx_chip_wakeup(wl, false);
-               if (ret < 0)
-                       goto power_off;
-
-               ret = wl1271_boot(wl);
-               if (ret < 0)
-                       goto power_off;
-
-               ret = wl1271_hw_init(wl);
-               if (ret < 0)
-                       goto irq_disable;
-
-               booted = true;
-               break;
-
-irq_disable:
-               mutex_unlock(&wl->mutex);
-               /* Unlocking the mutex in the middle of handling is
-                  inherently unsafe. In this case we deem it safe to do,
-                  because we need to let any possibly pending IRQ out of
-                  the system (and while we are WL1271_STATE_OFF the IRQ
-                  work function will not do anything.) Also, any other
-                  possible concurrent operations will fail due to the
-                  current state, hence the wl1271 struct should be safe. */
-               wl1271_disable_interrupts(wl);
-               wl1271_flush_deferred_work(wl);
-               cancel_work_sync(&wl->netstack_work);
-               mutex_lock(&wl->mutex);
-power_off:
-               wl1271_power_off(wl);
-       }
-
-       if (!booted) {
-               wl1271_error("firmware boot failed despite %d retries",
-                            WL1271_BOOT_RETRIES);
-               goto out;
-       }
-
-       wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
-
-       /* update hw/fw version info in wiphy struct */
-       wiphy->hw_version = wl->chip.id;
-       strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
-               sizeof(wiphy->fw_version));
-
-       /*
-        * Now we know if 11a is supported (info from the NVS), so disable
-        * 11a channels if not supported
-        */
-       if (!wl->enable_11a)
-               wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
-
-       wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
-                    wl->enable_11a ? "" : "not ");
-
-       wl->state = WL1271_STATE_ON;
-out:
-       return booted;
-}
-
-static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif)
-{
-       return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID;
-}
-
-/*
- * Check whether a fw switch (i.e. moving from one loaded
- * fw to another) is needed. This function is also responsible
- * for updating wl->last_vif_count, so it must be called before
- * loading a non-plt fw (so the correct fw (single-role/multi-role)
- * will be used).
- */
-static bool wl12xx_need_fw_change(struct wl1271 *wl,
-                                 struct vif_counter_data vif_counter_data,
-                                 bool add)
-{
-       enum wl12xx_fw_type current_fw = wl->fw_type;
-       u8 vif_count = vif_counter_data.counter;
-
-       if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags))
-               return false;
-
-       /* increase the vif count if this is a new vif */
-       if (add && !vif_counter_data.cur_vif_running)
-               vif_count++;
-
-       wl->last_vif_count = vif_count;
-
-       /* no need for fw change if the device is OFF */
-       if (wl->state == WL1271_STATE_OFF)
-               return false;
-
-       if (vif_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL)
-               return true;
-       if (vif_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI)
-               return true;
-
-       return false;
-}
-
-/*
- * Enter "forced psm". Make sure the sta is in psm against the ap,
- * to make the fw switch a bit more disconnection-persistent.
- */
-static void wl12xx_force_active_psm(struct wl1271 *wl)
-{
-       struct wl12xx_vif *wlvif;
-
-       wl12xx_for_each_wlvif_sta(wl, wlvif) {
-               wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE);
-       }
-}
-
-static int wl1271_op_add_interface(struct ieee80211_hw *hw,
-                                  struct ieee80211_vif *vif)
-{
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       struct vif_counter_data vif_count;
-       int ret = 0;
-       u8 role_type;
-       bool booted = false;
-
-       vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
-                            IEEE80211_VIF_SUPPORTS_CQM_RSSI;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
-                    ieee80211_vif_type_p2p(vif), vif->addr);
-
-       wl12xx_get_vif_count(hw, vif, &vif_count);
-
-       mutex_lock(&wl->mutex);
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out_unlock;
-
-       /*
-        * in some very corner case HW recovery scenarios its possible to
-        * get here before __wl1271_op_remove_interface is complete, so
-        * opt out if that is the case.
-        */
-       if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) ||
-           test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) {
-               ret = -EBUSY;
-               goto out;
-       }
-
-
-       ret = wl12xx_init_vif_data(wl, vif);
-       if (ret < 0)
-               goto out;
-
-       wlvif->wl = wl;
-       role_type = wl12xx_get_role_type(wl, wlvif);
-       if (role_type == WL12XX_INVALID_ROLE_TYPE) {
-               ret = -EINVAL;
-               goto out;
-       }
-
-       if (wl12xx_need_fw_change(wl, vif_count, true)) {
-               wl12xx_force_active_psm(wl);
-               set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags);
-               mutex_unlock(&wl->mutex);
-               wl1271_recovery_work(&wl->recovery_work);
-               return 0;
-       }
-
-       /*
-        * TODO: after the nvs issue will be solved, move this block
-        * to start(), and make sure here the driver is ON.
-        */
-       if (wl->state == WL1271_STATE_OFF) {
-               /*
-                * we still need this in order to configure the fw
-                * while uploading the nvs
-                */
-               memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN);
-
-               booted = wl12xx_init_fw(wl);
-               if (!booted) {
-                       ret = -EINVAL;
-                       goto out;
-               }
-       }
-
-       if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
-           wlvif->bss_type == BSS_TYPE_IBSS) {
-               /*
-                * The device role is a special role used for
-                * rx and tx frames prior to association (as
-                * the STA role can get packets only from
-                * its associated bssid)
-                */
-               ret = wl12xx_cmd_role_enable(wl, vif->addr,
-                                                WL1271_ROLE_DEVICE,
-                                                &wlvif->dev_role_id);
-               if (ret < 0)
-                       goto out;
-       }
-
-       ret = wl12xx_cmd_role_enable(wl, vif->addr,
-                                    role_type, &wlvif->role_id);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1271_init_vif_specific(wl, vif);
-       if (ret < 0)
-               goto out;
-
-       list_add(&wlvif->list, &wl->wlvif_list);
-       set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags);
-
-       if (wlvif->bss_type == BSS_TYPE_AP_BSS)
-               wl->ap_count++;
-       else
-               wl->sta_count++;
-out:
-       wl1271_ps_elp_sleep(wl);
-out_unlock:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-static void __wl1271_op_remove_interface(struct wl1271 *wl,
-                                        struct ieee80211_vif *vif,
-                                        bool reset_tx_queues)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       int i, ret;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
-
-       if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
-               return;
-
-       /* because of hardware recovery, we may get here twice */
-       if (wl->state != WL1271_STATE_ON)
-               return;
-
-       wl1271_info("down");
-
-       if (wl->scan.state != WL1271_SCAN_STATE_IDLE &&
-           wl->scan_vif == vif) {
-               /*
-                * Rearm the tx watchdog just before idling scan. This
-                * prevents just-finished scans from triggering the watchdog
-                */
-               wl12xx_rearm_tx_watchdog_locked(wl);
-
-               wl->scan.state = WL1271_SCAN_STATE_IDLE;
-               memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
-               wl->scan_vif = NULL;
-               wl->scan.req = NULL;
-               ieee80211_scan_completed(wl->hw, true);
-       }
-
-       if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) {
-               /* disable active roles */
-               ret = wl1271_ps_elp_wakeup(wl);
-               if (ret < 0)
-                       goto deinit;
-
-               if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
-                   wlvif->bss_type == BSS_TYPE_IBSS) {
-                       if (wl12xx_dev_role_started(wlvif))
-                               wl12xx_stop_dev(wl, wlvif);
-
-                       ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
-                       if (ret < 0)
-                               goto deinit;
-               }
-
-               ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id);
-               if (ret < 0)
-                       goto deinit;
-
-               wl1271_ps_elp_sleep(wl);
-       }
-deinit:
-       /* clear all hlids (except system_hlid) */
-       wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
-
-       if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
-           wlvif->bss_type == BSS_TYPE_IBSS) {
-               wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
-               wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
-               wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
-               wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
-       } else {
-               wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
-               wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
-               wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
-               wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
-               for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
-                       wl12xx_free_rate_policy(wl,
-                                               &wlvif->ap.ucast_rate_idx[i]);
-       }
-
-       wl12xx_tx_reset_wlvif(wl, wlvif);
-       wl1271_free_ap_keys(wl, wlvif);
-       if (wl->last_wlvif == wlvif)
-               wl->last_wlvif = NULL;
-       list_del(&wlvif->list);
-       memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map));
-       wlvif->role_id = WL12XX_INVALID_ROLE_ID;
-       wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
-
-       if (wlvif->bss_type == BSS_TYPE_AP_BSS)
-               wl->ap_count--;
-       else
-               wl->sta_count--;
-
-       mutex_unlock(&wl->mutex);
-
-       del_timer_sync(&wlvif->rx_streaming_timer);
-       cancel_work_sync(&wlvif->rx_streaming_enable_work);
-       cancel_work_sync(&wlvif->rx_streaming_disable_work);
-
-       mutex_lock(&wl->mutex);
-}
-
-static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
-                                      struct ieee80211_vif *vif)
-{
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       struct wl12xx_vif *iter;
-       struct vif_counter_data vif_count;
-       bool cancel_recovery = true;
-
-       wl12xx_get_vif_count(hw, vif, &vif_count);
-       mutex_lock(&wl->mutex);
-
-       if (wl->state == WL1271_STATE_OFF ||
-           !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
-               goto out;
-
-       /*
-        * wl->vif can be null here if someone shuts down the interface
-        * just when hardware recovery has been started.
-        */
-       wl12xx_for_each_wlvif(wl, iter) {
-               if (iter != wlvif)
-                       continue;
-
-               __wl1271_op_remove_interface(wl, vif, true);
-               break;
-       }
-       WARN_ON(iter != wlvif);
-       if (wl12xx_need_fw_change(wl, vif_count, false)) {
-               wl12xx_force_active_psm(wl);
-               set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags);
-               wl12xx_queue_recovery_work(wl);
-               cancel_recovery = false;
-       }
-out:
-       mutex_unlock(&wl->mutex);
-       if (cancel_recovery)
-               cancel_work_sync(&wl->recovery_work);
-}
-
-static int wl12xx_op_change_interface(struct ieee80211_hw *hw,
-                                     struct ieee80211_vif *vif,
-                                     enum nl80211_iftype new_type, bool p2p)
-{
-       struct wl1271 *wl = hw->priv;
-       int ret;
-
-       set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
-       wl1271_op_remove_interface(hw, vif);
-
-       vif->type = new_type;
-       vif->p2p = p2p;
-       ret = wl1271_op_add_interface(hw, vif);
-
-       clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
-       return ret;
-}
-
-static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                         bool set_assoc)
-{
-       int ret;
-       bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
-
-       /*
-        * One of the side effects of the JOIN command is that is clears
-        * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
-        * to a WPA/WPA2 access point will therefore kill the data-path.
-        * Currently the only valid scenario for JOIN during association
-        * is on roaming, in which case we will also be given new keys.
-        * Keep the below message for now, unless it starts bothering
-        * users who really like to roam a lot :)
-        */
-       if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
-               wl1271_info("JOIN while associated.");
-
-       /* clear encryption type */
-       wlvif->encryption_type = KEY_NONE;
-
-       if (set_assoc)
-               set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags);
-
-       if (is_ibss)
-               ret = wl12xx_cmd_role_start_ibss(wl, wlvif);
-       else
-               ret = wl12xx_cmd_role_start_sta(wl, wlvif);
-       if (ret < 0)
-               goto out;
-
-       if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
-               goto out;
-
-       /*
-        * The join command disable the keep-alive mode, shut down its process,
-        * and also clear the template config, so we need to reset it all after
-        * the join. The acx_aid starts the keep-alive process, and the order
-        * of the commands below is relevant.
-        */
-       ret = wl1271_acx_keep_alive_mode(wl, wlvif, true);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1271_acx_aid(wl, wlvif, wlvif->aid);
-       if (ret < 0)
-               goto out;
-
-       ret = wl12xx_cmd_build_klv_null_data(wl, wlvif);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1271_acx_keep_alive_config(wl, wlvif,
-                                          CMD_TEMPL_KLV_IDX_NULL_DATA,
-                                          ACX_KEEP_ALIVE_TPL_VALID);
-       if (ret < 0)
-               goto out;
-
-out:
-       return ret;
-}
-
-static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       int ret;
-
-       if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) {
-               struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-
-               wl12xx_cmd_stop_channel_switch(wl);
-               ieee80211_chswitch_done(vif, false);
-       }
-
-       /* to stop listening to a channel, we disconnect */
-       ret = wl12xx_cmd_role_stop_sta(wl, wlvif);
-       if (ret < 0)
-               goto out;
-
-       /* reset TX security counters on a clean disconnect */
-       wlvif->tx_security_last_seq_lsb = 0;
-       wlvif->tx_security_seq = 0;
-
-out:
-       return ret;
-}
-
-static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band];
-       wlvif->rate_set = wlvif->basic_rate_set;
-}
-
-static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                                 bool idle)
-{
-       int ret;
-       bool cur_idle = !test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
-
-       if (idle == cur_idle)
-               return 0;
-
-       if (idle) {
-               /* no need to croc if we weren't busy (e.g. during boot) */
-               if (wl12xx_dev_role_started(wlvif)) {
-                       ret = wl12xx_stop_dev(wl, wlvif);
-                       if (ret < 0)
-                               goto out;
-               }
-               wlvif->rate_set =
-                       wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
-               ret = wl1271_acx_sta_rate_policies(wl, wlvif);
-               if (ret < 0)
-                       goto out;
-               ret = wl1271_acx_keep_alive_config(
-                       wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA,
-                       ACX_KEEP_ALIVE_TPL_INVALID);
-               if (ret < 0)
-                       goto out;
-               clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
-       } else {
-               /* The current firmware only supports sched_scan in idle */
-               if (wl->sched_scanning) {
-                       wl1271_scan_sched_scan_stop(wl);
-                       ieee80211_sched_scan_stopped(wl->hw);
-               }
-
-               ret = wl12xx_start_dev(wl, wlvif);
-               if (ret < 0)
-                       goto out;
-               set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
-       }
-
-out:
-       return ret;
-}
-
-static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                            struct ieee80211_conf *conf, u32 changed)
-{
-       bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
-       int channel, ret;
-
-       channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
-
-       /* if the channel changes while joined, join again */
-       if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
-           ((wlvif->band != conf->channel->band) ||
-            (wlvif->channel != channel))) {
-               /* send all pending packets */
-               wl1271_tx_work_locked(wl);
-               wlvif->band = conf->channel->band;
-               wlvif->channel = channel;
-
-               if (!is_ap) {
-                       /*
-                        * FIXME: the mac80211 should really provide a fixed
-                        * rate to use here. for now, just use the smallest
-                        * possible rate for the band as a fixed rate for
-                        * association frames and other control messages.
-                        */
-                       if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
-                               wl1271_set_band_rate(wl, wlvif);
-
-                       wlvif->basic_rate =
-                               wl1271_tx_min_rate_get(wl,
-                                                      wlvif->basic_rate_set);
-                       ret = wl1271_acx_sta_rate_policies(wl, wlvif);
-                       if (ret < 0)
-                               wl1271_warning("rate policy for channel "
-                                              "failed %d", ret);
-
-                       /*
-                        * change the ROC channel. do it only if we are
-                        * not idle. otherwise, CROC will be called
-                        * anyway.
-                        */
-                       if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED,
-                                     &wlvif->flags) &&
-                           wl12xx_dev_role_started(wlvif) &&
-                           !(conf->flags & IEEE80211_CONF_IDLE)) {
-                               ret = wl12xx_stop_dev(wl, wlvif);
-                               if (ret < 0)
-                                       return ret;
-
-                               ret = wl12xx_start_dev(wl, wlvif);
-                               if (ret < 0)
-                                       return ret;
-                       }
-               }
-       }
-
-       if ((changed & IEEE80211_CONF_CHANGE_PS) && !is_ap) {
-
-               if ((conf->flags & IEEE80211_CONF_PS) &&
-                   test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
-                   !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
-
-                       int ps_mode;
-                       char *ps_mode_str;
-
-                       if (wl->conf.conn.forced_ps) {
-                               ps_mode = STATION_POWER_SAVE_MODE;
-                               ps_mode_str = "forced";
-                       } else {
-                               ps_mode = STATION_AUTO_PS_MODE;
-                               ps_mode_str = "auto";
-                       }
-
-                       wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str);
-
-                       ret = wl1271_ps_set_mode(wl, wlvif, ps_mode);
-
-                       if (ret < 0)
-                               wl1271_warning("enter %s ps failed %d",
-                                              ps_mode_str, ret);
-
-               } else if (!(conf->flags & IEEE80211_CONF_PS) &&
-                          test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
-
-                       wl1271_debug(DEBUG_PSM, "auto ps disabled");
-
-                       ret = wl1271_ps_set_mode(wl, wlvif,
-                                                STATION_ACTIVE_MODE);
-                       if (ret < 0)
-                               wl1271_warning("exit auto ps failed %d", ret);
-               }
-       }
-
-       if (conf->power_level != wlvif->power_level) {
-               ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level);
-               if (ret < 0)
-                       return ret;
-
-               wlvif->power_level = conf->power_level;
-       }
-
-       return 0;
-}
-
-static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
-{
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif;
-       struct ieee80211_conf *conf = &hw->conf;
-       int channel, ret = 0;
-
-       channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
-                    " changed 0x%x",
-                    channel,
-                    conf->flags & IEEE80211_CONF_PS ? "on" : "off",
-                    conf->power_level,
-                    conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
-                        changed);
-
-       /*
-        * mac80211 will go to idle nearly immediately after transmitting some
-        * frames, such as the deauth. To make sure those frames reach the air,
-        * wait here until the TX queue is fully flushed.
-        */
-       if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
-           (conf->flags & IEEE80211_CONF_IDLE))
-               wl1271_tx_flush(wl);
-
-       mutex_lock(&wl->mutex);
-
-       /* we support configuring the channel and band even while off */
-       if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
-               wl->band = conf->channel->band;
-               wl->channel = channel;
-       }
-
-       if (changed & IEEE80211_CONF_CHANGE_POWER)
-               wl->power_level = conf->power_level;
-
-       if (unlikely(wl->state == WL1271_STATE_OFF))
-               goto out;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       /* configure each interface */
-       wl12xx_for_each_wlvif(wl, wlvif) {
-               ret = wl12xx_config_vif(wl, wlvif, conf, changed);
-               if (ret < 0)
-                       goto out_sleep;
-       }
-
-out_sleep:
-       wl1271_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-struct wl1271_filter_params {
-       bool enabled;
-       int mc_list_length;
-       u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
-};
-
-static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw,
-                                      struct netdev_hw_addr_list *mc_list)
-{
-       struct wl1271_filter_params *fp;
-       struct netdev_hw_addr *ha;
-       struct wl1271 *wl = hw->priv;
-
-       if (unlikely(wl->state == WL1271_STATE_OFF))
-               return 0;
-
-       fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
-       if (!fp) {
-               wl1271_error("Out of memory setting filters.");
-               return 0;
-       }
-
-       /* update multicast filtering parameters */
-       fp->mc_list_length = 0;
-       if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
-               fp->enabled = false;
-       } else {
-               fp->enabled = true;
-               netdev_hw_addr_list_for_each(ha, mc_list) {
-                       memcpy(fp->mc_list[fp->mc_list_length],
-                                       ha->addr, ETH_ALEN);
-                       fp->mc_list_length++;
-               }
-       }
-
-       return (u64)(unsigned long)fp;
-}
-
-#define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
-                                 FIF_ALLMULTI | \
-                                 FIF_FCSFAIL | \
-                                 FIF_BCN_PRBRESP_PROMISC | \
-                                 FIF_CONTROL | \
-                                 FIF_OTHER_BSS)
-
-static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
-                                      unsigned int changed,
-                                      unsigned int *total, u64 multicast)
-{
-       struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif;
-
-       int ret;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
-                    " total %x", changed, *total);
-
-       mutex_lock(&wl->mutex);
-
-       *total &= WL1271_SUPPORTED_FILTERS;
-       changed &= WL1271_SUPPORTED_FILTERS;
-
-       if (unlikely(wl->state == WL1271_STATE_OFF))
-               goto out;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       wl12xx_for_each_wlvif(wl, wlvif) {
-               if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
-                       if (*total & FIF_ALLMULTI)
-                               ret = wl1271_acx_group_address_tbl(wl, wlvif,
-                                                                  false,
-                                                                  NULL, 0);
-                       else if (fp)
-                               ret = wl1271_acx_group_address_tbl(wl, wlvif,
-                                                       fp->enabled,
-                                                       fp->mc_list,
-                                                       fp->mc_list_length);
-                       if (ret < 0)
-                               goto out_sleep;
-               }
-       }
-
-       /*
-        * the fw doesn't provide an api to configure the filters. instead,
-        * the filters configuration is based on the active roles / ROC
-        * state.
-        */
-
-out_sleep:
-       wl1271_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-       kfree(fp);
-}
-
-static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                               u8 id, u8 key_type, u8 key_size,
-                               const u8 *key, u8 hlid, u32 tx_seq_32,
-                               u16 tx_seq_16)
-{
-       struct wl1271_ap_key *ap_key;
-       int i;
-
-       wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id);
-
-       if (key_size > MAX_KEY_SIZE)
-               return -EINVAL;
-
-       /*
-        * Find next free entry in ap_keys. Also check we are not replacing
-        * an existing key.
-        */
-       for (i = 0; i < MAX_NUM_KEYS; i++) {
-               if (wlvif->ap.recorded_keys[i] == NULL)
-                       break;
-
-               if (wlvif->ap.recorded_keys[i]->id == id) {
-                       wl1271_warning("trying to record key replacement");
-                       return -EINVAL;
-               }
-       }
-
-       if (i == MAX_NUM_KEYS)
-               return -EBUSY;
-
-       ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL);
-       if (!ap_key)
-               return -ENOMEM;
-
-       ap_key->id = id;
-       ap_key->key_type = key_type;
-       ap_key->key_size = key_size;
-       memcpy(ap_key->key, key, key_size);
-       ap_key->hlid = hlid;
-       ap_key->tx_seq_32 = tx_seq_32;
-       ap_key->tx_seq_16 = tx_seq_16;
-
-       wlvif->ap.recorded_keys[i] = ap_key;
-       return 0;
-}
-
-static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       int i;
-
-       for (i = 0; i < MAX_NUM_KEYS; i++) {
-               kfree(wlvif->ap.recorded_keys[i]);
-               wlvif->ap.recorded_keys[i] = NULL;
-       }
-}
-
-static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       int i, ret = 0;
-       struct wl1271_ap_key *key;
-       bool wep_key_added = false;
-
-       for (i = 0; i < MAX_NUM_KEYS; i++) {
-               u8 hlid;
-               if (wlvif->ap.recorded_keys[i] == NULL)
-                       break;
-
-               key = wlvif->ap.recorded_keys[i];
-               hlid = key->hlid;
-               if (hlid == WL12XX_INVALID_LINK_ID)
-                       hlid = wlvif->ap.bcast_hlid;
-
-               ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE,
-                                           key->id, key->key_type,
-                                           key->key_size, key->key,
-                                           hlid, key->tx_seq_32,
-                                           key->tx_seq_16);
-               if (ret < 0)
-                       goto out;
-
-               if (key->key_type == KEY_WEP)
-                       wep_key_added = true;
-       }
-
-       if (wep_key_added) {
-               ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key,
-                                                    wlvif->ap.bcast_hlid);
-               if (ret < 0)
-                       goto out;
-       }
-
-out:
-       wl1271_free_ap_keys(wl, wlvif);
-       return ret;
-}
-
-static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                      u16 action, u8 id, u8 key_type,
-                      u8 key_size, const u8 *key, u32 tx_seq_32,
-                      u16 tx_seq_16, struct ieee80211_sta *sta)
-{
-       int ret;
-       bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
-
-       if (is_ap) {
-               struct wl1271_station *wl_sta;
-               u8 hlid;
-
-               if (sta) {
-                       wl_sta = (struct wl1271_station *)sta->drv_priv;
-                       hlid = wl_sta->hlid;
-               } else {
-                       hlid = wlvif->ap.bcast_hlid;
-               }
-
-               if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
-                       /*
-                        * We do not support removing keys after AP shutdown.
-                        * Pretend we do to make mac80211 happy.
-                        */
-                       if (action != KEY_ADD_OR_REPLACE)
-                               return 0;
-
-                       ret = wl1271_record_ap_key(wl, wlvif, id,
-                                            key_type, key_size,
-                                            key, hlid, tx_seq_32,
-                                            tx_seq_16);
-               } else {
-                       ret = wl1271_cmd_set_ap_key(wl, wlvif, action,
-                                            id, key_type, key_size,
-                                            key, hlid, tx_seq_32,
-                                            tx_seq_16);
-               }
-
-               if (ret < 0)
-                       return ret;
-       } else {
-               const u8 *addr;
-               static const u8 bcast_addr[ETH_ALEN] = {
-                       0xff, 0xff, 0xff, 0xff, 0xff, 0xff
-               };
-
-               /*
-                * A STA set to GEM cipher requires 2 tx spare blocks.
-                * Return to default value when GEM cipher key is removed
-                */
-               if (key_type == KEY_GEM) {
-                       if (action == KEY_ADD_OR_REPLACE)
-                               wl->tx_spare_blocks = 2;
-                       else if (action == KEY_REMOVE)
-                               wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
-               }
-
-               addr = sta ? sta->addr : bcast_addr;
-
-               if (is_zero_ether_addr(addr)) {
-                       /* We dont support TX only encryption */
-                       return -EOPNOTSUPP;
-               }
-
-               /* The wl1271 does not allow to remove unicast keys - they
-                  will be cleared automatically on next CMD_JOIN. Ignore the
-                  request silently, as we dont want the mac80211 to emit
-                  an error message. */
-               if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
-                       return 0;
-
-               /* don't remove key if hlid was already deleted */
-               if (action == KEY_REMOVE &&
-                   wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
-                       return 0;
-
-               ret = wl1271_cmd_set_sta_key(wl, wlvif, action,
-                                            id, key_type, key_size,
-                                            key, addr, tx_seq_32,
-                                            tx_seq_16);
-               if (ret < 0)
-                       return ret;
-
-               /* the default WEP key needs to be configured at least once */
-               if (key_type == KEY_WEP) {
-                       ret = wl12xx_cmd_set_default_wep_key(wl,
-                                                       wlvif->default_key,
-                                                       wlvif->sta.hlid);
-                       if (ret < 0)
-                               return ret;
-               }
-       }
-
-       return 0;
-}
-
-static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
-                            struct ieee80211_vif *vif,
-                            struct ieee80211_sta *sta,
-                            struct ieee80211_key_conf *key_conf)
-{
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       int ret;
-       u32 tx_seq_32 = 0;
-       u16 tx_seq_16 = 0;
-       u8 key_type;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
-
-       wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta);
-       wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
-                    key_conf->cipher, key_conf->keyidx,
-                    key_conf->keylen, key_conf->flags);
-       wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
-
-       mutex_lock(&wl->mutex);
-
-       if (unlikely(wl->state == WL1271_STATE_OFF)) {
-               ret = -EAGAIN;
-               goto out_unlock;
-       }
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out_unlock;
-
-       switch (key_conf->cipher) {
-       case WLAN_CIPHER_SUITE_WEP40:
-       case WLAN_CIPHER_SUITE_WEP104:
-               key_type = KEY_WEP;
-
-               key_conf->hw_key_idx = key_conf->keyidx;
-               break;
-       case WLAN_CIPHER_SUITE_TKIP:
-               key_type = KEY_TKIP;
-
-               key_conf->hw_key_idx = key_conf->keyidx;
-               tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
-               tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
-               break;
-       case WLAN_CIPHER_SUITE_CCMP:
-               key_type = KEY_AES;
-
-               key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
-               tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
-               tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
-               break;
-       case WL1271_CIPHER_SUITE_GEM:
-               key_type = KEY_GEM;
-               tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
-               tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
-               break;
-       default:
-               wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
-
-               ret = -EOPNOTSUPP;
-               goto out_sleep;
-       }
-
-       switch (cmd) {
-       case SET_KEY:
-               ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE,
-                                key_conf->keyidx, key_type,
-                                key_conf->keylen, key_conf->key,
-                                tx_seq_32, tx_seq_16, sta);
-               if (ret < 0) {
-                       wl1271_error("Could not add or replace key");
-                       goto out_sleep;
-               }
-
-               /*
-                * reconfiguring arp response if the unicast (or common)
-                * encryption key type was changed
-                */
-               if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
-                   (sta || key_type == KEY_WEP) &&
-                   wlvif->encryption_type != key_type) {
-                       wlvif->encryption_type = key_type;
-                       ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
-                       if (ret < 0) {
-                               wl1271_warning("build arp rsp failed: %d", ret);
-                               goto out_sleep;
-                       }
-               }
-               break;
-
-       case DISABLE_KEY:
-               ret = wl1271_set_key(wl, wlvif, KEY_REMOVE,
-                                    key_conf->keyidx, key_type,
-                                    key_conf->keylen, key_conf->key,
-                                    0, 0, sta);
-               if (ret < 0) {
-                       wl1271_error("Could not remove key");
-                       goto out_sleep;
-               }
-               break;
-
-       default:
-               wl1271_error("Unsupported key cmd 0x%x", cmd);
-               ret = -EOPNOTSUPP;
-               break;
-       }
-
-out_sleep:
-       wl1271_ps_elp_sleep(wl);
-
-out_unlock:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
-                            struct ieee80211_vif *vif,
-                            struct cfg80211_scan_request *req)
-{
-       struct wl1271 *wl = hw->priv;
-       int ret;
-       u8 *ssid = NULL;
-       size_t len = 0;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
-
-       if (req->n_ssids) {
-               ssid = req->ssids[0].ssid;
-               len = req->ssids[0].ssid_len;
-       }
-
-       mutex_lock(&wl->mutex);
-
-       if (wl->state == WL1271_STATE_OFF) {
-               /*
-                * We cannot return -EBUSY here because cfg80211 will expect
-                * a call to ieee80211_scan_completed if we do - in this case
-                * there won't be any call.
-                */
-               ret = -EAGAIN;
-               goto out;
-       }
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       /* fail if there is any role in ROC */
-       if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) {
-               /* don't allow scanning right now */
-               ret = -EBUSY;
-               goto out_sleep;
-       }
-
-       ret = wl1271_scan(hw->priv, vif, ssid, len, req);
-out_sleep:
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw,
-                                    struct ieee80211_vif *vif)
-{
-       struct wl1271 *wl = hw->priv;
-       int ret;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan");
-
-       mutex_lock(&wl->mutex);
-
-       if (wl->state == WL1271_STATE_OFF)
-               goto out;
-
-       if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
-               goto out;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       if (wl->scan.state != WL1271_SCAN_STATE_DONE) {
-               ret = wl1271_scan_stop(wl);
-               if (ret < 0)
-                       goto out_sleep;
-       }
-
-       /*
-        * Rearm the tx watchdog just before idling scan. This
-        * prevents just-finished scans from triggering the watchdog
-        */
-       wl12xx_rearm_tx_watchdog_locked(wl);
-
-       wl->scan.state = WL1271_SCAN_STATE_IDLE;
-       memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
-       wl->scan_vif = NULL;
-       wl->scan.req = NULL;
-       ieee80211_scan_completed(wl->hw, true);
-
-out_sleep:
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-
-       cancel_delayed_work_sync(&wl->scan_complete_work);
-}
-
-static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
-                                     struct ieee80211_vif *vif,
-                                     struct cfg80211_sched_scan_request *req,
-                                     struct ieee80211_sched_scan_ies *ies)
-{
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       int ret;
-
-       wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
-
-       mutex_lock(&wl->mutex);
-
-       if (wl->state == WL1271_STATE_OFF) {
-               ret = -EAGAIN;
-               goto out;
-       }
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies);
-       if (ret < 0)
-               goto out_sleep;
-
-       ret = wl1271_scan_sched_scan_start(wl, wlvif);
-       if (ret < 0)
-               goto out_sleep;
-
-       wl->sched_scanning = true;
-
-out_sleep:
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-       return ret;
-}
-
-static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
-                                     struct ieee80211_vif *vif)
-{
-       struct wl1271 *wl = hw->priv;
-       int ret;
-
-       wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
-
-       mutex_lock(&wl->mutex);
-
-       if (wl->state == WL1271_STATE_OFF)
-               goto out;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       wl1271_scan_sched_scan_stop(wl);
-
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
-{
-       struct wl1271 *wl = hw->priv;
-       int ret = 0;
-
-       mutex_lock(&wl->mutex);
-
-       if (unlikely(wl->state == WL1271_STATE_OFF)) {
-               ret = -EAGAIN;
-               goto out;
-       }
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1271_acx_frag_threshold(wl, value);
-       if (ret < 0)
-               wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
-
-       wl1271_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
-{
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif;
-       int ret = 0;
-
-       mutex_lock(&wl->mutex);
-
-       if (unlikely(wl->state == WL1271_STATE_OFF)) {
-               ret = -EAGAIN;
-               goto out;
-       }
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       wl12xx_for_each_wlvif(wl, wlvif) {
-               ret = wl1271_acx_rts_threshold(wl, wlvif, value);
-               if (ret < 0)
-                       wl1271_warning("set rts threshold failed: %d", ret);
-       }
-       wl1271_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb,
-                           int offset)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       u8 ssid_len;
-       const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
-                                        skb->len - offset);
-
-       if (!ptr) {
-               wl1271_error("No SSID in IEs!");
-               return -ENOENT;
-       }
-
-       ssid_len = ptr[1];
-       if (ssid_len > IEEE80211_MAX_SSID_LEN) {
-               wl1271_error("SSID is too long!");
-               return -EINVAL;
-       }
-
-       wlvif->ssid_len = ssid_len;
-       memcpy(wlvif->ssid, ptr+2, ssid_len);
-       return 0;
-}
-
-static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset)
-{
-       int len;
-       const u8 *next, *end = skb->data + skb->len;
-       u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset,
-                                       skb->len - ieoffset);
-       if (!ie)
-               return;
-       len = ie[1] + 2;
-       next = ie + len;
-       memmove(ie, next, end - next);
-       skb_trim(skb, skb->len - len);
-}
-
-static void wl12xx_remove_vendor_ie(struct sk_buff *skb,
-                                           unsigned int oui, u8 oui_type,
-                                           int ieoffset)
-{
-       int len;
-       const u8 *next, *end = skb->data + skb->len;
-       u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
-                                              skb->data + ieoffset,
-                                              skb->len - ieoffset);
-       if (!ie)
-               return;
-       len = ie[1] + 2;
-       next = ie + len;
-       memmove(ie, next, end - next);
-       skb_trim(skb, skb->len - len);
-}
-
-static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates,
-                                        struct ieee80211_vif *vif)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       struct sk_buff *skb;
-       int ret;
-
-       skb = ieee80211_proberesp_get(wl->hw, vif);
-       if (!skb)
-               return -EOPNOTSUPP;
-
-       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
-                                     CMD_TEMPL_AP_PROBE_RESPONSE,
-                                     skb->data,
-                                     skb->len, 0,
-                                     rates);
-
-       dev_kfree_skb(skb);
-       return ret;
-}
-
-static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl,
-                                            struct ieee80211_vif *vif,
-                                            u8 *probe_rsp_data,
-                                            size_t probe_rsp_len,
-                                            u32 rates)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
-       u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE];
-       int ssid_ie_offset, ie_offset, templ_len;
-       const u8 *ptr;
-
-       /* no need to change probe response if the SSID is set correctly */
-       if (wlvif->ssid_len > 0)
-               return wl1271_cmd_template_set(wl, wlvif->role_id,
-                                              CMD_TEMPL_AP_PROBE_RESPONSE,
-                                              probe_rsp_data,
-                                              probe_rsp_len, 0,
-                                              rates);
-
-       if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) {
-               wl1271_error("probe_rsp template too big");
-               return -EINVAL;
-       }
-
-       /* start searching from IE offset */
-       ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
-
-       ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset,
-                              probe_rsp_len - ie_offset);
-       if (!ptr) {
-               wl1271_error("No SSID in beacon!");
-               return -EINVAL;
-       }
-
-       ssid_ie_offset = ptr - probe_rsp_data;
-       ptr += (ptr[1] + 2);
-
-       memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset);
-
-       /* insert SSID from bss_conf */
-       probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID;
-       probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len;
-       memcpy(probe_rsp_templ + ssid_ie_offset + 2,
-              bss_conf->ssid, bss_conf->ssid_len);
-       templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len;
-
-       memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len,
-              ptr, probe_rsp_len - (ptr - probe_rsp_data));
-       templ_len += probe_rsp_len - (ptr - probe_rsp_data);
-
-       return wl1271_cmd_template_set(wl, wlvif->role_id,
-                                      CMD_TEMPL_AP_PROBE_RESPONSE,
-                                      probe_rsp_templ,
-                                      templ_len, 0,
-                                      rates);
-}
-
-static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
-                                      struct ieee80211_vif *vif,
-                                      struct ieee80211_bss_conf *bss_conf,
-                                      u32 changed)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       int ret = 0;
-
-       if (changed & BSS_CHANGED_ERP_SLOT) {
-               if (bss_conf->use_short_slot)
-                       ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT);
-               else
-                       ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG);
-               if (ret < 0) {
-                       wl1271_warning("Set slot time failed %d", ret);
-                       goto out;
-               }
-       }
-
-       if (changed & BSS_CHANGED_ERP_PREAMBLE) {
-               if (bss_conf->use_short_preamble)
-                       wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT);
-               else
-                       wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG);
-       }
-
-       if (changed & BSS_CHANGED_ERP_CTS_PROT) {
-               if (bss_conf->use_cts_prot)
-                       ret = wl1271_acx_cts_protect(wl, wlvif,
-                                                    CTSPROTECT_ENABLE);
-               else
-                       ret = wl1271_acx_cts_protect(wl, wlvif,
-                                                    CTSPROTECT_DISABLE);
-               if (ret < 0) {
-                       wl1271_warning("Set ctsprotect failed %d", ret);
-                       goto out;
-               }
-       }
-
-out:
-       return ret;
-}
-
-static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
-                                         struct ieee80211_vif *vif,
-                                         struct ieee80211_bss_conf *bss_conf,
-                                         u32 changed)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
-       int ret = 0;
-
-       if ((changed & BSS_CHANGED_BEACON_INT)) {
-               wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
-                       bss_conf->beacon_int);
-
-               wlvif->beacon_int = bss_conf->beacon_int;
-       }
-
-       if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) {
-               u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
-               if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) {
-                       wl1271_debug(DEBUG_AP, "probe response updated");
-                       set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
-               }
-       }
-
-       if ((changed & BSS_CHANGED_BEACON)) {
-               struct ieee80211_hdr *hdr;
-               u32 min_rate;
-               int ieoffset = offsetof(struct ieee80211_mgmt,
-                                       u.beacon.variable);
-               struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
-               u16 tmpl_id;
-
-               if (!beacon) {
-                       ret = -EINVAL;
-                       goto out;
-               }
-
-               wl1271_debug(DEBUG_MASTER, "beacon updated");
-
-               ret = wl1271_ssid_set(vif, beacon, ieoffset);
-               if (ret < 0) {
-                       dev_kfree_skb(beacon);
-                       goto out;
-               }
-               min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
-               tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
-                                 CMD_TEMPL_BEACON;
-               ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id,
-                                             beacon->data,
-                                             beacon->len, 0,
-                                             min_rate);
-               if (ret < 0) {
-                       dev_kfree_skb(beacon);
-                       goto out;
-               }
-
-               /*
-                * In case we already have a probe-resp beacon set explicitly
-                * by usermode, don't use the beacon data.
-                */
-               if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
-                       goto end_bcn;
-
-               /* remove TIM ie from probe response */
-               wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
-
-               /*
-                * remove p2p ie from probe response.
-                * the fw reponds to probe requests that don't include
-                * the p2p ie. probe requests with p2p ie will be passed,
-                * and will be responded by the supplicant (the spec
-                * forbids including the p2p ie when responding to probe
-                * requests that didn't include it).
-                */
-               wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA,
-                                       WLAN_OUI_TYPE_WFA_P2P, ieoffset);
-
-               hdr = (struct ieee80211_hdr *) beacon->data;
-               hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
-                                                IEEE80211_STYPE_PROBE_RESP);
-               if (is_ap)
-                       ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
-                                               beacon->data,
-                                               beacon->len,
-                                               min_rate);
-               else
-                       ret = wl1271_cmd_template_set(wl, wlvif->role_id,
-                                               CMD_TEMPL_PROBE_RESPONSE,
-                                               beacon->data,
-                                               beacon->len, 0,
-                                               min_rate);
-end_bcn:
-               dev_kfree_skb(beacon);
-               if (ret < 0)
-                       goto out;
-       }
-
-out:
-       if (ret != 0)
-               wl1271_error("beacon info change failed: %d", ret);
-       return ret;
-}
-
-/* AP mode changes */
-static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
-                                      struct ieee80211_vif *vif,
-                                      struct ieee80211_bss_conf *bss_conf,
-                                      u32 changed)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       int ret = 0;
-
-       if ((changed & BSS_CHANGED_BASIC_RATES)) {
-               u32 rates = bss_conf->basic_rates;
-
-               wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates,
-                                                                wlvif->band);
-               wlvif->basic_rate = wl1271_tx_min_rate_get(wl,
-                                                       wlvif->basic_rate_set);
-
-               ret = wl1271_init_ap_rates(wl, wlvif);
-               if (ret < 0) {
-                       wl1271_error("AP rate policy change failed %d", ret);
-                       goto out;
-               }
-
-               ret = wl1271_ap_init_templates(wl, vif);
-               if (ret < 0)
-                       goto out;
-       }
-
-       ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
-       if (ret < 0)
-               goto out;
-
-       if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
-               if (bss_conf->enable_beacon) {
-                       if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
-                               ret = wl12xx_cmd_role_start_ap(wl, wlvif);
-                               if (ret < 0)
-                                       goto out;
-
-                               ret = wl1271_ap_init_hwenc(wl, wlvif);
-                               if (ret < 0)
-                                       goto out;
-
-                               set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
-                               wl1271_debug(DEBUG_AP, "started AP");
-                       }
-               } else {
-                       if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
-                               ret = wl12xx_cmd_role_stop_ap(wl, wlvif);
-                               if (ret < 0)
-                                       goto out;
-
-                               clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
-                               clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET,
-                                         &wlvif->flags);
-                               wl1271_debug(DEBUG_AP, "stopped AP");
-                       }
-               }
-       }
-
-       ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
-       if (ret < 0)
-               goto out;
-
-       /* Handle HT information change */
-       if ((changed & BSS_CHANGED_HT) &&
-           (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
-               ret = wl1271_acx_set_ht_information(wl, wlvif,
-                                       bss_conf->ht_operation_mode);
-               if (ret < 0) {
-                       wl1271_warning("Set ht information failed %d", ret);
-                       goto out;
-               }
-       }
-
-out:
-       return;
-}
-
-/* STA/IBSS mode changes */
-static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
-                                       struct ieee80211_vif *vif,
-                                       struct ieee80211_bss_conf *bss_conf,
-                                       u32 changed)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       bool do_join = false, set_assoc = false;
-       bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
-       bool ibss_joined = false;
-       u32 sta_rate_set = 0;
-       int ret;
-       struct ieee80211_sta *sta;
-       bool sta_exists = false;
-       struct ieee80211_sta_ht_cap sta_ht_cap;
-
-       if (is_ibss) {
-               ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
-                                                    changed);
-               if (ret < 0)
-                       goto out;
-       }
-
-       if (changed & BSS_CHANGED_IBSS) {
-               if (bss_conf->ibss_joined) {
-                       set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags);
-                       ibss_joined = true;
-               } else {
-                       if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED,
-                                              &wlvif->flags))
-                               wl1271_unjoin(wl, wlvif);
-               }
-       }
-
-       if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined)
-               do_join = true;
-
-       /* Need to update the SSID (for filtering etc) */
-       if ((changed & BSS_CHANGED_BEACON) && ibss_joined)
-               do_join = true;
-
-       if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) {
-               wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
-                            bss_conf->enable_beacon ? "enabled" : "disabled");
-
-               do_join = true;
-       }
-
-       if (changed & BSS_CHANGED_IDLE && !is_ibss) {
-               ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle);
-               if (ret < 0)
-                       wl1271_warning("idle mode change failed %d", ret);
-       }
-
-       if ((changed & BSS_CHANGED_CQM)) {
-               bool enable = false;
-               if (bss_conf->cqm_rssi_thold)
-                       enable = true;
-               ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable,
-                                                 bss_conf->cqm_rssi_thold,
-                                                 bss_conf->cqm_rssi_hyst);
-               if (ret < 0)
-                       goto out;
-               wlvif->rssi_thold = bss_conf->cqm_rssi_thold;
-       }
-
-       if (changed & BSS_CHANGED_BSSID &&
-           (is_ibss || bss_conf->assoc))
-               if (!is_zero_ether_addr(bss_conf->bssid)) {
-                       ret = wl12xx_cmd_build_null_data(wl, wlvif);
-                       if (ret < 0)
-                               goto out;
-
-                       ret = wl1271_build_qos_null_data(wl, vif);
-                       if (ret < 0)
-                               goto out;
-
-                       /* Need to update the BSSID (for filtering etc) */
-                       do_join = true;
-               }
-
-       if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) {
-               rcu_read_lock();
-               sta = ieee80211_find_sta(vif, bss_conf->bssid);
-               if (!sta)
-                       goto sta_not_found;
-
-               /* save the supp_rates of the ap */
-               sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
-               if (sta->ht_cap.ht_supported)
-                       sta_rate_set |=
-                           (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
-               sta_ht_cap = sta->ht_cap;
-               sta_exists = true;
-
-sta_not_found:
-               rcu_read_unlock();
-       }
-
-       if ((changed & BSS_CHANGED_ASSOC)) {
-               if (bss_conf->assoc) {
-                       u32 rates;
-                       int ieoffset;
-                       wlvif->aid = bss_conf->aid;
-                       wlvif->beacon_int = bss_conf->beacon_int;
-                       set_assoc = true;
-
-                       /*
-                        * use basic rates from AP, and determine lowest rate
-                        * to use with control frames.
-                        */
-                       rates = bss_conf->basic_rates;
-                       wlvif->basic_rate_set =
-                               wl1271_tx_enabled_rates_get(wl, rates,
-                                                           wlvif->band);
-                       wlvif->basic_rate =
-                               wl1271_tx_min_rate_get(wl,
-                                                      wlvif->basic_rate_set);
-                       if (sta_rate_set)
-                               wlvif->rate_set =
-                                       wl1271_tx_enabled_rates_get(wl,
-                                                               sta_rate_set,
-                                                               wlvif->band);
-                       ret = wl1271_acx_sta_rate_policies(wl, wlvif);
-                       if (ret < 0)
-                               goto out;
-
-                       /*
-                        * with wl1271, we don't need to update the
-                        * beacon_int and dtim_period, because the firmware
-                        * updates it by itself when the first beacon is
-                        * received after a join.
-                        */
-                       ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid);
-                       if (ret < 0)
-                               goto out;
-
-                       /*
-                        * Get a template for hardware connection maintenance
-                        */
-                       dev_kfree_skb(wlvif->probereq);
-                       wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl,
-                                                                       wlvif,
-                                                                       NULL);
-                       ieoffset = offsetof(struct ieee80211_mgmt,
-                                           u.probe_req.variable);
-                       wl1271_ssid_set(vif, wlvif->probereq, ieoffset);
-
-                       /* enable the connection monitoring feature */
-                       ret = wl1271_acx_conn_monit_params(wl, wlvif, true);
-                       if (ret < 0)
-                               goto out;
-               } else {
-                       /* use defaults when not associated */
-                       bool was_assoc =
-                           !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED,
-                                                &wlvif->flags);
-                       bool was_ifup =
-                           !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT,
-                                                &wlvif->flags);
-                       wlvif->aid = 0;
-
-                       /* free probe-request template */
-                       dev_kfree_skb(wlvif->probereq);
-                       wlvif->probereq = NULL;
-
-                       /* revert back to minimum rates for the current band */
-                       wl1271_set_band_rate(wl, wlvif);
-                       wlvif->basic_rate =
-                               wl1271_tx_min_rate_get(wl,
-                                                      wlvif->basic_rate_set);
-                       ret = wl1271_acx_sta_rate_policies(wl, wlvif);
-                       if (ret < 0)
-                               goto out;
-
-                       /* disable connection monitor features */
-                       ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
-
-                       /* Disable the keep-alive feature */
-                       ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
-                       if (ret < 0)
-                               goto out;
-
-                       /* restore the bssid filter and go to dummy bssid */
-                       if (was_assoc) {
-                               /*
-                                * we might have to disable roc, if there was
-                                * no IF_OPER_UP notification.
-                                */
-                               if (!was_ifup) {
-                                       ret = wl12xx_croc(wl, wlvif->role_id);
-                                       if (ret < 0)
-                                               goto out;
-                               }
-                               /*
-                                * (we also need to disable roc in case of
-                                * roaming on the same channel. until we will
-                                * have a better flow...)
-                                */
-                               if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
-                                       ret = wl12xx_croc(wl,
-                                                         wlvif->dev_role_id);
-                                       if (ret < 0)
-                                               goto out;
-                               }
-
-                               wl1271_unjoin(wl, wlvif);
-                               if (!bss_conf->idle)
-                                       wl12xx_start_dev(wl, wlvif);
-                       }
-               }
-       }
-
-       if (changed & BSS_CHANGED_IBSS) {
-               wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
-                            bss_conf->ibss_joined);
-
-               if (bss_conf->ibss_joined) {
-                       u32 rates = bss_conf->basic_rates;
-                       wlvif->basic_rate_set =
-                               wl1271_tx_enabled_rates_get(wl, rates,
-                                                           wlvif->band);
-                       wlvif->basic_rate =
-                               wl1271_tx_min_rate_get(wl,
-                                                      wlvif->basic_rate_set);
-
-                       /* by default, use 11b + OFDM rates */
-                       wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
-                       ret = wl1271_acx_sta_rate_policies(wl, wlvif);
-                       if (ret < 0)
-                               goto out;
-               }
-       }
-
-       ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
-       if (ret < 0)
-               goto out;
-
-       if (do_join) {
-               ret = wl1271_join(wl, wlvif, set_assoc);
-               if (ret < 0) {
-                       wl1271_warning("cmd join failed %d", ret);
-                       goto out;
-               }
-
-               /* ROC until connected (after EAPOL exchange) */
-               if (!is_ibss) {
-                       ret = wl12xx_roc(wl, wlvif, wlvif->role_id);
-                       if (ret < 0)
-                               goto out;
-
-                       if (test_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags))
-                               wl12xx_set_authorized(wl, wlvif);
-               }
-               /*
-                * stop device role if started (we might already be in
-                * STA/IBSS role).
-                */
-               if (wl12xx_dev_role_started(wlvif)) {
-                       ret = wl12xx_stop_dev(wl, wlvif);
-                       if (ret < 0)
-                               goto out;
-               }
-       }
-
-       /* Handle new association with HT. Do this after join. */
-       if (sta_exists) {
-               if ((changed & BSS_CHANGED_HT) &&
-                   (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
-                       ret = wl1271_acx_set_ht_capabilities(wl,
-                                                            &sta_ht_cap,
-                                                            true,
-                                                            wlvif->sta.hlid);
-                       if (ret < 0) {
-                               wl1271_warning("Set ht cap true failed %d",
-                                              ret);
-                               goto out;
-                       }
-               }
-               /* handle new association without HT and disassociation */
-               else if (changed & BSS_CHANGED_ASSOC) {
-                       ret = wl1271_acx_set_ht_capabilities(wl,
-                                                            &sta_ht_cap,
-                                                            false,
-                                                            wlvif->sta.hlid);
-                       if (ret < 0) {
-                               wl1271_warning("Set ht cap false failed %d",
-                                              ret);
-                               goto out;
-                       }
-               }
-       }
-
-       /* Handle HT information change. Done after join. */
-       if ((changed & BSS_CHANGED_HT) &&
-           (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
-               ret = wl1271_acx_set_ht_information(wl, wlvif,
-                                       bss_conf->ht_operation_mode);
-               if (ret < 0) {
-                       wl1271_warning("Set ht information failed %d", ret);
-                       goto out;
-               }
-       }
-
-       /* Handle arp filtering. Done after join. */
-       if ((changed & BSS_CHANGED_ARP_FILTER) ||
-           (!is_ibss && (changed & BSS_CHANGED_QOS))) {
-               __be32 addr = bss_conf->arp_addr_list[0];
-               wlvif->sta.qos = bss_conf->qos;
-               WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS);
-
-               if (bss_conf->arp_addr_cnt == 1 &&
-                   bss_conf->arp_filter_enabled) {
-                       wlvif->ip_addr = addr;
-                       /*
-                        * The template should have been configured only upon
-                        * association. however, it seems that the correct ip
-                        * isn't being set (when sending), so we have to
-                        * reconfigure the template upon every ip change.
-                        */
-                       ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
-                       if (ret < 0) {
-                               wl1271_warning("build arp rsp failed: %d", ret);
-                               goto out;
-                       }
-
-                       ret = wl1271_acx_arp_ip_filter(wl, wlvif,
-                               (ACX_ARP_FILTER_ARP_FILTERING |
-                                ACX_ARP_FILTER_AUTO_ARP),
-                               addr);
-               } else {
-                       wlvif->ip_addr = 0;
-                       ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr);
-               }
-
-               if (ret < 0)
-                       goto out;
-       }
-
-out:
-       return;
-}
-
-static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
-                                      struct ieee80211_vif *vif,
-                                      struct ieee80211_bss_conf *bss_conf,
-                                      u32 changed)
-{
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
-       int ret;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
-                    (int)changed);
-
-       mutex_lock(&wl->mutex);
-
-       if (unlikely(wl->state == WL1271_STATE_OFF))
-               goto out;
-
-       if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
-               goto out;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       if (is_ap)
-               wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed);
-       else
-               wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed);
-
-       wl1271_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
-                            struct ieee80211_vif *vif, u16 queue,
-                            const struct ieee80211_tx_queue_params *params)
-{
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       u8 ps_scheme;
-       int ret = 0;
-
-       mutex_lock(&wl->mutex);
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
-
-       if (params->uapsd)
-               ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
-       else
-               ps_scheme = CONF_PS_SCHEME_LEGACY;
-
-       if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
-               goto out;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       /*
-        * the txop is confed in units of 32us by the mac80211,
-        * we need us
-        */
-       ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
-                               params->cw_min, params->cw_max,
-                               params->aifs, params->txop << 5);
-       if (ret < 0)
-               goto out_sleep;
-
-       ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
-                                CONF_CHANNEL_TYPE_EDCF,
-                                wl1271_tx_get_queue(queue),
-                                ps_scheme, CONF_ACK_POLICY_LEGACY,
-                                0, 0);
-
-out_sleep:
-       wl1271_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw,
-                            struct ieee80211_vif *vif)
-{
-
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       u64 mactime = ULLONG_MAX;
-       int ret;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf");
-
-       mutex_lock(&wl->mutex);
-
-       if (unlikely(wl->state == WL1271_STATE_OFF))
-               goto out;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime);
-       if (ret < 0)
-               goto out_sleep;
-
-out_sleep:
-       wl1271_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-       return mactime;
-}
-
-static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
-                               struct survey_info *survey)
-{
-       struct wl1271 *wl = hw->priv;
-       struct ieee80211_conf *conf = &hw->conf;
-
-       if (idx != 0)
-               return -ENOENT;
-
-       survey->channel = conf->channel;
-       survey->filled = SURVEY_INFO_NOISE_DBM;
-       survey->noise = wl->noise;
-
-       return 0;
-}
-
-static int wl1271_allocate_sta(struct wl1271 *wl,
-                            struct wl12xx_vif *wlvif,
-                            struct ieee80211_sta *sta)
-{
-       struct wl1271_station *wl_sta;
-       int ret;
-
-
-       if (wl->active_sta_count >= AP_MAX_STATIONS) {
-               wl1271_warning("could not allocate HLID - too much stations");
-               return -EBUSY;
-       }
-
-       wl_sta = (struct wl1271_station *)sta->drv_priv;
-       ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid);
-       if (ret < 0) {
-               wl1271_warning("could not allocate HLID - too many links");
-               return -EBUSY;
-       }
-
-       set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map);
-       memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
-       wl->active_sta_count++;
-       return 0;
-}
-
-void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
-{
-       if (!test_bit(hlid, wlvif->ap.sta_hlid_map))
-               return;
-
-       clear_bit(hlid, wlvif->ap.sta_hlid_map);
-       memset(wl->links[hlid].addr, 0, ETH_ALEN);
-       wl->links[hlid].ba_bitmap = 0;
-       __clear_bit(hlid, &wl->ap_ps_map);
-       __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
-       wl12xx_free_link(wl, wlvif, &hlid);
-       wl->active_sta_count--;
-
-       /*
-        * rearm the tx watchdog when the last STA is freed - give the FW a
-        * chance to return STA-buffered packets before complaining.
-        */
-       if (wl->active_sta_count == 0)
-               wl12xx_rearm_tx_watchdog_locked(wl);
-}
-
-static int wl12xx_sta_add(struct wl1271 *wl,
-                         struct wl12xx_vif *wlvif,
-                         struct ieee80211_sta *sta)
-{
-       struct wl1271_station *wl_sta;
-       int ret = 0;
-       u8 hlid;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
-
-       ret = wl1271_allocate_sta(wl, wlvif, sta);
-       if (ret < 0)
-               return ret;
-
-       wl_sta = (struct wl1271_station *)sta->drv_priv;
-       hlid = wl_sta->hlid;
-
-       ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid);
-       if (ret < 0)
-               wl1271_free_sta(wl, wlvif, hlid);
-
-       return ret;
-}
-
-static int wl12xx_sta_remove(struct wl1271 *wl,
-                            struct wl12xx_vif *wlvif,
-                            struct ieee80211_sta *sta)
-{
-       struct wl1271_station *wl_sta;
-       int ret = 0, id;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
-
-       wl_sta = (struct wl1271_station *)sta->drv_priv;
-       id = wl_sta->hlid;
-       if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map)))
-               return -EINVAL;
-
-       ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid);
-       if (ret < 0)
-               return ret;
-
-       wl1271_free_sta(wl, wlvif, wl_sta->hlid);
-       return ret;
-}
-
-static int wl12xx_update_sta_state(struct wl1271 *wl,
-                                  struct wl12xx_vif *wlvif,
-                                  struct ieee80211_sta *sta,
-                                  enum ieee80211_sta_state old_state,
-                                  enum ieee80211_sta_state new_state)
-{
-       struct wl1271_station *wl_sta;
-       u8 hlid;
-       bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
-       bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
-       int ret;
-
-       wl_sta = (struct wl1271_station *)sta->drv_priv;
-       hlid = wl_sta->hlid;
-
-       /* Add station (AP mode) */
-       if (is_ap &&
-           old_state == IEEE80211_STA_NOTEXIST &&
-           new_state == IEEE80211_STA_NONE)
-               return wl12xx_sta_add(wl, wlvif, sta);
-
-       /* Remove station (AP mode) */
-       if (is_ap &&
-           old_state == IEEE80211_STA_NONE &&
-           new_state == IEEE80211_STA_NOTEXIST) {
-               /* must not fail */
-               wl12xx_sta_remove(wl, wlvif, sta);
-               return 0;
-       }
-
-       /* Authorize station (AP mode) */
-       if (is_ap &&
-           new_state == IEEE80211_STA_AUTHORIZED) {
-               ret = wl12xx_cmd_set_peer_state(wl, hlid);
-               if (ret < 0)
-                       return ret;
-
-               ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true,
-                                                    hlid);
-               return ret;
-       }
-
-       /* Authorize station */
-       if (is_sta &&
-           new_state == IEEE80211_STA_AUTHORIZED) {
-               set_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
-               return wl12xx_set_authorized(wl, wlvif);
-       }
-
-       if (is_sta &&
-           old_state == IEEE80211_STA_AUTHORIZED &&
-           new_state == IEEE80211_STA_ASSOC) {
-               clear_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
-               return 0;
-       }
-
-       return 0;
-}
-
-static int wl12xx_op_sta_state(struct ieee80211_hw *hw,
-                              struct ieee80211_vif *vif,
-                              struct ieee80211_sta *sta,
-                              enum ieee80211_sta_state old_state,
-                              enum ieee80211_sta_state new_state)
-{
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       int ret;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 sta %d state=%d->%d",
-                    sta->aid, old_state, new_state);
-
-       mutex_lock(&wl->mutex);
-
-       if (unlikely(wl->state == WL1271_STATE_OFF)) {
-               ret = -EBUSY;
-               goto out;
-       }
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       ret = wl12xx_update_sta_state(wl, wlvif, sta, old_state, new_state);
-
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-       if (new_state < old_state)
-               return 0;
-       return ret;
-}
-
-static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
-                                 struct ieee80211_vif *vif,
-                                 enum ieee80211_ampdu_mlme_action action,
-                                 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
-                                 u8 buf_size)
-{
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       int ret;
-       u8 hlid, *ba_bitmap;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action,
-                    tid);
-
-       /* sanity check - the fields in FW are only 8bits wide */
-       if (WARN_ON(tid > 0xFF))
-               return -ENOTSUPP;
-
-       mutex_lock(&wl->mutex);
-
-       if (unlikely(wl->state == WL1271_STATE_OFF)) {
-               ret = -EAGAIN;
-               goto out;
-       }
-
-       if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
-               hlid = wlvif->sta.hlid;
-               ba_bitmap = &wlvif->sta.ba_rx_bitmap;
-       } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
-               struct wl1271_station *wl_sta;
-
-               wl_sta = (struct wl1271_station *)sta->drv_priv;
-               hlid = wl_sta->hlid;
-               ba_bitmap = &wl->links[hlid].ba_bitmap;
-       } else {
-               ret = -EINVAL;
-               goto out;
-       }
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d",
-                    tid, action);
-
-       switch (action) {
-       case IEEE80211_AMPDU_RX_START:
-               if (!wlvif->ba_support || !wlvif->ba_allowed) {
-                       ret = -ENOTSUPP;
-                       break;
-               }
-
-               if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) {
-                       ret = -EBUSY;
-                       wl1271_error("exceeded max RX BA sessions");
-                       break;
-               }
-
-               if (*ba_bitmap & BIT(tid)) {
-                       ret = -EINVAL;
-                       wl1271_error("cannot enable RX BA session on active "
-                                    "tid: %d", tid);
-                       break;
-               }
-
-               ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true,
-                                                        hlid);
-               if (!ret) {
-                       *ba_bitmap |= BIT(tid);
-                       wl->ba_rx_session_count++;
-               }
-               break;
-
-       case IEEE80211_AMPDU_RX_STOP:
-               if (!(*ba_bitmap & BIT(tid))) {
-                       ret = -EINVAL;
-                       wl1271_error("no active RX BA session on tid: %d",
-                                    tid);
-                       break;
-               }
-
-               ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false,
-                                                        hlid);
-               if (!ret) {
-                       *ba_bitmap &= ~BIT(tid);
-                       wl->ba_rx_session_count--;
-               }
-               break;
-
-       /*
-        * The BA initiator session management in FW independently.
-        * Falling break here on purpose for all TX APDU commands.
-        */
-       case IEEE80211_AMPDU_TX_START:
-       case IEEE80211_AMPDU_TX_STOP:
-       case IEEE80211_AMPDU_TX_OPERATIONAL:
-               ret = -EINVAL;
-               break;
-
-       default:
-               wl1271_error("Incorrect ampdu action id=%x\n", action);
-               ret = -EINVAL;
-       }
-
-       wl1271_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
-                                  struct ieee80211_vif *vif,
-                                  const struct cfg80211_bitrate_mask *mask)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       struct wl1271 *wl = hw->priv;
-       int i, ret = 0;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x",
-               mask->control[NL80211_BAND_2GHZ].legacy,
-               mask->control[NL80211_BAND_5GHZ].legacy);
-
-       mutex_lock(&wl->mutex);
-
-       for (i = 0; i < IEEE80211_NUM_BANDS; i++)
-               wlvif->bitrate_masks[i] =
-                       wl1271_tx_enabled_rates_get(wl,
-                                                   mask->control[i].legacy,
-                                                   i);
-
-       if (unlikely(wl->state == WL1271_STATE_OFF))
-               goto out;
-
-       if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
-           !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
-
-               ret = wl1271_ps_elp_wakeup(wl);
-               if (ret < 0)
-                       goto out;
-
-               wl1271_set_band_rate(wl, wlvif);
-               wlvif->basic_rate =
-                       wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
-               ret = wl1271_acx_sta_rate_policies(wl, wlvif);
-
-               wl1271_ps_elp_sleep(wl);
-       }
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
-                                    struct ieee80211_channel_switch *ch_switch)
-{
-       struct wl1271 *wl = hw->priv;
-       struct wl12xx_vif *wlvif;
-       int ret;
-
-       wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch");
-
-       wl1271_tx_flush(wl);
-
-       mutex_lock(&wl->mutex);
-
-       if (unlikely(wl->state == WL1271_STATE_OFF)) {
-               wl12xx_for_each_wlvif_sta(wl, wlvif) {
-                       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-                       ieee80211_chswitch_done(vif, false);
-               }
-               goto out;
-       }
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       /* TODO: change mac80211 to pass vif as param */
-       wl12xx_for_each_wlvif_sta(wl, wlvif) {
-               ret = wl12xx_cmd_channel_switch(wl, wlvif, ch_switch);
-
-               if (!ret)
-                       set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags);
-       }
-
-       wl1271_ps_elp_sleep(wl);
-
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
-{
-       struct wl1271 *wl = hw->priv;
-       bool ret = false;
-
-       mutex_lock(&wl->mutex);
-
-       if (unlikely(wl->state == WL1271_STATE_OFF))
-               goto out;
-
-       /* packets are considered pending if in the TX queue or the FW */
-       ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0);
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-}
-
-/* can't be const, mac80211 writes to this */
-static struct ieee80211_rate wl1271_rates[] = {
-       { .bitrate = 10,
-         .hw_value = CONF_HW_BIT_RATE_1MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
-       { .bitrate = 20,
-         .hw_value = CONF_HW_BIT_RATE_2MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
-         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
-       { .bitrate = 55,
-         .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
-         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
-       { .bitrate = 110,
-         .hw_value = CONF_HW_BIT_RATE_11MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
-         .flags = IEEE80211_RATE_SHORT_PREAMBLE },
-       { .bitrate = 60,
-         .hw_value = CONF_HW_BIT_RATE_6MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
-       { .bitrate = 90,
-         .hw_value = CONF_HW_BIT_RATE_9MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
-       { .bitrate = 120,
-         .hw_value = CONF_HW_BIT_RATE_12MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
-       { .bitrate = 180,
-         .hw_value = CONF_HW_BIT_RATE_18MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
-       { .bitrate = 240,
-         .hw_value = CONF_HW_BIT_RATE_24MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
-       { .bitrate = 360,
-        .hw_value = CONF_HW_BIT_RATE_36MBPS,
-        .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
-       { .bitrate = 480,
-         .hw_value = CONF_HW_BIT_RATE_48MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
-       { .bitrate = 540,
-         .hw_value = CONF_HW_BIT_RATE_54MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
-};
-
-/* can't be const, mac80211 writes to this */
-static struct ieee80211_channel wl1271_channels[] = {
-       { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
-       { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
-       { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
-       { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
-       { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
-       { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
-       { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
-       { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
-       { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
-       { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
-       { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
-       { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
-       { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
-       { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
-};
-
-/* mapping to indexes for wl1271_rates */
-static const u8 wl1271_rate_to_idx_2ghz[] = {
-       /* MCS rates are used only with 11n */
-       7,                            /* CONF_HW_RXTX_RATE_MCS7_SGI */
-       7,                            /* CONF_HW_RXTX_RATE_MCS7 */
-       6,                            /* CONF_HW_RXTX_RATE_MCS6 */
-       5,                            /* CONF_HW_RXTX_RATE_MCS5 */
-       4,                            /* CONF_HW_RXTX_RATE_MCS4 */
-       3,                            /* CONF_HW_RXTX_RATE_MCS3 */
-       2,                            /* CONF_HW_RXTX_RATE_MCS2 */
-       1,                            /* CONF_HW_RXTX_RATE_MCS1 */
-       0,                            /* CONF_HW_RXTX_RATE_MCS0 */
-
-       11,                            /* CONF_HW_RXTX_RATE_54   */
-       10,                            /* CONF_HW_RXTX_RATE_48   */
-       9,                             /* CONF_HW_RXTX_RATE_36   */
-       8,                             /* CONF_HW_RXTX_RATE_24   */
-
-       /* TI-specific rate */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22   */
-
-       7,                             /* CONF_HW_RXTX_RATE_18   */
-       6,                             /* CONF_HW_RXTX_RATE_12   */
-       3,                             /* CONF_HW_RXTX_RATE_11   */
-       5,                             /* CONF_HW_RXTX_RATE_9    */
-       4,                             /* CONF_HW_RXTX_RATE_6    */
-       2,                             /* CONF_HW_RXTX_RATE_5_5  */
-       1,                             /* CONF_HW_RXTX_RATE_2    */
-       0                              /* CONF_HW_RXTX_RATE_1    */
-};
-
-/* 11n STA capabilities */
-#define HW_RX_HIGHEST_RATE     72
-
-#define WL12XX_HT_CAP { \
-       .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
-              (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
-       .ht_supported = true, \
-       .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
-       .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
-       .mcs = { \
-               .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
-               .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
-               .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
-               }, \
-}
-
-/* can't be const, mac80211 writes to this */
-static struct ieee80211_supported_band wl1271_band_2ghz = {
-       .channels = wl1271_channels,
-       .n_channels = ARRAY_SIZE(wl1271_channels),
-       .bitrates = wl1271_rates,
-       .n_bitrates = ARRAY_SIZE(wl1271_rates),
-       .ht_cap = WL12XX_HT_CAP,
-};
-
-/* 5 GHz data rates for WL1273 */
-static struct ieee80211_rate wl1271_rates_5ghz[] = {
-       { .bitrate = 60,
-         .hw_value = CONF_HW_BIT_RATE_6MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
-       { .bitrate = 90,
-         .hw_value = CONF_HW_BIT_RATE_9MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
-       { .bitrate = 120,
-         .hw_value = CONF_HW_BIT_RATE_12MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
-       { .bitrate = 180,
-         .hw_value = CONF_HW_BIT_RATE_18MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
-       { .bitrate = 240,
-         .hw_value = CONF_HW_BIT_RATE_24MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
-       { .bitrate = 360,
-        .hw_value = CONF_HW_BIT_RATE_36MBPS,
-        .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
-       { .bitrate = 480,
-         .hw_value = CONF_HW_BIT_RATE_48MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
-       { .bitrate = 540,
-         .hw_value = CONF_HW_BIT_RATE_54MBPS,
-         .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
-};
-
-/* 5 GHz band channels for WL1273 */
-static struct ieee80211_channel wl1271_channels_5ghz[] = {
-       { .hw_value = 7, .center_freq = 5035, .max_power = 25 },
-       { .hw_value = 8, .center_freq = 5040, .max_power = 25 },
-       { .hw_value = 9, .center_freq = 5045, .max_power = 25 },
-       { .hw_value = 11, .center_freq = 5055, .max_power = 25 },
-       { .hw_value = 12, .center_freq = 5060, .max_power = 25 },
-       { .hw_value = 16, .center_freq = 5080, .max_power = 25 },
-       { .hw_value = 34, .center_freq = 5170, .max_power = 25 },
-       { .hw_value = 36, .center_freq = 5180, .max_power = 25 },
-       { .hw_value = 38, .center_freq = 5190, .max_power = 25 },
-       { .hw_value = 40, .center_freq = 5200, .max_power = 25 },
-       { .hw_value = 42, .center_freq = 5210, .max_power = 25 },
-       { .hw_value = 44, .center_freq = 5220, .max_power = 25 },
-       { .hw_value = 46, .center_freq = 5230, .max_power = 25 },
-       { .hw_value = 48, .center_freq = 5240, .max_power = 25 },
-       { .hw_value = 52, .center_freq = 5260, .max_power = 25 },
-       { .hw_value = 56, .center_freq = 5280, .max_power = 25 },
-       { .hw_value = 60, .center_freq = 5300, .max_power = 25 },
-       { .hw_value = 64, .center_freq = 5320, .max_power = 25 },
-       { .hw_value = 100, .center_freq = 5500, .max_power = 25 },
-       { .hw_value = 104, .center_freq = 5520, .max_power = 25 },
-       { .hw_value = 108, .center_freq = 5540, .max_power = 25 },
-       { .hw_value = 112, .center_freq = 5560, .max_power = 25 },
-       { .hw_value = 116, .center_freq = 5580, .max_power = 25 },
-       { .hw_value = 120, .center_freq = 5600, .max_power = 25 },
-       { .hw_value = 124, .center_freq = 5620, .max_power = 25 },
-       { .hw_value = 128, .center_freq = 5640, .max_power = 25 },
-       { .hw_value = 132, .center_freq = 5660, .max_power = 25 },
-       { .hw_value = 136, .center_freq = 5680, .max_power = 25 },
-       { .hw_value = 140, .center_freq = 5700, .max_power = 25 },
-       { .hw_value = 149, .center_freq = 5745, .max_power = 25 },
-       { .hw_value = 153, .center_freq = 5765, .max_power = 25 },
-       { .hw_value = 157, .center_freq = 5785, .max_power = 25 },
-       { .hw_value = 161, .center_freq = 5805, .max_power = 25 },
-       { .hw_value = 165, .center_freq = 5825, .max_power = 25 },
-};
-
-/* mapping to indexes for wl1271_rates_5ghz */
-static const u8 wl1271_rate_to_idx_5ghz[] = {
-       /* MCS rates are used only with 11n */
-       7,                            /* CONF_HW_RXTX_RATE_MCS7_SGI */
-       7,                            /* CONF_HW_RXTX_RATE_MCS7 */
-       6,                            /* CONF_HW_RXTX_RATE_MCS6 */
-       5,                            /* CONF_HW_RXTX_RATE_MCS5 */
-       4,                            /* CONF_HW_RXTX_RATE_MCS4 */
-       3,                            /* CONF_HW_RXTX_RATE_MCS3 */
-       2,                            /* CONF_HW_RXTX_RATE_MCS2 */
-       1,                            /* CONF_HW_RXTX_RATE_MCS1 */
-       0,                            /* CONF_HW_RXTX_RATE_MCS0 */
-
-       7,                             /* CONF_HW_RXTX_RATE_54   */
-       6,                             /* CONF_HW_RXTX_RATE_48   */
-       5,                             /* CONF_HW_RXTX_RATE_36   */
-       4,                             /* CONF_HW_RXTX_RATE_24   */
-
-       /* TI-specific rate */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22   */
-
-       3,                             /* CONF_HW_RXTX_RATE_18   */
-       2,                             /* CONF_HW_RXTX_RATE_12   */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11   */
-       1,                             /* CONF_HW_RXTX_RATE_9    */
-       0,                             /* CONF_HW_RXTX_RATE_6    */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5  */
-       CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2    */
-       CONF_HW_RXTX_RATE_UNSUPPORTED  /* CONF_HW_RXTX_RATE_1    */
-};
-
-static struct ieee80211_supported_band wl1271_band_5ghz = {
-       .channels = wl1271_channels_5ghz,
-       .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
-       .bitrates = wl1271_rates_5ghz,
-       .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
-       .ht_cap = WL12XX_HT_CAP,
-};
-
-static const u8 *wl1271_band_rate_to_idx[] = {
-       [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz,
-       [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz
-};
-
-static const struct ieee80211_ops wl1271_ops = {
-       .start = wl1271_op_start,
-       .stop = wl1271_op_stop,
-       .add_interface = wl1271_op_add_interface,
-       .remove_interface = wl1271_op_remove_interface,
-       .change_interface = wl12xx_op_change_interface,
-#ifdef CONFIG_PM
-       .suspend = wl1271_op_suspend,
-       .resume = wl1271_op_resume,
-#endif
-       .config = wl1271_op_config,
-       .prepare_multicast = wl1271_op_prepare_multicast,
-       .configure_filter = wl1271_op_configure_filter,
-       .tx = wl1271_op_tx,
-       .set_key = wl1271_op_set_key,
-       .hw_scan = wl1271_op_hw_scan,
-       .cancel_hw_scan = wl1271_op_cancel_hw_scan,
-       .sched_scan_start = wl1271_op_sched_scan_start,
-       .sched_scan_stop = wl1271_op_sched_scan_stop,
-       .bss_info_changed = wl1271_op_bss_info_changed,
-       .set_frag_threshold = wl1271_op_set_frag_threshold,
-       .set_rts_threshold = wl1271_op_set_rts_threshold,
-       .conf_tx = wl1271_op_conf_tx,
-       .get_tsf = wl1271_op_get_tsf,
-       .get_survey = wl1271_op_get_survey,
-       .sta_state = wl12xx_op_sta_state,
-       .ampdu_action = wl1271_op_ampdu_action,
-       .tx_frames_pending = wl1271_tx_frames_pending,
-       .set_bitrate_mask = wl12xx_set_bitrate_mask,
-       .channel_switch = wl12xx_op_channel_switch,
-       CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
-};
-
-
-u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band)
-{
-       u8 idx;
-
-       BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *));
-
-       if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) {
-               wl1271_error("Illegal RX rate from HW: %d", rate);
-               return 0;
-       }
-
-       idx = wl1271_band_rate_to_idx[band][rate];
-       if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
-               wl1271_error("Unsupported RX rate from HW: %d", rate);
-               return 0;
-       }
-
-       return idx;
-}
-
-static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev,
-                                              struct device_attribute *attr,
-                                              char *buf)
-{
-       struct wl1271 *wl = dev_get_drvdata(dev);
-       ssize_t len;
-
-       len = PAGE_SIZE;
-
-       mutex_lock(&wl->mutex);
-       len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
-                      wl->sg_enabled);
-       mutex_unlock(&wl->mutex);
-
-       return len;
-
-}
-
-static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
-                                               struct device_attribute *attr,
-                                               const char *buf, size_t count)
-{
-       struct wl1271 *wl = dev_get_drvdata(dev);
-       unsigned long res;
-       int ret;
-
-       ret = kstrtoul(buf, 10, &res);
-       if (ret < 0) {
-               wl1271_warning("incorrect value written to bt_coex_mode");
-               return count;
-       }
-
-       mutex_lock(&wl->mutex);
-
-       res = !!res;
-
-       if (res == wl->sg_enabled)
-               goto out;
-
-       wl->sg_enabled = res;
-
-       if (wl->state == WL1271_STATE_OFF)
-               goto out;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       wl1271_acx_sg_enable(wl, wl->sg_enabled);
-       wl1271_ps_elp_sleep(wl);
-
- out:
-       mutex_unlock(&wl->mutex);
-       return count;
-}
-
-static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR,
-                  wl1271_sysfs_show_bt_coex_state,
-                  wl1271_sysfs_store_bt_coex_state);
-
-static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev,
-                                          struct device_attribute *attr,
-                                          char *buf)
-{
-       struct wl1271 *wl = dev_get_drvdata(dev);
-       ssize_t len;
-
-       len = PAGE_SIZE;
-
-       mutex_lock(&wl->mutex);
-       if (wl->hw_pg_ver >= 0)
-               len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
-       else
-               len = snprintf(buf, len, "n/a\n");
-       mutex_unlock(&wl->mutex);
-
-       return len;
-}
-
-static DEVICE_ATTR(hw_pg_ver, S_IRUGO,
-                  wl1271_sysfs_show_hw_pg_ver, NULL);
-
-static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj,
-                                      struct bin_attribute *bin_attr,
-                                      char *buffer, loff_t pos, size_t count)
-{
-       struct device *dev = container_of(kobj, struct device, kobj);
-       struct wl1271 *wl = dev_get_drvdata(dev);
-       ssize_t len;
-       int ret;
-
-       ret = mutex_lock_interruptible(&wl->mutex);
-       if (ret < 0)
-               return -ERESTARTSYS;
-
-       /* Let only one thread read the log at a time, blocking others */
-       while (wl->fwlog_size == 0) {
-               DEFINE_WAIT(wait);
-
-               prepare_to_wait_exclusive(&wl->fwlog_waitq,
-                                         &wait,
-                                         TASK_INTERRUPTIBLE);
-
-               if (wl->fwlog_size != 0) {
-                       finish_wait(&wl->fwlog_waitq, &wait);
-                       break;
-               }
-
-               mutex_unlock(&wl->mutex);
-
-               schedule();
-               finish_wait(&wl->fwlog_waitq, &wait);
-
-               if (signal_pending(current))
-                       return -ERESTARTSYS;
-
-               ret = mutex_lock_interruptible(&wl->mutex);
-               if (ret < 0)
-                       return -ERESTARTSYS;
-       }
-
-       /* Check if the fwlog is still valid */
-       if (wl->fwlog_size < 0) {
-               mutex_unlock(&wl->mutex);
-               return 0;
-       }
-
-       /* Seeking is not supported - old logs are not kept. Disregard pos. */
-       len = min(count, (size_t)wl->fwlog_size);
-       wl->fwlog_size -= len;
-       memcpy(buffer, wl->fwlog, len);
-
-       /* Make room for new messages */
-       memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size);
-
-       mutex_unlock(&wl->mutex);
-
-       return len;
-}
-
-static struct bin_attribute fwlog_attr = {
-       .attr = {.name = "fwlog", .mode = S_IRUSR},
-       .read = wl1271_sysfs_read_fwlog,
-};
-
-static bool wl12xx_mac_in_fuse(struct wl1271 *wl)
-{
-       bool supported = false;
-       u8 major, minor;
-
-       if (wl->chip.id == CHIP_ID_1283_PG20) {
-               major = WL128X_PG_GET_MAJOR(wl->hw_pg_ver);
-               minor = WL128X_PG_GET_MINOR(wl->hw_pg_ver);
-
-               /* in wl128x we have the MAC address if the PG is >= (2, 1) */
-               if (major > 2 || (major == 2 && minor >= 1))
-                       supported = true;
-       } else {
-               major = WL127X_PG_GET_MAJOR(wl->hw_pg_ver);
-               minor = WL127X_PG_GET_MINOR(wl->hw_pg_ver);
-
-               /* in wl127x we have the MAC address if the PG is >= (3, 1) */
-               if (major == 3 && minor >= 1)
-                       supported = true;
-       }
-
-       wl1271_debug(DEBUG_PROBE,
-                    "PG Ver major = %d minor = %d, MAC %s present",
-                    major, minor, supported ? "is" : "is not");
-
-       return supported;
-}
-
-static void wl12xx_derive_mac_addresses(struct wl1271 *wl,
-                                       u32 oui, u32 nic, int n)
-{
-       int i;
-
-       wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x, n %d",
-                    oui, nic, n);
-
-       if (nic + n - 1 > 0xffffff)
-               wl1271_warning("NIC part of the MAC address wraps around!");
-
-       for (i = 0; i < n; i++) {
-               wl->addresses[i].addr[0] = (u8)(oui >> 16);
-               wl->addresses[i].addr[1] = (u8)(oui >> 8);
-               wl->addresses[i].addr[2] = (u8) oui;
-               wl->addresses[i].addr[3] = (u8)(nic >> 16);
-               wl->addresses[i].addr[4] = (u8)(nic >> 8);
-               wl->addresses[i].addr[5] = (u8) nic;
-               nic++;
-       }
-
-       wl->hw->wiphy->n_addresses = n;
-       wl->hw->wiphy->addresses = wl->addresses;
-}
-
-static void wl12xx_get_fuse_mac(struct wl1271 *wl)
-{
-       u32 mac1, mac2;
-
-       wl1271_set_partition(wl, &wl12xx_part_table[PART_DRPW]);
-
-       mac1 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_1);
-       mac2 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_2);
-
-       /* these are the two parts of the BD_ADDR */
-       wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
-               ((mac1 & 0xff000000) >> 24);
-       wl->fuse_nic_addr = mac1 & 0xffffff;
-
-       wl1271_set_partition(wl, &wl12xx_part_table[PART_DOWN]);
-}
-
-static int wl12xx_get_hw_info(struct wl1271 *wl)
-{
-       int ret;
-       u32 die_info;
-
-       ret = wl12xx_set_power_on(wl);
-       if (ret < 0)
-               goto out;
-
-       wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
-
-       if (wl->chip.id == CHIP_ID_1283_PG20)
-               die_info = wl1271_top_reg_read(wl, WL128X_REG_FUSE_DATA_2_1);
-       else
-               die_info = wl1271_top_reg_read(wl, WL127X_REG_FUSE_DATA_2_1);
-
-       wl->hw_pg_ver = (s8) (die_info & PG_VER_MASK) >> PG_VER_OFFSET;
-
-       if (!wl12xx_mac_in_fuse(wl)) {
-               wl->fuse_oui_addr = 0;
-               wl->fuse_nic_addr = 0;
-       } else {
-               wl12xx_get_fuse_mac(wl);
-       }
-
-       wl1271_power_off(wl);
-out:
-       return ret;
-}
-
-static int wl1271_register_hw(struct wl1271 *wl)
-{
-       int ret;
-       u32 oui_addr = 0, nic_addr = 0;
-
-       if (wl->mac80211_registered)
-               return 0;
-
-       ret = wl12xx_get_hw_info(wl);
-       if (ret < 0) {
-               wl1271_error("couldn't get hw info");
-               goto out;
-       }
-
-       ret = wl1271_fetch_nvs(wl);
-       if (ret == 0) {
-               /* NOTE: The wl->nvs->nvs element must be first, in
-                * order to simplify the casting, we assume it is at
-                * the beginning of the wl->nvs structure.
-                */
-               u8 *nvs_ptr = (u8 *)wl->nvs;
-
-               oui_addr =
-                       (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6];
-               nic_addr =
-                       (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3];
-       }
-
-       /* if the MAC address is zeroed in the NVS derive from fuse */
-       if (oui_addr == 0 && nic_addr == 0) {
-               oui_addr = wl->fuse_oui_addr;
-               /* fuse has the BD_ADDR, the WLAN addresses are the next two */
-               nic_addr = wl->fuse_nic_addr + 1;
-       }
-
-       wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr, 2);
-
-       ret = ieee80211_register_hw(wl->hw);
-       if (ret < 0) {
-               wl1271_error("unable to register mac80211 hw: %d", ret);
-               goto out;
-       }
-
-       wl->mac80211_registered = true;
-
-       wl1271_debugfs_init(wl);
-
-       wl1271_notice("loaded");
-
-out:
-       return ret;
-}
-
-static void wl1271_unregister_hw(struct wl1271 *wl)
-{
-       if (wl->plt)
-               wl1271_plt_stop(wl);
-
-       ieee80211_unregister_hw(wl->hw);
-       wl->mac80211_registered = false;
-
-}
-
-static int wl1271_init_ieee80211(struct wl1271 *wl)
-{
-       static const u32 cipher_suites[] = {
-               WLAN_CIPHER_SUITE_WEP40,
-               WLAN_CIPHER_SUITE_WEP104,
-               WLAN_CIPHER_SUITE_TKIP,
-               WLAN_CIPHER_SUITE_CCMP,
-               WL1271_CIPHER_SUITE_GEM,
-       };
-
-       /* The tx descriptor buffer and the TKIP space. */
-       wl->hw->extra_tx_headroom = WL1271_EXTRA_SPACE_TKIP +
-               sizeof(struct wl1271_tx_hw_descr);
-
-       /* unit us */
-       /* FIXME: find a proper value */
-       wl->hw->channel_change_time = 10000;
-       wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval;
-
-       wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
-               IEEE80211_HW_SUPPORTS_PS |
-               IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
-               IEEE80211_HW_SUPPORTS_UAPSD |
-               IEEE80211_HW_HAS_RATE_CONTROL |
-               IEEE80211_HW_CONNECTION_MONITOR |
-               IEEE80211_HW_REPORTS_TX_ACK_STATUS |
-               IEEE80211_HW_SPECTRUM_MGMT |
-               IEEE80211_HW_AP_LINK_PS |
-               IEEE80211_HW_AMPDU_AGGREGATION |
-               IEEE80211_HW_TX_AMPDU_SETUP_IN_HW |
-               IEEE80211_HW_SCAN_WHILE_IDLE;
-
-       wl->hw->wiphy->cipher_suites = cipher_suites;
-       wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
-
-       wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
-               BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) |
-               BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
-       wl->hw->wiphy->max_scan_ssids = 1;
-       wl->hw->wiphy->max_sched_scan_ssids = 16;
-       wl->hw->wiphy->max_match_sets = 16;
-       /*
-        * Maximum length of elements in scanning probe request templates
-        * should be the maximum length possible for a template, without
-        * the IEEE80211 header of the template
-        */
-       wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
-                       sizeof(struct ieee80211_header);
-
-       wl->hw->wiphy->max_sched_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
-               sizeof(struct ieee80211_header);
-
-       wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD |
-                               WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
-
-       /* make sure all our channels fit in the scanned_ch bitmask */
-       BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) +
-                    ARRAY_SIZE(wl1271_channels_5ghz) >
-                    WL1271_MAX_CHANNELS);
-       /*
-        * We keep local copies of the band structs because we need to
-        * modify them on a per-device basis.
-        */
-       memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
-              sizeof(wl1271_band_2ghz));
-       memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
-              sizeof(wl1271_band_5ghz));
-
-       wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
-               &wl->bands[IEEE80211_BAND_2GHZ];
-       wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
-               &wl->bands[IEEE80211_BAND_5GHZ];
-
-       wl->hw->queues = 4;
-       wl->hw->max_rates = 1;
-
-       wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
-
-       /* the FW answers probe-requests in AP-mode */
-       wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
-       wl->hw->wiphy->probe_resp_offload =
-               NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
-               NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
-               NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
-
-       SET_IEEE80211_DEV(wl->hw, wl->dev);
-
-       wl->hw->sta_data_size = sizeof(struct wl1271_station);
-       wl->hw->vif_data_size = sizeof(struct wl12xx_vif);
-
-       wl->hw->max_rx_aggregation_subframes = 8;
-
-       return 0;
-}
-
-#define WL1271_DEFAULT_CHANNEL 0
-
-static struct ieee80211_hw *wl1271_alloc_hw(void)
-{
-       struct ieee80211_hw *hw;
-       struct wl1271 *wl;
-       int i, j, ret;
-       unsigned int order;
-
-       BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS);
-
-       hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
-       if (!hw) {
-               wl1271_error("could not alloc ieee80211_hw");
-               ret = -ENOMEM;
-               goto err_hw_alloc;
-       }
-
-       wl = hw->priv;
-       memset(wl, 0, sizeof(*wl));
-
-       INIT_LIST_HEAD(&wl->wlvif_list);
-
-       wl->hw = hw;
-
-       for (i = 0; i < NUM_TX_QUEUES; i++)
-               for (j = 0; j < WL12XX_MAX_LINKS; j++)
-                       skb_queue_head_init(&wl->links[j].tx_queue[i]);
-
-       skb_queue_head_init(&wl->deferred_rx_queue);
-       skb_queue_head_init(&wl->deferred_tx_queue);
-
-       INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
-       INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
-       INIT_WORK(&wl->tx_work, wl1271_tx_work);
-       INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
-       INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
-       INIT_DELAYED_WORK(&wl->tx_watchdog_work, wl12xx_tx_watchdog_work);
-
-       wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
-       if (!wl->freezable_wq) {
-               ret = -ENOMEM;
-               goto err_hw;
-       }
-
-       wl->channel = WL1271_DEFAULT_CHANNEL;
-       wl->rx_counter = 0;
-       wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
-       wl->band = IEEE80211_BAND_2GHZ;
-       wl->flags = 0;
-       wl->sg_enabled = true;
-       wl->hw_pg_ver = -1;
-       wl->ap_ps_map = 0;
-       wl->ap_fw_ps_map = 0;
-       wl->quirks = 0;
-       wl->platform_quirks = 0;
-       wl->sched_scanning = false;
-       wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
-       wl->system_hlid = WL12XX_SYSTEM_HLID;
-       wl->active_sta_count = 0;
-       wl->fwlog_size = 0;
-       init_waitqueue_head(&wl->fwlog_waitq);
-
-       /* The system link is always allocated */
-       __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
-
-       memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
-       for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
-               wl->tx_frames[i] = NULL;
-
-       spin_lock_init(&wl->wl_lock);
-
-       wl->state = WL1271_STATE_OFF;
-       wl->fw_type = WL12XX_FW_TYPE_NONE;
-       mutex_init(&wl->mutex);
-
-       /* Apply default driver configuration. */
-       wl1271_conf_init(wl);
-
-       order = get_order(WL1271_AGGR_BUFFER_SIZE);
-       wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
-       if (!wl->aggr_buf) {
-               ret = -ENOMEM;
-               goto err_wq;
-       }
-
-       wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
-       if (!wl->dummy_packet) {
-               ret = -ENOMEM;
-               goto err_aggr;
-       }
-
-       /* Allocate one page for the FW log */
-       wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL);
-       if (!wl->fwlog) {
-               ret = -ENOMEM;
-               goto err_dummy_packet;
-       }
-
-       return hw;
-
-err_dummy_packet:
-       dev_kfree_skb(wl->dummy_packet);
-
-err_aggr:
-       free_pages((unsigned long)wl->aggr_buf, order);
-
-err_wq:
-       destroy_workqueue(wl->freezable_wq);
-
-err_hw:
-       wl1271_debugfs_exit(wl);
-       ieee80211_free_hw(hw);
-
-err_hw_alloc:
-
-       return ERR_PTR(ret);
-}
-
-static int wl1271_free_hw(struct wl1271 *wl)
-{
-       /* Unblock any fwlog readers */
-       mutex_lock(&wl->mutex);
-       wl->fwlog_size = -1;
-       wake_up_interruptible_all(&wl->fwlog_waitq);
-       mutex_unlock(&wl->mutex);
-
-       device_remove_bin_file(wl->dev, &fwlog_attr);
-
-       device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
-
-       device_remove_file(wl->dev, &dev_attr_bt_coex_state);
-       free_page((unsigned long)wl->fwlog);
-       dev_kfree_skb(wl->dummy_packet);
-       free_pages((unsigned long)wl->aggr_buf,
-                       get_order(WL1271_AGGR_BUFFER_SIZE));
-
-       wl1271_debugfs_exit(wl);
-
-       vfree(wl->fw);
-       wl->fw = NULL;
-       wl->fw_type = WL12XX_FW_TYPE_NONE;
-       kfree(wl->nvs);
-       wl->nvs = NULL;
-
-       kfree(wl->fw_status);
-       kfree(wl->tx_res_if);
-       destroy_workqueue(wl->freezable_wq);
-
-       ieee80211_free_hw(wl->hw);
-
-       return 0;
-}
-
-static irqreturn_t wl12xx_hardirq(int irq, void *cookie)
-{
-       struct wl1271 *wl = cookie;
-       unsigned long flags;
-
-       wl1271_debug(DEBUG_IRQ, "IRQ");
-
-       /* complete the ELP completion */
-       spin_lock_irqsave(&wl->wl_lock, flags);
-       set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
-       if (wl->elp_compl) {
-               complete(wl->elp_compl);
-               wl->elp_compl = NULL;
-       }
-
-       if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
-               /* don't enqueue a work right now. mark it as pending */
-               set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
-               wl1271_debug(DEBUG_IRQ, "should not enqueue work");
-               disable_irq_nosync(wl->irq);
-               pm_wakeup_event(wl->dev, 0);
-               spin_unlock_irqrestore(&wl->wl_lock, flags);
-               return IRQ_HANDLED;
-       }
-       spin_unlock_irqrestore(&wl->wl_lock, flags);
-
-       return IRQ_WAKE_THREAD;
-}
-
-static int __devinit wl12xx_probe(struct platform_device *pdev)
-{
-       struct wl12xx_platform_data *pdata = pdev->dev.platform_data;
-       struct ieee80211_hw *hw;
-       struct wl1271 *wl;
-       unsigned long irqflags;
-       int ret = -ENODEV;
-
-       hw = wl1271_alloc_hw();
-       if (IS_ERR(hw)) {
-               wl1271_error("can't allocate hw");
-               ret = PTR_ERR(hw);
-               goto out;
-       }
-
-       wl = hw->priv;
-       wl->irq = platform_get_irq(pdev, 0);
-       wl->ref_clock = pdata->board_ref_clock;
-       wl->tcxo_clock = pdata->board_tcxo_clock;
-       wl->platform_quirks = pdata->platform_quirks;
-       wl->set_power = pdata->set_power;
-       wl->dev = &pdev->dev;
-       wl->if_ops = pdata->ops;
-
-       platform_set_drvdata(pdev, wl);
-
-       if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
-               irqflags = IRQF_TRIGGER_RISING;
-       else
-               irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
-
-       ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq,
-                                  irqflags,
-                                  pdev->name, wl);
-       if (ret < 0) {
-               wl1271_error("request_irq() failed: %d", ret);
-               goto out_free_hw;
-       }
-
-       ret = enable_irq_wake(wl->irq);
-       if (!ret) {
-               wl->irq_wake_enabled = true;
-               device_init_wakeup(wl->dev, 1);
-               if (pdata->pwr_in_suspend)
-                       hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
-
-       }
-       disable_irq(wl->irq);
-
-       ret = wl1271_init_ieee80211(wl);
-       if (ret)
-               goto out_irq;
-
-       ret = wl1271_register_hw(wl);
-       if (ret)
-               goto out_irq;
-
-       /* Create sysfs file to control bt coex state */
-       ret = device_create_file(wl->dev, &dev_attr_bt_coex_state);
-       if (ret < 0) {
-               wl1271_error("failed to create sysfs file bt_coex_state");
-               goto out_irq;
-       }
-
-       /* Create sysfs file to get HW PG version */
-       ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver);
-       if (ret < 0) {
-               wl1271_error("failed to create sysfs file hw_pg_ver");
-               goto out_bt_coex_state;
-       }
-
-       /* Create sysfs file for the FW log */
-       ret = device_create_bin_file(wl->dev, &fwlog_attr);
-       if (ret < 0) {
-               wl1271_error("failed to create sysfs file fwlog");
-               goto out_hw_pg_ver;
-       }
-
-       return 0;
-
-out_hw_pg_ver:
-       device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
-
-out_bt_coex_state:
-       device_remove_file(wl->dev, &dev_attr_bt_coex_state);
-
-out_irq:
-       free_irq(wl->irq, wl);
-
-out_free_hw:
-       wl1271_free_hw(wl);
-
-out:
-       return ret;
-}
-
-static int __devexit wl12xx_remove(struct platform_device *pdev)
-{
-       struct wl1271 *wl = platform_get_drvdata(pdev);
-
-       if (wl->irq_wake_enabled) {
-               device_init_wakeup(wl->dev, 0);
-               disable_irq_wake(wl->irq);
-       }
-       wl1271_unregister_hw(wl);
-       free_irq(wl->irq, wl);
-       wl1271_free_hw(wl);
-
-       return 0;
-}
-
-static const struct platform_device_id wl12xx_id_table[] __devinitconst = {
-       { "wl12xx", 0 },
-       {  } /* Terminating Entry */
-};
-MODULE_DEVICE_TABLE(platform, wl12xx_id_table);
-
-static struct platform_driver wl12xx_driver = {
-       .probe          = wl12xx_probe,
-       .remove         = __devexit_p(wl12xx_remove),
-       .id_table       = wl12xx_id_table,
-       .driver = {
-               .name   = "wl12xx_driver",
-               .owner  = THIS_MODULE,
-       }
-};
-
-static int __init wl12xx_init(void)
-{
-       return platform_driver_register(&wl12xx_driver);
-}
-module_init(wl12xx_init);
-
-static void __exit wl12xx_exit(void)
-{
-       platform_driver_unregister(&wl12xx_driver);
-}
-module_exit(wl12xx_exit);
-
-u32 wl12xx_debug_level = DEBUG_NONE;
-EXPORT_SYMBOL_GPL(wl12xx_debug_level);
-module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
-MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
-
-module_param_named(fwlog, fwlog_param, charp, 0);
-MODULE_PARM_DESC(fwlog,
-                "FW logger options: continuous, ondemand, dbgpins or disable");
-
-module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR);
-MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery");
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
-MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
diff --git a/drivers/net/wireless/wl12xx/ps.c b/drivers/net/wireless/wl12xx/ps.c
deleted file mode 100644 (file)
index 78f598b..0000000
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2008-2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include "reg.h"
-#include "ps.h"
-#include "io.h"
-#include "tx.h"
-#include "debug.h"
-
-#define WL1271_WAKEUP_TIMEOUT 500
-
-void wl1271_elp_work(struct work_struct *work)
-{
-       struct delayed_work *dwork;
-       struct wl1271 *wl;
-       struct wl12xx_vif *wlvif;
-
-       dwork = container_of(work, struct delayed_work, work);
-       wl = container_of(dwork, struct wl1271, elp_work);
-
-       wl1271_debug(DEBUG_PSM, "elp work");
-
-       mutex_lock(&wl->mutex);
-
-       if (unlikely(wl->state == WL1271_STATE_OFF))
-               goto out;
-
-       /* our work might have been already cancelled */
-       if (unlikely(!test_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags)))
-               goto out;
-
-       if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags))
-               goto out;
-
-       wl12xx_for_each_wlvif(wl, wlvif) {
-               if (wlvif->bss_type == BSS_TYPE_AP_BSS)
-                       goto out;
-
-               if (!test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags) &&
-                   test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags))
-                       goto out;
-       }
-
-       wl1271_debug(DEBUG_PSM, "chip to elp");
-       wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
-       set_bit(WL1271_FLAG_IN_ELP, &wl->flags);
-
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-/* Routines to toggle sleep mode while in ELP */
-void wl1271_ps_elp_sleep(struct wl1271 *wl)
-{
-       struct wl12xx_vif *wlvif;
-
-       /* we shouldn't get consecutive sleep requests */
-       if (WARN_ON(test_and_set_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags)))
-               return;
-
-       wl12xx_for_each_wlvif(wl, wlvif) {
-               if (wlvif->bss_type == BSS_TYPE_AP_BSS)
-                       return;
-
-               if (!test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags) &&
-                   test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags))
-                       return;
-       }
-
-       ieee80211_queue_delayed_work(wl->hw, &wl->elp_work,
-               msecs_to_jiffies(wl->conf.conn.dynamic_ps_timeout));
-}
-
-int wl1271_ps_elp_wakeup(struct wl1271 *wl)
-{
-       DECLARE_COMPLETION_ONSTACK(compl);
-       unsigned long flags;
-       int ret;
-       u32 start_time = jiffies;
-       bool pending = false;
-
-       /*
-        * we might try to wake up even if we didn't go to sleep
-        * before (e.g. on boot)
-        */
-       if (!test_and_clear_bit(WL1271_FLAG_ELP_REQUESTED, &wl->flags))
-               return 0;
-
-       /* don't cancel_sync as it might contend for a mutex and deadlock */
-       cancel_delayed_work(&wl->elp_work);
-
-       if (!test_bit(WL1271_FLAG_IN_ELP, &wl->flags))
-               return 0;
-
-       wl1271_debug(DEBUG_PSM, "waking up chip from elp");
-
-       /*
-        * The spinlock is required here to synchronize both the work and
-        * the completion variable in one entity.
-        */
-       spin_lock_irqsave(&wl->wl_lock, flags);
-       if (test_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags))
-               pending = true;
-       else
-               wl->elp_compl = &compl;
-       spin_unlock_irqrestore(&wl->wl_lock, flags);
-
-       wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
-
-       if (!pending) {
-               ret = wait_for_completion_timeout(
-                       &compl, msecs_to_jiffies(WL1271_WAKEUP_TIMEOUT));
-               if (ret == 0) {
-                       wl1271_error("ELP wakeup timeout!");
-                       wl12xx_queue_recovery_work(wl);
-                       ret = -ETIMEDOUT;
-                       goto err;
-               } else if (ret < 0) {
-                       wl1271_error("ELP wakeup completion error.");
-                       goto err;
-               }
-       }
-
-       clear_bit(WL1271_FLAG_IN_ELP, &wl->flags);
-
-       wl1271_debug(DEBUG_PSM, "wakeup time: %u ms",
-                    jiffies_to_msecs(jiffies - start_time));
-       goto out;
-
-err:
-       spin_lock_irqsave(&wl->wl_lock, flags);
-       wl->elp_compl = NULL;
-       spin_unlock_irqrestore(&wl->wl_lock, flags);
-       return ret;
-
-out:
-       return 0;
-}
-
-int wl1271_ps_set_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                      enum wl1271_cmd_ps_mode mode)
-{
-       int ret;
-       u16 timeout = wl->conf.conn.dynamic_ps_timeout;
-
-       switch (mode) {
-       case STATION_AUTO_PS_MODE:
-       case STATION_POWER_SAVE_MODE:
-               wl1271_debug(DEBUG_PSM, "entering psm (mode=%d,timeout=%u)",
-                            mode, timeout);
-
-               ret = wl1271_acx_wake_up_conditions(wl, wlvif,
-                                           wl->conf.conn.wake_up_event,
-                                           wl->conf.conn.listen_interval);
-               if (ret < 0) {
-                       wl1271_error("couldn't set wake up conditions");
-                       return ret;
-               }
-
-               ret = wl1271_cmd_ps_mode(wl, wlvif, mode, timeout);
-               if (ret < 0)
-                       return ret;
-
-               set_bit(WLVIF_FLAG_IN_PS, &wlvif->flags);
-
-               /* enable beacon early termination. Not relevant for 5GHz */
-               if (wlvif->band == IEEE80211_BAND_2GHZ) {
-                       ret = wl1271_acx_bet_enable(wl, wlvif, true);
-                       if (ret < 0)
-                               return ret;
-               }
-               break;
-       case STATION_ACTIVE_MODE:
-               wl1271_debug(DEBUG_PSM, "leaving psm");
-
-               /* disable beacon early termination */
-               if (wlvif->band == IEEE80211_BAND_2GHZ) {
-                       ret = wl1271_acx_bet_enable(wl, wlvif, false);
-                       if (ret < 0)
-                               return ret;
-               }
-
-               ret = wl1271_cmd_ps_mode(wl, wlvif, mode, 0);
-               if (ret < 0)
-                       return ret;
-
-               clear_bit(WLVIF_FLAG_IN_PS, &wlvif->flags);
-               break;
-       default:
-               wl1271_warning("trying to set ps to unsupported mode %d", mode);
-               ret = -EINVAL;
-       }
-
-       return ret;
-}
-
-static void wl1271_ps_filter_frames(struct wl1271 *wl, u8 hlid)
-{
-       int i;
-       struct sk_buff *skb;
-       struct ieee80211_tx_info *info;
-       unsigned long flags;
-       int filtered[NUM_TX_QUEUES];
-
-       /* filter all frames currently in the low level queues for this hlid */
-       for (i = 0; i < NUM_TX_QUEUES; i++) {
-               filtered[i] = 0;
-               while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) {
-                       filtered[i]++;
-
-                       if (WARN_ON(wl12xx_is_dummy_packet(wl, skb)))
-                               continue;
-
-                       info = IEEE80211_SKB_CB(skb);
-                       info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
-                       info->status.rates[0].idx = -1;
-                       ieee80211_tx_status_ni(wl->hw, skb);
-               }
-       }
-
-       spin_lock_irqsave(&wl->wl_lock, flags);
-       for (i = 0; i < NUM_TX_QUEUES; i++)
-               wl->tx_queue_count[i] -= filtered[i];
-       spin_unlock_irqrestore(&wl->wl_lock, flags);
-
-       wl1271_handle_tx_low_watermark(wl);
-}
-
-void wl12xx_ps_link_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                         u8 hlid, bool clean_queues)
-{
-       struct ieee80211_sta *sta;
-       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-
-       if (test_bit(hlid, &wl->ap_ps_map))
-               return;
-
-       wl1271_debug(DEBUG_PSM, "start mac80211 PSM on hlid %d pkts %d "
-                    "clean_queues %d", hlid, wl->links[hlid].allocated_pkts,
-                    clean_queues);
-
-       rcu_read_lock();
-       sta = ieee80211_find_sta(vif, wl->links[hlid].addr);
-       if (!sta) {
-               wl1271_error("could not find sta %pM for starting ps",
-                            wl->links[hlid].addr);
-               rcu_read_unlock();
-               return;
-       }
-
-       ieee80211_sta_ps_transition_ni(sta, true);
-       rcu_read_unlock();
-
-       /* do we want to filter all frames from this link's queues? */
-       if (clean_queues)
-               wl1271_ps_filter_frames(wl, hlid);
-
-       __set_bit(hlid, &wl->ap_ps_map);
-}
-
-void wl12xx_ps_link_end(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
-{
-       struct ieee80211_sta *sta;
-       struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
-
-       if (!test_bit(hlid, &wl->ap_ps_map))
-               return;
-
-       wl1271_debug(DEBUG_PSM, "end mac80211 PSM on hlid %d", hlid);
-
-       __clear_bit(hlid, &wl->ap_ps_map);
-
-       rcu_read_lock();
-       sta = ieee80211_find_sta(vif, wl->links[hlid].addr);
-       if (!sta) {
-               wl1271_error("could not find sta %pM for ending ps",
-                            wl->links[hlid].addr);
-               goto end;
-       }
-
-       ieee80211_sta_ps_transition_ni(sta, false);
-end:
-       rcu_read_unlock();
-}
diff --git a/drivers/net/wireless/wl12xx/ps.h b/drivers/net/wireless/wl12xx/ps.h
deleted file mode 100644 (file)
index 5f19d4f..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2008-2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __PS_H__
-#define __PS_H__
-
-#include "wl12xx.h"
-#include "acx.h"
-
-int wl1271_ps_set_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                      enum wl1271_cmd_ps_mode mode);
-void wl1271_ps_elp_sleep(struct wl1271 *wl);
-int wl1271_ps_elp_wakeup(struct wl1271 *wl);
-void wl1271_elp_work(struct work_struct *work);
-void wl12xx_ps_link_start(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                         u8 hlid, bool clean_queues);
-void wl12xx_ps_link_end(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid);
-
-#define WL1271_PS_COMPLETE_TIMEOUT 500
-
-#endif /* __WL1271_PS_H__ */
diff --git a/drivers/net/wireless/wl12xx/reg.h b/drivers/net/wireless/wl12xx/reg.h
deleted file mode 100644 (file)
index 340db32..0000000
+++ /dev/null
@@ -1,555 +0,0 @@
-/*
- * This file is part of wl12xx
- *
- * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
- * Copyright (C) 2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __REG_H__
-#define __REG_H__
-
-#include <linux/bitops.h>
-
-#define REGISTERS_BASE 0x00300000
-#define DRPW_BASE      0x00310000
-
-#define REGISTERS_DOWN_SIZE 0x00008800
-#define REGISTERS_WORK_SIZE 0x0000b000
-
-#define HW_ACCESS_ELP_CTRL_REG_ADDR         0x1FFFC
-#define FW_STATUS_ADDR                      (0x14FC0 + 0xA000)
-
-/* ELP register commands */
-#define ELPCTRL_WAKE_UP             0x1
-#define ELPCTRL_WAKE_UP_WLAN_READY  0x5
-#define ELPCTRL_SLEEP               0x0
-/* ELP WLAN_READY bit */
-#define ELPCTRL_WLAN_READY          0x2
-
-/*===============================================
-   Host Software Reset - 32bit RW
- ------------------------------------------
-    [31:1] Reserved
-    0  SOFT_RESET Soft Reset  - When this bit is set,
-    it holds the Wlan hardware in a soft reset state.
-    This reset disables all MAC and baseband processor
-    clocks except the CardBus/PCI interface clock.
-    It also initializes all MAC state machines except
-    the host interface. It does not reload the
-    contents of the EEPROM. When this bit is cleared
-    (not self-clearing), the Wlan hardware
-    exits the software reset state.
-===============================================*/
-#define ACX_REG_SLV_SOFT_RESET         (REGISTERS_BASE + 0x0000)
-
-#define WL1271_SLV_REG_DATA            (REGISTERS_BASE + 0x0008)
-#define WL1271_SLV_REG_ADATA           (REGISTERS_BASE + 0x000c)
-#define WL1271_SLV_MEM_DATA            (REGISTERS_BASE + 0x0018)
-
-#define ACX_REG_INTERRUPT_TRIG         (REGISTERS_BASE + 0x0474)
-#define ACX_REG_INTERRUPT_TRIG_H       (REGISTERS_BASE + 0x0478)
-
-/*=============================================
-  Host Interrupt Mask Register - 32bit (RW)
-  ------------------------------------------
-  Setting a bit in this register masks the
-  corresponding interrupt to the host.
-  0 - RX0              - Rx first dubble buffer Data Interrupt
-  1 - TXD              - Tx Data Interrupt
-  2 - TXXFR            - Tx Transfer Interrupt
-  3 - RX1              - Rx second dubble buffer Data Interrupt
-  4 - RXXFR            - Rx Transfer Interrupt
-  5 - EVENT_A  - Event Mailbox interrupt
-  6 - EVENT_B  - Event Mailbox interrupt
-  7 - WNONHST  - Wake On Host Interrupt
-  8 - TRACE_A  - Debug Trace interrupt
-  9 - TRACE_B  - Debug Trace interrupt
- 10 - CDCMP            - Command Complete Interrupt
- 11 -
- 12 -
- 13 -
- 14 - ICOMP            - Initialization Complete Interrupt
- 16 - SG SE            - Soft Gemini - Sense enable interrupt
- 17 - SG SD            - Soft Gemini - Sense disable interrupt
- 18 -                  -
- 19 -                  -
- 20 -                  -
- 21-                   -
- Default: 0x0001
-*==============================================*/
-#define ACX_REG_INTERRUPT_MASK         (REGISTERS_BASE + 0x04DC)
-
-/*=============================================
-  Host Interrupt Mask Set 16bit, (Write only)
-  ------------------------------------------
- Setting a bit in this register sets
- the corresponding bin in ACX_HINT_MASK register
- without effecting the mask
- state of other bits (0 = no effect).
-==============================================*/
-#define ACX_REG_HINT_MASK_SET          (REGISTERS_BASE + 0x04E0)
-
-/*=============================================
-  Host Interrupt Mask Clear 16bit,(Write only)
-  ------------------------------------------
- Setting a bit in this register clears
- the corresponding bin in ACX_HINT_MASK register
- without effecting the mask
- state of other bits (0 = no effect).
-=============================================*/
-#define ACX_REG_HINT_MASK_CLR          (REGISTERS_BASE + 0x04E4)
-
-/*=============================================
-  Host Interrupt Status Nondestructive Read
-  16bit,(Read only)
-  ------------------------------------------
- The host can read this register to determine
- which interrupts are active.
- Reading this register doesn't
- effect its content.
-=============================================*/
-#define ACX_REG_INTERRUPT_NO_CLEAR     (REGISTERS_BASE + 0x04E8)
-
-/*=============================================
-  Host Interrupt Status Clear on Read  Register
-  16bit,(Read only)
-  ------------------------------------------
- The host can read this register to determine
- which interrupts are active.
- Reading this register clears it,
- thus making all interrupts inactive.
-==============================================*/
-#define ACX_REG_INTERRUPT_CLEAR        (REGISTERS_BASE + 0x04F8)
-
-/*=============================================
-  Host Interrupt Acknowledge Register
-  16bit,(Write only)
-  ------------------------------------------
- The host can set individual bits in this
- register to clear (acknowledge) the corresp.
- interrupt status bits in the HINT_STS_CLR and
- HINT_STS_ND registers, thus making the
- assotiated interrupt inactive. (0-no effect)
-==============================================*/
-#define ACX_REG_INTERRUPT_ACK          (REGISTERS_BASE + 0x04F0)
-
-#define RX_DRIVER_COUNTER_ADDRESS      (REGISTERS_BASE + 0x0538)
-
-/* Device Configuration registers*/
-#define SOR_CFG                        (REGISTERS_BASE + 0x0800)
-
-/* Embedded ARM CPU Control */
-
-/*===============================================
- Halt eCPU   - 32bit RW
- ------------------------------------------
- 0 HALT_ECPU Halt Embedded CPU - This bit is the
- compliment of bit 1 (MDATA2) in the SOR_CFG register.
- During a hardware reset, this bit holds
- the inverse of MDATA2.
- When downloading firmware from the host,
- set this bit (pull down MDATA2).
- The host clears this bit after downloading the firmware into
- zero-wait-state SSRAM.
- When loading firmware from Flash, clear this bit (pull up MDATA2)
- so that the eCPU can run the bootloader code in Flash
- HALT_ECPU eCPU State
- --------------------
- 1 halt eCPU
- 0 enable eCPU
- ===============================================*/
-#define ACX_REG_ECPU_CONTROL           (REGISTERS_BASE + 0x0804)
-
-#define HI_CFG                         (REGISTERS_BASE + 0x0808)
-
-/*===============================================
- EEPROM Burst Read Start  - 32bit RW
- ------------------------------------------
- [31:1] Reserved
- 0  ACX_EE_START -  EEPROM Burst Read Start 0
- Setting this bit starts a burst read from
- the external EEPROM.
- If this bit is set (after reset) before an EEPROM read/write,
- the burst read starts at EEPROM address 0.
- Otherwise, it starts at the address
- following the address of the previous access.
- TheWlan hardware hardware clears this bit automatically.
-
- Default: 0x00000000
-*================================================*/
-#define ACX_REG_EE_START               (REGISTERS_BASE + 0x080C)
-
-#define OCP_POR_CTR                    (REGISTERS_BASE + 0x09B4)
-#define OCP_DATA_WRITE                 (REGISTERS_BASE + 0x09B8)
-#define OCP_DATA_READ                  (REGISTERS_BASE + 0x09BC)
-#define OCP_CMD                        (REGISTERS_BASE + 0x09C0)
-
-#define WL1271_HOST_WR_ACCESS          (REGISTERS_BASE + 0x09F8)
-
-#define CHIP_ID_B                      (REGISTERS_BASE + 0x5674)
-
-#define CHIP_ID_1271_PG10              (0x4030101)
-#define CHIP_ID_1271_PG20              (0x4030111)
-#define CHIP_ID_1283_PG10              (0x05030101)
-#define CHIP_ID_1283_PG20              (0x05030111)
-
-#define ENABLE                         (REGISTERS_BASE + 0x5450)
-
-/* Power Management registers */
-#define ELP_CFG_MODE                   (REGISTERS_BASE + 0x5804)
-#define ELP_CMD                        (REGISTERS_BASE + 0x5808)
-#define PLL_CAL_TIME                   (REGISTERS_BASE + 0x5810)
-#define CLK_REQ_TIME                   (REGISTERS_BASE + 0x5814)
-#define CLK_BUF_TIME                   (REGISTERS_BASE + 0x5818)
-
-#define CFG_PLL_SYNC_CNT               (REGISTERS_BASE + 0x5820)
-
-/* Scratch Pad registers*/
-#define SCR_PAD0                       (REGISTERS_BASE + 0x5608)
-#define SCR_PAD1                       (REGISTERS_BASE + 0x560C)
-#define SCR_PAD2                       (REGISTERS_BASE + 0x5610)
-#define SCR_PAD3                       (REGISTERS_BASE + 0x5614)
-#define SCR_PAD4                       (REGISTERS_BASE + 0x5618)
-#define SCR_PAD4_SET                   (REGISTERS_BASE + 0x561C)
-#define SCR_PAD4_CLR                   (REGISTERS_BASE + 0x5620)
-#define SCR_PAD5                       (REGISTERS_BASE + 0x5624)
-#define SCR_PAD5_SET                   (REGISTERS_BASE + 0x5628)
-#define SCR_PAD5_CLR                   (REGISTERS_BASE + 0x562C)
-#define SCR_PAD6                       (REGISTERS_BASE + 0x5630)
-#define SCR_PAD7                       (REGISTERS_BASE + 0x5634)
-#define SCR_PAD8                       (REGISTERS_BASE + 0x5638)
-#define SCR_PAD9                       (REGISTERS_BASE + 0x563C)
-
-/* Spare registers*/
-#define SPARE_A1                       (REGISTERS_BASE + 0x0994)
-#define SPARE_A2                       (REGISTERS_BASE + 0x0998)
-#define SPARE_A3                       (REGISTERS_BASE + 0x099C)
-#define SPARE_A4                       (REGISTERS_BASE + 0x09A0)
-#define SPARE_A5                       (REGISTERS_BASE + 0x09A4)
-#define SPARE_A6                       (REGISTERS_BASE + 0x09A8)
-#define SPARE_A7                       (REGISTERS_BASE + 0x09AC)
-#define SPARE_A8                       (REGISTERS_BASE + 0x09B0)
-#define SPARE_B1                       (REGISTERS_BASE + 0x5420)
-#define SPARE_B2                       (REGISTERS_BASE + 0x5424)
-#define SPARE_B3                       (REGISTERS_BASE + 0x5428)
-#define SPARE_B4                       (REGISTERS_BASE + 0x542C)
-#define SPARE_B5                       (REGISTERS_BASE + 0x5430)
-#define SPARE_B6                       (REGISTERS_BASE + 0x5434)
-#define SPARE_B7                       (REGISTERS_BASE + 0x5438)
-#define SPARE_B8                       (REGISTERS_BASE + 0x543C)
-
-#define PLL_PARAMETERS                 (REGISTERS_BASE + 0x6040)
-#define WU_COUNTER_PAUSE               (REGISTERS_BASE + 0x6008)
-#define WELP_ARM_COMMAND               (REGISTERS_BASE + 0x6100)
-#define DRPW_SCRATCH_START             (DRPW_BASE + 0x002C)
-
-
-#define ACX_SLV_SOFT_RESET_BIT   BIT(1)
-#define ACX_REG_EEPROM_START_BIT BIT(1)
-
-/* Command/Information Mailbox Pointers */
-
-/*===============================================
-  Command Mailbox Pointer - 32bit RW
- ------------------------------------------
- This register holds the start address of
- the command mailbox located in the Wlan hardware memory.
- The host must read this pointer after a reset to
- find the location of the command mailbox.
- The Wlan hardware initializes the command mailbox
- pointer with the default address of the command mailbox.
- The command mailbox pointer is not valid until after
- the host receives the Init Complete interrupt from
- the Wlan hardware.
- ===============================================*/
-#define REG_COMMAND_MAILBOX_PTR                                (SCR_PAD0)
-
-/*===============================================
-  Information Mailbox Pointer - 32bit RW
- ------------------------------------------
- This register holds the start address of
- the information mailbox located in the Wlan hardware memory.
- The host must read this pointer after a reset to find
- the location of the information mailbox.
- The Wlan hardware initializes the information mailbox pointer
- with the default address of the information mailbox.
- The information mailbox pointer is not valid
- until after the host receives the Init Complete interrupt from
- the Wlan hardware.
- ===============================================*/
-#define REG_EVENT_MAILBOX_PTR                          (SCR_PAD1)
-
-/*===============================================
- EEPROM Read/Write Request 32bit RW
- ------------------------------------------
- 1 EE_READ - EEPROM Read Request 1 - Setting this bit
- loads a single byte of data into the EE_DATA
- register from the EEPROM location specified in
- the EE_ADDR register.
- The Wlan hardware hardware clears this bit automatically.
- EE_DATA is valid when this bit is cleared.
-
- 0 EE_WRITE  - EEPROM Write Request  - Setting this bit
- writes a single byte of data from the EE_DATA register into the
- EEPROM location specified in the EE_ADDR register.
- The Wlan hardware hardware clears this bit automatically.
-*===============================================*/
-#define ACX_EE_CTL_REG                      EE_CTL
-#define EE_WRITE                            0x00000001ul
-#define EE_READ                             0x00000002ul
-
-/*===============================================
-  EEPROM Address  - 32bit RW
-  ------------------------------------------
-  This register specifies the address
-  within the EEPROM from/to which to read/write data.
-  ===============================================*/
-#define ACX_EE_ADDR_REG                     EE_ADDR
-
-/*===============================================
-  EEPROM Data  - 32bit RW
-  ------------------------------------------
-  This register either holds the read 8 bits of
-  data from the EEPROM or the write data
-  to be written to the EEPROM.
-  ===============================================*/
-#define ACX_EE_DATA_REG                     EE_DATA
-
-/*===============================================
-  EEPROM Base Address  - 32bit RW
-  ------------------------------------------
-  This register holds the upper nine bits
-  [23:15] of the 24-bit Wlan hardware memory
-  address for burst reads from EEPROM accesses.
-  The EEPROM provides the lower 15 bits of this address.
-  The MSB of the address from the EEPROM is ignored.
-  ===============================================*/
-#define ACX_EE_CFG                          EE_CFG
-
-/*===============================================
-  GPIO Output Values  -32bit, RW
-  ------------------------------------------
-  [31:16]  Reserved
-  [15: 0]  Specify the output values (at the output driver inputs) for
-  GPIO[15:0], respectively.
-  ===============================================*/
-#define ACX_GPIO_OUT_REG            GPIO_OUT
-#define ACX_MAX_GPIO_LINES          15
-
-/*===============================================
-  Contention window  -32bit, RW
-  ------------------------------------------
-  [31:26]  Reserved
-  [25:16]  Max (0x3ff)
-  [15:07]  Reserved
-  [06:00]  Current contention window value - default is 0x1F
-  ===============================================*/
-#define ACX_CONT_WIND_CFG_REG    CONT_WIND_CFG
-#define ACX_CONT_WIND_MIN_MASK   0x0000007f
-#define ACX_CONT_WIND_MAX        0x03ff0000
-
-/*===============================================
-  HI_CFG Interface Configuration Register Values
-  ------------------------------------------
-  ===============================================*/
-#define HI_CFG_UART_ENABLE          0x00000004
-#define HI_CFG_RST232_ENABLE        0x00000008
-#define HI_CFG_CLOCK_REQ_SELECT     0x00000010
-#define HI_CFG_HOST_INT_ENABLE      0x00000020
-#define HI_CFG_VLYNQ_OUTPUT_ENABLE  0x00000040
-#define HI_CFG_HOST_INT_ACTIVE_LOW  0x00000080
-#define HI_CFG_UART_TX_OUT_GPIO_15  0x00000100
-#define HI_CFG_UART_TX_OUT_GPIO_14  0x00000200
-#define HI_CFG_UART_TX_OUT_GPIO_7   0x00000400
-
-#define HI_CFG_DEF_VAL              \
-       (HI_CFG_UART_ENABLE |        \
-       HI_CFG_RST232_ENABLE |      \
-       HI_CFG_CLOCK_REQ_SELECT |   \
-       HI_CFG_HOST_INT_ENABLE)
-
-#define REF_FREQ_19_2                       0
-#define REF_FREQ_26_0                       1
-#define REF_FREQ_38_4                       2
-#define REF_FREQ_40_0                       3
-#define REF_FREQ_33_6                       4
-#define REF_FREQ_NUM                        5
-
-#define LUT_PARAM_INTEGER_DIVIDER           0
-#define LUT_PARAM_FRACTIONAL_DIVIDER        1
-#define LUT_PARAM_ATTN_BB                   2
-#define LUT_PARAM_ALPHA_BB                  3
-#define LUT_PARAM_STOP_TIME_BB              4
-#define LUT_PARAM_BB_PLL_LOOP_FILTER        5
-#define LUT_PARAM_NUM                       6
-
-#define ACX_EEPROMLESS_IND_REG              (SCR_PAD4)
-#define USE_EEPROM                          0
-#define SOFT_RESET_MAX_TIME                 1000000
-#define SOFT_RESET_STALL_TIME               1000
-#define NVS_DATA_BUNDARY_ALIGNMENT          4
-
-
-/* Firmware image load chunk size */
-#define CHUNK_SIZE     16384
-
-/* Firmware image header size */
-#define FW_HDR_SIZE 8
-
-#define ECPU_CONTROL_HALT                                      0x00000101
-
-
-/******************************************************************************
-
-    CHANNELS, BAND & REG DOMAINS definitions
-
-******************************************************************************/
-
-
-enum {
-       RADIO_BAND_2_4GHZ = 0,  /* 2.4 Ghz band */
-       RADIO_BAND_5GHZ = 1,    /* 5 Ghz band */
-       RADIO_BAND_JAPAN_4_9_GHZ = 2,
-       DEFAULT_BAND = RADIO_BAND_2_4GHZ,
-       INVALID_BAND = 0xFE,
-       MAX_RADIO_BANDS = 0xFF
-};
-
-#define SHORT_PREAMBLE_BIT   BIT(0) /* CCK or Barker depending on the rate */
-#define OFDM_RATE_BIT        BIT(6)
-#define PBCC_RATE_BIT        BIT(7)
-
-enum {
-       CCK_LONG = 0,
-       CCK_SHORT = SHORT_PREAMBLE_BIT,
-       PBCC_LONG = PBCC_RATE_BIT,
-       PBCC_SHORT = PBCC_RATE_BIT | SHORT_PREAMBLE_BIT,
-       OFDM = OFDM_RATE_BIT
-};
-
-/******************************************************************************
-
-Transmit-Descriptor RATE-SET field definitions...
-
-Define a new "Rate-Set" for TX path that incorporates the
-Rate & Modulation info into a single 16-bit field.
-
-TxdRateSet_t:
-b15   - Indicates Preamble type (1=SHORT, 0=LONG).
-       Notes:
-       Must be LONG (0) for 1Mbps rate.
-       Does not apply (set to 0) for RevG-OFDM rates.
-b14   - Indicates PBCC encoding (1=PBCC, 0=not).
-       Notes:
-       Does not apply (set to 0) for rates 1 and 2 Mbps.
-       Does not apply (set to 0) for RevG-OFDM rates.
-b13    - Unused (set to 0).
-b12-b0 - Supported Rate indicator bits as defined below.
-
-******************************************************************************/
-
-
-/*************************************************************************
-
-    Interrupt Trigger Register (Host -> WiLink)
-
-**************************************************************************/
-
-/* Hardware to Embedded CPU Interrupts - first 32-bit register set */
-
-/*
- * Host Command Interrupt. Setting this bit masks
- * the interrupt that the host issues to inform
- * the FW that it has sent a command
- * to the Wlan hardware Command Mailbox.
- */
-#define INTR_TRIG_CMD       BIT(0)
-
-/*
- * Host Event Acknowlegde Interrupt. The host
- * sets this bit to acknowledge that it received
- * the unsolicited information from the event
- * mailbox.
- */
-#define INTR_TRIG_EVENT_ACK BIT(1)
-
-/*
- * The host sets this bit to inform the Wlan
- * FW that a TX packet is in the XFER
- * Buffer #0.
- */
-#define INTR_TRIG_TX_PROC0 BIT(2)
-
-/*
- * The host sets this bit to inform the FW
- * that it read a packet from RX XFER
- * Buffer #0.
- */
-#define INTR_TRIG_RX_PROC0 BIT(3)
-
-#define INTR_TRIG_DEBUG_ACK BIT(4)
-
-#define INTR_TRIG_STATE_CHANGED BIT(5)
-
-
-/* Hardware to Embedded CPU Interrupts - second 32-bit register set */
-
-/*
- * The host sets this bit to inform the FW
- * that it read a packet from RX XFER
- * Buffer #1.
- */
-#define INTR_TRIG_RX_PROC1 BIT(17)
-
-/*
- * The host sets this bit to inform the Wlan
- * hardware that a TX packet is in the XFER
- * Buffer #1.
- */
-#define INTR_TRIG_TX_PROC1 BIT(18)
-
-#define WL127X_REG_FUSE_DATA_2_1       0x050a
-#define WL128X_REG_FUSE_DATA_2_1       0x2152
-#define PG_VER_MASK                    0x3c
-#define PG_VER_OFFSET                  2
-
-#define WL127X_PG_MAJOR_VER_MASK       0x3
-#define WL127X_PG_MAJOR_VER_OFFSET     0x0
-#define WL127X_PG_MINOR_VER_MASK       0xc
-#define WL127X_PG_MINOR_VER_OFFSET     0x2
-
-#define WL128X_PG_MAJOR_VER_MASK       0xc
-#define WL128X_PG_MAJOR_VER_OFFSET     0x2
-#define WL128X_PG_MINOR_VER_MASK       0x3
-#define WL128X_PG_MINOR_VER_OFFSET     0x0
-
-#define WL127X_PG_GET_MAJOR(pg_ver) ((pg_ver & WL127X_PG_MAJOR_VER_MASK) >> \
-                                    WL127X_PG_MAJOR_VER_OFFSET)
-#define WL127X_PG_GET_MINOR(pg_ver) ((pg_ver & WL127X_PG_MINOR_VER_MASK) >> \
-                                    WL127X_PG_MINOR_VER_OFFSET)
-#define WL128X_PG_GET_MAJOR(pg_ver) ((pg_ver & WL128X_PG_MAJOR_VER_MASK) >> \
-                                    WL128X_PG_MAJOR_VER_OFFSET)
-#define WL128X_PG_GET_MINOR(pg_ver) ((pg_ver & WL128X_PG_MINOR_VER_MASK) >> \
-                                    WL128X_PG_MINOR_VER_OFFSET)
-
-#define WL12XX_REG_FUSE_BD_ADDR_1      0x00310eb4
-#define WL12XX_REG_FUSE_BD_ADDR_2      0x00310eb8
-
-#endif
diff --git a/drivers/net/wireless/wl12xx/rx.c b/drivers/net/wireless/wl12xx/rx.c
deleted file mode 100644 (file)
index cfa6071..0000000
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/gfp.h>
-#include <linux/sched.h>
-
-#include "wl12xx.h"
-#include "debug.h"
-#include "acx.h"
-#include "reg.h"
-#include "rx.h"
-#include "tx.h"
-#include "io.h"
-
-static u8 wl12xx_rx_get_mem_block(struct wl12xx_fw_status *status,
-                                 u32 drv_rx_counter)
-{
-       return le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
-               RX_MEM_BLOCK_MASK;
-}
-
-static u32 wl12xx_rx_get_buf_size(struct wl12xx_fw_status *status,
-                                u32 drv_rx_counter)
-{
-       return (le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
-               RX_BUF_SIZE_MASK) >> RX_BUF_SIZE_SHIFT_DIV;
-}
-
-static bool wl12xx_rx_get_unaligned(struct wl12xx_fw_status *status,
-                                   u32 drv_rx_counter)
-{
-       /* Convert the value to bool */
-       return !!(le32_to_cpu(status->rx_pkt_descs[drv_rx_counter]) &
-               RX_BUF_UNALIGNED_PAYLOAD);
-}
-
-static void wl1271_rx_status(struct wl1271 *wl,
-                            struct wl1271_rx_descriptor *desc,
-                            struct ieee80211_rx_status *status,
-                            u8 beacon)
-{
-       memset(status, 0, sizeof(struct ieee80211_rx_status));
-
-       if ((desc->flags & WL1271_RX_DESC_BAND_MASK) == WL1271_RX_DESC_BAND_BG)
-               status->band = IEEE80211_BAND_2GHZ;
-       else
-               status->band = IEEE80211_BAND_5GHZ;
-
-       status->rate_idx = wl1271_rate_to_idx(desc->rate, status->band);
-
-       /* 11n support */
-       if (desc->rate <= CONF_HW_RXTX_RATE_MCS0)
-               status->flag |= RX_FLAG_HT;
-
-       status->signal = desc->rssi;
-
-       /*
-        * FIXME: In wl1251, the SNR should be divided by two.  In wl1271 we
-        * need to divide by two for now, but TI has been discussing about
-        * changing it.  This needs to be rechecked.
-        */
-       wl->noise = desc->rssi - (desc->snr >> 1);
-
-       status->freq = ieee80211_channel_to_frequency(desc->channel,
-                                                     status->band);
-
-       if (desc->flags & WL1271_RX_DESC_ENCRYPT_MASK) {
-               u8 desc_err_code = desc->status & WL1271_RX_DESC_STATUS_MASK;
-
-               status->flag |= RX_FLAG_IV_STRIPPED | RX_FLAG_MMIC_STRIPPED |
-                               RX_FLAG_DECRYPTED;
-
-               if (unlikely(desc_err_code == WL1271_RX_DESC_MIC_FAIL)) {
-                       status->flag |= RX_FLAG_MMIC_ERROR;
-                       wl1271_warning("Michael MIC error");
-               }
-       }
-}
-
-static int wl1271_rx_handle_data(struct wl1271 *wl, u8 *data, u32 length,
-                                bool unaligned, u8 *hlid)
-{
-       struct wl1271_rx_descriptor *desc;
-       struct sk_buff *skb;
-       struct ieee80211_hdr *hdr;
-       u8 *buf;
-       u8 beacon = 0;
-       u8 is_data = 0;
-       u8 reserved = unaligned ? NET_IP_ALIGN : 0;
-       u16 seq_num;
-
-       /*
-        * In PLT mode we seem to get frames and mac80211 warns about them,
-        * workaround this by not retrieving them at all.
-        */
-       if (unlikely(wl->plt))
-               return -EINVAL;
-
-       /* the data read starts with the descriptor */
-       desc = (struct wl1271_rx_descriptor *) data;
-
-       if (desc->packet_class == WL12XX_RX_CLASS_LOGGER) {
-               size_t len = length - sizeof(*desc);
-               wl12xx_copy_fwlog(wl, data + sizeof(*desc), len);
-               wake_up_interruptible(&wl->fwlog_waitq);
-               return 0;
-       }
-
-       switch (desc->status & WL1271_RX_DESC_STATUS_MASK) {
-       /* discard corrupted packets */
-       case WL1271_RX_DESC_DRIVER_RX_Q_FAIL:
-       case WL1271_RX_DESC_DECRYPT_FAIL:
-               wl1271_warning("corrupted packet in RX with status: 0x%x",
-                              desc->status & WL1271_RX_DESC_STATUS_MASK);
-               return -EINVAL;
-       case WL1271_RX_DESC_SUCCESS:
-       case WL1271_RX_DESC_MIC_FAIL:
-               break;
-       default:
-               wl1271_error("invalid RX descriptor status: 0x%x",
-                            desc->status & WL1271_RX_DESC_STATUS_MASK);
-               return -EINVAL;
-       }
-
-       /* skb length not included rx descriptor */
-       skb = __dev_alloc_skb(length + reserved - sizeof(*desc), GFP_KERNEL);
-       if (!skb) {
-               wl1271_error("Couldn't allocate RX frame");
-               return -ENOMEM;
-       }
-
-       /* reserve the unaligned payload(if any) */
-       skb_reserve(skb, reserved);
-
-       buf = skb_put(skb, length - sizeof(*desc));
-
-       /*
-        * Copy packets from aggregation buffer to the skbs without rx
-        * descriptor and with packet payload aligned care. In case of unaligned
-        * packets copy the packets in offset of 2 bytes guarantee IP header
-        * payload aligned to 4 bytes.
-        */
-       memcpy(buf, data + sizeof(*desc), length - sizeof(*desc));
-       *hlid = desc->hlid;
-
-       hdr = (struct ieee80211_hdr *)skb->data;
-       if (ieee80211_is_beacon(hdr->frame_control))
-               beacon = 1;
-       if (ieee80211_is_data_present(hdr->frame_control))
-               is_data = 1;
-
-       wl1271_rx_status(wl, desc, IEEE80211_SKB_RXCB(skb), beacon);
-
-       seq_num = (le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ) >> 4;
-       wl1271_debug(DEBUG_RX, "rx skb 0x%p: %d B %s seq %d hlid %d", skb,
-                    skb->len - desc->pad_len,
-                    beacon ? "beacon" : "",
-                    seq_num, *hlid);
-
-       skb_trim(skb, skb->len - desc->pad_len);
-
-       skb_queue_tail(&wl->deferred_rx_queue, skb);
-       queue_work(wl->freezable_wq, &wl->netstack_work);
-
-       return is_data;
-}
-
-void wl12xx_rx(struct wl1271 *wl, struct wl12xx_fw_status *status)
-{
-       struct wl1271_acx_mem_map *wl_mem_map = wl->target_mem_map;
-       unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0};
-       u32 buf_size;
-       u32 fw_rx_counter  = status->fw_rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
-       u32 drv_rx_counter = wl->rx_counter & NUM_RX_PKT_DESC_MOD_MASK;
-       u32 rx_counter;
-       u32 mem_block;
-       u32 pkt_length;
-       u32 pkt_offset;
-       u8 hlid;
-       bool unaligned = false;
-
-       while (drv_rx_counter != fw_rx_counter) {
-               buf_size = 0;
-               rx_counter = drv_rx_counter;
-               while (rx_counter != fw_rx_counter) {
-                       pkt_length = wl12xx_rx_get_buf_size(status, rx_counter);
-                       if (buf_size + pkt_length > WL1271_AGGR_BUFFER_SIZE)
-                               break;
-                       buf_size += pkt_length;
-                       rx_counter++;
-                       rx_counter &= NUM_RX_PKT_DESC_MOD_MASK;
-               }
-
-               if (buf_size == 0) {
-                       wl1271_warning("received empty data");
-                       break;
-               }
-
-               if (wl->chip.id != CHIP_ID_1283_PG20) {
-                       /*
-                        * Choose the block we want to read
-                        * For aggregated packets, only the first memory block
-                        * should be retrieved. The FW takes care of the rest.
-                        */
-                       mem_block = wl12xx_rx_get_mem_block(status,
-                                                           drv_rx_counter);
-
-                       wl->rx_mem_pool_addr.addr = (mem_block << 8) +
-                          le32_to_cpu(wl_mem_map->packet_memory_pool_start);
-
-                       wl->rx_mem_pool_addr.addr_extra =
-                               wl->rx_mem_pool_addr.addr + 4;
-
-                       wl1271_write(wl, WL1271_SLV_REG_DATA,
-                                    &wl->rx_mem_pool_addr,
-                                    sizeof(wl->rx_mem_pool_addr), false);
-               }
-
-               /* Read all available packets at once */
-               wl1271_read(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
-                               buf_size, true);
-
-               /* Split data into separate packets */
-               pkt_offset = 0;
-               while (pkt_offset < buf_size) {
-                       pkt_length = wl12xx_rx_get_buf_size(status,
-                                       drv_rx_counter);
-
-                       unaligned = wl12xx_rx_get_unaligned(status,
-                                       drv_rx_counter);
-
-                       /*
-                        * the handle data call can only fail in memory-outage
-                        * conditions, in that case the received frame will just
-                        * be dropped.
-                        */
-                       if (wl1271_rx_handle_data(wl,
-                                                 wl->aggr_buf + pkt_offset,
-                                                 pkt_length, unaligned,
-                                                 &hlid) == 1) {
-                               if (hlid < WL12XX_MAX_LINKS)
-                                       __set_bit(hlid, active_hlids);
-                               else
-                                       WARN(1,
-                                            "hlid exceeded WL12XX_MAX_LINKS "
-                                            "(%d)\n", hlid);
-                       }
-
-                       wl->rx_counter++;
-                       drv_rx_counter++;
-                       drv_rx_counter &= NUM_RX_PKT_DESC_MOD_MASK;
-                       pkt_offset += pkt_length;
-               }
-       }
-
-       /*
-        * Write the driver's packet counter to the FW. This is only required
-        * for older hardware revisions
-        */
-       if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION)
-               wl1271_write32(wl, RX_DRIVER_COUNTER_ADDRESS, wl->rx_counter);
-
-       wl12xx_rearm_rx_streaming(wl, active_hlids);
-}
diff --git a/drivers/net/wireless/wl12xx/rx.h b/drivers/net/wireless/wl12xx/rx.h
deleted file mode 100644 (file)
index 86ba6b1..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
- * Copyright (C) 2008-2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __RX_H__
-#define __RX_H__
-
-#include <linux/bitops.h>
-
-#define WL1271_RX_MAX_RSSI -30
-#define WL1271_RX_MIN_RSSI -95
-
-#define SHORT_PREAMBLE_BIT   BIT(0)
-#define OFDM_RATE_BIT        BIT(6)
-#define PBCC_RATE_BIT        BIT(7)
-
-#define PLCP_HEADER_LENGTH 8
-#define RX_DESC_PACKETID_SHIFT 11
-#define RX_MAX_PACKET_ID 3
-
-#define NUM_RX_PKT_DESC_MOD_MASK   7
-
-#define RX_DESC_VALID_FCS         0x0001
-#define RX_DESC_MATCH_RXADDR1     0x0002
-#define RX_DESC_MCAST             0x0004
-#define RX_DESC_STAINTIM          0x0008
-#define RX_DESC_VIRTUAL_BM        0x0010
-#define RX_DESC_BCAST             0x0020
-#define RX_DESC_MATCH_SSID        0x0040
-#define RX_DESC_MATCH_BSSID       0x0080
-#define RX_DESC_ENCRYPTION_MASK   0x0300
-#define RX_DESC_MEASURMENT        0x0400
-#define RX_DESC_SEQNUM_MASK       0x1800
-#define        RX_DESC_MIC_FAIL          0x2000
-#define        RX_DESC_DECRYPT_FAIL      0x4000
-
-/*
- * RX Descriptor flags:
- *
- * Bits 0-1 - band
- * Bit  2   - STBC
- * Bit  3   - A-MPDU
- * Bit  4   - HT
- * Bits 5-7 - encryption
- */
-#define WL1271_RX_DESC_BAND_MASK    0x03
-#define WL1271_RX_DESC_ENCRYPT_MASK 0xE0
-
-#define WL1271_RX_DESC_BAND_BG      0x00
-#define WL1271_RX_DESC_BAND_J       0x01
-#define WL1271_RX_DESC_BAND_A       0x02
-
-#define WL1271_RX_DESC_STBC         BIT(2)
-#define WL1271_RX_DESC_A_MPDU       BIT(3)
-#define WL1271_RX_DESC_HT           BIT(4)
-
-#define WL1271_RX_DESC_ENCRYPT_WEP  0x20
-#define WL1271_RX_DESC_ENCRYPT_TKIP 0x40
-#define WL1271_RX_DESC_ENCRYPT_AES  0x60
-#define WL1271_RX_DESC_ENCRYPT_GEM  0x80
-
-/*
- * RX Descriptor status
- *
- * Bits 0-2 - error code
- * Bits 3-5 - process_id tag (AP mode FW)
- * Bits 6-7 - reserved
- */
-#define WL1271_RX_DESC_STATUS_MASK      0x03
-
-#define WL1271_RX_DESC_SUCCESS          0x00
-#define WL1271_RX_DESC_DECRYPT_FAIL     0x01
-#define WL1271_RX_DESC_MIC_FAIL         0x02
-#define WL1271_RX_DESC_DRIVER_RX_Q_FAIL 0x03
-
-#define RX_MEM_BLOCK_MASK            0xFF
-#define RX_BUF_SIZE_MASK             0xFFF00
-#define RX_BUF_SIZE_SHIFT_DIV        6
-/* If set, the start of IP payload is not 4 bytes aligned */
-#define RX_BUF_UNALIGNED_PAYLOAD     BIT(20)
-
-enum {
-       WL12XX_RX_CLASS_UNKNOWN,
-       WL12XX_RX_CLASS_MANAGEMENT,
-       WL12XX_RX_CLASS_DATA,
-       WL12XX_RX_CLASS_QOS_DATA,
-       WL12XX_RX_CLASS_BCN_PRBRSP,
-       WL12XX_RX_CLASS_EAPOL,
-       WL12XX_RX_CLASS_BA_EVENT,
-       WL12XX_RX_CLASS_AMSDU,
-       WL12XX_RX_CLASS_LOGGER,
-};
-
-struct wl1271_rx_descriptor {
-       __le16 length;
-       u8  status;
-       u8  flags;
-       u8  rate;
-       u8  channel;
-       s8  rssi;
-       u8  snr;
-       __le32 timestamp;
-       u8  packet_class;
-       u8  hlid;
-       u8  pad_len;
-       u8  reserved;
-} __packed;
-
-void wl12xx_rx(struct wl1271 *wl, struct wl12xx_fw_status *status);
-u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band);
-
-#endif
diff --git a/drivers/net/wireless/wl12xx/scan.c b/drivers/net/wireless/wl12xx/scan.c
deleted file mode 100644 (file)
index fcba055..0000000
+++ /dev/null
@@ -1,770 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2009-2010 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/ieee80211.h>
-
-#include "wl12xx.h"
-#include "debug.h"
-#include "cmd.h"
-#include "scan.h"
-#include "acx.h"
-#include "ps.h"
-#include "tx.h"
-
-void wl1271_scan_complete_work(struct work_struct *work)
-{
-       struct delayed_work *dwork;
-       struct wl1271 *wl;
-       struct ieee80211_vif *vif;
-       struct wl12xx_vif *wlvif;
-       int ret;
-
-       dwork = container_of(work, struct delayed_work, work);
-       wl = container_of(dwork, struct wl1271, scan_complete_work);
-
-       wl1271_debug(DEBUG_SCAN, "Scanning complete");
-
-       mutex_lock(&wl->mutex);
-
-       if (wl->state == WL1271_STATE_OFF)
-               goto out;
-
-       if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
-               goto out;
-
-       vif = wl->scan_vif;
-       wlvif = wl12xx_vif_to_data(vif);
-
-       /*
-        * Rearm the tx watchdog just before idling scan. This
-        * prevents just-finished scans from triggering the watchdog
-        */
-       wl12xx_rearm_tx_watchdog_locked(wl);
-
-       wl->scan.state = WL1271_SCAN_STATE_IDLE;
-       memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
-       wl->scan.req = NULL;
-       wl->scan_vif = NULL;
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
-               /* restore hardware connection monitoring template */
-               wl1271_cmd_build_ap_probe_req(wl, wlvif, wlvif->probereq);
-       }
-
-       wl1271_ps_elp_sleep(wl);
-
-       if (wl->scan.failed) {
-               wl1271_info("Scan completed due to error.");
-               wl12xx_queue_recovery_work(wl);
-       }
-
-       ieee80211_scan_completed(wl->hw, false);
-
-out:
-       mutex_unlock(&wl->mutex);
-
-}
-
-
-static int wl1271_get_scan_channels(struct wl1271 *wl,
-                                   struct cfg80211_scan_request *req,
-                                   struct basic_scan_channel_params *channels,
-                                   enum ieee80211_band band, bool passive)
-{
-       struct conf_scan_settings *c = &wl->conf.scan;
-       int i, j;
-       u32 flags;
-
-       for (i = 0, j = 0;
-            i < req->n_channels && j < WL1271_SCAN_MAX_CHANNELS;
-            i++) {
-               flags = req->channels[i]->flags;
-
-               if (!test_bit(i, wl->scan.scanned_ch) &&
-                   !(flags & IEEE80211_CHAN_DISABLED) &&
-                   (req->channels[i]->band == band) &&
-                   /*
-                    * In passive scans, we scan all remaining
-                    * channels, even if not marked as such.
-                    * In active scans, we only scan channels not
-                    * marked as passive.
-                    */
-                   (passive || !(flags & IEEE80211_CHAN_PASSIVE_SCAN))) {
-                       wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
-                                    req->channels[i]->band,
-                                    req->channels[i]->center_freq);
-                       wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
-                                    req->channels[i]->hw_value,
-                                    req->channels[i]->flags);
-                       wl1271_debug(DEBUG_SCAN,
-                                    "max_antenna_gain %d, max_power %d",
-                                    req->channels[i]->max_antenna_gain,
-                                    req->channels[i]->max_power);
-                       wl1271_debug(DEBUG_SCAN, "beacon_found %d",
-                                    req->channels[i]->beacon_found);
-
-                       if (!passive) {
-                               channels[j].min_duration =
-                                       cpu_to_le32(c->min_dwell_time_active);
-                               channels[j].max_duration =
-                                       cpu_to_le32(c->max_dwell_time_active);
-                       } else {
-                               channels[j].min_duration =
-                                       cpu_to_le32(c->min_dwell_time_passive);
-                               channels[j].max_duration =
-                                       cpu_to_le32(c->max_dwell_time_passive);
-                       }
-                       channels[j].early_termination = 0;
-                       channels[j].tx_power_att = req->channels[i]->max_power;
-                       channels[j].channel = req->channels[i]->hw_value;
-
-                       memset(&channels[j].bssid_lsb, 0xff, 4);
-                       memset(&channels[j].bssid_msb, 0xff, 2);
-
-                       /* Mark the channels we already used */
-                       set_bit(i, wl->scan.scanned_ch);
-
-                       j++;
-               }
-       }
-
-       return j;
-}
-
-#define WL1271_NOTHING_TO_SCAN 1
-
-static int wl1271_scan_send(struct wl1271 *wl, struct ieee80211_vif *vif,
-                           enum ieee80211_band band,
-                           bool passive, u32 basic_rate)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       struct wl1271_cmd_scan *cmd;
-       struct wl1271_cmd_trigger_scan_to *trigger;
-       int ret;
-       u16 scan_options = 0;
-
-       /* skip active scans if we don't have SSIDs */
-       if (!passive && wl->scan.req->n_ssids == 0)
-               return WL1271_NOTHING_TO_SCAN;
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
-       if (!cmd || !trigger) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       if (wl->conf.scan.split_scan_timeout)
-               scan_options |= WL1271_SCAN_OPT_SPLIT_SCAN;
-
-       if (passive)
-               scan_options |= WL1271_SCAN_OPT_PASSIVE;
-
-       if (wlvif->bss_type == BSS_TYPE_AP_BSS ||
-           test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
-               cmd->params.role_id = wlvif->role_id;
-       else
-               cmd->params.role_id = wlvif->dev_role_id;
-
-       if (WARN_ON(cmd->params.role_id == WL12XX_INVALID_ROLE_ID)) {
-               ret = -EINVAL;
-               goto out;
-       }
-
-       cmd->params.scan_options = cpu_to_le16(scan_options);
-
-       cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req,
-                                                   cmd->channels,
-                                                   band, passive);
-       if (cmd->params.n_ch == 0) {
-               ret = WL1271_NOTHING_TO_SCAN;
-               goto out;
-       }
-
-       cmd->params.tx_rate = cpu_to_le32(basic_rate);
-       cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs;
-       cmd->params.tid_trigger = CONF_TX_AC_ANY_TID;
-       cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
-
-       if (band == IEEE80211_BAND_2GHZ)
-               cmd->params.band = WL1271_SCAN_BAND_2_4_GHZ;
-       else
-               cmd->params.band = WL1271_SCAN_BAND_5_GHZ;
-
-       if (wl->scan.ssid_len && wl->scan.ssid) {
-               cmd->params.ssid_len = wl->scan.ssid_len;
-               memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len);
-       }
-
-       memcpy(cmd->addr, vif->addr, ETH_ALEN);
-
-       ret = wl12xx_cmd_build_probe_req(wl, wlvif,
-                                        cmd->params.role_id, band,
-                                        wl->scan.ssid, wl->scan.ssid_len,
-                                        wl->scan.req->ie,
-                                        wl->scan.req->ie_len);
-       if (ret < 0) {
-               wl1271_error("PROBE request template failed");
-               goto out;
-       }
-
-       trigger->timeout = cpu_to_le32(wl->conf.scan.split_scan_timeout);
-       ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
-                             sizeof(*trigger), 0);
-       if (ret < 0) {
-               wl1271_error("trigger scan to failed for hw scan");
-               goto out;
-       }
-
-       wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd));
-
-       ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("SCAN failed");
-               goto out;
-       }
-
-out:
-       kfree(cmd);
-       kfree(trigger);
-       return ret;
-}
-
-void wl1271_scan_stm(struct wl1271 *wl, struct ieee80211_vif *vif)
-{
-       struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
-       int ret = 0;
-       enum ieee80211_band band;
-       u32 rate, mask;
-
-       switch (wl->scan.state) {
-       case WL1271_SCAN_STATE_IDLE:
-               break;
-
-       case WL1271_SCAN_STATE_2GHZ_ACTIVE:
-               band = IEEE80211_BAND_2GHZ;
-               mask = wlvif->bitrate_masks[band];
-               if (wl->scan.req->no_cck) {
-                       mask &= ~CONF_TX_CCK_RATES;
-                       if (!mask)
-                               mask = CONF_TX_RATE_MASK_BASIC_P2P;
-               }
-               rate = wl1271_tx_min_rate_get(wl, mask);
-               ret = wl1271_scan_send(wl, vif, band, false, rate);
-               if (ret == WL1271_NOTHING_TO_SCAN) {
-                       wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE;
-                       wl1271_scan_stm(wl, vif);
-               }
-
-               break;
-
-       case WL1271_SCAN_STATE_2GHZ_PASSIVE:
-               band = IEEE80211_BAND_2GHZ;
-               mask = wlvif->bitrate_masks[band];
-               if (wl->scan.req->no_cck) {
-                       mask &= ~CONF_TX_CCK_RATES;
-                       if (!mask)
-                               mask = CONF_TX_RATE_MASK_BASIC_P2P;
-               }
-               rate = wl1271_tx_min_rate_get(wl, mask);
-               ret = wl1271_scan_send(wl, vif, band, true, rate);
-               if (ret == WL1271_NOTHING_TO_SCAN) {
-                       if (wl->enable_11a)
-                               wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE;
-                       else
-                               wl->scan.state = WL1271_SCAN_STATE_DONE;
-                       wl1271_scan_stm(wl, vif);
-               }
-
-               break;
-
-       case WL1271_SCAN_STATE_5GHZ_ACTIVE:
-               band = IEEE80211_BAND_5GHZ;
-               rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
-               ret = wl1271_scan_send(wl, vif, band, false, rate);
-               if (ret == WL1271_NOTHING_TO_SCAN) {
-                       wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE;
-                       wl1271_scan_stm(wl, vif);
-               }
-
-               break;
-
-       case WL1271_SCAN_STATE_5GHZ_PASSIVE:
-               band = IEEE80211_BAND_5GHZ;
-               rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
-               ret = wl1271_scan_send(wl, vif, band, true, rate);
-               if (ret == WL1271_NOTHING_TO_SCAN) {
-                       wl->scan.state = WL1271_SCAN_STATE_DONE;
-                       wl1271_scan_stm(wl, vif);
-               }
-
-               break;
-
-       case WL1271_SCAN_STATE_DONE:
-               wl->scan.failed = false;
-               cancel_delayed_work(&wl->scan_complete_work);
-               ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
-                                            msecs_to_jiffies(0));
-               break;
-
-       default:
-               wl1271_error("invalid scan state");
-               break;
-       }
-
-       if (ret < 0) {
-               cancel_delayed_work(&wl->scan_complete_work);
-               ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
-                                            msecs_to_jiffies(0));
-       }
-}
-
-int wl1271_scan(struct wl1271 *wl, struct ieee80211_vif *vif,
-               const u8 *ssid, size_t ssid_len,
-               struct cfg80211_scan_request *req)
-{
-       /*
-        * cfg80211 should guarantee that we don't get more channels
-        * than what we have registered.
-        */
-       BUG_ON(req->n_channels > WL1271_MAX_CHANNELS);
-
-       if (wl->scan.state != WL1271_SCAN_STATE_IDLE)
-               return -EBUSY;
-
-       wl->scan.state = WL1271_SCAN_STATE_2GHZ_ACTIVE;
-
-       if (ssid_len && ssid) {
-               wl->scan.ssid_len = ssid_len;
-               memcpy(wl->scan.ssid, ssid, ssid_len);
-       } else {
-               wl->scan.ssid_len = 0;
-       }
-
-       wl->scan_vif = vif;
-       wl->scan.req = req;
-       memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
-
-       /* we assume failure so that timeout scenarios are handled correctly */
-       wl->scan.failed = true;
-       ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work,
-                                    msecs_to_jiffies(WL1271_SCAN_TIMEOUT));
-
-       wl1271_scan_stm(wl, vif);
-
-       return 0;
-}
-
-int wl1271_scan_stop(struct wl1271 *wl)
-{
-       struct wl1271_cmd_header *cmd = NULL;
-       int ret = 0;
-
-       if (WARN_ON(wl->scan.state == WL1271_SCAN_STATE_IDLE))
-               return -EINVAL;
-
-       wl1271_debug(DEBUG_CMD, "cmd scan stop");
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       ret = wl1271_cmd_send(wl, CMD_STOP_SCAN, cmd,
-                             sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("cmd stop_scan failed");
-               goto out;
-       }
-out:
-       kfree(cmd);
-       return ret;
-}
-
-static int
-wl1271_scan_get_sched_scan_channels(struct wl1271 *wl,
-                                   struct cfg80211_sched_scan_request *req,
-                                   struct conn_scan_ch_params *channels,
-                                   u32 band, bool radar, bool passive,
-                                   int start, int max_channels)
-{
-       struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
-       int i, j;
-       u32 flags;
-       bool force_passive = !req->n_ssids;
-
-       for (i = 0, j = start;
-            i < req->n_channels && j < max_channels;
-            i++) {
-               flags = req->channels[i]->flags;
-
-               if (force_passive)
-                       flags |= IEEE80211_CHAN_PASSIVE_SCAN;
-
-               if ((req->channels[i]->band == band) &&
-                   !(flags & IEEE80211_CHAN_DISABLED) &&
-                   (!!(flags & IEEE80211_CHAN_RADAR) == radar) &&
-                   /* if radar is set, we ignore the passive flag */
-                   (radar ||
-                    !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) {
-                       wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ",
-                                    req->channels[i]->band,
-                                    req->channels[i]->center_freq);
-                       wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X",
-                                    req->channels[i]->hw_value,
-                                    req->channels[i]->flags);
-                       wl1271_debug(DEBUG_SCAN, "max_power %d",
-                                    req->channels[i]->max_power);
-
-                       if (flags & IEEE80211_CHAN_RADAR) {
-                               channels[j].flags |= SCAN_CHANNEL_FLAGS_DFS;
-
-                               channels[j].passive_duration =
-                                       cpu_to_le16(c->dwell_time_dfs);
-                       } else {
-                               channels[j].passive_duration =
-                                       cpu_to_le16(c->dwell_time_passive);
-                       }
-
-                       channels[j].min_duration =
-                               cpu_to_le16(c->min_dwell_time_active);
-                       channels[j].max_duration =
-                               cpu_to_le16(c->max_dwell_time_active);
-
-                       channels[j].tx_power_att = req->channels[i]->max_power;
-                       channels[j].channel = req->channels[i]->hw_value;
-
-                       j++;
-               }
-       }
-
-       return j - start;
-}
-
-static bool
-wl1271_scan_sched_scan_channels(struct wl1271 *wl,
-                               struct cfg80211_sched_scan_request *req,
-                               struct wl1271_cmd_sched_scan_config *cfg)
-{
-       cfg->passive[0] =
-               wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
-                                                   IEEE80211_BAND_2GHZ,
-                                                   false, true, 0,
-                                                   MAX_CHANNELS_2GHZ);
-       cfg->active[0] =
-               wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2,
-                                                   IEEE80211_BAND_2GHZ,
-                                                   false, false,
-                                                   cfg->passive[0],
-                                                   MAX_CHANNELS_2GHZ);
-       cfg->passive[1] =
-               wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
-                                                   IEEE80211_BAND_5GHZ,
-                                                   false, true, 0,
-                                                   MAX_CHANNELS_5GHZ);
-       cfg->dfs =
-               wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
-                                                   IEEE80211_BAND_5GHZ,
-                                                   true, true,
-                                                   cfg->passive[1],
-                                                   MAX_CHANNELS_5GHZ);
-       cfg->active[1] =
-               wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5,
-                                                   IEEE80211_BAND_5GHZ,
-                                                   false, false,
-                                                   cfg->passive[1] + cfg->dfs,
-                                                   MAX_CHANNELS_5GHZ);
-       /* 802.11j channels are not supported yet */
-       cfg->passive[2] = 0;
-       cfg->active[2] = 0;
-
-       wl1271_debug(DEBUG_SCAN, "    2.4GHz: active %d passive %d",
-                    cfg->active[0], cfg->passive[0]);
-       wl1271_debug(DEBUG_SCAN, "    5GHz: active %d passive %d",
-                    cfg->active[1], cfg->passive[1]);
-       wl1271_debug(DEBUG_SCAN, "    DFS: %d", cfg->dfs);
-
-       return  cfg->passive[0] || cfg->active[0] ||
-               cfg->passive[1] || cfg->active[1] || cfg->dfs ||
-               cfg->passive[2] || cfg->active[2];
-}
-
-/* Returns the scan type to be used or a negative value on error */
-static int
-wl12xx_scan_sched_scan_ssid_list(struct wl1271 *wl,
-                                struct cfg80211_sched_scan_request *req)
-{
-       struct wl1271_cmd_sched_scan_ssid_list *cmd = NULL;
-       struct cfg80211_match_set *sets = req->match_sets;
-       struct cfg80211_ssid *ssids = req->ssids;
-       int ret = 0, type, i, j, n_match_ssids = 0;
-
-       wl1271_debug(DEBUG_CMD, "cmd sched scan ssid list");
-
-       /* count the match sets that contain SSIDs */
-       for (i = 0; i < req->n_match_sets; i++)
-               if (sets[i].ssid.ssid_len > 0)
-                       n_match_ssids++;
-
-       /* No filter, no ssids or only bcast ssid */
-       if (!n_match_ssids &&
-           (!req->n_ssids ||
-            (req->n_ssids == 1 && req->ssids[0].ssid_len == 0))) {
-               type = SCAN_SSID_FILTER_ANY;
-               goto out;
-       }
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       if (!n_match_ssids) {
-               /* No filter, with ssids */
-               type = SCAN_SSID_FILTER_DISABLED;
-
-               for (i = 0; i < req->n_ssids; i++) {
-                       cmd->ssids[cmd->n_ssids].type = (ssids[i].ssid_len) ?
-                               SCAN_SSID_TYPE_HIDDEN : SCAN_SSID_TYPE_PUBLIC;
-                       cmd->ssids[cmd->n_ssids].len = ssids[i].ssid_len;
-                       memcpy(cmd->ssids[cmd->n_ssids].ssid, ssids[i].ssid,
-                              ssids[i].ssid_len);
-                       cmd->n_ssids++;
-               }
-       } else {
-               type = SCAN_SSID_FILTER_LIST;
-
-               /* Add all SSIDs from the filters */
-               for (i = 0; i < req->n_match_sets; i++) {
-                       /* ignore sets without SSIDs */
-                       if (!sets[i].ssid.ssid_len)
-                               continue;
-
-                       cmd->ssids[cmd->n_ssids].type = SCAN_SSID_TYPE_PUBLIC;
-                       cmd->ssids[cmd->n_ssids].len = sets[i].ssid.ssid_len;
-                       memcpy(cmd->ssids[cmd->n_ssids].ssid,
-                              sets[i].ssid.ssid, sets[i].ssid.ssid_len);
-                       cmd->n_ssids++;
-               }
-               if ((req->n_ssids > 1) ||
-                   (req->n_ssids == 1 && req->ssids[0].ssid_len > 0)) {
-                       /*
-                        * Mark all the SSIDs passed in the SSID list as HIDDEN,
-                        * so they're used in probe requests.
-                        */
-                       for (i = 0; i < req->n_ssids; i++) {
-                               if (!req->ssids[i].ssid_len)
-                                       continue;
-
-                               for (j = 0; j < cmd->n_ssids; j++)
-                                       if (!memcmp(req->ssids[i].ssid,
-                                                  cmd->ssids[j].ssid,
-                                                  req->ssids[i].ssid_len)) {
-                                               cmd->ssids[j].type =
-                                                       SCAN_SSID_TYPE_HIDDEN;
-                                               break;
-                                       }
-                               /* Fail if SSID isn't present in the filters */
-                               if (j == cmd->n_ssids) {
-                                       ret = -EINVAL;
-                                       goto out_free;
-                               }
-                       }
-               }
-       }
-
-       wl1271_dump(DEBUG_SCAN, "SSID_LIST: ", cmd, sizeof(*cmd));
-
-       ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_SSID_CFG, cmd,
-                             sizeof(*cmd), 0);
-       if (ret < 0) {
-               wl1271_error("cmd sched scan ssid list failed");
-               goto out_free;
-       }
-
-out_free:
-       kfree(cmd);
-out:
-       if (ret < 0)
-               return ret;
-       return type;
-}
-
-int wl1271_scan_sched_scan_config(struct wl1271 *wl,
-                                 struct wl12xx_vif *wlvif,
-                                 struct cfg80211_sched_scan_request *req,
-                                 struct ieee80211_sched_scan_ies *ies)
-{
-       struct wl1271_cmd_sched_scan_config *cfg = NULL;
-       struct conf_sched_scan_settings *c = &wl->conf.sched_scan;
-       int i, ret;
-       bool force_passive = !req->n_ssids;
-
-       wl1271_debug(DEBUG_CMD, "cmd sched_scan scan config");
-
-       cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
-       if (!cfg)
-               return -ENOMEM;
-
-       cfg->rssi_threshold = c->rssi_threshold;
-       cfg->snr_threshold  = c->snr_threshold;
-       cfg->n_probe_reqs = c->num_probe_reqs;
-       /* cycles set to 0 it means infinite (until manually stopped) */
-       cfg->cycles = 0;
-       /* report APs when at least 1 is found */
-       cfg->report_after = 1;
-       /* don't stop scanning automatically when something is found */
-       cfg->terminate = 0;
-       cfg->tag = WL1271_SCAN_DEFAULT_TAG;
-       /* don't filter on BSS type */
-       cfg->bss_type = SCAN_BSS_TYPE_ANY;
-       /* currently NL80211 supports only a single interval */
-       for (i = 0; i < SCAN_MAX_CYCLE_INTERVALS; i++)
-               cfg->intervals[i] = cpu_to_le32(req->interval);
-
-       cfg->ssid_len = 0;
-       ret = wl12xx_scan_sched_scan_ssid_list(wl, req);
-       if (ret < 0)
-               goto out;
-
-       cfg->filter_type = ret;
-
-       wl1271_debug(DEBUG_SCAN, "filter_type = %d", cfg->filter_type);
-
-       if (!wl1271_scan_sched_scan_channels(wl, req, cfg)) {
-               wl1271_error("scan channel list is empty");
-               ret = -EINVAL;
-               goto out;
-       }
-
-       if (!force_passive && cfg->active[0]) {
-               u8 band = IEEE80211_BAND_2GHZ;
-               ret = wl12xx_cmd_build_probe_req(wl, wlvif,
-                                                wlvif->dev_role_id, band,
-                                                req->ssids[0].ssid,
-                                                req->ssids[0].ssid_len,
-                                                ies->ie[band],
-                                                ies->len[band]);
-               if (ret < 0) {
-                       wl1271_error("2.4GHz PROBE request template failed");
-                       goto out;
-               }
-       }
-
-       if (!force_passive && cfg->active[1]) {
-               u8 band = IEEE80211_BAND_5GHZ;
-               ret = wl12xx_cmd_build_probe_req(wl, wlvif,
-                                                wlvif->dev_role_id, band,
-                                                req->ssids[0].ssid,
-                                                req->ssids[0].ssid_len,
-                                                ies->ie[band],
-                                                ies->len[band]);
-               if (ret < 0) {
-                       wl1271_error("5GHz PROBE request template failed");
-                       goto out;
-               }
-       }
-
-       wl1271_dump(DEBUG_SCAN, "SCAN_CFG: ", cfg, sizeof(*cfg));
-
-       ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_CFG, cfg,
-                             sizeof(*cfg), 0);
-       if (ret < 0) {
-               wl1271_error("SCAN configuration failed");
-               goto out;
-       }
-out:
-       kfree(cfg);
-       return ret;
-}
-
-int wl1271_scan_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       struct wl1271_cmd_sched_scan_start *start;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_CMD, "cmd periodic scan start");
-
-       if (wlvif->bss_type != BSS_TYPE_STA_BSS)
-               return -EOPNOTSUPP;
-
-       if (test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags))
-               return -EBUSY;
-
-       start = kzalloc(sizeof(*start), GFP_KERNEL);
-       if (!start)
-               return -ENOMEM;
-
-       start->tag = WL1271_SCAN_DEFAULT_TAG;
-
-       ret = wl1271_cmd_send(wl, CMD_START_PERIODIC_SCAN, start,
-                             sizeof(*start), 0);
-       if (ret < 0) {
-               wl1271_error("failed to send scan start command");
-               goto out_free;
-       }
-
-out_free:
-       kfree(start);
-       return ret;
-}
-
-void wl1271_scan_sched_scan_results(struct wl1271 *wl)
-{
-       wl1271_debug(DEBUG_SCAN, "got periodic scan results");
-
-       ieee80211_sched_scan_results(wl->hw);
-}
-
-void wl1271_scan_sched_scan_stop(struct wl1271 *wl)
-{
-       struct wl1271_cmd_sched_scan_stop *stop;
-       int ret = 0;
-
-       wl1271_debug(DEBUG_CMD, "cmd periodic scan stop");
-
-       /* FIXME: what to do if alloc'ing to stop fails? */
-       stop = kzalloc(sizeof(*stop), GFP_KERNEL);
-       if (!stop) {
-               wl1271_error("failed to alloc memory to send sched scan stop");
-               return;
-       }
-
-       stop->tag = WL1271_SCAN_DEFAULT_TAG;
-
-       ret = wl1271_cmd_send(wl, CMD_STOP_PERIODIC_SCAN, stop,
-                             sizeof(*stop), 0);
-       if (ret < 0) {
-               wl1271_error("failed to send sched scan stop command");
-               goto out_free;
-       }
-
-out_free:
-       kfree(stop);
-}
diff --git a/drivers/net/wireless/wl12xx/scan.h b/drivers/net/wireless/wl12xx/scan.h
deleted file mode 100644 (file)
index 96ff457..0000000
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2009-2010 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __SCAN_H__
-#define __SCAN_H__
-
-#include "wl12xx.h"
-
-int wl1271_scan(struct wl1271 *wl, struct ieee80211_vif *vif,
-               const u8 *ssid, size_t ssid_len,
-               struct cfg80211_scan_request *req);
-int wl1271_scan_stop(struct wl1271 *wl);
-int wl1271_scan_build_probe_req(struct wl1271 *wl,
-                               const u8 *ssid, size_t ssid_len,
-                               const u8 *ie, size_t ie_len, u8 band);
-void wl1271_scan_stm(struct wl1271 *wl, struct ieee80211_vif *vif);
-void wl1271_scan_complete_work(struct work_struct *work);
-int wl1271_scan_sched_scan_config(struct wl1271 *wl,
-                                    struct wl12xx_vif *wlvif,
-                                    struct cfg80211_sched_scan_request *req,
-                                    struct ieee80211_sched_scan_ies *ies);
-int wl1271_scan_sched_scan_start(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-void wl1271_scan_sched_scan_stop(struct wl1271 *wl);
-void wl1271_scan_sched_scan_results(struct wl1271 *wl);
-
-#define WL1271_SCAN_MAX_CHANNELS       24
-#define WL1271_SCAN_DEFAULT_TAG        1
-#define WL1271_SCAN_CURRENT_TX_PWR     0
-#define WL1271_SCAN_OPT_ACTIVE         0
-#define WL1271_SCAN_OPT_PASSIVE               1
-#define WL1271_SCAN_OPT_SPLIT_SCAN     2
-#define WL1271_SCAN_OPT_PRIORITY_HIGH  4
-/* scan even if we fail to enter psm */
-#define WL1271_SCAN_OPT_FORCE          8
-#define WL1271_SCAN_BAND_2_4_GHZ 0
-#define WL1271_SCAN_BAND_5_GHZ 1
-
-#define WL1271_SCAN_TIMEOUT    10000 /* msec */
-
-enum {
-       WL1271_SCAN_STATE_IDLE,
-       WL1271_SCAN_STATE_2GHZ_ACTIVE,
-       WL1271_SCAN_STATE_2GHZ_PASSIVE,
-       WL1271_SCAN_STATE_5GHZ_ACTIVE,
-       WL1271_SCAN_STATE_5GHZ_PASSIVE,
-       WL1271_SCAN_STATE_DONE
-};
-
-struct basic_scan_params {
-       /* Scan option flags (WL1271_SCAN_OPT_*) */
-       __le16 scan_options;
-       u8 role_id;
-       /* Number of scan channels in the list (maximum 30) */
-       u8 n_ch;
-       /* This field indicates the number of probe requests to send
-          per channel for an active scan */
-       u8 n_probe_reqs;
-       u8 tid_trigger;
-       u8 ssid_len;
-       u8 use_ssid_list;
-
-       /* Rate bit field for sending the probes */
-       __le32 tx_rate;
-
-       u8 ssid[IEEE80211_MAX_SSID_LEN];
-       /* Band to scan */
-       u8 band;
-
-       u8 scan_tag;
-       u8 padding2[2];
-} __packed;
-
-struct basic_scan_channel_params {
-       /* Duration in TU to wait for frames on a channel for active scan */
-       __le32 min_duration;
-       __le32 max_duration;
-       __le32 bssid_lsb;
-       __le16 bssid_msb;
-       u8 early_termination;
-       u8 tx_power_att;
-       u8 channel;
-       /* FW internal use only! */
-       u8 dfs_candidate;
-       u8 activity_detected;
-       u8 pad;
-} __packed;
-
-struct wl1271_cmd_scan {
-       struct wl1271_cmd_header header;
-
-       struct basic_scan_params params;
-       struct basic_scan_channel_params channels[WL1271_SCAN_MAX_CHANNELS];
-
-       /* src mac address */
-       u8 addr[ETH_ALEN];
-       u8 padding[2];
-} __packed;
-
-struct wl1271_cmd_trigger_scan_to {
-       struct wl1271_cmd_header header;
-
-       __le32 timeout;
-} __packed;
-
-#define MAX_CHANNELS_2GHZ      14
-#define MAX_CHANNELS_5GHZ      23
-#define MAX_CHANNELS_4GHZ      4
-
-#define SCAN_MAX_CYCLE_INTERVALS 16
-#define SCAN_MAX_BANDS 3
-
-enum {
-       SCAN_SSID_FILTER_ANY      = 0,
-       SCAN_SSID_FILTER_SPECIFIC = 1,
-       SCAN_SSID_FILTER_LIST     = 2,
-       SCAN_SSID_FILTER_DISABLED = 3
-};
-
-enum {
-       SCAN_BSS_TYPE_INDEPENDENT,
-       SCAN_BSS_TYPE_INFRASTRUCTURE,
-       SCAN_BSS_TYPE_ANY,
-};
-
-#define SCAN_CHANNEL_FLAGS_DFS         BIT(0)
-#define SCAN_CHANNEL_FLAGS_DFS_ENABLED BIT(1)
-
-struct conn_scan_ch_params {
-       __le16 min_duration;
-       __le16 max_duration;
-       __le16 passive_duration;
-
-       u8  channel;
-       u8  tx_power_att;
-
-       /* bit 0: DFS channel; bit 1: DFS enabled */
-       u8  flags;
-
-       u8  padding[3];
-} __packed;
-
-struct wl1271_cmd_sched_scan_config {
-       struct wl1271_cmd_header header;
-
-       __le32 intervals[SCAN_MAX_CYCLE_INTERVALS];
-
-       s8 rssi_threshold; /* for filtering (in dBm) */
-       s8 snr_threshold;  /* for filtering (in dB) */
-
-       u8 cycles;       /* maximum number of scan cycles */
-       u8 report_after; /* report when this number of results are received */
-       u8 terminate;    /* stop scanning after reporting */
-
-       u8 tag;
-       u8 bss_type; /* for filtering */
-       u8 filter_type;
-
-       u8 ssid_len;     /* For SCAN_SSID_FILTER_SPECIFIC */
-       u8 ssid[IEEE80211_MAX_SSID_LEN];
-
-       u8 n_probe_reqs; /* Number of probes requests per channel */
-
-       u8 passive[SCAN_MAX_BANDS];
-       u8 active[SCAN_MAX_BANDS];
-
-       u8 dfs;
-
-       u8 padding[3];
-
-       struct conn_scan_ch_params channels_2[MAX_CHANNELS_2GHZ];
-       struct conn_scan_ch_params channels_5[MAX_CHANNELS_5GHZ];
-       struct conn_scan_ch_params channels_4[MAX_CHANNELS_4GHZ];
-} __packed;
-
-
-#define SCHED_SCAN_MAX_SSIDS 16
-
-enum {
-       SCAN_SSID_TYPE_PUBLIC = 0,
-       SCAN_SSID_TYPE_HIDDEN = 1,
-};
-
-struct wl1271_ssid {
-       u8 type;
-       u8 len;
-       u8 ssid[IEEE80211_MAX_SSID_LEN];
-       /* u8 padding[2]; */
-} __packed;
-
-struct wl1271_cmd_sched_scan_ssid_list {
-       struct wl1271_cmd_header header;
-
-       u8 n_ssids;
-       struct wl1271_ssid ssids[SCHED_SCAN_MAX_SSIDS];
-       u8 padding[3];
-} __packed;
-
-struct wl1271_cmd_sched_scan_start {
-       struct wl1271_cmd_header header;
-
-       u8 tag;
-       u8 padding[3];
-} __packed;
-
-struct wl1271_cmd_sched_scan_stop {
-       struct wl1271_cmd_header header;
-
-       u8 tag;
-       u8 padding[3];
-} __packed;
-
-
-#endif /* __WL1271_SCAN_H__ */
diff --git a/drivers/net/wireless/wl12xx/sdio.c b/drivers/net/wireless/wl12xx/sdio.c
deleted file mode 100644 (file)
index 4b3c327..0000000
+++ /dev/null
@@ -1,378 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2009-2010 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/irq.h>
-#include <linux/module.h>
-#include <linux/vmalloc.h>
-#include <linux/platform_device.h>
-#include <linux/mmc/sdio_func.h>
-#include <linux/mmc/sdio_ids.h>
-#include <linux/mmc/card.h>
-#include <linux/mmc/host.h>
-#include <linux/gpio.h>
-#include <linux/wl12xx.h>
-#include <linux/pm_runtime.h>
-
-#include "wl12xx.h"
-#include "wl12xx_80211.h"
-#include "io.h"
-
-#ifndef SDIO_VENDOR_ID_TI
-#define SDIO_VENDOR_ID_TI              0x0097
-#endif
-
-#ifndef SDIO_DEVICE_ID_TI_WL1271
-#define SDIO_DEVICE_ID_TI_WL1271       0x4076
-#endif
-
-struct wl12xx_sdio_glue {
-       struct device *dev;
-       struct platform_device *core;
-};
-
-static const struct sdio_device_id wl1271_devices[] __devinitconst = {
-       { SDIO_DEVICE(SDIO_VENDOR_ID_TI, SDIO_DEVICE_ID_TI_WL1271) },
-       {}
-};
-MODULE_DEVICE_TABLE(sdio, wl1271_devices);
-
-static void wl1271_sdio_set_block_size(struct device *child,
-                                      unsigned int blksz)
-{
-       struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
-       struct sdio_func *func = dev_to_sdio_func(glue->dev);
-
-       sdio_claim_host(func);
-       sdio_set_block_size(func, blksz);
-       sdio_release_host(func);
-}
-
-static void wl12xx_sdio_raw_read(struct device *child, int addr, void *buf,
-                                size_t len, bool fixed)
-{
-       int ret;
-       struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
-       struct sdio_func *func = dev_to_sdio_func(glue->dev);
-
-       sdio_claim_host(func);
-
-       if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
-               ((u8 *)buf)[0] = sdio_f0_readb(func, addr, &ret);
-               dev_dbg(child->parent, "sdio read 52 addr 0x%x, byte 0x%02x\n",
-                       addr, ((u8 *)buf)[0]);
-       } else {
-               if (fixed)
-                       ret = sdio_readsb(func, buf, addr, len);
-               else
-                       ret = sdio_memcpy_fromio(func, buf, addr, len);
-
-               dev_dbg(child->parent, "sdio read 53 addr 0x%x, %zu bytes\n",
-                       addr, len);
-       }
-
-       sdio_release_host(func);
-
-       if (ret)
-               dev_err(child->parent, "sdio read failed (%d)\n", ret);
-}
-
-static void wl12xx_sdio_raw_write(struct device *child, int addr, void *buf,
-                                 size_t len, bool fixed)
-{
-       int ret;
-       struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
-       struct sdio_func *func = dev_to_sdio_func(glue->dev);
-
-       sdio_claim_host(func);
-
-       if (unlikely(addr == HW_ACCESS_ELP_CTRL_REG_ADDR)) {
-               sdio_f0_writeb(func, ((u8 *)buf)[0], addr, &ret);
-               dev_dbg(child->parent, "sdio write 52 addr 0x%x, byte 0x%02x\n",
-                       addr, ((u8 *)buf)[0]);
-       } else {
-               dev_dbg(child->parent, "sdio write 53 addr 0x%x, %zu bytes\n",
-                       addr, len);
-
-               if (fixed)
-                       ret = sdio_writesb(func, addr, buf, len);
-               else
-                       ret = sdio_memcpy_toio(func, addr, buf, len);
-       }
-
-       sdio_release_host(func);
-
-       if (ret)
-               dev_err(child->parent, "sdio write failed (%d)\n", ret);
-}
-
-static int wl12xx_sdio_power_on(struct wl12xx_sdio_glue *glue)
-{
-       int ret;
-       struct sdio_func *func = dev_to_sdio_func(glue->dev);
-
-       /* If enabled, tell runtime PM not to power off the card */
-       if (pm_runtime_enabled(&func->dev)) {
-               ret = pm_runtime_get_sync(&func->dev);
-               if (ret < 0)
-                       goto out;
-       } else {
-               /* Runtime PM is disabled: power up the card manually */
-               ret = mmc_power_restore_host(func->card->host);
-               if (ret < 0)
-                       goto out;
-       }
-
-       sdio_claim_host(func);
-       sdio_enable_func(func);
-       sdio_release_host(func);
-
-out:
-       return ret;
-}
-
-static int wl12xx_sdio_power_off(struct wl12xx_sdio_glue *glue)
-{
-       int ret;
-       struct sdio_func *func = dev_to_sdio_func(glue->dev);
-
-       sdio_claim_host(func);
-       sdio_disable_func(func);
-       sdio_release_host(func);
-
-       /* Power off the card manually, even if runtime PM is enabled. */
-       ret = mmc_power_save_host(func->card->host);
-       if (ret < 0)
-               return ret;
-
-       /* If enabled, let runtime PM know the card is powered off */
-       if (pm_runtime_enabled(&func->dev))
-               ret = pm_runtime_put_sync(&func->dev);
-
-       return ret;
-}
-
-static int wl12xx_sdio_set_power(struct device *child, bool enable)
-{
-       struct wl12xx_sdio_glue *glue = dev_get_drvdata(child->parent);
-
-       if (enable)
-               return wl12xx_sdio_power_on(glue);
-       else
-               return wl12xx_sdio_power_off(glue);
-}
-
-static struct wl1271_if_operations sdio_ops = {
-       .read           = wl12xx_sdio_raw_read,
-       .write          = wl12xx_sdio_raw_write,
-       .power          = wl12xx_sdio_set_power,
-       .set_block_size = wl1271_sdio_set_block_size,
-};
-
-static int __devinit wl1271_probe(struct sdio_func *func,
-                                 const struct sdio_device_id *id)
-{
-       struct wl12xx_platform_data *wlan_data;
-       struct wl12xx_sdio_glue *glue;
-       struct resource res[1];
-       mmc_pm_flag_t mmcflags;
-       int ret = -ENOMEM;
-
-       /* We are only able to handle the wlan function */
-       if (func->num != 0x02)
-               return -ENODEV;
-
-       glue = kzalloc(sizeof(*glue), GFP_KERNEL);
-       if (!glue) {
-               dev_err(&func->dev, "can't allocate glue\n");
-               goto out;
-       }
-
-       glue->dev = &func->dev;
-
-       /* Grab access to FN0 for ELP reg. */
-       func->card->quirks |= MMC_QUIRK_LENIENT_FN0;
-
-       /* Use block mode for transferring over one block size of data */
-       func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
-
-       wlan_data = wl12xx_get_platform_data();
-       if (IS_ERR(wlan_data)) {
-               ret = PTR_ERR(wlan_data);
-               dev_err(glue->dev, "missing wlan platform data: %d\n", ret);
-               goto out_free_glue;
-       }
-
-       /* if sdio can keep power while host is suspended, enable wow */
-       mmcflags = sdio_get_host_pm_caps(func);
-       dev_dbg(glue->dev, "sdio PM caps = 0x%x\n", mmcflags);
-
-       if (mmcflags & MMC_PM_KEEP_POWER)
-               wlan_data->pwr_in_suspend = true;
-
-       wlan_data->ops = &sdio_ops;
-
-       sdio_set_drvdata(func, glue);
-
-       /* Tell PM core that we don't need the card to be powered now */
-       pm_runtime_put_noidle(&func->dev);
-
-       glue->core = platform_device_alloc("wl12xx", -1);
-       if (!glue->core) {
-               dev_err(glue->dev, "can't allocate platform_device");
-               ret = -ENOMEM;
-               goto out_free_glue;
-       }
-
-       glue->core->dev.parent = &func->dev;
-
-       memset(res, 0x00, sizeof(res));
-
-       res[0].start = wlan_data->irq;
-       res[0].flags = IORESOURCE_IRQ;
-       res[0].name = "irq";
-
-       ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
-       if (ret) {
-               dev_err(glue->dev, "can't add resources\n");
-               goto out_dev_put;
-       }
-
-       ret = platform_device_add_data(glue->core, wlan_data,
-                                      sizeof(*wlan_data));
-       if (ret) {
-               dev_err(glue->dev, "can't add platform data\n");
-               goto out_dev_put;
-       }
-
-       ret = platform_device_add(glue->core);
-       if (ret) {
-               dev_err(glue->dev, "can't add platform device\n");
-               goto out_dev_put;
-       }
-       return 0;
-
-out_dev_put:
-       platform_device_put(glue->core);
-
-out_free_glue:
-       kfree(glue);
-
-out:
-       return ret;
-}
-
-static void __devexit wl1271_remove(struct sdio_func *func)
-{
-       struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
-
-       /* Undo decrement done above in wl1271_probe */
-       pm_runtime_get_noresume(&func->dev);
-
-       platform_device_del(glue->core);
-       platform_device_put(glue->core);
-       kfree(glue);
-}
-
-#ifdef CONFIG_PM
-static int wl1271_suspend(struct device *dev)
-{
-       /* Tell MMC/SDIO core it's OK to power down the card
-        * (if it isn't already), but not to remove it completely */
-       struct sdio_func *func = dev_to_sdio_func(dev);
-       struct wl12xx_sdio_glue *glue = sdio_get_drvdata(func);
-       struct wl1271 *wl = platform_get_drvdata(glue->core);
-       mmc_pm_flag_t sdio_flags;
-       int ret = 0;
-
-       dev_dbg(dev, "wl1271 suspend. wow_enabled: %d\n",
-               wl->wow_enabled);
-
-       /* check whether sdio should keep power */
-       if (wl->wow_enabled) {
-               sdio_flags = sdio_get_host_pm_caps(func);
-
-               if (!(sdio_flags & MMC_PM_KEEP_POWER)) {
-                       dev_err(dev, "can't keep power while host "
-                                    "is suspended\n");
-                       ret = -EINVAL;
-                       goto out;
-               }
-
-               /* keep power while host suspended */
-               ret = sdio_set_host_pm_flags(func, MMC_PM_KEEP_POWER);
-               if (ret) {
-                       dev_err(dev, "error while trying to keep power\n");
-                       goto out;
-               }
-       }
-out:
-       return ret;
-}
-
-static int wl1271_resume(struct device *dev)
-{
-       dev_dbg(dev, "wl1271 resume\n");
-
-       return 0;
-}
-
-static const struct dev_pm_ops wl1271_sdio_pm_ops = {
-       .suspend        = wl1271_suspend,
-       .resume         = wl1271_resume,
-};
-#endif
-
-static struct sdio_driver wl1271_sdio_driver = {
-       .name           = "wl1271_sdio",
-       .id_table       = wl1271_devices,
-       .probe          = wl1271_probe,
-       .remove         = __devexit_p(wl1271_remove),
-#ifdef CONFIG_PM
-       .drv = {
-               .pm = &wl1271_sdio_pm_ops,
-       },
-#endif
-};
-
-static int __init wl1271_init(void)
-{
-       return sdio_register_driver(&wl1271_sdio_driver);
-}
-
-static void __exit wl1271_exit(void)
-{
-       sdio_unregister_driver(&wl1271_sdio_driver);
-}
-
-module_init(wl1271_init);
-module_exit(wl1271_exit);
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
-MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
-MODULE_FIRMWARE(WL127X_FW_NAME_SINGLE);
-MODULE_FIRMWARE(WL127X_FW_NAME_MULTI);
-MODULE_FIRMWARE(WL127X_PLT_FW_NAME);
-MODULE_FIRMWARE(WL128X_FW_NAME_SINGLE);
-MODULE_FIRMWARE(WL128X_FW_NAME_MULTI);
-MODULE_FIRMWARE(WL128X_PLT_FW_NAME);
diff --git a/drivers/net/wireless/wl12xx/spi.c b/drivers/net/wireless/wl12xx/spi.c
deleted file mode 100644 (file)
index 2fc18a8..0000000
+++ /dev/null
@@ -1,442 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2008-2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/interrupt.h>
-#include <linux/irq.h>
-#include <linux/module.h>
-#include <linux/crc7.h>
-#include <linux/spi/spi.h>
-#include <linux/wl12xx.h>
-#include <linux/platform_device.h>
-#include <linux/slab.h>
-
-#include "wl12xx.h"
-#include "wl12xx_80211.h"
-#include "io.h"
-
-#include "reg.h"
-
-#define WSPI_CMD_READ                 0x40000000
-#define WSPI_CMD_WRITE                0x00000000
-#define WSPI_CMD_FIXED                0x20000000
-#define WSPI_CMD_BYTE_LENGTH          0x1FFE0000
-#define WSPI_CMD_BYTE_LENGTH_OFFSET   17
-#define WSPI_CMD_BYTE_ADDR            0x0001FFFF
-
-#define WSPI_INIT_CMD_CRC_LEN       5
-
-#define WSPI_INIT_CMD_START         0x00
-#define WSPI_INIT_CMD_TX            0x40
-/* the extra bypass bit is sampled by the TNET as '1' */
-#define WSPI_INIT_CMD_BYPASS_BIT    0x80
-#define WSPI_INIT_CMD_FIXEDBUSY_LEN 0x07
-#define WSPI_INIT_CMD_EN_FIXEDBUSY  0x80
-#define WSPI_INIT_CMD_DIS_FIXEDBUSY 0x00
-#define WSPI_INIT_CMD_IOD           0x40
-#define WSPI_INIT_CMD_IP            0x20
-#define WSPI_INIT_CMD_CS            0x10
-#define WSPI_INIT_CMD_WS            0x08
-#define WSPI_INIT_CMD_WSPI          0x01
-#define WSPI_INIT_CMD_END           0x01
-
-#define WSPI_INIT_CMD_LEN           8
-
-#define HW_ACCESS_WSPI_FIXED_BUSY_LEN \
-               ((WL1271_BUSY_WORD_LEN - 4) / sizeof(u32))
-#define HW_ACCESS_WSPI_INIT_CMD_MASK  0
-
-/* HW limitation: maximum possible chunk size is 4095 bytes */
-#define WSPI_MAX_CHUNK_SIZE    4092
-
-#define WSPI_MAX_NUM_OF_CHUNKS (WL1271_AGGR_BUFFER_SIZE / WSPI_MAX_CHUNK_SIZE)
-
-struct wl12xx_spi_glue {
-       struct device *dev;
-       struct platform_device *core;
-};
-
-static void wl12xx_spi_reset(struct device *child)
-{
-       struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
-       u8 *cmd;
-       struct spi_transfer t;
-       struct spi_message m;
-
-       cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
-       if (!cmd) {
-               dev_err(child->parent,
-                       "could not allocate cmd for spi reset\n");
-               return;
-       }
-
-       memset(&t, 0, sizeof(t));
-       spi_message_init(&m);
-
-       memset(cmd, 0xff, WSPI_INIT_CMD_LEN);
-
-       t.tx_buf = cmd;
-       t.len = WSPI_INIT_CMD_LEN;
-       spi_message_add_tail(&t, &m);
-
-       spi_sync(to_spi_device(glue->dev), &m);
-
-       kfree(cmd);
-}
-
-static void wl12xx_spi_init(struct device *child)
-{
-       struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
-       u8 crc[WSPI_INIT_CMD_CRC_LEN], *cmd;
-       struct spi_transfer t;
-       struct spi_message m;
-
-       cmd = kzalloc(WSPI_INIT_CMD_LEN, GFP_KERNEL);
-       if (!cmd) {
-               dev_err(child->parent,
-                       "could not allocate cmd for spi init\n");
-               return;
-       }
-
-       memset(crc, 0, sizeof(crc));
-       memset(&t, 0, sizeof(t));
-       spi_message_init(&m);
-
-       /*
-        * Set WSPI_INIT_COMMAND
-        * the data is being send from the MSB to LSB
-        */
-       cmd[2] = 0xff;
-       cmd[3] = 0xff;
-       cmd[1] = WSPI_INIT_CMD_START | WSPI_INIT_CMD_TX;
-       cmd[0] = 0;
-       cmd[7] = 0;
-       cmd[6] |= HW_ACCESS_WSPI_INIT_CMD_MASK << 3;
-       cmd[6] |= HW_ACCESS_WSPI_FIXED_BUSY_LEN & WSPI_INIT_CMD_FIXEDBUSY_LEN;
-
-       if (HW_ACCESS_WSPI_FIXED_BUSY_LEN == 0)
-               cmd[5] |=  WSPI_INIT_CMD_DIS_FIXEDBUSY;
-       else
-               cmd[5] |= WSPI_INIT_CMD_EN_FIXEDBUSY;
-
-       cmd[5] |= WSPI_INIT_CMD_IOD | WSPI_INIT_CMD_IP | WSPI_INIT_CMD_CS
-               | WSPI_INIT_CMD_WSPI | WSPI_INIT_CMD_WS;
-
-       crc[0] = cmd[1];
-       crc[1] = cmd[0];
-       crc[2] = cmd[7];
-       crc[3] = cmd[6];
-       crc[4] = cmd[5];
-
-       cmd[4] |= crc7(0, crc, WSPI_INIT_CMD_CRC_LEN) << 1;
-       cmd[4] |= WSPI_INIT_CMD_END;
-
-       t.tx_buf = cmd;
-       t.len = WSPI_INIT_CMD_LEN;
-       spi_message_add_tail(&t, &m);
-
-       spi_sync(to_spi_device(glue->dev), &m);
-       kfree(cmd);
-}
-
-#define WL1271_BUSY_WORD_TIMEOUT 1000
-
-static int wl12xx_spi_read_busy(struct device *child)
-{
-       struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
-       struct wl1271 *wl = dev_get_drvdata(child);
-       struct spi_transfer t[1];
-       struct spi_message m;
-       u32 *busy_buf;
-       int num_busy_bytes = 0;
-
-       /*
-        * Read further busy words from SPI until a non-busy word is
-        * encountered, then read the data itself into the buffer.
-        */
-
-       num_busy_bytes = WL1271_BUSY_WORD_TIMEOUT;
-       busy_buf = wl->buffer_busyword;
-       while (num_busy_bytes) {
-               num_busy_bytes--;
-               spi_message_init(&m);
-               memset(t, 0, sizeof(t));
-               t[0].rx_buf = busy_buf;
-               t[0].len = sizeof(u32);
-               t[0].cs_change = true;
-               spi_message_add_tail(&t[0], &m);
-               spi_sync(to_spi_device(glue->dev), &m);
-
-               if (*busy_buf & 0x1)
-                       return 0;
-       }
-
-       /* The SPI bus is unresponsive, the read failed. */
-       dev_err(child->parent, "SPI read busy-word timeout!\n");
-       return -ETIMEDOUT;
-}
-
-static void wl12xx_spi_raw_read(struct device *child, int addr, void *buf,
-                               size_t len, bool fixed)
-{
-       struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
-       struct wl1271 *wl = dev_get_drvdata(child);
-       struct spi_transfer t[2];
-       struct spi_message m;
-       u32 *busy_buf;
-       u32 *cmd;
-       u32 chunk_len;
-
-       while (len > 0) {
-               chunk_len = min((size_t)WSPI_MAX_CHUNK_SIZE, len);
-
-               cmd = &wl->buffer_cmd;
-               busy_buf = wl->buffer_busyword;
-
-               *cmd = 0;
-               *cmd |= WSPI_CMD_READ;
-               *cmd |= (chunk_len << WSPI_CMD_BYTE_LENGTH_OFFSET) &
-                       WSPI_CMD_BYTE_LENGTH;
-               *cmd |= addr & WSPI_CMD_BYTE_ADDR;
-
-               if (fixed)
-                       *cmd |= WSPI_CMD_FIXED;
-
-               spi_message_init(&m);
-               memset(t, 0, sizeof(t));
-
-               t[0].tx_buf = cmd;
-               t[0].len = 4;
-               t[0].cs_change = true;
-               spi_message_add_tail(&t[0], &m);
-
-               /* Busy and non busy words read */
-               t[1].rx_buf = busy_buf;
-               t[1].len = WL1271_BUSY_WORD_LEN;
-               t[1].cs_change = true;
-               spi_message_add_tail(&t[1], &m);
-
-               spi_sync(to_spi_device(glue->dev), &m);
-
-               if (!(busy_buf[WL1271_BUSY_WORD_CNT - 1] & 0x1) &&
-                   wl12xx_spi_read_busy(child)) {
-                       memset(buf, 0, chunk_len);
-                       return;
-               }
-
-               spi_message_init(&m);
-               memset(t, 0, sizeof(t));
-
-               t[0].rx_buf = buf;
-               t[0].len = chunk_len;
-               t[0].cs_change = true;
-               spi_message_add_tail(&t[0], &m);
-
-               spi_sync(to_spi_device(glue->dev), &m);
-
-               if (!fixed)
-                       addr += chunk_len;
-               buf += chunk_len;
-               len -= chunk_len;
-       }
-}
-
-static void wl12xx_spi_raw_write(struct device *child, int addr, void *buf,
-                                size_t len, bool fixed)
-{
-       struct wl12xx_spi_glue *glue = dev_get_drvdata(child->parent);
-       struct spi_transfer t[2 * WSPI_MAX_NUM_OF_CHUNKS];
-       struct spi_message m;
-       u32 commands[WSPI_MAX_NUM_OF_CHUNKS];
-       u32 *cmd;
-       u32 chunk_len;
-       int i;
-
-       WARN_ON(len > WL1271_AGGR_BUFFER_SIZE);
-
-       spi_message_init(&m);
-       memset(t, 0, sizeof(t));
-
-       cmd = &commands[0];
-       i = 0;
-       while (len > 0) {
-               chunk_len = min((size_t)WSPI_MAX_CHUNK_SIZE, len);
-
-               *cmd = 0;
-               *cmd |= WSPI_CMD_WRITE;
-               *cmd |= (chunk_len << WSPI_CMD_BYTE_LENGTH_OFFSET) &
-                       WSPI_CMD_BYTE_LENGTH;
-               *cmd |= addr & WSPI_CMD_BYTE_ADDR;
-
-               if (fixed)
-                       *cmd |= WSPI_CMD_FIXED;
-
-               t[i].tx_buf = cmd;
-               t[i].len = sizeof(*cmd);
-               spi_message_add_tail(&t[i++], &m);
-
-               t[i].tx_buf = buf;
-               t[i].len = chunk_len;
-               spi_message_add_tail(&t[i++], &m);
-
-               if (!fixed)
-                       addr += chunk_len;
-               buf += chunk_len;
-               len -= chunk_len;
-               cmd++;
-       }
-
-       spi_sync(to_spi_device(glue->dev), &m);
-}
-
-static struct wl1271_if_operations spi_ops = {
-       .read           = wl12xx_spi_raw_read,
-       .write          = wl12xx_spi_raw_write,
-       .reset          = wl12xx_spi_reset,
-       .init           = wl12xx_spi_init,
-       .set_block_size = NULL,
-};
-
-static int __devinit wl1271_probe(struct spi_device *spi)
-{
-       struct wl12xx_spi_glue *glue;
-       struct wl12xx_platform_data *pdata;
-       struct resource res[1];
-       int ret = -ENOMEM;
-
-       pdata = spi->dev.platform_data;
-       if (!pdata) {
-               dev_err(&spi->dev, "no platform data\n");
-               return -ENODEV;
-       }
-
-       pdata->ops = &spi_ops;
-
-       glue = kzalloc(sizeof(*glue), GFP_KERNEL);
-       if (!glue) {
-               dev_err(&spi->dev, "can't allocate glue\n");
-               goto out;
-       }
-
-       glue->dev = &spi->dev;
-
-       spi_set_drvdata(spi, glue);
-
-       /* This is the only SPI value that we need to set here, the rest
-        * comes from the board-peripherals file */
-       spi->bits_per_word = 32;
-
-       ret = spi_setup(spi);
-       if (ret < 0) {
-               dev_err(glue->dev, "spi_setup failed\n");
-               goto out_free_glue;
-       }
-
-       glue->core = platform_device_alloc("wl12xx", -1);
-       if (!glue->core) {
-               dev_err(glue->dev, "can't allocate platform_device\n");
-               ret = -ENOMEM;
-               goto out_free_glue;
-       }
-
-       glue->core->dev.parent = &spi->dev;
-
-       memset(res, 0x00, sizeof(res));
-
-       res[0].start = spi->irq;
-       res[0].flags = IORESOURCE_IRQ;
-       res[0].name = "irq";
-
-       ret = platform_device_add_resources(glue->core, res, ARRAY_SIZE(res));
-       if (ret) {
-               dev_err(glue->dev, "can't add resources\n");
-               goto out_dev_put;
-       }
-
-       ret = platform_device_add_data(glue->core, pdata, sizeof(*pdata));
-       if (ret) {
-               dev_err(glue->dev, "can't add platform data\n");
-               goto out_dev_put;
-       }
-
-       ret = platform_device_add(glue->core);
-       if (ret) {
-               dev_err(glue->dev, "can't register platform device\n");
-               goto out_dev_put;
-       }
-
-       return 0;
-
-out_dev_put:
-       platform_device_put(glue->core);
-
-out_free_glue:
-       kfree(glue);
-out:
-       return ret;
-}
-
-static int __devexit wl1271_remove(struct spi_device *spi)
-{
-       struct wl12xx_spi_glue *glue = spi_get_drvdata(spi);
-
-       platform_device_del(glue->core);
-       platform_device_put(glue->core);
-       kfree(glue);
-
-       return 0;
-}
-
-
-static struct spi_driver wl1271_spi_driver = {
-       .driver = {
-               .name           = "wl1271_spi",
-               .owner          = THIS_MODULE,
-       },
-
-       .probe          = wl1271_probe,
-       .remove         = __devexit_p(wl1271_remove),
-};
-
-static int __init wl1271_init(void)
-{
-       return spi_register_driver(&wl1271_spi_driver);
-}
-
-static void __exit wl1271_exit(void)
-{
-       spi_unregister_driver(&wl1271_spi_driver);
-}
-
-module_init(wl1271_init);
-module_exit(wl1271_exit);
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
-MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
-MODULE_FIRMWARE(WL127X_FW_NAME_SINGLE);
-MODULE_FIRMWARE(WL127X_FW_NAME_MULTI);
-MODULE_FIRMWARE(WL127X_PLT_FW_NAME);
-MODULE_FIRMWARE(WL128X_FW_NAME_SINGLE);
-MODULE_FIRMWARE(WL128X_FW_NAME_MULTI);
-MODULE_FIRMWARE(WL128X_PLT_FW_NAME);
-MODULE_ALIAS("spi:wl1271");
diff --git a/drivers/net/wireless/wl12xx/testmode.c b/drivers/net/wireless/wl12xx/testmode.c
deleted file mode 100644 (file)
index b41428f..0000000
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2010 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-#include "testmode.h"
-
-#include <linux/slab.h>
-#include <net/genetlink.h>
-
-#include "wl12xx.h"
-#include "debug.h"
-#include "acx.h"
-#include "reg.h"
-#include "ps.h"
-#include "io.h"
-
-#define WL1271_TM_MAX_DATA_LENGTH 1024
-
-enum wl1271_tm_commands {
-       WL1271_TM_CMD_UNSPEC,
-       WL1271_TM_CMD_TEST,
-       WL1271_TM_CMD_INTERROGATE,
-       WL1271_TM_CMD_CONFIGURE,
-       WL1271_TM_CMD_NVS_PUSH,         /* Not in use. Keep to not break ABI */
-       WL1271_TM_CMD_SET_PLT_MODE,
-       WL1271_TM_CMD_RECOVER,
-       WL1271_TM_CMD_GET_MAC,
-
-       __WL1271_TM_CMD_AFTER_LAST
-};
-#define WL1271_TM_CMD_MAX (__WL1271_TM_CMD_AFTER_LAST - 1)
-
-enum wl1271_tm_attrs {
-       WL1271_TM_ATTR_UNSPEC,
-       WL1271_TM_ATTR_CMD_ID,
-       WL1271_TM_ATTR_ANSWER,
-       WL1271_TM_ATTR_DATA,
-       WL1271_TM_ATTR_IE_ID,
-       WL1271_TM_ATTR_PLT_MODE,
-
-       __WL1271_TM_ATTR_AFTER_LAST
-};
-#define WL1271_TM_ATTR_MAX (__WL1271_TM_ATTR_AFTER_LAST - 1)
-
-static struct nla_policy wl1271_tm_policy[WL1271_TM_ATTR_MAX + 1] = {
-       [WL1271_TM_ATTR_CMD_ID] =       { .type = NLA_U32 },
-       [WL1271_TM_ATTR_ANSWER] =       { .type = NLA_U8 },
-       [WL1271_TM_ATTR_DATA] =         { .type = NLA_BINARY,
-                                         .len = WL1271_TM_MAX_DATA_LENGTH },
-       [WL1271_TM_ATTR_IE_ID] =        { .type = NLA_U32 },
-       [WL1271_TM_ATTR_PLT_MODE] =     { .type = NLA_U32 },
-};
-
-
-static int wl1271_tm_cmd_test(struct wl1271 *wl, struct nlattr *tb[])
-{
-       int buf_len, ret, len;
-       struct sk_buff *skb;
-       void *buf;
-       u8 answer = 0;
-
-       wl1271_debug(DEBUG_TESTMODE, "testmode cmd test");
-
-       if (!tb[WL1271_TM_ATTR_DATA])
-               return -EINVAL;
-
-       buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
-       buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
-
-       if (tb[WL1271_TM_ATTR_ANSWER])
-               answer = nla_get_u8(tb[WL1271_TM_ATTR_ANSWER]);
-
-       if (buf_len > sizeof(struct wl1271_command))
-               return -EMSGSIZE;
-
-       mutex_lock(&wl->mutex);
-
-       if (wl->state == WL1271_STATE_OFF) {
-               ret = -EINVAL;
-               goto out;
-       }
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       ret = wl1271_cmd_test(wl, buf, buf_len, answer);
-       if (ret < 0) {
-               wl1271_warning("testmode cmd test failed: %d", ret);
-               goto out_sleep;
-       }
-
-       if (answer) {
-               len = nla_total_size(buf_len);
-               skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, len);
-               if (!skb) {
-                       ret = -ENOMEM;
-                       goto out_sleep;
-               }
-
-               if (nla_put(skb, WL1271_TM_ATTR_DATA, buf_len, buf))
-                       goto nla_put_failure;
-               ret = cfg80211_testmode_reply(skb);
-               if (ret < 0)
-                       goto out_sleep;
-       }
-
-out_sleep:
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-
-nla_put_failure:
-       kfree_skb(skb);
-       ret = -EMSGSIZE;
-       goto out_sleep;
-}
-
-static int wl1271_tm_cmd_interrogate(struct wl1271 *wl, struct nlattr *tb[])
-{
-       int ret;
-       struct wl1271_command *cmd;
-       struct sk_buff *skb;
-       u8 ie_id;
-
-       wl1271_debug(DEBUG_TESTMODE, "testmode cmd interrogate");
-
-       if (!tb[WL1271_TM_ATTR_IE_ID])
-               return -EINVAL;
-
-       ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
-
-       mutex_lock(&wl->mutex);
-
-       if (wl->state == WL1271_STATE_OFF) {
-               ret = -EINVAL;
-               goto out;
-       }
-
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
-       if (!cmd) {
-               ret = -ENOMEM;
-               goto out_sleep;
-       }
-
-       ret = wl1271_cmd_interrogate(wl, ie_id, cmd, sizeof(*cmd));
-       if (ret < 0) {
-               wl1271_warning("testmode cmd interrogate failed: %d", ret);
-               goto out_free;
-       }
-
-       skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, sizeof(*cmd));
-       if (!skb) {
-               ret = -ENOMEM;
-               goto out_free;
-       }
-
-       if (nla_put(skb, WL1271_TM_ATTR_DATA, sizeof(*cmd), cmd))
-               goto nla_put_failure;
-       ret = cfg80211_testmode_reply(skb);
-       if (ret < 0)
-               goto out_free;
-
-out_free:
-       kfree(cmd);
-out_sleep:
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-
-       return ret;
-
-nla_put_failure:
-       kfree_skb(skb);
-       ret = -EMSGSIZE;
-       goto out_free;
-}
-
-static int wl1271_tm_cmd_configure(struct wl1271 *wl, struct nlattr *tb[])
-{
-       int buf_len, ret;
-       void *buf;
-       u8 ie_id;
-
-       wl1271_debug(DEBUG_TESTMODE, "testmode cmd configure");
-
-       if (!tb[WL1271_TM_ATTR_DATA])
-               return -EINVAL;
-       if (!tb[WL1271_TM_ATTR_IE_ID])
-               return -EINVAL;
-
-       ie_id = nla_get_u8(tb[WL1271_TM_ATTR_IE_ID]);
-       buf = nla_data(tb[WL1271_TM_ATTR_DATA]);
-       buf_len = nla_len(tb[WL1271_TM_ATTR_DATA]);
-
-       if (buf_len > sizeof(struct wl1271_command))
-               return -EMSGSIZE;
-
-       mutex_lock(&wl->mutex);
-       ret = wl1271_cmd_configure(wl, ie_id, buf, buf_len);
-       mutex_unlock(&wl->mutex);
-
-       if (ret < 0) {
-               wl1271_warning("testmode cmd configure failed: %d", ret);
-               return ret;
-       }
-
-       return 0;
-}
-
-static int wl1271_tm_cmd_set_plt_mode(struct wl1271 *wl, struct nlattr *tb[])
-{
-       u32 val;
-       int ret;
-
-       wl1271_debug(DEBUG_TESTMODE, "testmode cmd set plt mode");
-
-       if (!tb[WL1271_TM_ATTR_PLT_MODE])
-               return -EINVAL;
-
-       val = nla_get_u32(tb[WL1271_TM_ATTR_PLT_MODE]);
-
-       switch (val) {
-       case 0:
-               ret = wl1271_plt_stop(wl);
-               break;
-       case 1:
-               ret = wl1271_plt_start(wl);
-               break;
-       default:
-               ret = -EINVAL;
-               break;
-       }
-
-       return ret;
-}
-
-static int wl1271_tm_cmd_recover(struct wl1271 *wl, struct nlattr *tb[])
-{
-       wl1271_debug(DEBUG_TESTMODE, "testmode cmd recover");
-
-       wl12xx_queue_recovery_work(wl);
-
-       return 0;
-}
-
-static int wl12xx_tm_cmd_get_mac(struct wl1271 *wl, struct nlattr *tb[])
-{
-       struct sk_buff *skb;
-       u8 mac_addr[ETH_ALEN];
-       int ret = 0;
-
-       mutex_lock(&wl->mutex);
-
-       if (!wl->plt) {
-               ret = -EINVAL;
-               goto out;
-       }
-
-       if (wl->fuse_oui_addr == 0 && wl->fuse_nic_addr == 0) {
-               ret = -EOPNOTSUPP;
-               goto out;
-       }
-
-       mac_addr[0] = (u8)(wl->fuse_oui_addr >> 16);
-       mac_addr[1] = (u8)(wl->fuse_oui_addr >> 8);
-       mac_addr[2] = (u8) wl->fuse_oui_addr;
-       mac_addr[3] = (u8)(wl->fuse_nic_addr >> 16);
-       mac_addr[4] = (u8)(wl->fuse_nic_addr >> 8);
-       mac_addr[5] = (u8) wl->fuse_nic_addr;
-
-       skb = cfg80211_testmode_alloc_reply_skb(wl->hw->wiphy, ETH_ALEN);
-       if (!skb) {
-               ret = -ENOMEM;
-               goto out;
-       }
-
-       if (nla_put(skb, WL1271_TM_ATTR_DATA, ETH_ALEN, mac_addr))
-               goto nla_put_failure;
-       ret = cfg80211_testmode_reply(skb);
-       if (ret < 0)
-               goto out;
-
-out:
-       mutex_unlock(&wl->mutex);
-       return ret;
-
-nla_put_failure:
-       kfree_skb(skb);
-       ret = -EMSGSIZE;
-       goto out;
-}
-
-int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len)
-{
-       struct wl1271 *wl = hw->priv;
-       struct nlattr *tb[WL1271_TM_ATTR_MAX + 1];
-       int err;
-
-       err = nla_parse(tb, WL1271_TM_ATTR_MAX, data, len, wl1271_tm_policy);
-       if (err)
-               return err;
-
-       if (!tb[WL1271_TM_ATTR_CMD_ID])
-               return -EINVAL;
-
-       switch (nla_get_u32(tb[WL1271_TM_ATTR_CMD_ID])) {
-       case WL1271_TM_CMD_TEST:
-               return wl1271_tm_cmd_test(wl, tb);
-       case WL1271_TM_CMD_INTERROGATE:
-               return wl1271_tm_cmd_interrogate(wl, tb);
-       case WL1271_TM_CMD_CONFIGURE:
-               return wl1271_tm_cmd_configure(wl, tb);
-       case WL1271_TM_CMD_SET_PLT_MODE:
-               return wl1271_tm_cmd_set_plt_mode(wl, tb);
-       case WL1271_TM_CMD_RECOVER:
-               return wl1271_tm_cmd_recover(wl, tb);
-       case WL1271_TM_CMD_GET_MAC:
-               return wl12xx_tm_cmd_get_mac(wl, tb);
-       default:
-               return -EOPNOTSUPP;
-       }
-}
diff --git a/drivers/net/wireless/wl12xx/testmode.h b/drivers/net/wireless/wl12xx/testmode.h
deleted file mode 100644 (file)
index 8071654..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2010 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __TESTMODE_H__
-#define __TESTMODE_H__
-
-#include <net/mac80211.h>
-
-int wl1271_tm_cmd(struct ieee80211_hw *hw, void *data, int len);
-
-#endif /* __WL1271_TESTMODE_H__ */
diff --git a/drivers/net/wireless/wl12xx/tx.c b/drivers/net/wireless/wl12xx/tx.c
deleted file mode 100644 (file)
index 43ae491..0000000
+++ /dev/null
@@ -1,1079 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/etherdevice.h>
-
-#include "wl12xx.h"
-#include "debug.h"
-#include "io.h"
-#include "reg.h"
-#include "ps.h"
-#include "tx.h"
-#include "event.h"
-
-static int wl1271_set_default_wep_key(struct wl1271 *wl,
-                                     struct wl12xx_vif *wlvif, u8 id)
-{
-       int ret;
-       bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
-
-       if (is_ap)
-               ret = wl12xx_cmd_set_default_wep_key(wl, id,
-                                                    wlvif->ap.bcast_hlid);
-       else
-               ret = wl12xx_cmd_set_default_wep_key(wl, id, wlvif->sta.hlid);
-
-       if (ret < 0)
-               return ret;
-
-       wl1271_debug(DEBUG_CRYPT, "default wep key idx: %d", (int)id);
-       return 0;
-}
-
-static int wl1271_alloc_tx_id(struct wl1271 *wl, struct sk_buff *skb)
-{
-       int id;
-
-       id = find_first_zero_bit(wl->tx_frames_map, ACX_TX_DESCRIPTORS);
-       if (id >= ACX_TX_DESCRIPTORS)
-               return -EBUSY;
-
-       __set_bit(id, wl->tx_frames_map);
-       wl->tx_frames[id] = skb;
-       wl->tx_frames_cnt++;
-       return id;
-}
-
-static void wl1271_free_tx_id(struct wl1271 *wl, int id)
-{
-       if (__test_and_clear_bit(id, wl->tx_frames_map)) {
-               if (unlikely(wl->tx_frames_cnt == ACX_TX_DESCRIPTORS))
-                       clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
-
-               wl->tx_frames[id] = NULL;
-               wl->tx_frames_cnt--;
-       }
-}
-
-static void wl1271_tx_ap_update_inconnection_sta(struct wl1271 *wl,
-                                                struct sk_buff *skb)
-{
-       struct ieee80211_hdr *hdr;
-
-       /*
-        * add the station to the known list before transmitting the
-        * authentication response. this way it won't get de-authed by FW
-        * when transmitting too soon.
-        */
-       hdr = (struct ieee80211_hdr *)(skb->data +
-                                      sizeof(struct wl1271_tx_hw_descr));
-       if (ieee80211_is_auth(hdr->frame_control))
-               wl1271_acx_set_inconnection_sta(wl, hdr->addr1);
-}
-
-static void wl1271_tx_regulate_link(struct wl1271 *wl,
-                                   struct wl12xx_vif *wlvif,
-                                   u8 hlid)
-{
-       bool fw_ps, single_sta;
-       u8 tx_pkts;
-
-       if (WARN_ON(!test_bit(hlid, wlvif->links_map)))
-               return;
-
-       fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
-       tx_pkts = wl->links[hlid].allocated_pkts;
-       single_sta = (wl->active_sta_count == 1);
-
-       /*
-        * if in FW PS and there is enough data in FW we can put the link
-        * into high-level PS and clean out its TX queues.
-        * Make an exception if this is the only connected station. In this
-        * case FW-memory congestion is not a problem.
-        */
-       if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
-               wl12xx_ps_link_start(wl, wlvif, hlid, true);
-}
-
-bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb)
-{
-       return wl->dummy_packet == skb;
-}
-
-u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                        struct sk_buff *skb)
-{
-       struct ieee80211_tx_info *control = IEEE80211_SKB_CB(skb);
-
-       if (control->control.sta) {
-               struct wl1271_station *wl_sta;
-
-               wl_sta = (struct wl1271_station *)
-                               control->control.sta->drv_priv;
-               return wl_sta->hlid;
-       } else {
-               struct ieee80211_hdr *hdr;
-
-               if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
-                       return wl->system_hlid;
-
-               hdr = (struct ieee80211_hdr *)skb->data;
-               if (ieee80211_is_mgmt(hdr->frame_control))
-                       return wlvif->ap.global_hlid;
-               else
-                       return wlvif->ap.bcast_hlid;
-       }
-}
-
-u8 wl12xx_tx_get_hlid(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                     struct sk_buff *skb)
-{
-       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
-
-       if (!wlvif || wl12xx_is_dummy_packet(wl, skb))
-               return wl->system_hlid;
-
-       if (wlvif->bss_type == BSS_TYPE_AP_BSS)
-               return wl12xx_tx_get_hlid_ap(wl, wlvif, skb);
-
-       if ((test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
-            test_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags)) &&
-           !ieee80211_is_auth(hdr->frame_control) &&
-           !ieee80211_is_assoc_req(hdr->frame_control))
-               return wlvif->sta.hlid;
-       else
-               return wlvif->dev_hlid;
-}
-
-static unsigned int wl12xx_calc_packet_alignment(struct wl1271 *wl,
-                                               unsigned int packet_length)
-{
-       if (wl->quirks & WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT)
-               return ALIGN(packet_length, WL1271_TX_ALIGN_TO);
-       else
-               return ALIGN(packet_length, WL12XX_BUS_BLOCK_SIZE);
-}
-
-static int wl1271_tx_allocate(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                             struct sk_buff *skb, u32 extra, u32 buf_offset,
-                             u8 hlid)
-{
-       struct wl1271_tx_hw_descr *desc;
-       u32 total_len = skb->len + sizeof(struct wl1271_tx_hw_descr) + extra;
-       u32 len;
-       u32 total_blocks;
-       int id, ret = -EBUSY, ac;
-       u32 spare_blocks = wl->tx_spare_blocks;
-       bool is_dummy = false;
-
-       if (buf_offset + total_len > WL1271_AGGR_BUFFER_SIZE)
-               return -EAGAIN;
-
-       /* allocate free identifier for the packet */
-       id = wl1271_alloc_tx_id(wl, skb);
-       if (id < 0)
-               return id;
-
-       /* approximate the number of blocks required for this packet
-          in the firmware */
-       len = wl12xx_calc_packet_alignment(wl, total_len);
-
-       /* in case of a dummy packet, use default amount of spare mem blocks */
-       if (unlikely(wl12xx_is_dummy_packet(wl, skb))) {
-               is_dummy = true;
-               spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
-       }
-
-       total_blocks = (len + TX_HW_BLOCK_SIZE - 1) / TX_HW_BLOCK_SIZE +
-               spare_blocks;
-
-       if (total_blocks <= wl->tx_blocks_available) {
-               desc = (struct wl1271_tx_hw_descr *)skb_push(
-                       skb, total_len - skb->len);
-
-               /* HW descriptor fields change between wl127x and wl128x */
-               if (wl->chip.id == CHIP_ID_1283_PG20) {
-                       desc->wl128x_mem.total_mem_blocks = total_blocks;
-               } else {
-                       desc->wl127x_mem.extra_blocks = spare_blocks;
-                       desc->wl127x_mem.total_mem_blocks = total_blocks;
-               }
-
-               desc->id = id;
-
-               wl->tx_blocks_available -= total_blocks;
-               wl->tx_allocated_blocks += total_blocks;
-
-               /* If the FW was empty before, arm the Tx watchdog */
-               if (wl->tx_allocated_blocks == total_blocks)
-                       wl12xx_rearm_tx_watchdog_locked(wl);
-
-               ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
-               wl->tx_allocated_pkts[ac]++;
-
-               if (!is_dummy && wlvif &&
-                   wlvif->bss_type == BSS_TYPE_AP_BSS &&
-                   test_bit(hlid, wlvif->ap.sta_hlid_map))
-                       wl->links[hlid].allocated_pkts++;
-
-               ret = 0;
-
-               wl1271_debug(DEBUG_TX,
-                            "tx_allocate: size: %d, blocks: %d, id: %d",
-                            total_len, total_blocks, id);
-       } else {
-               wl1271_free_tx_id(wl, id);
-       }
-
-       return ret;
-}
-
-static void wl1271_tx_fill_hdr(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                              struct sk_buff *skb, u32 extra,
-                              struct ieee80211_tx_info *control, u8 hlid)
-{
-       struct timespec ts;
-       struct wl1271_tx_hw_descr *desc;
-       int aligned_len, ac, rate_idx;
-       s64 hosttime;
-       u16 tx_attr = 0;
-       __le16 frame_control;
-       struct ieee80211_hdr *hdr;
-       u8 *frame_start;
-       bool is_dummy;
-
-       desc = (struct wl1271_tx_hw_descr *) skb->data;
-       frame_start = (u8 *)(desc + 1);
-       hdr = (struct ieee80211_hdr *)(frame_start + extra);
-       frame_control = hdr->frame_control;
-
-       /* relocate space for security header */
-       if (extra) {
-               int hdrlen = ieee80211_hdrlen(frame_control);
-               memmove(frame_start, hdr, hdrlen);
-       }
-
-       /* configure packet life time */
-       getnstimeofday(&ts);
-       hosttime = (timespec_to_ns(&ts) >> 10);
-       desc->start_time = cpu_to_le32(hosttime - wl->time_offset);
-
-       is_dummy = wl12xx_is_dummy_packet(wl, skb);
-       if (is_dummy || !wlvif || wlvif->bss_type != BSS_TYPE_AP_BSS)
-               desc->life_time = cpu_to_le16(TX_HW_MGMT_PKT_LIFETIME_TU);
-       else
-               desc->life_time = cpu_to_le16(TX_HW_AP_MODE_PKT_LIFETIME_TU);
-
-       /* queue */
-       ac = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
-       desc->tid = skb->priority;
-
-       if (is_dummy) {
-               /*
-                * FW expects the dummy packet to have an invalid session id -
-                * any session id that is different than the one set in the join
-                */
-               tx_attr = (SESSION_COUNTER_INVALID <<
-                          TX_HW_ATTR_OFST_SESSION_COUNTER) &
-                          TX_HW_ATTR_SESSION_COUNTER;
-
-               tx_attr |= TX_HW_ATTR_TX_DUMMY_REQ;
-       } else if (wlvif) {
-               /* configure the tx attributes */
-               tx_attr = wlvif->session_counter <<
-                         TX_HW_ATTR_OFST_SESSION_COUNTER;
-       }
-
-       desc->hlid = hlid;
-       if (is_dummy || !wlvif)
-               rate_idx = 0;
-       else if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
-               /* if the packets are destined for AP (have a STA entry)
-                  send them with AP rate policies, otherwise use default
-                  basic rates */
-               if (control->flags & IEEE80211_TX_CTL_NO_CCK_RATE)
-                       rate_idx = wlvif->sta.p2p_rate_idx;
-               else if (control->control.sta)
-                       rate_idx = wlvif->sta.ap_rate_idx;
-               else
-                       rate_idx = wlvif->sta.basic_rate_idx;
-       } else {
-               if (hlid == wlvif->ap.global_hlid)
-                       rate_idx = wlvif->ap.mgmt_rate_idx;
-               else if (hlid == wlvif->ap.bcast_hlid)
-                       rate_idx = wlvif->ap.bcast_rate_idx;
-               else
-                       rate_idx = wlvif->ap.ucast_rate_idx[ac];
-       }
-
-       tx_attr |= rate_idx << TX_HW_ATTR_OFST_RATE_POLICY;
-       desc->reserved = 0;
-
-       aligned_len = wl12xx_calc_packet_alignment(wl, skb->len);
-
-       if (wl->chip.id == CHIP_ID_1283_PG20) {
-               desc->wl128x_mem.extra_bytes = aligned_len - skb->len;
-               desc->length = cpu_to_le16(aligned_len >> 2);
-
-               wl1271_debug(DEBUG_TX, "tx_fill_hdr: hlid: %d "
-                            "tx_attr: 0x%x len: %d life: %d mem: %d",
-                            desc->hlid, tx_attr,
-                            le16_to_cpu(desc->length),
-                            le16_to_cpu(desc->life_time),
-                            desc->wl128x_mem.total_mem_blocks);
-       } else {
-               int pad;
-
-               /* Store the aligned length in terms of words */
-               desc->length = cpu_to_le16(aligned_len >> 2);
-
-               /* calculate number of padding bytes */
-               pad = aligned_len - skb->len;
-               tx_attr |= pad << TX_HW_ATTR_OFST_LAST_WORD_PAD;
-
-               wl1271_debug(DEBUG_TX, "tx_fill_hdr: pad: %d hlid: %d "
-                            "tx_attr: 0x%x len: %d life: %d mem: %d", pad,
-                            desc->hlid, tx_attr,
-                            le16_to_cpu(desc->length),
-                            le16_to_cpu(desc->life_time),
-                            desc->wl127x_mem.total_mem_blocks);
-       }
-
-       /* for WEP shared auth - no fw encryption is needed */
-       if (ieee80211_is_auth(frame_control) &&
-           ieee80211_has_protected(frame_control))
-               tx_attr |= TX_HW_ATTR_HOST_ENCRYPT;
-
-       desc->tx_attr = cpu_to_le16(tx_attr);
-}
-
-/* caller must hold wl->mutex */
-static int wl1271_prepare_tx_frame(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                                  struct sk_buff *skb, u32 buf_offset)
-{
-       struct ieee80211_tx_info *info;
-       u32 extra = 0;
-       int ret = 0;
-       u32 total_len;
-       u8 hlid;
-       bool is_dummy;
-
-       if (!skb)
-               return -EINVAL;
-
-       info = IEEE80211_SKB_CB(skb);
-
-       /* TODO: handle dummy packets on multi-vifs */
-       is_dummy = wl12xx_is_dummy_packet(wl, skb);
-
-       if (info->control.hw_key &&
-           info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP)
-               extra = WL1271_EXTRA_SPACE_TKIP;
-
-       if (info->control.hw_key) {
-               bool is_wep;
-               u8 idx = info->control.hw_key->hw_key_idx;
-               u32 cipher = info->control.hw_key->cipher;
-
-               is_wep = (cipher == WLAN_CIPHER_SUITE_WEP40) ||
-                        (cipher == WLAN_CIPHER_SUITE_WEP104);
-
-               if (unlikely(is_wep && wlvif->default_key != idx)) {
-                       ret = wl1271_set_default_wep_key(wl, wlvif, idx);
-                       if (ret < 0)
-                               return ret;
-                       wlvif->default_key = idx;
-               }
-       }
-       hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
-       if (hlid == WL12XX_INVALID_LINK_ID) {
-               wl1271_error("invalid hlid. dropping skb 0x%p", skb);
-               return -EINVAL;
-       }
-
-       ret = wl1271_tx_allocate(wl, wlvif, skb, extra, buf_offset, hlid);
-       if (ret < 0)
-               return ret;
-
-       wl1271_tx_fill_hdr(wl, wlvif, skb, extra, info, hlid);
-
-       if (!is_dummy && wlvif && wlvif->bss_type == BSS_TYPE_AP_BSS) {
-               wl1271_tx_ap_update_inconnection_sta(wl, skb);
-               wl1271_tx_regulate_link(wl, wlvif, hlid);
-       }
-
-       /*
-        * The length of each packet is stored in terms of
-        * words. Thus, we must pad the skb data to make sure its
-        * length is aligned.  The number of padding bytes is computed
-        * and set in wl1271_tx_fill_hdr.
-        * In special cases, we want to align to a specific block size
-        * (eg. for wl128x with SDIO we align to 256).
-        */
-       total_len = wl12xx_calc_packet_alignment(wl, skb->len);
-
-       memcpy(wl->aggr_buf + buf_offset, skb->data, skb->len);
-       memset(wl->aggr_buf + buf_offset + skb->len, 0, total_len - skb->len);
-
-       /* Revert side effects in the dummy packet skb, so it can be reused */
-       if (is_dummy)
-               skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
-
-       return total_len;
-}
-
-u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set,
-                               enum ieee80211_band rate_band)
-{
-       struct ieee80211_supported_band *band;
-       u32 enabled_rates = 0;
-       int bit;
-
-       band = wl->hw->wiphy->bands[rate_band];
-       for (bit = 0; bit < band->n_bitrates; bit++) {
-               if (rate_set & 0x1)
-                       enabled_rates |= band->bitrates[bit].hw_value;
-               rate_set >>= 1;
-       }
-
-       /* MCS rates indication are on bits 16 - 23 */
-       rate_set >>= HW_HT_RATES_OFFSET - band->n_bitrates;
-
-       for (bit = 0; bit < 8; bit++) {
-               if (rate_set & 0x1)
-                       enabled_rates |= (CONF_HW_BIT_RATE_MCS_0 << bit);
-               rate_set >>= 1;
-       }
-
-       return enabled_rates;
-}
-
-void wl1271_handle_tx_low_watermark(struct wl1271 *wl)
-{
-       unsigned long flags;
-       int i;
-
-       for (i = 0; i < NUM_TX_QUEUES; i++) {
-               if (test_bit(i, &wl->stopped_queues_map) &&
-                   wl->tx_queue_count[i] <= WL1271_TX_QUEUE_LOW_WATERMARK) {
-                       /* firmware buffer has space, restart queues */
-                       spin_lock_irqsave(&wl->wl_lock, flags);
-                       ieee80211_wake_queue(wl->hw,
-                                            wl1271_tx_get_mac80211_queue(i));
-                       clear_bit(i, &wl->stopped_queues_map);
-                       spin_unlock_irqrestore(&wl->wl_lock, flags);
-               }
-       }
-}
-
-static struct sk_buff_head *wl1271_select_queue(struct wl1271 *wl,
-                                               struct sk_buff_head *queues)
-{
-       int i, q = -1, ac;
-       u32 min_pkts = 0xffffffff;
-
-       /*
-        * Find a non-empty ac where:
-        * 1. There are packets to transmit
-        * 2. The FW has the least allocated blocks
-        *
-        * We prioritize the ACs according to VO>VI>BE>BK
-        */
-       for (i = 0; i < NUM_TX_QUEUES; i++) {
-               ac = wl1271_tx_get_queue(i);
-               if (!skb_queue_empty(&queues[ac]) &&
-                   (wl->tx_allocated_pkts[ac] < min_pkts)) {
-                       q = ac;
-                       min_pkts = wl->tx_allocated_pkts[q];
-               }
-       }
-
-       if (q == -1)
-               return NULL;
-
-       return &queues[q];
-}
-
-static struct sk_buff *wl12xx_lnk_skb_dequeue(struct wl1271 *wl,
-                                             struct wl1271_link *lnk)
-{
-       struct sk_buff *skb;
-       unsigned long flags;
-       struct sk_buff_head *queue;
-
-       queue = wl1271_select_queue(wl, lnk->tx_queue);
-       if (!queue)
-               return NULL;
-
-       skb = skb_dequeue(queue);
-       if (skb) {
-               int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
-               spin_lock_irqsave(&wl->wl_lock, flags);
-               WARN_ON_ONCE(wl->tx_queue_count[q] <= 0);
-               wl->tx_queue_count[q]--;
-               spin_unlock_irqrestore(&wl->wl_lock, flags);
-       }
-
-       return skb;
-}
-
-static struct sk_buff *wl12xx_vif_skb_dequeue(struct wl1271 *wl,
-                                             struct wl12xx_vif *wlvif)
-{
-       struct sk_buff *skb = NULL;
-       int i, h, start_hlid;
-
-       /* start from the link after the last one */
-       start_hlid = (wlvif->last_tx_hlid + 1) % WL12XX_MAX_LINKS;
-
-       /* dequeue according to AC, round robin on each link */
-       for (i = 0; i < WL12XX_MAX_LINKS; i++) {
-               h = (start_hlid + i) % WL12XX_MAX_LINKS;
-
-               /* only consider connected stations */
-               if (!test_bit(h, wlvif->links_map))
-                       continue;
-
-               skb = wl12xx_lnk_skb_dequeue(wl, &wl->links[h]);
-               if (!skb)
-                       continue;
-
-               wlvif->last_tx_hlid = h;
-               break;
-       }
-
-       if (!skb)
-               wlvif->last_tx_hlid = 0;
-
-       return skb;
-}
-
-static struct sk_buff *wl1271_skb_dequeue(struct wl1271 *wl)
-{
-       unsigned long flags;
-       struct wl12xx_vif *wlvif = wl->last_wlvif;
-       struct sk_buff *skb = NULL;
-
-       /* continue from last wlvif (round robin) */
-       if (wlvif) {
-               wl12xx_for_each_wlvif_continue(wl, wlvif) {
-                       skb = wl12xx_vif_skb_dequeue(wl, wlvif);
-                       if (skb) {
-                               wl->last_wlvif = wlvif;
-                               break;
-                       }
-               }
-       }
-
-       /* dequeue from the system HLID before the restarting wlvif list */
-       if (!skb)
-               skb = wl12xx_lnk_skb_dequeue(wl, &wl->links[wl->system_hlid]);
-
-       /* do a new pass over the wlvif list */
-       if (!skb) {
-               wl12xx_for_each_wlvif(wl, wlvif) {
-                       skb = wl12xx_vif_skb_dequeue(wl, wlvif);
-                       if (skb) {
-                               wl->last_wlvif = wlvif;
-                               break;
-                       }
-
-                       /*
-                        * No need to continue after last_wlvif. The previous
-                        * pass should have found it.
-                        */
-                       if (wlvif == wl->last_wlvif)
-                               break;
-               }
-       }
-
-       if (!skb &&
-           test_and_clear_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags)) {
-               int q;
-
-               skb = wl->dummy_packet;
-               q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
-               spin_lock_irqsave(&wl->wl_lock, flags);
-               WARN_ON_ONCE(wl->tx_queue_count[q] <= 0);
-               wl->tx_queue_count[q]--;
-               spin_unlock_irqrestore(&wl->wl_lock, flags);
-       }
-
-       return skb;
-}
-
-static void wl1271_skb_queue_head(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                                 struct sk_buff *skb)
-{
-       unsigned long flags;
-       int q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
-
-       if (wl12xx_is_dummy_packet(wl, skb)) {
-               set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
-       } else {
-               u8 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
-               skb_queue_head(&wl->links[hlid].tx_queue[q], skb);
-
-               /* make sure we dequeue the same packet next time */
-               wlvif->last_tx_hlid = (hlid + WL12XX_MAX_LINKS - 1) %
-                                     WL12XX_MAX_LINKS;
-       }
-
-       spin_lock_irqsave(&wl->wl_lock, flags);
-       wl->tx_queue_count[q]++;
-       spin_unlock_irqrestore(&wl->wl_lock, flags);
-}
-
-static bool wl1271_tx_is_data_present(struct sk_buff *skb)
-{
-       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)(skb->data);
-
-       return ieee80211_is_data_present(hdr->frame_control);
-}
-
-void wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids)
-{
-       struct wl12xx_vif *wlvif;
-       u32 timeout;
-       u8 hlid;
-
-       if (!wl->conf.rx_streaming.interval)
-               return;
-
-       if (!wl->conf.rx_streaming.always &&
-           !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags))
-               return;
-
-       timeout = wl->conf.rx_streaming.duration;
-       wl12xx_for_each_wlvif_sta(wl, wlvif) {
-               bool found = false;
-               for_each_set_bit(hlid, active_hlids, WL12XX_MAX_LINKS) {
-                       if (test_bit(hlid, wlvif->links_map)) {
-                               found  = true;
-                               break;
-                       }
-               }
-
-               if (!found)
-                       continue;
-
-               /* enable rx streaming */
-               if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
-                       ieee80211_queue_work(wl->hw,
-                                            &wlvif->rx_streaming_enable_work);
-
-               mod_timer(&wlvif->rx_streaming_timer,
-                         jiffies + msecs_to_jiffies(timeout));
-       }
-}
-
-void wl1271_tx_work_locked(struct wl1271 *wl)
-{
-       struct wl12xx_vif *wlvif;
-       struct sk_buff *skb;
-       struct wl1271_tx_hw_descr *desc;
-       u32 buf_offset = 0;
-       bool sent_packets = false;
-       unsigned long active_hlids[BITS_TO_LONGS(WL12XX_MAX_LINKS)] = {0};
-       int ret;
-
-       if (unlikely(wl->state == WL1271_STATE_OFF))
-               return;
-
-       while ((skb = wl1271_skb_dequeue(wl))) {
-               struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
-               bool has_data = false;
-
-               wlvif = NULL;
-               if (!wl12xx_is_dummy_packet(wl, skb) && info->control.vif)
-                       wlvif = wl12xx_vif_to_data(info->control.vif);
-
-               has_data = wlvif && wl1271_tx_is_data_present(skb);
-               ret = wl1271_prepare_tx_frame(wl, wlvif, skb, buf_offset);
-               if (ret == -EAGAIN) {
-                       /*
-                        * Aggregation buffer is full.
-                        * Flush buffer and try again.
-                        */
-                       wl1271_skb_queue_head(wl, wlvif, skb);
-                       wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
-                                    buf_offset, true);
-                       sent_packets = true;
-                       buf_offset = 0;
-                       continue;
-               } else if (ret == -EBUSY) {
-                       /*
-                        * Firmware buffer is full.
-                        * Queue back last skb, and stop aggregating.
-                        */
-                       wl1271_skb_queue_head(wl, wlvif, skb);
-                       /* No work left, avoid scheduling redundant tx work */
-                       set_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
-                       goto out_ack;
-               } else if (ret < 0) {
-                       if (wl12xx_is_dummy_packet(wl, skb))
-                               /*
-                                * fw still expects dummy packet,
-                                * so re-enqueue it
-                                */
-                               wl1271_skb_queue_head(wl, wlvif, skb);
-                       else
-                               ieee80211_free_txskb(wl->hw, skb);
-                       goto out_ack;
-               }
-               buf_offset += ret;
-               wl->tx_packets_count++;
-               if (has_data) {
-                       desc = (struct wl1271_tx_hw_descr *) skb->data;
-                       __set_bit(desc->hlid, active_hlids);
-               }
-       }
-
-out_ack:
-       if (buf_offset) {
-               wl1271_write(wl, WL1271_SLV_MEM_DATA, wl->aggr_buf,
-                               buf_offset, true);
-               sent_packets = true;
-       }
-       if (sent_packets) {
-               /*
-                * Interrupt the firmware with the new packets. This is only
-                * required for older hardware revisions
-                */
-               if (wl->quirks & WL12XX_QUIRK_END_OF_TRANSACTION)
-                       wl1271_write32(wl, WL1271_HOST_WR_ACCESS,
-                                      wl->tx_packets_count);
-
-               wl1271_handle_tx_low_watermark(wl);
-       }
-       wl12xx_rearm_rx_streaming(wl, active_hlids);
-}
-
-void wl1271_tx_work(struct work_struct *work)
-{
-       struct wl1271 *wl = container_of(work, struct wl1271, tx_work);
-       int ret;
-
-       mutex_lock(&wl->mutex);
-       ret = wl1271_ps_elp_wakeup(wl);
-       if (ret < 0)
-               goto out;
-
-       wl1271_tx_work_locked(wl);
-
-       wl1271_ps_elp_sleep(wl);
-out:
-       mutex_unlock(&wl->mutex);
-}
-
-static u8 wl1271_tx_get_rate_flags(u8 rate_class_index)
-{
-       u8 flags = 0;
-
-       if (rate_class_index >= CONF_HW_RXTX_RATE_MCS_MIN &&
-           rate_class_index <= CONF_HW_RXTX_RATE_MCS_MAX)
-               flags |= IEEE80211_TX_RC_MCS;
-       if (rate_class_index == CONF_HW_RXTX_RATE_MCS7_SGI)
-               flags |= IEEE80211_TX_RC_SHORT_GI;
-       return flags;
-}
-
-static void wl1271_tx_complete_packet(struct wl1271 *wl,
-                                     struct wl1271_tx_hw_res_descr *result)
-{
-       struct ieee80211_tx_info *info;
-       struct ieee80211_vif *vif;
-       struct wl12xx_vif *wlvif;
-       struct sk_buff *skb;
-       int id = result->id;
-       int rate = -1;
-       u8 rate_flags = 0;
-       u8 retries = 0;
-
-       /* check for id legality */
-       if (unlikely(id >= ACX_TX_DESCRIPTORS || wl->tx_frames[id] == NULL)) {
-               wl1271_warning("TX result illegal id: %d", id);
-               return;
-       }
-
-       skb = wl->tx_frames[id];
-       info = IEEE80211_SKB_CB(skb);
-
-       if (wl12xx_is_dummy_packet(wl, skb)) {
-               wl1271_free_tx_id(wl, id);
-               return;
-       }
-
-       /* info->control is valid as long as we don't update info->status */
-       vif = info->control.vif;
-       wlvif = wl12xx_vif_to_data(vif);
-
-       /* update the TX status info */
-       if (result->status == TX_SUCCESS) {
-               if (!(info->flags & IEEE80211_TX_CTL_NO_ACK))
-                       info->flags |= IEEE80211_TX_STAT_ACK;
-               rate = wl1271_rate_to_idx(result->rate_class_index,
-                                         wlvif->band);
-               rate_flags = wl1271_tx_get_rate_flags(result->rate_class_index);
-               retries = result->ack_failures;
-       } else if (result->status == TX_RETRY_EXCEEDED) {
-               wl->stats.excessive_retries++;
-               retries = result->ack_failures;
-       }
-
-       info->status.rates[0].idx = rate;
-       info->status.rates[0].count = retries;
-       info->status.rates[0].flags = rate_flags;
-       info->status.ack_signal = -1;
-
-       wl->stats.retry_count += result->ack_failures;
-
-       /*
-        * update sequence number only when relevant, i.e. only in
-        * sessions of TKIP, AES and GEM (not in open or WEP sessions)
-        */
-       if (info->control.hw_key &&
-           (info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP ||
-            info->control.hw_key->cipher == WLAN_CIPHER_SUITE_CCMP ||
-            info->control.hw_key->cipher == WL1271_CIPHER_SUITE_GEM)) {
-               u8 fw_lsb = result->tx_security_sequence_number_lsb;
-               u8 cur_lsb = wlvif->tx_security_last_seq_lsb;
-
-               /*
-                * update security sequence number, taking care of potential
-                * wrap-around
-                */
-               wlvif->tx_security_seq += (fw_lsb - cur_lsb) & 0xff;
-               wlvif->tx_security_last_seq_lsb = fw_lsb;
-       }
-
-       /* remove private header from packet */
-       skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
-
-       /* remove TKIP header space if present */
-       if (info->control.hw_key &&
-           info->control.hw_key->cipher == WLAN_CIPHER_SUITE_TKIP) {
-               int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
-               memmove(skb->data + WL1271_EXTRA_SPACE_TKIP, skb->data,
-                       hdrlen);
-               skb_pull(skb, WL1271_EXTRA_SPACE_TKIP);
-       }
-
-       wl1271_debug(DEBUG_TX, "tx status id %u skb 0x%p failures %u rate 0x%x"
-                    " status 0x%x",
-                    result->id, skb, result->ack_failures,
-                    result->rate_class_index, result->status);
-
-       /* return the packet to the stack */
-       skb_queue_tail(&wl->deferred_tx_queue, skb);
-       queue_work(wl->freezable_wq, &wl->netstack_work);
-       wl1271_free_tx_id(wl, result->id);
-}
-
-/* Called upon reception of a TX complete interrupt */
-void wl1271_tx_complete(struct wl1271 *wl)
-{
-       struct wl1271_acx_mem_map *memmap =
-               (struct wl1271_acx_mem_map *)wl->target_mem_map;
-       u32 count, fw_counter;
-       u32 i;
-
-       /* read the tx results from the chipset */
-       wl1271_read(wl, le32_to_cpu(memmap->tx_result),
-                   wl->tx_res_if, sizeof(*wl->tx_res_if), false);
-       fw_counter = le32_to_cpu(wl->tx_res_if->tx_result_fw_counter);
-
-       /* write host counter to chipset (to ack) */
-       wl1271_write32(wl, le32_to_cpu(memmap->tx_result) +
-                      offsetof(struct wl1271_tx_hw_res_if,
-                               tx_result_host_counter), fw_counter);
-
-       count = fw_counter - wl->tx_results_count;
-       wl1271_debug(DEBUG_TX, "tx_complete received, packets: %d", count);
-
-       /* verify that the result buffer is not getting overrun */
-       if (unlikely(count > TX_HW_RESULT_QUEUE_LEN))
-               wl1271_warning("TX result overflow from chipset: %d", count);
-
-       /* process the results */
-       for (i = 0; i < count; i++) {
-               struct wl1271_tx_hw_res_descr *result;
-               u8 offset = wl->tx_results_count & TX_HW_RESULT_QUEUE_LEN_MASK;
-
-               /* process the packet */
-               result =  &(wl->tx_res_if->tx_results_queue[offset]);
-               wl1271_tx_complete_packet(wl, result);
-
-               wl->tx_results_count++;
-       }
-}
-
-void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid)
-{
-       struct sk_buff *skb;
-       int i;
-       unsigned long flags;
-       struct ieee80211_tx_info *info;
-       int total[NUM_TX_QUEUES];
-
-       for (i = 0; i < NUM_TX_QUEUES; i++) {
-               total[i] = 0;
-               while ((skb = skb_dequeue(&wl->links[hlid].tx_queue[i]))) {
-                       wl1271_debug(DEBUG_TX, "link freeing skb 0x%p", skb);
-
-                       if (!wl12xx_is_dummy_packet(wl, skb)) {
-                               info = IEEE80211_SKB_CB(skb);
-                               info->status.rates[0].idx = -1;
-                               info->status.rates[0].count = 0;
-                               ieee80211_tx_status_ni(wl->hw, skb);
-                       }
-
-                       total[i]++;
-               }
-       }
-
-       spin_lock_irqsave(&wl->wl_lock, flags);
-       for (i = 0; i < NUM_TX_QUEUES; i++)
-               wl->tx_queue_count[i] -= total[i];
-       spin_unlock_irqrestore(&wl->wl_lock, flags);
-
-       wl1271_handle_tx_low_watermark(wl);
-}
-
-/* caller must hold wl->mutex and TX must be stopped */
-void wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif)
-{
-       int i;
-
-       /* TX failure */
-       for_each_set_bit(i, wlvif->links_map, WL12XX_MAX_LINKS) {
-               if (wlvif->bss_type == BSS_TYPE_AP_BSS)
-                       wl1271_free_sta(wl, wlvif, i);
-               else
-                       wlvif->sta.ba_rx_bitmap = 0;
-
-               wl->links[i].allocated_pkts = 0;
-               wl->links[i].prev_freed_pkts = 0;
-       }
-       wlvif->last_tx_hlid = 0;
-
-}
-/* caller must hold wl->mutex and TX must be stopped */
-void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues)
-{
-       int i;
-       struct sk_buff *skb;
-       struct ieee80211_tx_info *info;
-
-       /* only reset the queues if something bad happened */
-       if (WARN_ON_ONCE(wl1271_tx_total_queue_count(wl) != 0)) {
-               for (i = 0; i < WL12XX_MAX_LINKS; i++)
-                       wl1271_tx_reset_link_queues(wl, i);
-
-               for (i = 0; i < NUM_TX_QUEUES; i++)
-                       wl->tx_queue_count[i] = 0;
-       }
-
-       wl->stopped_queues_map = 0;
-
-       /*
-        * Make sure the driver is at a consistent state, in case this
-        * function is called from a context other than interface removal.
-        * This call will always wake the TX queues.
-        */
-       if (reset_tx_queues)
-               wl1271_handle_tx_low_watermark(wl);
-
-       for (i = 0; i < ACX_TX_DESCRIPTORS; i++) {
-               if (wl->tx_frames[i] == NULL)
-                       continue;
-
-               skb = wl->tx_frames[i];
-               wl1271_free_tx_id(wl, i);
-               wl1271_debug(DEBUG_TX, "freeing skb 0x%p", skb);
-
-               if (!wl12xx_is_dummy_packet(wl, skb)) {
-                       /*
-                        * Remove private headers before passing the skb to
-                        * mac80211
-                        */
-                       info = IEEE80211_SKB_CB(skb);
-                       skb_pull(skb, sizeof(struct wl1271_tx_hw_descr));
-                       if (info->control.hw_key &&
-                           info->control.hw_key->cipher ==
-                           WLAN_CIPHER_SUITE_TKIP) {
-                               int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
-                               memmove(skb->data + WL1271_EXTRA_SPACE_TKIP,
-                                       skb->data, hdrlen);
-                               skb_pull(skb, WL1271_EXTRA_SPACE_TKIP);
-                       }
-
-                       info->status.rates[0].idx = -1;
-                       info->status.rates[0].count = 0;
-
-                       ieee80211_tx_status_ni(wl->hw, skb);
-               }
-       }
-}
-
-#define WL1271_TX_FLUSH_TIMEOUT 500000
-
-/* caller must *NOT* hold wl->mutex */
-void wl1271_tx_flush(struct wl1271 *wl)
-{
-       unsigned long timeout;
-       int i;
-       timeout = jiffies + usecs_to_jiffies(WL1271_TX_FLUSH_TIMEOUT);
-
-       while (!time_after(jiffies, timeout)) {
-               mutex_lock(&wl->mutex);
-               wl1271_debug(DEBUG_TX, "flushing tx buffer: %d %d",
-                            wl->tx_frames_cnt,
-                            wl1271_tx_total_queue_count(wl));
-               if ((wl->tx_frames_cnt == 0) &&
-                   (wl1271_tx_total_queue_count(wl) == 0)) {
-                       mutex_unlock(&wl->mutex);
-                       return;
-               }
-               mutex_unlock(&wl->mutex);
-               msleep(1);
-       }
-
-       wl1271_warning("Unable to flush all TX buffers, timed out.");
-
-       /* forcibly flush all Tx buffers on our queues */
-       mutex_lock(&wl->mutex);
-       for (i = 0; i < WL12XX_MAX_LINKS; i++)
-               wl1271_tx_reset_link_queues(wl, i);
-       mutex_unlock(&wl->mutex);
-}
-
-u32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set)
-{
-       if (WARN_ON(!rate_set))
-               return 0;
-
-       return BIT(__ffs(rate_set));
-}
diff --git a/drivers/net/wireless/wl12xx/tx.h b/drivers/net/wireless/wl12xx/tx.h
deleted file mode 100644 (file)
index 5cf8c32..0000000
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
- * Copyright (C) 2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __TX_H__
-#define __TX_H__
-
-#define TX_HW_BLOCK_SPARE_DEFAULT        1
-#define TX_HW_BLOCK_SIZE                 252
-
-#define TX_HW_MGMT_PKT_LIFETIME_TU       2000
-#define TX_HW_AP_MODE_PKT_LIFETIME_TU    8000
-
-#define TX_HW_ATTR_SAVE_RETRIES          BIT(0)
-#define TX_HW_ATTR_HEADER_PAD            BIT(1)
-#define TX_HW_ATTR_SESSION_COUNTER       (BIT(2) | BIT(3) | BIT(4))
-#define TX_HW_ATTR_RATE_POLICY           (BIT(5) | BIT(6) | BIT(7) | \
-                                         BIT(8) | BIT(9))
-#define TX_HW_ATTR_LAST_WORD_PAD         (BIT(10) | BIT(11))
-#define TX_HW_ATTR_TX_CMPLT_REQ          BIT(12)
-#define TX_HW_ATTR_TX_DUMMY_REQ          BIT(13)
-#define TX_HW_ATTR_HOST_ENCRYPT          BIT(14)
-
-#define TX_HW_ATTR_OFST_SAVE_RETRIES     0
-#define TX_HW_ATTR_OFST_HEADER_PAD       1
-#define TX_HW_ATTR_OFST_SESSION_COUNTER  2
-#define TX_HW_ATTR_OFST_RATE_POLICY      5
-#define TX_HW_ATTR_OFST_LAST_WORD_PAD    10
-#define TX_HW_ATTR_OFST_TX_CMPLT_REQ     12
-
-#define TX_HW_RESULT_QUEUE_LEN           16
-#define TX_HW_RESULT_QUEUE_LEN_MASK      0xf
-
-#define WL1271_TX_ALIGN_TO 4
-#define WL1271_EXTRA_SPACE_TKIP 4
-#define WL1271_EXTRA_SPACE_AES  8
-#define WL1271_EXTRA_SPACE_MAX  8
-
-/* Used for management frames and dummy packets */
-#define WL1271_TID_MGMT 7
-
-struct wl127x_tx_mem {
-       /*
-        * Number of extra memory blocks to allocate for this packet
-        * in addition to the number of blocks derived from the packet
-        * length.
-        */
-       u8 extra_blocks;
-       /*
-        * Total number of memory blocks allocated by the host for
-        * this packet. Must be equal or greater than the actual
-        * blocks number allocated by HW.
-        */
-       u8 total_mem_blocks;
-} __packed;
-
-struct wl128x_tx_mem {
-       /*
-        * Total number of memory blocks allocated by the host for
-        * this packet.
-        */
-       u8 total_mem_blocks;
-       /*
-        * Number of extra bytes, at the end of the frame. the host
-        * uses this padding to complete each frame to integer number
-        * of SDIO blocks.
-        */
-       u8 extra_bytes;
-} __packed;
-
-/*
- * On wl128x based devices, when TX packets are aggregated, each packet
- * size must be aligned to the SDIO block size. The maximum block size
- * is bounded by the type of the padded bytes field that is sent to the
- * FW. Currently the type is u8, so the maximum block size is 256 bytes.
- */
-#define WL12XX_BUS_BLOCK_SIZE min(512u,        \
-           (1u << (8 * sizeof(((struct wl128x_tx_mem *) 0)->extra_bytes))))
-
-struct wl1271_tx_hw_descr {
-       /* Length of packet in words, including descriptor+header+data */
-       __le16 length;
-       union {
-               struct wl127x_tx_mem wl127x_mem;
-               struct wl128x_tx_mem wl128x_mem;
-       } __packed;
-       /* Device time (in us) when the packet arrived to the driver */
-       __le32 start_time;
-       /*
-        * Max delay in TUs until transmission. The last device time the
-        * packet can be transmitted is: start_time + (1024 * life_time)
-        */
-       __le16 life_time;
-       /* Bitwise fields - see TX_ATTR... definitions above. */
-       __le16 tx_attr;
-       /* Packet identifier used also in the Tx-Result. */
-       u8 id;
-       /* The packet TID value (as User-Priority) */
-       u8 tid;
-       /* host link ID (HLID) */
-       u8 hlid;
-       u8 reserved;
-} __packed;
-
-enum wl1271_tx_hw_res_status {
-       TX_SUCCESS          = 0,
-       TX_HW_ERROR         = 1,
-       TX_DISABLED         = 2,
-       TX_RETRY_EXCEEDED   = 3,
-       TX_TIMEOUT          = 4,
-       TX_KEY_NOT_FOUND    = 5,
-       TX_PEER_NOT_FOUND   = 6,
-       TX_SESSION_MISMATCH = 7,
-       TX_LINK_NOT_VALID   = 8,
-};
-
-struct wl1271_tx_hw_res_descr {
-       /* Packet Identifier - same value used in the Tx descriptor.*/
-       u8 id;
-       /* The status of the transmission, indicating success or one of
-          several possible reasons for failure. */
-       u8 status;
-       /* Total air access duration including all retrys and overheads.*/
-       __le16 medium_usage;
-       /* The time passed from host xfer to Tx-complete.*/
-       __le32 fw_handling_time;
-       /* Total media delay
-          (from 1st EDCA AIFS counter until TX Complete). */
-       __le32 medium_delay;
-       /* LS-byte of last TKIP seq-num (saved per AC for recovery). */
-       u8 tx_security_sequence_number_lsb;
-       /* Retry count - number of transmissions without successful ACK.*/
-       u8 ack_failures;
-       /* The rate that succeeded getting ACK
-          (Valid only if status=SUCCESS). */
-       u8 rate_class_index;
-       /* for 4-byte alignment. */
-       u8 spare;
-} __packed;
-
-struct wl1271_tx_hw_res_if {
-       __le32 tx_result_fw_counter;
-       __le32 tx_result_host_counter;
-       struct wl1271_tx_hw_res_descr tx_results_queue[TX_HW_RESULT_QUEUE_LEN];
-} __packed;
-
-static inline int wl1271_tx_get_queue(int queue)
-{
-       switch (queue) {
-       case 0:
-               return CONF_TX_AC_VO;
-       case 1:
-               return CONF_TX_AC_VI;
-       case 2:
-               return CONF_TX_AC_BE;
-       case 3:
-               return CONF_TX_AC_BK;
-       default:
-               return CONF_TX_AC_BE;
-       }
-}
-
-static inline int wl1271_tx_get_mac80211_queue(int queue)
-{
-       switch (queue) {
-       case CONF_TX_AC_VO:
-               return 0;
-       case CONF_TX_AC_VI:
-               return 1;
-       case CONF_TX_AC_BE:
-               return 2;
-       case CONF_TX_AC_BK:
-               return 3;
-       default:
-               return 2;
-       }
-}
-
-static inline int wl1271_tx_total_queue_count(struct wl1271 *wl)
-{
-       int i, count = 0;
-
-       for (i = 0; i < NUM_TX_QUEUES; i++)
-               count += wl->tx_queue_count[i];
-
-       return count;
-}
-
-void wl1271_tx_work(struct work_struct *work);
-void wl1271_tx_work_locked(struct wl1271 *wl);
-void wl1271_tx_complete(struct wl1271 *wl);
-void wl12xx_tx_reset_wlvif(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-void wl12xx_tx_reset(struct wl1271 *wl, bool reset_tx_queues);
-void wl1271_tx_flush(struct wl1271 *wl);
-u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band);
-u32 wl1271_tx_enabled_rates_get(struct wl1271 *wl, u32 rate_set,
-                               enum ieee80211_band rate_band);
-u32 wl1271_tx_min_rate_get(struct wl1271 *wl, u32 rate_set);
-u8 wl12xx_tx_get_hlid_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                        struct sk_buff *skb);
-u8 wl12xx_tx_get_hlid(struct wl1271 *wl, struct wl12xx_vif *wlvif,
-                     struct sk_buff *skb);
-void wl1271_tx_reset_link_queues(struct wl1271 *wl, u8 hlid);
-void wl1271_handle_tx_low_watermark(struct wl1271 *wl);
-bool wl12xx_is_dummy_packet(struct wl1271 *wl, struct sk_buff *skb);
-void wl12xx_rearm_rx_streaming(struct wl1271 *wl, unsigned long *active_hlids);
-
-/* from main.c */
-void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid);
-void wl12xx_rearm_tx_watchdog_locked(struct wl1271 *wl);
-
-#endif
diff --git a/drivers/net/wireless/wl12xx/wl12xx.h b/drivers/net/wireless/wl12xx/wl12xx.h
deleted file mode 100644 (file)
index 749a15a..0000000
+++ /dev/null
@@ -1,695 +0,0 @@
-/*
- * This file is part of wl1271
- *
- * Copyright (C) 1998-2009 Texas Instruments. All rights reserved.
- * Copyright (C) 2008-2009 Nokia Corporation
- *
- * Contact: Luciano Coelho <luciano.coelho@nokia.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#ifndef __WL12XX_H__
-#define __WL12XX_H__
-
-#include <linux/mutex.h>
-#include <linux/completion.h>
-#include <linux/spinlock.h>
-#include <linux/list.h>
-#include <linux/bitops.h>
-#include <net/mac80211.h>
-
-#include "conf.h"
-#include "ini.h"
-
-#define WL127X_FW_NAME_MULTI "ti-connectivity/wl127x-fw-4-mr.bin"
-#define WL127X_FW_NAME_SINGLE "ti-connectivity/wl127x-fw-4-sr.bin"
-
-#define WL128X_FW_NAME_MULTI "ti-connectivity/wl128x-fw-4-mr.bin"
-#define WL128X_FW_NAME_SINGLE "ti-connectivity/wl128x-fw-4-sr.bin"
-
-#define WL127X_PLT_FW_NAME "ti-connectivity/wl127x-fw-4-plt.bin"
-#define WL128X_PLT_FW_NAME "ti-connectivity/wl128x-fw-4-plt.bin"
-
-/*
- * wl127x and wl128x are using the same NVS file name. However, the
- * ini parameters between them are different.  The driver validates
- * the correct NVS size in wl1271_boot_upload_nvs().
- */
-#define WL12XX_NVS_NAME "ti-connectivity/wl1271-nvs.bin"
-
-#define WL1271_TX_SECURITY_LO16(s) ((u16)((s) & 0xffff))
-#define WL1271_TX_SECURITY_HI32(s) ((u32)(((s) >> 16) & 0xffffffff))
-#define WL1271_TX_SQN_POST_RECOVERY_PADDING 0xff
-
-#define WL1271_CIPHER_SUITE_GEM 0x00147201
-
-#define WL1271_BUSY_WORD_CNT 1
-#define WL1271_BUSY_WORD_LEN (WL1271_BUSY_WORD_CNT * sizeof(u32))
-
-#define WL1271_ELP_HW_STATE_ASLEEP 0
-#define WL1271_ELP_HW_STATE_IRQ    1
-
-#define WL1271_DEFAULT_BEACON_INT  100
-#define WL1271_DEFAULT_DTIM_PERIOD 1
-
-#define WL12XX_MAX_ROLES           4
-#define WL12XX_MAX_LINKS           12
-#define WL12XX_INVALID_ROLE_ID     0xff
-#define WL12XX_INVALID_LINK_ID     0xff
-
-#define WL12XX_MAX_RATE_POLICIES 16
-
-/* Defined by FW as 0. Will not be freed or allocated. */
-#define WL12XX_SYSTEM_HLID         0
-
-/*
- * When in AP-mode, we allow (at least) this number of packets
- * to be transmitted to FW for a STA in PS-mode. Only when packets are
- * present in the FW buffers it will wake the sleeping STA. We want to put
- * enough packets for the driver to transmit all of its buffered data before
- * the STA goes to sleep again. But we don't want to take too much memory
- * as it might hurt the throughput of active STAs.
- */
-#define WL1271_PS_STA_MAX_PACKETS  2
-
-#define WL1271_AP_BSS_INDEX        0
-#define WL1271_AP_DEF_BEACON_EXP   20
-
-#define ACX_TX_DESCRIPTORS         16
-
-#define WL1271_AGGR_BUFFER_SIZE (4 * PAGE_SIZE)
-
-enum wl1271_state {
-       WL1271_STATE_OFF,
-       WL1271_STATE_ON,
-};
-
-enum wl12xx_fw_type {
-       WL12XX_FW_TYPE_NONE,
-       WL12XX_FW_TYPE_NORMAL,
-       WL12XX_FW_TYPE_MULTI,
-       WL12XX_FW_TYPE_PLT,
-};
-
-enum wl1271_partition_type {
-       PART_DOWN,
-       PART_WORK,
-       PART_DRPW,
-
-       PART_TABLE_LEN
-};
-
-struct wl1271_partition {
-       u32 size;
-       u32 start;
-};
-
-struct wl1271_partition_set {
-       struct wl1271_partition mem;
-       struct wl1271_partition reg;
-       struct wl1271_partition mem2;
-       struct wl1271_partition mem3;
-};
-
-struct wl1271;
-
-enum {
-       FW_VER_CHIP,
-       FW_VER_IF_TYPE,
-       FW_VER_MAJOR,
-       FW_VER_SUBTYPE,
-       FW_VER_MINOR,
-
-       NUM_FW_VER
-};
-
-#define FW_VER_CHIP_WL127X 6
-#define FW_VER_CHIP_WL128X 7
-
-#define FW_VER_IF_TYPE_STA 1
-#define FW_VER_IF_TYPE_AP  2
-
-#define FW_VER_MINOR_1_SPARE_STA_MIN 58
-#define FW_VER_MINOR_1_SPARE_AP_MIN  47
-
-#define FW_VER_MINOR_FWLOG_STA_MIN 70
-
-struct wl1271_chip {
-       u32 id;
-       char fw_ver_str[ETHTOOL_BUSINFO_LEN];
-       unsigned int fw_ver[NUM_FW_VER];
-};
-
-struct wl1271_stats {
-       struct acx_statistics *fw_stats;
-       unsigned long fw_stats_update;
-
-       unsigned int retry_count;
-       unsigned int excessive_retries;
-};
-
-#define NUM_TX_QUEUES              4
-#define NUM_RX_PKT_DESC            8
-
-#define AP_MAX_STATIONS            8
-
-/* FW status registers */
-struct wl12xx_fw_status {
-       __le32 intr;
-       u8  fw_rx_counter;
-       u8  drv_rx_counter;
-       u8  reserved;
-       u8  tx_results_counter;
-       __le32 rx_pkt_descs[NUM_RX_PKT_DESC];
-       __le32 fw_localtime;
-
-       /*
-        * A bitmap (where each bit represents a single HLID)
-        * to indicate if the station is in PS mode.
-        */
-       __le32 link_ps_bitmap;
-
-       /*
-        * A bitmap (where each bit represents a single HLID) to indicate
-        * if the station is in Fast mode
-        */
-       __le32 link_fast_bitmap;
-
-       /* Cumulative counter of total released mem blocks since FW-reset */
-       __le32 total_released_blks;
-
-       /* Size (in Memory Blocks) of TX pool */
-       __le32 tx_total;
-
-       /* Cumulative counter of released packets per AC */
-       u8 tx_released_pkts[NUM_TX_QUEUES];
-
-       /* Cumulative counter of freed packets per HLID */
-       u8 tx_lnk_free_pkts[WL12XX_MAX_LINKS];
-
-       /* Cumulative counter of released Voice memory blocks */
-       u8 tx_voice_released_blks;
-       u8 padding_1[3];
-       __le32 log_start_addr;
-} __packed;
-
-struct wl1271_rx_mem_pool_addr {
-       u32 addr;
-       u32 addr_extra;
-};
-
-#define WL1271_MAX_CHANNELS 64
-struct wl1271_scan {
-       struct cfg80211_scan_request *req;
-       unsigned long scanned_ch[BITS_TO_LONGS(WL1271_MAX_CHANNELS)];
-       bool failed;
-       u8 state;
-       u8 ssid[IEEE80211_MAX_SSID_LEN+1];
-       size_t ssid_len;
-};
-
-struct wl1271_if_operations {
-       void (*read)(struct device *child, int addr, void *buf, size_t len,
-                    bool fixed);
-       void (*write)(struct device *child, int addr, void *buf, size_t len,
-                    bool fixed);
-       void (*reset)(struct device *child);
-       void (*init)(struct device *child);
-       int (*power)(struct device *child, bool enable);
-       void (*set_block_size) (struct device *child, unsigned int blksz);
-};
-
-#define MAX_NUM_KEYS 14
-#define MAX_KEY_SIZE 32
-
-struct wl1271_ap_key {
-       u8 id;
-       u8 key_type;
-       u8 key_size;
-       u8 key[MAX_KEY_SIZE];
-       u8 hlid;
-       u32 tx_seq_32;
-       u16 tx_seq_16;
-};
-
-enum wl12xx_flags {
-       WL1271_FLAG_GPIO_POWER,
-       WL1271_FLAG_TX_QUEUE_STOPPED,
-       WL1271_FLAG_TX_PENDING,
-       WL1271_FLAG_IN_ELP,
-       WL1271_FLAG_ELP_REQUESTED,
-       WL1271_FLAG_IRQ_RUNNING,
-       WL1271_FLAG_FW_TX_BUSY,
-       WL1271_FLAG_DUMMY_PACKET_PENDING,
-       WL1271_FLAG_SUSPENDED,
-       WL1271_FLAG_PENDING_WORK,
-       WL1271_FLAG_SOFT_GEMINI,
-       WL1271_FLAG_RECOVERY_IN_PROGRESS,
-       WL1271_FLAG_VIF_CHANGE_IN_PROGRESS,
-       WL1271_FLAG_INTENDED_FW_RECOVERY,
-};
-
-enum wl12xx_vif_flags {
-       WLVIF_FLAG_INITIALIZED,
-       WLVIF_FLAG_STA_ASSOCIATED,
-       WLVIF_FLAG_STA_AUTHORIZED,
-       WLVIF_FLAG_IBSS_JOINED,
-       WLVIF_FLAG_AP_STARTED,
-       WLVIF_FLAG_IN_PS,
-       WLVIF_FLAG_STA_STATE_SENT,
-       WLVIF_FLAG_RX_STREAMING_STARTED,
-       WLVIF_FLAG_PSPOLL_FAILURE,
-       WLVIF_FLAG_CS_PROGRESS,
-       WLVIF_FLAG_AP_PROBE_RESP_SET,
-       WLVIF_FLAG_IN_USE,
-};
-
-struct wl1271_link {
-       /* AP-mode - TX queue per AC in link */
-       struct sk_buff_head tx_queue[NUM_TX_QUEUES];
-
-       /* accounting for allocated / freed packets in FW */
-       u8 allocated_pkts;
-       u8 prev_freed_pkts;
-
-       u8 addr[ETH_ALEN];
-
-       /* bitmap of TIDs where RX BA sessions are active for this link */
-       u8 ba_bitmap;
-};
-
-struct wl1271 {
-       struct ieee80211_hw *hw;
-       bool mac80211_registered;
-
-       struct device *dev;
-
-       void *if_priv;
-
-       struct wl1271_if_operations *if_ops;
-
-       void (*set_power)(bool enable);
-       int irq;
-       int ref_clock;
-
-       spinlock_t wl_lock;
-
-       enum wl1271_state state;
-       enum wl12xx_fw_type fw_type;
-       bool plt;
-       u8 last_vif_count;
-       struct mutex mutex;
-
-       unsigned long flags;
-
-       struct wl1271_partition_set part;
-
-       struct wl1271_chip chip;
-
-       int cmd_box_addr;
-       int event_box_addr;
-
-       u8 *fw;
-       size_t fw_len;
-       void *nvs;
-       size_t nvs_len;
-
-       s8 hw_pg_ver;
-
-       /* address read from the fuse ROM */
-       u32 fuse_oui_addr;
-       u32 fuse_nic_addr;
-
-       /* we have up to 2 MAC addresses */
-       struct mac_address addresses[2];
-       int channel;
-       u8 system_hlid;
-
-       unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
-       unsigned long roles_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
-       unsigned long roc_map[BITS_TO_LONGS(WL12XX_MAX_ROLES)];
-       unsigned long rate_policies_map[
-                       BITS_TO_LONGS(WL12XX_MAX_RATE_POLICIES)];
-
-       struct list_head wlvif_list;
-
-       u8 sta_count;
-       u8 ap_count;
-
-       struct wl1271_acx_mem_map *target_mem_map;
-
-       /* Accounting for allocated / available TX blocks on HW */
-       u32 tx_blocks_freed;
-       u32 tx_blocks_available;
-       u32 tx_allocated_blocks;
-       u32 tx_results_count;
-
-       /* amount of spare TX blocks to use */
-       u32 tx_spare_blocks;
-
-       /* Accounting for allocated / available Tx packets in HW */
-       u32 tx_pkts_freed[NUM_TX_QUEUES];
-       u32 tx_allocated_pkts[NUM_TX_QUEUES];
-
-       /* Transmitted TX packets counter for chipset interface */
-       u32 tx_packets_count;
-
-       /* Time-offset between host and chipset clocks */
-       s64 time_offset;
-
-       /* Frames scheduled for transmission, not handled yet */
-       int tx_queue_count[NUM_TX_QUEUES];
-       long stopped_queues_map;
-
-       /* Frames received, not handled yet by mac80211 */
-       struct sk_buff_head deferred_rx_queue;
-
-       /* Frames sent, not returned yet to mac80211 */
-       struct sk_buff_head deferred_tx_queue;
-
-       struct work_struct tx_work;
-       struct workqueue_struct *freezable_wq;
-
-       /* Pending TX frames */
-       unsigned long tx_frames_map[BITS_TO_LONGS(ACX_TX_DESCRIPTORS)];
-       struct sk_buff *tx_frames[ACX_TX_DESCRIPTORS];
-       int tx_frames_cnt;
-
-       /* FW Rx counter */
-       u32 rx_counter;
-
-       /* Rx memory pool address */
-       struct wl1271_rx_mem_pool_addr rx_mem_pool_addr;
-
-       /* Intermediate buffer, used for packet aggregation */
-       u8 *aggr_buf;
-
-       /* Reusable dummy packet template */
-       struct sk_buff *dummy_packet;
-
-       /* Network stack work  */
-       struct work_struct netstack_work;
-
-       /* FW log buffer */
-       u8 *fwlog;
-
-       /* Number of valid bytes in the FW log buffer */
-       ssize_t fwlog_size;
-
-       /* Sysfs FW log entry readers wait queue */
-       wait_queue_head_t fwlog_waitq;
-
-       /* Hardware recovery work */
-       struct work_struct recovery_work;
-
-       /* The mbox event mask */
-       u32 event_mask;
-
-       /* Mailbox pointers */
-       u32 mbox_ptr[2];
-
-       /* Are we currently scanning */
-       struct ieee80211_vif *scan_vif;
-       struct wl1271_scan scan;
-       struct delayed_work scan_complete_work;
-
-       bool sched_scanning;
-
-       /* The current band */
-       enum ieee80211_band band;
-
-       struct completion *elp_compl;
-       struct delayed_work elp_work;
-
-       /* in dBm */
-       int power_level;
-
-       struct wl1271_stats stats;
-
-       __le32 buffer_32;
-       u32 buffer_cmd;
-       u32 buffer_busyword[WL1271_BUSY_WORD_CNT];
-
-       struct wl12xx_fw_status *fw_status;
-       struct wl1271_tx_hw_res_if *tx_res_if;
-
-       /* Current chipset configuration */
-       struct conf_drv_settings conf;
-
-       bool sg_enabled;
-
-       bool enable_11a;
-
-       /* Most recently reported noise in dBm */
-       s8 noise;
-
-       /* bands supported by this instance of wl12xx */
-       struct ieee80211_supported_band bands[IEEE80211_NUM_BANDS];
-
-       int tcxo_clock;
-
-       /*
-        * wowlan trigger was configured during suspend.
-        * (currently, only "ANY" trigger is supported)
-        */
-       bool wow_enabled;
-       bool irq_wake_enabled;
-
-       /*
-        * AP-mode - links indexed by HLID. The global and broadcast links
-        * are always active.
-        */
-       struct wl1271_link links[WL12XX_MAX_LINKS];
-
-       /* AP-mode - a bitmap of links currently in PS mode according to FW */
-       u32 ap_fw_ps_map;
-
-       /* AP-mode - a bitmap of links currently in PS mode in mac80211 */
-       unsigned long ap_ps_map;
-
-       /* Quirks of specific hardware revisions */
-       unsigned int quirks;
-
-       /* Platform limitations */
-       unsigned int platform_quirks;
-
-       /* number of currently active RX BA sessions */
-       int ba_rx_session_count;
-
-       /* AP-mode - number of currently connected stations */
-       int active_sta_count;
-
-       /* last wlvif we transmitted from */
-       struct wl12xx_vif *last_wlvif;
-
-       /* work to fire when Tx is stuck */
-       struct delayed_work tx_watchdog_work;
-};
-
-struct wl1271_station {
-       u8 hlid;
-};
-
-struct wl12xx_vif {
-       struct wl1271 *wl;
-       struct list_head list;
-       unsigned long flags;
-       u8 bss_type;
-       u8 p2p; /* we are using p2p role */
-       u8 role_id;
-
-       /* sta/ibss specific */
-       u8 dev_role_id;
-       u8 dev_hlid;
-
-       union {
-               struct {
-                       u8 hlid;
-                       u8 ba_rx_bitmap;
-
-                       u8 basic_rate_idx;
-                       u8 ap_rate_idx;
-                       u8 p2p_rate_idx;
-
-                       bool qos;
-               } sta;
-               struct {
-                       u8 global_hlid;
-                       u8 bcast_hlid;
-
-                       /* HLIDs bitmap of associated stations */
-                       unsigned long sta_hlid_map[BITS_TO_LONGS(
-                                                       WL12XX_MAX_LINKS)];
-
-                       /* recoreded keys - set here before AP startup */
-                       struct wl1271_ap_key *recorded_keys[MAX_NUM_KEYS];
-
-                       u8 mgmt_rate_idx;
-                       u8 bcast_rate_idx;
-                       u8 ucast_rate_idx[CONF_TX_MAX_AC_COUNT];
-               } ap;
-       };
-
-       /* the hlid of the last transmitted skb */
-       int last_tx_hlid;
-
-       unsigned long links_map[BITS_TO_LONGS(WL12XX_MAX_LINKS)];
-
-       u8 ssid[IEEE80211_MAX_SSID_LEN + 1];
-       u8 ssid_len;
-
-       /* The current band */
-       enum ieee80211_band band;
-       int channel;
-
-       u32 bitrate_masks[IEEE80211_NUM_BANDS];
-       u32 basic_rate_set;
-
-       /*
-        * currently configured rate set:
-        *      bits  0-15 - 802.11abg rates
-        *      bits 16-23 - 802.11n   MCS index mask
-        * support only 1 stream, thus only 8 bits for the MCS rates (0-7).
-        */
-       u32 basic_rate;
-       u32 rate_set;
-
-       /* probe-req template for the current AP */
-       struct sk_buff *probereq;
-
-       /* Beaconing interval (needed for ad-hoc) */
-       u32 beacon_int;
-
-       /* Default key (for WEP) */
-       u32 default_key;
-
-       /* Our association ID */
-       u16 aid;
-
-       /* Session counter for the chipset */
-       int session_counter;
-
-       /* retry counter for PSM entries */
-       u8 psm_entry_retry;
-
-       /* in dBm */
-       int power_level;
-
-       int rssi_thold;
-       int last_rssi_event;
-
-       /* save the current encryption type for auto-arp config */
-       u8 encryption_type;
-       __be32 ip_addr;
-
-       /* RX BA constraint value */
-       bool ba_support;
-       bool ba_allowed;
-
-       /* Rx Streaming */
-       struct work_struct rx_streaming_enable_work;
-       struct work_struct rx_streaming_disable_work;
-       struct timer_list rx_streaming_timer;
-
-       /*
-        * This struct must be last!
-        * data that has to be saved acrossed reconfigs (e.g. recovery)
-        * should be declared in this struct.
-        */
-       struct {
-               u8 persistent[0];
-               /*
-                * Security sequence number
-                *     bits 0-15: lower 16 bits part of sequence number
-                *     bits 16-47: higher 32 bits part of sequence number
-                *     bits 48-63: not in use
-                */
-               u64 tx_security_seq;
-
-               /* 8 bits of the last sequence number in use */
-               u8 tx_security_last_seq_lsb;
-       };
-};
-
-static inline struct wl12xx_vif *wl12xx_vif_to_data(struct ieee80211_vif *vif)
-{
-       return (struct wl12xx_vif *)vif->drv_priv;
-}
-
-static inline
-struct ieee80211_vif *wl12xx_wlvif_to_vif(struct wl12xx_vif *wlvif)
-{
-       return container_of((void *)wlvif, struct ieee80211_vif, drv_priv);
-}
-
-#define wl12xx_for_each_wlvif(wl, wlvif) \
-               list_for_each_entry(wlvif, &wl->wlvif_list, list)
-
-#define wl12xx_for_each_wlvif_continue(wl, wlvif) \
-               list_for_each_entry_continue(wlvif, &wl->wlvif_list, list)
-
-#define wl12xx_for_each_wlvif_bss_type(wl, wlvif, _bss_type)   \
-               wl12xx_for_each_wlvif(wl, wlvif)                \
-                       if (wlvif->bss_type == _bss_type)
-
-#define wl12xx_for_each_wlvif_sta(wl, wlvif)   \
-               wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_STA_BSS)
-
-#define wl12xx_for_each_wlvif_ap(wl, wlvif)    \
-               wl12xx_for_each_wlvif_bss_type(wl, wlvif, BSS_TYPE_AP_BSS)
-
-int wl1271_plt_start(struct wl1271 *wl);
-int wl1271_plt_stop(struct wl1271 *wl);
-int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif);
-void wl12xx_queue_recovery_work(struct wl1271 *wl);
-size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen);
-
-#define JOIN_TIMEOUT 5000 /* 5000 milliseconds to join */
-
-#define SESSION_COUNTER_MAX 6 /* maximum value for the session counter */
-#define SESSION_COUNTER_INVALID 7 /* used with dummy_packet */
-
-#define WL1271_DEFAULT_POWER_LEVEL 0
-
-#define WL1271_TX_QUEUE_LOW_WATERMARK  32
-#define WL1271_TX_QUEUE_HIGH_WATERMARK 256
-
-#define WL1271_DEFERRED_QUEUE_LIMIT    64
-
-/* WL1271 needs a 200ms sleep after power on, and a 20ms sleep before power
-   on in case is has been shut down shortly before */
-#define WL1271_PRE_POWER_ON_SLEEP 20 /* in milliseconds */
-#define WL1271_POWER_ON_SLEEP 200 /* in milliseconds */
-
-/* Macros to handle wl1271.sta_rate_set */
-#define HW_BG_RATES_MASK       0xffff
-#define HW_HT_RATES_OFFSET     16
-
-/* Quirks */
-
-/* Each RX/TX transaction requires an end-of-transaction transfer */
-#define WL12XX_QUIRK_END_OF_TRANSACTION                BIT(0)
-
-/* wl127x and SPI don't support SDIO block size alignment */
-#define WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT    BIT(2)
-
-/* Older firmwares did not implement the FW logger over bus feature */
-#define WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED     BIT(4)
-
-#define WL12XX_HW_BLOCK_SIZE   256
-
-#endif
diff --git a/drivers/net/wireless/wl12xx/wl12xx_80211.h b/drivers/net/wireless/wl12xx/wl12xx_80211.h
deleted file mode 100644 (file)
index 22b0bc9..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-#ifndef __WL12XX_80211_H__
-#define __WL12XX_80211_H__
-
-#include <linux/if_ether.h>    /* ETH_ALEN */
-#include <linux/if_arp.h>
-
-/* RATES */
-#define IEEE80211_CCK_RATE_1MB                 0x02
-#define IEEE80211_CCK_RATE_2MB                 0x04
-#define IEEE80211_CCK_RATE_5MB                 0x0B
-#define IEEE80211_CCK_RATE_11MB                        0x16
-#define IEEE80211_OFDM_RATE_6MB                        0x0C
-#define IEEE80211_OFDM_RATE_9MB                        0x12
-#define IEEE80211_OFDM_RATE_12MB               0x18
-#define IEEE80211_OFDM_RATE_18MB               0x24
-#define IEEE80211_OFDM_RATE_24MB               0x30
-#define IEEE80211_OFDM_RATE_36MB               0x48
-#define IEEE80211_OFDM_RATE_48MB               0x60
-#define IEEE80211_OFDM_RATE_54MB               0x6C
-#define IEEE80211_BASIC_RATE_MASK              0x80
-
-#define IEEE80211_CCK_RATE_1MB_MASK            (1<<0)
-#define IEEE80211_CCK_RATE_2MB_MASK            (1<<1)
-#define IEEE80211_CCK_RATE_5MB_MASK            (1<<2)
-#define IEEE80211_CCK_RATE_11MB_MASK           (1<<3)
-#define IEEE80211_OFDM_RATE_6MB_MASK           (1<<4)
-#define IEEE80211_OFDM_RATE_9MB_MASK           (1<<5)
-#define IEEE80211_OFDM_RATE_12MB_MASK          (1<<6)
-#define IEEE80211_OFDM_RATE_18MB_MASK          (1<<7)
-#define IEEE80211_OFDM_RATE_24MB_MASK          (1<<8)
-#define IEEE80211_OFDM_RATE_36MB_MASK          (1<<9)
-#define IEEE80211_OFDM_RATE_48MB_MASK          (1<<10)
-#define IEEE80211_OFDM_RATE_54MB_MASK          (1<<11)
-
-#define IEEE80211_CCK_RATES_MASK         0x0000000F
-#define IEEE80211_CCK_BASIC_RATES_MASK  (IEEE80211_CCK_RATE_1MB_MASK | \
-       IEEE80211_CCK_RATE_2MB_MASK)
-#define IEEE80211_CCK_DEFAULT_RATES_MASK (IEEE80211_CCK_BASIC_RATES_MASK | \
-       IEEE80211_CCK_RATE_5MB_MASK | \
-       IEEE80211_CCK_RATE_11MB_MASK)
-
-#define IEEE80211_OFDM_RATES_MASK        0x00000FF0
-#define IEEE80211_OFDM_BASIC_RATES_MASK          (IEEE80211_OFDM_RATE_6MB_MASK | \
-       IEEE80211_OFDM_RATE_12MB_MASK | \
-       IEEE80211_OFDM_RATE_24MB_MASK)
-#define IEEE80211_OFDM_DEFAULT_RATES_MASK (IEEE80211_OFDM_BASIC_RATES_MASK | \
-       IEEE80211_OFDM_RATE_9MB_MASK  | \
-       IEEE80211_OFDM_RATE_18MB_MASK | \
-       IEEE80211_OFDM_RATE_36MB_MASK | \
-       IEEE80211_OFDM_RATE_48MB_MASK | \
-       IEEE80211_OFDM_RATE_54MB_MASK)
-#define IEEE80211_DEFAULT_RATES_MASK (IEEE80211_OFDM_DEFAULT_RATES_MASK | \
-                                     IEEE80211_CCK_DEFAULT_RATES_MASK)
-
-
-/* This really should be 8, but not for our firmware */
-#define MAX_SUPPORTED_RATES 32
-#define MAX_COUNTRY_TRIPLETS 32
-
-/* Headers */
-struct ieee80211_header {
-       __le16 frame_ctl;
-       __le16 duration_id;
-       u8 da[ETH_ALEN];
-       u8 sa[ETH_ALEN];
-       u8 bssid[ETH_ALEN];
-       __le16 seq_ctl;
-       u8 payload[0];
-} __packed;
-
-struct wl12xx_ie_header {
-       u8 id;
-       u8 len;
-} __packed;
-
-/* IEs */
-
-struct wl12xx_ie_ssid {
-       struct wl12xx_ie_header header;
-       char ssid[IEEE80211_MAX_SSID_LEN];
-} __packed;
-
-struct wl12xx_ie_rates {
-       struct wl12xx_ie_header header;
-       u8 rates[MAX_SUPPORTED_RATES];
-} __packed;
-
-struct wl12xx_ie_ds_params {
-       struct wl12xx_ie_header header;
-       u8 channel;
-} __packed;
-
-struct country_triplet {
-       u8 channel;
-       u8 num_channels;
-       u8 max_tx_power;
-} __packed;
-
-struct wl12xx_ie_country {
-       struct wl12xx_ie_header header;
-       u8 country_string[IEEE80211_COUNTRY_STRING_LEN];
-       struct country_triplet triplets[MAX_COUNTRY_TRIPLETS];
-} __packed;
-
-
-/* Templates */
-
-struct wl12xx_null_data_template {
-       struct ieee80211_header header;
-} __packed;
-
-struct wl12xx_ps_poll_template {
-       __le16 fc;
-       __le16 aid;
-       u8 bssid[ETH_ALEN];
-       u8 ta[ETH_ALEN];
-} __packed;
-
-struct wl12xx_arp_rsp_template {
-       /* not including ieee80211 header */
-
-       u8 llc_hdr[sizeof(rfc1042_header)];
-       __be16 llc_type;
-
-       struct arphdr arp_hdr;
-       u8 sender_hw[ETH_ALEN];
-       __be32 sender_ip;
-       u8 target_hw[ETH_ALEN];
-       __be32 target_ip;
-} __packed;
-
-struct wl12xx_disconn_template {
-       struct ieee80211_header header;
-       __le16 disconn_reason;
-} __packed;
-
-#endif
diff --git a/drivers/net/wireless/wl12xx/wl12xx_platform_data.c b/drivers/net/wireless/wl12xx/wl12xx_platform_data.c
deleted file mode 100644 (file)
index 998e958..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * This file is part of wl12xx
- *
- * Copyright (C) 2010-2011 Texas Instruments, Inc.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <linux/module.h>
-#include <linux/err.h>
-#include <linux/wl12xx.h>
-
-static struct wl12xx_platform_data *platform_data;
-
-int __init wl12xx_set_platform_data(const struct wl12xx_platform_data *data)
-{
-       if (platform_data)
-               return -EBUSY;
-       if (!data)
-               return -EINVAL;
-
-       platform_data = kmemdup(data, sizeof(*data), GFP_KERNEL);
-       if (!platform_data)
-               return -ENOMEM;
-
-       return 0;
-}
-
-struct wl12xx_platform_data *wl12xx_get_platform_data(void)
-{
-       if (!platform_data)
-               return ERR_PTR(-ENODEV);
-
-       return platform_data;
-}
-EXPORT_SYMBOL(wl12xx_get_platform_data);
index cb6204f783002dc3ddcc79adebcc79fa61cc4392..e6ec16d92e65d2ee362119f3f015f6d9322d00d2 100644 (file)
@@ -266,9 +266,13 @@ struct pn533 {
        int in_maxlen;
        struct pn533_frame *in_frame;
 
-       struct tasklet_struct tasklet;
-       struct pn533_frame *tklt_in_frame;
-       int tklt_in_error;
+       struct sk_buff_head resp_q;
+
+       struct workqueue_struct *wq;
+       struct work_struct cmd_work;
+       struct work_struct mi_work;
+       struct pn533_frame *wq_in_frame;
+       int wq_in_error;
 
        pn533_cmd_complete_t cmd_complete;
        void *cmd_complete_arg;
@@ -383,15 +387,21 @@ static bool pn533_rx_frame_is_cmd_response(struct pn533_frame *frame, u8 cmd)
        return (PN533_FRAME_CMD(frame) == PN533_CMD_RESPONSE(cmd));
 }
 
-static void pn533_tasklet_cmd_complete(unsigned long arg)
+
+static void pn533_wq_cmd_complete(struct work_struct *work)
 {
-       struct pn533 *dev = (struct pn533 *) arg;
-       struct pn533_frame *in_frame = dev->tklt_in_frame;
+       struct pn533 *dev = container_of(work, struct pn533, cmd_work);
+       struct pn533_frame *in_frame;
        int rc;
 
-       if (dev->tklt_in_error)
+       if (dev == NULL)
+               return;
+
+       in_frame = dev->wq_in_frame;
+
+       if (dev->wq_in_error)
                rc = dev->cmd_complete(dev, dev->cmd_complete_arg, NULL,
-                                                       dev->tklt_in_error);
+                                                       dev->wq_in_error);
        else
                rc = dev->cmd_complete(dev, dev->cmd_complete_arg,
                                        PN533_FRAME_CMD_PARAMS_PTR(in_frame),
@@ -406,7 +416,7 @@ static void pn533_recv_response(struct urb *urb)
        struct pn533 *dev = urb->context;
        struct pn533_frame *in_frame;
 
-       dev->tklt_in_frame = NULL;
+       dev->wq_in_frame = NULL;
 
        switch (urb->status) {
        case 0:
@@ -417,36 +427,36 @@ static void pn533_recv_response(struct urb *urb)
        case -ESHUTDOWN:
                nfc_dev_dbg(&dev->interface->dev, "Urb shutting down with"
                                                " status: %d", urb->status);
-               dev->tklt_in_error = urb->status;
-               goto sched_tasklet;
+               dev->wq_in_error = urb->status;
+               goto sched_wq;
        default:
                nfc_dev_err(&dev->interface->dev, "Nonzero urb status received:"
                                                        " %d", urb->status);
-               dev->tklt_in_error = urb->status;
-               goto sched_tasklet;
+               dev->wq_in_error = urb->status;
+               goto sched_wq;
        }
 
        in_frame = dev->in_urb->transfer_buffer;
 
        if (!pn533_rx_frame_is_valid(in_frame)) {
                nfc_dev_err(&dev->interface->dev, "Received an invalid frame");
-               dev->tklt_in_error = -EIO;
-               goto sched_tasklet;
+               dev->wq_in_error = -EIO;
+               goto sched_wq;
        }
 
        if (!pn533_rx_frame_is_cmd_response(in_frame, dev->cmd)) {
                nfc_dev_err(&dev->interface->dev, "The received frame is not "
                                                "response to the last command");
-               dev->tklt_in_error = -EIO;
-               goto sched_tasklet;
+               dev->wq_in_error = -EIO;
+               goto sched_wq;
        }
 
        nfc_dev_dbg(&dev->interface->dev, "Received a valid frame");
-       dev->tklt_in_error = 0;
-       dev->tklt_in_frame = in_frame;
+       dev->wq_in_error = 0;
+       dev->wq_in_frame = in_frame;
 
-sched_tasklet:
-       tasklet_schedule(&dev->tasklet);
+sched_wq:
+       queue_work(dev->wq, &dev->cmd_work);
 }
 
 static int pn533_submit_urb_for_response(struct pn533 *dev, gfp_t flags)
@@ -471,21 +481,21 @@ static void pn533_recv_ack(struct urb *urb)
        case -ESHUTDOWN:
                nfc_dev_dbg(&dev->interface->dev, "Urb shutting down with"
                                                " status: %d", urb->status);
-               dev->tklt_in_error = urb->status;
-               goto sched_tasklet;
+               dev->wq_in_error = urb->status;
+               goto sched_wq;
        default:
                nfc_dev_err(&dev->interface->dev, "Nonzero urb status received:"
                                                        " %d", urb->status);
-               dev->tklt_in_error = urb->status;
-               goto sched_tasklet;
+               dev->wq_in_error = urb->status;
+               goto sched_wq;
        }
 
        in_frame = dev->in_urb->transfer_buffer;
 
        if (!pn533_rx_frame_is_ack(in_frame)) {
                nfc_dev_err(&dev->interface->dev, "Received an invalid ack");
-               dev->tklt_in_error = -EIO;
-               goto sched_tasklet;
+               dev->wq_in_error = -EIO;
+               goto sched_wq;
        }
 
        nfc_dev_dbg(&dev->interface->dev, "Received a valid ack");
@@ -494,15 +504,15 @@ static void pn533_recv_ack(struct urb *urb)
        if (rc) {
                nfc_dev_err(&dev->interface->dev, "usb_submit_urb failed with"
                                                        " result %d", rc);
-               dev->tklt_in_error = rc;
-               goto sched_tasklet;
+               dev->wq_in_error = rc;
+               goto sched_wq;
        }
 
        return;
 
-sched_tasklet:
-       dev->tklt_in_frame = NULL;
-       tasklet_schedule(&dev->tasklet);
+sched_wq:
+       dev->wq_in_frame = NULL;
+       queue_work(dev->wq, &dev->cmd_work);
 }
 
 static int pn533_submit_urb_for_ack(struct pn533 *dev, gfp_t flags)
@@ -1249,6 +1259,8 @@ static void pn533_deactivate_target(struct nfc_dev *nfc_dev, u32 target_idx)
 
        dev->tgt_active_prot = 0;
 
+       skb_queue_purge(&dev->resp_q);
+
        pn533_tx_frame_init(dev->out_frame, PN533_CMD_IN_RELEASE);
 
        tg = 1;
@@ -1447,11 +1459,49 @@ struct pn533_data_exchange_arg {
        void *cb_context;
 };
 
+static struct sk_buff *pn533_build_response(struct pn533 *dev)
+{
+       struct sk_buff *skb, *tmp, *t;
+       unsigned int skb_len = 0, tmp_len = 0;
+
+       nfc_dev_dbg(&dev->interface->dev, "%s\n", __func__);
+
+       if (skb_queue_empty(&dev->resp_q))
+               return NULL;
+
+       if (skb_queue_len(&dev->resp_q) == 1) {
+               skb = skb_dequeue(&dev->resp_q);
+               goto out;
+       }
+
+       skb_queue_walk_safe(&dev->resp_q, tmp, t)
+               skb_len += tmp->len;
+
+       nfc_dev_dbg(&dev->interface->dev, "%s total length %d\n",
+                   __func__, skb_len);
+
+       skb = alloc_skb(skb_len, GFP_KERNEL);
+       if (skb == NULL)
+               goto out;
+
+       skb_put(skb, skb_len);
+
+       skb_queue_walk_safe(&dev->resp_q, tmp, t) {
+               memcpy(skb->data + tmp_len, tmp->data, tmp->len);
+               tmp_len += tmp->len;
+       }
+
+out:
+       skb_queue_purge(&dev->resp_q);
+
+       return skb;
+}
+
 static int pn533_data_exchange_complete(struct pn533 *dev, void *_arg,
                                                u8 *params, int params_len)
 {
        struct pn533_data_exchange_arg *arg = _arg;
-       struct sk_buff *skb_resp = arg->skb_resp;
+       struct sk_buff *skb = NULL, *skb_resp = arg->skb_resp;
        struct pn533_frame *in_frame = (struct pn533_frame *) skb_resp->data;
        int err = 0;
        u8 status;
@@ -1459,15 +1509,13 @@ static int pn533_data_exchange_complete(struct pn533 *dev, void *_arg,
 
        nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
 
-       dev_kfree_skb_irq(arg->skb_out);
+       dev_kfree_skb(arg->skb_out);
 
        if (params_len < 0) { /* error */
                err = params_len;
                goto error;
        }
 
-       skb_put(skb_resp, PN533_FRAME_SIZE(in_frame));
-
        status = params[0];
 
        cmd_ret = status & PN533_CMD_RET_MASK;
@@ -1478,25 +1526,27 @@ static int pn533_data_exchange_complete(struct pn533 *dev, void *_arg,
                goto error;
        }
 
+       skb_put(skb_resp, PN533_FRAME_SIZE(in_frame));
+       skb_pull(skb_resp, PN533_CMD_DATAEXCH_HEAD_LEN);
+       skb_trim(skb_resp, skb_resp->len - PN533_FRAME_TAIL_SIZE);
+       skb_queue_tail(&dev->resp_q, skb_resp);
+
        if (status & PN533_CMD_MI_MASK) {
-               /* TODO: Implement support to multi-part data exchange */
-               nfc_dev_err(&dev->interface->dev, "Multi-part message not yet"
-                                                               " supported");
-               /* Prevent the other messages from controller */
-               pn533_send_ack(dev, GFP_ATOMIC);
-               err = -ENOSYS;
-               goto error;
+               queue_work(dev->wq, &dev->mi_work);
+               return -EINPROGRESS;
        }
 
-       skb_pull(skb_resp, PN533_CMD_DATAEXCH_HEAD_LEN);
-       skb_trim(skb_resp, skb_resp->len - PN533_FRAME_TAIL_SIZE);
+       skb = pn533_build_response(dev);
+       if (skb == NULL)
+               goto error;
 
-       arg->cb(arg->cb_context, skb_resp, 0);
+       arg->cb(arg->cb_context, skb, 0);
        kfree(arg);
        return 0;
 
 error:
-       dev_kfree_skb_irq(skb_resp);
+       skb_queue_purge(&dev->resp_q);
+       dev_kfree_skb(skb_resp);
        arg->cb(arg->cb_context, NULL, err);
        kfree(arg);
        return 0;
@@ -1571,6 +1621,68 @@ error:
        return rc;
 }
 
+static void pn533_wq_mi_recv(struct work_struct *work)
+{
+       struct pn533 *dev = container_of(work, struct pn533, mi_work);
+       struct sk_buff *skb_cmd;
+       struct pn533_data_exchange_arg *arg = dev->cmd_complete_arg;
+       struct pn533_frame *out_frame, *in_frame;
+       struct sk_buff *skb_resp;
+       int skb_resp_len;
+       int rc;
+
+       nfc_dev_dbg(&dev->interface->dev, "%s", __func__);
+
+       /* This is a zero payload size skb */
+       skb_cmd = alloc_skb(PN533_CMD_DATAEXCH_HEAD_LEN + PN533_FRAME_TAIL_SIZE,
+                           GFP_KERNEL);
+       if (skb_cmd == NULL)
+               goto error_cmd;
+
+       skb_reserve(skb_cmd, PN533_CMD_DATAEXCH_HEAD_LEN);
+
+       rc = pn533_data_exchange_tx_frame(dev, skb_cmd);
+       if (rc)
+               goto error_frame;
+
+       skb_resp_len = PN533_CMD_DATAEXCH_HEAD_LEN +
+                       PN533_CMD_DATAEXCH_DATA_MAXLEN +
+                       PN533_FRAME_TAIL_SIZE;
+       skb_resp = alloc_skb(skb_resp_len, GFP_KERNEL);
+       if (!skb_resp) {
+               rc = -ENOMEM;
+               goto error_frame;
+       }
+
+       in_frame = (struct pn533_frame *) skb_resp->data;
+       out_frame = (struct pn533_frame *) skb_cmd->data;
+
+       arg->skb_resp = skb_resp;
+       arg->skb_out = skb_cmd;
+
+       rc = __pn533_send_cmd_frame_async(dev, out_frame, in_frame,
+                                         skb_resp_len,
+                                         pn533_data_exchange_complete,
+                                         dev->cmd_complete_arg, GFP_KERNEL);
+       if (!rc)
+               return;
+
+       nfc_dev_err(&dev->interface->dev, "Error %d when trying to"
+                                               " perform data_exchange", rc);
+
+       kfree_skb(skb_resp);
+
+error_frame:
+       kfree_skb(skb_cmd);
+
+error_cmd:
+       pn533_send_ack(dev, GFP_KERNEL);
+
+       kfree(arg);
+
+       up(&dev->cmd_lock);
+}
+
 static int pn533_set_configuration(struct pn533 *dev, u8 cfgitem, u8 *cfgdata,
                                                                u8 cfgdata_len)
 {
@@ -1668,7 +1780,15 @@ static int pn533_probe(struct usb_interface *interface,
                        NULL, 0,
                        pn533_send_complete, dev);
 
-       tasklet_init(&dev->tasklet, pn533_tasklet_cmd_complete, (ulong)dev);
+       INIT_WORK(&dev->cmd_work, pn533_wq_cmd_complete);
+       INIT_WORK(&dev->mi_work, pn533_wq_mi_recv);
+       dev->wq = alloc_workqueue("pn533",
+                                 WQ_NON_REENTRANT | WQ_UNBOUND | WQ_MEM_RECLAIM,
+                                 1);
+       if (dev->wq == NULL)
+               goto error;
+
+       skb_queue_head_init(&dev->resp_q);
 
        usb_set_intfdata(interface, dev);
 
@@ -1678,7 +1798,7 @@ static int pn533_probe(struct usb_interface *interface,
        rc = pn533_send_cmd_frame_sync(dev, dev->out_frame, dev->in_frame,
                                                                dev->in_maxlen);
        if (rc)
-               goto kill_tasklet;
+               goto destroy_wq;
 
        fw_ver = (struct pn533_fw_version *)
                                PN533_FRAME_CMD_PARAMS_PTR(dev->in_frame);
@@ -1694,7 +1814,7 @@ static int pn533_probe(struct usb_interface *interface,
                                           PN533_CMD_DATAEXCH_HEAD_LEN,
                                           PN533_FRAME_TAIL_SIZE);
        if (!dev->nfc_dev)
-               goto kill_tasklet;
+               goto destroy_wq;
 
        nfc_set_parent_dev(dev->nfc_dev, &interface->dev);
        nfc_set_drvdata(dev->nfc_dev, dev);
@@ -1720,8 +1840,8 @@ static int pn533_probe(struct usb_interface *interface,
 
 free_nfc_dev:
        nfc_free_device(dev->nfc_dev);
-kill_tasklet:
-       tasklet_kill(&dev->tasklet);
+destroy_wq:
+       destroy_workqueue(dev->wq);
 error:
        kfree(dev->in_frame);
        usb_free_urb(dev->in_urb);
@@ -1744,7 +1864,9 @@ static void pn533_disconnect(struct usb_interface *interface)
        usb_kill_urb(dev->in_urb);
        usb_kill_urb(dev->out_urb);
 
-       tasklet_kill(&dev->tasklet);
+       destroy_workqueue(dev->wq);
+
+       skb_queue_purge(&dev->resp_q);
 
        kfree(dev->in_frame);
        usb_free_urb(dev->in_urb);
index db84e2f6b289ea61642846b0e9ece12361b7f7c7..ce9af89185148228c76f260bfd68a848f43e3977 100644 (file)
@@ -1458,7 +1458,7 @@ enum {
  * be specified in a vendor specific information element
  */
 enum {
-       IEEE80211_PATH_PROTOCOL_HWMP = 0,
+       IEEE80211_PATH_PROTOCOL_HWMP = 1,
        IEEE80211_PATH_PROTOCOL_VENDOR = 255,
 };
 
@@ -1470,7 +1470,7 @@ enum {
  * specified in a vendor specific information element
  */
 enum {
-       IEEE80211_PATH_METRIC_AIRTIME = 0,
+       IEEE80211_PATH_METRIC_AIRTIME = 1,
        IEEE80211_PATH_METRIC_VENDOR = 255,
 };
 
index 39c1fcf089c0a99ec654d4c5fb190eda696dd665..0ae9b5857c83b0786a9f7ea92ffe51991c34a1b8 100644 (file)
@@ -70,6 +70,7 @@ enum nfc_commands {
        NFC_EVENT_TARGETS_FOUND,
        NFC_EVENT_DEVICE_ADDED,
        NFC_EVENT_DEVICE_REMOVED,
+       NFC_EVENT_TARGET_LOST,
 /* private: internal use only */
        __NFC_CMD_AFTER_LAST
 };
index a587867375b2712bc3717be734f1e530bb331880..815dc3f37e2b5c0e21d95cbdc5186533aa9f89d7 100644 (file)
@@ -1710,7 +1710,8 @@ struct cfg80211_ops {
                                  struct net_device *dev,
                                  u16 noack_map);
 
-       struct ieee80211_channel *(*get_channel)(struct wiphy *wiphy);
+       struct ieee80211_channel *(*get_channel)(struct wiphy *wiphy,
+                                              enum nl80211_channel_type *type);
 };
 
 /*
@@ -1744,10 +1745,6 @@ struct cfg80211_ops {
  *     hints read the documenation for regulatory_hint_found_beacon()
  * @WIPHY_FLAG_NETNS_OK: if not set, do not allow changing the netns of this
  *     wiphy at all
- * @WIPHY_FLAG_ENFORCE_COMBINATIONS: Set this flag to enforce interface
- *     combinations for this device. This flag is used for backward
- *     compatibility only until all drivers advertise combinations and
- *     they will always be enforced.
  * @WIPHY_FLAG_PS_ON_BY_DEFAULT: if set to true, powersave will be enabled
  *     by default -- this flag will be set depending on the kernel's default
  *     on wiphy_new(), but can be changed by the driver if it has a good
@@ -1792,7 +1789,7 @@ enum wiphy_flags {
        WIPHY_FLAG_IBSS_RSN                     = BIT(8),
        WIPHY_FLAG_MESH_AUTH                    = BIT(10),
        WIPHY_FLAG_SUPPORTS_SCHED_SCAN          = BIT(11),
-       WIPHY_FLAG_ENFORCE_COMBINATIONS         = BIT(12),
+       /* use hole at 12 */
        WIPHY_FLAG_SUPPORTS_FW_ROAM             = BIT(13),
        WIPHY_FLAG_AP_UAPSD                     = BIT(14),
        WIPHY_FLAG_SUPPORTS_TDLS                = BIT(15),
index 32cd5171fa227c028119a6f44a2ceb9350ddb1de..bebd89f7f6c3b5c8a3d561c4870b54424b087ce3 100644 (file)
@@ -2947,6 +2947,7 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
  */
 __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
                                        struct ieee80211_vif *vif,
+                                       enum ieee80211_band band,
                                        size_t frame_len,
                                        struct ieee80211_rate *rate);
 
@@ -3800,4 +3801,7 @@ int ieee80211_add_srates_ie(struct ieee80211_vif *vif,
 
 int ieee80211_add_ext_srates_ie(struct ieee80211_vif *vif,
                                struct sk_buff *skb, bool need_basic);
+
+int ieee80211_ave_rssi(struct ieee80211_vif *vif);
+
 #endif /* MAC80211_H */
diff --git a/include/net/nfc/hci.h b/include/net/nfc/hci.h
new file mode 100644 (file)
index 0000000..aca65a5
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2011  Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __NET_HCI_H
+#define __NET_HCI_H
+
+#include <linux/skbuff.h>
+
+#include <net/nfc/nfc.h>
+
+struct nfc_hci_dev;
+
+struct nfc_hci_ops {
+       int (*open) (struct nfc_hci_dev *hdev);
+       void (*close) (struct nfc_hci_dev *hdev);
+       int (*hci_ready) (struct nfc_hci_dev *hdev);
+       int (*xmit) (struct nfc_hci_dev *hdev, struct sk_buff *skb);
+       int (*start_poll) (struct nfc_hci_dev *hdev, u32 protocols);
+       int (*target_from_gate) (struct nfc_hci_dev *hdev, u8 gate,
+                                struct nfc_target *target);
+       int (*complete_target_discovered) (struct nfc_hci_dev *hdev, u8 gate,
+                                          struct nfc_target *target);
+       int (*data_exchange) (struct nfc_hci_dev *hdev,
+                             struct nfc_target *target,
+                             struct sk_buff *skb, struct sk_buff **res_skb);
+};
+
+#define NFC_HCI_MAX_CUSTOM_GATES       15
+struct nfc_hci_init_data {
+       u8 gate_count;
+       u8 gates[NFC_HCI_MAX_CUSTOM_GATES];
+       char session_id[9];
+};
+
+typedef int (*xmit) (struct sk_buff *skb, void *cb_data);
+
+#define NFC_HCI_MAX_GATES              256
+
+struct nfc_hci_dev {
+       struct nfc_dev *ndev;
+
+       u32 max_data_link_payload;
+
+       struct mutex msg_tx_mutex;
+
+       struct list_head msg_tx_queue;
+
+       struct workqueue_struct *msg_tx_wq;
+       struct work_struct msg_tx_work;
+
+       struct timer_list cmd_timer;
+       struct hci_msg *cmd_pending_msg;
+
+       struct sk_buff_head rx_hcp_frags;
+
+       struct workqueue_struct *msg_rx_wq;
+       struct work_struct msg_rx_work;
+
+       struct sk_buff_head msg_rx_queue;
+
+       struct nfc_hci_ops *ops;
+
+       struct nfc_hci_init_data init_data;
+
+       void *clientdata;
+
+       u8 gate2pipe[NFC_HCI_MAX_GATES];
+
+       bool poll_started;
+       struct nfc_target *targets;
+       int target_count;
+
+       u8 sw_romlib;
+       u8 sw_patch;
+       u8 sw_flashlib_major;
+       u8 sw_flashlib_minor;
+
+       u8 hw_derivative;
+       u8 hw_version;
+       u8 hw_mpw;
+       u8 hw_software;
+       u8 hw_bsid;
+};
+
+/* hci device allocation */
+struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
+                                           struct nfc_hci_init_data *init_data,
+                                           u32 protocols,
+                                           int tx_headroom,
+                                           int tx_tailroom,
+                                           int max_link_payload);
+void nfc_hci_free_device(struct nfc_hci_dev *hdev);
+
+int nfc_hci_register_device(struct nfc_hci_dev *hdev);
+void nfc_hci_unregister_device(struct nfc_hci_dev *hdev);
+
+void nfc_hci_set_clientdata(struct nfc_hci_dev *hdev, void *clientdata);
+void *nfc_hci_get_clientdata(struct nfc_hci_dev *hdev);
+
+/* Host IDs */
+#define NFC_HCI_HOST_CONTROLLER_ID     0x00
+#define NFC_HCI_TERMINAL_HOST_ID       0x01
+#define NFC_HCI_UICC_HOST_ID           0x02
+
+/* Host Controller Gates and registry indexes */
+#define NFC_HCI_ADMIN_GATE 0x00
+#define NFC_HCI_ADMIN_SESSION_IDENTITY 0x01
+#define NFC_HCI_ADMIN_MAX_PIPE         0x02
+#define NFC_HCI_ADMIN_WHITELIST                0x03
+#define NFC_HCI_ADMIN_HOST_LIST                0x04
+
+#define NFC_HCI_LOOPBACK_GATE          0x04
+
+#define NFC_HCI_ID_MGMT_GATE           0x05
+#define NFC_HCI_ID_MGMT_VERSION_SW     0x01
+#define NFC_HCI_ID_MGMT_VERSION_HW     0x03
+#define NFC_HCI_ID_MGMT_VENDOR_NAME    0x04
+#define NFC_HCI_ID_MGMT_MODEL_ID       0x05
+#define NFC_HCI_ID_MGMT_HCI_VERSION    0x02
+#define NFC_HCI_ID_MGMT_GATES_LIST     0x06
+
+#define NFC_HCI_LINK_MGMT_GATE         0x06
+#define NFC_HCI_LINK_MGMT_REC_ERROR    0x01
+
+#define NFC_HCI_RF_READER_B_GATE                       0x11
+#define NFC_HCI_RF_READER_B_PUPI                       0x03
+#define NFC_HCI_RF_READER_B_APPLICATION_DATA           0x04
+#define NFC_HCI_RF_READER_B_AFI                                0x02
+#define NFC_HCI_RF_READER_B_HIGHER_LAYER_RESPONSE      0x01
+#define NFC_HCI_RF_READER_B_HIGHER_LAYER_DATA          0x05
+
+#define NFC_HCI_RF_READER_A_GATE               0x13
+#define NFC_HCI_RF_READER_A_UID                        0x02
+#define NFC_HCI_RF_READER_A_ATQA               0x04
+#define NFC_HCI_RF_READER_A_APPLICATION_DATA   0x05
+#define NFC_HCI_RF_READER_A_SAK                        0x03
+#define NFC_HCI_RF_READER_A_FWI_SFGT           0x06
+#define NFC_HCI_RF_READER_A_DATARATE_MAX       0x01
+
+#define NFC_HCI_TYPE_A_SEL_PROT(x)             (((x) & 0x60) >> 5)
+#define NFC_HCI_TYPE_A_SEL_PROT_MIFARE         0
+#define NFC_HCI_TYPE_A_SEL_PROT_ISO14443       1
+#define NFC_HCI_TYPE_A_SEL_PROT_DEP            2
+#define NFC_HCI_TYPE_A_SEL_PROT_ISO14443_DEP   3
+
+/* Generic events */
+#define NFC_HCI_EVT_HCI_END_OF_OPERATION       0x01
+#define NFC_HCI_EVT_POST_DATA                  0x02
+#define NFC_HCI_EVT_HOT_PLUG                   0x03
+
+/* Reader RF gates events */
+#define NFC_HCI_EVT_READER_REQUESTED   0x10
+#define NFC_HCI_EVT_END_OPERATION      0x11
+
+/* Reader Application gate events */
+#define NFC_HCI_EVT_TARGET_DISCOVERED  0x10
+
+/* receiving messages from lower layer */
+void nfc_hci_resp_received(struct nfc_hci_dev *hdev, u8 result,
+                          struct sk_buff *skb);
+void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
+                         struct sk_buff *skb);
+void nfc_hci_event_received(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
+                           struct sk_buff *skb);
+void nfc_hci_recv_frame(struct nfc_hci_dev *hdev, struct sk_buff *skb);
+
+/* connecting to gates and sending hci instructions */
+int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate);
+int nfc_hci_disconnect_gate(struct nfc_hci_dev *hdev, u8 gate);
+int nfc_hci_disconnect_all_gates(struct nfc_hci_dev *hdev);
+int nfc_hci_get_param(struct nfc_hci_dev *hdev, u8 gate, u8 idx,
+                     struct sk_buff **skb);
+int nfc_hci_set_param(struct nfc_hci_dev *hdev, u8 gate, u8 idx,
+                     const u8 *param, size_t param_len);
+int nfc_hci_send_cmd(struct nfc_hci_dev *hdev, u8 gate, u8 cmd,
+                    const u8 *param, size_t param_len, struct sk_buff **skb);
+int nfc_hci_send_response(struct nfc_hci_dev *hdev, u8 gate, u8 response,
+                         const u8 *param, size_t param_len);
+int nfc_hci_send_event(struct nfc_hci_dev *hdev, u8 gate, u8 event,
+                      const u8 *param, size_t param_len);
+
+#endif /* __NET_HCI_H */
index 79955a238ccc14f87ae6ce56e873e3e6b86fa1a5..9a2505a5b8de7687aa266f6f631b0b4a7396021e 100644 (file)
@@ -62,10 +62,12 @@ struct nfc_ops {
        int (*data_exchange)(struct nfc_dev *dev, u32 target_idx,
                             struct sk_buff *skb, data_exchange_cb_t cb,
                             void *cb_context);
+       int (*check_presence)(struct nfc_dev *dev, u32 target_idx);
 };
 
 #define NFC_TARGET_IDX_ANY -1
 #define NFC_MAX_GT_LEN 48
+#define NFC_TARGET_IDX_NONE 0xffffffff
 
 struct nfc_target {
        u32 idx;
@@ -78,6 +80,8 @@ struct nfc_target {
        u8 sensb_res[NFC_SENSB_RES_MAXSIZE];
        u8 sensf_res_len;
        u8 sensf_res[NFC_SENSF_RES_MAXSIZE];
+       u8 hci_reader_gate;
+       u8 logical_idx;
 };
 
 struct nfc_genl_data {
@@ -87,6 +91,7 @@ struct nfc_genl_data {
 
 struct nfc_dev {
        unsigned int idx;
+       u32 target_next_idx;
        struct nfc_target *targets;
        int n_targets;
        int targets_generation;
@@ -94,7 +99,7 @@ struct nfc_dev {
        struct device dev;
        bool dev_up;
        bool polling;
-       bool remote_activated;
+       u32 activated_target_idx;
        bool dep_link_up;
        u32 dep_rf_mode;
        struct nfc_genl_data genl_data;
@@ -103,6 +108,10 @@ struct nfc_dev {
        int tx_headroom;
        int tx_tailroom;
 
+       struct timer_list check_pres_timer;
+       struct workqueue_struct *check_pres_wq;
+       struct work_struct check_pres_work;
+
        struct nfc_ops *ops;
 };
 #define to_nfc_dev(_dev) container_of(_dev, struct nfc_dev, dev)
@@ -181,6 +190,7 @@ int nfc_set_remote_general_bytes(struct nfc_dev *dev,
 
 int nfc_targets_found(struct nfc_dev *dev,
                      struct nfc_target *targets, int ntargets);
+int nfc_target_lost(struct nfc_dev *dev, u32 target_idx);
 
 int nfc_dep_link_is_up(struct nfc_dev *dev, u32 target_idx,
                       u8 comm_mode, u8 rf_mode);
diff --git a/include/net/nfc/shdlc.h b/include/net/nfc/shdlc.h
new file mode 100644 (file)
index 0000000..1071987
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __NFC_SHDLC_H
+#define __NFC_SHDLC_H
+
+struct nfc_shdlc;
+
+struct nfc_shdlc_ops {
+       int (*open) (struct nfc_shdlc *shdlc);
+       void (*close) (struct nfc_shdlc *shdlc);
+       int (*hci_ready) (struct nfc_shdlc *shdlc);
+       int (*xmit) (struct nfc_shdlc *shdlc, struct sk_buff *skb);
+       int (*start_poll) (struct nfc_shdlc *shdlc, u32 protocols);
+       int (*target_from_gate) (struct nfc_shdlc *shdlc, u8 gate,
+                                struct nfc_target *target);
+       int (*complete_target_discovered) (struct nfc_shdlc *shdlc, u8 gate,
+                                          struct nfc_target *target);
+       int (*data_exchange) (struct nfc_shdlc *shdlc,
+                             struct nfc_target *target,
+                             struct sk_buff *skb, struct sk_buff **res_skb);
+};
+
+enum shdlc_state {
+       SHDLC_DISCONNECTED = 0,
+       SHDLC_CONNECTING = 1,
+       SHDLC_NEGOCIATING = 2,
+       SHDLC_CONNECTED = 3
+};
+
+struct nfc_shdlc {
+       struct mutex state_mutex;
+       enum shdlc_state state;
+       int hard_fault;
+
+       struct nfc_hci_dev *hdev;
+
+       wait_queue_head_t *connect_wq;
+       int connect_tries;
+       int connect_result;
+       struct timer_list connect_timer;/* aka T3 in spec 10.6.1 */
+
+       u8 w;                           /* window size */
+       bool srej_support;
+
+       struct timer_list t1_timer;     /* send ack timeout */
+       bool t1_active;
+
+       struct timer_list t2_timer;     /* guard/retransmit timeout */
+       bool t2_active;
+
+       int ns;                         /* next seq num for send */
+       int nr;                         /* next expected seq num for receive */
+       int dnr;                        /* oldest sent unacked seq num */
+
+       struct sk_buff_head rcv_q;
+
+       struct sk_buff_head send_q;
+       bool rnr;                       /* other side is not ready to receive */
+
+       struct sk_buff_head ack_pending_q;
+
+       struct workqueue_struct *sm_wq;
+       struct work_struct sm_work;
+
+       struct nfc_shdlc_ops *ops;
+
+       int client_headroom;
+       int client_tailroom;
+
+       void *clientdata;
+};
+
+void nfc_shdlc_recv_frame(struct nfc_shdlc *shdlc, struct sk_buff *skb);
+
+struct nfc_shdlc *nfc_shdlc_allocate(struct nfc_shdlc_ops *ops,
+                                    struct nfc_hci_init_data *init_data,
+                                    u32 protocols,
+                                    int tx_headroom, int tx_tailroom,
+                                    int max_link_payload, const char *devname);
+
+void nfc_shdlc_free(struct nfc_shdlc *shdlc);
+
+void nfc_shdlc_set_clientdata(struct nfc_shdlc *shdlc, void *clientdata);
+void *nfc_shdlc_get_clientdata(struct nfc_shdlc *shdlc);
+struct nfc_hci_dev *nfc_shdlc_get_hci_dev(struct nfc_shdlc *shdlc);
+
+#endif /* __NFC_SHDLC_H */
index 355735491252a53a4701f5bda3d291cdd19bff9f..510a745c31082c129fcc453a9212f29627b50252 100644 (file)
@@ -2688,10 +2688,12 @@ static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
 }
 
 static struct ieee80211_channel *
-ieee80211_wiphy_get_channel(struct wiphy *wiphy)
+ieee80211_wiphy_get_channel(struct wiphy *wiphy,
+                           enum nl80211_channel_type *type)
 {
        struct ieee80211_local *local = wiphy_priv(wiphy);
 
+       *type = local->_oper_channel_type;
        return local->oper_channel;
 }
 
index 4be11ea3dfc4c5dc06e17d51ca67b6f66e76fe46..bd7a451b084968627db4599c92935d2b4b280c98 100644 (file)
@@ -1260,6 +1260,7 @@ int ieee80211_request_internal_scan(struct ieee80211_sub_if_data *sdata,
 int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
                           struct cfg80211_scan_request *req);
 void ieee80211_scan_cancel(struct ieee80211_local *local);
+void ieee80211_run_deferred_scan(struct ieee80211_local *local);
 ieee80211_rx_result
 ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb);
 
@@ -1272,9 +1273,6 @@ ieee80211_bss_info_update(struct ieee80211_local *local,
                          struct ieee802_11_elems *elems,
                          struct ieee80211_channel *channel,
                          bool beacon);
-struct ieee80211_bss *
-ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
-                    u8 *ssid, u8 ssid_len);
 void ieee80211_rx_bss_put(struct ieee80211_local *local,
                          struct ieee80211_bss *bss);
 
@@ -1403,7 +1401,7 @@ static inline int __ieee80211_resume(struct ieee80211_hw *hw)
 extern void *mac80211_wiphy_privid; /* for wiphy privid */
 u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
                        enum nl80211_iftype type);
-int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
+int ieee80211_frame_duration(enum ieee80211_band band, size_t len,
                             int rate, int erp, int short_preamble);
 void mac80211_ev_michael_mic_failure(struct ieee80211_sub_if_data *sdata, int keyidx,
                                     struct ieee80211_hdr *hdr, const u8 *tsc,
index 6e85faed053d83afa375efe544ea96083be7ed05..23d1da376eb39f108296be63cd93de7b16d509fa 100644 (file)
@@ -163,7 +163,8 @@ static int ieee80211_check_queues(struct ieee80211_sub_if_data *sdata)
                        return -EINVAL;
        }
 
-       if (sdata->vif.type != NL80211_IFTYPE_AP) {
+       if ((sdata->vif.type != NL80211_IFTYPE_AP) ||
+           !(sdata->local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)) {
                sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE;
                return 0;
        }
index a80da3784a25bfcc3a342ff9a0121e091ee68327..503016f58631b88213b93015257123e75e892cea 100644 (file)
@@ -800,10 +800,11 @@ static void hwmp_rann_frame_process(struct ieee80211_sub_if_data *sdata,
                                       0, sdata);
                mpath->sn = orig_sn;
                mpath->rann_metric = metric + metric_txsta;
+               /* Recording RANNs sender address to send individually
+                * addressed PREQs destined for root mesh STA */
+               memcpy(mpath->rann_snd_addr, mgmt->sa, ETH_ALEN);
        }
 
-       /* Using individually addressed PREQ for root node */
-       memcpy(mpath->rann_snd_addr, mgmt->sa, ETH_ALEN);
        mpath->is_root = true;
 
        if (root_is_gate)
index 49aaefd99635f5ca08c31dbe735f568416ae054c..baa6096c66b4b4714c40bcac0f0cb47f75778186 100644 (file)
@@ -538,6 +538,8 @@ int mesh_path_add(u8 *dst, struct ieee80211_sub_if_data *sdata)
 
        read_lock_bh(&pathtbl_resize_lock);
        memcpy(new_mpath->dst, dst, ETH_ALEN);
+       memset(new_mpath->rann_snd_addr, 0xff, ETH_ALEN);
+       new_mpath->is_root = false;
        new_mpath->sdata = sdata;
        new_mpath->flags = 0;
        skb_queue_head_init(&new_mpath->frame_queue);
index f78b0139856f8df34232c26a8e2f9f2ff4d50fec..ff60d6bcc63164b224ad59400ca29c83a3359fdf 100644 (file)
 /* This is not in the standard.  It represents a tolerable tbtt drift below
  * which we do no TSF adjustment.
  */
-#define TBTT_MINIMUM_ADJUSTMENT 10
+#define TOFFSET_MINIMUM_ADJUSTMENT 10
+
+/* This is not in the standard. It is a margin added to the
+ * Toffset setpoint to mitigate TSF overcorrection
+ * introduced by TSF adjustment latency.
+ */
+#define TOFFSET_SET_MARGIN 20
+
+/* This is not in the standard.  It represents the maximum Toffset jump above
+ * which we'll invalidate the Toffset setpoint and choose a new setpoint.  This
+ * could be, for instance, in case a neighbor is restarted and its TSF counter
+ * reset.
+ */
+#define TOFFSET_MAXIMUM_ADJUSTMENT 30000               /* 30 ms */
 
 struct sync_method {
        u8 method;
@@ -156,15 +169,22 @@ static void mesh_sync_offset_rx_bcn_presp(struct ieee80211_sub_if_data *sdata,
        if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
                s64 t_clockdrift = sta->t_offset_setpoint
                                   - sta->t_offset;
-
-               msync_dbg("STA %pM : sta->t_offset=%lld,"
-                         " sta->t_offset_setpoint=%lld,"
-                         " t_clockdrift=%lld",
+               msync_dbg("STA %pM : sta->t_offset=%lld, sta->t_offset_setpoint=%lld, t_clockdrift=%lld",
                          sta->sta.addr,
                          (long long) sta->t_offset,
                          (long long)
                          sta->t_offset_setpoint,
                          (long long) t_clockdrift);
+
+               if (t_clockdrift > TOFFSET_MAXIMUM_ADJUSTMENT ||
+                       t_clockdrift < -TOFFSET_MAXIMUM_ADJUSTMENT) {
+                       msync_dbg("STA %pM : t_clockdrift=%lld too large, setpoint reset",
+                                 sta->sta.addr,
+                                 (long long) t_clockdrift);
+                       clear_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN);
+                       goto no_sync;
+               }
+
                rcu_read_unlock();
 
                spin_lock_bh(&ifmsh->sync_offset_lock);
@@ -200,7 +220,7 @@ static void mesh_sync_offset_adjust_tbtt(struct ieee80211_sub_if_data *sdata)
        spin_lock_bh(&ifmsh->sync_offset_lock);
 
        if (ifmsh->sync_offset_clockdrift_max >
-               TBTT_MINIMUM_ADJUSTMENT) {
+               TOFFSET_MINIMUM_ADJUSTMENT) {
                /* Since ajusting the tsf here would
                 * require a possibly blocking call
                 * to the driver tsf setter, we punt
index bbf1100d90d6d7a50e3566f435fc9551508a735b..c8836fa7d627c65b6aa5a5e276c56af790f8b9bc 100644 (file)
@@ -1447,19 +1447,24 @@ void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
 {
        struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
+       struct ieee80211_local *local = sdata->local;
 
+       mutex_lock(&local->mtx);
        if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
-                             IEEE80211_STA_CONNECTION_POLL)))
-           return;
+                             IEEE80211_STA_CONNECTION_POLL))) {
+               mutex_unlock(&local->mtx);
+               return;
+       }
 
        ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
                          IEEE80211_STA_BEACON_POLL);
-       mutex_lock(&sdata->local->iflist_mtx);
-       ieee80211_recalc_ps(sdata->local, -1);
-       mutex_unlock(&sdata->local->iflist_mtx);
+
+       mutex_lock(&local->iflist_mtx);
+       ieee80211_recalc_ps(local, -1);
+       mutex_unlock(&local->iflist_mtx);
 
        if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
-               return;
+               goto out;
 
        /*
         * We've received a probe response, but are not sure whether
@@ -1471,6 +1476,9 @@ static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
        mod_timer(&ifmgd->conn_mon_timer,
                  round_jiffies_up(jiffies +
                                   IEEE80211_CONNECTION_IDLE_TIME));
+out:
+       ieee80211_run_deferred_scan(local);
+       mutex_unlock(&local->mtx);
 }
 
 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
@@ -1546,17 +1554,18 @@ static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
        if (!ieee80211_sdata_running(sdata))
                return;
 
-       if (sdata->local->scanning)
-               return;
-
-       if (sdata->local->tmp_channel)
-               return;
-
        mutex_lock(&ifmgd->mtx);
 
        if (!ifmgd->associated)
                goto out;
 
+       mutex_lock(&sdata->local->mtx);
+
+       if (sdata->local->tmp_channel || sdata->local->scanning) {
+               mutex_unlock(&sdata->local->mtx);
+               goto out;
+       }
+
 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
        if (beacon && net_ratelimit())
                printk(KERN_DEBUG "%s: detected beacon loss from AP "
@@ -1583,6 +1592,8 @@ static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
        else
                ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
 
+       mutex_unlock(&sdata->local->mtx);
+
        if (already)
                goto out;
 
index b39dda523f3986053c2d4e8d9a9619dce518d7c4..79633ae06fd6720c1a8d7a2f21f69c7594a41c16 100644 (file)
@@ -334,14 +334,15 @@ minstrel_get_rate(void *priv, struct ieee80211_sta *sta,
 
 
 static void
-calc_rate_durations(struct ieee80211_local *local, struct minstrel_rate *d,
+calc_rate_durations(enum ieee80211_band band,
+                   struct minstrel_rate *d,
                    struct ieee80211_rate *rate)
 {
        int erp = !!(rate->flags & IEEE80211_RATE_ERP_G);
 
-       d->perfect_tx_time = ieee80211_frame_duration(local, 1200,
+       d->perfect_tx_time = ieee80211_frame_duration(band, 1200,
                        rate->bitrate, erp, 1);
-       d->ack_time = ieee80211_frame_duration(local, 10,
+       d->ack_time = ieee80211_frame_duration(band, 10,
                        rate->bitrate, erp, 1);
 }
 
@@ -379,14 +380,14 @@ minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
 {
        struct minstrel_sta_info *mi = priv_sta;
        struct minstrel_priv *mp = priv;
-       struct ieee80211_local *local = hw_to_local(mp->hw);
        struct ieee80211_rate *ctl_rate;
        unsigned int i, n = 0;
        unsigned int t_slot = 9; /* FIXME: get real slot time */
 
        mi->lowest_rix = rate_lowest_index(sband, sta);
        ctl_rate = &sband->bitrates[mi->lowest_rix];
-       mi->sp_ack_dur = ieee80211_frame_duration(local, 10, ctl_rate->bitrate,
+       mi->sp_ack_dur = ieee80211_frame_duration(sband->band, 10,
+                               ctl_rate->bitrate,
                                !!(ctl_rate->flags & IEEE80211_RATE_ERP_G), 1);
 
        for (i = 0; i < sband->n_bitrates; i++) {
@@ -402,7 +403,7 @@ minstrel_rate_init(void *priv, struct ieee80211_supported_band *sband,
 
                mr->rix = i;
                mr->bitrate = sband->bitrates[i].bitrate / 5;
-               calc_rate_durations(local, mr, &sband->bitrates[i]);
+               calc_rate_durations(sband->band, mr, &sband->bitrates[i]);
 
                /* calculate maximum number of retransmissions before
                 * fallback (based on maximum segment size) */
index 3b3dcae13bbc77bbd9280955eda1321a1b6a4729..2d1acc6c54455de4d397dc64cc471d8890e95bc7 100644 (file)
@@ -692,7 +692,6 @@ minstrel_ht_update_caps(void *priv, struct ieee80211_supported_band *sband,
        struct minstrel_ht_sta_priv *msp = priv_sta;
        struct minstrel_ht_sta *mi = &msp->ht;
        struct ieee80211_mcs_info *mcs = &sta->ht_cap.mcs;
-       struct ieee80211_local *local = hw_to_local(mp->hw);
        u16 sta_cap = sta->ht_cap.cap;
        int n_supported = 0;
        int ack_dur;
@@ -711,8 +710,8 @@ minstrel_ht_update_caps(void *priv, struct ieee80211_supported_band *sband,
        memset(mi, 0, sizeof(*mi));
        mi->stats_update = jiffies;
 
-       ack_dur = ieee80211_frame_duration(local, 10, 60, 1, 1);
-       mi->overhead = ieee80211_frame_duration(local, 0, 60, 1, 1) + ack_dur;
+       ack_dur = ieee80211_frame_duration(sband->band, 10, 60, 1, 1);
+       mi->overhead = ieee80211_frame_duration(sband->band, 0, 60, 1, 1) + ack_dur;
        mi->overhead_rtscts = mi->overhead + 2 * ack_dur;
 
        mi->avg_ampdu_len = MINSTREL_FRAC(1, 1);
index c70e176771359b5e9371df1da486b29a157084f7..45f5aa229efde33669127781e9d86980ce46fb8f 100644 (file)
 #define IEEE80211_CHANNEL_TIME (HZ / 33)
 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 8)
 
-struct ieee80211_bss *
-ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
-                    u8 *ssid, u8 ssid_len)
-{
-       struct cfg80211_bss *cbss;
-
-       cbss = cfg80211_get_bss(local->hw.wiphy,
-                               ieee80211_get_channel(local->hw.wiphy, freq),
-                               bssid, ssid, ssid_len, 0, 0);
-       if (!cbss)
-               return NULL;
-       return (void *)cbss->priv;
-}
-
 static void ieee80211_rx_bss_free(struct cfg80211_bss *cbss)
 {
        struct ieee80211_bss *bss = (void *)cbss->priv;
@@ -387,6 +373,33 @@ static int ieee80211_start_sw_scan(struct ieee80211_local *local)
        return 0;
 }
 
+static bool ieee80211_can_scan(struct ieee80211_local *local,
+                              struct ieee80211_sub_if_data *sdata)
+{
+       if (!list_empty(&local->work_list))
+               return false;
+
+       if (sdata->vif.type == NL80211_IFTYPE_STATION &&
+           sdata->u.mgd.flags & (IEEE80211_STA_BEACON_POLL |
+                                 IEEE80211_STA_CONNECTION_POLL))
+               return false;
+
+       return true;
+}
+
+void ieee80211_run_deferred_scan(struct ieee80211_local *local)
+{
+       lockdep_assert_held(&local->mtx);
+
+       if (!local->scan_req || local->scanning)
+               return;
+
+       if (!ieee80211_can_scan(local, local->scan_sdata))
+               return;
+
+       ieee80211_queue_delayed_work(&local->hw, &local->scan_work,
+                                    round_jiffies_relative(0));
+}
 
 static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
                                  struct cfg80211_scan_request *req)
@@ -399,7 +412,7 @@ static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
        if (local->scan_req)
                return -EBUSY;
 
-       if (!list_empty(&local->work_list)) {
+       if (!ieee80211_can_scan(local, sdata)) {
                /* wait for the work to finish/time out */
                local->scan_req = req;
                local->scan_sdata = sdata;
index 5f8f89e89d6b446e989d9d3ae546174a711e016f..05f257aa2e08551f0991d4964d9acd97f4dcdf88 100644 (file)
@@ -355,7 +355,13 @@ void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb)
        int rtap_len;
 
        for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
-               if (info->status.rates[i].idx < 0) {
+               if ((info->flags & IEEE80211_TX_CTL_AMPDU) &&
+                   !(info->flags & IEEE80211_TX_STAT_AMPDU)) {
+                       /* just the first aggr frame carry status info */
+                       info->status.rates[i].idx = -1;
+                       info->status.rates[i].count = 0;
+                       break;
+               } else if (info->status.rates[i].idx < 0) {
                        break;
                } else if (i >= hw->max_report_rates) {
                        /* the HW cannot have attempted that rate */
index 4f6aac16ac3aa506607e7b800cabcd11600ab8de..0abbef952c1427a2cc5683cb76d2a504507b9ee5 100644 (file)
@@ -159,7 +159,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx,
                /* Time needed to transmit ACK
                 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
                 * to closest integer */
-               dur = ieee80211_frame_duration(local, 10, rate, erp,
+               dur = ieee80211_frame_duration(sband->band, 10, rate, erp,
                                tx->sdata->vif.bss_conf.use_short_preamble);
 
        if (next_frag_len) {
@@ -167,7 +167,7 @@ static __le16 ieee80211_duration(struct ieee80211_tx_data *tx,
                 * transmit next fragment plus ACK and 2 x SIFS. */
                dur *= 2; /* ACK + SIFS */
                /* next fragment */
-               dur += ieee80211_frame_duration(local, next_frag_len,
+               dur += ieee80211_frame_duration(sband->band, next_frag_len,
                                txrate->bitrate, erp,
                                tx->sdata->vif.bss_conf.use_short_preamble);
        }
index e67fe5c1def99b848ca46b430f15511b61a78adc..89c1e5b9ba94c4903df690d743ce730e41694c7e 100644 (file)
@@ -106,7 +106,7 @@ void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
        }
 }
 
-int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
+int ieee80211_frame_duration(enum ieee80211_band band, size_t len,
                             int rate, int erp, int short_preamble)
 {
        int dur;
@@ -120,7 +120,7 @@ int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
         * DIV_ROUND_UP() operations.
         */
 
-       if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) {
+       if (band == IEEE80211_BAND_5GHZ || erp) {
                /*
                 * OFDM:
                 *
@@ -162,10 +162,10 @@ int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
 /* Exported duration function for driver use */
 __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
                                        struct ieee80211_vif *vif,
+                                       enum ieee80211_band band,
                                        size_t frame_len,
                                        struct ieee80211_rate *rate)
 {
-       struct ieee80211_local *local = hw_to_local(hw);
        struct ieee80211_sub_if_data *sdata;
        u16 dur;
        int erp;
@@ -179,7 +179,7 @@ __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
                        erp = rate->flags & IEEE80211_RATE_ERP_G;
        }
 
-       dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp,
+       dur = ieee80211_frame_duration(band, frame_len, rate->bitrate, erp,
                                       short_preamble);
 
        return cpu_to_le16(dur);
@@ -198,7 +198,7 @@ __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
        u16 dur;
        struct ieee80211_supported_band *sband;
 
-       sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+       sband = local->hw.wiphy->bands[frame_txctl->band];
 
        short_preamble = false;
 
@@ -213,13 +213,13 @@ __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
        }
 
        /* CTS duration */
-       dur = ieee80211_frame_duration(local, 10, rate->bitrate,
+       dur = ieee80211_frame_duration(sband->band, 10, rate->bitrate,
                                       erp, short_preamble);
        /* Data frame duration */
-       dur += ieee80211_frame_duration(local, frame_len, rate->bitrate,
+       dur += ieee80211_frame_duration(sband->band, frame_len, rate->bitrate,
                                        erp, short_preamble);
        /* ACK duration */
-       dur += ieee80211_frame_duration(local, 10, rate->bitrate,
+       dur += ieee80211_frame_duration(sband->band, 10, rate->bitrate,
                                        erp, short_preamble);
 
        return cpu_to_le16(dur);
@@ -239,7 +239,7 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
        u16 dur;
        struct ieee80211_supported_band *sband;
 
-       sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
+       sband = local->hw.wiphy->bands[frame_txctl->band];
 
        short_preamble = false;
 
@@ -253,11 +253,11 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
        }
 
        /* Data frame duration */
-       dur = ieee80211_frame_duration(local, frame_len, rate->bitrate,
+       dur = ieee80211_frame_duration(sband->band, frame_len, rate->bitrate,
                                       erp, short_preamble);
        if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
                /* ACK duration */
-               dur += ieee80211_frame_duration(local, 10, rate->bitrate,
+               dur += ieee80211_frame_duration(sband->band, 10, rate->bitrate,
                                                erp, short_preamble);
        }
 
@@ -909,10 +909,8 @@ u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
        int i;
 
        sband = local->hw.wiphy->bands[band];
-       if (!sband) {
-               WARN_ON(1);
-               sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
-       }
+       if (WARN_ON(!sband))
+               return 1;
 
        if (band == IEEE80211_BAND_2GHZ)
                mandatory_flag = IEEE80211_RATE_MANDATORY_B;
@@ -1146,10 +1144,8 @@ u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
        int i, j;
        sband = local->hw.wiphy->bands[band];
 
-       if (!sband) {
-               WARN_ON(1);
-               sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
-       }
+       if (WARN_ON(!sband))
+               return 1;
 
        bitrates = sband->bitrates;
        num_rates = sband->n_bitrates;
@@ -1797,3 +1793,11 @@ int ieee80211_add_ext_srates_ie(struct ieee80211_vif *vif,
        }
        return 0;
 }
+
+int ieee80211_ave_rssi(struct ieee80211_vif *vif)
+{
+       struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
+       struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
+
+       return ifmgd->ave_beacon_signal;
+}
index c6e230efa04952314cf3f995f4c58d08ba142038..b2650a9d45ff765c7555628f82dea3c673a76380 100644 (file)
@@ -122,9 +122,6 @@ static void ieee80211_work_work(struct work_struct *work)
        enum work_action rma;
        bool remain_off_channel = false;
 
-       if (local->scanning)
-               return;
-
        /*
         * ieee80211_queue_work() should have picked up most cases,
         * here we'll pick the rest.
@@ -134,6 +131,11 @@ static void ieee80211_work_work(struct work_struct *work)
 
        mutex_lock(&local->mtx);
 
+       if (local->scanning) {
+               mutex_unlock(&local->mtx);
+               return;
+       }
+
        ieee80211_recalc_idle(local);
 
        list_for_each_entry_safe(wk, tmp, &local->work_list, list) {
@@ -226,13 +228,8 @@ static void ieee80211_work_work(struct work_struct *work)
                run_again(local, jiffies + HZ/2);
        }
 
-       if (list_empty(&local->work_list) && local->scan_req &&
-           !local->scanning)
-               ieee80211_queue_delayed_work(&local->hw,
-                                            &local->scan_work,
-                                            round_jiffies_relative(0));
-
        ieee80211_recalc_idle(local);
+       ieee80211_run_deferred_scan(local);
 
        mutex_unlock(&local->mtx);
 
index 44c865b86d6f56f5324f63ad66b38c309cda8247..8d8d9bc4b6ff4da74734d68894a40bfc8118cb6c 100644 (file)
@@ -14,6 +14,7 @@ menuconfig NFC
          be called nfc.
 
 source "net/nfc/nci/Kconfig"
+source "net/nfc/hci/Kconfig"
 source "net/nfc/llcp/Kconfig"
 
 source "drivers/nfc/Kconfig"
index 7b4a6dcfa566b93a5f725daeceb5936797f2034c..d1a117c2c401720864b0566bd4fca0ef82bf6fbf 100644 (file)
@@ -4,6 +4,7 @@
 
 obj-$(CONFIG_NFC) += nfc.o
 obj-$(CONFIG_NFC_NCI) += nci/
+obj-$(CONFIG_NFC_HCI) += hci/
 
 nfc-objs := core.o netlink.o af_nfc.o rawsock.o
 nfc-$(CONFIG_NFC_LLCP) += llcp/llcp.o llcp/commands.o llcp/sock.o
index 32a7b615e65fdbce82a7a3027f065e6b84084198..3192c3f589eea87eb5f6e04f4803b584c36101fb 100644 (file)
@@ -33,6 +33,8 @@
 
 #define VERSION "0.1"
 
+#define NFC_CHECK_PRES_FREQ_MS 2000
+
 int nfc_devlist_generation;
 DEFINE_MUTEX(nfc_devlist_mutex);
 
@@ -95,7 +97,7 @@ int nfc_dev_down(struct nfc_dev *dev)
                goto error;
        }
 
-       if (dev->polling || dev->remote_activated) {
+       if (dev->polling || dev->activated_target_idx != NFC_TARGET_IDX_NONE) {
                rc = -EBUSY;
                goto error;
        }
@@ -211,6 +213,8 @@ int nfc_dep_link_up(struct nfc_dev *dev, int target_index, u8 comm_mode)
        }
 
        rc = dev->ops->dep_link_up(dev, target_index, comm_mode, gb, gb_len);
+       if (!rc)
+               dev->activated_target_idx = target_index;
 
 error:
        device_unlock(&dev->dev);
@@ -246,6 +250,7 @@ int nfc_dep_link_down(struct nfc_dev *dev)
        rc = dev->ops->dep_link_down(dev);
        if (!rc) {
                dev->dep_link_up = false;
+               dev->activated_target_idx = NFC_TARGET_IDX_NONE;
                nfc_llcp_mac_is_down(dev);
                nfc_genl_dep_link_down_event(dev);
        }
@@ -289,8 +294,13 @@ int nfc_activate_target(struct nfc_dev *dev, u32 target_idx, u32 protocol)
        }
 
        rc = dev->ops->activate_target(dev, target_idx, protocol);
-       if (!rc)
-               dev->remote_activated = true;
+       if (!rc) {
+               dev->activated_target_idx = target_idx;
+
+               if (dev->ops->check_presence)
+                       mod_timer(&dev->check_pres_timer, jiffies +
+                                 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
+       }
 
 error:
        device_unlock(&dev->dev);
@@ -317,8 +327,11 @@ int nfc_deactivate_target(struct nfc_dev *dev, u32 target_idx)
                goto error;
        }
 
+       if (dev->ops->check_presence)
+               del_timer_sync(&dev->check_pres_timer);
+
        dev->ops->deactivate_target(dev, target_idx);
-       dev->remote_activated = false;
+       dev->activated_target_idx = NFC_TARGET_IDX_NONE;
 
 error:
        device_unlock(&dev->dev);
@@ -352,8 +365,27 @@ int nfc_data_exchange(struct nfc_dev *dev, u32 target_idx, struct sk_buff *skb,
                goto error;
        }
 
+       if (dev->activated_target_idx == NFC_TARGET_IDX_NONE) {
+               rc = -ENOTCONN;
+               kfree_skb(skb);
+               goto error;
+       }
+
+       if (target_idx != dev->activated_target_idx) {
+               rc = -EADDRNOTAVAIL;
+               kfree_skb(skb);
+               goto error;
+       }
+
+       if (dev->ops->check_presence)
+               del_timer_sync(&dev->check_pres_timer);
+
        rc = dev->ops->data_exchange(dev, target_idx, skb, cb, cb_context);
 
+       if (!rc && dev->ops->check_presence)
+               mod_timer(&dev->check_pres_timer, jiffies +
+                         msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
+
 error:
        device_unlock(&dev->dev);
        return rc;
@@ -428,10 +460,15 @@ EXPORT_SYMBOL(nfc_alloc_recv_skb);
 int nfc_targets_found(struct nfc_dev *dev,
                      struct nfc_target *targets, int n_targets)
 {
+       int i;
+
        pr_debug("dev_name=%s n_targets=%d\n", dev_name(&dev->dev), n_targets);
 
        dev->polling = false;
 
+       for (i = 0; i < n_targets; i++)
+               targets[i].idx = dev->target_next_idx++;
+
        spin_lock_bh(&dev->targets_lock);
 
        dev->targets_generation++;
@@ -455,17 +492,92 @@ int nfc_targets_found(struct nfc_dev *dev,
 }
 EXPORT_SYMBOL(nfc_targets_found);
 
+int nfc_target_lost(struct nfc_dev *dev, u32 target_idx)
+{
+       struct nfc_target *tg;
+       int i;
+
+       pr_debug("dev_name %s n_target %d\n", dev_name(&dev->dev), target_idx);
+
+       spin_lock_bh(&dev->targets_lock);
+
+       for (i = 0; i < dev->n_targets; i++) {
+               tg = &dev->targets[i];
+               if (tg->idx == target_idx)
+                       break;
+       }
+
+       if (i == dev->n_targets) {
+               spin_unlock_bh(&dev->targets_lock);
+               return -EINVAL;
+       }
+
+       dev->targets_generation++;
+       dev->n_targets--;
+       dev->activated_target_idx = NFC_TARGET_IDX_NONE;
+
+       if (dev->n_targets) {
+               memcpy(&dev->targets[i], &dev->targets[i + 1],
+                      (dev->n_targets - i) * sizeof(struct nfc_target));
+       } else {
+               kfree(dev->targets);
+               dev->targets = NULL;
+       }
+
+       spin_unlock_bh(&dev->targets_lock);
+
+       nfc_genl_target_lost(dev, target_idx);
+
+       return 0;
+}
+EXPORT_SYMBOL(nfc_target_lost);
+
 static void nfc_release(struct device *d)
 {
        struct nfc_dev *dev = to_nfc_dev(d);
 
        pr_debug("dev_name=%s\n", dev_name(&dev->dev));
 
+       if (dev->ops->check_presence) {
+               del_timer_sync(&dev->check_pres_timer);
+               destroy_workqueue(dev->check_pres_wq);
+       }
+
        nfc_genl_data_exit(&dev->genl_data);
        kfree(dev->targets);
        kfree(dev);
 }
 
+static void nfc_check_pres_work(struct work_struct *work)
+{
+       struct nfc_dev *dev = container_of(work, struct nfc_dev,
+                                          check_pres_work);
+       int rc;
+
+       device_lock(&dev->dev);
+
+       if (dev->activated_target_idx != NFC_TARGET_IDX_NONE &&
+           timer_pending(&dev->check_pres_timer) == 0) {
+               rc = dev->ops->check_presence(dev, dev->activated_target_idx);
+               if (!rc) {
+                       mod_timer(&dev->check_pres_timer, jiffies +
+                                 msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
+               } else {
+                       nfc_target_lost(dev, dev->activated_target_idx);
+                       dev->activated_target_idx = NFC_TARGET_IDX_NONE;
+               }
+       }
+
+       device_unlock(&dev->dev);
+}
+
+static void nfc_check_pres_timeout(unsigned long data)
+{
+       struct nfc_dev *dev = (struct nfc_dev *)data;
+
+       queue_work(dev->check_pres_wq, &dev->check_pres_work);
+}
+
 struct class nfc_class = {
        .name = "nfc",
        .dev_release = nfc_release,
@@ -531,6 +643,26 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
        /* first generation must not be 0 */
        dev->targets_generation = 1;
 
+       dev->activated_target_idx = NFC_TARGET_IDX_NONE;
+
+       if (ops->check_presence) {
+               char name[32];
+               init_timer(&dev->check_pres_timer);
+               dev->check_pres_timer.data = (unsigned long)dev;
+               dev->check_pres_timer.function = nfc_check_pres_timeout;
+
+               INIT_WORK(&dev->check_pres_work, nfc_check_pres_work);
+               snprintf(name, sizeof(name), "nfc%d_check_pres_wq", dev->idx);
+               dev->check_pres_wq = alloc_workqueue(name, WQ_NON_REENTRANT |
+                                                    WQ_UNBOUND |
+                                                    WQ_MEM_RECLAIM, 1);
+               if (dev->check_pres_wq == NULL) {
+                       kfree(dev);
+                       return NULL;
+               }
+       }
+
+
        return dev;
 }
 EXPORT_SYMBOL(nfc_allocate_device);
diff --git a/net/nfc/hci/Kconfig b/net/nfc/hci/Kconfig
new file mode 100644 (file)
index 0000000..17213a6
--- /dev/null
@@ -0,0 +1,16 @@
+config NFC_HCI
+       depends on NFC
+       tristate "NFC HCI implementation"
+       default n
+       help
+        Say Y here if you want to build support for a kernel NFC HCI
+        implementation. This is mostly needed for devices that only process
+        HCI frames, like for example the NXP pn544.
+
+config NFC_SHDLC
+       depends on NFC_HCI
+       bool "SHDLC link layer for HCI based NFC drivers"
+       default n
+       ---help---
+         Say yes if you use an NFC HCI driver that requires SHDLC link layer.
+         If unsure, say N here.
diff --git a/net/nfc/hci/Makefile b/net/nfc/hci/Makefile
new file mode 100644 (file)
index 0000000..f9c44b2
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# Makefile for the Linux NFC HCI layer.
+#
+
+obj-$(CONFIG_NFC_HCI) += hci.o
+
+hci-y                  := core.o hcp.o command.o
+hci-$(CONFIG_NFC_SHDLC)        += shdlc.o
diff --git a/net/nfc/hci/command.c b/net/nfc/hci/command.c
new file mode 100644 (file)
index 0000000..8729abf
--- /dev/null
@@ -0,0 +1,354 @@
+/*
+ * Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#define pr_fmt(fmt) "hci: %s: " fmt, __func__
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/module.h>
+
+#include <net/nfc/hci.h>
+
+#include "hci.h"
+
+static int nfc_hci_result_to_errno(u8 result)
+{
+       switch (result) {
+       case NFC_HCI_ANY_OK:
+               return 0;
+       case NFC_HCI_ANY_E_TIMEOUT:
+               return -ETIMEDOUT;
+       default:
+               return -1;
+       }
+}
+
+static void nfc_hci_execute_cb(struct nfc_hci_dev *hdev, u8 result,
+                              struct sk_buff *skb, void *cb_data)
+{
+       struct hcp_exec_waiter *hcp_ew = (struct hcp_exec_waiter *)cb_data;
+
+       pr_debug("HCI Cmd completed with HCI result=%d\n", result);
+
+       hcp_ew->exec_result = nfc_hci_result_to_errno(result);
+       if (hcp_ew->exec_result == 0)
+               hcp_ew->result_skb = skb;
+       else
+               kfree_skb(skb);
+       hcp_ew->exec_complete = true;
+
+       wake_up(hcp_ew->wq);
+}
+
+static int nfc_hci_execute_cmd(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
+                              const u8 *param, size_t param_len,
+                              struct sk_buff **skb)
+{
+       DECLARE_WAIT_QUEUE_HEAD_ONSTACK(ew_wq);
+       struct hcp_exec_waiter hcp_ew;
+       hcp_ew.wq = &ew_wq;
+       hcp_ew.exec_complete = false;
+       hcp_ew.result_skb = NULL;
+
+       pr_debug("through pipe=%d, cmd=%d, plen=%zd\n", pipe, cmd, param_len);
+
+       /* TODO: Define hci cmd execution delay. Should it be the same
+        * for all commands?
+        */
+       hcp_ew.exec_result = nfc_hci_hcp_message_tx(hdev, pipe,
+                                                   NFC_HCI_HCP_COMMAND, cmd,
+                                                   param, param_len,
+                                                   nfc_hci_execute_cb, &hcp_ew,
+                                                   3000);
+       if (hcp_ew.exec_result < 0)
+               return hcp_ew.exec_result;
+
+       wait_event(ew_wq, hcp_ew.exec_complete == true);
+
+       if (hcp_ew.exec_result == 0) {
+               if (skb)
+                       *skb = hcp_ew.result_skb;
+               else
+                       kfree_skb(hcp_ew.result_skb);
+       }
+
+       return hcp_ew.exec_result;
+}
+
+int nfc_hci_send_event(struct nfc_hci_dev *hdev, u8 gate, u8 event,
+                      const u8 *param, size_t param_len)
+{
+       u8 pipe;
+
+       pr_debug("%d to gate %d\n", event, gate);
+
+       pipe = hdev->gate2pipe[gate];
+       if (pipe == NFC_HCI_INVALID_PIPE)
+               return -EADDRNOTAVAIL;
+
+       return nfc_hci_hcp_message_tx(hdev, pipe, NFC_HCI_HCP_EVENT, event,
+                                     param, param_len, NULL, NULL, 0);
+}
+EXPORT_SYMBOL(nfc_hci_send_event);
+
+int nfc_hci_send_response(struct nfc_hci_dev *hdev, u8 gate, u8 response,
+                         const u8 *param, size_t param_len)
+{
+       u8 pipe;
+
+       pr_debug("\n");
+
+       pipe = hdev->gate2pipe[gate];
+       if (pipe == NFC_HCI_INVALID_PIPE)
+               return -EADDRNOTAVAIL;
+
+       return nfc_hci_hcp_message_tx(hdev, pipe, NFC_HCI_HCP_RESPONSE,
+                                     response, param, param_len, NULL, NULL,
+                                     0);
+}
+EXPORT_SYMBOL(nfc_hci_send_response);
+
+/*
+ * Execute an hci command sent to gate.
+ * skb will contain response data if success. skb can be NULL if you are not
+ * interested by the response.
+ */
+int nfc_hci_send_cmd(struct nfc_hci_dev *hdev, u8 gate, u8 cmd,
+                    const u8 *param, size_t param_len, struct sk_buff **skb)
+{
+       u8 pipe;
+
+       pr_debug("\n");
+
+       pipe = hdev->gate2pipe[gate];
+       if (pipe == NFC_HCI_INVALID_PIPE)
+               return -EADDRNOTAVAIL;
+
+       return nfc_hci_execute_cmd(hdev, pipe, cmd, param, param_len, skb);
+}
+EXPORT_SYMBOL(nfc_hci_send_cmd);
+
+int nfc_hci_set_param(struct nfc_hci_dev *hdev, u8 gate, u8 idx,
+                     const u8 *param, size_t param_len)
+{
+       int r;
+       u8 *tmp;
+
+       /* TODO ELa: reg idx must be inserted before param, but we don't want
+        * to ask the caller to do it to keep a simpler API.
+        * For now, just create a new temporary param buffer. This is far from
+        * optimal though, and the plan is to modify APIs to pass idx down to
+        * nfc_hci_hcp_message_tx where the frame is actually built, thereby
+        * eliminating the need for the temp allocation-copy here.
+        */
+
+       pr_debug("idx=%d to gate %d\n", idx, gate);
+
+       tmp = kmalloc(1 + param_len, GFP_KERNEL);
+       if (tmp == NULL)
+               return -ENOMEM;
+
+       *tmp = idx;
+       memcpy(tmp + 1, param, param_len);
+
+       r = nfc_hci_send_cmd(hdev, gate, NFC_HCI_ANY_SET_PARAMETER,
+                            tmp, param_len + 1, NULL);
+
+       kfree(tmp);
+
+       return r;
+}
+EXPORT_SYMBOL(nfc_hci_set_param);
+
+int nfc_hci_get_param(struct nfc_hci_dev *hdev, u8 gate, u8 idx,
+                     struct sk_buff **skb)
+{
+       pr_debug("gate=%d regidx=%d\n", gate, idx);
+
+       return nfc_hci_send_cmd(hdev, gate, NFC_HCI_ANY_GET_PARAMETER,
+                               &idx, 1, skb);
+}
+EXPORT_SYMBOL(nfc_hci_get_param);
+
+static int nfc_hci_open_pipe(struct nfc_hci_dev *hdev, u8 pipe)
+{
+       struct sk_buff *skb;
+       int r;
+
+       pr_debug("pipe=%d\n", pipe);
+
+       r = nfc_hci_execute_cmd(hdev, pipe, NFC_HCI_ANY_OPEN_PIPE,
+                               NULL, 0, &skb);
+       if (r == 0) {
+               /* dest host other than host controller will send
+                * number of pipes already open on this gate before
+                * execution. The number can be found in skb->data[0]
+                */
+               kfree_skb(skb);
+       }
+
+       return r;
+}
+
+static int nfc_hci_close_pipe(struct nfc_hci_dev *hdev, u8 pipe)
+{
+       pr_debug("\n");
+
+       return nfc_hci_execute_cmd(hdev, pipe, NFC_HCI_ANY_CLOSE_PIPE,
+                                  NULL, 0, NULL);
+}
+
+static u8 nfc_hci_create_pipe(struct nfc_hci_dev *hdev, u8 dest_host,
+                             u8 dest_gate, int *result)
+{
+       struct sk_buff *skb;
+       struct hci_create_pipe_params params;
+       struct hci_create_pipe_resp *resp;
+       u8 pipe;
+
+       pr_debug("gate=%d\n", dest_gate);
+
+       params.src_gate = NFC_HCI_ADMIN_GATE;
+       params.dest_host = dest_host;
+       params.dest_gate = dest_gate;
+
+       *result = nfc_hci_execute_cmd(hdev, NFC_HCI_ADMIN_PIPE,
+                                     NFC_HCI_ADM_CREATE_PIPE,
+                                     (u8 *) &params, sizeof(params), &skb);
+       if (*result == 0) {
+               resp = (struct hci_create_pipe_resp *)skb->data;
+               pipe = resp->pipe;
+               kfree_skb(skb);
+
+               pr_debug("pipe created=%d\n", pipe);
+
+               return pipe;
+       } else
+               return NFC_HCI_INVALID_PIPE;
+}
+
+static int nfc_hci_delete_pipe(struct nfc_hci_dev *hdev, u8 pipe)
+{
+       pr_debug("\n");
+
+       return nfc_hci_execute_cmd(hdev, NFC_HCI_ADMIN_PIPE,
+                                  NFC_HCI_ADM_DELETE_PIPE, &pipe, 1, NULL);
+}
+
+static int nfc_hci_clear_all_pipes(struct nfc_hci_dev *hdev)
+{
+       int r;
+
+       u8 param[2];
+
+       /* TODO: Find out what the identity reference data is
+        * and fill param with it. HCI spec 6.1.3.5 */
+
+       pr_debug("\n");
+
+       r = nfc_hci_execute_cmd(hdev, NFC_HCI_ADMIN_PIPE,
+                               NFC_HCI_ADM_CLEAR_ALL_PIPE, param, 2, NULL);
+
+       return 0;
+}
+
+int nfc_hci_disconnect_gate(struct nfc_hci_dev *hdev, u8 gate)
+{
+       int r;
+       u8 pipe = hdev->gate2pipe[gate];
+
+       pr_debug("\n");
+
+       if (pipe == NFC_HCI_INVALID_PIPE)
+               return -EADDRNOTAVAIL;
+
+       r = nfc_hci_close_pipe(hdev, pipe);
+       if (r < 0)
+               return r;
+
+       if (pipe != NFC_HCI_LINK_MGMT_PIPE && pipe != NFC_HCI_ADMIN_PIPE) {
+               r = nfc_hci_delete_pipe(hdev, pipe);
+               if (r < 0)
+                       return r;
+       }
+
+       hdev->gate2pipe[gate] = NFC_HCI_INVALID_PIPE;
+
+       return 0;
+}
+EXPORT_SYMBOL(nfc_hci_disconnect_gate);
+
+int nfc_hci_disconnect_all_gates(struct nfc_hci_dev *hdev)
+{
+       int r;
+
+       pr_debug("\n");
+
+       r = nfc_hci_clear_all_pipes(hdev);
+       if (r < 0)
+               return r;
+
+       memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe));
+
+       return 0;
+}
+EXPORT_SYMBOL(nfc_hci_disconnect_all_gates);
+
+int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate)
+{
+       u8 pipe = NFC_HCI_INVALID_PIPE;
+       bool pipe_created = false;
+       int r;
+
+       pr_debug("\n");
+
+       if (hdev->gate2pipe[dest_gate] != NFC_HCI_INVALID_PIPE)
+               return -EADDRINUSE;
+
+       switch (dest_gate) {
+       case NFC_HCI_LINK_MGMT_GATE:
+               pipe = NFC_HCI_LINK_MGMT_PIPE;
+               break;
+       case NFC_HCI_ADMIN_GATE:
+               pipe = NFC_HCI_ADMIN_PIPE;
+               break;
+       default:
+               pipe = nfc_hci_create_pipe(hdev, dest_host, dest_gate, &r);
+               if (pipe == NFC_HCI_INVALID_PIPE)
+                       return r;
+               pipe_created = true;
+               break;
+       }
+
+       r = nfc_hci_open_pipe(hdev, pipe);
+       if (r < 0) {
+               if (pipe_created)
+                       if (nfc_hci_delete_pipe(hdev, pipe) < 0) {
+                               /* TODO: Cannot clean by deleting pipe...
+                                * -> inconsistent state */
+                       }
+               return r;
+       }
+
+       hdev->gate2pipe[dest_gate] = pipe;
+
+       return 0;
+}
+EXPORT_SYMBOL(nfc_hci_connect_gate);
diff --git a/net/nfc/hci/core.c b/net/nfc/hci/core.c
new file mode 100644 (file)
index 0000000..86fd00d
--- /dev/null
@@ -0,0 +1,830 @@
+/*
+ * Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#define pr_fmt(fmt) "hci: %s: " fmt, __func__
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/nfc.h>
+
+#include <net/nfc/nfc.h>
+#include <net/nfc/hci.h>
+
+#include "hci.h"
+
+/* Largest headroom needed for outgoing HCI commands */
+#define HCI_CMDS_HEADROOM 1
+
+static void nfc_hci_msg_tx_work(struct work_struct *work)
+{
+       struct nfc_hci_dev *hdev = container_of(work, struct nfc_hci_dev,
+                                               msg_tx_work);
+       struct hci_msg *msg;
+       struct sk_buff *skb;
+       int r = 0;
+
+       mutex_lock(&hdev->msg_tx_mutex);
+
+       if (hdev->cmd_pending_msg) {
+               if (timer_pending(&hdev->cmd_timer) == 0) {
+                       if (hdev->cmd_pending_msg->cb)
+                               hdev->cmd_pending_msg->cb(hdev,
+                                                         NFC_HCI_ANY_E_TIMEOUT,
+                                                         NULL,
+                                                         hdev->
+                                                         cmd_pending_msg->
+                                                         cb_context);
+                       kfree(hdev->cmd_pending_msg);
+                       hdev->cmd_pending_msg = NULL;
+               } else
+                       goto exit;
+       }
+
+next_msg:
+       if (list_empty(&hdev->msg_tx_queue))
+               goto exit;
+
+       msg = list_first_entry(&hdev->msg_tx_queue, struct hci_msg, msg_l);
+       list_del(&msg->msg_l);
+
+       pr_debug("msg_tx_queue has a cmd to send\n");
+       while ((skb = skb_dequeue(&msg->msg_frags)) != NULL) {
+               r = hdev->ops->xmit(hdev, skb);
+               if (r < 0) {
+                       kfree_skb(skb);
+                       skb_queue_purge(&msg->msg_frags);
+                       if (msg->cb)
+                               msg->cb(hdev, NFC_HCI_ANY_E_NOK, NULL,
+                                       msg->cb_context);
+                       kfree(msg);
+                       break;
+               }
+       }
+
+       if (r)
+               goto next_msg;
+
+       if (msg->wait_response == false) {
+               kfree(msg);
+               goto next_msg;
+       }
+
+       hdev->cmd_pending_msg = msg;
+       mod_timer(&hdev->cmd_timer, jiffies +
+                 msecs_to_jiffies(hdev->cmd_pending_msg->completion_delay));
+
+exit:
+       mutex_unlock(&hdev->msg_tx_mutex);
+}
+
+static void nfc_hci_msg_rx_work(struct work_struct *work)
+{
+       struct nfc_hci_dev *hdev = container_of(work, struct nfc_hci_dev,
+                                               msg_rx_work);
+       struct sk_buff *skb;
+       struct hcp_message *message;
+       u8 pipe;
+       u8 type;
+       u8 instruction;
+
+       while ((skb = skb_dequeue(&hdev->msg_rx_queue)) != NULL) {
+               pipe = skb->data[0];
+               skb_pull(skb, NFC_HCI_HCP_PACKET_HEADER_LEN);
+               message = (struct hcp_message *)skb->data;
+               type = HCP_MSG_GET_TYPE(message->header);
+               instruction = HCP_MSG_GET_CMD(message->header);
+               skb_pull(skb, NFC_HCI_HCP_MESSAGE_HEADER_LEN);
+
+               nfc_hci_hcp_message_rx(hdev, pipe, type, instruction, skb);
+       }
+}
+
+void nfc_hci_resp_received(struct nfc_hci_dev *hdev, u8 result,
+                          struct sk_buff *skb)
+{
+       mutex_lock(&hdev->msg_tx_mutex);
+
+       if (hdev->cmd_pending_msg == NULL) {
+               kfree_skb(skb);
+               goto exit;
+       }
+
+       del_timer_sync(&hdev->cmd_timer);
+
+       if (hdev->cmd_pending_msg->cb)
+               hdev->cmd_pending_msg->cb(hdev, result, skb,
+                                         hdev->cmd_pending_msg->cb_context);
+       else
+               kfree_skb(skb);
+
+       kfree(hdev->cmd_pending_msg);
+       hdev->cmd_pending_msg = NULL;
+
+       queue_work(hdev->msg_tx_wq, &hdev->msg_tx_work);
+
+exit:
+       mutex_unlock(&hdev->msg_tx_mutex);
+}
+
+void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd,
+                         struct sk_buff *skb)
+{
+       kfree_skb(skb);
+}
+
+static u32 nfc_hci_sak_to_protocol(u8 sak)
+{
+       switch (NFC_HCI_TYPE_A_SEL_PROT(sak)) {
+       case NFC_HCI_TYPE_A_SEL_PROT_MIFARE:
+               return NFC_PROTO_MIFARE_MASK;
+       case NFC_HCI_TYPE_A_SEL_PROT_ISO14443:
+               return NFC_PROTO_ISO14443_MASK;
+       case NFC_HCI_TYPE_A_SEL_PROT_DEP:
+               return NFC_PROTO_NFC_DEP_MASK;
+       case NFC_HCI_TYPE_A_SEL_PROT_ISO14443_DEP:
+               return NFC_PROTO_ISO14443_MASK | NFC_PROTO_NFC_DEP_MASK;
+       default:
+               return 0xffffffff;
+       }
+}
+
+static int nfc_hci_target_discovered(struct nfc_hci_dev *hdev, u8 gate)
+{
+       struct nfc_target *targets;
+       struct sk_buff *atqa_skb = NULL;
+       struct sk_buff *sak_skb = NULL;
+       int r;
+
+       pr_debug("from gate %d\n", gate);
+
+       targets = kzalloc(sizeof(struct nfc_target), GFP_KERNEL);
+       if (targets == NULL)
+               return -ENOMEM;
+
+       switch (gate) {
+       case NFC_HCI_RF_READER_A_GATE:
+               r = nfc_hci_get_param(hdev, NFC_HCI_RF_READER_A_GATE,
+                                     NFC_HCI_RF_READER_A_ATQA, &atqa_skb);
+               if (r < 0)
+                       goto exit;
+
+               r = nfc_hci_get_param(hdev, NFC_HCI_RF_READER_A_GATE,
+                                     NFC_HCI_RF_READER_A_SAK, &sak_skb);
+               if (r < 0)
+                       goto exit;
+
+               if (atqa_skb->len != 2 || sak_skb->len != 1) {
+                       r = -EPROTO;
+                       goto exit;
+               }
+
+               targets->supported_protocols =
+                               nfc_hci_sak_to_protocol(sak_skb->data[0]);
+               if (targets->supported_protocols == 0xffffffff) {
+                       r = -EPROTO;
+                       goto exit;
+               }
+
+               targets->sens_res = be16_to_cpu(*(u16 *)atqa_skb->data);
+               targets->sel_res = sak_skb->data[0];
+
+               if (hdev->ops->complete_target_discovered) {
+                       r = hdev->ops->complete_target_discovered(hdev, gate,
+                                                                 targets);
+                       if (r < 0)
+                               goto exit;
+               }
+               break;
+       case NFC_HCI_RF_READER_B_GATE:
+               targets->supported_protocols = NFC_PROTO_ISO14443_MASK;
+               break;
+       default:
+               if (hdev->ops->target_from_gate)
+                       r = hdev->ops->target_from_gate(hdev, gate, targets);
+               else
+                       r = -EPROTO;
+               if (r < 0)
+                       goto exit;
+
+               if (hdev->ops->complete_target_discovered) {
+                       r = hdev->ops->complete_target_discovered(hdev, gate,
+                                                                 targets);
+                       if (r < 0)
+                               goto exit;
+               }
+               break;
+       }
+
+       targets->hci_reader_gate = gate;
+
+       r = nfc_targets_found(hdev->ndev, targets, 1);
+       if (r < 0)
+               goto exit;
+
+       kfree(hdev->targets);
+       hdev->targets = targets;
+       targets = NULL;
+       hdev->target_count = 1;
+
+exit:
+       kfree(targets);
+       kfree_skb(atqa_skb);
+       kfree_skb(sak_skb);
+
+       return r;
+}
+
+void nfc_hci_event_received(struct nfc_hci_dev *hdev, u8 pipe, u8 event,
+                           struct sk_buff *skb)
+{
+       int r = 0;
+
+       switch (event) {
+       case NFC_HCI_EVT_TARGET_DISCOVERED:
+               if (hdev->poll_started == false) {
+                       r = -EPROTO;
+                       goto exit;
+               }
+
+               if (skb->len < 1) {     /* no status data? */
+                       r = -EPROTO;
+                       goto exit;
+               }
+
+               if (skb->data[0] == 3) {
+                       /* TODO: Multiple targets in field, none activated
+                        * poll is supposedly stopped, but there is no
+                        * single target to activate, so nothing to report
+                        * up.
+                        * if we need to restart poll, we must save the
+                        * protocols from the initial poll and reuse here.
+                        */
+               }
+
+               if (skb->data[0] != 0) {
+                       r = -EPROTO;
+                       goto exit;
+               }
+
+               r = nfc_hci_target_discovered(hdev,
+                                             nfc_hci_pipe2gate(hdev, pipe));
+               break;
+       default:
+               /* TODO: Unknown events are hardware specific
+                * pass them to the driver (needs a new hci_ops) */
+               break;
+       }
+
+exit:
+       kfree_skb(skb);
+
+       if (r) {
+               /* TODO: There was an error dispatching the event,
+                * how to propagate up to nfc core?
+                */
+       }
+}
+
+static void nfc_hci_cmd_timeout(unsigned long data)
+{
+       struct nfc_hci_dev *hdev = (struct nfc_hci_dev *)data;
+
+       queue_work(hdev->msg_tx_wq, &hdev->msg_tx_work);
+}
+
+static int hci_dev_connect_gates(struct nfc_hci_dev *hdev, u8 gate_count,
+                                u8 gates[])
+{
+       int r;
+       u8 *p = gates;
+       while (gate_count--) {
+               r = nfc_hci_connect_gate(hdev, NFC_HCI_HOST_CONTROLLER_ID, *p);
+               if (r < 0)
+                       return r;
+               p++;
+       }
+
+       return 0;
+}
+
+static int hci_dev_session_init(struct nfc_hci_dev *hdev)
+{
+       struct sk_buff *skb = NULL;
+       int r;
+       u8 hci_gates[] = {      /* NFC_HCI_ADMIN_GATE MUST be first */
+               NFC_HCI_ADMIN_GATE, NFC_HCI_LOOPBACK_GATE,
+               NFC_HCI_ID_MGMT_GATE, NFC_HCI_LINK_MGMT_GATE,
+               NFC_HCI_RF_READER_B_GATE, NFC_HCI_RF_READER_A_GATE
+       };
+
+       r = nfc_hci_connect_gate(hdev, NFC_HCI_HOST_CONTROLLER_ID,
+                                NFC_HCI_ADMIN_GATE);
+       if (r < 0)
+               goto exit;
+
+       r = nfc_hci_get_param(hdev, NFC_HCI_ADMIN_GATE,
+                             NFC_HCI_ADMIN_SESSION_IDENTITY, &skb);
+       if (r < 0)
+               goto disconnect_all;
+
+       if (skb->len && skb->len == strlen(hdev->init_data.session_id))
+               if (memcmp(hdev->init_data.session_id, skb->data,
+                          skb->len) == 0) {
+                       /* TODO ELa: restore gate<->pipe table from
+                        * some TBD location.
+                        * note: it doesn't seem possible to get the chip
+                        * currently open gate/pipe table.
+                        * It is only possible to obtain the supported
+                        * gate list.
+                        */
+
+                       /* goto exit
+                        * For now, always do a full initialization */
+               }
+
+       r = nfc_hci_disconnect_all_gates(hdev);
+       if (r < 0)
+               goto exit;
+
+       r = hci_dev_connect_gates(hdev, sizeof(hci_gates), hci_gates);
+       if (r < 0)
+               goto disconnect_all;
+
+       r = hci_dev_connect_gates(hdev, hdev->init_data.gate_count,
+                                 hdev->init_data.gates);
+       if (r < 0)
+               goto disconnect_all;
+
+       r = nfc_hci_set_param(hdev, NFC_HCI_ADMIN_GATE,
+                             NFC_HCI_ADMIN_SESSION_IDENTITY,
+                             hdev->init_data.session_id,
+                             strlen(hdev->init_data.session_id));
+       if (r == 0)
+               goto exit;
+
+disconnect_all:
+       nfc_hci_disconnect_all_gates(hdev);
+
+exit:
+       if (skb)
+               kfree_skb(skb);
+
+       return r;
+}
+
+static int hci_dev_version(struct nfc_hci_dev *hdev)
+{
+       int r;
+       struct sk_buff *skb;
+
+       r = nfc_hci_get_param(hdev, NFC_HCI_ID_MGMT_GATE,
+                             NFC_HCI_ID_MGMT_VERSION_SW, &skb);
+       if (r < 0)
+               return r;
+
+       if (skb->len != 3) {
+               kfree_skb(skb);
+               return -EINVAL;
+       }
+
+       hdev->sw_romlib = (skb->data[0] & 0xf0) >> 4;
+       hdev->sw_patch = skb->data[0] & 0x0f;
+       hdev->sw_flashlib_major = skb->data[1];
+       hdev->sw_flashlib_minor = skb->data[2];
+
+       kfree_skb(skb);
+
+       r = nfc_hci_get_param(hdev, NFC_HCI_ID_MGMT_GATE,
+                             NFC_HCI_ID_MGMT_VERSION_HW, &skb);
+       if (r < 0)
+               return r;
+
+       if (skb->len != 3) {
+               kfree_skb(skb);
+               return -EINVAL;
+       }
+
+       hdev->hw_derivative = (skb->data[0] & 0xe0) >> 5;
+       hdev->hw_version = skb->data[0] & 0x1f;
+       hdev->hw_mpw = (skb->data[1] & 0xc0) >> 6;
+       hdev->hw_software = skb->data[1] & 0x3f;
+       hdev->hw_bsid = skb->data[2];
+
+       kfree_skb(skb);
+
+       pr_info("SOFTWARE INFO:\n");
+       pr_info("RomLib         : %d\n", hdev->sw_romlib);
+       pr_info("Patch          : %d\n", hdev->sw_patch);
+       pr_info("FlashLib Major : %d\n", hdev->sw_flashlib_major);
+       pr_info("FlashLib Minor : %d\n", hdev->sw_flashlib_minor);
+       pr_info("HARDWARE INFO:\n");
+       pr_info("Derivative     : %d\n", hdev->hw_derivative);
+       pr_info("HW Version     : %d\n", hdev->hw_version);
+       pr_info("#MPW           : %d\n", hdev->hw_mpw);
+       pr_info("Software       : %d\n", hdev->hw_software);
+       pr_info("BSID Version   : %d\n", hdev->hw_bsid);
+
+       return 0;
+}
+
+static int hci_dev_up(struct nfc_dev *nfc_dev)
+{
+       struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
+       int r = 0;
+
+       if (hdev->ops->open) {
+               r = hdev->ops->open(hdev);
+               if (r < 0)
+                       return r;
+       }
+
+       r = hci_dev_session_init(hdev);
+       if (r < 0)
+               goto exit;
+
+       r = nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE,
+                              NFC_HCI_EVT_END_OPERATION, NULL, 0);
+       if (r < 0)
+               goto exit;
+
+       if (hdev->ops->hci_ready) {
+               r = hdev->ops->hci_ready(hdev);
+               if (r < 0)
+                       goto exit;
+       }
+
+       r = hci_dev_version(hdev);
+       if (r < 0)
+               goto exit;
+
+exit:
+       if (r < 0)
+               if (hdev->ops->close)
+                       hdev->ops->close(hdev);
+       return r;
+}
+
+static int hci_dev_down(struct nfc_dev *nfc_dev)
+{
+       struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
+
+       if (hdev->ops->close)
+               hdev->ops->close(hdev);
+
+       memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe));
+
+       return 0;
+}
+
+static int hci_start_poll(struct nfc_dev *nfc_dev, u32 protocols)
+{
+       struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
+       int r;
+
+       if (hdev->ops->start_poll)
+               r = hdev->ops->start_poll(hdev, protocols);
+       else
+               r = nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE,
+                                      NFC_HCI_EVT_READER_REQUESTED, NULL, 0);
+       if (r == 0)
+               hdev->poll_started = true;
+
+       return r;
+}
+
+static void hci_stop_poll(struct nfc_dev *nfc_dev)
+{
+       struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
+
+       if (hdev->poll_started) {
+               nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE,
+                                  NFC_HCI_EVT_END_OPERATION, NULL, 0);
+               hdev->poll_started = false;
+       }
+}
+
+static struct nfc_target *hci_find_target(struct nfc_hci_dev *hdev,
+                                         u32 target_idx)
+{
+       int i;
+       if (hdev->poll_started == false || hdev->targets == NULL)
+               return NULL;
+
+       for (i = 0; i < hdev->target_count; i++) {
+               if (hdev->targets[i].idx == target_idx)
+                       return &hdev->targets[i];
+       }
+
+       return NULL;
+}
+
+static int hci_activate_target(struct nfc_dev *nfc_dev, u32 target_idx,
+                              u32 protocol)
+{
+       struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
+
+       if (hci_find_target(hdev, target_idx) == NULL)
+               return -ENOMEDIUM;
+
+       return 0;
+}
+
+static void hci_deactivate_target(struct nfc_dev *nfc_dev, u32 target_idx)
+{
+}
+
+static int hci_data_exchange(struct nfc_dev *nfc_dev, u32 target_idx,
+                            struct sk_buff *skb, data_exchange_cb_t cb,
+                            void *cb_context)
+{
+       struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
+       int r;
+       struct nfc_target *target;
+       struct sk_buff *res_skb = NULL;
+
+       pr_debug("target_idx=%d\n", target_idx);
+
+       target = hci_find_target(hdev, target_idx);
+       if (target == NULL)
+               return -ENOMEDIUM;
+
+       switch (target->hci_reader_gate) {
+       case NFC_HCI_RF_READER_A_GATE:
+       case NFC_HCI_RF_READER_B_GATE:
+               if (hdev->ops->data_exchange) {
+                       r = hdev->ops->data_exchange(hdev, target, skb,
+                                                    &res_skb);
+                       if (r <= 0)     /* handled */
+                               break;
+               }
+
+               *skb_push(skb, 1) = 0;  /* CTR, see spec:10.2.2.1 */
+               r = nfc_hci_send_cmd(hdev, target->hci_reader_gate,
+                                    NFC_HCI_WR_XCHG_DATA,
+                                    skb->data, skb->len, &res_skb);
+               /*
+                * TODO: Check RF Error indicator to make sure data is valid.
+                * It seems that HCI cmd can complete without error, but data
+                * can be invalid if an RF error occured? Ignore for now.
+                */
+               if (r == 0)
+                       skb_trim(res_skb, res_skb->len - 1); /* RF Err ind */
+               break;
+       default:
+               if (hdev->ops->data_exchange) {
+                       r = hdev->ops->data_exchange(hdev, target, skb,
+                                                    &res_skb);
+                       if (r == 1)
+                               r = -ENOTSUPP;
+               }
+               else
+                       r = -ENOTSUPP;
+       }
+
+       kfree_skb(skb);
+
+       cb(cb_context, res_skb, r);
+
+       return 0;
+}
+
+struct nfc_ops hci_nfc_ops = {
+       .dev_up = hci_dev_up,
+       .dev_down = hci_dev_down,
+       .start_poll = hci_start_poll,
+       .stop_poll = hci_stop_poll,
+       .activate_target = hci_activate_target,
+       .deactivate_target = hci_deactivate_target,
+       .data_exchange = hci_data_exchange,
+};
+
+struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
+                                           struct nfc_hci_init_data *init_data,
+                                           u32 protocols,
+                                           int tx_headroom,
+                                           int tx_tailroom,
+                                           int max_link_payload)
+{
+       struct nfc_hci_dev *hdev;
+
+       if (ops->xmit == NULL)
+               return NULL;
+
+       if (protocols == 0)
+               return NULL;
+
+       hdev = kzalloc(sizeof(struct nfc_hci_dev), GFP_KERNEL);
+       if (hdev == NULL)
+               return NULL;
+
+       hdev->ndev = nfc_allocate_device(&hci_nfc_ops, protocols,
+                                        tx_headroom + HCI_CMDS_HEADROOM,
+                                        tx_tailroom);
+       if (!hdev->ndev) {
+               kfree(hdev);
+               return NULL;
+       }
+
+       hdev->ops = ops;
+       hdev->max_data_link_payload = max_link_payload;
+       hdev->init_data = *init_data;
+
+       nfc_set_drvdata(hdev->ndev, hdev);
+
+       memset(hdev->gate2pipe, NFC_HCI_INVALID_PIPE, sizeof(hdev->gate2pipe));
+
+       return hdev;
+}
+EXPORT_SYMBOL(nfc_hci_allocate_device);
+
+void nfc_hci_free_device(struct nfc_hci_dev *hdev)
+{
+       nfc_free_device(hdev->ndev);
+       kfree(hdev);
+}
+EXPORT_SYMBOL(nfc_hci_free_device);
+
+int nfc_hci_register_device(struct nfc_hci_dev *hdev)
+{
+       struct device *dev = &hdev->ndev->dev;
+       const char *devname = dev_name(dev);
+       char name[32];
+       int r = 0;
+
+       mutex_init(&hdev->msg_tx_mutex);
+
+       INIT_LIST_HEAD(&hdev->msg_tx_queue);
+
+       INIT_WORK(&hdev->msg_tx_work, nfc_hci_msg_tx_work);
+       snprintf(name, sizeof(name), "%s_hci_msg_tx_wq", devname);
+       hdev->msg_tx_wq = alloc_workqueue(name, WQ_NON_REENTRANT | WQ_UNBOUND |
+                                         WQ_MEM_RECLAIM, 1);
+       if (hdev->msg_tx_wq == NULL) {
+               r = -ENOMEM;
+               goto exit;
+       }
+
+       init_timer(&hdev->cmd_timer);
+       hdev->cmd_timer.data = (unsigned long)hdev;
+       hdev->cmd_timer.function = nfc_hci_cmd_timeout;
+
+       skb_queue_head_init(&hdev->rx_hcp_frags);
+
+       INIT_WORK(&hdev->msg_rx_work, nfc_hci_msg_rx_work);
+       snprintf(name, sizeof(name), "%s_hci_msg_rx_wq", devname);
+       hdev->msg_rx_wq = alloc_workqueue(name, WQ_NON_REENTRANT | WQ_UNBOUND |
+                                         WQ_MEM_RECLAIM, 1);
+       if (hdev->msg_rx_wq == NULL) {
+               r = -ENOMEM;
+               goto exit;
+       }
+
+       skb_queue_head_init(&hdev->msg_rx_queue);
+
+       r = nfc_register_device(hdev->ndev);
+
+exit:
+       if (r < 0) {
+               if (hdev->msg_tx_wq)
+                       destroy_workqueue(hdev->msg_tx_wq);
+               if (hdev->msg_rx_wq)
+                       destroy_workqueue(hdev->msg_rx_wq);
+       }
+
+       return r;
+}
+EXPORT_SYMBOL(nfc_hci_register_device);
+
+void nfc_hci_unregister_device(struct nfc_hci_dev *hdev)
+{
+       struct hci_msg *msg;
+
+       skb_queue_purge(&hdev->rx_hcp_frags);
+       skb_queue_purge(&hdev->msg_rx_queue);
+
+       while ((msg = list_first_entry(&hdev->msg_tx_queue, struct hci_msg,
+                                      msg_l)) != NULL) {
+               list_del(&msg->msg_l);
+               skb_queue_purge(&msg->msg_frags);
+               kfree(msg);
+       }
+
+       del_timer_sync(&hdev->cmd_timer);
+
+       nfc_unregister_device(hdev->ndev);
+
+       destroy_workqueue(hdev->msg_tx_wq);
+
+       destroy_workqueue(hdev->msg_rx_wq);
+}
+EXPORT_SYMBOL(nfc_hci_unregister_device);
+
+void nfc_hci_set_clientdata(struct nfc_hci_dev *hdev, void *clientdata)
+{
+       hdev->clientdata = clientdata;
+}
+EXPORT_SYMBOL(nfc_hci_set_clientdata);
+
+void *nfc_hci_get_clientdata(struct nfc_hci_dev *hdev)
+{
+       return hdev->clientdata;
+}
+EXPORT_SYMBOL(nfc_hci_get_clientdata);
+
+void nfc_hci_recv_frame(struct nfc_hci_dev *hdev, struct sk_buff *skb)
+{
+       struct hcp_packet *packet;
+       u8 type;
+       u8 instruction;
+       struct sk_buff *hcp_skb;
+       u8 pipe;
+       struct sk_buff *frag_skb;
+       int msg_len;
+
+       if (skb == NULL) {
+               /* TODO ELa: lower layer had permanent failure, need to
+                * propagate that up
+                */
+
+               skb_queue_purge(&hdev->rx_hcp_frags);
+
+               return;
+       }
+
+       packet = (struct hcp_packet *)skb->data;
+       if ((packet->header & ~NFC_HCI_FRAGMENT) == 0) {
+               skb_queue_tail(&hdev->rx_hcp_frags, skb);
+               return;
+       }
+
+       /* it's the last fragment. Does it need re-aggregation? */
+       if (skb_queue_len(&hdev->rx_hcp_frags)) {
+               pipe = packet->header & NFC_HCI_FRAGMENT;
+               skb_queue_tail(&hdev->rx_hcp_frags, skb);
+
+               msg_len = 0;
+               skb_queue_walk(&hdev->rx_hcp_frags, frag_skb) {
+                       msg_len += (frag_skb->len -
+                                   NFC_HCI_HCP_PACKET_HEADER_LEN);
+               }
+
+               hcp_skb = nfc_alloc_recv_skb(NFC_HCI_HCP_PACKET_HEADER_LEN +
+                                            msg_len, GFP_KERNEL);
+               if (hcp_skb == NULL) {
+                       /* TODO ELa: cannot deliver HCP message. How to
+                        * propagate error up?
+                        */
+               }
+
+               *skb_put(hcp_skb, NFC_HCI_HCP_PACKET_HEADER_LEN) = pipe;
+
+               skb_queue_walk(&hdev->rx_hcp_frags, frag_skb) {
+                       msg_len = frag_skb->len - NFC_HCI_HCP_PACKET_HEADER_LEN;
+                       memcpy(skb_put(hcp_skb, msg_len),
+                              frag_skb->data + NFC_HCI_HCP_PACKET_HEADER_LEN,
+                              msg_len);
+               }
+
+               skb_queue_purge(&hdev->rx_hcp_frags);
+       } else {
+               packet->header &= NFC_HCI_FRAGMENT;
+               hcp_skb = skb;
+       }
+
+       /* if this is a response, dispatch immediately to
+        * unblock waiting cmd context. Otherwise, enqueue to dispatch
+        * in separate context where handler can also execute command.
+        */
+       packet = (struct hcp_packet *)hcp_skb->data;
+       type = HCP_MSG_GET_TYPE(packet->message.header);
+       if (type == NFC_HCI_HCP_RESPONSE) {
+               pipe = packet->header;
+               instruction = HCP_MSG_GET_CMD(packet->message.header);
+               skb_pull(hcp_skb, NFC_HCI_HCP_PACKET_HEADER_LEN +
+                        NFC_HCI_HCP_MESSAGE_HEADER_LEN);
+               nfc_hci_hcp_message_rx(hdev, pipe, type, instruction, hcp_skb);
+       } else {
+               skb_queue_tail(&hdev->msg_rx_queue, hcp_skb);
+               queue_work(hdev->msg_rx_wq, &hdev->msg_rx_work);
+       }
+}
+EXPORT_SYMBOL(nfc_hci_recv_frame);
+
+MODULE_LICENSE("GPL");
diff --git a/net/nfc/hci/hci.h b/net/nfc/hci/hci.h
new file mode 100644 (file)
index 0000000..45f2fe4
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __LOCAL_HCI_H
+#define __LOCAL_HCI_H
+
+struct gate_pipe_map {
+       u8 gate;
+       u8 pipe;
+};
+
+struct hcp_message {
+       u8 header;              /* type -cmd,evt,rsp- + instruction */
+       u8 data[];
+} __packed;
+
+struct hcp_packet {
+       u8 header;              /* cbit+pipe */
+       struct hcp_message message;
+} __packed;
+
+/*
+ * HCI command execution completion callback.
+ * result will be one of the HCI response codes.
+ * skb contains the response data and must be disposed.
+ */
+typedef void (*hci_cmd_cb_t) (struct nfc_hci_dev *hdev, u8 result,
+                             struct sk_buff *skb, void *cb_data);
+
+struct hcp_exec_waiter {
+       wait_queue_head_t *wq;
+       bool exec_complete;
+       int exec_result;
+       struct sk_buff *result_skb;
+};
+
+struct hci_msg {
+       struct list_head msg_l;
+       struct sk_buff_head msg_frags;
+       bool wait_response;
+       hci_cmd_cb_t cb;
+       void *cb_context;
+       unsigned long completion_delay;
+};
+
+struct hci_create_pipe_params {
+       u8 src_gate;
+       u8 dest_host;
+       u8 dest_gate;
+} __packed;
+
+struct hci_create_pipe_resp {
+       u8 src_host;
+       u8 src_gate;
+       u8 dest_host;
+       u8 dest_gate;
+       u8 pipe;
+} __packed;
+
+#define NFC_HCI_FRAGMENT       0x7f
+
+#define HCP_HEADER(type, instr) ((((type) & 0x03) << 6) | ((instr) & 0x3f))
+#define HCP_MSG_GET_TYPE(header) ((header & 0xc0) >> 6)
+#define HCP_MSG_GET_CMD(header) (header & 0x3f)
+
+int nfc_hci_hcp_message_tx(struct nfc_hci_dev *hdev, u8 pipe,
+                          u8 type, u8 instruction,
+                          const u8 *payload, size_t payload_len,
+                          hci_cmd_cb_t cb, void *cb_data,
+                          unsigned long completion_delay);
+
+u8 nfc_hci_pipe2gate(struct nfc_hci_dev *hdev, u8 pipe);
+
+void nfc_hci_hcp_message_rx(struct nfc_hci_dev *hdev, u8 pipe, u8 type,
+                           u8 instruction, struct sk_buff *skb);
+
+/* HCP headers */
+#define NFC_HCI_HCP_PACKET_HEADER_LEN  1
+#define NFC_HCI_HCP_MESSAGE_HEADER_LEN 1
+#define NFC_HCI_HCP_HEADER_LEN         2
+
+/* HCP types */
+#define NFC_HCI_HCP_COMMAND    0x00
+#define NFC_HCI_HCP_EVENT      0x01
+#define NFC_HCI_HCP_RESPONSE   0x02
+
+/* Generic commands */
+#define NFC_HCI_ANY_SET_PARAMETER      0x01
+#define NFC_HCI_ANY_GET_PARAMETER      0x02
+#define NFC_HCI_ANY_OPEN_PIPE          0x03
+#define NFC_HCI_ANY_CLOSE_PIPE         0x04
+
+/* Reader RF commands */
+#define NFC_HCI_WR_XCHG_DATA           0x10
+
+/* Admin commands */
+#define NFC_HCI_ADM_CREATE_PIPE                        0x10
+#define NFC_HCI_ADM_DELETE_PIPE                        0x11
+#define NFC_HCI_ADM_NOTIFY_PIPE_CREATED                0x12
+#define NFC_HCI_ADM_NOTIFY_PIPE_DELETED                0x13
+#define NFC_HCI_ADM_CLEAR_ALL_PIPE             0x14
+#define NFC_HCI_ADM_NOTIFY_ALL_PIPE_CLEARED    0x15
+
+/* Generic responses */
+#define NFC_HCI_ANY_OK                         0x00
+#define NFC_HCI_ANY_E_NOT_CONNECTED            0x01
+#define NFC_HCI_ANY_E_CMD_PAR_UNKNOWN          0x02
+#define NFC_HCI_ANY_E_NOK                      0x03
+#define NFC_HCI_ANY_E_PIPES_FULL               0x04
+#define NFC_HCI_ANY_E_REG_PAR_UNKNOWN          0x05
+#define NFC_HCI_ANY_E_PIPE_NOT_OPENED          0x06
+#define NFC_HCI_ANY_E_CMD_NOT_SUPPORTED                0x07
+#define NFC_HCI_ANY_E_INHIBITED                        0x08
+#define NFC_HCI_ANY_E_TIMEOUT                  0x09
+#define NFC_HCI_ANY_E_REG_ACCESS_DENIED                0x0a
+#define NFC_HCI_ANY_E_PIPE_ACCESS_DENIED       0x0b
+
+/* Pipes */
+#define NFC_HCI_INVALID_PIPE   0x80
+#define NFC_HCI_LINK_MGMT_PIPE 0x00
+#define NFC_HCI_ADMIN_PIPE     0x01
+
+#endif /* __LOCAL_HCI_H */
diff --git a/net/nfc/hci/hcp.c b/net/nfc/hci/hcp.c
new file mode 100644 (file)
index 0000000..7212cf2
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#define pr_fmt(fmt) "hci: %s: " fmt, __func__
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+
+#include <net/nfc/hci.h>
+
+#include "hci.h"
+
+/*
+ * Payload is the HCP message data only. Instruction will be prepended.
+ * Guarantees that cb will be called upon completion or timeout delay
+ * counted from the moment the cmd is sent to the transport.
+ */
+int nfc_hci_hcp_message_tx(struct nfc_hci_dev *hdev, u8 pipe,
+                          u8 type, u8 instruction,
+                          const u8 *payload, size_t payload_len,
+                          hci_cmd_cb_t cb, void *cb_data,
+                          unsigned long completion_delay)
+{
+       struct nfc_dev *ndev = hdev->ndev;
+       struct hci_msg *cmd;
+       const u8 *ptr = payload;
+       int hci_len, err;
+       bool firstfrag = true;
+
+       cmd = kzalloc(sizeof(struct hci_msg), GFP_KERNEL);
+       if (cmd == NULL)
+               return -ENOMEM;
+
+       INIT_LIST_HEAD(&cmd->msg_l);
+       skb_queue_head_init(&cmd->msg_frags);
+       cmd->wait_response = (type == NFC_HCI_HCP_COMMAND) ? true : false;
+       cmd->cb = cb;
+       cmd->cb_context = cb_data;
+       cmd->completion_delay = completion_delay;
+
+       hci_len = payload_len + 1;
+       while (hci_len > 0) {
+               struct sk_buff *skb;
+               int skb_len, data_link_len;
+               struct hcp_packet *packet;
+
+               if (NFC_HCI_HCP_PACKET_HEADER_LEN + hci_len <=
+                   hdev->max_data_link_payload)
+                       data_link_len = hci_len;
+               else
+                       data_link_len = hdev->max_data_link_payload -
+                                       NFC_HCI_HCP_PACKET_HEADER_LEN;
+
+               skb_len = ndev->tx_headroom + NFC_HCI_HCP_PACKET_HEADER_LEN +
+                         data_link_len + ndev->tx_tailroom;
+               hci_len -= data_link_len;
+
+               skb = alloc_skb(skb_len, GFP_KERNEL);
+               if (skb == NULL) {
+                       err = -ENOMEM;
+                       goto out_skb_err;
+               }
+               skb_reserve(skb, ndev->tx_headroom);
+
+               skb_put(skb, NFC_HCI_HCP_PACKET_HEADER_LEN + data_link_len);
+
+               /* Only the last fragment will have the cb bit set to 1 */
+               packet = (struct hcp_packet *)skb->data;
+               packet->header = pipe;
+               if (firstfrag) {
+                       firstfrag = false;
+                       packet->message.header = HCP_HEADER(type, instruction);
+                       if (ptr) {
+                               memcpy(packet->message.data, ptr,
+                                      data_link_len - 1);
+                               ptr += data_link_len - 1;
+                       }
+               } else {
+                       memcpy(&packet->message, ptr, data_link_len);
+                       ptr += data_link_len;
+               }
+
+               /* This is the last fragment, set the cb bit */
+               if (hci_len == 0)
+                       packet->header |= ~NFC_HCI_FRAGMENT;
+
+               skb_queue_tail(&cmd->msg_frags, skb);
+       }
+
+       mutex_lock(&hdev->msg_tx_mutex);
+       list_add_tail(&hdev->msg_tx_queue, &cmd->msg_l);
+       mutex_unlock(&hdev->msg_tx_mutex);
+
+       queue_work(hdev->msg_tx_wq, &hdev->msg_tx_work);
+
+       return 0;
+
+out_skb_err:
+       skb_queue_purge(&cmd->msg_frags);
+       kfree(cmd);
+
+       return err;
+}
+
+u8 nfc_hci_pipe2gate(struct nfc_hci_dev *hdev, u8 pipe)
+{
+       int gate;
+
+       for (gate = 0; gate < NFC_HCI_MAX_GATES; gate++)
+               if (hdev->gate2pipe[gate] == pipe)
+                       return gate;
+
+       return 0xff;
+}
+
+/*
+ * Receive hcp message for pipe, with type and cmd.
+ * skb contains optional message data only.
+ */
+void nfc_hci_hcp_message_rx(struct nfc_hci_dev *hdev, u8 pipe, u8 type,
+                           u8 instruction, struct sk_buff *skb)
+{
+       switch (type) {
+       case NFC_HCI_HCP_RESPONSE:
+               nfc_hci_resp_received(hdev, instruction, skb);
+               break;
+       case NFC_HCI_HCP_COMMAND:
+               nfc_hci_cmd_received(hdev, pipe, instruction, skb);
+               break;
+       case NFC_HCI_HCP_EVENT:
+               nfc_hci_event_received(hdev, pipe, instruction, skb);
+               break;
+       default:
+               pr_err("UNKNOWN MSG Type %d, instruction=%d\n",
+                      type, instruction);
+               kfree_skb(skb);
+               break;
+       }
+}
diff --git a/net/nfc/hci/shdlc.c b/net/nfc/hci/shdlc.c
new file mode 100644 (file)
index 0000000..923bdf7
--- /dev/null
@@ -0,0 +1,945 @@
+/*
+ * Copyright (C) 2012  Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the
+ * Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#define pr_fmt(fmt) "shdlc: %s: " fmt, __func__
+
+#include <linux/sched.h>
+#include <linux/export.h>
+#include <linux/wait.h>
+#include <linux/crc-ccitt.h>
+#include <linux/slab.h>
+#include <linux/skbuff.h>
+
+#include <net/nfc/hci.h>
+#include <net/nfc/shdlc.h>
+
+#define SHDLC_LLC_HEAD_ROOM    2
+#define SHDLC_LLC_TAIL_ROOM    2
+
+#define SHDLC_MAX_WINDOW       4
+#define SHDLC_SREJ_SUPPORT     false
+
+#define SHDLC_CONTROL_HEAD_MASK        0xe0
+#define SHDLC_CONTROL_HEAD_I   0x80
+#define SHDLC_CONTROL_HEAD_I2  0xa0
+#define SHDLC_CONTROL_HEAD_S   0xc0
+#define SHDLC_CONTROL_HEAD_U   0xe0
+
+#define SHDLC_CONTROL_NS_MASK  0x38
+#define SHDLC_CONTROL_NR_MASK  0x07
+#define SHDLC_CONTROL_TYPE_MASK        0x18
+
+#define SHDLC_CONTROL_M_MASK   0x1f
+
+enum sframe_type {
+       S_FRAME_RR = 0x00,
+       S_FRAME_REJ = 0x01,
+       S_FRAME_RNR = 0x02,
+       S_FRAME_SREJ = 0x03
+};
+
+enum uframe_modifier {
+       U_FRAME_UA = 0x06,
+       U_FRAME_RSET = 0x19
+};
+
+#define SHDLC_CONNECT_VALUE_MS 5
+#define SHDLC_T1_VALUE_MS(w)   ((5 * w) / 4)
+#define SHDLC_T2_VALUE_MS      300
+
+#define SHDLC_DUMP_SKB(info, skb)                                \
+do {                                                             \
+       pr_debug("%s:\n", info);                                  \
+       print_hex_dump(KERN_DEBUG, "shdlc: ", DUMP_PREFIX_OFFSET, \
+                      16, 1, skb->data, skb->len, 0);            \
+} while (0)
+
+/* checks x < y <= z modulo 8 */
+static bool nfc_shdlc_x_lt_y_lteq_z(int x, int y, int z)
+{
+       if (x < z)
+               return ((x < y) && (y <= z)) ? true : false;
+       else
+               return ((y > x) || (y <= z)) ? true : false;
+}
+
+/* checks x <= y < z modulo 8 */
+static bool nfc_shdlc_x_lteq_y_lt_z(int x, int y, int z)
+{
+       if (x <= z)
+               return ((x <= y) && (y < z)) ? true : false;
+       else                    /* x > z -> z+8 > x */
+               return ((y >= x) || (y < z)) ? true : false;
+}
+
+static struct sk_buff *nfc_shdlc_alloc_skb(struct nfc_shdlc *shdlc,
+                                          int payload_len)
+{
+       struct sk_buff *skb;
+
+       skb = alloc_skb(shdlc->client_headroom + SHDLC_LLC_HEAD_ROOM +
+                       shdlc->client_tailroom + SHDLC_LLC_TAIL_ROOM +
+                       payload_len, GFP_KERNEL);
+       if (skb)
+               skb_reserve(skb, shdlc->client_headroom + SHDLC_LLC_HEAD_ROOM);
+
+       return skb;
+}
+
+static void nfc_shdlc_add_len_crc(struct sk_buff *skb)
+{
+       u16 crc;
+       int len;
+
+       len = skb->len + 2;
+       *skb_push(skb, 1) = len;
+
+       crc = crc_ccitt(0xffff, skb->data, skb->len);
+       crc = ~crc;
+       *skb_put(skb, 1) = crc & 0xff;
+       *skb_put(skb, 1) = crc >> 8;
+}
+
+/* immediately sends an S frame. */
+static int nfc_shdlc_send_s_frame(struct nfc_shdlc *shdlc,
+                                 enum sframe_type sframe_type, int nr)
+{
+       int r;
+       struct sk_buff *skb;
+
+       pr_debug("sframe_type=%d nr=%d\n", sframe_type, nr);
+
+       skb = nfc_shdlc_alloc_skb(shdlc, 0);
+       if (skb == NULL)
+               return -ENOMEM;
+
+       *skb_push(skb, 1) = SHDLC_CONTROL_HEAD_S | (sframe_type << 3) | nr;
+
+       nfc_shdlc_add_len_crc(skb);
+
+       r = shdlc->ops->xmit(shdlc, skb);
+
+       kfree_skb(skb);
+
+       return r;
+}
+
+/* immediately sends an U frame. skb may contain optional payload */
+static int nfc_shdlc_send_u_frame(struct nfc_shdlc *shdlc,
+                                 struct sk_buff *skb,
+                                 enum uframe_modifier uframe_modifier)
+{
+       int r;
+
+       pr_debug("uframe_modifier=%d\n", uframe_modifier);
+
+       *skb_push(skb, 1) = SHDLC_CONTROL_HEAD_U | uframe_modifier;
+
+       nfc_shdlc_add_len_crc(skb);
+
+       r = shdlc->ops->xmit(shdlc, skb);
+
+       kfree_skb(skb);
+
+       return r;
+}
+
+/*
+ * Free ack_pending frames until y_nr - 1, and reset t2 according to
+ * the remaining oldest ack_pending frame sent time
+ */
+static void nfc_shdlc_reset_t2(struct nfc_shdlc *shdlc, int y_nr)
+{
+       struct sk_buff *skb;
+       int dnr = shdlc->dnr;   /* MUST initially be < y_nr */
+
+       pr_debug("release ack pending up to frame %d excluded\n", y_nr);
+
+       while (dnr != y_nr) {
+               pr_debug("release ack pending frame %d\n", dnr);
+
+               skb = skb_dequeue(&shdlc->ack_pending_q);
+               kfree_skb(skb);
+
+               dnr = (dnr + 1) % 8;
+       }
+
+       if (skb_queue_empty(&shdlc->ack_pending_q)) {
+               if (shdlc->t2_active) {
+                       del_timer_sync(&shdlc->t2_timer);
+                       shdlc->t2_active = false;
+
+                       pr_debug
+                           ("All sent frames acked. Stopped T2(retransmit)\n");
+               }
+       } else {
+               skb = skb_peek(&shdlc->ack_pending_q);
+
+               mod_timer(&shdlc->t2_timer, *(unsigned long *)skb->cb +
+                         msecs_to_jiffies(SHDLC_T2_VALUE_MS));
+               shdlc->t2_active = true;
+
+               pr_debug
+                   ("Start T2(retransmit) for remaining unacked sent frames\n");
+       }
+}
+
+/*
+ * Receive validated frames from lower layer. skb contains HCI payload only.
+ * Handle according to algorithm at spec:10.8.2
+ */
+static void nfc_shdlc_rcv_i_frame(struct nfc_shdlc *shdlc,
+                                 struct sk_buff *skb, int ns, int nr)
+{
+       int x_ns = ns;
+       int y_nr = nr;
+
+       pr_debug("recvd I-frame %d, remote waiting frame %d\n", ns, nr);
+
+       if (shdlc->state != SHDLC_CONNECTED)
+               goto exit;
+
+       if (x_ns != shdlc->nr) {
+               nfc_shdlc_send_s_frame(shdlc, S_FRAME_REJ, shdlc->nr);
+               goto exit;
+       }
+
+       if (shdlc->t1_active == false) {
+               shdlc->t1_active = true;
+               mod_timer(&shdlc->t1_timer,
+                         msecs_to_jiffies(SHDLC_T1_VALUE_MS(shdlc->w)));
+               pr_debug("(re)Start T1(send ack)\n");
+       }
+
+       if (skb->len) {
+               nfc_hci_recv_frame(shdlc->hdev, skb);
+               skb = NULL;
+       }
+
+       shdlc->nr = (shdlc->nr + 1) % 8;
+
+       if (nfc_shdlc_x_lt_y_lteq_z(shdlc->dnr, y_nr, shdlc->ns)) {
+               nfc_shdlc_reset_t2(shdlc, y_nr);
+
+               shdlc->dnr = y_nr;
+       }
+
+exit:
+       if (skb)
+               kfree_skb(skb);
+}
+
+static void nfc_shdlc_rcv_ack(struct nfc_shdlc *shdlc, int y_nr)
+{
+       pr_debug("remote acked up to frame %d excluded\n", y_nr);
+
+       if (nfc_shdlc_x_lt_y_lteq_z(shdlc->dnr, y_nr, shdlc->ns)) {
+               nfc_shdlc_reset_t2(shdlc, y_nr);
+               shdlc->dnr = y_nr;
+       }
+}
+
+static void nfc_shdlc_requeue_ack_pending(struct nfc_shdlc *shdlc)
+{
+       struct sk_buff *skb;
+
+       pr_debug("ns reset to %d\n", shdlc->dnr);
+
+       while ((skb = skb_dequeue_tail(&shdlc->ack_pending_q))) {
+               skb_pull(skb, 2);       /* remove len+control */
+               skb_trim(skb, skb->len - 2);    /* remove crc */
+               skb_queue_head(&shdlc->send_q, skb);
+       }
+       shdlc->ns = shdlc->dnr;
+}
+
+static void nfc_shdlc_rcv_rej(struct nfc_shdlc *shdlc, int y_nr)
+{
+       struct sk_buff *skb;
+
+       pr_debug("remote asks retransmition from frame %d\n", y_nr);
+
+       if (nfc_shdlc_x_lteq_y_lt_z(shdlc->dnr, y_nr, shdlc->ns)) {
+               if (shdlc->t2_active) {
+                       del_timer_sync(&shdlc->t2_timer);
+                       shdlc->t2_active = false;
+                       pr_debug("Stopped T2(retransmit)\n");
+               }
+
+               if (shdlc->dnr != y_nr) {
+                       while ((shdlc->dnr = ((shdlc->dnr + 1) % 8)) != y_nr) {
+                               skb = skb_dequeue(&shdlc->ack_pending_q);
+                               kfree_skb(skb);
+                       }
+               }
+
+               nfc_shdlc_requeue_ack_pending(shdlc);
+       }
+}
+
+/* See spec RR:10.8.3 REJ:10.8.4 */
+static void nfc_shdlc_rcv_s_frame(struct nfc_shdlc *shdlc,
+                                 enum sframe_type s_frame_type, int nr)
+{
+       struct sk_buff *skb;
+
+       if (shdlc->state != SHDLC_CONNECTED)
+               return;
+
+       switch (s_frame_type) {
+       case S_FRAME_RR:
+               nfc_shdlc_rcv_ack(shdlc, nr);
+               if (shdlc->rnr == true) {       /* see SHDLC 10.7.7 */
+                       shdlc->rnr = false;
+                       if (shdlc->send_q.qlen == 0) {
+                               skb = nfc_shdlc_alloc_skb(shdlc, 0);
+                               if (skb)
+                                       skb_queue_tail(&shdlc->send_q, skb);
+                       }
+               }
+               break;
+       case S_FRAME_REJ:
+               nfc_shdlc_rcv_rej(shdlc, nr);
+               break;
+       case S_FRAME_RNR:
+               nfc_shdlc_rcv_ack(shdlc, nr);
+               shdlc->rnr = true;
+               break;
+       default:
+               break;
+       }
+}
+
+static void nfc_shdlc_connect_complete(struct nfc_shdlc *shdlc, int r)
+{
+       pr_debug("result=%d\n", r);
+
+       del_timer_sync(&shdlc->connect_timer);
+
+       if (r == 0) {
+               shdlc->ns = 0;
+               shdlc->nr = 0;
+               shdlc->dnr = 0;
+
+               shdlc->state = SHDLC_CONNECTED;
+       } else {
+               shdlc->state = SHDLC_DISCONNECTED;
+
+               /*
+                * TODO: Could it be possible that there are pending
+                * executing commands that are waiting for connect to complete
+                * before they can be carried? As connect is a blocking
+                * operation, it would require that the userspace process can
+                * send commands on the same device from a second thread before
+                * the device is up. I don't think that is possible, is it?
+                */
+       }
+
+       shdlc->connect_result = r;
+
+       wake_up(shdlc->connect_wq);
+}
+
+static int nfc_shdlc_connect_initiate(struct nfc_shdlc *shdlc)
+{
+       struct sk_buff *skb;
+
+       pr_debug("\n");
+
+       skb = nfc_shdlc_alloc_skb(shdlc, 2);
+       if (skb == NULL)
+               return -ENOMEM;
+
+       *skb_put(skb, 1) = SHDLC_MAX_WINDOW;
+       *skb_put(skb, 1) = SHDLC_SREJ_SUPPORT ? 1 : 0;
+
+       return nfc_shdlc_send_u_frame(shdlc, skb, U_FRAME_RSET);
+}
+
+static int nfc_shdlc_connect_send_ua(struct nfc_shdlc *shdlc)
+{
+       struct sk_buff *skb;
+
+       pr_debug("\n");
+
+       skb = nfc_shdlc_alloc_skb(shdlc, 0);
+       if (skb == NULL)
+               return -ENOMEM;
+
+       return nfc_shdlc_send_u_frame(shdlc, skb, U_FRAME_UA);
+}
+
+static void nfc_shdlc_rcv_u_frame(struct nfc_shdlc *shdlc,
+                                 struct sk_buff *skb,
+                                 enum uframe_modifier u_frame_modifier)
+{
+       u8 w = SHDLC_MAX_WINDOW;
+       bool srej_support = SHDLC_SREJ_SUPPORT;
+       int r;
+
+       pr_debug("u_frame_modifier=%d\n", u_frame_modifier);
+
+       switch (u_frame_modifier) {
+       case U_FRAME_RSET:
+               if (shdlc->state == SHDLC_NEGOCIATING) {
+                       /* we sent RSET, but chip wants to negociate */
+                       if (skb->len > 0)
+                               w = skb->data[0];
+
+                       if (skb->len > 1)
+                               srej_support = skb->data[1] & 0x01 ? true :
+                                              false;
+
+                       if ((w <= SHDLC_MAX_WINDOW) &&
+                           (SHDLC_SREJ_SUPPORT || (srej_support == false))) {
+                               shdlc->w = w;
+                               shdlc->srej_support = srej_support;
+                               r = nfc_shdlc_connect_send_ua(shdlc);
+                               nfc_shdlc_connect_complete(shdlc, r);
+                       }
+               } else if (shdlc->state > SHDLC_NEGOCIATING) {
+                       /*
+                        * TODO: Chip wants to reset link
+                        * send ua, empty skb lists, reset counters
+                        * propagate info to HCI layer
+                        */
+               }
+               break;
+       case U_FRAME_UA:
+               if ((shdlc->state == SHDLC_CONNECTING &&
+                    shdlc->connect_tries > 0) ||
+                   (shdlc->state == SHDLC_NEGOCIATING))
+                       nfc_shdlc_connect_complete(shdlc, 0);
+               break;
+       default:
+               break;
+       }
+
+       kfree_skb(skb);
+}
+
+static void nfc_shdlc_handle_rcv_queue(struct nfc_shdlc *shdlc)
+{
+       struct sk_buff *skb;
+       u8 control;
+       int nr;
+       int ns;
+       enum sframe_type s_frame_type;
+       enum uframe_modifier u_frame_modifier;
+
+       if (shdlc->rcv_q.qlen)
+               pr_debug("rcvQlen=%d\n", shdlc->rcv_q.qlen);
+
+       while ((skb = skb_dequeue(&shdlc->rcv_q)) != NULL) {
+               control = skb->data[0];
+               skb_pull(skb, 1);
+               switch (control & SHDLC_CONTROL_HEAD_MASK) {
+               case SHDLC_CONTROL_HEAD_I:
+               case SHDLC_CONTROL_HEAD_I2:
+                       ns = (control & SHDLC_CONTROL_NS_MASK) >> 3;
+                       nr = control & SHDLC_CONTROL_NR_MASK;
+                       nfc_shdlc_rcv_i_frame(shdlc, skb, ns, nr);
+                       break;
+               case SHDLC_CONTROL_HEAD_S:
+                       s_frame_type = (control & SHDLC_CONTROL_TYPE_MASK) >> 3;
+                       nr = control & SHDLC_CONTROL_NR_MASK;
+                       nfc_shdlc_rcv_s_frame(shdlc, s_frame_type, nr);
+                       kfree_skb(skb);
+                       break;
+               case SHDLC_CONTROL_HEAD_U:
+                       u_frame_modifier = control & SHDLC_CONTROL_M_MASK;
+                       nfc_shdlc_rcv_u_frame(shdlc, skb, u_frame_modifier);
+                       break;
+               default:
+                       pr_err("UNKNOWN Control=%d\n", control);
+                       kfree_skb(skb);
+                       break;
+               }
+       }
+}
+
+static int nfc_shdlc_w_used(int ns, int dnr)
+{
+       int unack_count;
+
+       if (dnr <= ns)
+               unack_count = ns - dnr;
+       else
+               unack_count = 8 - dnr + ns;
+
+       return unack_count;
+}
+
+/* Send frames according to algorithm at spec:10.8.1 */
+static void nfc_shdlc_handle_send_queue(struct nfc_shdlc *shdlc)
+{
+       struct sk_buff *skb;
+       int r;
+       unsigned long time_sent;
+
+       if (shdlc->send_q.qlen)
+               pr_debug
+                   ("sendQlen=%d ns=%d dnr=%d rnr=%s w_room=%d unackQlen=%d\n",
+                    shdlc->send_q.qlen, shdlc->ns, shdlc->dnr,
+                    shdlc->rnr == false ? "false" : "true",
+                    shdlc->w - nfc_shdlc_w_used(shdlc->ns, shdlc->dnr),
+                    shdlc->ack_pending_q.qlen);
+
+       while (shdlc->send_q.qlen && shdlc->ack_pending_q.qlen < shdlc->w &&
+              (shdlc->rnr == false)) {
+
+               if (shdlc->t1_active) {
+                       del_timer_sync(&shdlc->t1_timer);
+                       shdlc->t1_active = false;
+                       pr_debug("Stopped T1(send ack)\n");
+               }
+
+               skb = skb_dequeue(&shdlc->send_q);
+
+               *skb_push(skb, 1) = SHDLC_CONTROL_HEAD_I | (shdlc->ns << 3) |
+                                   shdlc->nr;
+
+               pr_debug("Sending I-Frame %d, waiting to rcv %d\n", shdlc->ns,
+                        shdlc->nr);
+       /*      SHDLC_DUMP_SKB("shdlc frame written", skb); */
+
+               nfc_shdlc_add_len_crc(skb);
+
+               r = shdlc->ops->xmit(shdlc, skb);
+               if (r < 0) {
+                       /*
+                        * TODO: Cannot send, shdlc machine is dead, we
+                        * must propagate the information up to HCI.
+                        */
+                       shdlc->hard_fault = r;
+                       break;
+               }
+
+               shdlc->ns = (shdlc->ns + 1) % 8;
+
+               time_sent = jiffies;
+               *(unsigned long *)skb->cb = time_sent;
+
+               skb_queue_tail(&shdlc->ack_pending_q, skb);
+
+               if (shdlc->t2_active == false) {
+                       shdlc->t2_active = true;
+                       mod_timer(&shdlc->t2_timer, time_sent +
+                                 msecs_to_jiffies(SHDLC_T2_VALUE_MS));
+                       pr_debug("Started T2 (retransmit)\n");
+               }
+       }
+}
+
+static void nfc_shdlc_connect_timeout(unsigned long data)
+{
+       struct nfc_shdlc *shdlc = (struct nfc_shdlc *)data;
+
+       pr_debug("\n");
+
+       queue_work(shdlc->sm_wq, &shdlc->sm_work);
+}
+
+static void nfc_shdlc_t1_timeout(unsigned long data)
+{
+       struct nfc_shdlc *shdlc = (struct nfc_shdlc *)data;
+
+       pr_debug("SoftIRQ: need to send ack\n");
+
+       queue_work(shdlc->sm_wq, &shdlc->sm_work);
+}
+
+static void nfc_shdlc_t2_timeout(unsigned long data)
+{
+       struct nfc_shdlc *shdlc = (struct nfc_shdlc *)data;
+
+       pr_debug("SoftIRQ: need to retransmit\n");
+
+       queue_work(shdlc->sm_wq, &shdlc->sm_work);
+}
+
+static void nfc_shdlc_sm_work(struct work_struct *work)
+{
+       struct nfc_shdlc *shdlc = container_of(work, struct nfc_shdlc, sm_work);
+       int r;
+
+       pr_debug("\n");
+
+       mutex_lock(&shdlc->state_mutex);
+
+       switch (shdlc->state) {
+       case SHDLC_DISCONNECTED:
+               skb_queue_purge(&shdlc->rcv_q);
+               skb_queue_purge(&shdlc->send_q);
+               skb_queue_purge(&shdlc->ack_pending_q);
+               break;
+       case SHDLC_CONNECTING:
+               if (shdlc->connect_tries++ < 5)
+                       r = nfc_shdlc_connect_initiate(shdlc);
+               else
+                       r = -ETIME;
+               if (r < 0)
+                       nfc_shdlc_connect_complete(shdlc, r);
+               else {
+                       mod_timer(&shdlc->connect_timer, jiffies +
+                                 msecs_to_jiffies(SHDLC_CONNECT_VALUE_MS));
+
+                       shdlc->state = SHDLC_NEGOCIATING;
+               }
+               break;
+       case SHDLC_NEGOCIATING:
+               if (timer_pending(&shdlc->connect_timer) == 0) {
+                       shdlc->state = SHDLC_CONNECTING;
+                       queue_work(shdlc->sm_wq, &shdlc->sm_work);
+               }
+
+               nfc_shdlc_handle_rcv_queue(shdlc);
+               break;
+       case SHDLC_CONNECTED:
+               nfc_shdlc_handle_rcv_queue(shdlc);
+               nfc_shdlc_handle_send_queue(shdlc);
+
+               if (shdlc->t1_active && timer_pending(&shdlc->t1_timer) == 0) {
+                       pr_debug
+                           ("Handle T1(send ack) elapsed (T1 now inactive)\n");
+
+                       shdlc->t1_active = false;
+                       r = nfc_shdlc_send_s_frame(shdlc, S_FRAME_RR,
+                                                  shdlc->nr);
+                       if (r < 0)
+                               shdlc->hard_fault = r;
+               }
+
+               if (shdlc->t2_active && timer_pending(&shdlc->t2_timer) == 0) {
+                       pr_debug
+                           ("Handle T2(retransmit) elapsed (T2 inactive)\n");
+
+                       shdlc->t2_active = false;
+
+                       nfc_shdlc_requeue_ack_pending(shdlc);
+                       nfc_shdlc_handle_send_queue(shdlc);
+               }
+
+               if (shdlc->hard_fault) {
+                       /*
+                        * TODO: Handle hard_fault that occured during
+                        * this invocation of the shdlc worker
+                        */
+               }
+               break;
+       default:
+               break;
+       }
+       mutex_unlock(&shdlc->state_mutex);
+}
+
+/*
+ * Called from syscall context to establish shdlc link. Sleeps until
+ * link is ready or failure.
+ */
+static int nfc_shdlc_connect(struct nfc_shdlc *shdlc)
+{
+       DECLARE_WAIT_QUEUE_HEAD_ONSTACK(connect_wq);
+
+       pr_debug("\n");
+
+       mutex_lock(&shdlc->state_mutex);
+
+       shdlc->state = SHDLC_CONNECTING;
+       shdlc->connect_wq = &connect_wq;
+       shdlc->connect_tries = 0;
+       shdlc->connect_result = 1;
+
+       mutex_unlock(&shdlc->state_mutex);
+
+       queue_work(shdlc->sm_wq, &shdlc->sm_work);
+
+       wait_event(connect_wq, shdlc->connect_result != 1);
+
+       return shdlc->connect_result;
+}
+
+static void nfc_shdlc_disconnect(struct nfc_shdlc *shdlc)
+{
+       pr_debug("\n");
+
+       mutex_lock(&shdlc->state_mutex);
+
+       shdlc->state = SHDLC_DISCONNECTED;
+
+       mutex_unlock(&shdlc->state_mutex);
+
+       queue_work(shdlc->sm_wq, &shdlc->sm_work);
+}
+
+/*
+ * Receive an incoming shdlc frame. Frame has already been crc-validated.
+ * skb contains only LLC header and payload.
+ * If skb == NULL, it is a notification that the link below is dead.
+ */
+void nfc_shdlc_recv_frame(struct nfc_shdlc *shdlc, struct sk_buff *skb)
+{
+       if (skb == NULL) {
+               pr_err("NULL Frame -> link is dead\n");
+               shdlc->hard_fault = -EREMOTEIO;
+       } else {
+               SHDLC_DUMP_SKB("incoming frame", skb);
+               skb_queue_tail(&shdlc->rcv_q, skb);
+       }
+
+       queue_work(shdlc->sm_wq, &shdlc->sm_work);
+}
+EXPORT_SYMBOL(nfc_shdlc_recv_frame);
+
+static int nfc_shdlc_open(struct nfc_hci_dev *hdev)
+{
+       struct nfc_shdlc *shdlc = nfc_hci_get_clientdata(hdev);
+       int r;
+
+       pr_debug("\n");
+
+       if (shdlc->ops->open) {
+               r = shdlc->ops->open(shdlc);
+               if (r < 0)
+                       return r;
+       }
+
+       r = nfc_shdlc_connect(shdlc);
+       if (r < 0 && shdlc->ops->close)
+               shdlc->ops->close(shdlc);
+
+       return r;
+}
+
+static void nfc_shdlc_close(struct nfc_hci_dev *hdev)
+{
+       struct nfc_shdlc *shdlc = nfc_hci_get_clientdata(hdev);
+
+       pr_debug("\n");
+
+       nfc_shdlc_disconnect(shdlc);
+
+       if (shdlc->ops->close)
+               shdlc->ops->close(shdlc);
+}
+
+static int nfc_shdlc_hci_ready(struct nfc_hci_dev *hdev)
+{
+       struct nfc_shdlc *shdlc = nfc_hci_get_clientdata(hdev);
+       int r = 0;
+
+       pr_debug("\n");
+
+       if (shdlc->ops->hci_ready)
+               r = shdlc->ops->hci_ready(shdlc);
+
+       return r;
+}
+
+static int nfc_shdlc_xmit(struct nfc_hci_dev *hdev, struct sk_buff *skb)
+{
+       struct nfc_shdlc *shdlc = nfc_hci_get_clientdata(hdev);
+
+       SHDLC_DUMP_SKB("queuing HCP packet to shdlc", skb);
+
+       skb_queue_tail(&shdlc->send_q, skb);
+
+       queue_work(shdlc->sm_wq, &shdlc->sm_work);
+
+       return 0;
+}
+
+static int nfc_shdlc_start_poll(struct nfc_hci_dev *hdev, u32 protocols)
+{
+       struct nfc_shdlc *shdlc = nfc_hci_get_clientdata(hdev);
+
+       pr_debug("\n");
+
+       if (shdlc->ops->start_poll)
+               return shdlc->ops->start_poll(shdlc, protocols);
+
+       return 0;
+}
+
+static int nfc_shdlc_target_from_gate(struct nfc_hci_dev *hdev, u8 gate,
+                                     struct nfc_target *target)
+{
+       struct nfc_shdlc *shdlc = nfc_hci_get_clientdata(hdev);
+
+       if (shdlc->ops->target_from_gate)
+               return shdlc->ops->target_from_gate(shdlc, gate, target);
+
+       return -EPERM;
+}
+
+static int nfc_shdlc_complete_target_discovered(struct nfc_hci_dev *hdev,
+                                               u8 gate,
+                                               struct nfc_target *target)
+{
+       struct nfc_shdlc *shdlc = nfc_hci_get_clientdata(hdev);
+
+       pr_debug("\n");
+
+       if (shdlc->ops->complete_target_discovered)
+               return shdlc->ops->complete_target_discovered(shdlc, gate,
+                                                             target);
+
+       return 0;
+}
+
+static int nfc_shdlc_data_exchange(struct nfc_hci_dev *hdev,
+                                  struct nfc_target *target,
+                                  struct sk_buff *skb,
+                                  struct sk_buff **res_skb)
+{
+       struct nfc_shdlc *shdlc = nfc_hci_get_clientdata(hdev);
+
+       if (shdlc->ops->data_exchange)
+               return shdlc->ops->data_exchange(shdlc, target, skb, res_skb);
+
+       return -EPERM;
+}
+
+static struct nfc_hci_ops shdlc_ops = {
+       .open = nfc_shdlc_open,
+       .close = nfc_shdlc_close,
+       .hci_ready = nfc_shdlc_hci_ready,
+       .xmit = nfc_shdlc_xmit,
+       .start_poll = nfc_shdlc_start_poll,
+       .target_from_gate = nfc_shdlc_target_from_gate,
+       .complete_target_discovered = nfc_shdlc_complete_target_discovered,
+       .data_exchange = nfc_shdlc_data_exchange,
+};
+
+struct nfc_shdlc *nfc_shdlc_allocate(struct nfc_shdlc_ops *ops,
+                                    struct nfc_hci_init_data *init_data,
+                                    u32 protocols,
+                                    int tx_headroom, int tx_tailroom,
+                                    int max_link_payload, const char *devname)
+{
+       struct nfc_shdlc *shdlc;
+       int r;
+       char name[32];
+
+       if (ops->xmit == NULL)
+               return NULL;
+
+       shdlc = kzalloc(sizeof(struct nfc_shdlc), GFP_KERNEL);
+       if (shdlc == NULL)
+               return NULL;
+
+       mutex_init(&shdlc->state_mutex);
+       shdlc->ops = ops;
+       shdlc->state = SHDLC_DISCONNECTED;
+
+       init_timer(&shdlc->connect_timer);
+       shdlc->connect_timer.data = (unsigned long)shdlc;
+       shdlc->connect_timer.function = nfc_shdlc_connect_timeout;
+
+       init_timer(&shdlc->t1_timer);
+       shdlc->t1_timer.data = (unsigned long)shdlc;
+       shdlc->t1_timer.function = nfc_shdlc_t1_timeout;
+
+       init_timer(&shdlc->t2_timer);
+       shdlc->t2_timer.data = (unsigned long)shdlc;
+       shdlc->t2_timer.function = nfc_shdlc_t2_timeout;
+
+       shdlc->w = SHDLC_MAX_WINDOW;
+       shdlc->srej_support = SHDLC_SREJ_SUPPORT;
+
+       skb_queue_head_init(&shdlc->rcv_q);
+       skb_queue_head_init(&shdlc->send_q);
+       skb_queue_head_init(&shdlc->ack_pending_q);
+
+       INIT_WORK(&shdlc->sm_work, nfc_shdlc_sm_work);
+       snprintf(name, sizeof(name), "%s_shdlc_sm_wq", devname);
+       shdlc->sm_wq = alloc_workqueue(name, WQ_NON_REENTRANT | WQ_UNBOUND |
+                                      WQ_MEM_RECLAIM, 1);
+       if (shdlc->sm_wq == NULL)
+               goto err_allocwq;
+
+       shdlc->client_headroom = tx_headroom;
+       shdlc->client_tailroom = tx_tailroom;
+
+       shdlc->hdev = nfc_hci_allocate_device(&shdlc_ops, init_data, protocols,
+                                             tx_headroom + SHDLC_LLC_HEAD_ROOM,
+                                             tx_tailroom + SHDLC_LLC_TAIL_ROOM,
+                                             max_link_payload);
+       if (shdlc->hdev == NULL)
+               goto err_allocdev;
+
+       nfc_hci_set_clientdata(shdlc->hdev, shdlc);
+
+       r = nfc_hci_register_device(shdlc->hdev);
+       if (r < 0)
+               goto err_regdev;
+
+       return shdlc;
+
+err_regdev:
+       nfc_hci_free_device(shdlc->hdev);
+
+err_allocdev:
+       destroy_workqueue(shdlc->sm_wq);
+
+err_allocwq:
+       kfree(shdlc);
+
+       return NULL;
+}
+EXPORT_SYMBOL(nfc_shdlc_allocate);
+
+void nfc_shdlc_free(struct nfc_shdlc *shdlc)
+{
+       pr_debug("\n");
+
+       /* TODO: Check that this cannot be called while still in use */
+
+       nfc_hci_unregister_device(shdlc->hdev);
+       nfc_hci_free_device(shdlc->hdev);
+
+       destroy_workqueue(shdlc->sm_wq);
+
+       skb_queue_purge(&shdlc->rcv_q);
+       skb_queue_purge(&shdlc->send_q);
+       skb_queue_purge(&shdlc->ack_pending_q);
+
+       kfree(shdlc);
+}
+EXPORT_SYMBOL(nfc_shdlc_free);
+
+void nfc_shdlc_set_clientdata(struct nfc_shdlc *shdlc, void *clientdata)
+{
+       pr_debug("\n");
+
+       shdlc->clientdata = clientdata;
+}
+EXPORT_SYMBOL(nfc_shdlc_set_clientdata);
+
+void *nfc_shdlc_get_clientdata(struct nfc_shdlc *shdlc)
+{
+       return shdlc->clientdata;
+}
+EXPORT_SYMBOL(nfc_shdlc_get_clientdata);
+
+struct nfc_hci_dev *nfc_shdlc_get_hci_dev(struct nfc_shdlc *shdlc)
+{
+       return shdlc->hdev;
+}
+EXPORT_SYMBOL(nfc_shdlc_get_hci_dev);
index ef10ffcb4b6ffb5ed79eecdc8005dccc0de34575..11a3b7d98dc5bbeb1a1cd4c91ef193f4dd921844 100644 (file)
@@ -102,7 +102,7 @@ u8 *nfc_llcp_build_tlv(u8 type, u8 *value, u8 value_length, u8 *tlv_length)
        length = llcp_tlv_length[type];
        if (length == 0 && value_length == 0)
                return NULL;
-       else
+       else if (length == 0)
                length = value_length;
 
        *tlv_length = 2 + length;
@@ -248,7 +248,7 @@ int nfc_llcp_disconnect(struct nfc_llcp_sock *sock)
 
        skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE);
 
-       skb = llcp_add_header(skb, sock->ssap, sock->dsap, LLCP_PDU_DISC);
+       skb = llcp_add_header(skb, sock->dsap, sock->ssap, LLCP_PDU_DISC);
 
        skb_queue_tail(&local->tx_queue, skb);
 
@@ -416,7 +416,7 @@ int nfc_llcp_send_dm(struct nfc_llcp_local *local, u8 ssap, u8 dsap, u8 reason)
 
        skb_reserve(skb, dev->tx_headroom + NFC_HEADER_SIZE);
 
-       skb = llcp_add_header(skb, ssap, dsap, LLCP_PDU_DM);
+       skb = llcp_add_header(skb, dsap, ssap, LLCP_PDU_DM);
 
        memcpy(skb_put(skb, 1), &reason, 1);
 
@@ -522,7 +522,7 @@ int nfc_llcp_send_rr(struct nfc_llcp_sock *sock)
 
        skb_put(skb, LLCP_SEQUENCE_SIZE);
 
-       skb->data[2] = sock->recv_n % 16;
+       skb->data[2] = sock->recv_n;
 
        skb_queue_head(&local->tx_queue, skb);
 
index 17a578f641f12f8bf5b98a58996af292e5ef50a0..92988aa620dcb04d73ae45eb573249bddac0a6cf 100644 (file)
@@ -307,6 +307,8 @@ static int nfc_llcp_build_gb(struct nfc_llcp_local *local)
        u8 *gb_cur, *version_tlv, version, version_length;
        u8 *lto_tlv, lto, lto_length;
        u8 *wks_tlv, wks_length;
+       u8 *miux_tlv, miux_length;
+       __be16 miux;
        u8 gb_len = 0;
 
        version = LLCP_VERSION_11;
@@ -316,7 +318,7 @@ static int nfc_llcp_build_gb(struct nfc_llcp_local *local)
 
        /* 1500 ms */
        lto = 150;
-       lto_tlv = nfc_llcp_build_tlv(LLCP_TLV_VERSION, &lto, 1, &lto_length);
+       lto_tlv = nfc_llcp_build_tlv(LLCP_TLV_LTO, &lto, 1, &lto_length);
        gb_len += lto_length;
 
        pr_debug("Local wks 0x%lx\n", local->local_wks);
@@ -324,6 +326,11 @@ static int nfc_llcp_build_gb(struct nfc_llcp_local *local)
                                     &wks_length);
        gb_len += wks_length;
 
+       miux = cpu_to_be16(LLCP_MAX_MIUX);
+       miux_tlv = nfc_llcp_build_tlv(LLCP_TLV_MIUX, (u8 *)&miux, 0,
+                                     &miux_length);
+       gb_len += miux_length;
+
        gb_len += ARRAY_SIZE(llcp_magic);
 
        if (gb_len > NFC_MAX_GT_LEN) {
@@ -345,6 +352,9 @@ static int nfc_llcp_build_gb(struct nfc_llcp_local *local)
        memcpy(gb_cur, wks_tlv, wks_length);
        gb_cur += wks_length;
 
+       memcpy(gb_cur, miux_tlv, miux_length);
+       gb_cur += miux_length;
+
        kfree(version_tlv);
        kfree(lto_tlv);
 
@@ -388,6 +398,9 @@ static void nfc_llcp_tx_work(struct work_struct *work)
        skb = skb_dequeue(&local->tx_queue);
        if (skb != NULL) {
                pr_debug("Sending pending skb\n");
+               print_hex_dump(KERN_DEBUG, "LLCP Tx: ", DUMP_PREFIX_OFFSET,
+                              16, 1, skb->data, skb->len, true);
+
                nfc_data_exchange(local->dev, local->target_idx,
                                  skb, nfc_llcp_recv, local);
        } else {
@@ -425,7 +438,7 @@ static u8 nfc_llcp_nr(struct sk_buff *pdu)
 
 static void nfc_llcp_set_nrns(struct nfc_llcp_sock *sock, struct sk_buff *pdu)
 {
-       pdu->data[2] = (sock->send_n << 4) | (sock->recv_n % 16);
+       pdu->data[2] = (sock->send_n << 4) | (sock->recv_n);
        sock->send_n = (sock->send_n + 1) % 16;
        sock->recv_ack_n = (sock->recv_n - 1) % 16;
 }
@@ -814,6 +827,10 @@ static void nfc_llcp_rx_work(struct work_struct *work)
 
        pr_debug("ptype 0x%x dsap 0x%x ssap 0x%x\n", ptype, dsap, ssap);
 
+       if (ptype != LLCP_PDU_SYMM)
+               print_hex_dump(KERN_DEBUG, "LLCP Rx: ", DUMP_PREFIX_OFFSET,
+                              16, 1, skb->data, skb->len, true);
+
        switch (ptype) {
        case LLCP_PDU_SYMM:
                pr_debug("SYMM\n");
index 9ec065bb9ee1e78b96321a8f2f1e5c6827dd15bc..8737c2089fddeb005253afd768b89d0f814e13a4 100644 (file)
@@ -477,7 +477,7 @@ static int nci_activate_target(struct nfc_dev *nfc_dev, __u32 target_idx,
        }
 
        if (atomic_read(&ndev->state) == NCI_W4_HOST_SELECT) {
-               param.rf_discovery_id = target->idx;
+               param.rf_discovery_id = target->logical_idx;
 
                if (protocol == NFC_PROTO_JEWEL)
                        param.rf_protocol = NCI_RF_PROTOCOL_T1T;
index 2e3dee42196d064d0fdcf5ad7c6e4fe50945d57b..99e1632e6aac7535efb587012979807a5f590619 100644 (file)
@@ -227,7 +227,7 @@ static void nci_add_new_target(struct nci_dev *ndev,
 
        for (i = 0; i < ndev->n_targets; i++) {
                target = &ndev->targets[i];
-               if (target->idx == ntf->rf_discovery_id) {
+               if (target->logical_idx == ntf->rf_discovery_id) {
                        /* This target already exists, add the new protocol */
                        nci_add_new_protocol(ndev, target, ntf->rf_protocol,
                                             ntf->rf_tech_and_mode,
@@ -248,10 +248,10 @@ static void nci_add_new_target(struct nci_dev *ndev,
                                  ntf->rf_tech_and_mode,
                                  &ntf->rf_tech_specific_params);
        if (!rc) {
-               target->idx = ntf->rf_discovery_id;
+               target->logical_idx = ntf->rf_discovery_id;
                ndev->n_targets++;
 
-               pr_debug("target_idx %d, n_targets %d\n", target->idx,
+               pr_debug("logical idx %d, n_targets %d\n", target->logical_idx,
                         ndev->n_targets);
        }
 }
@@ -372,10 +372,11 @@ static void nci_target_auto_activated(struct nci_dev *ndev,
        if (rc)
                return;
 
-       target->idx = ntf->rf_discovery_id;
+       target->logical_idx = ntf->rf_discovery_id;
        ndev->n_targets++;
 
-       pr_debug("target_idx %d, n_targets %d\n", target->idx, ndev->n_targets);
+       pr_debug("logical idx %d, n_targets %d\n",
+                target->logical_idx, ndev->n_targets);
 
        nfc_targets_found(ndev->nfc_dev, ndev->targets, ndev->n_targets);
 }
index 8937664674fae623f4ec8e27fad62e5d2e8c9ec4..f1829f6ae9c552fab7b2090fddb2283511b7f4d5 100644 (file)
@@ -188,6 +188,37 @@ free_msg:
        return -EMSGSIZE;
 }
 
+int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx)
+{
+       struct sk_buff *msg;
+       void *hdr;
+
+       msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
+       if (!msg)
+               return -ENOMEM;
+
+       hdr = genlmsg_put(msg, 0, 0, &nfc_genl_family, 0,
+                         NFC_EVENT_TARGET_LOST);
+       if (!hdr)
+               goto free_msg;
+
+       if (nla_put_string(msg, NFC_ATTR_DEVICE_NAME, nfc_device_name(dev)) ||
+           nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target_idx))
+               goto nla_put_failure;
+
+       genlmsg_end(msg, hdr);
+
+       genlmsg_multicast(msg, 0, nfc_genl_event_mcgrp.id, GFP_KERNEL);
+
+       return 0;
+
+nla_put_failure:
+       genlmsg_cancel(msg, hdr);
+free_msg:
+       nlmsg_free(msg);
+       return -EMSGSIZE;
+}
+
 int nfc_genl_device_added(struct nfc_dev *dev)
 {
        struct sk_buff *msg;
index 061a830b0a884004f5ce4b55c7f11b8a25a31a2f..7d589a81942e169cb21792754452a9f6c2ea69a9 100644 (file)
@@ -119,6 +119,7 @@ void nfc_genl_data_init(struct nfc_genl_data *genl_data);
 void nfc_genl_data_exit(struct nfc_genl_data *genl_data);
 
 int nfc_genl_targets_found(struct nfc_dev *dev);
+int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx);
 
 int nfc_genl_device_added(struct nfc_dev *dev);
 int nfc_genl_device_removed(struct nfc_dev *dev);
index 5a839ceb2e82f1f23e45595ae836526b9589fefd..ec1134c9e07fcd34fc5d6116e1a4aef9dedf6f23 100644 (file)
@@ -92,6 +92,12 @@ static int rawsock_connect(struct socket *sock, struct sockaddr *_addr,
                goto error;
        }
 
+       if (addr->target_idx > dev->target_next_idx - 1 ||
+           addr->target_idx < dev->target_next_idx - dev->n_targets) {
+               rc = -EINVAL;
+               goto error;
+       }
+
        rc = nfc_activate_target(dev, addr->target_idx, addr->nfc_protocol);
        if (rc)
                goto put_dev;
index 59f4a7e7c0921f4baaf5c00eb243d3ec70cc60d3..39f2538a46fc03936e7ef4145c7de29c0a624a62 100644 (file)
@@ -422,10 +422,6 @@ static int wiphy_verify_combinations(struct wiphy *wiphy)
        const struct ieee80211_iface_combination *c;
        int i, j;
 
-       /* If we have combinations enforce them */
-       if (wiphy->n_iface_combinations)
-               wiphy->flags |= WIPHY_FLAG_ENFORCE_COMBINATIONS;
-
        for (i = 0; i < wiphy->n_iface_combinations; i++) {
                u32 cnt = 0;
                u16 all_iftypes = 0;
index ff1a6c7fbe3392d17860d866399606449b9270d4..83d71d6b63a45570dbdceea6a4fdb82c70c93d21 100644 (file)
@@ -1540,6 +1540,19 @@ static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
                        (cfg80211_rdev_list_generation << 2)))
                goto nla_put_failure;
 
+       if (rdev->ops->get_channel) {
+               struct ieee80211_channel *chan;
+               enum nl80211_channel_type channel_type;
+
+               chan = rdev->ops->get_channel(&rdev->wiphy, &channel_type);
+               if (chan &&
+                   (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
+                                   chan->center_freq) ||
+                    nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
+                                   channel_type)))
+                       goto nla_put_failure;
+       }
+
        return genlmsg_end(msg, hdr);
 
  nla_put_failure:
index fdbcfe692a36e60d37ff35f5f870c5d6c2d52928..1442bb68a3f3cc5a1a2d94895ac47b3b45e3e087 100644 (file)
@@ -18,7 +18,7 @@
 #include "nl80211.h"
 #include "wext-compat.h"
 
-#define IEEE80211_SCAN_RESULT_EXPIRE   (15 * HZ)
+#define IEEE80211_SCAN_RESULT_EXPIRE   (30 * HZ)
 
 void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak)
 {
index 1b7a08df933c79bf4ffe62455747464468c84bdb..ffced852284d46c8b69cd72a147cccc715888289 100644 (file)
@@ -946,13 +946,6 @@ int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
        if (rdev->wiphy.software_iftypes & BIT(iftype))
                return 0;
 
-       /*
-        * Drivers will gradually all set this flag, until all
-        * have it we only enforce for those that set it.
-        */
-       if (!(rdev->wiphy.flags & WIPHY_FLAG_ENFORCE_COMBINATIONS))
-               return 0;
-
        memset(num, 0, sizeof(num));
 
        num[iftype] = 1;
@@ -972,6 +965,9 @@ int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
        }
        mutex_unlock(&rdev->devlist_mtx);
 
+       if (total == 1)
+               return 0;
+
        for (i = 0; i < rdev->wiphy.n_iface_combinations; i++) {
                const struct ieee80211_iface_combination *c;
                struct ieee80211_iface_limit *limits;
index 3c24eb97e9d7f0eaf60cff02f2372967f29e5284..6a6181a673ca07a378a4b524f88249de78b661e4 100644 (file)
@@ -821,6 +821,7 @@ static int cfg80211_wext_giwfreq(struct net_device *dev,
        struct wireless_dev *wdev = dev->ieee80211_ptr;
        struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
        struct ieee80211_channel *chan;
+       enum nl80211_channel_type channel_type;
 
        switch (wdev->iftype) {
        case NL80211_IFTYPE_STATION:
@@ -831,7 +832,7 @@ static int cfg80211_wext_giwfreq(struct net_device *dev,
                if (!rdev->ops->get_channel)
                        return -EINVAL;
 
-               chan = rdev->ops->get_channel(wdev->wiphy);
+               chan = rdev->ops->get_channel(wdev->wiphy, &channel_type);
                if (!chan)
                        return -EINVAL;
                freq->m = chan->center_freq;
This page took 1.036252 seconds and 5 git commands to generate.